From d97f548efccfbecd54441e009db52e636e37009b Mon Sep 17 00:00:00 2001 From: David Huculak Date: Mon, 19 Feb 2024 13:42:26 -0500 Subject: [PATCH] inline frustum_intersection_test function to prevent accidental perf footgun; disable debug-assertions in wgpu-types to prevent validation layers from being enable since https://github.com/gfx-rs/wgpu/pull/4230 --- Cargo.toml | 3 +++ ikari/src/collisions.rs | 12 +----------- ikari/src/renderer.rs | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8db77a85..314c68fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,6 +77,9 @@ opt-level = 3 [profile.dev.package."wgpu-core"] debug-assertions = false +[profile.dev.package."wgpu-types"] +debug-assertions = false + # [profile.dev.package."wgpu"] # debug-assertions = false diff --git a/ikari/src/collisions.rs b/ikari/src/collisions.rs index 2fc01382..c0b9da28 100644 --- a/ikari/src/collisions.rs +++ b/ikari/src/collisions.rs @@ -369,17 +369,7 @@ impl From for Frustum { } impl CameraFrustumDescriptor { - // TODO: this function is slow due to the calls to to_convex_polyhedron. should cache the convex polyhedra. - pub fn frustum_intersection_test(&self, other: &CameraFrustumDescriptor) -> bool { - rapier3d_f64::parry::query::intersection_test( - &rapier3d_f64::na::Isometry::identity(), - &self.to_convex_polyhedron(), - &rapier3d_f64::na::Isometry::identity(), - &other.to_convex_polyhedron(), - ) - .unwrap() - } - + /// this is not free. consider caching the result pub fn to_convex_polyhedron(&self) -> ConvexPolyhedron { let points: Vec<_> = self .to_basic_mesh() diff --git a/ikari/src/renderer.rs b/ikari/src/renderer.rs index 50d9366f..1905268c 100644 --- a/ikari/src/renderer.rs +++ b/ikari/src/renderer.rs @@ -3334,8 +3334,14 @@ impl Renderer { }; let debug_culling_frustum_mesh = debug_frustum_descriptor.to_basic_mesh(); - let collision_based_color = if frustum_descriptor - .frustum_intersection_test(main_culling_frustum_desc) + let identity = rapier3d_f64::na::Isometry::identity(); + let collision_based_color = if rapier3d_f64::parry::query::intersection_test( + &identity, + &frustum_descriptor.to_convex_polyhedron(), + &identity, + &main_culling_frustum_desc.to_convex_polyhedron(), + ) + .unwrap() { Vec4::new(0.0, 1.0, 0.0, 0.1) } else { @@ -4038,7 +4044,13 @@ impl Renderer { // that are inside the main view so we can completely skip the shadow map // render pass for this light view let is_light_view_culled = if USE_EXTRA_SHADOW_MAP_CULLING { - !desc.frustum_intersection_test(&culling_frustum_desc) + !rapier3d_f64::parry::query::intersection_test( + &rapier3d_f64::na::Isometry::identity(), + &desc.to_convex_polyhedron(), + &rapier3d_f64::na::Isometry::identity(), + &culling_frustum_desc.to_convex_polyhedron(), + ) + .unwrap() } else { false };