@@ -334,52 +334,6 @@ impl<T: GpuStruct, U: Allocation<T>> GpuObject<T, U> {
334334 GpuObject :: < T , U > :: new_boxed ( alloc, Box :: try_new ( inner) ?, callback)
335335 }
336336
337- /// Create a new GpuObject given an allocator, with callback-based initialization.
338- ///
339- /// This is used when the construction of the `T` type requires knowing the GPU VA address of
340- /// the structure that is being constructed ahead of time. The first callback constructs a
341- /// `Box<T>` given the pointer to the about-to-be-initialized GPU structure, and the second
342- /// callback initializes that structure as in `new_boxed`.
343- pub ( crate ) fn new_prealloc (
344- alloc : U ,
345- inner_cb : impl FnOnce ( GpuWeakPointer < T > ) -> Result < Box < T > > ,
346- raw_cb : impl for < ' a > FnOnce (
347- & ' a T ,
348- & ' a mut MaybeUninit < T :: Raw < ' a > > ,
349- GpuWeakPointer < T > ,
350- ) -> Result < & ' a mut T :: Raw < ' a > > ,
351- ) -> Result < Self > {
352- if alloc. size ( ) < mem:: size_of :: < T :: Raw < ' static > > ( ) {
353- return Err ( ENOMEM ) ;
354- }
355- let gpu_ptr =
356- GpuWeakPointer :: < T > ( NonZeroU64 :: new ( alloc. gpu_ptr ( ) ) . ok_or ( EINVAL ) ?, PhantomData ) ;
357- mod_dev_dbg ! (
358- alloc. device( ) ,
359- "Allocating {} @ {:#x}\n " ,
360- core:: any:: type_name:: <T >( ) ,
361- alloc. gpu_ptr( )
362- ) ;
363- let inner = inner_cb ( gpu_ptr) ?;
364- let p = alloc. ptr ( ) . ok_or ( EINVAL ) ?. as_ptr ( ) as * mut MaybeUninit < T :: Raw < ' _ > > ;
365- // SAFETY: `p` is guaranteed to be valid per the Allocation invariant.
366- let raw = raw_cb ( & * inner, unsafe { & mut * p } , gpu_ptr) ?;
367- if p as * mut T :: Raw < ' _ > != raw as * mut _ {
368- dev_err ! (
369- alloc. device( ) ,
370- "Allocation callback returned a mismatched reference ({})\n " ,
371- core:: any:: type_name:: <T >( ) ,
372- ) ;
373- return Err ( EINVAL ) ;
374- }
375- Ok ( Self {
376- raw : p as * mut u8 as * mut T :: Raw < ' static > ,
377- gpu_ptr,
378- alloc,
379- inner,
380- } )
381- }
382-
383337 /// Create a new GpuObject given an allocator and the boxed inner data (a type implementing
384338 /// GpuStruct).
385339 ///
0 commit comments