KhronosGroup / glslang

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

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

Open infapi00 opened 6 years ago

infapi00 commented 6 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 1 year ago

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

arcady-lunarg commented 1 year ago

Go for it, patches are most welcome.