diff options
| author | Sébastien Crozet <sebcrozet@dimforge.com> | 2024-04-07 22:16:58 +0200 |
|---|---|---|
| committer | Sébastien Crozet <sebastien@crozet.re> | 2024-04-30 23:10:46 +0200 |
| commit | 996400726927fb952999afbc36db6e2bfba7d44e (patch) | |
| tree | 8258505b69d0a0ad928284880137ff090f05b17e | |
| parent | e69e73e589cf4525c96ee7b919032c80ce205244 (diff) | |
| download | rapier-996400726927fb952999afbc36db6e2bfba7d44e.tar.gz rapier-996400726927fb952999afbc36db6e2bfba7d44e.tar.bz2 rapier-996400726927fb952999afbc36db6e2bfba7d44e.zip | |
feat: add some additional perf counters
| -rw-r--r-- | src/counters/mod.rs | 12 | ||||
| -rw-r--r-- | src/counters/solver_counters.rs | 17 | ||||
| -rw-r--r-- | src/counters/stages_counters.rs | 12 | ||||
| -rw-r--r-- | src/dynamics/solver/island_solver.rs | 8 | ||||
| -rw-r--r-- | src/pipeline/physics_pipeline.rs | 17 | ||||
| -rw-r--r-- | src_testbed/ui.rs | 24 |
6 files changed, 57 insertions, 33 deletions
diff --git a/src/counters/mod.rs b/src/counters/mod.rs index 324696f..e707025 100644 --- a/src/counters/mod.rs +++ b/src/counters/mod.rs @@ -182,6 +182,12 @@ measure_method!( stages.solver_time ); measure_method!(ccd_started, ccd_completed, ccd_time, stages.ccd_time); +measure_method!( + query_pipeline_update_started, + query_pipeline_update_completed, + query_pipeline_update_time, + stages.query_pipeline_time +); measure_method!( assembly_started, @@ -202,12 +208,6 @@ measure_method!( solver.velocity_update_time ); measure_method!( - position_resolution_started, - position_resolution_completed, - position_resolution_time, - solver.position_resolution_time -); -measure_method!( broad_phase_started, broad_phase_completed, broad_phase_time, diff --git a/src/counters/solver_counters.rs b/src/counters/solver_counters.rs index babcf41..aced5f3 100644 --- a/src/counters/solver_counters.rs +++ b/src/counters/solver_counters.rs @@ -14,10 +14,8 @@ pub struct SolverCounters { pub velocity_assembly_time: Timer, /// Time spent for the update of the velocity of the bodies. pub velocity_update_time: Timer, - /// Time spent for the assembly of all the position constraints. - pub position_assembly_time: Timer, - /// Time spent for the update of the position of the bodies. - pub position_resolution_time: Timer, + /// Time spent to write force back to user-accessible data. + pub velocity_writeback_time: Timer, } impl SolverCounters { @@ -29,8 +27,7 @@ impl SolverCounters { velocity_assembly_time: Timer::new(), velocity_resolution_time: Timer::new(), velocity_update_time: Timer::new(), - position_assembly_time: Timer::new(), - position_resolution_time: Timer::new(), + velocity_writeback_time: Timer::new(), } } @@ -41,8 +38,7 @@ impl SolverCounters { self.velocity_resolution_time.reset(); self.velocity_assembly_time.reset(); self.velocity_update_time.reset(); - self.position_assembly_time.reset(); - self.position_resolution_time.reset(); + self.velocity_writeback_time.reset(); } } @@ -57,11 +53,10 @@ impl Display for SolverCounters { self.velocity_resolution_time )?; writeln!(f, "Velocity update time: {}", self.velocity_update_time)?; - writeln!(f, "Position assembly time: {}", self.position_assembly_time)?; writeln!( f, - "Position resolution time: {}", - self.position_resolution_time + "Velocity writeback time: {}", + self.velocity_writeback_time ) } } diff --git a/src/counters/stages_counters.rs b/src/counters/stages_counters.rs index b61adb7..7e3198a 100644 --- a/src/counters/stages_counters.rs +++ b/src/counters/stages_counters.rs @@ -14,6 +14,10 @@ pub struct StagesCounters { pub solver_time: Timer, /// Total time spent for CCD and CCD resolution. pub ccd_time: Timer, + /// Total time spent updating the query pipeline (if provided to `PhysicsPipeline::step`). + pub query_pipeline_time: Timer, + /// Total time spent propagating user changes. + pub user_changes: Timer, } impl StagesCounters { @@ -25,6 +29,8 @@ impl StagesCounters { island_construction_time: Timer::new(), solver_time: Timer::new(), ccd_time: Timer::new(), + query_pipeline_time: Timer::new(), + user_changes: Timer::new(), } } @@ -35,6 +41,8 @@ impl StagesCounters { self.island_construction_time.reset(); self.solver_time.reset(); self.ccd_time.reset(); + self.query_pipeline_time.reset(); + self.user_changes.reset(); } } @@ -52,6 +60,8 @@ impl Display for StagesCounters { self.island_construction_time )?; writeln!(f, "Solver time: {}", self.solver_time)?; - writeln!(f, "CCD time: {}", self.ccd_time) + writeln!(f, "CCD time: {}", self.ccd_time)?; + writeln!(f, "Query pipeline time: {}", self.query_pipeline_time)?; + writeln!(f, "User changes time: {}", self.user_changes) } } diff --git a/src/dynamics/solver/island_solver.rs b/src/dynamics/solver/island_solver.rs index 2953f98..159bfa7 100644 --- a/src/dynamics/solver/island_solver.rs +++ b/src/dynamics/solver/island_solver.rs @@ -41,7 +41,7 @@ impl IslandSolver { joint_indices: &[JointIndex], multibodies: &mut MultibodyJointSet, ) { - counters.solver.velocity_resolution_time.resume(); + counters.solver.velocity_assembly_time.resume(); let num_solver_iterations = base_params.num_solver_iterations.get() + islands.active_island_additional_solver_iterations(island_id); @@ -76,8 +76,10 @@ impl IslandSolver { &mut self.contact_constraints, &mut self.joint_constraints, ); + counters.solver.velocity_assembly_time.pause(); // SOLVE + counters.solver.velocity_resolution_time.resume(); self.velocity_solver.solve_constraints( ¶ms, num_solver_iterations, @@ -86,8 +88,10 @@ impl IslandSolver { &mut self.contact_constraints, &mut self.joint_constraints, ); + counters.solver.velocity_resolution_time.pause(); // WRITEBACK + counters.solver.velocity_writeback_time.resume(); self.joint_constraints.writeback_impulses(impulse_joints); self.contact_constraints.writeback_impulses(manifolds); self.velocity_solver.writeback_bodies( @@ -98,6 +102,6 @@ impl IslandSolver { bodies, multibodies, ); - counters.solver.velocity_resolution_time.pause(); + counters.solver.velocity_writeback_time.pause(); } } diff --git a/src/pipeline/physics_pipeline.rs b/src/pipeline/physics_pipeline.rs index e921062..a268cda 100644 --- a/src/pipeline/physics_pipeline.rs +++ b/src/pipeline/physics_pipeline.rs @@ -142,6 +142,7 @@ impl PhysicsPipeline { ); narrow_phase.compute_contacts( integration_parameters.prediction_distance, + integration_parameters.dt, bodies, colliders, impulse_joints, @@ -178,7 +179,6 @@ impl PhysicsPipeline { multibody_joints, integration_parameters.min_island_size, ); - self.counters.stages.island_construction_time.pause(); if self.manifold_indices.len() < islands.num_islands() { self.manifold_indices @@ -203,6 +203,7 @@ impl PhysicsPipeline { bodies, &mut self.joint_constraint_indices, ); + self.counters.stages.island_construction_time.pause(); self.counters.stages.update_time.resume(); for handle in islands.active_dynamic_bodies() { @@ -421,6 +422,7 @@ impl PhysicsPipeline { self.counters.step_started(); // Apply some of delayed wake-ups. + self.counters.stages.user_changes.start(); for handle in impulse_joints .to_wake_up .drain(..) @@ -459,6 +461,7 @@ impl PhysicsPipeline { .copied() .filter(|h| colliders.get(*h).map(|c| !c.is_enabled()).unwrap_or(false)), ); + self.counters.stages.user_changes.pause(); // TODO: do this only on user-change. // TODO: do we want some kind of automatic inverse kinematics? @@ -486,12 +489,16 @@ impl PhysicsPipeline { ); if let Some(queries) = query_pipeline.as_deref_mut() { + self.counters.stages.query_pipeline_time.start(); queries.update_incremental(colliders, &modified_colliders, &removed_colliders, false); + self.counters.stages.query_pipeline_time.pause(); } + self.counters.stages.user_changes.resume(); self.clear_modified_colliders(colliders, &mut modified_colliders); self.clear_modified_bodies(bodies, &mut modified_bodies); removed_colliders.clear(); + self.counters.stages.user_changes.pause(); let mut remaining_time = integration_parameters.dt; let mut integration_parameters = *integration_parameters; @@ -508,7 +515,7 @@ impl PhysicsPipeline { // the timestep into multiple intervals. First, estimate the // size of the time slice we will integrate for this substep. // - // Note that we must do this now, before the constrains resolution + // Note that we must do this now, before the constraints resolution // because we need to use the correct timestep length for the // integration of external forces. // @@ -599,7 +606,9 @@ impl PhysicsPipeline { } } + self.counters.stages.update_time.resume(); self.advance_to_final_positions(islands, bodies, colliders, &mut modified_colliders); + self.counters.stages.update_time.pause(); self.detect_collisions( &integration_parameters, @@ -618,12 +627,14 @@ impl PhysicsPipeline { ); if let Some(queries) = query_pipeline.as_deref_mut() { + self.counters.stages.query_pipeline_time.resume(); queries.update_incremental( colliders, &modified_colliders, &[], remaining_substeps == 0, ); + self.counters.stages.query_pipeline_time.pause(); } self.clear_modified_colliders(colliders, &mut modified_colliders); @@ -635,10 +646,12 @@ impl PhysicsPipeline { // TODO: avoid updating the world mass properties twice (here, and // at the beginning of the next timestep) for bodies that were // not modified by the user in the mean time. + self.counters.stages.update_time.resume(); for handle in islands.active_dynamic_bodies() { let rb = bodies.index_mut_internal(*handle); rb.mprops.update_world_mass_properties(&rb.pos.position); } + self.counters.stages.update_time.pause(); self.counters.step_completed(); } diff --git a/src_testbed/ui.rs b/src_testbed/ui.rs index 7d50f62..c76b288 100644 --- a/src_testbed/ui.rs +++ b/src_testbed/ui.rs @@ -227,20 +227,21 @@ fn profiling_string(counters: &Counters) -> String { r#"Total: {:.2}ms Collision detection: {:.2}ms |_ Broad-phase: {:.2}ms - Narrow-phase: {:.2}ms + Narrow-phase: {:.2}ms Island computation: {:.2}ms Solver: {:.2}ms |_ Velocity assembly: {:.2}ms - Velocity resolution: {:.2}ms - Velocity integration: {:.2}ms - Position assembly: {:.2}ms - Position resolution: {:.2}ms + Velocity resolution: {:.2}ms + Velocity integration: {:.2}ms + Writeback: {:.2}ms CCD: {:.2}ms |_ # of substeps: {} - TOI computation: {:.2}ms - Broad-phase: {:.2}ms - Narrow-phase: {:.2}ms - Solver: {:.2}ms"#, + TOI computation: {:.2}ms + Broad-phase: {:.2}ms + Narrow-phase: {:.2}ms + Solver: {:.2}ms +Query pipeline: {:.2}ms +User changes: {:.2}ms"#, counters.step_time(), counters.collision_detection_time(), counters.broad_phase_time(), @@ -250,14 +251,15 @@ CCD: {:.2}ms counters.solver.velocity_assembly_time.time(), counters.velocity_resolution_time(), counters.solver.velocity_update_time.time(), - counters.solver.position_assembly_time.time(), - counters.position_resolution_time(), + counters.solver.velocity_writeback_time.time(), counters.ccd_time(), counters.ccd.num_substeps, counters.ccd.toi_computation_time.time(), counters.ccd.broad_phase_time.time(), counters.ccd.narrow_phase_time.time(), counters.ccd.solver_time.time(), + counters.query_pipeline_update_time(), + counters.stages.user_changes.time(), ) } |
