From 1843dfc794c6845c4239c05abd11a8fa1d7e694d Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 24 Jan 2025 23:15:11 -0800 Subject: [PATCH] Eliminate an atomic operation by performing an exchange if threshold passed. --- src/shaders/compute.wgsl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/shaders/compute.wgsl b/src/shaders/compute.wgsl index abb665b..b6ee298 100644 --- a/src/shaders/compute.wgsl +++ b/src/shaders/compute.wgsl @@ -1432,9 +1432,11 @@ fn main(id: vec3) { /** * Set nonce if it passes the threshold and no other thread has set it */ - if ((BLAKE2B_IV32_0.y ^ v0.y ^ v8.y) > threshold && atomicLoad(&work.found) == 0u) { - atomicStore(&work.found, 1u); + if ((BLAKE2B_IV32_0.y ^ v0.y ^ v8.y) > threshold) { + let wasFound: u32 = atomicExchange(&work.found, 1u); + if (wasFound == 0u) { work.nonce = m0; + } } return; } -- 2.34.1