v154 · frag_depth modifiers
Why early-Z matters
Early depth testing is worth a lot and costs nothing — until a shader writes depth, at which point the driver turns it off for the whole draw call. This models the arithmetic: how many fragment shader invocations you run with it, without it, and with the modifier that gets it back.
Model a draw call
Depth complexity is how many surfaces cover the average pixel. Front-to-back order is what makes early-Z effective: each surface rejects the ones behind it, so the first one shades and the rest are discarded before the shader runs. Back to front, nothing can be rejected and the optimisation is worth almost nothing — which is a fact about your renderer, not about the modifier.
| shader | early-Z | invocations | shader ops | vs best case |
|---|
Where the depth test happens
Early-Z kept
- rasterise the triangle
- depth test — reject what is already hidden
- run the fragment shader on survivors
- write colour and depth
Early-Z disabled
- rasterise the triangle
- depth test — cannot run yet, the shader may change the depth
- run the fragment shader on everything
- depth test, then write colour and depth