MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
DescriptorBuffer.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Buffers {
7
8/**
9 * @class DescriptorBuffer
10 * @brief Specialized buffer for shader parameter bindings from nodes
11 *
12 * Binds node outputs to shader uniforms and storage buffers.
13 * Designed for parameterizing shaders with live data: time, frequencies,
14 * control values, arrays, matrices, etc.
15 *
16 * Philosophy:
17 * - Shaders are controlled by DATA, not hardcoded values
18 * - Any node can drive any shader parameter
19 * - Cross-domain flow: audio nodes → visual shader parameters
20 *
21 * Usage:
22 * ShaderProcessorConfig config;
23 * config.shader_path = "parametric.comp";
24 * config.bindings = {
25 * {"time", {.binding = 0, .type = vk::DescriptorType::eUniformBuffer}},
26 * {"spectrum", {.binding = 1, .type = vk::DescriptorType::eStorageBuffer}}
27 * };
28 *
29 * auto buffer = std::make_shared<DescriptorBuffer>(config);
30 * buffer->bind_scalar("time", time_node, "time");
31 * buffer->bind_vector("spectrum", fft_node, "spectrum");
32 *
33 * auto compute = std::make_shared<ComputeProcessor>(config);
34 * buffer->add_processor(compute) | Graphics;
35 */
36class MAYAFLUX_API DescriptorBuffer : public VKBuffer {
37public:
38 /**
39 * @brief Create descriptor buffer with shader configuration
40 * @param config Shader processor configuration with binding definitions
41 * @param initial_size Initial buffer size (will grow as needed)
42 */
43 explicit DescriptorBuffer(
44 const ShaderProcessorConfig& config,
45 size_t initial_size = 4096);
46
47 ~DescriptorBuffer() override = default;
48
49 /**
50 * @brief Initialize the buffer and its processors
51 */
52 void initialize();
53
54 /**
55 * @brief Bind scalar node output to uniform/SSBO
56 * @param name Logical binding name
57 * @param node Node providing scalar value
58 * @param descriptor_name Name in shader config bindings
59 * @param set Descriptor set index (default: 0)
60 */
61 void bind_scalar(
62 const std::string& name,
63 const std::shared_ptr<Nodes::Node>& node,
64 const std::string& descriptor_name,
65 uint32_t set = 0);
66
67 /**
68 * @brief Bind vector node output to SSBO
69 * @param name Logical binding name
70 * @param node Node providing vector data (via VectorContext)
71 * @param descriptor_name Name in shader config bindings
72 * @param set Descriptor set index (default: 0)
73 */
74 void bind_vector(
75 const std::string& name,
76 const std::shared_ptr<Nodes::Node>& node,
77 const std::string& descriptor_name,
78 uint32_t set = 0);
79
80 /**
81 * @brief Bind matrix node output to SSBO
82 * @param name Logical binding name
83 * @param node Node providing matrix data (via MatrixContext)
84 * @param descriptor_name Name in shader config bindings
85 * @param set Descriptor set index (default: 0)
86 */
87 void bind_matrix(
88 const std::string& name,
89 const std::shared_ptr<Nodes::Node>& node,
90 const std::string& descriptor_name,
91 uint32_t set = 0);
92
93 /**
94 * @brief Bind structured node output to SSBO
95 * @param name Logical binding name
96 * @param node Node providing structured data
97 * @param descriptor_name Name in shader config bindings
98 * @param set Descriptor set index (default: 0)
99 */
100 void bind_structured(
101 const std::string& name,
102 const std::shared_ptr<Nodes::Node>& node,
103 const std::string& descriptor_name,
104 uint32_t set = 0);
105
106 /**
107 * @brief Remove a binding
108 */
109 void unbind(const std::string& name);
110
111 /**
112 * @brief Get the bindings processor
113 */
114 [[nodiscard]] std::shared_ptr<DescriptorBindingsProcessor> get_bindings_processor() const
115 {
116 return m_bindings_processor;
117 }
118
119 /**
120 * @brief Get all binding names
121 */
122 [[nodiscard]] std::vector<std::string> get_binding_names() const;
123
124private:
125 std::shared_ptr<DescriptorBindingsProcessor> m_bindings_processor;
127};
128
129} // namespace MayaFlux::Buffers
std::shared_ptr< DescriptorBindingsProcessor > m_bindings_processor
std::shared_ptr< DescriptorBindingsProcessor > get_bindings_processor() const
Get the bindings processor.
~DescriptorBuffer() override=default
Specialized buffer for shader parameter bindings from nodes.
Vulkan-backed buffer wrapper used in processing chains.
Definition VKBuffer.hpp:52
void initialize()
Definition main.cpp:11
Complete configuration for shader processor.