@@ -22,8 +22,9 @@ use crate::{
2222 resource_log, track, FastHashMap , SubmissionIndex ,
2323} ;
2424
25- use hal:: { CommandEncoder as _, Device as _, Queue as _, RawSet as _ } ;
25+ use hal:: { CommandEncoder as _, Device as _, Queue as _} ;
2626use parking_lot:: Mutex ;
27+ use smallvec:: SmallVec ;
2728
2829use std:: {
2930 iter, mem, ptr,
@@ -227,20 +228,6 @@ impl<A: HalApi> PendingWrites<A> {
227228 . push ( TempResource :: StagingBuffer ( buffer) ) ;
228229 }
229230
230- #[ must_use]
231- fn pre_submit ( & mut self ) -> Option < & A :: CommandBuffer > {
232- self . dst_buffers . clear ( ) ;
233- self . dst_textures . clear ( ) ;
234- if self . is_active {
235- let cmd_buf = unsafe { self . command_encoder . end_encoding ( ) . unwrap ( ) } ;
236- self . is_active = false ;
237- self . executing_command_buffers . push ( cmd_buf) ;
238- self . executing_command_buffers . last ( )
239- } else {
240- None
241- }
242- }
243-
244231 #[ must_use]
245232 fn post_submit (
246233 & mut self ,
@@ -1116,15 +1103,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
11161103 + 1 ;
11171104 let mut active_executions = Vec :: new ( ) ;
11181105
1119- // SAFETY: We're constructing this during the submission phase,
1120- // where all resources it uses are guaranteed to outlive this
1121- // short-lived set.
1122- let mut submit_surface_textures = A :: SubmitSurfaceTextureSet :: new ( ) ;
1123-
11241106 let mut used_surface_textures = track:: TextureUsageScope :: new ( ) ;
11251107
11261108 let snatch_guard = device. snatchable_lock . read ( ) ;
11271109
1110+ let mut submit_surface_textures = SmallVec :: < [ _ ; 2 ] > :: new ( ) ;
1111+
11281112 {
11291113 let mut command_buffer_guard = hub. command_buffers . write ( ) ;
11301114
@@ -1231,9 +1215,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
12311215 has_work. store ( true , Ordering :: Relaxed ) ;
12321216
12331217 if let Some ( raw) = raw {
1234- unsafe {
1235- submit_surface_textures. insert ( raw) ;
1236- }
1218+ submit_surface_textures. push ( raw) ;
12371219 }
12381220
12391221 true
@@ -1434,9 +1416,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
14341416 has_work. store ( true , Ordering :: Relaxed ) ;
14351417
14361418 if let Some ( raw) = raw {
1437- unsafe {
1438- submit_surface_textures. insert ( raw) ;
1439- }
1419+ submit_surface_textures. push ( raw) ;
14401420 }
14411421
14421422 unsafe {
@@ -1468,8 +1448,18 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
14681448 }
14691449 }
14701450
1471- let refs = pending_writes
1472- . pre_submit ( )
1451+ pending_writes. dst_buffers . clear ( ) ;
1452+
1453+ let refs = if pending_writes. is_active {
1454+ let cmd_buf = unsafe { pending_writes. command_encoder . end_encoding ( ) . unwrap ( ) } ;
1455+ pending_writes. is_active = false ;
1456+ pending_writes. executing_command_buffers . push ( cmd_buf) ;
1457+ pending_writes. executing_command_buffers . last ( )
1458+ } else {
1459+ None
1460+ } ;
1461+
1462+ let refs = refs
14731463 . into_iter ( )
14741464 . chain (
14751465 active_executions
@@ -1487,6 +1477,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
14871477 . map_err ( DeviceError :: from) ?;
14881478 }
14891479
1480+ // We clear this here, since dst_textures is in use during the call to submit.
1481+ pending_writes. dst_textures . clear ( ) ;
1482+
14901483 profiling:: scope!( "cleanup" ) ;
14911484 if let Some ( pending_execution) = pending_writes. post_submit (
14921485 device. command_allocator . lock ( ) . as_mut ( ) . unwrap ( ) ,
0 commit comments