MayaFlux 0.1.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 struct NodeBinding {
38 std::shared_ptr<Nodes::Node> node;
40 size_t size = sizeof(float);
41 };
42
43 using ShaderProcessor::ShaderProcessor;
44
45 /**
46 * @brief Bind node output to push constant offset
47 * @param name Logical name for this binding
48 * @param node Node whose output will be read
49 * @param offset Byte offset in push constant struct
50 * @param size Size of value (default: sizeof(float))
51 */
52 void bind_node(
53 const std::string& name,
54 const std::shared_ptr<Nodes::Node>& node,
55 uint32_t offset,
56 size_t size = sizeof(float));
57
58 /**
59 * @brief Remove node binding
60 */
61 void unbind_node(const std::string& name);
62
63 /**
64 * @brief Check if binding exists
65 */
66 bool has_binding(const std::string& name) const;
67
68 /**
69 * @brief Get all binding names
70 */
71 std::vector<std::string> get_binding_names() const;
72
73protected:
74 /**
75 * @brief Hook called before shader dispatch
76 * Automatically updates push constants from bound nodes
77 */
78 void on_before_dispatch(
80 const std::shared_ptr<VKBuffer>& buffer) override;
81
82private:
83 void update_push_constants_from_nodes();
84
85 std::unordered_map<std::string, NodeBinding> m_bindings;
86};
87
88} // namespace MayaFlux::Buffers
std::unordered_map< std::string, NodeBinding > m_bindings
ShaderProcessor with automatic node-to-push-constant binding.
Generic compute shader processor for VKBuffers.
Contains the node-based computational processing system components.
Definition Chronie.hpp:5