]> zoso.dev Git - libnemo.git/commitdiff
Simplify canvas config with a single static constant.
authorChris Duncan <chris@zoso.dev>
Fri, 13 Dec 2024 20:14:36 +0000 (12:14 -0800)
committerChris Duncan <chris@zoso.dev>
Fri, 13 Dec 2024 20:14:36 +0000 (12:14 -0800)
src/lib/workers/pow.ts

index dfcffaee061220bc042b2d7b3e927d88cbca3726..567843332239fc972f21eef4dc68f7a4b47193ee 100644 (file)
@@ -3,6 +3,7 @@
 
 export class Pow {
        static SEND_THRESHOLD = '0xfffffff8'
+       static WORKLOAD: number = 256 * 4               // must be a multiple of 256
 
        static async find (hash: string, threshold: string = this.SEND_THRESHOLD): Promise<string> {
                return new Promise<string>(resolve => {
@@ -26,12 +27,7 @@ export class Pow {
        * @param threshold         Number|String   Optional difficulty threshold (default=0xFFFFFFF8 since v21)
        */
 
-       // Both width and height must be multiple of 256, (one byte)
-       // but do not need to be the same,
-       // matching GPU capabilities is the aim
-       static webglWidth = 256 * 2
-       static webglHeight = 256 * 2
-       static gl = new OffscreenCanvas(this.webglWidth, this.webglHeight).getContext('webgl2')
+       static gl = new OffscreenCanvas(this.WORKLOAD, this.WORKLOAD).getContext('webgl2')
        static work0 = new Uint8Array(4)
        static work1 = new Uint8Array(4)
        static SIGMA82: number[] = [
@@ -216,8 +212,8 @@ export class Pow {
 
                void main() {
                        int i;
-                       uint uv_x = uint(uv_pos.x * ${this.webglWidth - 1}.);
-                       uint uv_y = uint(uv_pos.y * ${this.webglHeight - 1}.);
+                       uint uv_x = uint(uv_pos.x * ${this.WORKLOAD - 1}.);
+                       uint uv_y = uint(uv_pos.y * ${this.WORKLOAD - 1}.);
                        uint x_pos = uv_x % 256u;
                        uint y_pos = uv_y % 256u;
                        uint x_index = (uv_x - x_pos) / 256u;