Image load/stores in primitive order

#1

Assume I render a trianguted mesh. My fragment shader does an atomic exchange operation like this:

float prevDepth = atomicExchange(someImage, fragCoord, currDepth);
 //doing something with prevDepth

The spec (https://vulkan.lunarg.com/doc/view/1.0.26.0/linux/vkspec.chunked/ch08s03.html) says:

The relative order of invocations of the same shader type are undefined. A store issued by a shader when working on primitive B might complete prior to a store for primitive A, even if primitive A is specified prior to primitive B. This applies even to fragment shaders; while fragment shader outputs are always written to the framebuffer in primitive order, stores executed by fragment shader invocations are not.

I, however, want to ensure that these exchanges are all done in primitive order. Every fragment only accesses a single pixel it’s rasterized on. Is there a way to guarantee such thing?

#2

Not without extensions. Specifically, VK_EXT_fragment_shader_interlock. This is not a particularly widely provided extension. AMD doesn’t support it at all (note that their OpenGL implementations don’t support the GL equivalent extension either), and even Intel support is somewhat sketchy.

#3

I’m OK with using extensions for it. However, if even AMD does not support it, it sounds a little sad.