Resolve a Depth/Stencil buffer

Started by
7 comments, last by AleksBak 6 years, 7 months ago

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.

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);".

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

I'll try. I really do not know yet in which way, but I'll try.

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;

 

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!

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...

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
 
 

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.

This topic is closed to new replies.

Advertisement