5 GL_ARB_shader_atomic_counters
9 #extension GL_ARB_compute_shader: require
10 #extension GL_ARB_shader_atomic_counters: require
12 layout(local_size_x = 32) in;
17 layout(binding = 0) uniform atomic_uint pass;
18 layout(binding = 0) uniform atomic_uint fail;
22 if (gl_LocalInvocationIndex == 0u) {
23 /* Bootstrapping this with zero is unavoidable, bit it
24 * also causes problems later. Namely it means that
25 * bit 0 will get set twice and invocation 0 can see a
26 * zero value. Note the explicit checks for bit != 0
27 * and gl_LocalInvocationIndex != 0 below.
35 int f = atomicExchange(value, 2 * int(gl_LocalInvocationIndex));
36 uint i = uint(f) / 2u;
41 /* If the bit was already set, the test fails. */
42 uint r = atomicOr(mask, m);
43 if (bit != 0u && (r & m) != 0u)
44 atomicCounterIncrement(fail);
46 /* Invocation index 0 can read it's own index (due to
47 * bootstrapping with zero), but no other invocation should.
49 if (gl_LocalInvocationIndex != 0u &&
50 bit == gl_LocalInvocationIndex)
51 atomicCounterIncrement(fail);
53 atomicCounterIncrement(fail);
58 if (gl_LocalInvocationIndex == 0u) {
59 uint i = uint(value / 2);
63 uint final = m | mask;
65 /* If all 32 bits are set, the test passes. */
66 if (final == 0xffffffffu)
67 atomicCounterIncrement(pass);
74 probe atomic counter 0 == 24
75 probe atomic counter 1 == 0