]> zoso.dev Git - nano-pow.git/commitdiff
Remove unused static GPU initiatlization since it will be initialized in the classes...
authorChris Duncan <chris@zoso.dev>
Sun, 12 Jan 2025 19:45:23 +0000 (11:45 -0800)
committerChris Duncan <chris@zoso.dev>
Sun, 12 Jan 2025 19:45:23 +0000 (11:45 -0800)
src/classes/gl.ts
src/classes/gpu.ts

index 9eae6026a0bb526665d72e8a7ba2c29ba18f7924..81ec49b2233ef860a9108217d738b28bd55df3a5 100644 (file)
@@ -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<boolean> {
+       static async #checkQueryResult (): Promise<boolean> {
                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<void> => {
-                                       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) {
index c8de386cdb51f42fc6f7cf517a7ffec6a07fdb91..ed8a9e8842087f969be11b44f59ec44bb3b15b94 100644 (file)
@@ -18,10 +18,6 @@ export class NanoPowGpu {
        static #bindGroupLayout: GPUBindGroupLayout
        static #pipeline: GPUComputePipeline
 
-       // static {
-       //      this.init()
-       // }
-
        // Initialize WebGPU
        static async init (): Promise<void> {
                if (this.#busy) return