perf(render): batch and cull mesh instances

Share repeated block geometry across GPU instances.\n\nPatch changed mesh chunks and cull large batches with indirect draws.
This commit is contained in:
Hakan Seven committed 2026-07-27 01:11:21 +03:00
1 parent b5f9a06e78
commit 4887a53d66
8 files changed
+1747 -400

No files matched your search

+25
View File
@@ -167,6 +167,19 @@ pub struct MeshLodSet {
/// triangle). `verts` carry only the high half of the double-single
/// position, so the bound is f32-precise — fine for a conservative cull.
pub z_aabb: [f32; 2],
/// Immutable block-local geometry shared by every INSERT instance of this
/// block entity. Top-level meshes leave this empty.
pub instance_source: Option<std::sync::Arc<MeshInstanceSource>>,
/// Accumulated block-local → world transform for this rendered instance.
pub instance_transform: Option<acadrust::types::Transform>,
}
#[derive(Clone, Debug)]
pub struct MeshInstanceSource {
pub handle: acadrust::Handle,
pub lods: Vec<MeshModel>,
pub edge_verts: Vec<[f32; 3]>,
pub edge_verts_low: Vec<[f32; 3]>,
}
/// 3D bounds of every LOD's vertices: `([min_x, min_y, max_x, max_y], [min_z, max_z])`.
@@ -279,6 +292,8 @@ impl MeshLodSet {
metrics,
world_aabb,
z_aabb,
instance_source: None,
instance_transform: None,
}
}
@@ -297,4 +312,14 @@ impl MeshLodSet {
self.world_aabb = xy;
self.z_aabb = z;
}
pub fn prepare_instance_source(&mut self, handle: acadrust::Handle) {
self.instance_source = Some(std::sync::Arc::new(MeshInstanceSource {
handle,
lods: self.lods.clone(),
edge_verts: self.edge_verts.clone(),
edge_verts_low: self.edge_verts_low.clone(),
}));
self.instance_transform = None;
}
}