From febec1928e37c0ca5084cef550d01242bd7c6316 Mon Sep 17 00:00:00 2001 From: Jasper Bekkers Date: Tue, 24 Jan 2023 16:50:01 +0100 Subject: [PATCH] Speed up rkyv serialization --- src/bounding_volume/simd_aabb.rs | 2 +- src/partitioning/mod.rs | 1 + src/partitioning/qbvh/qbvh.rs | 9 +++++++-- src/shape/trimesh.rs | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/bounding_volume/simd_aabb.rs b/src/bounding_volume/simd_aabb.rs index 15a7c090..c8fce942 100644 --- a/src/bounding_volume/simd_aabb.rs +++ b/src/bounding_volume/simd_aabb.rs @@ -9,7 +9,7 @@ use simba::simd::{SimdPartialOrd, SimdValue}; #[derive(Debug, Copy, Clone)] #[cfg_attr( feature = "rkyv", - derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize) + derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize), )] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] pub struct SimdAabb { diff --git a/src/partitioning/mod.rs b/src/partitioning/mod.rs index 48c03823..5537d7c7 100644 --- a/src/partitioning/mod.rs +++ b/src/partitioning/mod.rs @@ -6,6 +6,7 @@ pub use self::qbvh::{ }; pub use self::qbvh::{ GenericQbvh, IndexedData, NodeIndex, Qbvh, QbvhNode, QbvhProxy, QbvhStorage, SimdNodeIndex, + QbvhNodeFlags, }; #[cfg(feature = "parallel")] pub use self::visitor::{ParallelSimdSimultaneousVisitor, ParallelSimdVisitor}; diff --git a/src/partitioning/qbvh/qbvh.rs b/src/partitioning/qbvh/qbvh.rs index 7c52c44c..9e92331e 100644 --- a/src/partitioning/qbvh/qbvh.rs +++ b/src/partitioning/qbvh/qbvh.rs @@ -98,7 +98,7 @@ bitflags! { #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] #[derive(Default)] /// The status of a QBVH node. - pub struct QbvhNodeFlags: u8 { + pub struct QbvhNodeFlags: u64 { /// If this bit is set, the node is a leaf. const LEAF = 0b0001; /// If this bit is set, this node was recently changed. @@ -115,9 +115,10 @@ bitflags! { #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "rkyv", - derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize) + derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize), )] #[cfg_attr(feature = "cuda", derive(cust_core::DeviceCopy))] +#[repr(C)] pub struct QbvhNode { /// The Aabbs of the qbvh nodes represented by this node. pub simd_aabb: SimdAabb, @@ -234,9 +235,13 @@ impl QbvhProxy { #[derive(Debug)] pub struct GenericQbvh> { pub(super) root_aabb: Aabb, + #[cfg_attr(feature = "rkyv", with(rkyv::with::CopyOptimize))] pub(super) nodes: Storage::Nodes, + #[cfg_attr(feature = "rkyv", with(rkyv::with::CopyOptimize))] pub(super) dirty_nodes: Storage::ArrayU32, + #[cfg_attr(feature = "rkyv", with(rkyv::with::CopyOptimize))] pub(super) free_list: Storage::ArrayU32, + #[cfg_attr(feature = "rkyv", with(rkyv::with::CopyOptimize))] pub(super) proxies: Storage::ArrayProxies, } diff --git a/src/shape/trimesh.rs b/src/shape/trimesh.rs index faa38080..04f69ccc 100644 --- a/src/shape/trimesh.rs +++ b/src/shape/trimesh.rs @@ -342,7 +342,9 @@ bitflags::bitflags! { /// A triangle mesh. pub struct GenericTriMesh { qbvh: GenericQbvh, + #[cfg_attr(feature = "rkyv", with(rkyv::with::CopyOptimize))] vertices: Storage::ArrayPoint, + #[cfg_attr(feature = "rkyv", with(rkyv::with::CopyOptimize))] indices: Storage::ArrayIdx, #[cfg(feature = "dim3")] pub(crate) pseudo_normals: Option>,