MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GraphicsUtils.hpp
Go to the documentation of this file.
1#pragma once
2
3namespace MayaFlux::Core {
4class Window;
5class VKImage;
6}
7
9
10//============================================================================
11// Primitive Topology
12//============================================================================
13
14/**
15 * @enum PrimitiveTopology
16 * @brief Vertex assembly primitive topology
17 *
18 * Used to configure how vertices are assembled into primitives
19 * before rasterization.
20 */
29
30//============================================================================
31// Rasterization
32//============================================================================
33
34/**
35 * @enum PolygonMode
36 * @brief Rasterization polygon mode
37 */
38enum class PolygonMode : uint8_t {
39 FILL,
40 LINE,
41 POINT
42};
43
44/**
45 * @enum CullMode
46 * @brief Face culling mode
47 */
48enum class CullMode : uint8_t {
49 NONE,
50 FRONT,
51 BACK,
53};
54
55//============================================================================
56// Depth/Stencil
57//============================================================================
58
59/**
60 * @enum CompareOp
61 * @brief Depth/stencil comparison operation
62 */
63enum class CompareOp : uint8_t {
64 NEVER,
65 LESS,
66 EQUAL,
68 GREATER,
71 ALWAYS
72};
73
74//============================================================================
75// Blending
76//============================================================================
77
78/**
79 * @enum BlendFactor
80 * @brief Blending factor
81 */
94
95/**
96 * @enum BlendOp
97 * @brief Blending operation
98 */
99enum class BlendOp : uint8_t {
100 ADD,
101 SUBTRACT,
103 MIN,
104 MAX
105};
106
107//============================================================================
108// GPU Buffer Bindings
109//============================================================================
110
111/**
112 * @enum BufferUsageHint
113 * @brief Semantic usage hint for buffer allocation and memory properties
114 *
115 * This enum describes the intended usage pattern of a buffer, which informs
116 * the graphics backend how to allocate memory and set Vulkan usage flags.
117 * It is not a direct mapping to Vulkan flags, but rather a higher-level
118 * abstraction for common use cases.
119 */
120enum class BufferUsageHint : uint8_t {
121 STAGING, ///< Host-visible staging buffer (CPU-writable, eTransferSrc|Dst)
122 DEVICE, ///< Device-local GPU-only buffer
123 COMPUTE, ///< Storage buffer for compute shaders (device-local)
124 VERTEX, ///< Vertex buffer
125 INDEX, ///< Index buffer
126 UNIFORM, ///< Uniform buffer (host-visible)
127 UNIFORM_BDA, ///< Uniform buffer with device address query support
128 STORAGE_BDA, ///< Storage buffer with device address query support
129 INDIRECT, ///< Indirect draw/dispatch buffer (device-local)
130 HOST_STORAGE, ///< Host-visible storage buffer (eStorageBuffer + eHostVisible|eHostCoherent)
131 COMPUTE_STORAGE, ///< Bare eStorageBuffer, no transfer flags. GpuResourceManager's host-visible/host-coherent compute buffers.
132};
133
134/**
135 * @struct GpuBufferBinding
136 * @brief Declares a single storage buffer or image binding a compute shader expects.
137 *
138 * Vulkan-agnostic description consumed by ComputePress/ShaderFoundry to
139 * derive descriptor types, barrier targets, and staging behavior. Carries
140 * no vk:: types itself; translation to vk::DescriptorType happens at the
141 * point of use.
142 */
144 uint32_t set { 0 }; ///< Descriptor set index.
145 uint32_t binding { 0 }; ///< Binding index within the set.
146 bool skip_auto_readback { false }; ///< Skip automatic CPU readback after dispatch for this binding.
147
148 /**
149 * @enum Direction
150 * @brief Data flow direction for this binding.
151 *
152 * INPUT_OUTPUT bindings receive a cross-pass memory barrier when used
153 * across multiple recorded dispatches in one command buffer (see
154 * ComputePress::record_sequence), since the same resource is both
155 * read and written by consecutive stages.
156 */
157 enum class Direction : uint8_t {
158 INPUT,
159 OUTPUT,
161 } direction { Direction::INPUT };
162
163 /**
164 * @enum ElementType
165 * @brief Element type the shader expects in this binding.
166 *
167 * FLOAT32 — cast double channels to float (default).
168 * UINT32 — reinterpret variant bytes as uint32_t.
169 * INT32 — reinterpret variant bytes as int32_t.
170 * PASSTHROUGH — upload raw variant bytes with no cast; caller
171 * must pre-stage for INPUT / INPUT_OUTPUT bindings.
172 * IMAGE_STORAGE — writeonly/readonly image2D, storage image descriptor.
173 * IMAGE_SAMPLED — sampler2D, combined image sampler descriptor.
174 */
175 enum class ElementType : uint8_t {
176 FLOAT32,
177 UINT32,
178 INT32,
182 } element_type { ElementType::FLOAT32 };
183
184 BufferUsageHint usage_hint { BufferUsageHint::COMPUTE_STORAGE }; ///< Hint for buffer allocation and memory properties.
185};
186
187/**
188 * @brief Byte width of one GpuBufferBinding::ElementType element.
189 *
190 * Bridges to Kakshya::gpu_data_format_bytes for FLOAT32/UINT32/INT32,
191 * the single authoritative sizing source. Returns 0 for PASSTHROUGH,
192 * IMAGE_STORAGE, and IMAGE_SAMPLED, which carry no fixed element width.
193 *
194 * @param et ElementType to size.
195 * @return Byte width, or 0 if unsized.
196 */
197[[nodiscard]] size_t element_type_bytes(GpuBufferBinding::ElementType et) noexcept;
198
199//============================================================================
200// Shader Types
201//============================================================================
202
203/**
204 * @enum ShaderStage
205 * @brief User-friendly shader stage enum
206 *
207 * Abstracts vk::ShaderStageFlagBits for Portal API convenience.
208 * Maps directly to Vulkan stages internally.
209 */
210enum class ShaderStage : uint8_t {
211 COMPUTE,
212 VERTEX,
213 FRAGMENT,
214 GEOMETRY,
217 MESH,
218 TASK
219};
220
221//============================================================================
222// Image Helpers
223//============================================================================
224
225/**
226 * @enum ImageFormat
227 * @brief User-friendly image format enum
228 *
229 * Abstracts Vulkan formats for Portal API convenience.
230 * Maps to vk::Format internally.
231 */
232enum class ImageFormat : uint8_t {
233 // Normalized formats
234 R8, ///< Single channel 8-bit
235 RG8, ///< Two channel 8-bit
236 RGB8, ///< Three channel 8-bit
237 RGBA8, ///< Four channel 8-bit
238 RGBA8_SRGB, ///< Four channel 8-bit sRGB
239
240 BGRA8, ///< 8-bit BGRA unsigned normalized
241 BGRA8_SRGB, ///< 8-bit BGRA sRGB
242
243 // Floating point formats
244 R16F, ///< Single channel 16-bit float
245 RG16F, ///< Two channel 16-bit float
246 RGBA16F, ///< Four channel 16-bit float
247 R32F, ///< Single channel 32-bit float
248 RG32F, ///< Two channel 32-bit float
249 RGBA32F, ///< Four channel 32-bit float
250
251 R16, ///< Single channel 16-bit unsigned integer
252 RG16, ///< Two channel 16-bit unsigned integer
253 RGBA16, ///< Four channel 16-bit unsigned integer
254
255 // Depth/stencil formats
256 DEPTH16, ///< 16-bit depth
257 DEPTH24, ///< 24-bit depth
258 DEPTH32F, ///< 32-bit float depth
259 DEPTH24_STENCIL8 ///< 24-bit depth + 8-bit stencil
260};
261
262/**
263 * @enum FilterMode
264 * @brief Texture filtering mode
265 */
266enum class FilterMode : uint8_t {
267 NEAREST, ///< Nearest neighbor (pixelated)
268 LINEAR, ///< Bilinear filtering (smooth)
269 CUBIC ///< Bicubic filtering (high quality, slower)
270};
271
272/**
273 * @enum AddressMode
274 * @brief Texture addressing mode (wrapping)
275 */
276enum class AddressMode : uint8_t {
277 REPEAT, ///< Repeat texture
278 MIRRORED_REPEAT, ///< Mirror and repeat
279 CLAMP_TO_EDGE, ///< Clamp to edge color
280 CLAMP_TO_BORDER ///< Clamp to border color
281};
282
283/**
284 * @struct SamplerConfig
285 * @brief Sampler configuration
286 */
296
297/**
298 * @struct RenderConfig
299 * @brief Unified rendering configuration for graphics buffers
300 *
301 * This is the persistent state that processors query and react to.
302 * All rendering parameters in one place, independent of buffer type.
303 * Child buffer classes populate it with context-specific defaults
304 * during construction, then expose it to their processors.
305 *
306 * Design:
307 * - Owned by VKBuffer as persistent state
308 * - Processors query and react to changes
309 * - Child classes have their own convenience RenderConfig with defaults
310 * that bridge to this Portal-level config
311 */
313 std::shared_ptr<Core::Window> target_window;
314 std::string vertex_shader;
315 std::string fragment_shader;
316 std::string geometry_shader;
321
322 std::vector<std::pair<std::string, std::shared_ptr<Core::VKImage>>> additional_textures;
323
324 ///< For child-specific fields
325 std::unordered_map<std::string, std::string> extra_string_params;
326
327 bool operator==(const RenderConfig& other) const = default;
328};
329
330}
PolygonMode
Rasterization polygon mode.
size_t element_type_bytes(GpuBufferBinding::ElementType et) noexcept
Byte width of one GpuBufferBinding::ElementType element.
AddressMode
Texture addressing mode (wrapping)
@ CLAMP_TO_BORDER
Clamp to border color.
ShaderStage
User-friendly shader stage enum.
FilterMode
Texture filtering mode.
@ LINEAR
Bilinear filtering (smooth)
@ NEAREST
Nearest neighbor (pixelated)
@ CUBIC
Bicubic filtering (high quality, slower)
BlendOp
Blending operation.
ImageFormat
User-friendly image format enum.
@ DEPTH24_STENCIL8
24-bit depth + 8-bit stencil
@ RG16
Two channel 16-bit unsigned integer.
@ BGRA8
8-bit BGRA unsigned normalized
@ RGBA16
Four channel 16-bit unsigned integer.
@ RGBA32F
Four channel 32-bit float.
@ R16F
Single channel 16-bit float.
@ R16
Single channel 16-bit unsigned integer.
@ RGBA16F
Four channel 16-bit float.
@ RG32F
Two channel 32-bit float.
@ R32F
Single channel 32-bit float.
@ RG16F
Two channel 16-bit float.
@ RGBA8_SRGB
Four channel 8-bit sRGB.
BufferUsageHint
Semantic usage hint for buffer allocation and memory properties.
@ STORAGE_BDA
Storage buffer with device address query support.
@ HOST_STORAGE
Host-visible storage buffer (eStorageBuffer + eHostVisible|eHostCoherent)
@ INDIRECT
Indirect draw/dispatch buffer (device-local)
@ UNIFORM
Uniform buffer (host-visible)
@ COMPUTE
Storage buffer for compute shaders (device-local)
@ STAGING
Host-visible staging buffer (CPU-writable, eTransferSrc|Dst)
@ UNIFORM_BDA
Uniform buffer with device address query support.
@ COMPUTE_STORAGE
Bare eStorageBuffer, no transfer flags. GpuResourceManager's host-visible/host-coherent compute buffe...
@ DEVICE
Device-local GPU-only buffer.
PrimitiveTopology
Vertex assembly primitive topology.
CompareOp
Depth/stencil comparison operation.
ElementType
Element type the shader expects in this binding.
Direction
Data flow direction for this binding.
BufferUsageHint usage_hint
Hint for buffer allocation and memory properties.
enum MayaFlux::Portal::Graphics::GpuBufferBinding::Direction INPUT
bool skip_auto_readback
Skip automatic CPU readback after dispatch for this binding.
uint32_t binding
Binding index within the set.
enum MayaFlux::Portal::Graphics::GpuBufferBinding::ElementType FLOAT32
Declares a single storage buffer or image binding a compute shader expects.
std::shared_ptr< Core::Window > target_window
std::unordered_map< std::string, std::string > extra_string_params
std::vector< std::pair< std::string, std::shared_ptr< Core::VKImage > > > additional_textures
For child-specific fields.
bool operator==(const RenderConfig &other) const =default
Unified rendering configuration for graphics buffers.