@@ -112,17 +112,17 @@ impl<T, U: RawAllocation> Debug for GenericAlloc<T, U> {
112112#[ repr( C ) ]
113113struct AllocDebugData {
114114 state : u32 ,
115- _pad : u32 ,
115+ tag : u32 ,
116116 size : u64 ,
117117 base_gpuva : u64 ,
118118 obj_gpuva : u64 ,
119119 name : [ u8 ; 0x20 ] ,
120120}
121121
122122/// Magic flag indicating a live allocation.
123- const STATE_LIVE : u32 = 0x4556494c ;
123+ const STATE_LIVE : u32 = u32 :: from_le_bytes ( * b"LIVE" ) ;
124124/// Magic flag indicating a freed allocation.
125- const STATE_DEAD : u32 = 0x44414544 ;
125+ const STATE_DEAD : u32 = u32 :: from_le_bytes ( * b"DEAD" ) ;
126126
127127/// Marker byte to identify when firmware/GPU write beyond the end of an allocation.
128128const GUARD_MARKER : u8 = 0x93 ;
@@ -292,6 +292,7 @@ pub(crate) trait Allocator {
292292 & mut self ,
293293 size : usize ,
294294 align : usize ,
295+ tag : Option < u32 > ,
295296 ) -> Result < GenericAlloc < T , Self :: Raw > > {
296297 let padding = if debug_enabled ( DebugFlags :: DetectOverflows ) {
297298 size
@@ -309,7 +310,7 @@ pub(crate) trait Allocator {
309310
310311 let mut debug = AllocDebugData {
311312 state : STATE_LIVE ,
312- _pad : 0 ,
313+ tag : tag . unwrap_or ( 0 ) ,
313314 size : size as u64 ,
314315 base_gpuva : alloc. gpu_ptr ( ) ,
315316 obj_gpuva : alloc. gpu_ptr ( ) + debug_offset as u64 ,
@@ -376,7 +377,7 @@ pub(crate) trait Allocator {
376377 let size = mem:: size_of :: < T :: Raw < ' static > > ( ) ;
377378 let align = mem:: align_of :: < T :: Raw < ' static > > ( ) ;
378379
379- self . alloc_generic ( size, align)
380+ self . alloc_generic ( size, align, None )
380381 }
381382
382383 /// Allocate an empty `GpuArray` of a given type and length.
@@ -387,7 +388,20 @@ pub(crate) trait Allocator {
387388 let size = mem:: size_of :: < T > ( ) * count;
388389 let align = mem:: align_of :: < T > ( ) ;
389390
390- let alloc = self . alloc_generic ( size, align) ?;
391+ let alloc = self . alloc_generic ( size, align, None ) ?;
392+ GpuArray :: < T , GenericAlloc < T , Self :: Raw > > :: empty ( alloc, count)
393+ }
394+
395+ /// Allocate an empty `GpuArray` of a given type and length.
396+ fn array_empty_tagged < T : Sized + Default > (
397+ & mut self ,
398+ count : usize ,
399+ tag : & [ u8 ; 4 ] ,
400+ ) -> Result < GpuArray < T , GenericAlloc < T , Self :: Raw > > > {
401+ let size = mem:: size_of :: < T > ( ) * count;
402+ let align = mem:: align_of :: < T > ( ) ;
403+
404+ let alloc = self . alloc_generic ( size, align, Some ( u32:: from_le_bytes ( * tag) ) ) ?;
391405 GpuArray :: < T , GenericAlloc < T , Self :: Raw > > :: empty ( alloc, count)
392406 }
393407
@@ -399,7 +413,7 @@ pub(crate) trait Allocator {
399413 let size = mem:: size_of :: < T > ( ) * count;
400414 let align = mem:: align_of :: < T > ( ) ;
401415
402- let alloc = self . alloc_generic ( size, align) ?;
416+ let alloc = self . alloc_generic ( size, align, None ) ?;
403417 GpuOnlyArray :: < T , GenericAlloc < T , Self :: Raw > > :: new ( alloc, count)
404418 }
405419}
0 commit comments