From d24722ba96e9cad3327037fdcb66cbf10c4989b1 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Sat, 2 Mar 2024 11:21:33 -0800 Subject: [PATCH] renderer_vulkan: Separate glsl->spirv compilation to `CompileGLSLtoSPIRV` Allows other library code to compile GLSL to SPRIV intermediately before creating a shader-module --- src/video_core/renderer_vulkan/vk_shader_util.cpp | 15 +++++++++++++-- src/video_core/renderer_vulkan/vk_shader_util.h | 9 +++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_shader_util.cpp b/src/video_core/renderer_vulkan/vk_shader_util.cpp index ba5c5f867..c60fe3b7f 100644 --- a/src/video_core/renderer_vulkan/vk_shader_util.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_util.cpp @@ -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 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 code, vk::Device device) { diff --git a/src/video_core/renderer_vulkan/vk_shader_util.h b/src/video_core/renderer_vulkan/vk_shader_util.h index eb932e07d..2c38c3b56 100644 --- a/src/video_core/renderer_vulkan/vk_shader_util.h +++ b/src/video_core/renderer_vulkan/vk_shader_util.h @@ -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 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.