I am trying to implement a depth peel algorithm using integer textures for shader mutexes. As suggested in this question, I suspect one can use imageAtomicCompSwap(...).
Looking in the documentation for that function, and selecting the overload for an unsigned integer:
uint imageAtomicCompSwap(gimage2D image, ivec2 P, uint data);
However, it's unclear how this can be used. The documentation reads:
imageAtomicCompSwap atomically compares the value of data with that of the texel at coordinate P . . . . If the values are equal, data is stored into the texel, otherwise it is discarded. It returns the new value of the texel.
This sounds to me like the function compares the data to the already existing value in the texel. If the values are equal, effectively nothing happens ("data is stored into the texel", but they compared equal so there's no change). If the values are unequal, nothing happens ("otherwise it is discarded"). The function then returns the new value of the texel (which, because nothing happened either way, is just the original value of the texel to begin with). Clearly I am missing something.
Complicating matters, I also haven't been able to get this function to even show up. Writing:
//img2D_0 is declared "layout(r32ui) coherent restrict uniform uimage2D img2D_0"
imageAtomicCompSwap(img2D_0,coord,1u);
. . . gives:
0(14) : error C1115: unable to find compatible overloaded function "imageAtomicCompSwap(struct uimage2D1x32, ivec2, uint)"
It's worth mentioning that if I pass two numbers:
imageAtomicCompSwap(img2D_0,coord,1u,1u);
It compiles fine--I understand this should only work for multisampling, though; did I somehow declare a multisampled image? So, A: what does the documentation mean, B: why doesn't the function I need work? I'm confused.