@@ -172,10 +172,10 @@ impl CommandEncoder {
172172 /// [l]: CommandEncoder::list
173173 /// [`transition_buffers`]: hal::CommandEncoder::transition_buffers
174174 /// [`transition_textures`]: hal::CommandEncoder::transition_textures
175- fn close_and_swap ( & mut self ) -> Result < ( ) , DeviceError > {
175+ fn close_and_swap ( & mut self , device : & Device ) -> Result < ( ) , DeviceError > {
176176 if self . is_open {
177177 self . is_open = false ;
178- let new = unsafe { self . raw . end_encoding ( ) ? } ;
178+ let new = unsafe { self . raw . end_encoding ( ) } . map_err ( |e| device . handle_hal_error ( e ) ) ? ;
179179 self . list . insert ( self . list . len ( ) - 1 , new) ;
180180 }
181181
@@ -192,10 +192,11 @@ impl CommandEncoder {
192192 /// On return, the underlying hal encoder is closed.
193193 ///
194194 /// [l]: CommandEncoder::list
195- fn close ( & mut self ) -> Result < ( ) , DeviceError > {
195+ fn close ( & mut self , device : & Device ) -> Result < ( ) , DeviceError > {
196196 if self . is_open {
197197 self . is_open = false ;
198- let cmd_buf = unsafe { self . raw . end_encoding ( ) ? } ;
198+ let cmd_buf =
199+ unsafe { self . raw . end_encoding ( ) } . map_err ( |e| device. handle_hal_error ( e) ) ?;
199200 self . list . push ( cmd_buf) ;
200201 }
201202
@@ -215,11 +216,15 @@ impl CommandEncoder {
215216 /// Begin recording a new command buffer, if we haven't already.
216217 ///
217218 /// The underlying hal encoder is put in the "recording" state.
218- pub ( crate ) fn open ( & mut self ) -> Result < & mut dyn hal:: DynCommandEncoder , DeviceError > {
219+ pub ( crate ) fn open (
220+ & mut self ,
221+ device : & Device ,
222+ ) -> Result < & mut dyn hal:: DynCommandEncoder , DeviceError > {
219223 if !self . is_open {
220224 self . is_open = true ;
221225 let hal_label = self . hal_label . as_deref ( ) ;
222- unsafe { self . raw . begin_encoding ( hal_label) ? } ;
226+ unsafe { self . raw . begin_encoding ( hal_label) }
227+ . map_err ( |e| device. handle_hal_error ( e) ) ?;
223228 }
224229
225230 Ok ( self . raw . as_mut ( ) )
@@ -229,9 +234,9 @@ impl CommandEncoder {
229234 /// its own label.
230235 ///
231236 /// The underlying hal encoder is put in the "recording" state.
232- fn open_pass ( & mut self , hal_label : Option < & str > ) -> Result < ( ) , DeviceError > {
237+ fn open_pass ( & mut self , hal_label : Option < & str > , device : & Device ) -> Result < ( ) , DeviceError > {
233238 self . is_open = true ;
234- unsafe { self . raw . begin_encoding ( hal_label) ? } ;
239+ unsafe { self . raw . begin_encoding ( hal_label) } . map_err ( |e| device . handle_hal_error ( e ) ) ? ;
235240
236241 Ok ( ( ) )
237242 }
@@ -276,8 +281,9 @@ pub struct CommandBufferMutable {
276281impl CommandBufferMutable {
277282 pub ( crate ) fn open_encoder_and_tracker (
278283 & mut self ,
284+ device : & Device ,
279285 ) -> Result < ( & mut dyn hal:: DynCommandEncoder , & mut Tracker ) , DeviceError > {
280- let encoder = self . encoder . open ( ) ?;
286+ let encoder = self . encoder . open ( device ) ?;
281287 let tracker = & mut self . trackers ;
282288
283289 Ok ( ( encoder, tracker) )
@@ -621,7 +627,7 @@ impl Global {
621627 let cmd_buf_data = cmd_buf_data. as_mut ( ) . unwrap ( ) ;
622628 match cmd_buf_data. status {
623629 CommandEncoderStatus :: Recording => {
624- if let Err ( e) = cmd_buf_data. encoder . close ( ) {
630+ if let Err ( e) = cmd_buf_data. encoder . close ( & cmd_buf . device ) {
625631 Some ( e. into ( ) )
626632 } else {
627633 cmd_buf_data. status = CommandEncoderStatus :: Finished ;
@@ -671,7 +677,7 @@ impl Global {
671677 list. push ( TraceCommand :: PushDebugGroup ( label. to_string ( ) ) ) ;
672678 }
673679
674- let cmd_buf_raw = cmd_buf_data. encoder . open ( ) ?;
680+ let cmd_buf_raw = cmd_buf_data. encoder . open ( & cmd_buf . device ) ?;
675681 if !self
676682 . instance
677683 . flags
@@ -713,7 +719,7 @@ impl Global {
713719 . flags
714720 . contains ( wgt:: InstanceFlags :: DISCARD_HAL_LABELS )
715721 {
716- let cmd_buf_raw = cmd_buf_data. encoder . open ( ) ?;
722+ let cmd_buf_raw = cmd_buf_data. encoder . open ( & cmd_buf . device ) ?;
717723 unsafe {
718724 cmd_buf_raw. insert_debug_marker ( label) ;
719725 }
@@ -744,7 +750,7 @@ impl Global {
744750 list. push ( TraceCommand :: PopDebugGroup ) ;
745751 }
746752
747- let cmd_buf_raw = cmd_buf_data. encoder . open ( ) ?;
753+ let cmd_buf_raw = cmd_buf_data. encoder . open ( & cmd_buf . device ) ?;
748754 if !self
749755 . instance
750756 . flags
0 commit comments