Debugging the stencil buffer

Started by
5 comments, last by menohack 10 years, 9 months ago

Is it possible to display the stencil buffer as a texture? The only formats available to a shader resource view are DXGI_FORMAT_R24_UNORM_X8_TYPELESS and DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS. When I try to draw this as a quad I only seem to have access to the x or r component, which is the depth.

Thanks!

Advertisement

It depends on which format you used to create the depth buffer. If you used DXGI_FORMAT_R24G8_TYPELESS, then use DXGI_FORMAT_X24_TYPELESS_G8_UINT to create your SRV and then access the G channel in your shader. If you used DXGI_FORMAT_R32G8X24_TYPELESS, then do the same with DXGI_FORMAT_X32_TYPELESS_G8X24_UINT.

In your shader, make sure that you declare your texture as Texture2D<uint2>. You'll then get an integer that's [0, 255], which you can convert to a [0,1] float for displaying.

Exactly what I needed. Thank you very much!

The other way of doing this is to turn color writes back on and stencil writes off for the objects you are rendering to the stencil, they will then appear on screen. This is easier then rendering to a render target and then displaying that if all you need to do is debugging.

I used this a lot during the development of DiRT3 where we were using a lot of stencil animations to do certain transitions, because of how our renderer worked. This is a renderstate change as well no need for an additional shader or texture.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

nividia's NSight can display the stencil buffer for you. Great tool for debugging this kind of thing.

So can AMDs gDEBugger and GPU PerfStudio 2

gDEBugger is GL only and PerStudio is when you have a AMD card instead of an NVidia one (NSight only supports NVidia GPUs).

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Just for future reference: I believe that the Shader Debugger in Visual Studio 2012 can also check the stencil buffer.

This topic is closed to new replies.

Advertisement