Uploads all geometry nodes to their target vertex buffers. Uses staging buffers for device-local targets.
147{
150 if (auto vk = std::dynamic_pointer_cast<VKBuffer>(buffer)) {
151 if (auto rp = vk->get_render_processor()) {
154 }
155 }
156 }
158 }
159
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
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
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 }
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.
std::atomic_flag m_texture_dirty
std::optional< PendingTexture > m_pending_texture
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.