MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
NodeBindingsProcessor.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 NodeBindingsProcessor
13 * @brief ShaderProcessor with automatic node-to-push-constant binding
14 *
15 * Extends ShaderProcessor to automatically read node outputs and write them
16 * to shader push constants before dispatch. This enables nodes to drive
17 * GPU shader parameters in real-time.
18 *
19 * Example:
20 * struct MyPushConstants {
21 * float brightness;
22 * float frequency;
23 * };
24 *
25 * auto processor = std::make_shared<NodeBindingsProcessor>("shader.comp");
26 * processor->set_push_constant_size<MyPushConstants>();
27 *
28 * auto brightness = std::make_shared<Sine>(1.0, 0.5);
29 * processor->bind_node("brightness", brightness, offsetof(MyPushConstants, brightness));
30 *
31 * // In frame loop
32 * node_manager->process_token(VISUAL_RATE, 1); // Tick nodes
33 * processor->process(buffer); // Auto-updates push constants from nodes, then dispatches
34 */
35class MAYAFLUX_API NodeBindingsProcessor : public ShaderProcessor {
36public:
37 enum class ProcessingMode : uint8_t {
38 INTERNAL, ///< Processor calls extract_single_sample() - owns the processing
39 EXTERNAL ///< Processor reads get_last_output() - node processed elsewhere
40 };
41
42 struct NodeBinding {
43 std::shared_ptr<Nodes::Node> node;
45 size_t size { sizeof(float) };
46 std::atomic<ProcessingMode> processing_mode { ProcessingMode::INTERNAL };
47 };
48
49 using ShaderProcessor::ShaderProcessor;
50
51 /**
52 * @brief Bind node output to push constant offset
53 * @param name Logical name for this binding
54 * @param node Node whose output will be read
55 * @param offset Byte offset in push constant struct
56 * @param size Size of value (default: sizeof(float))
57 * @param mode Processing mode (default: INTERNAL)
58 */
59 void bind_node(
60 const std::string& name,
61 const std::shared_ptr<Nodes::Node>& node,
62 uint32_t offset,
63 size_t size = sizeof(float),
64 ProcessingMode mode = ProcessingMode::INTERNAL);
65
66 /**
67 * @brief Remove node binding
68 */
69 void unbind_node(const std::string& name);
70
71 /**
72 * @brief Check if binding exists
73 */
74 bool has_binding(const std::string& name) const;
75
76 /**
77 * @brief Get all binding names
78 */
79 std::vector<std::string> get_binding_names() const;
80
81 /**
82 * @brief Set processing mode for a specific binding
83 * @param name Binding name
84 * @param mode INTERNAL (processor extracts samples) or EXTERNAL (processor reads node state)
85 */
86 void set_processing_mode(const std::string& name, ProcessingMode mode);
87
88 /**
89 * @brief Set processing mode for all bindings
90 * @param mode INTERNAL or EXTERNAL
91 */
92 void set_processing_mode(ProcessingMode mode);
93
94 /**
95 * @brief Get processing mode for a specific binding
96 * @param name Binding name
97 * @return Current processing mode
98 */
99 ProcessingMode get_processing_mode(const std::string& name) const;
100
101protected:
102 void execute_shader(const std::shared_ptr<VKBuffer>& buffer) override;
103
104 void initialize_pipeline(const std::shared_ptr<VKBuffer>& buffer) override { }
105
106 void initialize_descriptors(const std::shared_ptr<VKBuffer>& buffer) override { }
107
108private:
109 void update_push_constants_from_nodes();
110
111 std::unordered_map<std::string, NodeBinding> m_bindings;
112};
113
114} // namespace MayaFlux::Buffers
void initialize_pipeline(const std::shared_ptr< VKBuffer > &buffer) override
void initialize_descriptors(const std::shared_ptr< VKBuffer > &buffer) override
std::unordered_map< std::string, NodeBinding > m_bindings
ShaderProcessor with automatic node-to-push-constant binding.
Abstract base class for shader-based buffer processing.
Contains the node-based computational processing system components.
Definition Chronie.hpp:11