You copied the Doc URL to your clipboard.

Using Early-z

Mali™ GPUs include the ability to do an Early-Z algorithm. Early-Z improves performance by removing overdrawn fragments.

The Mali GPU typically executes the Early-Z algorithm on most content, but there are cases where, to preserve correctness, it is not executed. This can be difficult to control from within Unity because it depends on both the Unity engine and the code generated by the compiler, however there are some signs you can look for.

Compile your shader for mobile and have a look at the code. Ensure your shader does not fall into one of the following categories:

Shader has side effects
This means a shader thread modifies global state during its execution, so executing the shader a second time might produce different results. Typically this means that your shader writes to a shared read/write memory buffer such as shader storage buffer objects or images. For example, if you create a shader that increments a counter to measure performance, this shader has side effects.
The following are not classed as side effects:
  • Read-only memory accesses.

  • Writes to write-only buffers.

  • Purely local memory accesses.

Shader calls discard()
If the fragment shader can call discard() during its execution, the Mali GPU cannot enable Early-Z. This is because the fragment shader can discard the current fragment, but the depth value was previously modified by the Early-Z test and this cannot be reverted.
Alpha-to-coverage is enabled
If Alpha-to-coverage is enabled, the fragment shader computes data that is later accessed to define the alpha.
For example, when rendering the leaves of a tree, they are typically represented as a plane and the texture defines what region of the leaf that is transparent or opaque. If early-z is enabled you get incorrect results because part of the scene can be occluded by a transparent part of the plane.
Depth source not fixed function
The depth value used for depth testing does not come from the vertex shader. If your fragment shader writes to gl_FragDepth, the Mali GPU cannot perform the Early-Z test.
Was this page helpful? Yes No