MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
NodeBindingsProcessor.cpp
Go to the documentation of this file.
3
5
6namespace MayaFlux::Buffers {
7
9 const std::string& name,
10 const std::shared_ptr<Nodes::Node>& node,
11 uint32_t offset,
12 size_t size,
13 ProcessingMode mode)
14{
15 auto [it, inserted] = m_bindings.try_emplace(name);
16 auto& binding = it->second;
17
18 binding.node = node;
19 binding.push_constant_offset = offset;
20 binding.size = size;
21 binding.processing_mode.store(mode, std::memory_order_release);
22}
23
24void NodeBindingsProcessor::unbind_node(const std::string& name)
25{
26 m_bindings.erase(name);
27}
28
29bool NodeBindingsProcessor::has_binding(const std::string& name) const
30{
31 return m_bindings.contains(name);
32}
33
34std::vector<std::string> NodeBindingsProcessor::get_binding_names() const
35{
36 std::vector<std::string> names;
37 names.reserve(m_bindings.size());
38 for (const auto& [name, _] : m_bindings) {
39 names.push_back(name);
40 }
41 return names;
42}
43
45{
46 auto it = m_bindings.find(name);
47 if (it != m_bindings.end()) {
48 it->second.processing_mode.store(mode, std::memory_order_release);
49 }
50}
51
53{
54 for (auto& [name, binding] : m_bindings) {
55 binding.processing_mode.store(mode, std::memory_order_release);
56 }
57}
58
60{
61 auto it = m_bindings.find(name);
62 if (it != m_bindings.end()) {
63 return it->second.processing_mode.load(std::memory_order_acquire);
64 }
66}
67
68void NodeBindingsProcessor::execute_shader(const std::shared_ptr<VKBuffer>& buffer)
69{
71
72 auto& staging = buffer->get_pipeline_context().push_constant_staging;
73
74 for (const auto& [name, binding] : m_bindings) {
75 size_t end_offset = binding.push_constant_offset + binding.size;
76
77 if (staging.size() < end_offset) {
78 staging.resize(end_offset);
79 }
80
81 std::memcpy(
82 staging.data() + binding.push_constant_offset,
83 m_push_constant_data.data() + binding.push_constant_offset,
84 binding.size);
85
87 "NodeBindingsProcessor: Merged binding '{}' at offset {} ({} bytes)",
88 name, binding.push_constant_offset, binding.size);
89 }
90}
91
93{
94 if (m_bindings.empty()) {
96 "No node bindings configured for NodeBindingsProcessor");
97 return;
98 }
99
100 auto& pc_data = get_push_constant_data();
101
102 for (auto& [name, binding] : m_bindings) {
103 size_t required_size = binding.push_constant_offset + binding.size;
104 if (pc_data.size() < required_size) {
105 pc_data.resize(required_size);
106 }
107
108 if (!binding.node) {
110 "Node binding '{}' has null node", name);
111 continue;
112 }
113
114 double value {};
115 ProcessingMode mode = binding.processing_mode.load(std::memory_order_acquire);
116
117 if (mode == ProcessingMode::INTERNAL) {
118 value = Buffers::extract_single_sample(binding.node);
119 } else {
120 value = binding.node->get_last_output();
121 }
122
123 if (binding.size == sizeof(float)) {
124 auto float_val = static_cast<float>(value);
125 std::memcpy(
126 pc_data.data() + binding.push_constant_offset,
127 &float_val,
128 sizeof(float));
129 } else if (binding.size == sizeof(double)) {
130 std::memcpy(
131 pc_data.data() + binding.push_constant_offset,
132 &value,
133 sizeof(double));
134 }
135 }
136}
137
138} // namespace MayaFlux::Buffers
#define MF_RT_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
void bind_node(const std::string &name, const std::shared_ptr< Nodes::Node > &node, uint32_t offset, size_t size=sizeof(float), ProcessingMode mode=ProcessingMode::INTERNAL)
Bind node output to push constant offset.
bool has_binding(const std::string &name) const
Check if binding exists.
ProcessingMode get_processing_mode(const std::string &name) const
Get processing mode for a specific binding.
void execute_shader(const std::shared_ptr< VKBuffer > &buffer) override
@ INTERNAL
Processor calls extract_single_sample() - owns the processing.
std::unordered_map< std::string, NodeBinding > m_bindings
void unbind_node(const std::string &name)
Remove node binding.
void set_processing_mode(const std::string &name, ProcessingMode mode)
Set processing mode for a specific binding.
std::vector< std::string > get_binding_names() const
Get all binding names.
const std::vector< uint8_t > & get_push_constant_data() const
Get current push constant data.
std::vector< uint8_t > m_push_constant_data
double extract_single_sample(const std::shared_ptr< Nodes::Node > &node)
Extract a single sample from a node with proper snapshot management.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.