title: Reading texture data with glGetTexImage after writing from compute shader with imageStore
body: <p>I'm generating noise into 3D texture in compute shader and then building mesh out of it on CPU. It works fine when I do that in the main loop, but I noticed that I'm only getting ~1% of noise filled on the first render. Here is minimal example, where I'm trying to fill 3D texture with ones in shader, but getting zeroes or noise in return:</p>
  <pre><code>#include &lt;glad/glad.h&gt;
  #include &lt;GLFW/glfw3.h&gt;
  
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void error(const char* message) { ... }
  
  const char* slurp_file(const char* filename) { ... }
  
  int main() {
    glfwInit();
  
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  
    GLFWwindow* window = glfwCreateWindow(100, 100, &quot;&quot;, NULL, NULL);
    glfwMakeContextCurrent(window);
    gladLoadGL();
    
    // create texture
    GLuint texture;
    glGenTextures(1, &amp;texture);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_3D, texture);
  
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
  
    // allocate it
    size_t size = 4;
    glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, size, size, size, 0, GL_RED, GL_FLOAT, NULL);
  
    // create shader
    const char* shader_source = slurp_file(&quot;shaders/example.comp&quot;);
    GLuint shader = glCreateShader(GL_COMPUTE_SHADER);
    glShaderSource(shader, 1, &amp;shader_source, NULL);
    glCompileShader(shader);
  
    // check it
    int code;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &amp;code);
    if (!code) error(&quot;shader compilation failed&quot;);
  
    // create program
    int program = glCreateProgram();
    glAttachShader(program, shader);
    glLinkProgram(program);
  
    // check it
    glGetProgramiv(program, GL_LINK_STATUS, &amp;code);
    if (!code) error(&quot;program linkage failed&quot;);
  
    // run shader
    glUseProgram(program);
    // i don't think it's needed, as 0 would be a default value
    int uniform_loc = glGetUniformLocation(program, &quot;img_output&quot;);
    glUniform1i(uniform_loc, 0);
  
    // dispatch and sync
    glDispatchCompute(size, size, size);
    // originally i had GL_TEXTURE_FETCH_BARRIER_BIT here
    glMemoryBarrier(GL_ALL_BARRIER_BITS);
  
    // read texture data
    float* data = malloc(size * size * size * sizeof(float));
    glBindImageTexture(0, texture, 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32F);
    glGetTexImage(GL_TEXTURE_3D, 0, GL_RED, GL_FLOAT, data);
  
    // prints 0s or noise, but i expect all 1s
    for (int i = 0; i &lt; size * size * size; i++)
      printf(&quot;%f &quot;, data[i]);
  }
  </code></pre>
  <p>Here is the shader:</p>
  <pre><code>#version 430
  
  layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
  layout(binding = 0, r32f) writeonly uniform image3D img_output;
  
  void main() {
    ivec3 texture_coords = ivec3(gl_GlobalInvocationID.xyz);
  
    vec4  pixel = vec4(1, 0, 0, 0);
  
    imageStore(img_output, texture_coords, pixel);
  }
  </code></pre>
  <p>Just adding sleep after <code>glDispatchCompute</code> does nothing, so I think I'm missing some locking? Or maybe texture should be configured in some other way?</p>