Search code examples
openglglslopengl-extensions

What is the syntax for 'pixel_interlock_ordered' in GLSL?


I'm trying out the ARB_fragment_shader_interlock extension in OpenGL 4.5 and am failing to get the shader to compile when trying to use pixel_interlock_ordered.

#version 430
#extension GL_ARB_shading_language_420pack : require
#extension GL_ARB_shader_image_load_store : require
#extension GL_ARB_fragment_shader_interlock : require

layout(location = 0, rg8, pixel_interlock_ordered) uniform image2D image1;

void main()
{
    beginInvocationInterlockARB();

    ivec2 coords = ivec2(gl_FragCoord.xy);
    vec4 pixel = imageLoad(image1, coords);

    pixel.g = pixel.g + 0.01;
    if (pixel.g > 0.5)
        pixel.r = pixel.r + 0.01;
    else
        pixel.r = pixel.r + 0.02;

    imageStore(image1, coords, pixel);

    endInvocationInterlockARB();
}

The following shader fails compilation with:

0(6) : error C7600: no value specified for layout qualifier 'pixel_interlock_ordered'

Which is the same error you would get for any random name instead of pixel_interlock_ordered. I guess the syntax is different somehow, but the spec (https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_fragment_shader_interlock.txt) refer to it as a "layout qualifier".

Googling "pixel_interlock_ordered" comes up short with just links to the official specs, so I can't find an example. What is the correct syntax?


Solution

  • Layout qualifiers in GLSL are a bit weird. They usually apply to declarations, but some of them effectively apply to the shader as a whole. Such qualifiers are basically shader-specific options you set from within the shader.

    The interlock qualifiers are those kinds of qualifiers. You're not saying that this variable will be accessed via interlocking, because that's not what interlocking means. It means that the execution of the interlock-bound code will have a certain property, relative to executing interlock-bound code on other invocations of the same shader. The qualifier specifies the details of the execution restriction.

    Qualifiers that apply to the shader as a whole are grammatically specified as qualifiers on in or out (most such qualifiers use in, but a few use out):

    layout(pixel_interlock_ordered) in;