@@ -2,18 +2,21 @@ use alloc::{borrow::ToOwned as _, sync::Arc, vec::Vec};
22use core:: { ptr:: NonNull , sync:: atomic} ;
33use std:: { thread, time} ;
44
5+ use bytemuck:: TransparentWrapper ;
56use objc2:: {
67 msg_send,
78 rc:: { autoreleasepool, Retained } ,
89 runtime:: ProtocolObject ,
910} ;
1011use objc2_foundation:: { ns_string, NSError , NSRange , NSString } ;
1112use 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 ,
1720 MTLRenderPipelineDescriptor , MTLResource , MTLResourceID , MTLResourceOptions ,
1821 MTLSamplerAddressMode , MTLSamplerDescriptor , MTLSamplerMipFilter , MTLSamplerState , MTLSize ,
1922 MTLStencilDescriptor , MTLStorageMode , MTLTexture , MTLTextureDescriptor , MTLTextureType ,
@@ -1790,8 +1793,42 @@ impl crate::Device for super::Device {
17901793 // self.counters.acceleration_structures.sub(1);
17911794 }
17921795
1793- fn tlas_instance_to_bytes ( & self , _instance : TlasInstance ) -> Vec < u8 > {
1794- unimplemented ! ( )
1796+ fn tlas_instance_to_bytes ( & self , instance : TlasInstance ) -> Vec < u8 > {
1797+ let temp = MTLIndirectAccelerationStructureInstanceDescriptor {
1798+ transformationMatrix : MTLPackedFloat4x3 {
1799+ columns : [
1800+ MTLPackedFloat3 {
1801+ x : instance. transform [ 0 ] ,
1802+ y : instance. transform [ 4 ] ,
1803+ z : instance. transform [ 8 ] ,
1804+ } ,
1805+ MTLPackedFloat3 {
1806+ x : instance. transform [ 1 ] ,
1807+ y : instance. transform [ 5 ] ,
1808+ z : instance. transform [ 9 ] ,
1809+ } ,
1810+ MTLPackedFloat3 {
1811+ x : instance. transform [ 2 ] ,
1812+ y : instance. transform [ 6 ] ,
1813+ z : instance. transform [ 10 ] ,
1814+ } ,
1815+ MTLPackedFloat3 {
1816+ x : instance. transform [ 3 ] ,
1817+ y : instance. transform [ 7 ] ,
1818+ z : instance. transform [ 11 ] ,
1819+ } ,
1820+ ] ,
1821+ } ,
1822+ options : MTLAccelerationStructureInstanceOptions :: None ,
1823+ mask : instance. mask as u32 ,
1824+ intersectionFunctionTableOffset : 0 ,
1825+ userID : instance. custom_data ,
1826+ accelerationStructureID : unsafe { MTLResourceID :: from_raw ( instance. blas_address ) } ,
1827+ } ;
1828+
1829+ wgt:: bytemuck_wrapper!( unsafe struct Desc ( MTLIndirectAccelerationStructureInstanceDescriptor ) ) ;
1830+
1831+ bytemuck:: bytes_of ( & Desc :: wrap ( temp) ) . to_vec ( )
17951832 }
17961833
17971834 fn get_internal_counters ( & self ) -> wgt:: HalCounters {
0 commit comments