]> zoso.dev Git - libnemo.git/commitdiff
Revert nonce and found swap.
authorChris Duncan <chris@zoso.dev>
Sun, 5 Jan 2025 08:43:12 +0000 (00:43 -0800)
committerChris Duncan <chris@zoso.dev>
Sun, 5 Jan 2025 08:43:12 +0000 (00:43 -0800)
src/lib/workers/powgpu.ts

index 920e090f07350a379fc9903b123f9f1980904935..431f1ebf0508e5e697418854c9d78cc792d03363 100644 (file)
@@ -53,8 +53,8 @@ export class PowGpu extends WorkerInterface {
                @group(0) @binding(0) var<uniform> ubo: UBO;
 
                struct WORK {
-                       found: atomic<u32>,
-                       nonce: vec2<u32>
+                       nonce: vec2<u32>,
+                       found: atomic<u32>
                };
                @group(0) @binding(1) var<storage, read_write> work: WORK;
 
@@ -220,10 +220,6 @@ export class PowGpu extends WorkerInterface {
                                work.nonce.y = m[1];
                                return;
                        }
-
-                       /**
-                       * Nonce not found in this execution context
-                       */
                        return;
                }
        `;
@@ -326,7 +322,7 @@ export class PowGpu extends WorkerInterface {
                PowGpu.#device.queue.writeBuffer(PowGpu.#uboBuffer, 0, uboView)
 
                // Reset `found` flag to 0u in WORK before each calculation
-               PowGpu.#device.queue.writeBuffer(PowGpu.#gpuBuffer, 0, new Uint32Array([0]))
+               PowGpu.#device.queue.writeBuffer(PowGpu.#gpuBuffer, 8, new Uint32Array([0]))
 
                // Bind UBO read and GPU write buffers
                const bindGroup = PowGpu.#device.createBindGroup({
@@ -373,8 +369,8 @@ export class PowGpu extends WorkerInterface {
                await PowGpu.#cpuBuffer.mapAsync(GPUMapMode.READ)
                await PowGpu.#device.queue.onSubmittedWorkDone()
                const data = new DataView(PowGpu.#cpuBuffer.getMappedRange())
-               const found = !!data.getUint32(0)
-               const nonce = data.getBigUint64(8, true)
+               const nonce = data.getBigUint64(0, true)
+               const found = !!data.getUint32(8)
                PowGpu.#cpuBuffer.unmap()
 
                if (found) {