From 2eb63b06c1e3dbe0a69f31ce9be0b12408befe72 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 7 Jan 2025 14:12:21 -0800 Subject: [PATCH] Upload new bundle for platform testing. --- global.min.js | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/global.min.js b/global.min.js index 45a4b4c..6b7a55a 100644 --- a/global.min.js +++ b/global.min.js @@ -3488,6 +3488,10 @@ var init_powgpu = __esm({ static #bindGroupLayout; static #pipeline; static { + this.init(); + } + // Initialize WebGPU + static init() { if (navigator.gpu == null) { throw new Error("WebGPU is not supported in this browser."); } @@ -3554,12 +3558,12 @@ var init_powgpu = __esm({ throw new TypeError(`Invalid hash ${hash2}`); if (typeof threshold !== "number") throw new TypeError(`Invalid threshold ${threshold}`); - while (_PowGpu.#device == null && performance.now() < 8e3) { + while (this.#device == null && performance.now() < 8e3) { await new Promise((resolve) => { setTimeout(resolve, 500); }); } - if (_PowGpu.#device == null) + if (this.#device == null) throw new Error(`WebGPU device failed to load.`); const uboView = new DataView(new ArrayBuffer(48)); for (let i = 0; i < 64; i += 8) { @@ -3569,39 +3573,45 @@ var init_powgpu = __esm({ const random = Math.floor(Math.random() * 4294967295); uboView.setUint32(32, random, true); uboView.setUint32(36, threshold, true); - _PowGpu.#device.queue.writeBuffer(_PowGpu.#uboBuffer, 0, uboView); - _PowGpu.#device.queue.writeBuffer(_PowGpu.#gpuBuffer, 8, new Uint32Array([0])); - const bindGroup = _PowGpu.#device.createBindGroup({ - layout: _PowGpu.#bindGroupLayout, + this.#device.queue.writeBuffer(this.#uboBuffer, 0, uboView); + this.#device.queue.writeBuffer(this.#gpuBuffer, 8, new Uint32Array([0])); + const bindGroup = this.#device.createBindGroup({ + layout: this.#bindGroupLayout, entries: [ { binding: 0, resource: { - buffer: _PowGpu.#uboBuffer + buffer: this.#uboBuffer } }, { binding: 1, resource: { - buffer: _PowGpu.#gpuBuffer + buffer: this.#gpuBuffer } } ] }); - const commandEncoder = _PowGpu.#device.createCommandEncoder(); + const commandEncoder = this.#device.createCommandEncoder(); const passEncoder = commandEncoder.beginComputePass(); - passEncoder.setPipeline(_PowGpu.#pipeline); + passEncoder.setPipeline(this.#pipeline); passEncoder.setBindGroup(0, bindGroup); passEncoder.dispatchWorkgroups(256, 256, 256); passEncoder.end(); - commandEncoder.copyBufferToBuffer(_PowGpu.#gpuBuffer, 0, _PowGpu.#cpuBuffer, 0, 12); - _PowGpu.#device.queue.submit([commandEncoder.finish()]); - await _PowGpu.#cpuBuffer.mapAsync(GPUMapMode.READ); - await _PowGpu.#device.queue.onSubmittedWorkDone(); - const data = new DataView(_PowGpu.#cpuBuffer.getMappedRange()); + commandEncoder.copyBufferToBuffer(this.#gpuBuffer, 0, this.#cpuBuffer, 0, 12); + this.#device.queue.submit([commandEncoder.finish()]); + try { + await this.#cpuBuffer.mapAsync(GPUMapMode.READ); + await this.#device.queue.onSubmittedWorkDone(); + } catch (err) { + console.warn(`Reinitializing after catching error ${err}`); + this.init(); + return await this.search(hash2, threshold); + } + const data = new DataView(this.#cpuBuffer.getMappedRange()); const nonce = data.getBigUint64(0, true); const found = !!data.getUint32(8); - _PowGpu.#cpuBuffer.unmap(); + this.#cpuBuffer.unmap(); if (found) { const hex2 = nonce.toString(16).padStart(16, "0"); return hex2; -- 2.34.1