-
Standard Portable Intermediate Representation V .
-
SPIR-V .
-
Vulkan’s official shader format (portable, efficient).
-
SPIR-V is a binary format.
-
Works with Metal via MoltenVK.
Compiling
-
You can write GLSL or HLSL and compile to SPIR-V.
-
GLSL to SPIR-V:
-
glslangValidator (from Khronos)
# Compile GLSL → SPIR-V (Vulkan) glslangValidator -V vertex_shader.vert -o vert.spv glslangValidator -V fragment_shader.frag -o frag.spv -
-
HLSL to SPIR-V:
-
DXC (DirectX Shader Compiler)
dxc -T vs_6_0 -E VSMain -spirv shader.hlsl -Fo vert.spv-
Requires HLSL shaders with Vulkan-compatible semantics.
-
-
Convert SPIR-V to other formats:
-
SPIRV-Cross (converts HLSL to GLSL/SPIR-V)
-
-
-
Compiling shaders on the commandline is one of the most straightforward options and it's the one that we'll use in this tutorial, but it's also possible to compile shaders directly from your own code.
-
The Vulkan SDK includes libshaderc , which is a library to compile GLSL code to SPIR-V from within your program.
-
Advantages
-
The advantage of using a bytecode format is that the compilers written by GPU vendors to turn shader code into native code are significantly less complex. The past has shown that with human-readable syntax like GLSL, some GPU vendors were rather flexible with their interpretation of the standard. If you happen to write non-trivial shaders with a GPU from one of these vendors, then you’d risk another vendor’s drivers rejecting your code due to syntax errors, or worse, your shader running differently because of compiler bugs. With a straightforward bytecode format like SPIR-V that will hopefully be avoided.
Tooling
spirv-cross
-
Cross-compilation
-
Converts SPIR-V shader binaries into high-level shading languages:
-
GLSL (various versions)
-
HLSL
-
MSL (Metal Shading Language for Apple platforms)
-
WGSL (WebGPU shading language)
-
-
This lets you write shaders once (e.g. in GLSL or HLSL), compile to SPIR-V, then regenerate source for other backends.
-
-
Reflection
-
Inspects SPIR-V binaries and reports metadata about:
-
Descriptor sets and bindings
-
Push constants
-
Vertex input/output attributes
-
Specialization constants
-
-
With the
--reflectflag, it outputs this data as JSON , making it easy to drive engine code-generation or runtime Vulkan setup.
-
-
Ex :
-
spirv-cross scene_vert.spv --reflect > scene_vert.json.
-