v154 · frag_depth modifiers

The three shader forms

The same shader written three ways. If this machine has a GPU the demo compiles each one and shows the WGSL compiler's own diagnostics; if it does not, it says so rather than inventing a verdict.

Compile all three

Press Compile.

What each modifier promises

The invariant you are taking responsibility for
formthe promiseearly-Zif you break it
no modifiernonedisabled for the draw callnothing to break
greaterthe written depth is never nearer than the interpolated onekept — a fragment already behind stays behindundefined results, not an error
lessthe written depth is never further than the interpolated onekept, for the reversed-depth setupundefined results, not an error

Nothing checks the promise at runtime — that is the trade. You get the optimisation because the hardware trusts you, and a shader that lies produces artefacts that will not reproduce on the machine you debug on. Use the modifier when the maths guarantees the direction, not when it usually holds.

see also