MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ processing_function()

void MayaFlux::Buffers::GeometryBindingsProcessor::processing_function ( const std::shared_ptr< Buffer > &  buffer)
overridevirtual

BufferProcessor interface - uploads all bound geometries.

Parameters
bufferThe buffer this processor is attached to

Uploads all geometry nodes to their target vertex buffers. Uses staging buffers for device-local targets.

Implements MayaFlux::Buffers::BufferProcessor.

Definition at line 132 of file GeometryBindingsProcessor.cpp.

133{
134 if (m_bindings.empty()) {
135 return;
136 }
137
138 auto vk_buffer = std::dynamic_pointer_cast<VKBuffer>(buffer);
139 if (!vk_buffer) {
141 "GeometryBindingsProcessor requires VKBuffer, got different buffer type");
142 return;
143 }
144
145 for (auto& [name, binding] : m_bindings) {
146 if (!binding.node->needs_gpu_update()) {
148 "Geometry '{}' unchanged, skipping upload", name);
149 continue;
150 }
151
152 auto vertices = binding.node->get_vertex_data();
153
154 if (vertices.empty()) {
155 if (binding.gpu_vertex_buffer->is_host_visible()) {
156 binding.gpu_vertex_buffer->clear();
157 }
158
159 if (binding.node->get_vertex_layout()) {
160 binding.gpu_vertex_buffer->set_vertex_layout(
161 binding.node->get_vertex_layout().value());
162 }
163
165 "Geometry '{}' cleared", name);
166 continue;
167 }
168
170 vertices.data(),
171 vertices.size_bytes(),
172 binding.gpu_vertex_buffer,
173 binding.staging_buffer);
174
175 if (binding.node->get_vertex_layout()) {
176 binding.gpu_vertex_buffer->set_vertex_layout(
177 binding.node->get_vertex_layout().value());
178
180 "Set vertex layout for '{}' ({} vertices, {} attributes)",
181 name,
182 binding.node->get_vertex_count(),
183 binding.node->get_vertex_layout()->attributes.size());
184 } else {
186 "Geometry node '{}' has no vertex layout. "
187 "RenderProcessor may fail without layout info.",
188 name);
189 }
190
191 upload_index_data(name, binding);
192 binding.node->clear_gpu_update_flag();
193 }
194
195 bool attached_is_target = false;
196 for (const auto& [name, binding] : m_bindings) {
197 if (binding.gpu_vertex_buffer == vk_buffer) {
198 attached_is_target = true;
199 break;
200 }
201 }
202
203 if (!attached_is_target && !m_bindings.empty()) {
204 auto& first_binding = m_bindings.begin()->second;
205 if (first_binding.node->needs_gpu_update()) {
206 auto vertices = first_binding.node->get_vertex_data();
207
208 if (!vertices.empty()) {
210 vertices.data(),
211 vertices.size_bytes(),
212 vk_buffer,
213 first_binding.staging_buffer);
214
215 if (first_binding.node->get_vertex_layout()) {
216 vk_buffer->set_vertex_layout(
217 first_binding.node->get_vertex_layout().value());
218 }
219 }
220 upload_index_data(m_bindings.begin()->first, first_binding);
221 first_binding.node->clear_gpu_update_flag();
222 }
223 }
224}
#define MF_RT_WARN(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
#define MF_TRACE(comp, ctx,...)
#define MF_RT_TRACE(comp, ctx,...)
std::unordered_map< std::string, GeometryBinding > m_bindings
void upload_index_data(const std::string &name, GeometryBinding &binding)
Upload index data for one binding, creating or growing the GPU index buffer as needed.
void upload_resizing(const void *data, size_t size, const std::shared_ptr< VKBuffer > &target, const std::shared_ptr< VKBuffer > &staging, float growth_factor)
Upload size bytes to target, growing both buffers first if needed.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, m_bindings, MF_RT_ERROR, MF_RT_TRACE, MF_RT_WARN, MF_TRACE, upload_index_data(), and MayaFlux::Buffers::upload_resizing().

+ Here is the call graph for this function: