]> zoso.dev Git - libnemo.git/commitdiff
Fix threshold offset in Javascript. Tweak commenting and remove logging.
authorChris Duncan <chris@zoso.dev>
Sat, 4 Jan 2025 09:47:41 +0000 (01:47 -0800)
committerChris Duncan <chris@zoso.dev>
Sat, 4 Jan 2025 09:47:41 +0000 (01:47 -0800)
src/lib/workers/powgpu.ts

index fd04dbe82db916fe41ccd3869b01d92665af68d9..e727a997c2b41e1c5d3cbc186eff28e1b16cd5cf 100644 (file)
@@ -151,9 +151,9 @@ export class PowGpu extends WorkerInterface {
                                return;
                        }
                        var id: u32 = ((workgroup_id.x & 0xff) << 24) |
-                                                                               ((workgroup_id.y & 0xff) << 16) |
-                                                                               ((workgroup_id.z & 0xff) << 8) |
-                                                                               (local_id.x & 0xff);
+                               ((workgroup_id.y & 0xff) << 16) |
+                               ((workgroup_id.z & 0xff) << 8) |
+                               (local_id.x & 0xff);
                        var m: array<u32, 16>;
                        m[0u] = ubo.random;
                        m[1u] = id ^ ubo.random;
@@ -167,13 +167,13 @@ export class PowGpu extends WorkerInterface {
                        m[9u] = ubo.blockhash[1u].w;
 
                        /**
-                       * Compression buffer, intialized to 2 instances of the initialization vector
+                       * Compression buffer intialized to 2 instances of initialization vector
                        * The following values have been modified from the BLAKE2B_IV:
                        * OUTLEN is constant 8 bytes
                        * v[0u] ^= 0x01010000u ^ uint(OUTLEN);
                        * INLEN is constant 40 bytes: work value (8) + block hash (32)
                        * v[24u] ^= uint(INLEN);
-                       * It's always the "last" compression at this INLEN
+                       * It is always the "last" compression at this INLEN
                        * v[28u] = ~v[28u];
                        * v[29u] = ~v[29u];
                        */
@@ -212,6 +212,9 @@ export class PowGpu extends WorkerInterface {
                                return;
                        }
 
+                       /**
+                       * Nonce not found in this execution context
+                       */
                        return;
                }
        `;
@@ -296,15 +299,15 @@ export class PowGpu extends WorkerInterface {
                }
 
                // Set up uniform buffer object
-               const uboView = new DataView(new ArrayBuffer(64))
+               // Note: u32 size is 4, but total alignment must be multiple of 16
+               const uboView = new DataView(new ArrayBuffer(48))
                for (let i = 0; i < 64; i += 8) {
                        const uint32 = hashHex.slice(i, i + 8)
                        uboView.setUint32(i / 2, parseInt(uint32, 16))
                }
                const random = crypto.getRandomValues(new Uint32Array(1))[0]
-               console.log(`random: ${random}`)
                uboView.setUint32(32, random, true)
-               uboView.setUint32(48, threshold, true)
+               uboView.setUint32(36, threshold, true)
                const uboBuffer = PowGpu.#device.createBuffer({
                        size: uboView.byteLength,
                        usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
@@ -358,7 +361,6 @@ export class PowGpu extends WorkerInterface {
                const data = new DataView(PowGpu.#cpuBuffer.getMappedRange())
                const nonce = data.getBigUint64(0, true)
                const found = !!data.getUint32(8)
-               console.log(new Uint32Array(data.buffer))
                PowGpu.#cpuBuffer.unmap()
 
                if (found) {