MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
AggregateBindingsProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Nodes {
6class Node;
7}
8
9namespace MayaFlux::Buffers {
10
11/**
12 * @class AggregateBindingsProcessor
13 * @brief BufferProcessor that aggregates multiple node outputs into GPU buffers
14 *
15 * Collects outputs from multiple nodes and uploads them as contiguous arrays
16 * to GPU buffers. Supports multiple independent target buffers, each receiving
17 * aggregated data from a subset of nodes.
18 *
19 * Behavior:
20 * - Uploads ALL registered aggregates to their target buffers
21 * - If attached buffer is one of the targets, it receives its aggregate
22 * - If attached buffer is NOT a target, it receives the first aggregate
23 *
24 * Usage:
25 * auto velocity_buffer = std::make_shared<VKBuffer>(1000 * sizeof(float), ...);
26 * auto aggregate = std::make_shared<AggregateBindingsProcessor>();
27 *
28 * // Add nodes to "velocities" aggregate
29 * for (int i = 0; i < 1000; i++) {
30 * aggregate->add_node("velocities", velocity_node, velocity_buffer);
31 * }
32 *
33 * velocity_buffer->set_default_processor(aggregate);
34 * velocity_buffer->process_default(); // Uploads all aggregates
35 */
36class MAYAFLUX_API AggregateBindingsProcessor : public VKBufferProcessor {
37public:
38 enum class ProcessingMode : uint8_t {
39 INTERNAL, ///< Processor calls extract_single_sample() or processes node context
40 EXTERNAL ///< Processor reads node's current state (get_last_output/get_last_context)
41 };
42
44 std::vector<std::shared_ptr<Nodes::Node>> nodes;
45 std::shared_ptr<VKBuffer> target_buffer;
46 std::vector<float> staging_data;
47 std::atomic<ProcessingMode> processing_mode { ProcessingMode::INTERNAL };
48 };
49
50 /**
51 * @brief Default constructor
52 */
54
55 /**
56 * @brief Add a node to a named aggregate
57 * @param aggregate_name Name of the aggregate group
58 * @param node Node to add
59 * @param target Target buffer for this aggregate
60 * @param mode Processing mode for this aggregate (default: INTERNAL)
61 *
62 * Nodes with the same aggregate_name are grouped together and uploaded
63 * to the same target buffer. Nodes are ordered by insertion.
64 */
65 void add_node(
66 const std::string& aggregate_name,
67 const std::shared_ptr<Nodes::Node>& node,
68 const std::shared_ptr<VKBuffer>& target,
69 ProcessingMode mode = ProcessingMode::INTERNAL);
70
71 /**
72 * @brief Remove a node from an aggregate
73 * @param aggregate_name Name of the aggregate group
74 * @param node Node to remove
75 */
76 void remove_node(
77 const std::string& aggregate_name,
78 const std::shared_ptr<Nodes::Node>& node);
79
80 /**
81 * @brief Clear all nodes from an aggregate
82 * @param aggregate_name Name of the aggregate group
83 */
84 void clear_aggregate(const std::string& aggregate_name);
85
86 /**
87 * @brief Clear all aggregates
88 */
89 void clear_all_aggregates();
90
91 /**
92 * @brief Get number of nodes in an aggregate
93 * @param aggregate_name Name of the aggregate group
94 * @return Node count (0 if aggregate doesn't exist)
95 */
96 [[nodiscard]] size_t get_node_count(const std::string& aggregate_name) const;
97
98 /**
99 * @brief Get total number of nodes across all aggregates
100 * @return Total node count
101 */
102 [[nodiscard]] size_t get_total_node_count() const;
103
104 /**
105 * @brief Get all aggregate names
106 * @return Vector of aggregate names
107 */
108 [[nodiscard]] std::vector<std::string> get_aggregate_names() const;
109
110 /**
111 * @brief Get number of aggregates
112 * @return Aggregate count
113 */
114 [[nodiscard]] size_t get_aggregate_count() const;
115
116 /**
117 * @brief BufferProcessor interface - uploads all aggregates
118 * @param buffer The buffer this processor is attached to
119 */
120 void processing_function(const std::shared_ptr<Buffer>& buffer) override;
121
122private:
123 std::unordered_map<std::string, AggregateBinding> m_aggregates;
124};
125
126} // namespace MayaFlux::Buffers
AggregateBindingsProcessor()=default
Default constructor.
std::unordered_map< std::string, AggregateBinding > m_aggregates
BufferProcessor that aggregates multiple node outputs into GPU buffers.
Contains the node-based computational processing system components.
Definition Chronie.hpp:11