I'm doing depth peeling with a very simple fragment function:
struct VertexOut {
float4 position [[ position ]];
};
fragment void depthPeelFragment(VertexOut in [[ stage_in ]],
depth2d<float, access::read=""> previousDepth)
{
float4 p = in.position;
if(!is_null_texture(previousDepth) && p.z <= previousDepth.read(uint2(p.xy)))
{
discard_fragment();
}
}
(My depth buffer pixel format is `MTLPixelFormatDepth32Float`)
This works well on my Mac. In each pass I submit the same geometry, and eventually no more fragments are written and the process terminates. For example, with a test sphere, there are two passes with the same number of fragments written each pass (front and back hemispheres).
However on iPad, the process does not terminate. There are some (not all) fragments which, despite being rendered in the previous pass, are not discarded in subsequent passes.
What platform differences could cause this?
Is the z-coordinate of the position attribute always the value written to the depth buffer?
Note that I cannot simply limit the number of passes (I'm not using this for OIT).