which step come first? z-test or "pixel shader program" evaluation ?

Started by
6 comments, last by Hodgman 12 years, 6 months ago
hi,all. i have a question that if z-test failed, will the "pixel shader program" evaluate or not? in other words, which step come first? z-test or "pixel shader program" evaluation ?
thanks for your reply.:)
Advertisement
it seems that z-test come first can avoid unnecessary pixel shader evaluation.:unsure:
Hello smile.gifIndeed the depth test is performed before invoking the pixel shader (if the depth test fails, the pixel shader isn't invoked)
It isn't quite as easy as that.

The pipeline specifies that the z test is performed AFTER the pixel shader is executed, however most hardware has 'early z rejection' ability which allows it to perform the z test before the pixel shader is run but only if the z position of pixel/fragment isn't changed during execution. If you have a shader which changes the z position of the pixel/fragment then it will run before the z-test.

It isn't quite as easy as that.

The pipeline specifies that the z test is performed AFTER the pixel shader is executed, however most hardware has 'early z rejection' ability which allows it to perform the z test before the pixel shader is run but only if the z position of pixel/fragment isn't changed during execution. If you have a shader which changes the z position of the pixel/fragment then it will run before the z-test.


thanks for your reply, Is the early-z default if I didn't change the z-value ? OR: I need to explicitly tell the hardware do early-z.
Thank you phantom for your explanation
Early z is on by default. But if you use an unordered acces view in the pixel shader then the pixel wont be clipped at all if i remember correctly so you have to write something like [earlydepthstencil] before the shader entry point
If you search for something like "nvidia GPU programming guide" you can find the advice from each GPU manufacturer regarding early-z (AKA, Hi-Z, ZCull, etc) for different generations of GPUs.

The main rules of thumb are -
-- clear your depth buffer every frame.
-- do not change the direction of the z-test (e.g. going from a greater-than test to less-than test) within a frame.
-- shaders that output modified depth values are the enemy of Hi-Z (unless using DX11 conservative depth writes).
-- shaders that perform clipping/alpha-testing will not contribute to the Hi-Z buffer.

This topic is closed to new replies.

Advertisement