title: Issue with simple atomic counter test in OpenGL compute shader
body: <p>I've been trying to wrap my head around memory synchronization and coherency by trying trivial examples.</p>
  
  <p>In this, I'm dispatching a compute shader with 8x8x1 size work groups. The number of work groups is sufficient to cover the screen, which is 720x480.</p>
  
  <p>Compute shader code:</p>
  
  <pre><code>#version 450 core
  
  layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
  
  layout (binding = 0, rgba8) uniform image2D u_fboImg;
  
  layout (binding = 0, offset = 0) uniform atomic_uint u_counters[100];
  
  void main() {
      ivec2 texCoord = ivec2(gl_GlobalInvocationID.xy);
  
      // Only use shader invocations within first 100x500 pixels
      if (texCoord.x &gt;= 100 || texCoord.y &gt;= 500) {
          return;
      }
  
      // Each counter should be incremented 400 times
      atomicCounterIncrement(u_counters[texCoord.x]);
  
      memoryBarrier();
  
      // Use only "bottom row" of invocations to draw results
      // Draw a white column as high as the counter at given x
      if (texCoord.y == 0) {
          int c = int(atomicCounter(u_counters[texCoord.x]));
          for (int y = 0; y &lt; c; ++y) {
              imageStore(u_fboImg, ivec2(texCoord.x, y), vec4(1.0f));
          }
      }
  }
  </code></pre>
  
  <p>This is what I get: (The heights of the jagged bars are different each time, but on average about that height)</p>
  
  <p><a href="https://i.stack.imgur.com/KLzq1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KLzq1.png" alt="enter image description here"></a></p>
  
  <p>This is what I would expect, and is the result of hard coding the for loop to go to 400.</p>
  
  <p><a href="https://i.stack.imgur.com/uVFko.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uVFko.png" alt="enter image description here"></a></p>
  
  <p>Strangely enough, if I decrease the number of work groups in the dispatch, say by halving the x value (would now only cover half the screen), the bars get bigger:</p>
  
  <p><a href="https://i.stack.imgur.com/gEZUF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gEZUF.png" alt="enter image description here"></a></p>
  
  <p>Finally to prove there isn't some other nonsense going on, here i'm just coloring based on local invocation id:</p>
  
  <p><a href="https://i.stack.imgur.com/lVsSj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lVsSj.png" alt="enter image description here"></a></p>
  
  <p>*Edit: Forgot to mention the dispatch is followed immediately by <code>glMemoryBarrier(GL_ALL_BARRIER_BITS);</code></p>