MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ compile_glsl_to_spirv()

std::vector< uint32_t > MayaFlux::Core::VKShaderModule::compile_glsl_to_spirv ( const std::string &  glsl_source,
vk::ShaderStageFlagBits  stage,
const std::vector< std::string > &  include_directories,
const std::unordered_map< std::string, std::string > &  defines 
)
private

Compile GLSL to SPIR-V using shaderc.

Parameters
glsl_sourceGLSL source code
stageShader stage (affects compiler settings)
include_directoriesInclude paths
definesPreprocessor macros
Returns
SPIR-V bytecode, or empty vector on failure

Definition at line 711 of file VKShaderModule.cpp.

716{
717 shaderc::Compiler compiler;
718 shaderc::CompileOptions options;
719
720 options.SetTargetEnvironment(shaderc_target_env_vulkan, shaderc_env_version_vulkan_1_3);
721 options.SetTargetSpirv(shaderc_spirv_version_1_6);
722 options.SetOptimizationLevel(shaderc_optimization_level_performance);
723 options.SetIncluder(std::make_unique<FileIncluder>(include_directories));
724
725 for (const auto& [name, value] : defines) {
726 options.AddMacroDefinition(name, value);
727 }
728
729 shaderc_shader_kind shader_kind;
730 switch (stage) {
731 case vk::ShaderStageFlagBits::eVertex:
732 shader_kind = shaderc_glsl_vertex_shader;
733 break;
734 case vk::ShaderStageFlagBits::eFragment:
735 shader_kind = shaderc_glsl_fragment_shader;
736 break;
737 case vk::ShaderStageFlagBits::eCompute:
738 shader_kind = shaderc_glsl_compute_shader;
739 break;
740 case vk::ShaderStageFlagBits::eGeometry:
741 shader_kind = shaderc_glsl_geometry_shader;
742 break;
743 case vk::ShaderStageFlagBits::eTessellationControl:
744 shader_kind = shaderc_glsl_tess_control_shader;
745 break;
746 case vk::ShaderStageFlagBits::eTessellationEvaluation:
747 shader_kind = shaderc_glsl_tess_evaluation_shader;
748 break;
749 case vk::ShaderStageFlagBits::eMeshEXT:
750 shader_kind = shaderc_glsl_mesh_shader;
751 break;
752 case vk::ShaderStageFlagBits::eTaskEXT:
753 shader_kind = shaderc_glsl_task_shader;
754 break;
755 default:
757 "Unsupported shader stage for GLSL compilation: {}", vk::to_string(stage));
758 return {};
759 }
760
761 shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(
762 glsl_source,
763 shader_kind,
764 "shader.glsl",
765 options);
766
767 if (result.GetCompilationStatus() != shaderc_compilation_status_success) {
769 "GLSL compilation failed:\n{}", result.GetErrorMessage());
770 return {};
771 }
772
773 std::vector<uint32_t> spirv(result.cbegin(), result.cend());
774
776 "Compiled GLSL ({} stage) -> {} bytes SPIR-V",
777 vk::to_string(stage), spirv.size() * 4);
778
779 return spirv;
780}
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
float value
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.

References MayaFlux::Journal::Core, MayaFlux::Journal::GraphicsBackend, MF_DEBUG, MF_ERROR, and value.

Referenced by create_from_glsl().

+ Here is the caller graph for this function: