Shaders in Vulkan have to be precompiled into SPIR-V format

In Vulkan, shaders use a new intermediate, byte-code format called SPIR-V. SPIR-V can be used for both graphical and compute operations, so is also compatible with OpenCL.

Shaders can still be written in GLSL, but then must be converted to SPIR-V using an offline compiler. To help with compile code from GLSL to SPIR-V, Khronos released a vendor agnostic compiler called glslang. glslang also automatically error checks and verifies that the shader is standard-compliant.

In Vulkan applications, the shader code is loaded into a thin wrapper called a shader module. Shader modules hold a pointer to the source code in memory and also reference the stage of the pipeline at which the shader will be used, for example the vertex shader or fragment shader stage. Shader modules are referenced when a pipeline is created.

The main advantages of using the SPIR-V format are:
  • Less flexibility to vendor compilers on how to interpret the code
  • Streamlined portability of shaders across different vendor compilers that have to turn the shader into native code