Skip to content

Commit

Permalink
Merge pull request #96 from dimforge/rkyv-rayon
Browse files Browse the repository at this point in the history
Add partial rkyv support + parallel qbvh traversal + Heigthfield support of Cuda kernels
  • Loading branch information
sebcrozet authored Oct 2, 2022
2 parents 8e106ec + a640841 commit fa852f6
Show file tree
Hide file tree
Showing 54 changed files with 792 additions and 148 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
- Add the support for linear shape-cast (`query::time_of_impact`) for heightfields.
- Make the convex polyhedron scaling more forgiving regarding normals to avoid frequent unjustified panics.
- Fix panic happening when building a convex polyhedron with empty inputs.

- Add the support of Heightfields on CUDA kernels written in Rust using the `cust` crate.
- Add the `rkyv-serialize` feature that enables the implementation of `rkyv` serialization/deserialization
for most shapes.
- Add the `parallel` feature that enables methods for the parallel traversal of QBVH trees: `QBVH::traverse_bvtt_parallel`,
`QBVH::traverse_bvtt_node_parallel`, `QBVH::traverse_depth_first_parallel`, `QBVH::traverse_depth_first_node_parallel`.

### Fixed
- Fix the application of non-uniform scaling to balls.
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ parry3d = { path = "crates/parry3d" }
parry2d-f64 = { path = "crates/parry2d-f64" }
parry3d-f64 = { path = "crates/parry3d-f64" }

