]> zoso.dev Git - nano-pow.git/commitdiff
Avoid main function call entirely if work was already found.
authorChris Duncan <chris@zoso.dev>
Fri, 17 Jan 2025 18:47:09 +0000 (10:47 -0800)
committerChris Duncan <chris@zoso.dev>
Fri, 17 Jan 2025 18:47:09 +0000 (10:47 -0800)
src/shaders/compute.wgsl

index 79486d0be45a005328073201bc46fafb5f64f860..beec4a9755d4d185bd8a98210ffa7307f579356f 100644 (file)
@@ -35,6 +35,7 @@ const ROTATE_31 = vec2(31u, 31u);
 */
 @compute @workgroup_size(8,8)
 fn search(@builtin(global_invocation_id) global_id: vec3<u32>) {
+       if (atomicLoad(&work.found) != 0u) { return; }
        main(global_id);
 }
 
@@ -44,6 +45,7 @@ fn search(@builtin(global_invocation_id) global_id: vec3<u32>) {
 */
 @compute @workgroup_size(1)
 fn validate(@builtin(global_invocation_id) global_id: vec3<u32>) {
+       if (atomicLoad(&work.found) != 0u) { return; }
        main(global_id);
 }
 
@@ -58,8 +60,6 @@ fn validate(@builtin(global_invocation_id) global_id: vec3<u32>) {
 * performance, but the variable name still contains the original index digit.
 */
 fn main(id: vec3<u32>) {
-       if (atomicLoad(&work.found) != 0u) { return; }
-
        let threshold: u32 = ubo.threshold;
 
        /**