Jump to content
  • Advertisement
ErnieDingo

DX11 Resolving MSAA - Depth Buffer to Non MSAA

Recommended Posts

HI, 

I'm doing a final pass on my water rendering, as such, I would like to be able to reference a copy of the depth buffer to understand how deep the water is at a point based upon the water pixels Z and the Depth of the Z value.  Im doing some water depth related effects, therefore sampling the Z Depth.

I have a few ideas on how to solve this.  The simplest I believe is not possible, so it leaves me with a couple of options.

1 - ResolveSubresource from a MSAS Depth buffer to a non MSAA Depth buffer (believe this is not possible as resolving from a depth buffer with depth stencil flag set).

2 - I just copy the depth resource as a MSAA Depth buffer to a MSAA Depth buffer. Then Use Load to sample in the shader for the depth.  Slower, but should work.

3 - Render the MSAA Depth buffer using a full screen quad to another target which is a non MSAA SRV.

4 - Consider this is a transparency pass, I probably could use the depth buffer unbound from rendertarget and use as a SRV and use Load to sample from it (no need to copy at all).

2 or 4 seem to be the go.  I believe 4 would be best of all the options.  and should be the fastest option.

Comments.  Am I missing something here?

Cheers

Share this post


Link to post
Share on other sites
Advertisement

ResolveSubresource unfortunately doesn't work for depth buffers. If you want to do it, you need to do it manually with a pixel shader that outputs to SV_Depth.  You also probably wouldn't want the average of the sub-pixel depth values, since this wouldn't make much sense.

Anyway, you don't need to copy the depth resource to do #2, as long as you're not writing to the depth buffer during your water pass. If you create a read-only depth-stencil view, then you can read from it using an SRV while the DSV is still bound to the pipeline.

Share this post


Link to post
Share on other sites

I'm thinking i should do as you mentioned, which is to target a 2nd non msaa depth buffer.

My question is whether i render the entire scene again but depth only or render including scene.  Rather than resolve the msaa buffer.  I'm thinking the former is best. 

Share this post


Link to post
Share on other sites
20 hours ago, ErnieDingo said:

2 - I just copy the depth resource as a MSAA Depth buffer to a MSAA Depth buffer. Then Use Load to sample in the shader for the depth.  Slower, but should work.

In my experience sampling from an MSAA surface can be very slow if your sampling pattern is too random (i.e. I attempted this at SSAO and SSR, didn't go well). I'm not sure why, whether it's because of cache effects or the GPU simply not being fast at it. But likely for your scenario that's not a problem.

 

20 hours ago, ErnieDingo said:

3 - Render the MSAA Depth buffer using a full screen quad to another target which is a non MSAA SRV.

If you're doing this approach using a regular colour buffer (instead of a depth buffer) would be better. Depth buffers have additional baggage you don't need (Z compression, early Z) and will only waste you memory and cycles.

Btw if you're going to be resolving the MSAA surface, remember an average of Z values isn't always the best idea.

20 hours ago, ErnieDingo said:

4 - Consider this is a transparency pass, I probably could use the depth buffer unbound from rendertarget and use as a SRV and use Load to sample from it (no need to copy at all).

That won't work because the water still needs the depth buffer to avoid being rendering on top of opaque objects that should be obstructing the water.

However as MJP pointed out, you can have the depth buffer bound and sample from it at the same time as long as it's marked read-only (IIRC only works on D3D10.1 HW onwards).

This is probably the best option if all you'll be doing is measuring the depth of the ocean at the given pixel.

 

Cheers

Share this post


Link to post
Share on other sites

 Thinking now a depth only render pass to a non msaa depth buffer is my only real option.  Which means rendering the scene again sans water. 

Need to balance this against the performance hit of sampling from a msaa based buffer.   Performance hit is more consistent than the increasing hit of higher and higher msaa levels

Edited by ErnieDingo

Share this post


Link to post
Share on other sites

Scratch that. I had a revelation.

I'm currently rendering to a non msaa buffer for my shadow depth buffer.  I should add a 2nd depth target to render to.  As the first is orthagonal for shadow.  I could also render a projective version to a 2nd depth buffer. 

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!