From: Chris Duncan Date: Sun, 12 Jan 2025 19:45:23 +0000 (-0800) Subject: Remove unused static GPU initiatlization since it will be initialized in the classes... X-Git-Tag: v1.2.0~14 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=82b1c17180a911d1190a1736e2afa7d6e0cbb9d7;p=nano-pow.git Remove unused static GPU initiatlization since it will be initialized in the classes export barrel. Convert GL initialization similarly. Make GL unexported functions private. --- diff --git a/src/classes/gl.ts b/src/classes/gl.ts index 9eae602..81ec49b 100644 --- a/src/classes/gl.ts +++ b/src/classes/gl.ts @@ -37,7 +37,7 @@ export class NanoPowGl { ]) /** Compile */ - static { + static async init() { this.#gl = new OffscreenCanvas(this.#WORKLOAD, this.#WORKLOAD).getContext('webgl2') if (this.#gl == null) throw new Error('WebGL 2 is required') this.#gl.clearColor(0, 0, 0, 1) @@ -128,16 +128,16 @@ export class NanoPowGl { let nonce = null const work = new Uint8Array(8) while (nonce == null) { - this.draw(work) - const found = await this.checkQueryResult() + this.#draw(work) + const found = await this.#checkQueryResult() if (found) { - nonce = this.readResult(work) + nonce = this.#readResult(work) } } return nonce } - static draw (work: Uint8Array): void { + static #draw (work: Uint8Array): void { if (this.#gl == null || this.#query == null) throw new Error('WebGL 2 is required to draw and query pixels') if (this.#workBuffer == null) throw new Error('Work buffer is required to draw') this.#gl.clear(this.#gl.COLOR_BUFFER_BIT) @@ -153,7 +153,7 @@ export class NanoPowGl { this.#gl.endQuery(this.#gl.ANY_SAMPLES_PASSED_CONSERVATIVE) } - static async checkQueryResult (): Promise { + static async #checkQueryResult (): Promise { if (this.#gl == null || this.#query == null) throw new Error('WebGL 2 is required to check query results') if (this.#gl.getQueryParameter(this.#query, this.#gl.QUERY_RESULT_AVAILABLE)) { return this.#gl.getQueryParameter(this.#query, this.#gl.QUERY_RESULT) @@ -162,7 +162,7 @@ export class NanoPowGl { return new Promise((resolve, reject): void => { try { requestAnimationFrame(async (): Promise => { - const result = await NanoPowGl.checkQueryResult() + const result = await NanoPowGl.#checkQueryResult() resolve(result) }) } catch (err) { @@ -179,7 +179,7 @@ export class NanoPowGl { * @param work - Buffer with the original random nonce value * @returns Nonce as an 8-byte (16-char) hexadecimal string */ - static readResult (work: Uint8Array): string { + static #readResult (work: Uint8Array): string { if (this.#gl == null) throw new Error('WebGL 2 is required to read pixels') this.#gl.readPixels(0, 0, this.#gl.drawingBufferWidth, this.#gl.drawingBufferHeight, this.#gl.RGBA, this.#gl.UNSIGNED_BYTE, this.#pixels) for (let i = 0; i < this.#pixels.length; i += 4) { diff --git a/src/classes/gpu.ts b/src/classes/gpu.ts index c8de386..ed8a9e8 100644 --- a/src/classes/gpu.ts +++ b/src/classes/gpu.ts @@ -18,10 +18,6 @@ export class NanoPowGpu { static #bindGroupLayout: GPUBindGroupLayout static #pipeline: GPUComputePipeline - // static { - // this.init() - // } - // Initialize WebGPU static async init (): Promise { if (this.#busy) return