Advertisement

Resolving MSAA - Depth Buffer to Non MSAA

Started by December 24, 2017 08:09 AM
5 comments, last by ErnieDingo 7 years, 1 month ago

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

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

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.

Advertisement

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. 

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

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

 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

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

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. 

Indie game developer - Game WIP

Strafe (Working Title) - Currently in need of another developer and modeler/graphic artist (professional & amateur's artists welcome)

Insane Software Facebook

This topic is closed to new replies.

Advertisement