MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Portal::Graphics::ShaderFoundry Class Reference

Portal-level shader compilation and caching. More...

#include <ShaderFoundry.hpp>

+ Collaboration diagram for MayaFlux::Portal::Graphics::ShaderFoundry:

Classes

struct  CommandBufferState
 
struct  DescriptorSetState
 
struct  FenceState
 
struct  SemaphoreState
 
struct  ShaderState
 
struct  TimestampResult
 

Public Types

enum class  CommandBufferType : uint8_t { GRAPHICS , COMPUTE , TRANSFER }
 

Public Member Functions

 ShaderFoundry (const ShaderFoundry &)=delete
 
ShaderFoundryoperator= (const ShaderFoundry &)=delete
 
 ShaderFoundry (ShaderFoundry &&) noexcept=delete
 
ShaderFoundryoperator= (ShaderFoundry &&) noexcept=delete
 
bool initialize (const std::shared_ptr< Core::VulkanBackend > &backend, const ShaderCompilerConfig &config={})
 Initialize shader compiler.
 
void shutdown ()
 Shutdown and cleanup.
 
bool is_initialized () const
 Check if compiler is initialized.
 
ShaderID load_shader (const std::string &content, std::optional< ShaderStage > stage=std::nullopt, const std::string &entry_point="main")
 Universal shader loader - auto-detects source type.
 
ShaderID load_shader (const ShaderSource &source)
 Load shader from explicit ShaderSource descriptor.
 
ShaderID reload_shader (const std::string &filepath)
 Hot-reload shader (returns new ID)
 
void destroy_shader (ShaderID shader_id)
 Destroy shader (cleanup internal state)
 
std::shared_ptr< Core::VKShaderModulecompile (const ShaderSource &shader_source)
 Compile shader from ShaderSource descriptor.
 
ShaderReflectionInfo get_shader_reflection (ShaderID shader_id)
 Get reflection info for compiled shader.
 
ShaderStage get_shader_stage (ShaderID shader_id)
 Get shader stage for compiled shader.
 
std::string get_shader_entry_point (ShaderID shader_id)
 Get entry point name for compiled shader.
 
void invalidate_cache (const std::string &cache_key)
 Invalidate cache for specific shader.
 
void clear_cache ()
 Invalidate entire shader cache.
 
std::shared_ptr< Core::VKShaderModulehot_reload (const std::string &filepath)
 Hot-reload a shader from file.
 
void set_config (const ShaderCompilerConfig &config)
 Update compiler configuration.
 
const ShaderCompilerConfigget_config () const
 Get current compiler configuration.
 
void add_include_directory (const std::string &directory)
 Add include directory for shader compilation.
 
void add_define (const std::string &name, const std::string &value="")
 Add preprocessor define for shader compilation.
 
bool is_cached (const std::string &cache_key) const
 Check if shader is cached.
 
std::vector< std::string > get_cached_keys () const
 Get all cached shader keys.
 
size_t get_cache_size () const
 Get number of cached shaders.
 
DescriptorSetID allocate_descriptor_set (vk::DescriptorSetLayout layout)
 Allocate descriptor set for a pipeline.
 
void update_descriptor_buffer (DescriptorSetID descriptor_set_id, uint32_t binding, vk::DescriptorType type, vk::Buffer buffer, size_t offset, size_t size)
 Update descriptor set with buffer binding.
 
void update_descriptor_image (DescriptorSetID descriptor_set_id, uint32_t binding, vk::ImageView image_view, vk::Sampler sampler, vk::ImageLayout layout=vk::ImageLayout::eShaderReadOnlyOptimal)
 Update descriptor set with image binding.
 
void update_descriptor_storage_image (DescriptorSetID descriptor_set_id, uint32_t binding, vk::ImageView image_view, vk::ImageLayout layout=vk::ImageLayout::eGeneral)
 Update descriptor set with storage image binding.
 
vk::DescriptorSet get_descriptor_set (DescriptorSetID descriptor_set_id)
 Get Vulkan descriptor set handle from DescriptorSetID.
 
CommandBufferID begin_commands (CommandBufferType type)
 Begin recording command buffer.
 
vk::CommandBuffer get_command_buffer (CommandBufferID cmd_id)
 Get Vulkan command buffer handle from CommandBufferID.
 
void submit_and_wait (CommandBufferID cmd_id)
 Submit command buffer and wait for completion.
 
FenceID submit_async (CommandBufferID cmd_id)
 Submit command buffer asynchronously, returning a fence.
 
SemaphoreID submit_with_signal (CommandBufferID cmd_id)
 Submit command buffer asynchronously, returning a semaphore.
 
void wait_for_fence (FenceID fence_id)
 Wait for fence to be signaled.
 
void wait_for_fences (const std::vector< FenceID > &fence_ids)
 Wait for multiple fences to be signaled.
 
bool is_fence_signaled (FenceID fence_id)
 Check if fence is signaled.
 
CommandBufferID begin_commands_with_wait (CommandBufferType type, SemaphoreID wait_semaphore, vk::PipelineStageFlags wait_stage)
 Begin command buffer that waits on a semaphore.
 
vk::Semaphore get_semaphore_handle (SemaphoreID semaphore_id)
 Get Vulkan fence handle from FenceID.
 
void buffer_barrier (CommandBufferID cmd_id, vk::Buffer buffer, vk::AccessFlags src_access, vk::AccessFlags dst_access, vk::PipelineStageFlags src_stage, vk::PipelineStageFlags dst_stage)
 Insert buffer memory barrier.
 
