MayaFlux 0.2.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(const ShaderConfig& config, size_t initial_size = 4096);
44
45 ~DescriptorBuffer() override = default;
46
47 /**
48 * @brief Initialize the buffer and its processors
49 */
50 void initialize();
51
52 /**
53 * @brief Bind scalar node output to uniform/SSBO
54 * @param name Logical binding name
55 * @param node Node providing scalar value
56 * @param descriptor_name Name in shader config bindings
57 * @param set Descriptor set index (default: 0)
58 */
59 void bind_scalar(
60 const std::string& name,
61 const std::shared_ptr<Nodes::Node>& node,
62 const std::string& descriptor_name,
63 uint32_t set = 0);
64
65 /**
66 * @brief Bind vector node output to SSBO
67 * @param name Logical binding name
68 * @param node Node providing vector data (via VectorContext)
69 * @param descriptor_name Name in shader config bindings
70 * @param set Descriptor set index (default: 0)
71 */
72 void bind_vector(
73 const std::string& name,
74 const std::shared_ptr<Nodes::Node>& node,
75 const std::string& descriptor_name,
76 uint32_t set = 0);
77
78 /**
79 * @brief Bind matrix node output to SSBO
80 * @param name Logical binding name
81 * @param node Node providing matrix data (via MatrixContext)
82 * @param descriptor_name Name in shader config bindings
83 * @param set Descriptor set index (default: 0)
84 */
85 void bind_matrix(
86 const std::string& name,
87 const std::shared_ptr<Nodes::Node>& node,
88 const std::string& descriptor_name,
89 uint32_t set = 0);
90
91 /**
92 * @brief Bind structured node output to SSBO
93 * @param name Logical binding name
94 * @param node Node providing structured data
95 * @param descriptor_name Name in shader config bindings
96 * @param set Descriptor set index (default: 0)
97 */
98 void bind_structured(
99 const std::string& name,
100 const std::shared_ptr<Nodes::Node>& node,
101 const std::string& descriptor_name,
102 uint32_t set = 0);
103
104 /**
105 * @brief Remove a binding
106 */
107 void unbind(const std::string& name);
108
109 /**
110 * @brief Get the bindings processor
111 */
112 [[nodiscard]] std::shared_ptr<DescriptorBindingsProcessor> get_bindings_processor() const
113 {
114 return m_bindings_processor;
115 }
116
117 /**
118 * @brief Get all binding names
119 */
120 [[nodiscard]] std::vector<std::string> get_binding_names() const;
121
122private:
123 std::shared_ptr<DescriptorBindingsProcessor> m_bindings_processor;
125};
126
127} // 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