From db0c58de1600a9d9016686fd10dae09eb9f5d5a0 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 11 Jan 2025 22:11:10 -0800 Subject: [PATCH] Extend random input to shader to accomodate validation of nonces. --- src/classes/gpu.ts | 3 ++- src/shaders/compute.wgsl | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/classes/gpu.ts b/src/classes/gpu.ts index 85d907b..7b825f3 100644 --- a/src/classes/gpu.ts +++ b/src/classes/gpu.ts @@ -141,7 +141,8 @@ export class NanoPowGpu { } const random = Math.floor((Math.random() * 0xffffffff)) uboView.setUint32(32, random, true) - uboView.setUint32(36, threshold, true) + uboView.setUint32(36, random, true) + uboView.setUint32(40, threshold, true) this.#device.queue.writeBuffer(this.#uboBuffer, 0, uboView) // Reset `nonce` and `found` to 0u in WORK before each calculation diff --git a/src/shaders/compute.wgsl b/src/shaders/compute.wgsl index 8036a7d..354b65f 100644 --- a/src/shaders/compute.wgsl +++ b/src/shaders/compute.wgsl @@ -3,7 +3,7 @@ struct UBO { blockhash: array, 2>, - random: u32, + random: vec2, threshold: u32 }; @group(0) @binding(0) var ubo: UBO; @@ -35,8 +35,8 @@ fn main(@builtin(global_invocation_id) id: vec3) { /** * Initialize (nonce||blockhash) concatenation */ - var m0: u32 = ubo.random ^ id.x; - var m1: u32 = ubo.random ^ id.y; + var m0: u32 = ubo.random.x ^ id.x; + var m1: u32 = ubo.random.y ^ id.y; var m2: u32 = ubo.blockhash[0u].x; var m3: u32 = ubo.blockhash[0u].y; var m4: u32 = ubo.blockhash[0u].z; -- 2.34.1