@@ -2,18 +2,21 @@ use alloc::{borrow::ToOwned as _, sync::Arc, vec::Vec};
2
2
use core:: { ptr:: NonNull , sync:: atomic} ;
3
3
use std:: { thread, time} ;
4
4
5
+ use bytemuck:: TransparentWrapper ;
5
6
use objc2:: {
6
7
msg_send,
7
8
rc:: { autoreleasepool, Retained } ,
8
9
runtime:: ProtocolObject ,
9
10
} ;
10
11
use objc2_foundation:: { ns_string, NSError , NSRange , NSString } ;
11
12
use objc2_metal:: {
12
- MTLAccelerationStructure , MTLBuffer , MTLCaptureManager , MTLCaptureScope , MTLCommandBuffer ,
13
- MTLCommandBufferStatus , MTLCompileOptions , MTLComputePipelineDescriptor ,
14
- MTLComputePipelineState , MTLCounterSampleBufferDescriptor , MTLCounterSet , MTLDepthClipMode ,
15
- MTLDepthStencilDescriptor , MTLDevice , MTLFunction , MTLLanguageVersion , MTLLibrary ,
16
- MTLMutability , MTLPipelineBufferDescriptorArray , MTLPixelFormat , MTLPrimitiveTopologyClass ,
13
+ MTLAccelerationStructure , MTLAccelerationStructureInstanceOptions , MTLBuffer ,
14
+ MTLCaptureManager , MTLCaptureScope , MTLCommandBuffer , MTLCommandBufferStatus ,
15
+ MTLCompileOptions , MTLComputePipelineDescriptor , MTLComputePipelineState ,
16
+ MTLCounterSampleBufferDescriptor , MTLCounterSet , MTLDepthClipMode , MTLDepthStencilDescriptor ,
17
+ MTLDevice , MTLFunction , MTLIndirectAccelerationStructureInstanceDescriptor , MTLLanguageVersion ,
18
+ MTLLibrary , MTLMutability , MTLPackedFloat3 , MTLPackedFloat4x3 ,
19
+ MTLPipelineBufferDescriptorArray , MTLPixelFormat , MTLPrimitiveTopologyClass ,
17
20
MTLRenderPipelineDescriptor , MTLResource , MTLResourceID , MTLResourceOptions ,
18
21
MTLSamplerAddressMode , MTLSamplerDescriptor , MTLSamplerMipFilter , MTLSamplerState , MTLSize ,
19
22
MTLStencilDescriptor , MTLStorageMode , MTLTexture , MTLTextureDescriptor , MTLTextureType ,
@@ -1706,8 +1709,42 @@ impl crate::Device for super::Device {
1706
1709
// self.counters.acceleration_structures.sub(1);
1707
1710
}
1708
1711
1709
- fn tlas_instance_to_bytes ( & self , _instance : TlasInstance ) -> Vec < u8 > {
1710
- unimplemented ! ( )
1712
+ fn tlas_instance_to_bytes ( & self , instance : TlasInstance ) -> Vec < u8 > {
1713
+ let temp = MTLIndirectAccelerationStructureInstanceDescriptor {
1714
+ transformationMatrix : MTLPackedFloat4x3 {
1715
+ columns : [
1716
+ MTLPackedFloat3 {
1717
+ x : instance. transform [ 0 ] ,
1718
+ y : instance. transform [ 4 ] ,
1719
+ z : instance. transform [ 8 ] ,
1720
+ } ,
1721
+ MTLPackedFloat3 {
1722
+ x : instance. transform [ 1 ] ,
1723
+ y : instance. transform [ 5 ] ,
1724
+ z : instance. transform [ 9 ] ,
1725
+ } ,
1726
+ MTLPackedFloat3 {
1727
+ x : instance. transform [ 2 ] ,
1728
+ y : instance. transform [ 6 ] ,
1729
+ z : instance. transform [ 10 ] ,
1730
+ } ,
1731
+ MTLPackedFloat3 {
1732
+ x : instance. transform [ 3 ] ,
1733
+ y : instance. transform [ 7 ] ,
1734
+ z : instance. transform [ 11 ] ,
1735
+ } ,
1736
+ ] ,
1737
+ } ,
1738
+ options : MTLAccelerationStructureInstanceOptions :: None ,
1739
+ mask : instance. mask as u32 ,
1740
+ intersectionFunctionTableOffset : 0 ,
1741
+ userID : instance. custom_data ,
1742
+ accelerationStructureID : unsafe { MTLResourceID :: from_raw ( instance. blas_address ) } ,
1743
+ } ;
1744
+
1745
+ wgt:: bytemuck_wrapper!( unsafe struct Desc ( MTLIndirectAccelerationStructureInstanceDescriptor ) ) ;
1746
+
1747
+ bytemuck:: bytes_of ( & Desc :: wrap ( temp) ) . to_vec ( )
1711
1748
}
1712
1749
1713
1750
fn get_internal_counters ( & self ) -> wgt:: HalCounters {
0 commit comments