pub struct BvhGpuTraverser { /* private fields */ }Expand description
GPU-accelerated BVH ray traversal.
Encodes a flat BVH into GPU-resident buffers and dispatches the
bvh_traversal.wgsl kernel. Falls back to CPU traversal when no GPU
adapter is available.
§Usage
use oxiphysics_gpu::bvh::{Aabb, Bvh, BvhPrimitive, BvhGpuTraverser, GpuRay};
let prims = vec![
BvhPrimitive::new(Aabb::new([0.0, 0.0, 0.0], [1.0, 1.0, 1.0]), 0),
];
let bvh = Bvh::build(prims);
let traverser = BvhGpuTraverser::new(&bvh);
let rays = vec![GpuRay::new([0.5, 0.5, -1.0], [0.0, 0.0, 1.0], 100.0)];
let hits = traverser.traverse_rays(&rays);
assert_eq!(hits.len(), 1);Implementations§
Source§impl BvhGpuTraverser
impl BvhGpuTraverser
Sourcepub fn new(bvh: &Bvh) -> Self
pub fn new(bvh: &Bvh) -> Self
Create a traverser from a BVH.
Flattens the BVH and uploads the node + primitive buffers to the GPU. Falls back to CPU traversal if no GPU adapter is found.
Sourcepub fn new_cpu(bvh: &Bvh) -> Self
pub fn new_cpu(bvh: &Bvh) -> Self
Create a CPU-only traverser (useful for testing without a GPU).
Sourcepub fn dispatch_count(&self) -> u64
pub fn dispatch_count(&self) -> u64
Returns the current dispatch count (GPU variant only; always 0 for CPU).
Sourcepub fn creation_id(&self) -> Option<u64>
pub fn creation_id(&self) -> Option<u64>
Returns the creation_id of the underlying GPU state (for reuse tests).
Sourcepub fn traverse_rays(&self, rays: &[GpuRay]) -> Vec<i32>
pub fn traverse_rays(&self, rays: &[GpuRay]) -> Vec<i32>
Traverse the BVH for each ray.
Returns a Vec<i32> of length rays.len(). Each element is either:
- the
object_idof the first hit leaf’s primitive, or -1if no intersection was found.
Auto Trait Implementations§
impl Freeze for BvhGpuTraverser
impl RefUnwindSafe for BvhGpuTraverser
impl Send for BvhGpuTraverser
impl Sync for BvhGpuTraverser
impl Unpin for BvhGpuTraverser
impl UnsafeUnpin for BvhGpuTraverser
impl UnwindSafe for BvhGpuTraverser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more