Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parry benchmarks compilation #255

Merged
merged 6 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/workflows/parry-ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: parry CI build

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -74,6 +74,16 @@ jobs:
- name: install stable Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
toolchain: stable
- name: cargo doc
run: cargo doc --workspace --features bytemuck-serialize,serde-serialize,rkyv-serialize,parallel --no-deps --document-private-items
check-benchmarks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install nightly Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
- name: check benchmarks
run: cargo +nightly check --benches
5 changes: 5 additions & 0 deletions crates/parry3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ oorandom = "11"
ptree = "0.4.0"
rand = { version = "0.8" }
macroquad = "0.4.12"
nalgebra = { version = "0.33", default-features = false, features = [
"libm",
Vrixyz marked this conversation as resolved.
Show resolved Hide resolved
"rand",
] }
rand_isaac = "0.3"

[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--generate-link-to-definition"]
Expand Down
7 changes: 7 additions & 0 deletions crates/parry3d/benches/all.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![feature(test)]
Vrixyz marked this conversation as resolved.
Show resolved Hide resolved
#![allow(unused_macros)]

use parry3d::math::{Point, Real};

extern crate nalgebra as na;
extern crate parry3d;
extern crate rand;
Expand All @@ -10,3 +12,8 @@ mod bounding_volume;
mod common;
mod query;
mod support_map;

#[cfg(feature = "dim2")]
type ConvexHull = Vec<Point<Real>>;
#[cfg(feature = "dim3")]
type ConvexHull = (Vec<Point<Real>>, Vec<[u32; 3]>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[cfg(feature = "dim2")]
type ConvexHull = Vec<Point<Real>>;
#[cfg(feature = "dim3")]
type ConvexHull = (Vec<Point<Real>>, Vec<[u32; 3]>);

7 changes: 3 additions & 4 deletions crates/parry3d/benches/bounding_volume/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use crate::common::{generate, generate_trimesh_around_origin, unref};
use na::Isometry3;
use parry3d::bounding_volume::BoundingVolume;
use parry3d::bounding_volume::{Aabb, BoundingSphere};
use parry3d::shape::{
Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, TriMesh, Triangle,
};
use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, TriMesh, Triangle};
use rand::SeedableRng;
use rand_isaac::IsaacRng;
use test::Bencher;
Expand Down Expand Up @@ -132,6 +130,7 @@ bench_method!(
m: Isometry3<f32>
);

/*
bench_method!(
bench_convex_aabb,
aabb: Aabb,
Expand All @@ -143,7 +142,7 @@ bench_method!(
bounding_sphere: BoundingSphere,
c: ConvexHull,
m: Isometry3<f32>
);
);*/
Copy link
Contributor Author

@Vrixyz Vrixyz Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConvexHull is no longer a type as iitself, but rather an alias to Vec<Point<Real>>, I think it would have value to be its own type, but slightly out of scope for this PR.

@sebcrozet I'd appreciate instructions as how to proceed:

Should I straight up remove that code, or keep it in and create a tracking issue (+ comment) ?

Then, should I either:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ConvexHull shpe type has been renamed ConvexPolyhedron in 3D and ConvexPolygon in 2D.


bench_method_gen!(
bench_mesh_aabb,
Expand Down
14 changes: 10 additions & 4 deletions crates/parry3d/benches/common/default_gen.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use na::{
self, Isometry2, Isometry3, Matrix2, Matrix3, Matrix4, Point2, Point3, Point4, RealField,
Vector2, Vector3, Vector4,
self, Isometry2, Isometry3, Matrix2, Matrix3, Matrix4, Point2, Point3, Point4, Vector2,
Vector3, Vector4,
};
use parry3d::bounding_volume::{Aabb, BoundingSphere};
use parry3d::math::{Point, Real, Vector};
use parry3d::query::Ray;
use parry3d::shape::{Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, Triangle};
use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, Triangle};
use rand::distributions::{Distribution, Standard};
use rand::Rng;

use crate::ConvexHull;

pub trait DefaultGen {
fn generate<R: Rng>(rng: &mut R) -> Self;
}
Expand Down Expand Up @@ -76,7 +78,11 @@ where
Standard: Distribution<Real>,
{
fn generate<R: Rng>(rng: &mut R) -> Capsule {
Capsule::new(rng.gen::<Real>().abs(), rng.gen::<Real>().abs())
Capsule::new(
rng.gen::<Point<Real>>(),
rng.gen::<Point<Real>>(),
rng.gen::<Real>().abs(),
)
}
}

Expand Down
9 changes: 3 additions & 6 deletions crates/parry3d/benches/common/generators.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use na::{Point2, Point3};
use na::Point3;
use parry3d::shape::TriMesh;
use rand::Rng;

pub fn generate_trimesh_around_origin<R: Rng>(rng: &mut R) -> TriMesh {
let pts = (0..3000).map(|_| rng.gen::<Point3<f32>>() * 3.0).collect();
let uvs = (0..3000).map(|_| rng.gen::<Point2<f32>>() * 3.0).collect();
let indices = (0..1000)
.map(|i| Point3::new(i * 3, i * 3 + 1, i * 3 + 2))
.collect();
let indices = (0..1000).map(|i| [i * 3, i * 3 + 1, i * 3 + 2]).collect();

TriMesh::new(pts, indices, Some(uvs))
TriMesh::new(pts, indices)
}
2 changes: 1 addition & 1 deletion crates/parry3d/benches/common/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ macro_rules! bench_method_gen (

unsafe {
let val: $tres = test::black_box($arg.get_unchecked(i).$method($(unref($args.get_unchecked(i)),)*));
drop(val);
let _ = val;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was that change needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using drop results in a warning:

warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
   --> crates/parry3d/benches/bounding_volume/../common/macros.rs:75:21

Aabb and BoundingSphere are concerned. I don´t think this is an opportunity to make benchmarks more accurate (if we're unexpectedly copying).

Actually I'm not exactly sure why this drop is necessary. As we're in an unsafe call, I guess it might be useful, but not really used in current usage. It doesn´t hurt being here I guess.

}
})
}
Expand Down
15 changes: 10 additions & 5 deletions crates/parry3d/benches/query/contacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,49 @@ mod macros;
bench_free_fn!(
bench_ball_against_ball,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Ball,
pos2: Isometry3<f32>,
b2: Ball,
prediction: f32
);

