Coherent GLSL 420 imageBuffer access in single-stage, single-pass scenario

Sorry if this question has been asked before, but I find lots of confusing information in the forums. Sometimes this information is (I believe) contradicting the specification of OpenGL.

When carefully reading the following paragraph in the ARB_shader_image_load_store spec:

“Using variables declared as “coherent” guarantees that the results of stores will be immediately visible to shader invocations using similarly-declared variables; calling MemoryBarrier is required to ensure that the stores are visible to other operations.”

I conclude that all imageStore()'s will be immediately visible to all fragment shader invocation in my situation: single pass, single shader. Also, image load/store operations are guaranteed to be executed in-order.

My fragment shader looks like this:

coherent layout(1x32) uniform uimageBuffer data;

void main()
{
  ...
  various calls to imageLoad(data, ..., ...);
  ...
  various calls to imageStore(data, ..., ...);
  ...
}

Because in-order execution is guaranteed, if a given invocation performs the following:

imageStore(data, 0, 1234);
imageStore(data, 1, 5678);

the following is true, for any other invocation:

if (imageLoad(data, 0) == 1234)
{
  int result = imageLoad(data, 1);
  // result here is GUARANTEED to be 5678
  // because 'data' is marked as 'coherent'
  // and I'm in a single shader instance
  // (matching the spec 'similarly-declared' variable)
}

Is that correct? (no need to call memoryBarrier() at all, for instance).

NB: not interested in non-coherent or multi-stage or multi-pass processing scenarios. Only coherent imageBuffer declarations, single pass, just using the fragment shader.

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