if (this.#device == null) throw new Error(`WebGPU device failed to load.`)
// Create buffers for writing GPU calculations and reading from Javascript
this.#gpuBuffer = this.#device.createBuffer({
- size: 16,
+ size: 32,
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC
})
this.#cpuBuffer = this.#device.createBuffer({
- size: 16,
+ size: 32,
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
})
this.#uboBuffer = this.#device.createBuffer({
passEncoder.end()
// Copy 8-byte nonce and 4-byte found flag from GPU to CPU for reading
- commandEncoder.copyBufferToBuffer(this.#gpuBuffer, 0, this.#cpuBuffer, 0, 12)
+ commandEncoder.copyBufferToBuffer(this.#gpuBuffer, 0, this.#cpuBuffer, 0, 32)
// End computation by passing array of command buffers to command queue for execution
this.#device.queue.submit([commandEncoder.finish()])
const random0 = Math.floor(Math.random() * 0xffffffff)
const random1 = Math.floor(Math.random() * 0xffffffff)
const seed = (BigInt(random0) << 32n) | BigInt(random1)
- if (this.#debug) console.log(`seed: ${seed}`)
+ if (this.#debug) console.log('seed', seed.toString(16).padStart(16, '0'))
const data = await this.#dispatch(this.#searchPipeline, seed, hash, threshold, effort)
nonce = data.getBigUint64(0, true)
this.#busy = !data.getUint32(8)
+ if (this.#debug) console.log('result', data.getBigUint64(16).toString(16).padStart(16, '0'))
times.push(performance.now() - start)
} while (this.#busy)
if (this.#debug) this.#logAverages(times)
}
const seed = BigInt(`0x${work}`)
- if (this.#debug) console.log(`work: ${work}`)
+ if (this.#debug) console.log('work', work)
const data = await this.#dispatch(this.#validatePipeline, seed, hash, threshold, 1)
const nonce = data.getBigUint64(0, true)
const found = !!data.getUint32(8)
+ if (this.#debug) console.log('result', data.getBigUint64(16).toString(16).padStart(16, '0'))
this.#busy = false
if (this.#debug) console.log('nonce', nonce, nonce.toString(16).padStart(16, '0'))
if (found && work !== nonce.toString(16).padStart(16, '0')) throw new Error(`Nonce (${nonce.toString(16).padStart(16, '0')}) found but does not match work (${work})`)