Browse Source

Remove debug code

Popov72 4 years ago
parent
commit
db1dda51ff
2 changed files with 2 additions and 136 deletions
  1. 1 111
      src/Engines/WebGPU/webgpuTextureHelper.ts
  2. 1 25
      src/Engines/webgpuEngine.ts

+ 1 - 111
src/Engines/WebGPU/webgpuTextureHelper.ts

@@ -308,7 +308,7 @@ export class WebGPUTextureHelper {
         };
 
         if ((imageBitmap as Uint8Array).byteLength !== undefined) {
-            // TODO WEBGPU handle invertY / premultiplyAlpha
+            // Note that we can't honor the invertY / premultiplyAlpha flags as we don't know the format of the array
             imageBitmap = imageBitmap as Uint8Array;
 
             const bytesPerRow = Math.ceil(width / blockInformation.width) * blockInformation.length;
@@ -353,114 +353,4 @@ export class WebGPUTextureHelper {
             }
         }
     }
-
-    // TODO WEBGPU remove this function when not needed anymore for testing
-    public updateTextureTest(imageBitmap: ImageBitmap | HTMLCanvasElement, gpuTexture: GPUTexture, width: number, height: number, faceIndex: number = 0, mipLevel: number = 0, invertY = false, premultiplyAlpha = false, offsetX = 0, offsetY = 0,
-        commandEncoder?: GPUCommandEncoder): void
-    {
-        /*let promise: Promise<ImageBitmap | HTMLCanvasElement>;
-
-        if ((invertY || premultiplyAlpha) && imageBitmap instanceof ImageBitmap) {
-            promise = createImageBitmap(imageBitmap, { imageOrientation: invertY ? "flipY" : "none", premultiplyAlpha: premultiplyAlpha ? "premultiply" : "none" });
-        } else {
-            promise = Promise.resolve(imageBitmap);
-        }
-
-        promise.then((imageBitmap) => {*/
-            const useOwnCommandEncoder = commandEncoder === undefined;
-
-            if (useOwnCommandEncoder) {
-                commandEncoder = this._device.createCommandEncoder({});
-            }
-
-            let gpuBuffer;
-
-            const bytesPerRow = Math.ceil(width * 4 / 256) * 256;
-
-            if (bytesPerRow === width * 4) {
-                if (!(this as any).textureView || !(this as any).textureView[offsetX]) {
-                    console.log("updateTextureTest create texture view and extent", width, height);
-                    const textureView = {
-                        texture: gpuTexture,
-                        origin: {
-                            x: 0/*offsetX*/,
-                            y: offsetY,
-                            z: Math.max(faceIndex, 0)
-                        },
-                        mipLevel: mipLevel
-                    };
-                    const textureExtent = {
-                        width,
-                        height,
-                        depth: 1
-                    };
-                    if (!(this as any).textureView) {
-                        (this as any).textureView = [];
-                        (this as any).textureExtent = [];
-                    }
-                    (this as any).textureView[offsetX] = textureView;
-                    (this as any).textureExtent[offsetX] = textureExtent;
-                }
-                (this as any).textureView[offsetX].texture = gpuTexture;
-                if (imageBitmap instanceof HTMLCanvasElement && (!(this as any).bufferView || !(this as any).bufferView[offsetX])) {
-                    console.log("updateTextureTest create data", width, height, offsetX);
-                    const canvas = imageBitmap as unknown as HTMLCanvasElement;
-                    const ctx = canvas.getContext('2d')!;
-                    const data = ctx.getImageData(0, 0, width, height).data;
-                    const dataBuffer = this._bufferManager.createBuffer(data, WebGPUConstants.BufferUsage.CopySrc | WebGPUConstants.BufferUsage.CopyDst);
-                    const bufferView: GPUBufferCopyView = {
-                        buffer: dataBuffer.underlyingResource,
-                        bytesPerRow: bytesPerRow,
-                        rowsPerImage: height,
-                        offset: 0,
-                    };
-                    if (!(this as any).bufferView) {
-                        (this as any).bufferView = [];
-                        (this as any).dataBuffer = [];
-                        (this as any).data = [];
-                    }
-                    (this as any).bufferView[offsetX] = bufferView;
-                    (this as any).dataBuffer[offsetX] = dataBuffer;
-                    (this as any).data[offsetX] = data;
-                }
-                if ((this as any).bufferView) {
-                    /*const canvas = imageBitmap as unknown as HTMLCanvasElement;
-                    const ctx = canvas.getContext('2d')!;
-                    const data = ctx.getImageData(0, 0, width, height).data;
-                    (this as any).data[offsetX] = data;*/
-
-                    //this._device.defaultQueue.writeTexture({ texture: gpuTexture }, (this as any).data[offsetX], { bytesPerRow }, (this as any).textureExtent[offsetX]);
-
-                    //this._bufferManager.setSubData((this as any).dataBuffer[offsetX], 0, (this as any).data[offsetX]);
-                    //commandEncoder!.copyBufferToTexture((this as any).bufferView[offsetX], (this as any).textureView[offsetX], (this as any).textureExtent[offsetX]);
-
-                    gpuBuffer = this._device.createBuffer({
-                        mappedAtCreation: true,
-                        size: (this as any).data[offsetX].byteLength,
-                        usage: GPUBufferUsage.MAP_WRITE | GPUBufferUsage.COPY_SRC
-                      });
-                    const arrayBuffer = gpuBuffer.getMappedRange();
-                    new Uint8Array(arrayBuffer).set((this as any).data[offsetX]);
-                    gpuBuffer.unmap();
-
-                    commandEncoder!.copyBufferToTexture({
-                        buffer: gpuBuffer,
-                        bytesPerRow: bytesPerRow,
-                        rowsPerImage: height,
-                        offset: 0,
-                    }, (this as any).textureView[offsetX], (this as any).textureExtent[offsetX]);
-                } else {
-                    this._device.defaultQueue.copyImageBitmapToTexture({ imageBitmap: imageBitmap as ImageBitmap }, (this as any).textureView[offsetX], (this as any).textureExtent[offsetX]);
-                }
-            }
-
-            if (useOwnCommandEncoder) {
-                this._device.defaultQueue.submit([commandEncoder!.finish()]);
-                commandEncoder = null as any;
-                if (gpuBuffer) {
-                    gpuBuffer.destroy();
-                }
-            }
-        //});
-    }
 }