void image_barrier (CommandBufferID cmd_id, vk::Image image, vk::ImageLayout old_layout, vk::ImageLayout new_layout, vk::AccessFlags src_access, vk::AccessFlags dst_access, vk::PipelineStageFlags src_stage, vk::PipelineStageFlags dst_stage)
 Insert image memory barrier.
 
void set_graphics_queue (vk::Queue queue)
 Set Vulkan queues for command submission.
 
void set_compute_queue (vk::Queue queue)
 Set Vulkan queues for command submission.
 
void set_transfer_queue (vk::Queue queue)
 Set Vulkan queues for command submission.
 
vk::Queue get_graphics_queue () const
 Get Vulkan graphics queue.
 
vk::Queue get_compute_queue () const
 Get Vulkan compute queue.
 
vk::Queue get_transfer_queue () const
 Get Vulkan transfer queue.
 
void begin_timestamp (CommandBufferID cmd_id, const std::string &label="")
 
void end_timestamp (CommandBufferID cmd_id, const std::string &label="")
 
TimestampResult get_timestamp_result (CommandBufferID cmd_id, const std::string &label)
 

Static Public Member Functions

static ShaderFoundryinstance ()
 
static vk::ShaderStageFlagBits to_vulkan_stage (ShaderStage stage)
 Convert Portal ShaderStage to Vulkan ShaderStageFlagBits.
 
static std::optional< ShaderStagedetect_stage_from_extension (const std::string &filepath)
 Auto-detect shader stage from file extension.
 

Private Types

enum class  DetectedSourceType : uint8_t { FILE_GLSL , FILE_SPIRV , SOURCE_STRING , UNKNOWN }
 Internal enum for source type detection. More...
 

Private Member Functions

 ShaderFoundry ()=default
 
 ~ShaderFoundry ()
 
DetectedSourceType detect_source_type (const std::string &content) const
 
std::optional< std::filesystem::path > resolve_shader_path (const std::string &filepath) const
 
std::string generate_source_cache_key (const std::string &source, ShaderStage stage) const
 
std::shared_ptr< Core::VKShaderModulecreate_shader_module ()
 
vk::Device get_device () const
 
std::shared_ptr< Core::VKShaderModulecompile_from_file (const std::string &filepath, std::optional< ShaderStage > stage=std::nullopt, const std::string &entry_point="main")
 
std::shared_ptr< Core::VKShaderModulecompile_from_source (const std::string &source, ShaderStage stage, const std::string &entry_point="main")
 
std::shared_ptr< Core::VKShaderModulecompile_from_source_cached (const std::string &source, ShaderStage stage, const std::string &cache_key, const std::string &entry_point="main")
 
std::shared_ptr< Core::VKShaderModulecompile_from_spirv (const std::string &spirv_path, ShaderStage stage, const std::string &entry_point="main")
 
std::shared_ptr< Core::VKShaderModuleget_vk_shader_module (ShaderID shader_id)
 

Private Attributes

std::shared_ptr< Core::VulkanBackendm_backend
 
ShaderCompilerConfig m_config
 
std::unordered_map< std::string, std::shared_ptr< Core::VKShaderModule > > m_shader_cache
 
std::unordered_map< ShaderID, ShaderStatem_shaders
 
std::unordered_map< std::string, ShaderIDm_shader_filepath_cache
 
std::shared_ptr< Core::VKDescriptorManagerm_global_descriptor_manager
 
std::unordered_map< DescriptorSetID, DescriptorSetStatem_descriptor_sets
 
std::unordered_map< CommandBufferID, CommandBufferStatem_command_buffers
 
std::unordered_map< FenceID, FenceStatem_fences
 
std::unordered_map< SemaphoreID, SemaphoreStatem_semaphores
 
vk::Queue m_graphics_queue
 
vk::Queue m_compute_queue
 
vk::Queue m_transfer_queue
 
std::atomic< uint64_t > m_next_shader_id { 1 }
 
std::atomic< uint64_t > m_next_descriptor_set_id { 1 }
 
std::atomic< uint64_t > m_next_command_id { 1 }
 
std::atomic< uint64_t > m_next_fence_id { 1 }
 
std::atomic< uint64_t > m_next_semaphore_id { 1 }
 

Static Private Attributes

static bool s_initialized = false
 

Friends

class ComputePress
 
class RenderFlow
 

Detailed Description

Portal-level shader compilation and caching.

ShaderFoundry is a thin glue layer that:

  • Wraps Core::VKShaderModule for convenient shader creation
  • Provides caching to avoid redundant compilation
  • Supports hot-reload workflows (watch files, recompile)
  • Returns VKShaderModule directly for use in pipelines

Design Philosophy:

  • Manages compilation, NOT execution (that's Pipeline/Compute)
  • Returns VKShaderModule directly (no wrapping)
  • Simple, focused API aligned with VKShaderModule capabilities
  • Integrates with existing Core shader infrastructure

Consumers:

  • VKBufferProcessor subclasses (compute shaders)
  • Future Yantra::ComputePipeline (compute shaders)
  • Future Yantra::RenderPipeline (graphics shaders)
  • Future DataProcessors (image processing shaders)

Usage: auto& compiler = Portal::Graphics::ShaderFoundry::instance();

// Compile from file auto shader = compiler.compile_from_file("shaders/my_kernel.comp");

// Compile from string auto shader = compiler.compile_from_source(glsl_code, ShaderStage::COMPUTE);

// Use in pipeline my_buffer_processor->set_shader(shader); my_compute_pipeline->set_shader(shader);

Definition at line 156 of file ShaderFoundry.hpp.


The documentation for this class was generated from the following files: