File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -419,9 +419,12 @@ impl crate::CommandEncoder for super::CommandEncoder {
419419 list. set_name ( label) ?;
420420 }
421421
422- self . list = Some ( list ) ;
422+ // Ensure clean state even if the last encoding did not complete normally.
423423 self . temp . clear ( ) ;
424424 self . pass . clear ( ) ;
425+ self . end_of_pass_timer_query = None ;
426+
427+ self . list = Some ( list) ;
425428 Ok ( ( ) )
426429 }
427430 unsafe fn discard_encoding ( & mut self ) {
Original file line number Diff line number Diff line change @@ -964,6 +964,8 @@ impl PassState {
964964 }
965965}
966966
967+ // Any state in this struct that may be dirty after an abandoned encoding must
968+ // be reset for reused encoders in `begin_encoding`.
967969pub struct CommandEncoder {
968970 allocator : Direct3D12 :: ID3D12CommandAllocator ,
969971 device : Direct3D12 :: ID3D12Device ,
Original file line number Diff line number Diff line change @@ -490,6 +490,11 @@ impl crate::CommandEncoder for super::CommandEncoder {
490490 cmd_buf_ref. to_owned ( )
491491 } ) ;
492492
493+ // Queries should either be closed out, or cleared in `discard_encoding`.
494+ // This assertion is here mainly to facilitate comparison with the other
495+ // backends, which clear in `begin_encoding` rather than `discard_encoding`.
496+ debug_assert ! ( self . state. pending_timer_queries. is_empty( ) ) ;
497+
493498 self . raw_cmd_buf = Some ( raw) ;
494499
495500 Ok ( ( ) )
@@ -506,6 +511,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
506511 if let Some ( encoder) = self . state . compute . take ( ) {
507512 encoder. endEncoding ( ) ;
508513 }
514+ self . state . pending_timer_queries . clear ( ) ;
509515 let had_command_buffer = self . raw_cmd_buf . is_some ( ) ;
510516 // Clear the Option first so the underlying `metal::CommandBuffer` is
511517 // dropped before we update the counter.
Original file line number Diff line number Diff line change @@ -1080,6 +1080,8 @@ struct Temp {
10801080 binding_sizes : Vec < u32 > ,
10811081}
10821082
1083+ // Any state in this struct that may be dirty after an abandoned encoding must
1084+ // be reset in `discard_encoding` for possible encoder reuse.
10831085struct CommandState {
10841086 blit : Option < Retained < ProtocolObject < dyn MTLBlitCommandEncoder > > > ,
10851087 acceleration_structure_builder :
@@ -1119,6 +1121,8 @@ struct CommandState {
11191121 pending_timer_queries : Vec < ( QuerySet , u32 ) > ,
11201122}
11211123
1124+ // Any state in this struct that may be dirty after an abandoned encoding must
1125+ // be reset in `discard_encoding` for possible encoder reuse.
11221126pub struct CommandEncoder {
11231127 shared : Arc < AdapterShared > ,
11241128 queue_shared : Arc < QueueShared > ,
Original file line number Diff line number Diff line change @@ -138,8 +138,9 @@ impl crate::CommandEncoder for super::CommandEncoder {
138138 // previous name assigned to this.
139139 unsafe { self . device . set_object_name ( raw, label. unwrap_or_default ( ) ) } ;
140140
141- // Reset this in case the last renderpass was never ended.
141+ // Reset some state in case the last renderpass was never ended.
142142 self . rpass_debug_marker_active = false ;
143+ self . end_of_pass_timer_query = None ;
143144
144145 let vk_info = vk:: CommandBufferBeginInfo :: default ( )
145146 . flags ( vk:: CommandBufferUsageFlags :: ONE_TIME_SUBMIT ) ;
Original file line number Diff line number Diff line change @@ -984,6 +984,8 @@ struct TempTextureViewKey {
984984 depth_slice : u32 ,
985985}
986986
987+ // Any state in this struct that may be dirty after an abandoned encoding must
988+ // be reset for reused encoders in `begin_encoding`.
987989pub struct CommandEncoder {
988990 raw : vk:: CommandPool ,
989991 device : Arc < DeviceShared > ,
You can’t perform that action at this time.
0 commit comments