In short, Metal will incorrectly discard fragments with side effects under certain circumstances prematurely even when the side effect takes place before discard. The conditions are the following:
Fragment will always be discarded
Pre fragment depth fails fails
Modifies depth value for a constant value in the fragment shader. This constant value will also fail the depth test.
To circumvent this issue, we need to trick Metal into thinking that not all fragment executions may be discarded
Details can be found here: https://github.com/KhronosGroup/MoltenVK/issues/2233
In short, Metal will incorrectly discard fragments with side effects under certain circumstances prematurely even when the side effect takes place before discard. The conditions are the following:
To circumvent this issue, we need to trick Metal into thinking that not all fragment executions may be discarded