Resolving a Depth/Stencil buffer?

Started by
3 comments, last by kazemi 12 years, 10 months ago
I'm trying to implement a deferred rendering engine with Direct3D 11, now somewhere in my code I have to resolve a MS Depth buffer so that I can bind it for use in the forward rendering pass where it should be single sampled. I use ResolveSubresource like this:

pD3DDeviceContext->ResolveSubresource(destTexture, 0, srcTexture, 0, DXGI_FORMAT_D24_UNORM_S8_UINT);

But it doesn't seem to do anything at all! Can you think of anything that I'm doing wrong?

Thanks
Advertisement

I'm trying to implement a deferred rendering engine with Direct3D 11, now somewhere in my code I have to resolve a MS Depth buffer so that I can bind it for use in the forward rendering pass where it should be single sampled. I use ResolveSubresource like this:

pD3DDeviceContext->ResolveSubresource(destTexture, 0, srcTexture, 0, DXGI_FORMAT_D24_UNORM_S8_UINT);

But it doesn't seem to do anything at all! Can you think of anything that I'm doing wrong?

Thanks


DXGI_FORMAT_D24_UNORM_S8_UINT doesn't support MSAA resolve. This chart shows you which operations are supported for each format. Besides even if you could do that, it doesn't make much sense to average depth samples in that way (which also goes for anything else in a G-Buffer).

You'll need to access your depth buffer as a Texture2DMS in your shader if you want to sample it. If you want you can just grab the 0th subsample for each pixel, but ideally if you're implementing MSAA then you should detect pixels where a triangle didn't cover all subsamples and then light each subsample individually.
MJP, Thanks for your answer. I'm trying to bind the buffer again as a depth buffer in another pass. I assume it's not possible to bind a ms depth buffer along with single sampled render targets at the same time. Is there any solution for that?
Yeah the number of MSAA samples needs to match for all render targets and depth-stencil buffers bound to the context at the same time. You'll need to create a non-MSAA depth-stencil buffer, and then perform a manual resolve using a pixel shader. Basically you just bind the non MSAA depth buffer as the depth-stencil buffer on the context and bind the MSAA depth buffer as a shader resource, and then render a full screen quad where the pixel shader samples one or more depth subsamples using a Texture2DMS and then writes out the resolved depth value to SV_Depth. To start out you can just sample and write out the 0th subsample, but you can also try experimenting with taking the min or max of all subsamples to get a more or less conservative bounds on the depth for a pixel.
That totally answered my question, thanks!

This topic is closed to new replies.

Advertisement