Sign in to follow this  
Corefanatic

Depth Buffer questions

Recommended Posts

Corefanatic    176
Hi all,
I have been programming graphics for some time now, and recently a few questions started bugging me at the back of my mind:

1) When does the depth comparison for each fragment occur (in order for it to be potentially rejected)? Before or after it's value is calculated?

2)I know different vendors have different tech for early z rejection, but can't find any recent documents on how the trigger them and general good practice guides. Anyone good place to start?

3)Is it still beneficial to render opaque geometry from front to back?

I think that's all for now, hopefully your answers will fill a few holes in my knowledge :)

Share this post


Link to post
Share on other sites
MJP    19754
1. In most cases it will actually happen before the pixel shader is executed, so that the hardware can skip shading pixels that fail the depth or stencil test.

2. Unfortunately the exact details aren't public. However I can tell you that the hardware for early Z detection has defintiely become more sophisticated over the years. Older hardware (up to and including DX9-era hardware) only used coarse-grained rejection through the use of a hierarchical Z/stencil buffer. Basically the hardware would keep track of the min and max depth values among a screen-space "tile" (rectangular group of pixels), and use that to determine if a fragment could be conservatively accepted or rejected based on those min/max values. This meant that the test could fail to reject occluded pixel in scenarios involving overly complex geometry, and it was also really easy to do things that would cause the early Z test to be disabled. For instance using alpha test, or switching the depth testing direction mid-frame. In DX10+ hardware the early-z units are more flexible, and a generally capable of providing some sort of early z test for all situations (including a fine-grained Z/stencil test). The one exception is outputting a depth value from the pixel shader, since it's imposible to perform the depth test when the depth value hasn't been generated yet. DX11 did add support for putting an upper or lower bound on the SV_Depth output, which does allow a fragment to be conservatively rejected in some cases.

Nvidia does have some information [url="http://developer.download.nvidia.com/GPU_Programming_Guide/GPU_Programming_Guide_G80.pdf"]here[/url] from the G80 era, which is probably somewhat out-of-date. I'm not aware of AMD/ATI having anything recent to look at, although they may have mentioned something in one of their many GDC presentations.

3. It depends on your scene complexity, how well you sort, the granularity of draw calls in your scene, whether or not you're CPU or GPU-bound, whether you get more benefit from sorting to avoid state changes, etc. If your pixel shader is heavy then you may be better off just doing an z-only prepass, so that you only shade visible pixels. A z-only pass can be pretty cheap.

Share this post


Link to post
Share on other sites
Corefanatic    176
Thx MJP, definitely clears up things.

About z-only pre-pass, I've read somewhere that GPUs support mode for doing this extremely fast, ie. skipping though most of the pipeline except for the vertex shader of course. Is there a way to manually set this up in DX11 on latest Nvidia GPUs?

Share this post


Link to post
Share on other sites
kauna    2922
[quote name='Corefanatic' timestamp='1329809874' post='4915106']
About z-only pre-pass, I've read somewhere that GPUs support mode for doing this extremely fast, ie. skipping though most of the pipeline except for the vertex shader of course. Is there a way to manually set this up in DX11 on latest Nvidia GPUs?
[/quote]

As far as I know, simply use OMSetRenderTargets to bind only a depthstencil view (and no render targets). For opaque geometry you should set the pixel shader to null.

Cheers!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this