From 55e7beb6de9fcc8817d40d0a663857e3553c3632 Mon Sep 17 00:00:00 2001 From: Isaac W Date: Wed, 25 Nov 2026 06:38:17 +1000 Subject: [PATCH] D3D12.X: a draw does not wait for a graphics pipeline still being built pso_async means a graphics pipeline still being built to go on with its stand-in, which draws nothing, while a worker builds it; only compute pipelines are waited for (a skipped dispatch would leave its outputs unwritten). But graphics_bound and ExecuteIndirect called resolve_wait, which waits for the build - and builds it on the title's thread when no worker has started it. With lazy pipelines that is every graphics pipeline's first draw. On an NVIDIA GPU the retail title of #505 had its threads held 1 - 5 s per draw in the driver's compiler as its world loaded: 25 graphics binds, 33.2 s in all within 25 s (counted with #899's log), and its hang watchdog ended the run. A test report on #889 (RTX 4080) found a title thread held in bind::execute_indirect -> resolve_wait at the abort. Draws and ExecuteIndirect now take their pipeline with resolve_for_bind: a graphics one still being built goes to the workers and the draw uses its stand-in (ExecuteIndirect skips, as it already did for a pending one); a compute one is waited for as before. With this, the same world load logged no graphics wait. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/bind.rs | 42 ++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs index da5b15ef4..27719d80e 100644 --- a/crates/xcl/src/hle/d3d12x/bind.rs +++ b/crates/xcl/src/hle/d3d12x/bind.rs @@ -253,7 +253,7 @@ fn signature_dispatches(sig: usize) -> bool { pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: usize, max: u32, args: usize, args_off: u64, count_buf: usize, count_off: u64) { type F = unsafe extern "system" fn(*mut c_void, usize, u32, usize, u64, usize, u64); let pc: F = std::mem::transmute(super::real::orig_fn(this, 59)); - let pso = super::pso_async::resolve_wait(with(this, |s| s.pso)); + let pso = pso_for_draw(with(this, |s| s.pso)); let (gfx, compute) = (super::real::is_translated_graphics(pso), super::real::is_translated_compute(pso)); let (args_off, count_off) = (args_off + super::real::buffer_delta(args), count_off + super::real::buffer_delta(count_buf)); if !gfx && !compute { @@ -489,14 +489,23 @@ pub(super) unsafe fn emit_prepared_indexed_draw( list.DrawIndexedInstanced(indices, instances, first_index, base_vertex, first_instance); } +/// The pipeline a draw (or an ExecuteIndirect) uses now: a graphics pipeline still being built +/// is not waited for – its build goes to the workers and its stand-in, which draws nothing, is +/// used until it is built (`pso_async`). A compute one is waited for. Waiting held a retail +/// title's threads 1 – 5 s per draw in the driver's compiler (33 s in all as its world loaded, +/// on an NVIDIA GPU), and its hang watchdog ended it. +fn pso_for_draw(pso: usize) -> usize { + super::pso_async::resolve_for_bind(pso) +} + /// Before a draw: with a translated pipeline its ABI root signature and the kept graphics /// arguments are bound (None: the draw is skipped – a console pipeline without a /// translation, or no unified memory). unsafe fn graphics_bound(this: *mut c_void) -> Option { let list = ID3D12GraphicsCommandList::from_raw_borrowed(&this)?.clone(); let pso = with(this, |s| s.pso); - // a pipeline still being built in the background is waited for (its stand-in draws nothing) - if !super::real::is_translated_graphics(super::pso_async::resolve_wait(pso)) { + // a pipeline still being built in the background is not waited for (`pso_for_draw`) + if !super::real::is_translated_graphics(pso_for_draw(pso)) { count(DRAWS_PC); if super::present::trace_frame() { // which pipelines draw without a translation (first 12 distinct) @@ -504,7 +513,7 @@ unsafe fn graphics_bound(this: *mut c_void) -> Option let mut g = SEEN.lock().unwrap(); if !g.contains(&pso) && g.len() < 12 { g.push(pso); - let real = super::pso_async::resolve_wait(pso); + let real = super::pso_async::resolve(pso); crate::xlog_info!( "frame trace: draw with an untranslated pipeline {pso:#x} (resolves to {real:#x}; pending {}, two-pass {}, RT0 {:?})", super::pso_async::is_pending(pso), @@ -1178,6 +1187,31 @@ void main(uint t : SV_GroupIndex) { } } + /// A draw does not wait for a graphics pipeline still being built: its build goes to the + /// workers and the draw gets the stand-in at once; once built, the real one. A compute + /// pipeline is still waited for. + #[test] + fn a_draw_does_not_wait_for_a_graphics_pipeline_still_being_built() { + let (graphics, compute) = (0x7E57_6101usize, 0x7E57_6102usize); + pso_async::submit_lazy(graphics, false, Box::new(|| { + std::thread::sleep(std::time::Duration::from_millis(1500)); + 0x1301 + }), 0); + pso_async::submit_lazy(compute, true, Box::new(|| 0x1302), 0); + let t = std::time::Instant::now(); + assert_eq!(pso_for_draw(graphics), graphics, "the stand-in, not the real one"); + assert!(t.elapsed() < std::time::Duration::from_millis(500), "a draw waited {:?}", t.elapsed()); + // the draw sent it to the workers: it is built with no further draw + let start = std::time::Instant::now(); + while pso_async::is_pending(graphics) && start.elapsed() < std::time::Duration::from_secs(10) { + std::thread::sleep(std::time::Duration::from_millis(5)); + } + assert_eq!(pso_for_draw(graphics), 0x1301, "built by a worker"); + assert_eq!(pso_for_draw(compute), 0x1302, "a compute pipeline is waited for"); + pso_async::released(graphics); + pso_async::released(compute); + } + /// Minimal RTS0 v2 root signature blob with one 4-constant parameter. fn test_rts0_blob() -> Vec { let words: [u32; 12] = [