MayaFlux 0.4.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 114 of file ShaderFoundry.cpp.

118{
119 if (!is_initialized()) {
121 "ShaderFoundry not initialized");
122 return nullptr;
123 }
124
125 auto it = m_shader_cache.find(filepath);
126 if (it != m_shader_cache.end()) {
128 "Using cached shader: {}", filepath);
129 return it->second;
130 }
131
132 std::optional<vk::ShaderStageFlagBits> vk_stage;
133 if (stage.has_value()) {
134 vk_stage = to_vulkan_stage(*stage);
135 }
136
137 auto shader = create_shader_module();
138
139 if (filepath.ends_with(".spv")) {
140 if (!shader->create_from_spirv_file(
141 get_device(), filepath,
142 vk_stage.value_or(vk::ShaderStageFlagBits::eCompute),
143 entry_point, m_config.enable_reflection)) {
145 "Failed to compile SPIR-V shader: {}", filepath);
146 return nullptr;
147 }
148 } else {
149 if (!shader->create_from_glsl_file(
150 get_device(), filepath, vk_stage, entry_point,
152 m_config.defines)) {
154 "Failed to compile GLSL shader: {}", filepath);
155 return nullptr;
156 }
157 }
158
159 m_shader_cache[filepath] = shader;
161 "Compiled shader: {} ({})", filepath, vk::to_string(shader->get_stage()));
162 return shader;
163}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
vk::Device get_device() const
Get logical device handle.
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: