threshold: u32
};
@group(0) @binding(0) var<uniform> ubo: UBO;
- @group(0) @binding(1) var<storage, read_write> work: u32;
+ @group(0) @binding(1) var<storage, read_write> work: vec2<u32>;
/**
* Defined separately from uint v[32] below as the original value is required
* Main compute function
*/
@compute @workgroup_size(256)
- fn main(
- @builtin(global_invocation_id) global_id: vec3<u32>,
- @builtin(workgroup_id) workgroup_id: vec3<u32>,
- @builtin(local_invocation_id) local_id: vec3<u32>
- ) {
+ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
var m: array<u32, 16>;
// 8-byte work is split into two 4-byte u32
- // First 3 bytes provided, last byte defined by this compute index
- m[0u] = (ubo.rand.x << 8u) ^ workgroup_id.x;
- m[1u] = (ubo.rand.y << 8u) ^ local_id.x;
+ // First 6 bytes provided, last 2 bytes defined by this compute index
+ m[0u] = ubo.rand.x;
+ m[1u] = (ubo.rand.y << 16u) ^ global_id.x;
// Block hash
m[2u] = ubo.blockhash[0u].x;
}
// Store the result directly into work array
- if ((BLAKE2B_IV32_1 ^ v[1u] ^ v[17u]) > 0u) {
- work = global_id.x;
+ if ((BLAKE2B_IV32_1 ^ v[1u] ^ v[17u]) > 0xffffffffu) {
+ work.x = ubo.rand.x;
+ work.y = (ubo.rand.y << 16u) ^ global_id.x;
}
}
`;
uboView.setUint32(i / 2, parseInt(uint32, 16))
}
const rand = crypto.getRandomValues(new Uint32Array(2))
+ console.log(rand)
uboView.setUint32(32, rand[0], true)
uboView.setUint32(36, rand[1], true)
uboView.setUint32(40, threshold, true)
const result = new Uint32Array(PowGpu.#cpuBuffer.getMappedRange()).slice()
PowGpu.#cpuBuffer.unmap()
- console.log(`result`)
- console.dir(result)
+ console.log(`result: ${[...result]}`)
if (result[0] !== 0 || result[1] !== 0) {
- const hex = PowGpu.#hexify([...result])
+ const hex = PowGpu.#hexify([result[0], result[1]])
typeof callback === 'function' && callback(hex)
return
}