@@ -669,12 +669,12 @@ impl<A: HalApi> Buffer<A> {
669669 }
670670 let _ = ptr;
671671
672- if !staging_buffer . is_coherent {
673- unsafe {
674- device
675- . raw ( )
676- . flush_mapped_ranges ( staging_buffer. raw ( ) , iter :: once ( 0 .. self . size ) ) ;
677- }
672+ let mut pending_writes = device . pending_writes . lock ( ) ;
673+ let pending_writes = pending_writes . as_mut ( ) . unwrap ( ) ;
674+
675+ if let Err ( e ) = unsafe { staging_buffer . flush ( ) } {
676+ pending_writes . consume ( staging_buffer) ;
677+ return Err ( e . into ( ) ) ;
678678 }
679679
680680 self . use_at ( device. active_submission_index . load ( Ordering :: Relaxed ) + 1 ) ;
@@ -691,8 +691,6 @@ impl<A: HalApi> Buffer<A> {
691691 buffer : raw_buf,
692692 usage : hal:: BufferUses :: empty ( ) ..hal:: BufferUses :: COPY_DST ,
693693 } ;
694- let mut pending_writes = device. pending_writes . lock ( ) ;
695- let pending_writes = pending_writes. as_mut ( ) . unwrap ( ) ;
696694 let encoder = pending_writes. activate ( ) ;
697695 unsafe {
698696 encoder. transition_buffers (
@@ -706,7 +704,7 @@ impl<A: HalApi> Buffer<A> {
706704 ) ;
707705 }
708706 }
709- pending_writes. consume_temp ( queue :: TempResource :: StagingBuffer ( staging_buffer) ) ;
707+ pending_writes. consume ( staging_buffer) ;
710708 pending_writes. insert_buffer ( self ) ;
711709 }
712710 BufferMapState :: Idle => {
@@ -866,7 +864,7 @@ pub struct StagingBuffer<A: HalApi> {
866864 raw : ManuallyDrop < A :: Buffer > ,
867865 device : Arc < Device < A > > ,
868866 pub ( crate ) size : wgt:: BufferSize ,
869- pub ( crate ) is_coherent : bool ,
867+ is_coherent : bool ,
870868}
871869
872870impl < A : HalApi > StagingBuffer < A > {
0 commit comments