Sign in to follow this  
kazemi

Resolving a Depth/Stencil buffer?

Recommended Posts

kazemi    126
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

Share this post


Link to post
Share on other sites
MJP    19754
[quote name='CodeLord' timestamp='1306288186' post='4815395']
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
[/quote]

DXGI_FORMAT_D24_UNORM_S8_UINT doesn't support MSAA resolve. [url="http://msdn.microsoft.com/en-us/library/ff471325%28v=vs.85%29.aspx"]This chart[/url] 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.

Share this post


Link to post
Share on other sites
kazemi    126
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?

Share this post


Link to post
Share on other sites
MJP    19754
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this