From: Chris Duncan Date: Fri, 13 Dec 2024 20:14:36 +0000 (-0800) Subject: Simplify canvas config with a single static constant. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=443d4ef902eb45df76186560c09efdfcce79ff20;p=libnemo.git Simplify canvas config with a single static constant. --- diff --git a/src/lib/workers/pow.ts b/src/lib/workers/pow.ts index dfcffae..5678433 100644 --- a/src/lib/workers/pow.ts +++ b/src/lib/workers/pow.ts @@ -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 { return new Promise(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;