There are explicit rules in the OpenGL specification about invariance guarantees. For the purpose of this discussion, these rules boil down to the following.
Given a particular series of vertex processing shaders (VS, tessellation, and GS), there are some set of input values, uniforms, and the like which lead to the computation of the final
gl_Position value for the primitives in that process. If all of these values are binary identical (including the way the vertex format leads to any VS inputs), then you're guaranteed that
gl_Position will have binary identical values. And if two primitive of the same type have binary identical positions, the rasterizer is required to generate binary identical fragment positions.
And thus, no z-fighting.
Now, that's kind of restrictive, as it only works with the same shaders. You can use different shaders, so long as:
- all shaders involved get binary identical values on expressions leading to the computation of
- all shaders involved use the exact same expressions (and I mean exact;
a + b isn't the "same expression" as
b + a, no matter what mathematics says) to compute
gl_Position and any inter-shader in/out variables leading to its computation are qualified with the
invariant qualifier in all shaders. This tells the compiler not to optimize certain things away in expressions leading to the computation of such values.