]> zoso.dev Git - libnemo.git/commitdiff
Set local variable for UBO member to avoid slowly dereferencing it.
authorChris Duncan <chris@zoso.dev>
Sun, 5 Jan 2025 11:09:24 +0000 (03:09 -0800)
committerChris Duncan <chris@zoso.dev>
Sun, 5 Jan 2025 11:09:24 +0000 (03:09 -0800)
src/lib/workers/powgpu.ts

index 37acec9e132641a73adb9e36f5efda0f7003d5b3..984b1a25370356430e54f69cf057e1c744908bc8 100644 (file)
@@ -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)