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 146 of file GeometryBindingsProcessor.cpp.

147{
148 if (m_texture_dirty.test(std::memory_order_acquire)) {
149 m_texture_dirty.clear(std::memory_order_release);
150 if (auto vk = std::dynamic_pointer_cast<VKBuffer>(buffer)) {
151 if (auto rp = vk->get_render_processor()) {
152 if (m_pending_texture) {
153 rp->bind_texture(m_pending_texture->binding, m_pending_texture->image);
154 }
155 }
156 }
157 m_pending_texture.reset();
158 }
159
160 if (m_bindings.empty()) {
161 return;
162 }
163
164 auto vk_buffer = std::dynamic_pointer_cast<VKBuffer>(buffer);
165 if (!vk_buffer) {
167 "GeometryBindingsProcessor requires VKBuffer, got different buffer type");
168 return;
169 }
170
171 for (auto& [name, binding] : m_bindings) {
172 if (!binding.node->needs_gpu_update()) {
174 "Geometry '{}' unchanged, skipping upload", name);
175 continue;
176 }
177
178 auto vertices = binding.node->get_vertex_data();
179
180 if (vertices.empty()) {
181 if (binding.gpu_vertex_buffer->is_host_visible()) {
182 binding.gpu_vertex_buffer->clear();
183 }
184
185 if (binding.node->get_vertex_layout()) {
186 binding.gpu_vertex_buffer->set_vertex_layout(
187 binding.node->get_vertex_layout().value());
188 }
189
191 "Geometry '{}' cleared", name);
192 continue;
193 }
194
196 vertices.data(),
197 vertices.size_bytes(),
198 binding.gpu_vertex_buffer,
199 binding.staging_buffer);
200
201 if (binding.node->get_vertex_layout()) {
202 binding.gpu_vertex_buffer->set_vertex_layout(
203 binding.node->get_vertex_layout().value());
204
206 "Set vertex layout for '{}' ({} vertices, {} attributes)",
207 name,
208 binding.node->get_vertex_count(),
209 binding.node->get_vertex_layout()->attributes.size());
210 } else {
212 "Geometry node '{}' has no vertex layout. "
213 "RenderProcessor may fail without layout info.",
214 name);
215 }
216
217 upload_index_data(name, binding);
218 binding.node->clear_gpu_update_flag();
219 }
220
221 bool attached_is_target = false;
222 for (const auto& [name, binding] : m_bindings) {
223 if (binding.gpu_vertex_buffer == vk_buffer) {
224 attached_is_target = true;
225 break;
226 }
227 }
228
229 if (!attached_is_target && !m_bindings.empty()) {
230 auto& first_binding = m_bindings.begin()->second;
231 if (first_binding.node->needs_gpu_update()) {
232 auto vertices = first_binding.node->get_vertex_data();
233
234 if (!vertices.empty()) {
236 vertices.data(),
237 vertices.size_bytes(),
238 vk_buffer,
239 first_binding.staging_buffer);
240
241 if (first_binding.node->get_vertex_layout()) {
242 vk_buffer->set_vertex_layout(
243 first_binding.node->get_vertex_layout().value());
244 }
245 }
246 upload_index_data(m_bindings.begin()->first, first_binding);
247 first_binding.node->clear_gpu_update_flag();
248 }
249 }
250}
#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, m_pending_texture, m_texture_dirty, 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: