Image coherency

Hello,
I am using ext_image_load_store extension for the conventional rendering and need to implement the z-buffer algorithm.
I am using coherent textures as they should by specification guarantee consistent reads/writes from different shader threads.

//<vertex>
	varying out float fDepth;
	void main()
	{
		gl_Position = ftransform();
//pow function just for the sake of visibility
		fDepth = 100.0 * pow(gl_Position.z / gl_Position.w, 10.0);

	}
//</vertex>


//<fragment>
	#version 400
	#extension GL_NV_gpu_shader5 : enable
	#extension GL_EXT_shader_image_load_store : enable
	#extension GL_EXT_bindable_uniform : enable
	#extension GL_NV_shader_buffer_load : enable
	#extension GL_NV_shader_buffer_store : enable
	
	coherent uniform layout(size4x32) image2D finalResult;
	in vec3 vecNormal;
	in float fDepth;
	
	void main()
	{
		vec3 vecColor = vec3(0.0, 1.0, 0.0);
//if pixel succeeds depth test, replace value in the buffer
		if (fDepth < imageLoad(finalResult, ivec2(gl_FragCoord.xy)).x)
		{
			imageStore(finalResult, ivec2(gl_FragCoord.xy), vec4(fDepth, 0.0, 0.0, 1.0));
		}
	}
//</fragment>

Here is the result, showing some artifacts, typical for read/write conflict:

What am I doing wrong?

I am not sure but it looks like to need to look at the GLSL “memoryBarrier” function defined in the GL_EXT_shader_image_load_store specification.

They were bugs with this function on nVidia implementation, I’m not sure if everything is fixed.

I got it!
The problem here is that read and write inside one thread are not a single atomic operation.
So, imagine two threads running (1, 2).
Naturally, you expect it to be.
read1
write1
read1
write2
But it could be as well:
read1
read2
write1
write2

And if conditions for both fragments is true (which is natural, when the depth buffer is clear), then random fragment depth will be written in output.