Compile a shader to SPIR-V with glslc
Compile a GLSL shader to SPIR-V with glslc from the Vulkan SDK, letting the file extension pick the stage and setting the target environment.
Vulkan does not accept GLSL. It takes SPIR-V, so every shader goes through a compiler first. glslc comes with the LunarG Vulkan SDK 1.3 and wraps Google's shaderc. It picks the shader stage from the file extension: .vert, .frag, .comp, and the others.
#version 450
layout(location = 0) in vec3 in_pos;
layout(location = 1) in vec3 in_color;
layout(location = 0) out vec3 v_color;
void main()
{
gl_Position = vec4(in_pos, 1.0);
v_color = in_color;
}glslc --target-env=vulkan1.3 -O triangle.vert -o triangle.vert.spv--target-env=vulkan1.3 makes glslc emit SPIR-V 1.6 and allows features of that Vulkan version. Without it the default is Vulkan 1.0 and the output is older SPIR-V, which still loads but rejects newer extensions in the source. -O runs the optimiser, and -O0 skips it, which keeps names for debugging.
The result is a binary, not text. The first four bytes are the SPIR-V magic number 0x07230203 in little-endian order, which is a quick way to confirm the file is real:
xxd -l 4 triangle.vert.spv00000000: 0302 2307 ..#.For a file with a non-standard extension, force the stage with -fshader-stage=vertex. Compile at build time in your build system and not at run time, so a shader syntax error fails the build.