SPIR-V require locations on user in/out in Vulkan 1.0.51.1 +

4.3k views Asked by At

i installed the latest Vulkan SDK on my computer how ever whenever i want to generate the SPIR-V files for my shaders through glslValidator.exe it fails and returns the following errors

ERROR: Shader.vert:17: 'location' : SPIR-V requires location for user input/output
ERROR: 1 compilation errors.  No code generated.
ERROR: Linking vertex stage: Missing entry point: Each stage requires one entry point
SPIR-V is not generated for failed compile or link

I found out that since update 1.0.51.1 there are some changes that might cause my old shaders to fail

Require locations on user in/out in GL_KHR_vulkan_glsl (internal issue 783).

what is the proper/new way to fix this issue?

vertex shader

#version 450
#extension GL_ARB_separate_shader_objects : enable

layout(binding = 0)uniform UniformBufferObject {
mat4 model;
mat4 view;
mat4 proj;
} ubo;


layout(location = 0)in vec3 inPosition;
layout(location = 1)in vec3 inNormals;
layout(location = 2)in vec2 inTexCoord;

layout(location = 0)out vec3 fragColor;
layout(location = 1)out vec2 fragTexCoord;
out vec4 Normal;

out gl_PerVertex{
    vec4 gl_Position;
};



void main()
{
    gl_Position = ubo.proj * ubo.view * ubo.model * vec4 (inPosition, 1.0);
    //fragColor = inColor;
    fragTexCoord = inTexCoord;
    Normal = ubo.proj * ubo.view * ubo.model * vec4 (inNormals, 1.0);
}
1

There are 1 answers

8
Ekzuzy On BEST ANSWER

I assume that You need to explicitly set the location through layout qualifier for all Your variables:

layout( location=<number> ) ...

Vulkan requires all input, output and uniform variables to have an explicitly provided location value. Interface matching between shader stages is performed only through a location value (as opposed to OpenGL where it can be performed through both names or locations). I'm not sure as I have always provided the location value, but maybe in earlier versions glslangValidator set them implicitly (if locations were missing).