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

◆ compile_from_file()

std::shared_ptr< Core::VKShaderModule > MayaFlux::Portal::Graphics::ShaderFoundry::compile_from_file ( const std::string &  filepath,
std::optional< ShaderStage stage = std::nullopt,
const std::string &  entry_point = "main" 
)
private

Definition at line 110 of file ShaderFoundry.cpp.

114{
115 if (!is_initialized()) {
117 "ShaderFoundry not initialized");
118 return nullptr;
119 }
120
121 auto it = m_shader_cache.find(filepath);
122 if (it != m_shader_cache.end()) {
124 "Using cached shader: {}", filepath);
125 return it->second;
126 }
127
128 std::optional<vk::ShaderStageFlagBits> vk_stage;
129 if (stage.has_value()) {
130 vk_stage = to_vulkan_stage(*stage);
131 }
132
133 auto shader = create_shader_module();
134
135 if (filepath.ends_with(".spv")) {
136 if (!shader->create_from_spirv_file(
137 get_device(), filepath,
138 vk_stage.value_or(vk::ShaderStageFlagBits::eCompute),
139 entry_point, m_config.enable_reflection)) {
141 "Failed to compile SPIR-V shader: {}", filepath);
142 return nullptr;
143 }
144 } else {
145 if (!shader->create_from_glsl_file(
146 get_device(), filepath, vk_stage, entry_point,
148 m_config.defines)) {
150 "Failed to compile GLSL shader: {}", filepath);
151 return nullptr;
152 }
153 }
154
155 m_shader_cache[filepath] = shader;
157 "Compiled shader: {} ({})", filepath, vk::to_string(shader->get_stage()));
158 return shader;
159}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
std::shared_ptr< Core::VKShaderModule > create_shader_module()
std::unordered_map< std::string, std::shared_ptr< Core::VKShaderModule > > m_shader_cache
static vk::ShaderStageFlagBits to_vulkan_stage(ShaderStage stage)
Convert Portal ShaderStage to Vulkan ShaderStageFlagBits.
bool is_initialized() const
Check if compiler is initialized.
@ ShaderCompilation
Shader compilation tasks (Portal::Graphics::ShaderCompiler)
@ Portal
High-level user-facing API layer.
bool enable_reflection
Extract descriptor bindings and metadata.
std::vector< std::string > include_directories
Paths for #include resolution.
std::unordered_map< std::string, std::string > defines
Preprocessor macros.

References create_shader_module(), MayaFlux::Portal::Graphics::ShaderCompilerConfig::defines, MayaFlux::Portal::Graphics::ShaderCompilerConfig::enable_reflection, get_device(), MayaFlux::Portal::Graphics::ShaderCompilerConfig::include_directories, is_initialized(), m_config, m_shader_cache, MF_DEBUG, MF_ERROR, MF_INFO, MayaFlux::Journal::Portal, MayaFlux::Journal::ShaderCompilation, and to_vulkan_stage().

Referenced by compile(), hot_reload(), and load_shader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: