Pārlūkot izejas kodu

Fix crash when reading pixels while in a render pass

Popov72 4 gadi atpakaļ
vecāks
revīzija
5aa46aaf02
2 mainītis faili ar 23 papildinājumiem un 0 dzēšanām
  1. 21 0
      src/Engines/webgpuEngine.ts
  2. 2 0
      tests/validation/config.json

+ 21 - 0
src/Engines/webgpuEngine.ts

@@ -2521,6 +2521,20 @@ export class WebGPUEngine extends Engine {
     }
 
     public flushFramebuffer(): void {
+        // we need to end the current render pass (main or rtt) if any as we are not allowed to submit the command buffers when being in a pass
+        let currentPassType = 0; // 0 if no pass, 1 for rtt, 2 for main pass
+        if (this._currentRenderPass) {
+            if (this._currentRenderTarget) {
+                if (this._currentRenderPass) {
+                    currentPassType = 1;
+                    this._endRenderTargetRenderPass();
+                }
+            } else {
+                currentPassType = 2;
+                this._endMainRenderPass();
+            }
+        }
+
         this._commandBuffers[0] = this._uploadEncoder.finish();
         this._commandBuffers[1] = this._renderTargetEncoder.finish();
         this._commandBuffers[2] = this._renderEncoder.finish();
@@ -2530,6 +2544,13 @@ export class WebGPUEngine extends Engine {
         this._uploadEncoder = this._device.createCommandEncoder(this._uploadEncoderDescriptor);
         this._renderEncoder = this._device.createCommandEncoder(this._renderEncoderDescriptor);
         this._renderTargetEncoder = this._device.createCommandEncoder(this._renderTargetEncoderDescriptor);
+
+        // restart the render pass
+        if (currentPassType === 1) {
+            this._startRenderTargetRenderPass(this._currentRenderTarget!, null, false, false);
+        } else if (currentPassType === 2) {
+            this._startMainRenderPass();
+        }
     }
 
     public restoreDefaultFramebuffer(): void {

+ 2 - 0
tests/validation/config.json

@@ -80,6 +80,7 @@
         {
             "title": "Node material PBR 1",
             "playgroundId": "#D8AK3Z#15",
+            "renderCount": 5,
             "referenceImage": "node-material-pbr-1.png"
         },    
         {
@@ -914,6 +915,7 @@
         {
             "title": "Realtime Filtering",
             "playgroundId": "#FEEK7G#118",
+            "renderCount": 5,
             "referenceImage": "realtimeFiltering.png"
         },
         {