MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ShaderUtils.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "vulkan/vulkan.hpp"
4
5#include "GraphicsUtils.hpp"
6
8
9namespace MayaFlux::Core {
10struct VertexBinding;
11struct VertexAttribute;
12}
13
15
16using ShaderID = uint64_t;
17using DescriptorSetID = uint64_t;
18using CommandBufferID = uint64_t;
19using FenceID = uint64_t;
20using SemaphoreID = uint64_t;
21using RenderPipelineID = uint64_t;
22using FramebufferID = uint64_t;
23
27constexpr FenceID INVALID_FENCE = 0;
31
32/**
33 * @struct ShaderCompilerConfig
34 * @brief Configuration for shader compilation
35 */
38 bool enable_debug_info = false; ///< Include debug symbols (line numbers, variable names)
39 bool enable_reflection = true; ///< Extract descriptor bindings and metadata
40 bool enable_validation = true; ///< Validate SPIR-V after compilation
41 std::vector<std::string> include_directories; ///< Paths for #include resolution
42 std::unordered_map<std::string, std::string> defines; ///< Preprocessor macros
43
45};
46
47/**
48 * @struct ShaderSource
49 * @brief Shader source descriptor for compilation
50 */
52 std::string content; ///< Shader source code or SPIR-V path
54 std::string entry_point = "main";
55
56 enum class SourceType : uint8_t {
57 GLSL_STRING, ///< In-memory GLSL source
58 GLSL_FILE, ///< Path to .comp/.vert/.frag/etc
59 SPIRV_FILE ///< Path to .spv file
60 } type
62
63 ShaderSource() = default;
64 ShaderSource(std::string content_, ShaderStage stage_, SourceType type_)
65 : content(std::move(content_))
66 , stage(stage_)
67 , type(type_)
68 {
69 }
70};
71
72/**
73 * @enum DescriptorRole
74 * @brief Semantic descriptor type — maps to Vulkan descriptor types internally.
75 *
76 * Users declare what role a binding plays rather than which Vulkan type to use.
77 * The mapping is:
78 * UNIFORM → vk::DescriptorType::eUniformBuffer (small, frequently updated values)
79 * STORAGE → vk::DescriptorType::eStorageBuffer (large or write-capable arrays)
80 * TEXTURE → vk::DescriptorType::eCombinedImageSampler (sampled image + sampler)
81 * STORAGE_IMAGE → vk::DescriptorType::eStorageImage (compute read/write image)
82 */
83enum class DescriptorRole : uint8_t {
84 UNIFORM, ///< Small, read-only, frequently updated (scalars, param structs)
85 STORAGE, ///< Large arrays or buffers the shader may write (SSBO)
86 TEXTURE, ///< Sampled image + sampler combined
87 STORAGE_IMAGE ///< Compute-writable image
88};
89
90/**
91 * @brief Convert DescriptorRole to the corresponding vk::DescriptorType.
92 */
93[[nodiscard]] inline vk::DescriptorType to_vk_descriptor_type(DescriptorRole role)
94{
95 switch (role) {
97 return vk::DescriptorType::eUniformBuffer;
99 return vk::DescriptorType::eStorageBuffer;
101 return vk::DescriptorType::eCombinedImageSampler;
103 return vk::DescriptorType::eStorageImage;
104 }
105 return vk::DescriptorType::eStorageBuffer;
106}
107
108/**
109 * @struct DescriptorBindingConfig
110 * @brief Portal-level descriptor binding configuration
111 */
113 uint32_t set {};
114 uint32_t binding {};
115 vk::DescriptorType type = vk::DescriptorType::eStorageBuffer;
116 vk::DescriptorBufferInfo buffer_info;
117 std::string name;
118};
119
120/**
121 * @struct PushConstantRangeInfo
122 * @brief Extracted push constant range from shader reflection
123 */
125 uint32_t offset;
126 uint32_t size;
127};
128
129/**
130 * @struct ShaderReflectionInfo
131 * @brief Extracted reflection information from compiled shader
132 */
135 std::string entry_point;
136 std::optional<std::array<uint32_t, 3>> workgroup_size;
137 std::vector<DescriptorBindingInfo> descriptor_bindings;
138 std::vector<PushConstantRangeInfo> push_constant_ranges;
139};
140
141/**
142 * @struct RasterizationConfig
143 * @brief Rasterization state configuration
144 */
155
156/**
157 * @struct DepthStencilConfig
158 * @brief Depth and stencil test configuration
159 */
168
169/**
170 * @struct BlendAttachmentConfig
171 * @brief Per-attachment blend configuration
172 */
196
197/**
198 * @struct RenderPipelineConfig
199 * @brief Complete render pipeline configuration
200 */
202 // Shader stages
210
211 // Vertex input
212 std::vector<Core::VertexBinding> vertex_bindings;
213 std::vector<Core::VertexAttribute> vertex_attributes;
214
215 // Input assembly
217
218 // Optional semantic vertex layout
219 std::optional<Kakshya::VertexLayout> semantic_vertex_layout;
220
221 // Use reflection to auto-configure from vertex shader
223
224 // Rasterization
226
227 // Depth/stencil
229
230 // Blend
231 std::vector<BlendAttachmentConfig> blend_attachments;
232
233 // Descriptor sets (similar to compute)
234 std::vector<std::vector<DescriptorBindingInfo>> descriptor_sets;
235
236 // Push constants
238
240};
241
242} // namespace MayaFlux::Portal::Graphics
PolygonMode
Rasterization polygon mode.
constexpr RenderPipelineID INVALID_RENDER_PIPELINE
constexpr ShaderID INVALID_SHADER
ShaderStage
User-friendly shader stage enum.
constexpr FenceID INVALID_FENCE
DescriptorRole
Semantic descriptor type — maps to Vulkan descriptor types internally.
@ STORAGE_IMAGE
Compute-writable image.
@ TEXTURE
Sampled image + sampler combined.
@ STORAGE
Large arrays or buffers the shader may write (SSBO)
@ UNIFORM
Small, read-only, frequently updated (scalars, param structs)
constexpr FramebufferID INVALID_FRAMEBUFFER
BlendOp
Blending operation.
PrimitiveTopology
Vertex assembly primitive topology.
vk::DescriptorType to_vk_descriptor_type(DescriptorRole role)
Convert DescriptorRole to the corresponding vk::DescriptorType.
CompareOp
Depth/stencil comparison operation.
constexpr DescriptorSetID INVALID_DESCRIPTOR_SET
constexpr SemaphoreID INVALID_SEMAPHORE
constexpr CommandBufferID INVALID_COMMAND_BUFFER
static BlendAttachmentConfig alpha_blend()
Create standard alpha blending configuration.
Per-attachment blend configuration.
Depth and stencil test configuration.
Extracted push constant range from shader reflection.
Rasterization state configuration.
std::vector< std::vector< DescriptorBindingInfo > > descriptor_sets
std::vector< Core::VertexAttribute > vertex_attributes
std::vector< Core::VertexBinding > vertex_bindings
std::optional< Kakshya::VertexLayout > semantic_vertex_layout
std::vector< BlendAttachmentConfig > blend_attachments
Complete render pipeline configuration.
bool enable_reflection
Extract descriptor bindings and metadata.
std::vector< std::string > include_directories
Paths for #include resolution.
bool enable_debug_info
Include debug symbols (line numbers, variable names)
bool enable_validation
Validate SPIR-V after compilation.
std::unordered_map< std::string, std::string > defines
Preprocessor macros.
Configuration for shader compilation.
std::optional< std::array< uint32_t, 3 > > workgroup_size
std::vector< PushConstantRangeInfo > push_constant_ranges
std::vector< DescriptorBindingInfo > descriptor_bindings
Extracted reflection information from compiled shader.
std::string content
Shader source code or SPIR-V path.
enum MayaFlux::Portal::Graphics::ShaderSource::SourceType type
ShaderSource(std::string content_, ShaderStage stage_, SourceType type_)
Shader source descriptor for compilation.