From: Chris Duncan Date: Sun, 15 Dec 2024 19:25:58 +0000 (-0800) Subject: Draw depends on a specific work value, so move them into the function call to avoid... X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=583c2316627b683213eb1e20f093f464139a18bd;p=libnemo.git Draw depends on a specific work value, so move them into the function call to avoid collisions with other class usage. --- diff --git a/src/lib/workers/pow.ts b/src/lib/workers/pow.ts index 72fa88c..fc1080b 100644 --- a/src/lib/workers/pow.ts +++ b/src/lib/workers/pow.ts @@ -203,8 +203,6 @@ void main() { /** Used to set canvas size. Must be a multiple of 256. */ static #WORKLOAD: number = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency / 2)) - static #work0 = new Uint8Array(4) - static #work1 = new Uint8Array(4) static #hexify (arr: number[] | Uint8Array): string { let out = '' @@ -307,6 +305,8 @@ void main() { view.setUint8(i / 2, parseInt(byte, 16)) } const hashBytes = new Uint32Array(view.buffer) + const work0 = new Uint8Array(4) + const work1 = new Uint8Array(4) // Draw output until success or progressCallback says to stop let n = 0 @@ -315,14 +315,14 @@ void main() { n++ if (Pow.#gl == null) throw new Error('WebGL 2 is required') performance.mark('start') - crypto.getRandomValues(Pow.#work0) - crypto.getRandomValues(Pow.#work1) + crypto.getRandomValues(work0) + crypto.getRandomValues(work1) - Pow.#gl.uniform4uiv(Pow.#work0Location, this.#work0) - Pow.#gl.uniform4uiv(Pow.#work1Location, this.#work1) + 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, this.#WORKLOAD - 1) + Pow.#gl.uniform1f(Pow.#workloadLocation, Pow.#WORKLOAD - 1) Pow.#gl.clear(Pow.#gl.COLOR_BUFFER_BIT) Pow.#gl.drawArrays(Pow.#gl.TRIANGLES, 0, 6) @@ -336,11 +336,11 @@ void main() { performance.clearMarks() console.log(`average frame time: ${(frameTimes.reduce((a, b) => a + b)) / frameTimes.length} ms`) console.log(`frames calculated: ${n}`) - const hex = this.#hexify(this.#work1) + this.#hexify([ + const hex = this.#hexify(work1) + this.#hexify([ pixels[i + 2], pixels[i + 3], - this.#work0[2] ^ (pixels[i] - 1), - this.#work0[3] ^ (pixels[i + 1] - 1) + work0[2] ^ (pixels[i] - 1), + work0[3] ^ (pixels[i + 1] - 1) ]) // Return the work value with the custom bits typeof callback === 'function' && callback(hex)