Controling access to SSBO in fragment shader


I’m working with per-pixel data in fragment shader. The result is written into SSBO but it seems that fragment shader is being called multiple times for the same pixel. So some memory access is need but I can’t get it from the documentation for to do it properly.
Here is the essential part of the fragment shader code relevant to the problem

vec4 xy = gl_FragCoord;
        //int x = int(xy.x*imageWidth);
        //int y = int(xy.y*imageHeight);
        highp int x = int(xy.x);
        highp int y = int(xy.y);
        int stride = imageWidth*3;//SIZE_OF_VEC3*imageWidth;
        int maxOffset = imageWidth*imageHeight*3;//*SIZE_OF_VEC3;
        int offset = int(3*x + y*stride);
	if(offset>=maxOffset) offset= maxOffset-1;
	int ind = offset;

	int strideDepth = imageWidth;
        int offsetDepth = int(x + y*strideDepth);
	if( (xy.z<SharedDepthBuffer.depth[offsetDepth]) || (SharedDepthBuffer.depth[offsetDepth] == 0))
		SharedDepthBuffer.depth[offsetDepth] = xy.z;

			SharedBuffer.image[offset] = colorIn.x;
			SharedBuffer.image[offset+1] = colorIn.y;
			SharedBuffer.image[offset+2] = colorIn.z;


Could anyone explain how to use correctly memory barriers and their working princliple in general. Followng official documentation gives no results

Have you read these sections in the OpenGL Wiki?:

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.