Compiling shaders to SPIR-V
In contrast to OpenGL, which typically compiles shaders from high-level languages into binary format during runtime, Vulkan only supports an intermediate representation called SPIR-V. SPIR-V is a cross-platform, low-level intermediate representation that can be produced from various shading languages.
In this recipe, you will learn how to compile GLSL to SPIR-V using the glslang
library.
Getting ready
In this recipe, we use a third-party library that compiles GLSL code into SPIR-V at runtime called glslang
. It can be downloaded from https://github.com/KhronosGroup/glslang.git.
In our code, we provide the VulkanCore::ShaderModule
class that encapsulates shaders. It provides the ShaderModule::glslToSpirv
method (and overloads) that compiles shader source code from GLSL to SPIR-V.
How to do it…
The steps presented here are part of the ShaderModule::glslToSpirv()
method. Here’s how it works:
- The
glslang
library needs to...