Initializing Vulkan shader modules
The Vulkan API consumes shaders in the form of compiled SPIR-V binaries. In the Compiling Vulkan shaders at runtime recipe, we learned how to compile shaders from source code to SPIR-V using the open source glslang compiler from Khronos. In this recipe, we will learn how to use these binaries in Vulkan.
Getting ready
We recommend reading the Compiling Vulkan shaders at runtime recipe before proceeding.
How to do it...
- Let's declare a structure that will hold a SPIR-V binary and its corresponding shader module object:
struct ShaderModule { Â Â std::vector<unsigned int> SPIRV; Â Â VkShaderModule shaderModule; };
- The following function will compile a shader that's been loaded from a file using
glslang
and upload the resulting SPIR-V binary to Vulkan:VkResult createShaderModule(  VkDevice device, ShaderModule* sm,  const char* fileName) {   if (!compileShaderFile(fileName...