Depth (Z) and stencil (S) testing

Depth (Z) and stencil (S) testing discards pixels that are hidden by other objects or stencil masks. There are two stages in the pixel processing pipeline, where this can happen. Early ZS testing takes place before fragment shading, and late ZS testing takes place after fragment shading.

Mali pixel processing pipeline

Early ZS test

Early ZS testing is relatively inexpensive, because it happens before any pixels are colored in by fragment shading. To get the benefit of early ZS, your application must pass in geometry in a front-to-back render order, starting at the point closest to the camera and moving further away. Use the Mali Early ZS Rate chart in Streamline to check how much work is culled by early ZS testing.

If your application must pass in geometry in a back-to-front order, early ZS testing can not be used. However, Mali GPUs can use hidden surface removal, also known as forward pixel kill (FPK), to stop rendering of objects that are behind other opaque objects. However, this still has a cost, so try to avoid relying on this optimization if you are able to take advantage of early ZS testing.

Late ZS test

The late ZS test handles any work that couldn’t  be processed before fragment shading. For example, if a shader programmatically modifies gl_FragDepth, early ZS testing cannot be used, and late ZS testing is forced. Late ZS testing happens after all the fragment shading work has been done, therefore it is expensive and should be avoided. Use the Mali Late ZS Rate chart in Streamline to check how much work is culled by late ZS testing. 

Tip: If shader programs modify their coverage mask, for example, by using a discard statement, or by using alpha-to-coverage, they must use a late ZS update. Similarly, if fragment shaders write to gl_FragDepth, the depth value cannot be known early, and the fragment will be forced to late-ZS test and update. You can check the behavior of your shader programs using Mali Offline Compiler, which reports whether your shader program uses a late ZS test and update.
Previous Next