@@ -554,71 +554,34 @@ impl DescriptorAllocator {
554554 }
555555 }
556556
557- /// Free descriptor sets .
557+ /// Free a descriptor set .
558558 ///
559559 /// # Safety
560560 ///
561561 /// * Same `device` instance must be passed to all method calls of
562562 /// one `DescriptorAllocator` instance.
563- /// * None of descriptor sets can be referenced in any pending command buffers.
564- /// * All command buffers where at least one of descriptor sets referenced
563+ /// * The descriptor set cannot be referenced in any pending command buffers.
564+ /// * All command buffers where the descriptor set is referenced
565565 /// move to invalid state.
566- pub unsafe fn free < I > ( & mut self , device : & super :: DeviceShared , sets : I )
567- where
568- I : IntoIterator < Item = DescriptorSet > ,
569- {
566+ pub unsafe fn free ( & mut self , device : & super :: DeviceShared , set : DescriptorSet ) {
570567 debug_assert ! ( self . raw_sets_cache. is_empty( ) ) ;
571568
572- let mut last_key = ( Default :: default ( ) , false ) ;
573- let mut last_pool_id = None ;
569+ self . raw_sets_cache . push ( set. raw ) ;
574570
575- let mut descriptor_count = 0 ;
576-
577- // Batch freeing of adjacent descriptor sets that belong to the same bucket and pool.
578- for set in sets {
579- descriptor_count += set. size . total ( ) ;
580-
581- if last_key != ( set. size , set. update_after_bind ) || last_pool_id != Some ( set. pool_id ) {
582- if let Some ( pool_id) = last_pool_id {
583- unsafe {
584- self . free_raw_sets_cache ( device, & last_key, pool_id, descriptor_count)
585- } ;
586- descriptor_count = 0 ;
587- }
588-
589- last_key = ( set. size , set. update_after_bind ) ;
590- last_pool_id = Some ( set. pool_id ) ;
591- }
592- self . raw_sets_cache . push ( set. raw ) ;
593- }
594-
595- if let Some ( pool_id) = last_pool_id {
596- unsafe { self . free_raw_sets_cache ( device, & last_key, pool_id, descriptor_count) } ;
597- }
598- }
599-
600- /// Frees the cached descriptor sets which must be allocated from the same bucket and pool.
601- unsafe fn free_raw_sets_cache (
602- & mut self ,
603- device : & super :: DeviceShared ,
604- bucket_key : & ( DescriptorTotalCount , bool ) ,
605- pool_id : u64 ,
606- descriptor_count : u32 ,
607- ) {
608571 let bucket = self
609572 . buckets
610- . get_mut ( bucket_key )
573+ . get_mut ( & ( set . size , set . update_after_bind ) )
611574 . expect ( "Set must be allocated from this allocator" ) ;
612575
613576 debug_assert ! ( u32 :: try_from( self . raw_sets_cache. len( ) )
614577 . ok( )
615578 . is_some_and( |count| count <= bucket. total) ) ;
616579
617- unsafe { bucket. free ( device, self . raw_sets_cache . drain ( ..) , pool_id) } ;
580+ unsafe { bucket. free ( device, self . raw_sets_cache . drain ( ..) , set . pool_id ) } ;
618581
619- self . total -= descriptor_count ;
582+ self . total -= set . size . total ( ) ;
620583 if bucket. update_after_bind {
621- self . current_update_after_bind_descriptors_in_all_pools -= descriptor_count ;
584+ self . current_update_after_bind_descriptors_in_all_pools -= set . size . total ( ) ;
622585 }
623586 }
624587
0 commit comments