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.

Fragment shader invocations per frame
shaderearly-Zinvocationsshader opsvs best case

Where the depth test happens

Early-Z kept

  1. rasterise the triangle
  2. depth test — reject what is already hidden
  3. run the fragment shader on survivors
  4. write colour and depth

Early-Z disabled

  1. rasterise the triangle
  2. depth test — cannot run yet, the shader may change the depth
  3. run the fragment shader on everything
  4. depth test, then write colour and depth

see also