1 # Verify simple sampling of a texture with output to an atomic counter
7 GL_ARB_shader_atomic_counters
11 #extension GL_ARB_compute_shader: enable
12 #extension GL_ARB_shader_atomic_counters: require
14 layout(binding = 0) uniform atomic_uint r;
15 layout(binding = 0) uniform atomic_uint g;
16 layout(binding = 0) uniform atomic_uint b;
17 layout(binding = 0) uniform atomic_uint w;
19 uniform sampler2D tex;
21 layout(local_size_x = 1, local_size_y = 1) in;
24 #define HALF_SIZE (SIZE / 2u)
25 #define RED vec3(1, 0, 0)
26 #define GREEN vec3(0, 1, 0)
27 #define BLUE vec3(0, 0, 1)
28 #define WHITE vec3(1, 1, 1)
32 for (uint y = 0u; y < SIZE; y++) {
33 for (uint x = 0u; x < SIZE; x++) {
34 ivec2 coord = ivec2(x, y);
35 vec3 color = texelFetch(tex, coord, 0).rgb;
37 if (color == RED && x < HALF_SIZE && y < HALF_SIZE) {
38 atomicCounterIncrement(r);
39 } else if (color == GREEN && x >= HALF_SIZE && y < HALF_SIZE) {
40 atomicCounterIncrement(g);
41 } else if (color == BLUE && x < HALF_SIZE && y >= HALF_SIZE) {
42 atomicCounterIncrement(b);
43 } else if (color == WHITE && x >= HALF_SIZE && y >= HALF_SIZE) {
44 atomicCounterIncrement(w);
52 texture rgbw 0 (64, 64)
54 image texture 0 GL_RGBA8
59 probe atomic counter 0 == 1024
60 probe atomic counter 1 == 1024
61 probe atomic counter 2 == 1024
62 probe atomic counter 3 == 1024