Search code examples
glslshaderfragment-shadervertex-shaderspir-v

getting 'location' : too large for fragment output error while using glslang


Iam using glslang SDK in my code to compile shader programs online, however i get the following errors for my fragment shader:

GLSL Parsing Failed for: Text.frag ERROR: 0:6: 'location' : too large for fragment output ERROR: 1 compilation errors. No code generated.

GLSL Linking Failed for: Text.frag ERROR: 0:6: 'location' : too large for fragment output ERROR: 1 compilation errors. No code generated.

Assertion failed: node->getOp(), file C:\projects\glslang\SPIRV\GlslangToSpv.cpp, line 2412

my vertex shader:

#version 450
#extension GL_ARB_separate_shader_objects : enable

layout(location = 0) out vec3 fragColor;

vec2 positions[3] = vec2[](
    vec2(0.0, -0.5),
    vec2(0.5, 0.5),
    vec2(-0.5, 0.5)
);

vec3 colors[3] = vec3[](
    vec3(1.0, 0.0, 0.0),
    vec3(0.0, 1.0, 0.0),
    vec3(0.0, 0.0, 1.0)
);

void main() {
    gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
    fragColor = colors[gl_VertexIndex];
}

My fragment shader

#version 450
#extension GL_ARB_separate_shader_objects : enable

layout(location = 0) in vec3 fragColor;

layout(location = 0) out vec4 outColor;

void main() {
    outColor = vec4(fragColor, 1.0);
}

Solution

  • Iam using glslang SDK in my code to compile the shader programs online, apparently in the glslang code you have to tweak some limitation parameters manually for glslang to accept shader variables that are normally not accepted, this issue was fixed by setting maxDrawBuffers to true as the following

    resources = DefaultTBuiltInResource;
    
    resources.maxDrawBuffers = true;
    

    I am not sure what exactly this does and why it is not set natively, but perhaps someone can explain this further.