Quellcode durchsuchen

Added some debug code + renaming of variables

Popov72 vor 4 Jahren
Ursprung
Commit
2c3d914e4e
2 geänderte Dateien mit 33 neuen und 16 gelöschten Zeilen
  1. 4 3
      src/Engines/WebGPU/webgpuTextureHelper.ts
  2. 29 13
      src/Engines/webgpuEngine.ts

+ 4 - 3
src/Engines/WebGPU/webgpuTextureHelper.ts

@@ -340,7 +340,7 @@ export class WebGPUTextureHelper {
     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>;
+        /*let promise: Promise<ImageBitmap | HTMLCanvasElement>;
 
         if ((invertY || premultiplyAlpha) && imageBitmap instanceof ImageBitmap) {
             promise = createImageBitmap(imageBitmap, { imageOrientation: invertY ? "flipY" : "none", premultiplyAlpha: premultiplyAlpha ? "premultiply" : "none" });
@@ -348,7 +348,7 @@ export class WebGPUTextureHelper {
             promise = Promise.resolve(imageBitmap);
         }
 
-        promise.then((imageBitmap) => {
+        promise.then((imageBitmap) => {*/
             const useOwnCommandEncoder = commandEncoder === undefined;
 
             if (useOwnCommandEncoder) {
@@ -381,6 +381,7 @@ export class WebGPUTextureHelper {
                     (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;
@@ -419,6 +420,6 @@ export class WebGPUTextureHelper {
                 this._device.defaultQueue.submit([commandEncoder!.finish()]);
                 commandEncoder = null as any;
             }
-        });
+        //});
     }
 }

+ 29 - 13
src/Engines/webgpuEngine.ts

@@ -894,6 +894,9 @@ export class WebGPUEngine extends Engine {
     public _releaseTexture(texture: InternalTexture): void {
         texture._hardwareTexture?.release();
 
+        // TODO WEBGPU remove debug code
+        (texture as any)._released = true;
+
         const index = this._internalTexturesCache.indexOf(texture);
         if (index !== -1) {
             this._internalTexturesCache.splice(index, 1);
@@ -1316,8 +1319,10 @@ export class WebGPUEngine extends Engine {
                 internalTexture._cachedWrapR = texture.wrapR;
             }
 
-            if (pipeline.samplers[name]) {
-                pipeline.samplers[name]!.texture = internalTexture!;
+            // TODO WEBGPU remove debug code
+            if ((internalTexture as any)._released) {
+                console.error("using a released texture in engine.setTexture!", internalTexture);
+                debugger;
             }
 
             if (webgpuPipelineContext.samplers[name]) {
@@ -1428,27 +1433,33 @@ export class WebGPUEngine extends Engine {
             gpuTexture = this._createGPUTextureForInternalTexture(texture, width, height);
         }
 
+        // TODO WEBGPU remove debug code
+        if ((texture as any)._released) {
+            console.log("using a released texture in updateDynamicTexture");
+        }
+
         // TODO WEBGPU: handle format if <> 0
         // let internalFormat = format ? this._getInternalFormat(format) : this._gl.RGBA;
 
         // TODO WEBGPU remove test code
-        if (canvas.width === 2560) {
+        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) {
+            /*if (!(this as any)._bitmap) {
                 createImageBitmap(canvas).then((imageBitmap) => {
                     (this as any)._bitmap = imageBitmap;
                 });
-            }
-            if ((this as any)._bitmap) {
+            }*/
+            //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, gpuTexture, width, height, 0, 0, invertY, premulAlpha, swap, 0, this._uploadEncoder);
             //texture.isReady = true;
             return;
@@ -2313,9 +2324,9 @@ export class WebGPUEngine extends Engine {
 
     private _getRenderPipeline(topology: GPUPrimitiveTopology): GPURenderPipeline {
         // This is wrong to cache this way but workarounds the need of cache in the simple demo context.
-        const gpuPipeline = this._currentEffect!._pipelineContext as WebGPUPipelineContext;
-        if (gpuPipeline.renderPipeline) {
-            return gpuPipeline.renderPipeline;
+        const webgpuPipelineContext = this._currentEffect!._pipelineContext as WebGPUPipelineContext;
+        if (webgpuPipelineContext.renderPipeline) {
+            return webgpuPipelineContext.renderPipeline;
         }
 
         // Unsupported at the moment but needs to be extracted from the MSAA param.
@@ -2326,7 +2337,7 @@ export class WebGPUEngine extends Engine {
         const inputStateDescriptor = this._getVertexInputDescriptor(topology);
         const pipelineLayout = this._getPipelineLayout();
 
-        gpuPipeline.renderPipeline = this._device.createRenderPipeline({
+        webgpuPipelineContext.renderPipeline = this._device.createRenderPipeline({
             sampleCount: this._mainPassSampleCount,
             primitiveTopology: topology,
             rasterizationState: rasterizationStateDescriptor,
@@ -2337,7 +2348,7 @@ export class WebGPUEngine extends Engine {
             vertexState: inputStateDescriptor,
             layout: pipelineLayout,
         });
-        return gpuPipeline.renderPipeline;
+        return webgpuPipelineContext.renderPipeline;
     }
 
     private _getVertexInputsToRender(): IWebGPUPipelineContextVertexInputsCache {
@@ -2451,6 +2462,11 @@ export class WebGPUEngine extends Engine {
                             debugger;
                         }
 
+                        if ((bindingInfo.texture as any)._released) {
+                            console.error("Trying to bind a released texture!", bindingInfo.texture);
+                            debugger;
+                        }
+
                         entries.push({
                             binding: bindingInfo.textureBinding,
                             resource: hardwareTexture.view!,
@@ -2516,7 +2532,7 @@ export class WebGPUEngine extends Engine {
         for (let i = 0; i < vertexInputs.vertexBuffers.length; i++) {
             const buf = vertexInputs.vertexBuffers[i];
             if (buf) {
-                renderPass.setVertexBuffer(vertexInputs.vertexStartSlot + i, vertexInputs.vertexBuffers[i], vertexInputs.vertexOffsets[i]);
+                renderPass.setVertexBuffer(vertexInputs.vertexStartSlot + i, buf, vertexInputs.vertexOffsets[i]);
             }
         }
     }