Jump to content
  • Advertisement
Sign in to follow this  

[D3D12] Depth reading issue

This topic is 982 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 am reading hardware depth buffer from the pixel shader and all the values are always equal to 1.0 when I step through the shader with VS graphics debugger.


If I check binded depth SRV, it seems to be valid on  the screen shot https://www.dropbox.com/s/5sjugwbb6bgnd26/DepthScreenShot.png?dl=0


Also, I tried to output depth values to RTV from the pixel shader and check RTV content from VS graphics debugger. Again, everything is equal to 1.0.


The depth buffer is created with DXGI_FORMAT_R32_TYPELESS, depth SRV with DXGI_FORMAT_R32_FLOAT and DSV with DXGI_FORMAT_D32_FLOAT format.




I have also uploaded VS debugger capture in case you have a chance to check it. The issue occurs while executing the last command list before Present.




Edited by _void_

Share this post

Link to post
Share on other sites

I've had a look at the capture and I don't think you're doing anything wrong. I think you're probably just being misled by VSGD.


Firstly, it appears that VSGD is misleadingly rounding your depth pixels to "1" when all the depth values that aren't the clear value are between 0.9999339 and 0.99999 when you mouse over them and it displays them below the image. There's quite clearly a depth image in there as you can see the boxes and yet VSGD reports 1 for the depth of each pixel. Assume that's a bug for now and I'll report it.


Secondly, when you debug the pixel shader right now you'll be debugging pixel (0,0) whether you want to or not. Since pixel (0,0) is not on a part of the image rendered to by your geometry the depth actually is 1.0f in this area of the screen.


To verify that you can actually read the depth image correctly I edited your shader to grab the depth from pixel (160,160) and verified it was not 1:




With the following pixel shader I get this:

float hardwareDepth = DepthTexture.Load(int3(input.screenSpacePos.xy, 0)).r;
return (hardwareDepth > 0.99999);



In conclusion, there's nothing wrong with reading the texture.

Share this post

Link to post
Share on other sites
Sign in to follow this  

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