title: GLSL output corrupted when using layout image2D
body: <p>I am having a problem with corrupted OpenGL displays.  If I knew what caused it I could giver a better description, but here goes...</p>
  <p>I have a GLSL shader as follows that draws a square and then does a basic box blur over it.  This is the smallest example code I could make to show the problem.</p>
  <pre><code>#version 430
  
  uniform float time;
  uniform int frames;
  uniform vec2 resolution;
  
  const int image_width=960;
  const int image_height=540;
  
  layout (binding=1,r32f) uniform image2D layer1;
  
  int x_pixel,y_pixel,xp,yp,x_res,y_res,range,range_div;
  float layer1_result;
  
  //rectangular neighborhood blur
  float Rectangular_Neighborhood(int range) {
      float f=0.0;
      int range_div=(range*2+1)*(range*2+1);
      for (int y=y_pixel-range;y&lt;=y_pixel+range;y++) {
          for (int x=x_pixel-range;x&lt;=x_pixel+range;x++) {
              int xp=x;
              int yp=y;
              if (xp&lt;0) { xp=xp+x_res; }
              if (xp&gt;=x_res) { xp=xp-x_res; }
              if (yp&lt;0) { yp=yp+y_res; }
              if (yp&gt;=y_res) { yp=yp-y_res; }
              f+=imageLoad( layer1, ivec2(xp,yp) ).r;
          }
      }
      f=f/range_div;
      return f;
  }
  
  void main()
  {
      x_pixel=int(gl_FragCoord.x);
      y_pixel=int(gl_FragCoord.y);
      x_res=int(resolution.x);
      y_res=int(resolution.y);
      
      //initially draw the white square pixels
      if(time&lt;1.0) {
          vec4 col;
          if ((abs(x_res/2-x_pixel)&lt;100)&amp;&amp;(abs(y_res/2-y_pixel)&lt;100)) { col=vec4(1.0,1.0,1.0,1.0); } else { col=vec4(0.0,0.0,0.0,1.0); }
           imageStore( layer1, ivec2(gl_FragCoord.xy), vec4(col.r,0,0,1));
          gl_FragColor=col;
      } else {
          float f,r,g,b;
          //blur the pixels
          f=Rectangular_Neighborhood(3);
          
          //PROBLEM LINE
          //f=f+0.05; if (f&gt;1.0) { f=f-1.0; } if (f&lt;0.0) { f=f+1.0; }
          
          layer1_result=f;
      
          //SQUARE RENDERS FINE
          //layer1_result=imageLoad( layer1, ivec2(x_pixel,y_pixel) ).r;
          
          imageStore( layer1, ivec2(x_pixel,y_pixel), vec4(layer1_result,0,0,1));
  
          //display RGB values based on layer values
          r=layer1_result;
          g=layer1_result;
          b=layer1_result;
          
          //update display
          gl_FragColor=vec4(r,g,b,1.0);
      }
      
  }
  </code></pre>
  <p>When run, it generates a square for the first 2 seconds and then begins to blur it with a basic box blur.  This works as expected and gives an image like the following</p>
  <p><a href="https://ibb.co/y4C4pnT" rel="nofollow noreferrer">https://ibb.co/y4C4pnT</a></p>
  <p>The problem comes when I uncomment the line after //PROBLEM LINE that adds a small amount to the blur value.  This should just bump all values up, but it corrupts the image/array somehow.  Gives the following result</p>
  <p><a href="https://ibb.co/zJFtPyV" rel="nofollow noreferrer">https://ibb.co/zJFtPyV</a></p>
  <p>Just in case this is how I declare the layer1 image</p>
  <pre><code>  glGenTextures(1,@layer1);
    glBindTexture(GL_TEXTURE_2D,layer1);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, imwidth, imheight, 0, GL_RED, GL_FLOAT, nil);
    glBindImageTexture( 1,                  //unit
                        layer1,             //texture
                        0,                  //level
                        false,              //layered
                        0,                  //layer
                        GL_READ_WRITE,      //access
                        GL_R32F);           //format
  </code></pre>
  <p>I think what should happen is that while blurring the square and background should get evenly brighter until the pixels that pass pure white then get wrapped back to 0.  But it should not have these almost random like patterns and that diagonal line?</p>
  <p>I thought it may have been how I am passing the image data to and from the shader, but if I uncomment the line after //SQUARE RENDERS FINE then I get the square repeatedly rendering as expected without any corruption.</p>
  <p>Any ideas what I may be missing or doing wrong here?</p>