renderer_vulkan: Separate glsl->spirv compilation to CompileGLSLtoSPIRV

Allows other library code to compile GLSL to SPRIV intermediately before creating a shader-module
This commit is contained in:
Wunkolo 2024-03-02 11:21:33 -08:00
parent 21bfc043f0
commit d24722ba96
2 changed files with 22 additions and 2 deletions

View File

@ -158,7 +158,14 @@ bool InitializeCompiler() {
}
} // Anonymous namespace
vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, vk::Device device) {
/**
* @brief Compiles GLSL into SPIRV
* @param code The string containing GLSL code.
* @param stage The pipeline stage the shader will be used in.
* @param device The vulkan device handle.
*/
std::vector<u32> CompileGLSLtoSPIRV(std::string_view code, vk::ShaderStageFlagBits stage,
vk::Device device) {
if (!InitializeCompiler()) {
return {};
}
@ -212,7 +219,11 @@ vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, v
LOG_INFO(Render_Vulkan, "SPIR-V conversion messages: {}", spv_messages);
}
return CompileSPV(out_code, device);
return out_code;
}
vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, vk::Device device) {
return CompileSPV(CompileGLSLtoSPIRV(code, stage, device), device);
}
vk::ShaderModule CompileSPV(std::span<const u32> code, vk::Device device) {

View File

@ -10,6 +10,15 @@
namespace Vulkan {
/**
* @brief Compiles GLSL into SPIRV
* @param code The string containing GLSL code.
* @param stage The pipeline stage the shader will be used in.
* @param device The vulkan device handle.
*/
std::vector<u32> CompileGLSLtoSPIRV(std::string_view code, vk::ShaderStageFlagBits stage,
vk::Device device);
/**
* @brief Creates a vulkan shader module from GLSL by converting it to SPIR-V using glslang.
* @param code The string containing GLSL code.