From 2482747fb25d1a09d7e2ba2c80ca6e353748cf4a Mon Sep 17 00:00:00 2001 From: Dmitry Stepanov Date: Wed, 8 Jul 2026 18:41:16 +0300 Subject: [PATCH] fixed batching in `push_triangles` - do not add new bundle when the evaluated id is the same - instead, update the number of triangles in the bundle - vertex/index buffer will be the same across all bundles with the same vertex layout --- fyrox-impl/src/renderer/bundle.rs | 34 ++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/fyrox-impl/src/renderer/bundle.rs b/fyrox-impl/src/renderer/bundle.rs index 3feb5a39b..2e1ca90d4 100644 --- a/fyrox-impl/src/renderer/bundle.rs +++ b/fyrox-impl/src/renderer/bundle.rs @@ -840,6 +840,7 @@ pub struct RenderDataBundleStorage { pub bundles: Vec, pub light_sources: Vec, pub environment_map: Option, + last_bundle_id: u64, } pub struct RenderDataBundleStorageOptions { @@ -862,6 +863,7 @@ impl RenderDataBundleStorage { bundles: Default::default(), light_sources: Default::default(), environment_map: None, + last_bundle_id: 0, } } @@ -885,6 +887,7 @@ impl RenderDataBundleStorage { bundles: Vec::with_capacity(capacity), light_sources: Default::default(), environment_map: None, + last_bundle_id: 0, }; let frustum = Frustum::from_view_projection_matrix( @@ -1216,16 +1219,27 @@ impl RenderDataBundleStorageTrait for RenderDataBundleStorage { func(vertex_buffer, triangle_buffer); - let instance = SurfaceInstanceData { - node_handle, - element_range: ElementRange::Specific { - offset, - count: data.geometry_buffer.len() - offset, - }, - ..Default::default() - }; - - bundle.instances.push(instance); + let emitted_triangles_count = data.geometry_buffer.len() - offset; + if self.last_bundle_id != bundle_id { + let instance = SurfaceInstanceData { + node_handle, + element_range: ElementRange::Specific { + offset, + count: emitted_triangles_count, + }, + ..Default::default() + }; + bundle.instances.push(instance); + self.last_bundle_id = bundle_id; + } else { + let instance = bundle + .instances + .last_mut() + .expect("bundle must contain at least one instance!"); + if let ElementRange::Specific { ref mut count, .. } = instance.element_range { + *count += emitted_triangles_count; + } + } } /// Adds a new surface instance to the storage. The method will automatically put the instance in the appropriate