Skip to content

Commit d704072

Browse files
committed
Implements Device::tlas_instance_to_bytes().
1 parent 95ca795 commit d704072

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

wgpu-hal/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ metal = [
7575
"naga/msl-out",
7676
"dep:arrayvec",
7777
"dep:block",
78+
"dep:bytemuck",
7879
"dep:core-graphics-types",
7980
"dep:hashbrown",
8081
"dep:libc",

wgpu-hal/src/metal/device.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use alloc::{borrow::ToOwned as _, sync::Arc, vec::Vec};
22
use core::{ptr::NonNull, sync::atomic};
33
use std::{thread, time};
44

5+
use bytemuck::TransparentWrapper;
56
use parking_lot::Mutex;
67

78
use super::{conv, PassthroughShader};
@@ -1613,8 +1614,39 @@ impl crate::Device for super::Device {
16131614
// self.counters.acceleration_structures.sub(1);
16141615
}
16151616

1616-
fn tlas_instance_to_bytes(&self, _instance: TlasInstance) -> Vec<u8> {
1617-
unimplemented!()
1617+
fn tlas_instance_to_bytes(&self, instance: TlasInstance) -> Vec<u8> {
1618+
let temp = metal::MTLAccelerationStructureInstanceDescriptor {
1619+
transformation_matrix: [
1620+
[
1621+
instance.transform[0],
1622+
instance.transform[4],
1623+
instance.transform[8],
1624+
],
1625+
[
1626+
instance.transform[1],
1627+
instance.transform[5],
1628+
instance.transform[9],
1629+
],
1630+
[
1631+
instance.transform[2],
1632+
instance.transform[6],
1633+
instance.transform[10],
1634+
],
1635+
[
1636+
instance.transform[3],
1637+
instance.transform[7],
1638+
instance.transform[11],
1639+
],
1640+
],
1641+
options: metal::MTLAccelerationStructureInstanceOptions::None,
1642+
mask: (instance.custom_data << 8) | instance.mask as u32,
1643+
intersection_function_table_offset: 0,
1644+
acceleration_structure_index: instance.blas_address as u32,
1645+
};
1646+
1647+
wgt::bytemuck_wrapper!(unsafe struct Desc(metal::MTLAccelerationStructureInstanceDescriptor));
1648+
1649+
bytemuck::bytes_of(&Desc::wrap(temp)).to_vec()
16181650
}
16191651

16201652
fn get_internal_counters(&self) -> wgt::HalCounters {

0 commit comments

Comments
 (0)