engine icon indicating copy to clipboard operation
engine copied to clipboard

WebGPU MSAA render target with depth buffer fails

Open slimbuck opened this issue 1 year ago • 1 comments

It is not possible to create a multisampled render target and specify a target depth texture roughly like so:

const colorBuffer = createTexture(widthPixels, heightPixels, PIXELFORMAT_RGBA8);
const depthBuffer = createTexture(widthPixels, heightPixels, PIXELFORMAT_DEPTH);
const renderTarget = new RenderTarget({
    name: 'rt',
    colorBuffer: colorBuffer,
    depthBuffer: depthBuffer,
    flipY: false,
    samples: device.maxSamples,
    autoResolve: false
});

The resulting error is: Screenshot 2023-10-04 at 17 30 00

slimbuck avatar Oct 04 '23 16:10 slimbuck

Yep, this is not supported at the moment. What needs to happen for this to work:

  • in WebgpuRenderTarget, when samples > 1 and a depthBuffer is passed in, we need to allocate multi-sampled depth buffer for rendering. We cannot specify the provided single-sampled buffer as a resolve target, as WebGPU cannot automatically resolve depth.
  • then in the endPass for WebGPU, just before passEncoder.end (so using existing pass encoder) use WebgpuResolver to manually resolve the depth, which it already handles.
  • we possibly might need to update framegraph for the render pass in question to store the multisampled depth, as by default I think it just gets discarded.

mvaligursky avatar Oct 06 '23 11:10 mvaligursky