0

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);
}
BulBul
  • 1,159
  • 3
  • 24
  • 37

1 Answers1

1

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).

Ekzuzy
  • 3,193
  • 1
  • 16
  • 14
  • i have not changed any of my shaders and they used to work with the SDK version 1.0.48.0 from LunarG, i updated my post you can see my vertex shader there it is really simple and straight forward – BulBul Sep 03 '17 at 19:05
  • 1
    The line with "out vec4 Normal;" lacks the location qualifier. – Ekzuzy Sep 03 '17 at 19:08
  • it fixed the issue, well i used to good old openGL shaders and initially it was allowed in vulkan, anyway thanks for your help – BulBul Sep 03 '17 at 19:22
  • 1
    hey i just realized who you are :P, and i realized i would never get a chance like this once in a life time :D, i have one specific question ( not as dump as this one ) :) and i realized there is not enough information about it online, is there a way that i could send you my question directly to you? through email or any other means of communication? it is also related to vulkan – BulBul Sep 03 '17 at 19:46
  • Please, don't feel offended or misunderstand my respone but Your comment made me laugh :-D. As it is very positive to read such feedback though I don't know what do You mean by "who you are". I'm just me ;-). Nevertheless, feel free to write to me. Wherever You find the "Ekzuzy" or "Ekzuzy Milsfar" nickname, it's probably me - Reddit, StackOverflow, FB, Twitter, GMail... to name the few. Choose what best fits You ;-). But I can't promise I will know the answer to Your question. Vulkan still has many secrets ;-). – Ekzuzy Sep 03 '17 at 19:53
  • 1
    Well if my debit card validity was not expired i was gonna buy vulkan cookbook from amazon, now iam directly talking with the author himself. It is a different dimension of being lucky :D i will send you my question and hopefully wait for the answer – BulBul Sep 03 '17 at 19:59
  • I guess it did not add them correctly when it was allowed. Indeed, if you did not put the location in the shader, the shader "worked" on Nvidia, but not in Intel for example. You had to explicitly write it for intel to work :) – Antoine Morrier Sep 08 '17 at 07:58
  • Does someone know if inputs, outputs, fragment and vertex have separate location counts? For example can the first input in vertex shader, first output in vertex shader, first input in fragment shader and first output in fragment shader all have the location index 0? – Desperado17 Mar 16 '21 at 15:12