@@ -464,10 +464,37 @@ impl RenderPipelineBuilder {
464464 ) ;
465465 dfmt = texture:: DepthFormat :: Depth24PlusStencil8 ;
466466 }
467- // Map to platform and keep context depth format in sync for attachment creation.
468- let dfmt_platform = dfmt. to_platform ( ) ;
469- render_context. depth_format = dfmt_platform;
470- rp_builder = rp_builder. with_depth_stencil ( dfmt_platform) ;
467+
468+ let requested_depth_format = dfmt. to_platform ( ) ;
469+
470+ // Derive the pass attachment depth format from pass configuration.
471+ let pass_has_stencil = _render_pass. stencil_operations ( ) . is_some ( ) ;
472+ let pass_depth_format = if pass_has_stencil {
473+ platform_texture:: DepthFormat :: Depth24PlusStencil8
474+ } else {
475+ render_context. depth_format ( )
476+ } ;
477+
478+ // Align the pipeline depth format with the pass attachment format to
479+ // avoid hidden global state on the render context. When formats differ,
480+ // prefer the pass attachment format and log for easier debugging.
481+ let final_depth_format = if requested_depth_format != pass_depth_format {
482+ #[ cfg( any(
483+ debug_assertions,
484+ feature = "render-validation-depth" ,
485+ feature = "render-validation-stencil" ,
486+ ) ) ]
487+ logging:: error!(
488+ "Render pipeline depth format {:?} does not match pass depth attachment format {:?}; aligning pipeline to pass format" ,
489+ requested_depth_format,
490+ pass_depth_format
491+ ) ;
492+ pass_depth_format
493+ } else {
494+ pass_depth_format
495+ } ;
496+
497+ rp_builder = rp_builder. with_depth_stencil ( final_depth_format) ;
471498 if let Some ( compare) = self . depth_compare {
472499 rp_builder = rp_builder. with_depth_compare ( compare. to_platform ( ) ) ;
473500 }
0 commit comments