KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
2.98k stars 823 forks source link

gl_FragDepth redeclaration only needed if there are a static assignment #1516

Open infapi00 opened 5 years ago

infapi00 commented 5 years ago

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.

Sh0g0-1758 commented 11 months ago

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

arcady-lunarg commented 11 months ago

Go for it, patches are most welcome.