From: Chris Duncan Date: Wed, 18 Dec 2024 23:50:30 +0000 (-0800) Subject: Move uniform transfers outside of draw loop where possible. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=98a8751c9f1b2d0a7f0f8a1aacff9b0457f1a320;p=libnemo.git Move uniform transfers outside of draw loop where possible. --- diff --git a/src/lib/workers/pow.ts b/src/lib/workers/pow.ts index fee4e81..c9e3bab 100644 --- a/src/lib/workers/pow.ts +++ b/src/lib/workers/pow.ts @@ -16,12 +16,6 @@ export class Pow { }) } - /** - * nano-webgl-pow - * Nano Currency Proof of Work Value generation using WebGL2 - * Author: numtel - * License: MIT - */ // Vertex Shader static #vsSource = `#version 300 es #pragma vscode_glsllint_stage: vert @@ -294,6 +288,7 @@ void main() { } static #calculate (hashHex: string, callback: (nonce: string | PromiseLike) => any, threshold: number): void { + if (Pow.#gl == null) throw new Error('WebGL 2 is required') if (!/^[A-F-a-f0-9]{64}$/.test(hashHex)) throw new Error(`invalid_hash ${hashHex}`) if (typeof threshold !== 'number') throw new TypeError(`Invalid threshold ${threshold}`) if (this.#gl == null) throw new Error('WebGL 2 is required') @@ -305,6 +300,9 @@ void main() { view.setUint8(i / 2, parseInt(byte, 16)) } const hashBytes = new Uint32Array(view.buffer) + Pow.#gl.uniform1uiv(Pow.#blockHashLocation, hashBytes) + Pow.#gl.uniform1ui(Pow.#thresholdLocation, threshold) + Pow.#gl.uniform1f(Pow.#workloadLocation, Pow.#WORKLOAD - 1) const work0 = new Uint8Array(4) const work1 = new Uint8Array(4) @@ -322,9 +320,6 @@ void main() { Pow.#gl.uniform4uiv(Pow.#work0Location, work0) Pow.#gl.uniform4uiv(Pow.#work1Location, work1) - Pow.#gl.uniform1uiv(Pow.#blockHashLocation, hashBytes) - Pow.#gl.uniform1ui(Pow.#thresholdLocation, threshold) - Pow.#gl.uniform1f(Pow.#workloadLocation, Pow.#WORKLOAD - 1) Pow.#gl.beginQuery(Pow.#gl.ANY_SAMPLES_PASSED_CONSERVATIVE, Pow.#query) Pow.#gl.drawArrays(Pow.#gl.TRIANGLES, 0, 6)