fix(web): use browser-safe render timing

This commit is contained in:
Hakan Seven 2026-08-13 23:57:47 +03:00
commit e58bef39dc
2 changed files with 11 additions and 11 deletions

View file

@ -692,7 +692,7 @@ fn mesh_click_result<'a>(
eye: glam::DVec3, eye: glam::DVec3,
bounds: Rectangle, bounds: Rectangle,
) -> Option<(f64, Handle, glam::DVec3)> { ) -> Option<(f64, Handle, glam::DVec3)> {
let profile = crate::perf::enabled().then(std::time::Instant::now); let profile = crate::perf::enabled().then(iced::time::Instant::now);
let mut set_count = 0usize; let mut set_count = 0usize;
let mut bound_hits = 0usize; let mut bound_hits = 0usize;
let mut exact_triangles = 0usize; let mut exact_triangles = 0usize;

View file

@ -1148,7 +1148,7 @@ fn build_instanced_chunk(
parts: &[MeshBatchPart<'_>], parts: &[MeshBatchPart<'_>],
profile_enabled: bool, profile_enabled: bool,
) -> Option<(MeshBatchChunk, u64, InstancedBuildProfile)> { ) -> Option<(MeshBatchChunk, u64, InstancedBuildProfile)> {
let started = profile_enabled.then(std::time::Instant::now); let started = profile_enabled.then(iced::time::Instant::now);
let first = parts.first()?; let first = parts.first()?;
let source = first.set.instance_source.as_ref()?; let source = first.set.instance_source.as_ref()?;
let mesh = first.mesh; let mesh = first.mesh;
@ -1209,7 +1209,7 @@ fn build_instanced_chunk(
} else { } else {
Vec::new() Vec::new()
}; };
let vertices_at = profile_enabled.then(std::time::Instant::now); let vertices_at = profile_enabled.then(iced::time::Instant::now);
let edge_color = first let edge_color = first
.set .set
.visual_style .visual_style
@ -1250,7 +1250,7 @@ fn build_instanced_chunk(
]); ]);
} }
} }
let edges_at = profile_enabled.then(std::time::Instant::now); let edges_at = profile_enabled.then(iced::time::Instant::now);
let transparent = material_is_transparent(material, color); let transparent = material_is_transparent(material, color);
let face_indices = first.include_faces.then_some(first.indices.as_ref()); let face_indices = first.include_faces.then_some(first.indices.as_ref());
let opaque_indices = if transparent { let opaque_indices = if transparent {
@ -1298,7 +1298,7 @@ fn build_instanced_chunk(
} }
} }
} }
let instances_at = profile_enabled.then(std::time::Instant::now); let instances_at = profile_enabled.then(iced::time::Instant::now);
let triangles = if first.include_faces { let triangles = if first.include_faces {
(first.indices.len() / 3) as u64 * instances.len() as u64 (first.indices.len() / 3) as u64 * instances.len() as u64
} else { } else {
@ -1332,7 +1332,7 @@ fn build_instanced_chunk(
.entry(edge_key) .entry(edge_key)
.or_insert_with(|| chunk.edge_vertex_buffer.clone()); .or_insert_with(|| chunk.edge_vertex_buffer.clone());
} }
let uploaded_at = profile_enabled.then(std::time::Instant::now); let uploaded_at = profile_enabled.then(iced::time::Instant::now);
Some(( Some((
chunk, chunk,
triangles, triangles,
@ -1559,7 +1559,7 @@ pub fn build_mesh_batch_filtered(
sets: &[MeshLodSet], sets: &[MeshLodSet],
handles: Option<&rustc_hash::FxHashSet<acadrust::Handle>>, handles: Option<&rustc_hash::FxHashSet<acadrust::Handle>>,
) -> (Vec<MeshBatchChunk>, u64) { ) -> (Vec<MeshBatchChunk>, u64) {
let perf_started = crate::perf::enabled().then(std::time::Instant::now); let perf_started = crate::perf::enabled().then(iced::time::Instant::now);
// Derive the caps from the real device limit and vertex size. The previous // Derive the caps from the real device limit and vertex size. The previous
// fixed 6 M-vertex cap assumed 40 B/vertex, but `position_low` (RTE) grew // fixed 6 M-vertex cap assumed 40 B/vertex, but `position_low` (RTE) grew
// MeshVertex to 52 B, so 6 M × 52 B = 312 MB blew past the 256 MB cap. // MeshVertex to 52 B, so 6 M × 52 B = 312 MB blew past the 256 MB cap.
@ -1741,7 +1741,7 @@ pub fn build_mesh_batch_filtered(
}); });
} }
} }
let prepared_at = std::time::Instant::now(); let prepared_at = iced::time::Instant::now();
let spatial_bounds = sets.iter().fold( let spatial_bounds = sets.iter().fold(
[ [
f32::INFINITY, f32::INFINITY,
@ -1828,7 +1828,7 @@ pub fn build_mesh_batch_filtered(
mesh_spatial_key(part.set, spatial_bounds), mesh_spatial_key(part.set, spatial_bounds),
) )
}); });
let grouped_at = std::time::Instant::now(); let grouped_at = iced::time::Instant::now();
let ordered = direct_parts; let ordered = direct_parts;
let mut active_key: Option<MaterialBatchKey> = None; let mut active_key: Option<MaterialBatchKey> = None;
let mut active_material: Option<&crate::scene::model::material_model::MeshMaterial> = None; let mut active_material: Option<&crate::scene::model::material_model::MeshMaterial> = None;
@ -2224,7 +2224,7 @@ pub fn build_mesh_batch_filtered(
None, None,
)); ));
} }
let direct_at = std::time::Instant::now(); let direct_at = iced::time::Instant::now();
let mut instanced_profile = InstancedBuildProfile::default(); let mut instanced_profile = InstancedBuildProfile::default();
let mut instanced_buffers = InstancedBufferCache::default(); let mut instanced_buffers = InstancedBufferCache::default();
for parts in instance_groups.values() { for parts in instance_groups.values() {
@ -2249,7 +2249,7 @@ pub fn build_mesh_batch_filtered(
} }
} }
if let Some(started) = perf_started { if let Some(started) = perf_started {
let done = std::time::Instant::now(); let done = iced::time::Instant::now();
crate::perf_record!( crate::perf_record!(
"[perf] mesh-build-detail prepare={:.1} group={:.1} direct={:.1} instanced={:.1}", "[perf] mesh-build-detail prepare={:.1} group={:.1} direct={:.1} instanced={:.1}",
prepared_at.duration_since(started).as_secs_f64() * 1000.0, prepared_at.duration_since(started).as_secs_f64() * 1000.0,