@@ -6,21 +6,23 @@ mod visualizer;
66pub  use  visualizer:: AllocatorVisualizer ; 
77
88use  log:: debug; 
9- use  metal:: { MTLDevice  as  _,  MTLHeap  as  _,  MTLResource  as  _} ; 
109use  objc2:: { rc:: Retained ,  runtime:: ProtocolObject } ; 
1110use  objc2_foundation:: NSString ; 
12- use  objc2_metal as  metal; 
11+ use  objc2_metal:: { 
12+     MTLAccelerationStructure ,  MTLBuffer ,  MTLCPUCacheMode ,  MTLDevice ,  MTLHeap ,  MTLHeapDescriptor , 
13+     MTLHeapType ,  MTLResource ,  MTLResourceOptions ,  MTLStorageMode ,  MTLTexture ,  MTLTextureDescriptor , 
14+ } ; 
1315
1416use  crate :: { 
1517    allocator:: { self ,  AllocatorReport ,  MemoryBlockReport } , 
1618    AllocationError ,  AllocationSizes ,  AllocatorDebugSettings ,  MemoryLocation ,  Result , 
1719} ; 
1820
19- fn  memory_location_to_metal ( location :  MemoryLocation )  -> metal :: MTLResourceOptions  { 
21+ fn  memory_location_to_metal ( location :  MemoryLocation )  -> MTLResourceOptions  { 
2022    match  location { 
21-         MemoryLocation :: GpuOnly  => metal :: MTLResourceOptions :: MTLResourceStorageModePrivate , 
23+         MemoryLocation :: GpuOnly  => MTLResourceOptions :: MTLResourceStorageModePrivate , 
2224        MemoryLocation :: CpuToGpu  | MemoryLocation :: GpuToCpu  | MemoryLocation :: Unknown  => { 
23-             metal :: MTLResourceOptions :: MTLResourceStorageModeShared 
25+             MTLResourceOptions :: MTLResourceStorageModeShared 
2426        } 
2527    } 
2628} 
@@ -32,16 +34,16 @@ pub struct Allocation {
3234    size :  u64 , 
3335    memory_block_index :  usize , 
3436    memory_type_index :  usize , 
35-     heap :  Retained < ProtocolObject < dyn  metal :: MTLHeap > > , 
37+     heap :  Retained < ProtocolObject < dyn  MTLHeap > > , 
3638    name :  Option < Box < str > > , 
3739} 
3840
3941impl  Allocation  { 
40-     pub  fn  heap ( & self )  -> & ProtocolObject < dyn  metal :: MTLHeap >  { 
42+     pub  fn  heap ( & self )  -> & ProtocolObject < dyn  MTLHeap >  { 
4143        & self . heap 
4244    } 
4345
44-     pub  fn  make_buffer ( & self )  -> Option < Retained < ProtocolObject < dyn  metal :: MTLBuffer > > >  { 
46+     pub  fn  make_buffer ( & self )  -> Option < Retained < ProtocolObject < dyn  MTLBuffer > > >  { 
4547        let  resource = unsafe  { 
4648            self . heap . newBufferWithLength_options_offset ( 
4749                self . size  as  usize , 
@@ -59,8 +61,8 @@ impl Allocation {
5961
6062    pub  fn  make_texture ( 
6163        & self , 
62-         desc :  & metal :: MTLTextureDescriptor , 
63-     )  -> Option < Retained < ProtocolObject < dyn  metal :: MTLTexture > > >  { 
64+         desc :  & MTLTextureDescriptor , 
65+     )  -> Option < Retained < ProtocolObject < dyn  MTLTexture > > >  { 
6466        let  resource = unsafe  { 
6567            self . heap 
6668                . newTextureWithDescriptor_offset ( desc,  self . offset  as  usize ) 
@@ -75,7 +77,7 @@ impl Allocation {
7577
7678    pub  fn  make_acceleration_structure ( 
7779        & self , 
78-     )  -> Option < Retained < ProtocolObject < dyn  metal :: MTLAccelerationStructure > > >  { 
80+     )  -> Option < Retained < ProtocolObject < dyn  MTLAccelerationStructure > > >  { 
7981        let  resource = unsafe  { 
8082            self . heap 
8183                . newAccelerationStructureWithSize_offset ( self . size  as  usize ,  self . offset  as  usize ) 
@@ -105,7 +107,7 @@ pub struct AllocationCreateDesc<'a> {
105107
106108impl < ' a >  AllocationCreateDesc < ' a >  { 
107109    pub  fn  buffer ( 
108-         device :  & ProtocolObject < dyn  metal :: MTLDevice > , 
110+         device :  & ProtocolObject < dyn  MTLDevice > , 
109111        name :  & ' a  str , 
110112        length :  u64 , 
111113        location :  MemoryLocation , 
@@ -123,27 +125,27 @@ impl<'a> AllocationCreateDesc<'a> {
123125    } 
124126
125127    pub  fn  texture ( 
126-         device :  & ProtocolObject < dyn  metal :: MTLDevice > , 
128+         device :  & ProtocolObject < dyn  MTLDevice > , 
127129        name :  & ' a  str , 
128-         desc :  & metal :: MTLTextureDescriptor , 
130+         desc :  & MTLTextureDescriptor , 
129131    )  -> Self  { 
130132        let  size_and_align = device. heapTextureSizeAndAlignWithDescriptor ( desc) ; 
131133        Self  { 
132134            name, 
133135            location :  match  desc. storageMode ( )  { 
134-                 metal :: MTLStorageMode :: Shared 
135-                 | metal :: MTLStorageMode :: Managed 
136-                 | metal :: MTLStorageMode :: Memoryless  =>  MemoryLocation :: Unknown , 
137-                 metal :: MTLStorageMode :: Private  => MemoryLocation :: GpuOnly , 
138-                 metal :: MTLStorageMode ( mode /* @ 4.. */ )  => todo ! ( "Unknown storage mode {mode}" ) , 
136+                 MTLStorageMode :: Shared  |  MTLStorageMode :: Managed  |  MTLStorageMode :: Memoryless  =>  { 
137+                      MemoryLocation :: Unknown 
138+                 } 
139+                 MTLStorageMode :: Private  => MemoryLocation :: GpuOnly , 
140+                 MTLStorageMode ( mode /* @ 4.. */ )  => todo ! ( "Unknown storage mode {mode}" ) , 
139141            } , 
140142            size :  size_and_align. size  as  u64 , 
141143            alignment :  size_and_align. align  as  u64 , 
142144        } 
143145    } 
144146
145147    pub  fn  acceleration_structure_with_size ( 
146-         device :  & ProtocolObject < dyn  metal :: MTLDevice > , 
148+         device :  & ProtocolObject < dyn  MTLDevice > , 
147149        name :  & ' a  str , 
148150        size :  u64 ,  // TODO: usize 
149151        location :  MemoryLocation , 
@@ -162,7 +164,7 @@ impl<'a> AllocationCreateDesc<'a> {
162164} 
163165
164166pub  struct  Allocator  { 
165-     device :  Retained < ProtocolObject < dyn  metal :: MTLDevice > > , 
167+     device :  Retained < ProtocolObject < dyn  MTLDevice > > , 
166168    debug_settings :  AllocatorDebugSettings , 
167169    memory_types :  Vec < MemoryType > , 
168170    allocation_sizes :  AllocationSizes , 
@@ -176,7 +178,7 @@ impl std::fmt::Debug for Allocator {
176178
177179#[ derive( Debug ) ]  
178180pub  struct  AllocatorCreateDesc  { 
179-     pub  device :  Retained < ProtocolObject < dyn  metal :: MTLDevice > > , 
181+     pub  device :  Retained < ProtocolObject < dyn  MTLDevice > > , 
180182    pub  debug_settings :  AllocatorDebugSettings , 
181183    pub  allocation_sizes :  AllocationSizes , 
182184} 
@@ -189,16 +191,16 @@ pub struct CommittedAllocationStatistics {
189191
190192#[ derive( Debug ) ]  
191193struct  MemoryBlock  { 
192-     heap :  Retained < ProtocolObject < dyn  metal :: MTLHeap > > , 
194+     heap :  Retained < ProtocolObject < dyn  MTLHeap > > , 
193195    size :  u64 , 
194196    sub_allocator :  Box < dyn  allocator:: SubAllocator > , 
195197} 
196198
197199impl  MemoryBlock  { 
198200    fn  new ( 
199-         device :  & ProtocolObject < dyn  metal :: MTLDevice > , 
201+         device :  & ProtocolObject < dyn  MTLDevice > , 
200202        size :  u64 , 
201-         heap_descriptor :  & metal :: MTLHeapDescriptor , 
203+         heap_descriptor :  & MTLHeapDescriptor , 
202204        dedicated :  bool , 
203205        memory_location :  MemoryLocation , 
204206    )  -> Result < Self >  { 
@@ -231,23 +233,22 @@ struct MemoryType {
231233    memory_blocks :  Vec < Option < MemoryBlock > > , 
232234    _committed_allocations :  CommittedAllocationStatistics , 
233235    memory_location :  MemoryLocation , 
234-     heap_properties :  Retained < metal :: MTLHeapDescriptor > , 
236+     heap_properties :  Retained < MTLHeapDescriptor > , 
235237    memory_type_index :  usize , 
236238    active_general_blocks :  usize , 
237239} 
238240
239241impl  MemoryType  { 
240242    fn  allocate ( 
241243        & mut  self , 
242-         device :  & ProtocolObject < dyn  metal :: MTLDevice > , 
244+         device :  & ProtocolObject < dyn  MTLDevice > , 
243245        desc :  & AllocationCreateDesc < ' _ > , 
244246        backtrace :  Arc < Backtrace > , 
245247        allocation_sizes :  & AllocationSizes , 
246248    )  -> Result < Allocation >  { 
247249        let  allocation_type = allocator:: AllocationType :: Linear ; 
248250
249-         let  memblock_size = if  self . heap_properties . storageMode ( )  == metal:: MTLStorageMode :: Private 
250-         { 
251+         let  memblock_size = if  self . heap_properties . storageMode ( )  == MTLStorageMode :: Private  { 
251252            allocation_sizes. device_memblock_size 
252253        }  else  { 
253254            allocation_sizes. host_memblock_size 
@@ -422,24 +423,24 @@ impl Allocator {
422423    pub  fn  new ( desc :  & AllocatorCreateDesc )  -> Result < Self >  { 
423424        let  heap_types = [ 
424425            ( MemoryLocation :: GpuOnly ,  { 
425-                 let  heap_desc = unsafe  {  metal :: MTLHeapDescriptor :: new ( )  } ; 
426-                 heap_desc. setCpuCacheMode ( metal :: MTLCPUCacheMode :: DefaultCache ) ; 
427-                 heap_desc. setStorageMode ( metal :: MTLStorageMode :: Private ) ; 
428-                 heap_desc. setType ( metal :: MTLHeapType :: Placement ) ; 
426+                 let  heap_desc = unsafe  {  MTLHeapDescriptor :: new ( )  } ; 
427+                 heap_desc. setCpuCacheMode ( MTLCPUCacheMode :: DefaultCache ) ; 
428+                 heap_desc. setStorageMode ( MTLStorageMode :: Private ) ; 
429+                 heap_desc. setType ( MTLHeapType :: Placement ) ; 
429430                heap_desc
430431            } ) , 
431432            ( MemoryLocation :: CpuToGpu ,  { 
432-                 let  heap_desc = unsafe  {  metal :: MTLHeapDescriptor :: new ( )  } ; 
433-                 heap_desc. setCpuCacheMode ( metal :: MTLCPUCacheMode :: WriteCombined ) ; 
434-                 heap_desc. setStorageMode ( metal :: MTLStorageMode :: Shared ) ; 
435-                 heap_desc. setType ( metal :: MTLHeapType :: Placement ) ; 
433+                 let  heap_desc = unsafe  {  MTLHeapDescriptor :: new ( )  } ; 
434+                 heap_desc. setCpuCacheMode ( MTLCPUCacheMode :: WriteCombined ) ; 
435+                 heap_desc. setStorageMode ( MTLStorageMode :: Shared ) ; 
436+                 heap_desc. setType ( MTLHeapType :: Placement ) ; 
436437                heap_desc
437438            } ) , 
438439            ( MemoryLocation :: GpuToCpu ,  { 
439-                 let  heap_desc = unsafe  {  metal :: MTLHeapDescriptor :: new ( )  } ; 
440-                 heap_desc. setCpuCacheMode ( metal :: MTLCPUCacheMode :: DefaultCache ) ; 
441-                 heap_desc. setStorageMode ( metal :: MTLStorageMode :: Shared ) ; 
442-                 heap_desc. setType ( metal :: MTLHeapType :: Placement ) ; 
440+                 let  heap_desc = unsafe  {  MTLHeapDescriptor :: new ( )  } ; 
441+                 heap_desc. setCpuCacheMode ( MTLCPUCacheMode :: DefaultCache ) ; 
442+                 heap_desc. setStorageMode ( MTLStorageMode :: Shared ) ; 
443+                 heap_desc. setType ( MTLHeapType :: Placement ) ; 
443444                heap_desc
444445            } ) , 
445446        ] ; 
@@ -525,7 +526,7 @@ impl Allocator {
525526    } 
526527
527528    /// Returns heaps for all memory blocks 
528-      pub  fn  heaps ( & self )  -> impl  Iterator < Item  = & ProtocolObject < dyn  metal :: MTLHeap > >  { 
529+      pub  fn  heaps ( & self )  -> impl  Iterator < Item  = & ProtocolObject < dyn  MTLHeap > >  { 
529530        self . memory_types . iter ( ) . flat_map ( |memory_type| { 
530531            memory_type
531532                . memory_blocks 
0 commit comments