]> zoso.dev Git - libnemo.git/commitdiff
Revert "Pass SIGMA82 into shader as uniform."
authorChris Duncan <chris@zoso.dev>
Sun, 15 Dec 2024 08:14:40 +0000 (00:14 -0800)
committerChris Duncan <chris@zoso.dev>
Sun, 15 Dec 2024 08:14:40 +0000 (00:14 -0800)
This reverts commit b385c33875c09a27ad5498237f54aafa24b74d37.

src/lib/workers/pow.ts

index c1173411315bb726a0cb5d1fb2e49024e3f0458e..a8752aed73f7b97b0d494557831c35490e3badc5 100644 (file)
@@ -47,21 +47,13 @@ out vec4 fragColor;
 uniform uvec4 u_work0;
 // Last 4 bytes remain as generated externally
 uniform uvec4 u_work1;
-
 // Precalculated block hash components
 uniform uint blockHash[8];
-
 // Threshold is 0xfffffff8 for send/change blocks and 0xfffffe for all else
 uniform uint threshold;
-
 // Defines canvas size
 uniform float workload;
 
-// Offsets into the input data buffer for each mixing step.
-// They are multiplied by 2 from the original SIGMA values in
-// the C reference implementation, which refered to uint64s.
-uniform int SIGMA82[192];
-
 // Defined separately from uint v[32] below as the original value is required
 // to calculate the second uint32 of the digest for threshold comparison
 #define BLAKE2B_IV32_1 0x6A09E667u
@@ -91,6 +83,20 @@ uint v[32] = uint[32](
 // Input data buffer
 uint m[32];
 
+// These are offsets into the input data buffer for each mixing step.
+// They are multiplied by 2 from the original SIGMA values in
+// the C reference implementation, which refered to uint64s.
+const int SIGMA82[192] = int[192](
+       0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,28,20,8,16,18,30,26,12,2,24,
+       0,4,22,14,10,6,22,16,24,0,10,4,30,26,20,28,6,12,14,2,18,8,14,18,6,2,26,
+       24,22,28,4,12,10,20,8,0,30,16,18,0,10,14,4,8,20,30,28,2,22,24,12,16,6,
+       26,4,24,12,20,0,22,16,6,8,26,14,10,30,28,2,18,24,10,2,30,28,26,8,20,0,
+       14,12,6,18,4,16,22,26,22,14,28,24,2,6,18,10,0,30,8,16,12,4,20,12,30,28,
+       18,22,6,0,16,24,4,26,14,2,8,20,10,20,4,16,8,14,12,2,10,30,22,18,28,6,24,
+       26,0,0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,28,20,8,16,18,30,26,12,
+       2,24,0,4,22,14,10,6
+);
+
 // 64-bit unsigned addition within the compression buffer
 // Sets v[a,a+1] += b
 // b0 is the low 32 bits of b, b1 represents the high 32 bits
@@ -196,24 +202,15 @@ void main() {
        static #WORKLOAD: number = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency / 2))
        static #work0 = new Uint8Array(4)
        static #work1 = new Uint8Array(4)
-       /**
-       * Offsets into the input data buffer for each mixing step. They are multiplied
-       * by 2 from the original SIGMA values in the C reference implementation, which
-       * refered to uint64s.
-       */
        static #SIGMA82: number[] = [
-               0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
-               28, 20, 8, 16, 18, 30, 26, 12, 2, 24, 0, 4, 22, 14, 10, 6,
-               22, 16, 24, 0, 10, 4, 30, 26, 20, 28, 6, 12, 14, 2, 18, 8,
-               14, 18, 6, 2, 26, 24, 22, 28, 4, 12, 10, 20, 8, 0, 30, 16,
-               18, 0, 10, 14, 4, 8, 20, 30, 28, 2, 22, 24, 12, 16, 6, 26,
-               4, 24, 12, 20, 0, 22, 16, 6, 8, 26, 14, 10, 30, 28, 2, 18,
-               24, 10, 2, 30, 28, 26, 8, 20, 0, 14, 12, 6, 18, 4, 16, 22,
-               26, 22, 14, 28, 24, 2, 6, 18, 10, 0, 30, 8, 16, 12, 4, 20,
-               12, 30, 28, 18, 22, 6, 0, 16, 24, 4, 26, 14, 2, 8, 20, 10,
-               20, 4, 16, 8, 14, 12, 2, 10, 30, 22, 18, 28, 6, 24, 26, 0,
-               0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30,
-               28, 20, 8, 16, 18, 30, 26, 12, 2, 24, 0, 4, 22, 14, 10, 6
+               0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 28, 20, 8, 16, 18, 30, 26, 12, 2, 24,
+               0, 4, 22, 14, 10, 6, 22, 16, 24, 0, 10, 4, 30, 26, 20, 28, 6, 12, 14, 2, 18, 8, 14, 18, 6, 2, 26,
+               24, 22, 28, 4, 12, 10, 20, 8, 0, 30, 16, 18, 0, 10, 14, 4, 8, 20, 30, 28, 2, 22, 24, 12, 16, 6,
+               26, 4, 24, 12, 20, 0, 22, 16, 6, 8, 26, 14, 10, 30, 28, 2, 18, 24, 10, 2, 30, 28, 26, 8, 20, 0,
+               14, 12, 6, 18, 4, 16, 22, 26, 22, 14, 28, 24, 2, 6, 18, 10, 0, 30, 8, 16, 12, 4, 20, 12, 30, 28,
+               18, 22, 6, 0, 16, 24, 4, 26, 14, 2, 8, 20, 10, 20, 4, 16, 8, 14, 12, 2, 10, 30, 22, 18, 28, 6, 24,
+               26, 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 28, 20, 8, 16, 18, 30, 26, 12,
+               2, 24, 0, 4, 22, 14, 10, 6
        ]
        static #B2B_G_params: number[] = []
        static {
@@ -271,7 +268,6 @@ void main() {
        static #blockHashLocation: WebGLUniformLocation | null
        static #thresholdLocation: WebGLUniformLocation | null
        static #workloadLocation: WebGLUniformLocation | null
-       static #sigma82Location: WebGLUniformLocation | null
        static #vertexShader: WebGLShader | null
        static #fragmentShader: WebGLShader | null
        static #positionBuffer: WebGLBuffer | null
@@ -336,7 +332,6 @@ void main() {
                this.#blockHashLocation = this.#gl.getUniformLocation(this.#program, "blockHash")
                this.#thresholdLocation = this.#gl.getUniformLocation(this.#program, "threshold")
                this.#workloadLocation = this.#gl.getUniformLocation(this.#program, "workload")
-               this.#sigma82Location = this.#gl.getUniformLocation(this.#program, "SIGMA82")
        }
 
        static #calculate (hashHex: string, callback: (nonce: string | PromiseLike<string>) => any, threshold: number): void {
@@ -360,7 +355,6 @@ void main() {
                        Pow.#gl.uniform1uiv(Pow.#blockHashLocation, hashBytes)
                        Pow.#gl.uniform1ui(Pow.#thresholdLocation, threshold)
                        Pow.#gl.uniform1f(Pow.#workloadLocation, this.#WORKLOAD - 1)
-                       Pow.#gl.uniform1iv(Pow.#sigma82Location, this.#SIGMA82)
 
                        Pow.#gl.clear(Pow.#gl.COLOR_BUFFER_BIT)
                        Pow.#gl.drawArrays(Pow.#gl.TRIANGLES, 0, 6)