1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
[require]
GL >= 3.3
GLSL >= 3.30
GL_ARB_compute_shader
GL_ARB_shader_atomic_counters
GL_NV_shader_atomic_float
[compute shader]
#version 330
#extension GL_ARB_compute_shader: require
#extension GL_ARB_shader_atomic_counters: require
#extension GL_NV_shader_atomic_float: require
layout(local_size_x = 32) in;
shared float value;
shared uint mask;
layout(binding = 0) uniform atomic_uint pass;
layout(binding = 0) uniform atomic_uint fail;
void main()
{
if (gl_LocalInvocationIndex == 0u) {
value = 0.0;
mask = 0u;
}
barrier();
/* Each local invocation should see a unique value. Each value
* observed is tracked in "mask." The test automatically fails if a
* duplicate value is observed. The test passes once all 32 possible
* values have been observed.
*/
float f = atomicAdd(value, .5);
uint i = uint(f * 2.0);
uint bit = i % 32u;
uint m = 1u << bit;
if (i < 32u) {
/* If the bit was already set, the test fails. */
uint r = atomicOr(mask, m);
if ((r & m) != 0u)
atomicCounterIncrement(fail);
/* Once all 32 bits are set, the test passes. */
if ((r | m) == 0xffffffffu)
atomicCounterIncrement(pass);
} else {
atomicCounterIncrement(fail);
}
}
[test]
atomic counters 2
compute 2 3 4
probe atomic counter 0 == 24
probe atomic counter 1 == 0
|