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 60 61 62 63
|
[require]
GL >= 3.3
GLSL >= 3.30
GL_ARB_shader_storage_buffer_object
GL_ARB_shader_atomic_counters
GL_ARB_shader_atomic_counter_ops
GL_INTEL_shader_atomic_float_minmax
[vertex shader passthrough]
[fragment shader]
#extension GL_ARB_shader_storage_buffer_object: require
#extension GL_ARB_shader_atomic_counters: require
#extension GL_ARB_shader_atomic_counter_ops: require
#extension GL_INTEL_shader_atomic_float_minmax: require
layout(binding = 0, std430) buffer bufblock {
float value[8];
};
/* +0.0 and -0.0 stored as bits. Storing these in a uniform and converting
* them to float using uintBitsToFloat should prevent the compiler from
* silently dropping the sign bit.
*/
uniform uint zeros[] = uint[](0x00000000u, 0x80000000u);
layout(binding = 0) uniform atomic_uint pass;
out vec4 color;
void main()
{
uint idx = uint(gl_FragCoord.x + gl_FragCoord.y) % uint(value.length());
float v = uintBitsToFloat(zeros[idx & 1u]);
float f = atomicCompSwap(value[idx], v, 47.0 + float(idx));
if (f == 0.0) {
atomicCounterIncrement(pass);
color = vec4(0.0, 1.0, 0.0, 1.0);
} else {
color = vec4(0.0, 0.0, 1.0, 1.0);
}
}
[test]
atomic counters 1
ssbo 0 32
ssbo 0 subdata int 0 0x80000000
ssbo 0 subdata int 4 0x00000000
ssbo 0 subdata int 8 0x80000000
ssbo 0 subdata int 12 0x00000000
ssbo 0 subdata int 16 0x80000000
ssbo 0 subdata int 20 0x00000000
ssbo 0 subdata int 24 0x80000000
ssbo 0 subdata int 28 0x00000000
clear color 0.5 0.5 0.5 0.5
clear
draw rect -1 -1 2 2
probe atomic counter 0 == 8
|