@@ -562,41 +562,52 @@ impl RenderContext {
562562 return Ok ( ( ) ) ;
563563 }
564564
565- let requires_surface = commands. iter ( ) . any ( |cmd| match cmd {
566- RenderCommand :: BeginRenderPass { .. } => true ,
567- RenderCommand :: BeginRenderPassTo {
568- destination : RenderDestination :: Surface ,
569- ..
570- } => true ,
571- _ => false ,
565+ // Determine whether this command list needs access to the presentation
566+ // surface. We only acquire a surface frame when a surface-backed pass is
567+ // requested; offscreen-only command lists can render without a window.
568+ let requires_surface = commands. iter ( ) . any ( |cmd| {
569+ return matches ! (
570+ cmd,
571+ RenderCommand :: BeginRenderPass { .. }
572+ | RenderCommand :: BeginRenderPassTo {
573+ destination: RenderDestination :: Surface ,
574+ ..
575+ }
576+ ) ;
572577 } ) ;
573578
574579 let mut frame = if requires_surface {
575- Some (
576- match {
577- let surface = self . surface . as_mut ( ) . ok_or_else ( || {
578- RenderError :: Configuration (
579- "No surface attached to RenderContext" . to_string ( ) ,
580- )
581- } ) ?;
582- surface. acquire_frame ( )
583- } {
584- Ok ( frame) => frame,
585- Err ( err) => match err {
586- targets:: surface:: SurfaceError :: Lost
587- | targets:: surface:: SurfaceError :: Outdated => {
588- self . reconfigure_surface ( self . size ) ?;
589- let surface = self . surface . as_mut ( ) . ok_or_else ( || {
590- RenderError :: Configuration (
591- "No surface attached to RenderContext" . to_string ( ) ,
592- )
593- } ) ?;
594- surface. acquire_frame ( ) . map_err ( RenderError :: Surface ) ?
595- }
596- _ => return Err ( RenderError :: Surface ( err) ) ,
597- } ,
580+ // Acquire exactly one surface frame up-front and reuse its `TextureView`
581+ // for all surface-backed render passes in this command list. The acquired
582+ // frame is presented after encoding completes.
583+ //
584+ // If acquisition fails due to surface loss/outdated config, attempt to
585+ // reconfigure the surface to the current context size and retry once.
586+ let acquired = {
587+ let surface = self . surface . as_mut ( ) . ok_or_else ( || {
588+ RenderError :: Configuration (
589+ "No surface attached to RenderContext" . to_string ( ) ,
590+ )
591+ } ) ?;
592+ surface. acquire_frame ( )
593+ } ;
594+
595+ Some ( match acquired {
596+ Ok ( frame) => frame,
597+ Err ( err) => match err {
598+ targets:: surface:: SurfaceError :: Lost
599+ | targets:: surface:: SurfaceError :: Outdated => {
600+ self . reconfigure_surface ( self . size ) ?;
601+ let surface = self . surface . as_mut ( ) . ok_or_else ( || {
602+ RenderError :: Configuration (
603+ "No surface attached to RenderContext" . to_string ( ) ,
604+ )
605+ } ) ?;
606+ surface. acquire_frame ( ) . map_err ( RenderError :: Surface ) ?
607+ }
608+ _ => return Err ( RenderError :: Surface ( err) ) ,
598609 } ,
599- )
610+ } )
600611 } else {
601612 None
602613 } ;
0 commit comments