glslang icon indicating copy to clipboard operation
glslang copied to clipboard

gl_FragDepth redeclaration only needed if there are a static assignment

Open infapi00 opened this issue 6 years ago • 2 comments

Using the following shaders:

01.frag:

#version 450

layout(depth_less) out float gl_FragDepth;

void foo();
void main()
{
     gl_FragDepth = gl_FragCoord.z;
     foo();
}

02.frag:

#version 450

/* this shader contains no static write to gl_FragDepth,
 * so need not redeclare it
 */

out vec4 color;

void foo()
{
   color = vec4(1);
}

And executing glslang as: $glslangValidator -G --aml --amb /tmp/01.frag /tmp/02.frag

It throws the following error:

ERROR: Linking fragment stage: Contradictory depth layouts

It throws the error as the second fragment stage doesn't redeclare it with the previous depth layout. But as the comment say, from GLSL 4.6 spec, section 4.4.2 "Ouput Layout Qualifiers", "Fragment Outputs":

If gl_FragDepth is redeclared in any fragment shader in a program, it must be redeclared in all fragment shaders in that program that have static assignments to gl_FragDepth

That redeclaration is only needed if gl_FragDepth is assigned on the shader.

infapi00 avatar Oct 02 '18 11:10 infapi00

Hey, ran into this issue. Seeing this is an open issue, Can I work on it?

Sh0g0-1758 avatar Sep 21 '23 17:09 Sh0g0-1758

Go for it, patches are most welcome.

arcady-lunarg avatar Sep 21 '23 21:09 arcady-lunarg