MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ShaderFoundry.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "ShaderUtils.hpp"
4
5#include "ShaderSpec.hpp"
6
7namespace MayaFlux::Core {
8class VulkanBackend;
9class VKShaderModule;
10class VKComputePipeline;
11class VKDescriptorManager;
12}
13
15
16class ComputePress;
17class RenderFlow;
18
19namespace detail {
20 /**
21 * @brief Emit complete SPIR-V assembly text for a generated compute kernel.
22 * @param spec ShaderSpec produced by ShaderSpec::Assemble::build().
23 * @return SPIR-V assembly string suitable for spvTextToBinary.
24 */
25 std::string emit_spirv_asm(const ShaderSpec& spec);
26
27 /**
28 * Emit a complete GLSL compute shader from spec metadata and a KernelSource body.
29 *
30 * Binding names are used directly as GLSL identifiers. The body text from
31 * KernelSource::parse() is injected verbatim inside main() after uint i and
32 * optional ivec2 coord are declared. Push constant fields are accessible as
33 * pc.<name>. SSBO arrays are accessible as <name>[i].
34 */
35 std::string emit_glsl_kernel(const ShaderSpec& spec);
36}
37
38/**
39 * @class ShaderFoundry
40 * @brief Portal-level shader compilation and caching
41 *
42 * ShaderFoundry is a thin glue layer that:
43 * - Wraps Core::VKShaderModule for convenient shader creation
44 * - Provides caching to avoid redundant compilation
45 * - Supports hot-reload workflows (watch files, recompile)
46 * - Returns VKShaderModule directly for use in pipelines
47 *
48 * Design Philosophy:
49 * - Manages compilation, NOT execution (that's Pipeline/Compute)
50 * - Returns VKShaderModule directly (no wrapping)
51 * - Simple, focused API aligned with VKShaderModule capabilities
52 * - Integrates with existing Core shader infrastructure
53 *
54 * Consumers:
55 * - VKBufferProcessor subclasses (compute shaders)
56 * - Future Yantra::ComputePipeline (compute shaders)
57 * - Future Yantra::RenderPipeline (graphics shaders)
58 * - Future DataProcessors (image processing shaders)
59 *
60 * Usage:
61 * auto& compiler = Portal::Graphics::ShaderFoundry::instance();
62 *
63 * // Compile from file
64 * auto shader = compiler.compile_from_file("shaders/my_kernel.comp");
65 *
66 * // Compile from string
67 * auto shader = compiler.compile_from_source(glsl_code, ShaderStage::COMPUTE);
68 *
69 * // Use in pipeline
70 * my_buffer_processor->set_shader(shader);
71 * my_compute_pipeline->set_shader(shader);
72 */
73class MAYAFLUX_API ShaderFoundry {
74public:
75 enum class CommandBufferType : uint8_t {
77 COMPUTE,
78 TRANSFER
79 };
80
81 enum class CommandBufferLevel : uint8_t {
82 PRIMARY,
83 SECONDARY
84 };
85
86private:
88 vk::DescriptorSet descriptor_set;
89 };
90
92 vk::CommandBuffer cmd;
94 CommandBufferLevel level { CommandBufferLevel::PRIMARY };
96 vk::QueryPool timestamp_pool;
97 std::unordered_map<std::string, uint32_t> timestamp_queries;
98 };
99
100 struct FenceState {
101 vk::Fence fence;
103
105 };
106
108 vk::Semaphore semaphore;
109 };
110
111 struct ShaderState {
112 std::shared_ptr<Core::VKShaderModule> module;
113 std::string filepath;
115 std::string entry_point;
116 };
117
118public:
120 {
121 static ShaderFoundry compiler;
122 return compiler;
123 }
124
125 ShaderFoundry(const ShaderFoundry&) = delete;
127 ShaderFoundry(ShaderFoundry&&) noexcept = delete;
128 ShaderFoundry& operator=(ShaderFoundry&&) noexcept = delete;
129
130 /**
131 * @brief Initialize shader compiler
132 * @param backend Shared pointer to VulkanBackend
133 * @param config Compiler configuration
134 * @return True if initialization succeeded
135 *
136 * Must be called before compiling any shaders.
137 */
138 bool initialize(
139 const std::shared_ptr<Core::VulkanBackend>& backend,
140 const ShaderCompilerConfig& config = {});
141
142 /**
143 * @brief Stop active command recording and free command buffers
144 *
145 * Frees all command buffers back to pool and destroys query pools.
146 * Call this BEFORE destroying pipelines/resources that command buffers reference.
147 * Does NOT destroy the command pool itself - that happens in shutdown().
148 */
149 void stop();
150
151 /**
152 * @brief Shutdown and cleanup all ShaderFoundry resources
153 *
154 * Destroys sync objects, descriptor resources, and shader modules.
155 * Must be called AFTER stop() and AFTER pipeline consumers (RenderFlow/ComputePress) shutdown.
156 */
157 void shutdown();
158
159 /**
160 * @brief Check if compiler is initialized
161 */
162 [[nodiscard]] bool is_initialized() const { return m_backend != nullptr; }
163
164 //==========================================================================
165 // Shader Compilation - Primary API
166 //==========================================================================
167
168 /**
169 * @brief Universal shader loader - auto-detects source type
170 * @param content File path, GLSL source string, or SPIR-V path
171 * @param stage Optional stage override (auto-detected if omitted)
172 * @param entry_point Entry point function name (default: "main")
173 * @return ShaderID, or INVALID_SHADER on failure
174 *
175 * Supports:
176 * - GLSL files: .comp, .vert, .frag, .geom, .tesc, .tese
177 * - SPIR-V files: .spv
178 *
179 * Stage auto-detection:
180 * .comp → COMPUTE
181 * .vert → VERTEX
182 * .frag → FRAGMENT
183 * .geom → GEOMETRY
184 * .tesc → TESS_CONTROL
185 * .tese → TESS_EVALUATION
186 * .mesh → MESH
187 * .task → TASK
188 *
189 * Examples:
190 * load_shader("shaders/kernel.comp"); // File
191 * load_shader("shaders/kernel.spv", COMPUTE); // SPIR-V
192 * load_shader("#version 460\nvoid main(){}", COMPUTE); // Source
193 */
194 ShaderID load_shader(
195 const std::string& content,
196 std::optional<ShaderStage> stage = std::nullopt,
197 const std::string& entry_point = "main");
198
199 /**
200 * @brief Load shader from explicit ShaderSource descriptor
201 * @param source Complete shader source specification
202 * @return ShaderID, or INVALID_SHADER on failure
203 */
204 ShaderID load_shader(const ShaderSource& source);
205
206 /**
207 * @brief Compile and cache a compute shader from a declarative ShaderSpec.
208 *
209 * Emits SPIR-V assembly text from the spec via detail::emit_spirv_asm(),
210 * assembles it via VKShaderModule::create_from_spirv_asm() using
211 * SPIRV-Tools, and caches the result by content hash. No shaderc or
212 * GLSL toolchain is involved.
213 *
214 * Subsequent calls with a spec that produces identical assembly are cache
215 * hits and return the existing ShaderID at no cost.
216 *
217 * The emitted shader is always a compute stage. Entry point is "main".
218 * Binding 0 at set 0 is never emitted; it is engine-reserved.
219 *
220 * @param spec ShaderSpec produced by ShaderSpec::Assemble::build().
221 * @return ShaderID on success, INVALID_SHADER on compilation failure.
222 */
223 ShaderID load_shader(const ShaderSpec& spec);
224
225 /**
226 * @brief Hot-reload shader (returns new ID)
227 */
228 ShaderID reload_shader(const std::string& filepath);
229
230 /**
231 * @brief Destroy shader (cleanup internal state)
232 */
233 void destroy_shader(ShaderID shader_id);
234
235 /**
236 * @brief Compile shader from ShaderSource descriptor
237 * @param shader_source Shader descriptor (path or source + type + stage)
238 * @return Compiled shader module, or nullptr on failure
239 *
240 * Unified interface that dispatches to appropriate compile method.
241 * Useful for abstracted shader loading pipelines.
242 */
243 std::shared_ptr<Core::VKShaderModule> compile(const ShaderSource& shader_source);
244
245 //==========================================================================
246 // Shader Introspection
247 //==========================================================================
248
249 /**
250 * @brief Get reflection info for compiled shader
251 * @param shader_id ID of compiled shader
252 * @return Reflection information
253 *
254 * Extracted during compilation if enabled in config.
255 * Includes descriptor bindings, push constant ranges, workgroup size, etc.
256 */
257 ShaderReflectionInfo get_shader_reflection(ShaderID shader_id);
258
259 /**
260 * @brief Get shader stage for compiled shader
261 * @param shader_id ID of compiled shader
262 * @return Shader stage (COMPUTE, VERTEX, FRAGMENT, etc.)
263 */
264 ShaderStage get_shader_stage(ShaderID shader_id);
265
266 /**
267 * @brief Get entry point name for compiled shader
268 * @param shader_id ID of compiled shader
269 * @return Entry point function name
270 */
271 std::string get_shader_entry_point(ShaderID shader_id);
272
273 //==========================================================================
274 // Hot-Reload Support
275 //==========================================================================
276
277 /**
278 * @brief Invalidate cache for specific shader
279 * @param cache_key File path or cache key
280 *
281 * Forces next compilation to recompile from source.
282 * Useful for hot-reload workflows.
283 */
284 void invalidate_cache(const std::string& cache_key);
285
286 /**
287 * @brief Invalidate entire shader cache
288 *
289 * Forces all subsequent compilations to recompile.
290 * Does NOT destroy existing shader modules (they remain valid).
291 */
292 void clear_cache();
293
294 /**
295 * @brief Hot-reload a shader from file
296 * @param filepath Path to shader file
297 * @return Recompiled shader module, or nullptr on failure
298 *
299 * Convenience method: invalidate_cache() + compile_from_file().
300 * Returns new shader module; consumers must update references.
301 */
302 std::shared_ptr<Core::VKShaderModule> hot_reload(const std::string& filepath);
303
304 //==========================================================================
305 // Configuration
306 //==========================================================================
307
308 /**
309 * @brief Update compiler configuration
310 * @param config New configuration
311 *
312 * Affects future compilations.
313 * Does NOT recompile existing shaders.
314 */
315 void set_config(const ShaderCompilerConfig& config);
316
317 /**
318 * @brief Get current compiler configuration
319 */
320 [[nodiscard]] const ShaderCompilerConfig& get_config() const { return m_config; }
321
322 /**
323 * @brief Add include directory for shader compilation
324 * @param directory Path to directory containing shader includes
325 *
326 * Used for #include resolution in GLSL files.
327 */
328 void add_include_directory(const std::string& directory);
329
330 /**
331 * @brief Add preprocessor define for shader compilation
332 * @param name Macro name
333 * @param value Macro value (optional)
334 *
335 * Example: define("DEBUG", "1") → #define DEBUG 1
336 */
337 void add_define(const std::string& name, const std::string& value = "");
338
339 //==========================================================================
340 // Introspection
341 //==========================================================================
342
343 /**
344 * @brief Check if shader is cached
345 * @param cache_key File path or cache key
346 */
347 [[nodiscard]] bool is_cached(const std::string& cache_key) const;
348
349 /**
350 * @brief Get all cached shader keys
351 */
352 [[nodiscard]] std::vector<std::string> get_cached_keys() const;
353
354 /**
355 * @brief Get number of cached shaders
356 */
357 [[nodiscard]] size_t get_cache_size() const { return m_shader_cache.size(); }
358
359 //==========================================================================
360 // Descriptor Set Management - ShaderFoundry allocates and tracks
361 //==========================================================================
362
363 /**
364 * @brief Allocate descriptor set for a pipeline
365 * @param pipeline_id Which pipeline this is for
366 * @param set_index Which descriptor set (0, 1, 2...)
367 * @return Descriptor set ID
368 */
369 DescriptorSetID allocate_descriptor_set(vk::DescriptorSetLayout layout);
370
371 /**
372 * @brief Update descriptor set with buffer binding
373 * @param descriptor_set_id ID of descriptor set to update
374 * @param binding Binding index within the descriptor set
375 * @param type Descriptor type (e.g., eStorageBuffer, eUniformBuffer)
376 * @param buffer Vulkan buffer to bind
377 * @param offset Offset within the buffer
378 * @param size Size of the buffer region
379 */
380 void update_descriptor_buffer(
381 DescriptorSetID descriptor_set_id,
382 uint32_t binding,
383 vk::DescriptorType type,
384 vk::Buffer buffer,
385 size_t offset,
386 size_t size);
387
388 /**
389 * @brief Update descriptor set with image binding
390 * @param descriptor_set_id ID of descriptor set to update
391 * @param binding Binding index within the descriptor set
392 * @param image_view Vulkan image view to bind
393 * @param sampler Vulkan sampler to bind
394 * @param layout Image layout (default: eShaderReadOnlyOptimal)
395 * @param array_element Array index for array bindings (default: 0)
396 */
397 void update_descriptor_image(
398 DescriptorSetID descriptor_set_id,
399 uint32_t binding,
400 vk::ImageView image_view,
401 vk::Sampler sampler,
402 vk::ImageLayout layout = vk::ImageLayout::eShaderReadOnlyOptimal,
403 uint32_t array_element = 0);
404
405 /**
406 * @brief Update descriptor set with storage image binding
407 * @param descriptor_set_id ID of descriptor set to update
408 * @param binding Binding index within the descriptor set
409 * @param image_view Vulkan image view to bind
410 * @param layout Image layout (default: eGeneral)
411 */
412 void update_descriptor_storage_image(
413 DescriptorSetID descriptor_set_id,
414 uint32_t binding,
415 vk::ImageView image_view,
416 vk::ImageLayout layout = vk::ImageLayout::eGeneral);
417
418 /**
419 * @brief Get Vulkan descriptor set handle from DescriptorSetID
420 * @param descriptor_set_id Descriptor set ID
421 * @return Vulkan descriptor set handle
422 */
423 vk::DescriptorSet get_descriptor_set(DescriptorSetID descriptor_set_id);
424
425 //==========================================================================
426 // Command Recording - ShaderFoundry manages command buffers
427 //==========================================================================
428
429 /**
430 * @brief Begin recording command buffer
431 * @param type Command buffer type (GRAPHICS, COMPUTE, TRANSFER)
432 * @return Command buffer ID
433 */
434 CommandBufferID begin_commands(CommandBufferType type);
435
436 /**
437 * @brief Begin recording a secondary command buffer for dynamic rendering
438 * @param color_format Format of the color attachment (from swapchain)
439 * @return Command buffer ID
440 *
441 * With dynamic rendering, secondary buffers don't need render pass objects.
442 * They only need to know the attachment formats they'll render to.
443 */
444 CommandBufferID begin_secondary_commands(
445 vk::Format color_format,
446 vk::Format depth_format = vk::Format::eUndefined);
447
448 /**
449 * @brief Get Vulkan command buffer handle from CommandBufferID
450 * @param cmd_id Command buffer ID
451 */
452 vk::CommandBuffer get_command_buffer(CommandBufferID cmd_id);
453
454 /**
455 * @brief End recording command buffer
456 * @param cmd_id Command buffer ID to end
457 * @return True if successful, false if invalid ID or not active
458 */
459 bool end_commands(CommandBufferID cmd_id);
460
461 /**
462 * @brief Free all allocated command buffers
463 */
464 void free_all_command_buffers();
465
466 //==========================================================================
467 // Memory Barriers and Synchronization
468 //==========================================================================
469
470 /**
471 * @brief Submit command buffer and wait for completion
472 * @param cmd_id Command buffer ID to submit
473 */
474 void submit_and_wait(CommandBufferID cmd_id);
475
476 /**
477 * @brief Submit command buffer asynchronously, returning a fence
478 * @param cmd_id Command buffer ID to submit
479 * @return Fence ID to wait on later
480 */
481 FenceID submit_async(CommandBufferID cmd_id);
482
483 /**
484 * @brief Submit command buffer asynchronously, returning a semaphore
485 * @param cmd_id Command buffer ID to submit
486 * @return Semaphore ID to wait on later
487 */
488 SemaphoreID submit_with_signal(CommandBufferID cmd_id);
489
490 /**
491 * @brief Wait for fence to be signaled
492 * @param fence_id Fence ID to wait on
493 */
494 void wait_for_fence(FenceID fence_id);
495
496 /**
497 * @brief Wait for multiple fences to be signaled
498 * @param fence_ids Vector of fence IDs to wait on
499 */
500 void wait_for_fences(const std::vector<FenceID>& fence_ids);
501
502 /**
503 * @brief Destroy the fence and free its associated command buffer.
504 *
505 * Must be called once per FenceID returned by submit_async, after
506 * is_fence_signaled returns true. Failure to call this leaks a VkFence
507 * and a command buffer slot every dispatch cycle.
508 *
509 * Safe to call with INVALID_FENCE.
510 *
511 * @param fence_id FenceID returned by submit_async.
512 */
513 void release_fence(FenceID fence_id);
514
515 /**
516 * @brief Check if fence is signaled
517 * @param fence_id Fence ID to check
518 * @return True if fence is signaled, false otherwise
519 */
520 bool is_fence_signaled(FenceID fence_id);
521
522 /**
523 * @brief Begin command buffer that waits on a semaphore
524 * @param type Command buffer type (GRAPHICS, COMPUTE, TRANSFER)
525 * @param wait_semaphore Semaphore ID to wait on
526 * @param wait_stage Pipeline stage to wait at
527 * @return Command buffer ID
528 */
529 CommandBufferID begin_commands_with_wait(
530 CommandBufferType type,
531 SemaphoreID wait_semaphore,
532 vk::PipelineStageFlags wait_stage);
533
534 /**
535 * @brief Get Vulkan fence handle from FenceID
536 * @param fence_id Fence ID
537 */
538 vk::Semaphore get_semaphore_handle(SemaphoreID semaphore_id);
539
540 /**
541 * @brief Insert buffer memory barrier
542 */
543 void buffer_barrier(
544 CommandBufferID cmd_id,
545 vk::Buffer buffer,
546 vk::AccessFlags src_access,
547 vk::AccessFlags dst_access,
548 vk::PipelineStageFlags src_stage,
549 vk::PipelineStageFlags dst_stage);
550
551 /**
552 * @brief Insert image memory barrier
553 */
554 void image_barrier(
555 CommandBufferID cmd_id,
556 vk::Image image,
557 vk::ImageLayout old_layout,
558 vk::ImageLayout new_layout,
559 vk::AccessFlags src_access,
560 vk::AccessFlags dst_access,
561 vk::PipelineStageFlags src_stage,
562 vk::PipelineStageFlags dst_stage);
563
564 //==========================================================================
565 // Queue Management
566 //==========================================================================
567
568 /**
569 * @brief Set Vulkan queues for command submission
570 */
571 void set_graphics_queue(vk::Queue queue);
572
573 /**
574 * @brief Set Vulkan queues for command submission
575 */
576 void set_compute_queue(vk::Queue queue);
577
578 /**
579 * @brief Set Vulkan queues for command submission
580 */
581 void set_transfer_queue(vk::Queue queue);
582
583 /**
584 * @brief Get Vulkan graphics queue
585 */
586 [[nodiscard]] vk::Queue get_graphics_queue() const;
587
588 /**
589 * @brief Get Vulkan compute queue
590 */
591 [[nodiscard]] vk::Queue get_compute_queue() const;
592
593 /**
594 * @brief Get Vulkan transfer queue
595 */
596 [[nodiscard]] vk::Queue get_transfer_queue() const;
597
598 //==========================================================================
599 // Profiling
600 //==========================================================================
601
602 void begin_timestamp(CommandBufferID cmd_id, const std::string& label = "");
603 void end_timestamp(CommandBufferID cmd_id, const std::string& label = "");
604
606 std::string label;
607 uint64_t duration_ns;
608 bool valid;
609 };
610
611 TimestampResult get_timestamp_result(CommandBufferID cmd_id, const std::string& label);
612
613 //==========================================================================
614 // Utilities
615 //==========================================================================
616
617 /**
618 * @brief Convert Portal ShaderStage to Vulkan ShaderStageFlagBits
619 */
620 static vk::ShaderStageFlagBits to_vulkan_stage(ShaderStage stage);
621
622 /**
623 * @brief Auto-detect shader stage from file extension
624 * @param filepath Path to shader file
625 * @return Detected stage, or nullopt if unknown
626 *
627 * Delegates to VKShaderModule::detect_stage_from_extension().
628 */
629 static std::optional<ShaderStage> detect_stage_from_extension(const std::string& filepath);
630
631 //==========================================================================
632 // Device Access
633 //==========================================================================
634
635 /**
636 * @brief Get logical device handle
637 */
638 [[nodiscard]] vk::Device get_device() const;
639
640 /**
641 * @brief Get physical device handle
642 *
643 * Required by consumers that allocate raw Vulkan buffers directly
644 * (e.g. GpuComputeOperation) and need memory type selection via
645 * vk::PhysicalDevice::getMemoryProperties().
646 */
647 [[nodiscard]] vk::PhysicalDevice get_physical_device() const;
648
649private:
650 /**
651 * @enum DetectedSourceType
652 * @brief Internal enum for source type detection
653 */
654 enum class DetectedSourceType : uint8_t {
655 FILE_GLSL,
656 FILE_SPIRV,
657 SOURCE_STRING,
658 UNKNOWN
659 };
660
661 ShaderFoundry() = default;
662 ~ShaderFoundry() { shutdown(); }
663
664 std::shared_ptr<Core::VulkanBackend> m_backend;
666
667 std::unordered_map<std::string, std::shared_ptr<Core::VKShaderModule>> m_shader_cache;
668 std::unordered_map<ShaderID, ShaderState> m_shaders;
669 std::unordered_map<std::string, ShaderID> m_shader_filepath_cache;
670
671 std::shared_ptr<Core::VKDescriptorManager> m_global_descriptor_manager;
672 std::unordered_map<DescriptorSetID, DescriptorSetState> m_descriptor_sets;
673
674 std::unordered_map<CommandBufferID, CommandBufferState> m_command_buffers;
675 std::unordered_map<FenceID, FenceState> m_fences;
676 std::unordered_map<SemaphoreID, SemaphoreState> m_semaphores;
677
681
682 std::atomic<uint64_t> m_next_shader_id { 1 };
683 std::atomic<uint64_t> m_next_descriptor_set_id { 1 };
684 std::atomic<uint64_t> m_next_command_id { 1 };
685 std::atomic<uint64_t> m_next_fence_id { 1 };
686 std::atomic<uint64_t> m_next_semaphore_id { 1 };
687
688 DetectedSourceType detect_source_type(const std::string& content) const;
689 std::optional<std::filesystem::path> resolve_shader_path(const std::string& filepath) const;
690 std::string generate_source_cache_key(const std::string& source, ShaderStage stage) const;
691
692 std::shared_ptr<Core::VKShaderModule> create_shader_module();
693
694 void cleanup_sync_objects();
695 void cleanup_descriptor_resources();
696 void cleanup_shader_modules();
697
698 //==========================================================================
699 // INTERNAL Shader Compilation Methods
700 //==========================================================================
701
702 std::shared_ptr<Core::VKShaderModule> compile_from_file(
703 const std::string& filepath,
704 std::optional<ShaderStage> stage = std::nullopt,
705 const std::string& entry_point = "main");
706
707 std::shared_ptr<Core::VKShaderModule> compile_from_source(
708 const std::string& source,
709 ShaderStage stage,
710 const std::string& entry_point = "main");
711
712 std::shared_ptr<Core::VKShaderModule> compile_from_source_cached(
713 const std::string& source,
714 ShaderStage stage,
715 const std::string& cache_key,
716 const std::string& entry_point = "main");
717
718 std::shared_ptr<Core::VKShaderModule> compile_from_spirv(
719 const std::string& spirv_path,
720 ShaderStage stage,
721 const std::string& entry_point = "main");
722
723 std::shared_ptr<Core::VKShaderModule> compile_from_spirv_asm(
724 const std::string& spirv_asm,
725 ShaderStage stage,
726 const std::string& entry_point = "main");
727
728 std::shared_ptr<Core::VKShaderModule> get_vk_shader_module(ShaderID shader_id);
729
730 friend class ComputePress;
731 friend class RenderFlow;
732
733 static bool s_initialized;
734};
735
736/**
737 * @brief Get the global shader compiler instance
738 * @return Reference to singleton shader compiler
739 *
740 * Must call initialize() before first use.
741 * Thread-safe after initialization.
742 */
743inline MAYAFLUX_API ShaderFoundry& get_shader_foundry()
744{
746}
747
748} // namespace MayaFlux::Portal::Graphics
IO::ImageData image
Definition Decoder.cpp:64
float value
float offset
Compute-specific pipeline and dispatch orchestration.
Graphics pipeline orchestration for dynamic rendering.
ShaderFoundry(const ShaderFoundry &)=delete
ShaderFoundry & operator=(const ShaderFoundry &)=delete
size_t get_cache_size() const
Get number of cached shaders.
void set_compute_queue(vk::Queue queue)
Set Vulkan queues for command submission.
DetectedSourceType
Internal enum for source type detection.
std::unordered_map< std::string, ShaderID > m_shader_filepath_cache
std::unordered_map< FenceID, FenceState > m_fences
void set_graphics_queue(vk::Queue queue)
Set Vulkan queues for command submission.
void set_transfer_queue(vk::Queue queue)
Set Vulkan queues for command submission.
ShaderFoundry(ShaderFoundry &&) noexcept=delete
std::unordered_map< std::string, std::shared_ptr< Core::VKShaderModule > > m_shader_cache
std::unordered_map< DescriptorSetID, DescriptorSetState > m_descriptor_sets
std::unordered_map< CommandBufferID, CommandBufferState > m_command_buffers
std::shared_ptr< Core::VKDescriptorManager > m_global_descriptor_manager
bool is_initialized() const
Check if compiler is initialized.
std::shared_ptr< Core::VulkanBackend > m_backend
std::unordered_map< SemaphoreID, SemaphoreState > m_semaphores
const ShaderCompilerConfig & get_config() const
Get current compiler configuration.
std::unordered_map< ShaderID, ShaderState > m_shaders
Portal-level shader compilation and caching.
void initialize()
Definition main.cpp:11
std::string emit_glsl_kernel(const ShaderSpec &spec)
Emit a complete GLSL compute shader from spec metadata and a KernelSource body.
std::string emit_spirv_asm(const ShaderSpec &spec)
Emit complete SPIR-V assembly text for a generated compute kernel.
void stop()
Stop all Portal::Graphics operations.
Definition Graphics.cpp:69
ShaderStage
User-friendly shader stage enum.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
constexpr CommandBufferID INVALID_COMMAND_BUFFER
@ GRAPHICS
Standard real-time graphics processing domain.
Definition Domain.hpp:55
Configuration for shader compilation.
std::unordered_map< std::string, uint32_t > timestamp_queries
std::shared_ptr< Core::VKShaderModule > std::string filepath
Extracted reflection information from compiled shader.
Shader source descriptor for compilation.
Complete declarative description of a generated compute shader.