Jump to content
  • Advertisement
AleksBak

DX11 Resolve a Depth/Stencil buffer

This topic is 436 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to resolve the depth buffer texture. This depth/stencil buffer (ID3D11DepthStencilView*) I get every frame with such parameters (from it's desc):

SampleDesc.Count = 2;

SampleDesc.Quality = 0;

ArraySize = 1;

Format = DXGI_FORMAT_R24G8_TYPELESS;

And I need a simple non-MSAA depth buffer in the end. For use it with non-MSAA RenderTarget (I already have it). As I understand, I can not do this with hardware conversion - with DeviceContext->ResolveSubresource(...). It is possible to do this through a pixel shader. (?) But I still do not understand how to do it. If anyone has a solution to this problem(resolve depth texture) through a pixel shader please show it.  Thank.

Edited by AleksBak

Share this post


Link to post
Share on other sites
Advertisement

You can create an SRV over your Depth/Stencil buffer using the format DXGI_FORMAT_R24_UNORM_X8_TYPELESS.

In HLSL you can then declare a:

Texture2DMS<float> depthBuffer;

And read the two samples using ".Load(coord, 0);" and ".Load(coord, 1);".

Share this post


Link to post
Share on other sites

You can resolve it and keep using it as a depth buffer if you do the resolve in a pixel shader. Do a full screen pass, read your samples of the shader resource view of your MSAA depth buffer with Texture2DMS.Load(). The last argument of the Load is the sample index, as mentioned in the above answer.

Now, you probably want to take either the max or the min of the loaded samples. Output the final value as a depth export instead of color write. For that, you should declare your pixel shader output with the SV_Depth semantic instead of SV_Target.

On the C++ API side, you want to turn off your depth testing but depth writing should be ON. For that, you should create a depth stencil state object with a descriptor like this:

D3D11_DEPTH_STENCIL_DESC dsd;
dsd.DepthEnable = true;
dsd.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
dsd.DepthFunc = D3D11_COMPARISON_ALWAYS;
dsd.StencilEnable = false;

 

Edited by turanszkij
removed false information

Share this post


Link to post
Share on other sites

Many thanks for the clarifications! I unfortunately never worked with the depth buffer in the shader. Only connected it to the output marge and that's it. And now I will try. So far, I do not quite understand how, but it is necessary. Thank you!

Share this post


Link to post
Share on other sites

What do you want as a result?

Averaging multiple depth values together (which is what a default resolve filter will do) just gives you a nonsense result.
You could take the minimum, maximum, median or modal depth, which may be better, depending on what you want to achieve...

Share this post


Link to post
Share on other sites
2 hours ago, Hodgman said:

What do you want as a result? ...

I just need a ready non-MSAA depth buffer. Then use it for proper rendering with non-MSAA RenderTaget (I also get it in this form!! It's non MSAA!!!! But depth buffer is MSAA as I said!! Such an outrage is happening! And no one to complain. ) . This depth buffer is given to me in this (MSAA) form - I can not change anything in the code where it comes out. I'm adding rendering a 3D model to the finished project. 

And thanks for taking a look!
 
 
 
 
30/5000
 
 
Edited by AleksBak

Share this post


Link to post
Share on other sites

I do not understand after all how the MSAA works. Could not we just disable it somehow in the texture? Or get a pointer to some basic texture? I do not understand yet. Excuse me.

Share this post


Link to post
Share on other sites

  • 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!