0
votes

For some post-rendering effects I need to read the depth-texture. This works fine as long as multi-sampling is turned off. But with multi-sampling I have trouble reading the texture.

Trying to use the multisample-texture in the shader though an depth2d_ms argument the compiler will fail at run time with an error message "Internal Compiler Error".

I found that with OpenGL you'd first blit the multisample depth buffer to a resolved depth buffer to read the sampled values, but with Metal I get an assertion error stating that sample counts of blit textures need to match, so there is no chance blitting 4 samples into 1.

So how would I read sampled or unsampled values from the depth buffer whilst using multi-sampling?

2

2 Answers

2
votes

I don't know the answer. But suggest to try below solution:

Set the storeAction of MTLRenderPassDepthAttachmentDescriptor as below:

  depthAttachment.storeAction = MTLStoreActionMultisampleResolve;

and also set its resolveTexture to another texture:

  depthAttachment.resolveTexture = targetResolvedDepthTexture.

at last, try to read the targetResolvedDepthTexture content.