From a94f9e1842bc01423af2d7667d655d246008ae03 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sun, 5 Jan 2025 03:09:24 -0800 Subject: [PATCH] Set local variable for UBO member to avoid slowly dereferencing it. --- src/lib/workers/powgpu.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/workers/powgpu.ts b/src/lib/workers/powgpu.ts index 37acec9..984b1a2 100644 --- a/src/lib/workers/powgpu.ts +++ b/src/lib/workers/powgpu.ts @@ -152,6 +152,8 @@ export class PowGpu extends WorkerInterface { ) { if (atomicLoad(&work.found) != 0u) { return; } + let threshold: u32 = ubo.threshold; + /** * Flatten 3D workgroup and local identifiers into u32 for each thread */ @@ -323,7 +325,7 @@ export class PowGpu extends WorkerInterface { /** * Set nonce if it passes the threshold and no other thread has set it */ - if ((BLAKE2B_IV32_1 ^ v[1u] ^ v[17u]) > ubo.threshold && atomicLoad(&work.found) == 0u) { + if ((BLAKE2B_IV32_1 ^ v[1u] ^ v[17u]) > threshold && atomicLoad(&work.found) == 0u) { atomicStore(&work.found, 1u); work.nonce.x = m[0]; work.nonce.y = m[1]; @@ -474,8 +476,10 @@ export class PowGpu extends WorkerInterface { PowGpu.#device.queue.submit([commandEncoder.finish()]) // Read results back to Javascript and then unmap buffer after reading + const start = performance.now() await PowGpu.#cpuBuffer.mapAsync(GPUMapMode.READ) await PowGpu.#device.queue.onSubmittedWorkDone() + console.log(`mapAsync and onSubmittedWorkDone (${performance.now() - start} ms)`) const data = new DataView(PowGpu.#cpuBuffer.getMappedRange()) const nonce = data.getBigUint64(0, true) const found = !!data.getUint32(8) -- 2.34.1