GLSL_Thing.tox (950 Bytes)
I have a glsl compute shader with two atomic counters, and I increment them both one after the other.
For debugging I have set the shader to output the difference between the counters. I would expect this to be all black, as each counter should have the same value, but this is not the case. I see red stripes. I have observed that the width of the red stripes is the same as local_size, and also the difference in values occurs in multiples of local_size as well. I’m probably just misunderstanding how atomic counters are supposed to work but i can’t figure out why this is happening. Any ideas? See attached file
layout (binding = 0) uniform atomic_uint incounter;
layout (binding = 0) uniform atomic_uint outcounter;
layout (local_size_x = 16, local_size_y = 1) in;
void main()
{
ivec2 mycoord = ivec2(gl_GlobalInvocationID.xy);
uint inc = atomicCounterIncrement(incounter);
uint outc= atomicCounterIncrement(outcounter);
imageStore(mTDComputeOutputs[0], mycoord, TDOutputSwizzle(vec4(float(inc)-float(outc),0.0,0.0,1.0)));
}