@@ -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 ,
@@ -1706,8 +1709,42 @@ impl crate::Device for super::Device {
17061709 // self.counters.acceleration_structures.sub(1);
17071710 }
17081711
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 ( )
17111748 }
17121749
17131750 fn get_internal_counters ( & self ) -> wgt:: HalCounters {
0 commit comments