MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ComputeService.hpp
Go to the documentation of this file.
1#pragma once
2
4
5/**
6 * @brief Backend compute shader and pipeline service interface
7 *
8 * Defines GPU compute operations for data-parallel processing.
9 * Supports shader compilation, descriptor management, and compute dispatch.
10 *
11 * Typical Workflow:
12 * 1. create_shader_module() -> ShaderHandle
13 * 2. create_descriptor_manager() -> DescriptorManagerHandle
14 * 3. create_descriptor_layout() -> DescriptorLayoutHandle
15 * 4. create_compute_pipeline() -> PipelineHandle
16 * 5. dispatch_compute() -> execute shader
17 * 6. cleanup_resource() -> cleanup when done
18 */
19struct MAYAFLUX_API ComputeService {
20 /**
21 * @brief Create a shader module from compiled shader code
22 * @param spirv_path Path to shader file (SPIR-V or backend-specific format)
23 * @param stage Shader stage flags (compute, vertex, fragment, etc.)
24 * @return Opaque shader module handle
25 *
26 * For Vulkan: SPIR-V bytecode (.spv files)
27 * For OpenGL: GLSL source code
28 * For Metal: .metallib or source
29 * For DirectX: DXIL or HLSL
30 */
31 std::function<std::shared_ptr<void>(const std::string&, uint32_t)> create_shader_module;
32
33 /**
34 * @brief Create a descriptor set manager/pool
35 * @param pool_size Maximum number of descriptor sets to allocate
36 * @return Opaque descriptor manager handle
37 *
38 * Manages allocation of descriptor sets. Pool size determines
39 * maximum concurrent allocations before reset/reallocation needed.
40 */
41 std::function<std::shared_ptr<void>(uint32_t)> create_descriptor_manager;
42
43 /**
44 * @brief Create a descriptor set layout
45 * @param manager Descriptor manager handle
46 * @param bindings Vector of (binding index, descriptor type) pairs
47 * @return Opaque descriptor layout handle
48 *
49 * Defines the structure of shader resource bindings.
50 * Descriptor type values are backend-specific:
51 * - Vulkan: VK_DESCRIPTOR_TYPE_* enum values
52 * - OpenGL: GL_UNIFORM_BUFFER, GL_SHADER_STORAGE_BUFFER, etc.
53 *
54 * Example bindings:
55 * {0, UNIFORM_BUFFER}, // binding 0: uniform buffer
56 * {1, STORAGE_BUFFER}, // binding 1: storage buffer
57 * {2, COMBINED_IMAGE_SAMPLER} // binding 2: texture
58 */
59 std::function<void*(const std::shared_ptr<void>&, const std::vector<std::pair<uint32_t, uint32_t>>&)> create_descriptor_layout;
60
61 /**
62 * @brief Create a compute pipeline
63 * @param shader Compute shader module handle
64 * @param layouts Vector of descriptor set layout handles
65 * @param push_constant_size Size of push constants in bytes (0 if unused)
66 * @return Opaque compute pipeline handle
67 *
68 * Combines shader code with resource layout to create executable pipeline.
69 * Multiple descriptor set layouts enable logical grouping of resources.
70 * Push constants provide fast, small data updates without descriptor sets.
71 */
72 std::function<std::shared_ptr<void>(const std::shared_ptr<void>&, const std::vector<void*>&, uint32_t)> create_compute_pipeline;
73
74 /**
75 * @brief Dispatch a compute shader execution
76 * @param pipeline Compute pipeline to execute
77 * @param group_count_x Number of workgroups in X dimension
78 * @param group_count_y Number of workgroups in Y dimension
79 * @param group_count_z Number of workgroups in Z dimension
80 *
81 * Executes compute shader with specified workgroup counts.
82 * Total invocations = (group_count_x * local_size_x) *
83 * (group_count_y * local_size_y) *
84 * (group_count_z * local_size_z)
85 *
86 * Must be called within a command recording context
87 * (execute_immediate or record_deferred from IBufferService).
88 */
89 std::function<void(const std::shared_ptr<void>&, uint32_t, uint32_t, uint32_t)> dispatch_compute;
90
91 /**
92 * @brief Cleanup a compute resource
93 * @param resource Opaque resource handle (shader, pipeline, layout, etc.)
94 *
95 * Safe to call with any compute resource type. Implementation determines
96 * actual resource type and performs appropriate cleanup. No-op for
97 * invalid/null handles.
98 */
99 std::function<void(const std::shared_ptr<void>&)> cleanup_resource;
100};
101
102} // namespace MayaFlux::Registry::Services
std::function< std::shared_ptr< void >(const std::shared_ptr< void > &, const std::vector< void * > &, uint32_t)> create_compute_pipeline
Create a compute pipeline.
std::function< std::shared_ptr< void >(const std::string &, uint32_t)> create_shader_module
Create a shader module from compiled shader code.
std::function< void(const std::shared_ptr< void > &, uint32_t, uint32_t, uint32_t)> dispatch_compute
Dispatch a compute shader execution.
std::function< std::shared_ptr< void >(uint32_t)> create_descriptor_manager
Create a descriptor set manager/pool.
std::function< void(const std::shared_ptr< void > &)> cleanup_resource
Cleanup a compute resource.
Backend compute shader and pipeline service interface.