bench_free_fn!(
bench_cuboid_against_cuboid,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Cuboid,
pos2: Isometry3<f32>,
b2: Cuboid,
prediction: f32
);

bench_free_fn!(
bench_capsule_against_capsule,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Capsule,
pos2: Isometry3<f32>,
b2: Capsule,
prediction: f32
);

bench_free_fn!(
bench_cone_against_cone,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Cone,
pos2: Isometry3<f32>,
b2: Cone,
prediction: f32
);

bench_free_fn!(
bench_cylinder_against_cylinder,
query::contact,
pos12: Isometry3<f32>,
pos1: Isometry3<f32>,
b1: Cylinder,
pos2: Isometry3<f32>,
b2: Cylinder,
prediction: f32
);
42 changes: 21 additions & 21 deletions crates/parry3d/benches/query/ray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use crate::common::{generate, generate_trimesh_around_origin, unref};
use na::Isometry3;
use parry3d::bounding_volume::{Aabb, BoundingSphere};
use parry3d::query::{Ray, RayCast};
use parry3d::shape::{
Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, TriMesh, Triangle,
};
use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, TriMesh, Triangle};
use rand::SeedableRng;
use rand_isaac::IsaacRng;
use test::Bencher;
Expand Down Expand Up @@ -85,8 +83,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_ball_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_ball_with_normal,
cast_ray_and_get_normal,
b: Ball,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -95,8 +93,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_cuboid_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_cuboid_with_normal,
cast_ray_and_get_normal,
c: Cuboid,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -105,8 +103,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_capsule_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_capsule_with_normal,
cast_ray_and_get_normal,
c: Capsule,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -115,8 +113,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_cone_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_cone_with_normal,
cast_ray_and_get_normal,
c: Cone,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -125,8 +123,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_cylinder_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_cylinder_with_normal,
cast_ray_and_get_normal,
c: Cylinder,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -135,8 +133,8 @@ bench_method!(
);

bench_method!(
bench_ray_against_segment_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_segment_with_normal,
cast_ray_and_get_normal,
c: Segment,
pos: Isometry3<f32>,
ray: Ray,
Expand All @@ -145,28 +143,30 @@ bench_method!(
);

bench_method!(
bench_ray_against_triangle_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_triangle_with_normal,
cast_ray_and_get_normal,
c: Triangle,
pos: Isometry3<f32>,
ray: Ray,
max_time_of_impact: f32,
solid: bool
);

/*
bench_method!(
bench_ray_against_convex_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_convex_with_normal,
cast_ray_and_get_normal,
c: ConvexHull,
pos: Isometry3<f32>,
ray: Ray,
max_time_of_impact: f32,
solid: bool
);
*/

bench_method_gen!(
bench_ray_against_trimesh_with_normal_uv,
cast_ray_and_get_normal_and_uv,
bench_ray_against_trimesh_with_normal,
cast_ray_and_get_normal,
m: TriMesh = generate_trimesh_around_origin,
pos: Isometry3<f32> = generate,
ray: Ray = generate,
Expand Down
4 changes: 3 additions & 1 deletion crates/parry3d/benches/support_map/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::common::{generate, unref};
use na::{Isometry3, Vector3};
use parry3d::shape::SupportMap;
use parry3d::shape::{Ball, Capsule, Cone, ConvexHull, Cuboid, Cylinder, Segment, Triangle};
use parry3d::shape::{Ball, Capsule, Cone, Cuboid, Cylinder, Segment, Triangle};
use rand::SeedableRng;
use rand_isaac::IsaacRng;
use test::Bencher;
Expand Down Expand Up @@ -59,10 +59,12 @@ bench_method!(
m: Isometry3<f32>,
dir: Vector3<f32>
);
/*
bench_method!(
bench_convex_support_map,
support_point,
c: ConvexHull,
m: Isometry3<f32>,
dir: Vector3<f32>
);
*/
Vrixyz marked this conversation as resolved.
Show resolved Hide resolved