+ 1 - 25
src/Engines/webgpuEngine.ts

@@ -1617,30 +1617,6 @@ export class WebGPUEngine extends Engine {
             console.log("using a released texture in updateDynamicTexture");
         }
 
-        // TODO WEBGPU remove test code
-        if (canvas.width === 25600) {
-            if ((this as any)._swap === undefined) { (this as any)._swap = 0; }
-            (this as any)._swap ^= 1;
-
-            const swap = (this as any)._swap;
-
-            /*if (!(this as any)._bitmap) {
-                createImageBitmap(canvas).then((imageBitmap) => {
-                    (this as any)._bitmap = imageBitmap;
-                });
-            }*/
-            //if ((this as any)._bitmap) {
-                /*createImageBitmap(canvas).then((bitmap: ImageBitmap) => {
-                    this._textureHelper.updateTextureTest(bitmap, gpuTexture, width, height, 0, 0, invertY, premulAlpha, swap, 0, this._uploadEncoder);
-                    texture.isReady = true;
-                });*/
-            //}
-
-            this._textureHelper.updateTextureTest(canvas as HTMLCanvasElement, gpuTextureWrapper.underlyingResource!, width, height, 0, 0, invertY, premulAlpha, swap, 0/*, this._uploadEncoder*/);
-            texture.isReady = true;
-            return;
-        }
-
         createImageBitmap(canvas).then((bitmap) => {
             this._textureHelper.updateTexture(bitmap, gpuTextureWrapper.underlyingResource!, width, height, gpuTextureWrapper.format, 0, 0, invertY, premulAlpha, 0, 0, this._uploadEncoder);
             if (texture.generateMipMaps) {
@@ -2116,7 +2092,7 @@ export class WebGPUEngine extends Engine {
             baseMipLevel: 0,
             arrayLayerCount: 1,
             aspect: WebGPUConstants.TextureAspect.All
-        }
+        };
 
         this._currentRenderPass = null; // lazy creation of the render pass, hoping the render pass will be created by a call to clear()...