#simba = { path = "../simba" }
#simba = { git = "https://github.com/dimforge/simba", rev = "b1392df62a0f4cf91e397bbb6bd41b7731afb6ab" }
# nalgebra = { git = "https://github.com/dimforge/nalgebra" }
8 changes: 6 additions & 2 deletions crates/parry2d-f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ std = [ "nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "
dim2 = [ ]
f64 = [ ]
serde-serialize = [ "serde", "nalgebra/serde-serialize", "arrayvec/serde" ]
rkyv-serialize = [ "rkyv", "nalgebra/rkyv-serialize", "simba/rkyv-serialize" ]
simd-stable = [ "simba/wide", "simd-is-enabled" ]
simd-nightly = [ "simba/packed_simd", "simd-is-enabled" ]
enhanced-determinism = [ "simba/libm_force", "indexmap" ]
cuda = [ "cust_core", "cust", "nalgebra/cuda" ]
parallel = [ "rayon" ]

# Do not enable this feature directly. It is automatically
# enabled with the "simd-stable" or "simd-nightly" feature.
Expand All @@ -45,15 +47,17 @@ num-traits = { version = "0.2", default-features = false }
smallvec = "1"
slab = { version = "0.4", optional = true }
arrayvec = { version = "0.7", default-features = false }
simba = { version = "0.7", default-features = false }
simba = { version = "^0.7.2", default-features = false }
nalgebra = { version = "0.31", default-features = false, features = [ "libm" ] }
approx = { version = "0.5", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive"]}
serde = { version = "1.0", optional = true, features = ["derive"] }
rkyv = { version = "0.7", optional = true }
num-derive = "0.3"
indexmap = { version = "1", features = [ "serde-1" ], optional = true }
rustc-hash = { version = "1", optional = true }
cust_core = { version = "0.1", optional = true }
spade = { version = "2", optional = true } # Make this optional?
rayon = { version = "1", optional = true }

[target.'cfg(not(target_os = "cuda"))'.dependencies]
cust = { version = "0.3", optional = true }
Expand Down
12 changes: 8 additions & 4 deletions crates/parry2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ std = [ "nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "
dim2 = [ ]
f32 = [ ]
serde-serialize = [ "serde", "nalgebra/serde-serialize", "arrayvec/serde" ]
rkyv-serialize = [ "rkyv", "nalgebra/rkyv-serialize", "simba/rkyv-serialize" ]
simd-stable = [ "simba/wide", "simd-is-enabled" ]
simd-nightly = [ "simba/packed_simd", "simd-is-enabled" ]
enhanced-determinism = [ "simba/libm_force", "indexmap" ]
cuda = [ "cust_core", "cust", "nalgebra/cuda" ]
cuda = [ "cust_core", "cust", "nalgebra/cuda" ]
parallel = [ "rayon" ]

# Do not enable this feature directly. It is automatically
# enabled with the "simd-stable" or "simd-nightly" feature.
Expand All @@ -45,15 +47,17 @@ num-traits = { version = "0.2", default-features = false }
smallvec = "1"
slab = { version = "0.4", optional = true }
arrayvec = { version = "0.7", default-features = false }
simba = { version = "0.7", default-features = false }
simba = { version = "^0.7.2", default-features = false }
nalgebra = { version = "0.31", default-features = false, features = [ "libm" ] }
approx = { version = "0.5", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive"]}
serde = { version = "1.0", optional = true, features = ["derive"] }
rkyv = { version = "0.7", optional = true }
num-derive = "0.3"
indexmap = { version = "1", features = [ "serde-1" ], optional = true }
rustc-hash = { version = "1", optional = true }
cust_core = { version = "0.1", optional = true }
spade = { version = "2", optional = true } # Make this optional?
spade = { version = "2", optional = true }
rayon = { version = "1", optional = true }

[target.'cfg(not(target_os = "cuda"))'.dependencies]
cust = { version = "0.3", optional = true }
Expand Down
6 changes: 5 additions & 1 deletion crates/parry3d-f64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ std = [ "nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "
dim3 = [ ]
f64 = [ ]
serde-serialize = [ "serde", "nalgebra/serde-serialize" ]
rkyv-serialize = [ "rkyv", "nalgebra/rkyv-serialize", "simba/rkyv-serialize" ]
simd-stable = [ "simba/wide", "simd-is-enabled" ]
simd-nightly = [ "simba/packed_simd", "simd-is-enabled" ]
enhanced-determinism = [ "simba/libm_force", "indexmap" ]
cuda = [ "cust_core", "cust", "nalgebra/cuda" ]
parallel = [ "rayon" ]

# Do not enable this feature directly. It is automatically
# enabled with the "simd-stable" or "simd-nightly" feature.
Expand All @@ -45,15 +47,17 @@ num-traits = { version = "0.2", default-features = false }
smallvec = "1"
slab = { version = "0.4", optional = true }
arrayvec = { version = "0.7", default-features = false }
simba = { version = "0.7", default-features = false }
simba = { version = "^0.7.2", default-features = false }
nalgebra = { version = "0.31", default-features = false, features = [ "libm" ] }
approx = { version = "0.5", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive", "rc"]}
rkyv = { version = "0.7", optional = true }
num-derive = "0.3"
indexmap = { version = "1", features = [ "serde-1" ], optional = true }
rustc-hash = { version = "1", optional = true }
cust_core = { version = "0.1", optional = true }
spade = { version = "2", optional = true } # Make this optional?
rayon = { version = "1", optional = true }

[target.'cfg(not(target_os = "cuda"))'.dependencies]
cust = { version = "0.3", optional = true }
Expand Down
7 changes: 6 additions & 1 deletion crates/parry3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ std = [ "nalgebra/std", "slab", "rustc-hash", "simba/std", "arrayvec/std", "
dim3 = [ ]
f32 = [ ]
serde-serialize = [ "serde", "nalgebra/serde-serialize" ]
rkyv-serialize = [ "rkyv", "nalgebra/rkyv-serialize", "simba/rkyv-serialize" ]

simd-stable = [ "simba/wide", "simd-is-enabled" ]
simd-nightly = [ "simba/packed_simd", "simd-is-enabled" ]
enhanced-determinism = [ "simba/libm_force", "indexmap" ]
cuda = [ "cust_core", "cust", "nalgebra/cuda" ]
parallel = [ "rayon" ]

# Do not enable this feature directly. It is automatically
# enabled with the "simd-stable" or "simd-nightly" feature.
Expand All @@ -45,15 +48,17 @@ num-traits = { version = "0.2", default-features = false }
smallvec = "1"
slab = { version = "0.4", optional = true }
arrayvec = { version = "0.7", default-features = false }
simba = { version = "0.7", default-features = false }
simba = { version = "^0.7.2", default-features = false }
nalgebra = { version = "0.31", default-features = false, features = [ "libm" ] }
approx = { version = "0.5", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive", "rc"]}
rkyv = { version = "0.7", optional = true }
num-derive = "0.3"
indexmap = { version = "1", features = [ "serde-1" ], optional = true }
rustc-hash = { version = "1", optional = true }
cust_core = { version = "0.1", optional = true }
spade = { version = "2", optional = true } # Make this optional?
rayon = { version = "1", optional = true }

[target.'cfg(not(target_os = "cuda"))'.dependencies]
cust = { version = "0.3", optional = true }
Expand Down
4 changes: 4 additions & 0 deletions src/bounding_volume/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ use na::ComplexField; // for .abs()

/// An Axis Aligned Bounding Box.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
)]
#[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))]
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct AABB {
Expand Down
4 changes: 4 additions & 0 deletions src/bounding_volume/bounding_sphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use num::Zero;

/// A Bounding Sphere.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
)]
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct BoundingSphere {
pub center: Point<Real>,
Expand Down
4 changes: 4 additions & 0 deletions src/bounding_volume/simd_aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use simba::simd::{SimdPartialOrd, SimdValue};

/// Four AABB represented as a single SoA AABB with SIMD components.
#[derive(Debug, Copy, Clone)]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
)]
pub struct SimdAABB {
/// The min coordinates of the AABBs.
pub mins: Point<SimdReal>,
Expand Down
40 changes: 9 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ std::compile_error!("The `simd-is-enabled` feature should not be enabled explici
std::compile_error!(
"SIMD cannot be enabled when the `enhanced-determinism` feature is also enabled."
);
#[cfg(all(feature = "simd-is-enabled", feature = "f64"))]
std::compile_error!(
"Explicit SIMD optimization are not yet supported when the f64 feature is enabled."
);

macro_rules! array(
($callback: expr; SIMD_WIDTH) => {
Expand Down Expand Up @@ -252,36 +248,18 @@ mod simd {

#[cfg(feature = "simd-is-enabled")]
mod simd {
#[allow(unused_imports)]
#[cfg(feature = "simd-nightly")]
use simba::simd::{f32x16, f32x4, f32x8, m32x16, m32x4, m32x8, u8x16, u8x4, u8x8};
#[cfg(feature = "simd-stable")]
use simba::simd::{WideBoolF32x4, WideF32x4};
#[cfg(all(feature = "simd-nightly", feature = "f32"))]
pub use simba::simd::{f32x4 as SimdReal, m32x4 as SimdBool};
#[cfg(all(feature = "simd-stable", feature = "f32"))]
pub use simba::simd::{WideBoolF32x4 as SimdBool, WideF32x4 as SimdReal};

#[cfg(all(feature = "simd-nightly", feature = "f64"))]
pub use simba::simd::{f64x4 as SimdReal, m64x4 as SimdBool};
#[cfg(all(feature = "simd-stable", feature = "f64"))]
pub use simba::simd::{WideBoolF64x4 as SimdBool, WideF64x4 as SimdReal};

/// The number of lanes of a SIMD number.
pub const SIMD_WIDTH: usize = 4;
/// SIMD_WIDTH - 1
pub const SIMD_LAST_INDEX: usize = 3;
#[cfg(not(feature = "simd-nightly"))]
/// A SIMD float with SIMD_WIDTH lanes.
pub type SimdReal = WideF32x4;
#[cfg(not(feature = "simd-nightly"))]
/// A SIMD bool with SIMD_WIDTH lanes.
pub type SimdBool = WideBoolF32x4;
#[cfg(feature = "simd-nightly")]
/// A SIMD float with SIMD_WIDTH lanes.
pub type SimdReal = f32x4;
#[cfg(feature = "simd-nightly")]
/// A bool float with SIMD_WIDTH lanes.
pub type SimdBool = m32x4;

// pub const SIMD_WIDTH: usize = 8;
// pub const SIMD_LAST_INDEX: usize = 7;
// pub type SimdReal = f32x8;
// pub type SimdBool = m32x8;

// pub const SIMD_WIDTH: usize = 16;
// pub const SIMD_LAST_INDEX: usize = 15;
// pub type SimdReal = f32x16;
// pub type SimdBool = m32x16;
}
4 changes: 4 additions & 0 deletions src/mass_properties/mass_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const EPSILON: Real = f32::EPSILON as Real;

#[derive(Copy, Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
)]
/// The local mass properties of a rigid-body.
pub struct MassProperties {
/// The center of mass of a rigid-body expressed in its local-space.
Expand Down
7 changes: 6 additions & 1 deletion src/partitioning/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//! Spatial partitioning tools.
pub use self::qbvh::{IndexedData, QBVHDataGenerator, QbvhNonOverlappingDataSplitter, QBVH};
pub use self::qbvh::{
CenterDataSplitter, IndexedData, NodeIndex, QBVHDataGenerator, QBVHNode, QBVHProxy,
QbvhNonOverlappingDataSplitter, SimdNodeIndex, QBVH,
};
#[cfg(feature = "parallel")]
pub use self::visitor::{ParallelSimdSimultaneousVisitor, ParallelSimdVisitor};
pub use self::visitor::{
SimdBestFirstVisitStatus, SimdBestFirstVisitor, SimdSimultaneousVisitStatus,
SimdSimultaneousVisitor, SimdVisitStatus, SimdVisitor,
Expand Down
Loading

0 comments on commit fa852f6

Please sign in to comment.