From 93445592be144d697a0ba2323112a028502e8213 Mon Sep 17 00:00:00 2001 From: John Howard <49204095+Royalflamejlh@users.noreply.github.com> Date: Wed, 25 Nov 2026 16:15:33 -0700 Subject: [PATCH] D3D12.X: a build a submit waits for is wanted from the moment its call is put off need_by_submit marked a put-off call's pipeline by_submit and moved it ahead of the workers' queue, but not wanted, and the big-compile gate reads only wanted: until record_deferred reached the call and marked the next four, those builds went through the gate one at a time, behind the background slot. In a retail title's world start on Linux (RTX 4060 Ti, with #2404 and #2333) the put-off builds spent 3,153 s waiting at the gate against 320 s in the driver. Since ae00ec7 wanted builds have a hard cap of their own (XCL_HUGE_PSO_WANTED_CONCURRENCY), so marking them all at once no longer lets an unbounded number skip the commit headroom; the look-ahead window of four in record_deferred, and want/want_bound behind it, go. Found by reading the gate waits of Bench E's runs. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/bind.rs | 5 ---- crates/xcl/src/hle/d3d12x/list_x.rs | 8 +------ crates/xcl/src/hle/d3d12x/pso_async.rs | 33 +++++++++++++++++++------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs index 3f31c48b43..ed975dae00 100644 --- a/crates/xcl/src/hle/d3d12x/bind.rs +++ b/crates/xcl/src/hle/d3d12x/bind.rs @@ -121,11 +121,6 @@ pub(super) fn inherit_for_split(from: *mut c_void, to: *mut c_void, allocator: u console_list::hold_until_reset(old, blocks); } -/// A submit is about to wait for the pipeline `this` has bound. -pub(super) fn want_bound(this: *mut c_void) { - super::pso_async::want(with(this, |s| s.pso)); -} - /// A put-off dispatch that could not be recorded. pub(super) fn dispatch_dropped() { count(DISPATCHES_SKIPPED); diff --git a/crates/xcl/src/hle/d3d12x/list_x.rs b/crates/xcl/src/hle/d3d12x/list_x.rs index ee544dec22..ae986ab716 100644 --- a/crates/xcl/src/hle/d3d12x/list_x.rs +++ b/crates/xcl/src/hle/d3d12x/list_x.rs @@ -2661,9 +2661,6 @@ pub(super) unsafe fn defer(list: *mut c_void, what: Deferred) -> bool { true } -/// Builds of a submit's put-off calls that go on without the commit headroom, as a title thread's own do: about what the title's threads had in the driver at once before. -const WANTED_AT_ONCE: usize = 4; - /// Records the deferred dispatches of `wrapper`'s recording, waiting for their pipelines as a bind did. pub(super) unsafe fn record_deferred(wrapper: *mut c_void) { let mut segs = Vec::new(); @@ -2671,10 +2668,7 @@ pub(super) unsafe fn record_deferred(wrapper: *mut c_void) { let Some(&first) = segs.first() else { return }; segs.retain(|&seg| seg == first || LISTS.lock().unwrap().as_ref().and_then(|m| m.get(&(seg as usize))).is_some_and(|s| s.deferred.is_some())); let mut last: Option<*mut c_void> = None; - for (i, &seg) in segs.iter().enumerate().skip(1) { - for &ahead in segs[i..].iter().take(WANTED_AT_ONCE) { - super::bind::want_bound(ahead); - } + for &seg in segs.iter().skip(1) { let Some((what, ty, heaps)) = LISTS.lock().unwrap().as_mut().and_then(|m| m.get_mut(&(seg as usize))).and_then(|s| Some((s.deferred.take()?, s.list_type?, s.bindings.heaps.clone()))) else { continue; }; diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs index 63d62a7df4..29938ed0fb 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -760,6 +760,28 @@ mod used_tests { let _ = released(standin); } + #[test] + fn a_build_a_submit_needs_is_wanted() { + let standin = 0x7E57_B006usize; + let (started_tx, started) = mpsc::channel(); + submit(standin, true, Box::new(move || { + started_tx.send(()).unwrap(); + let t = std::time::Instant::now(); + while !build_is_wanted() && t.elapsed() < std::time::Duration::from_secs(10) { + std::thread::sleep(std::time::Duration::from_millis(1)); + } + if build_is_wanted() { 0x5757 } else { 0 } + })); + started.recv().unwrap(); + need_by_submit(standin); + let t = std::time::Instant::now(); + while is_pending(standin) && t.elapsed() < std::time::Duration::from_secs(15) { + std::thread::sleep(std::time::Duration::from_millis(5)); + } + assert_eq!(resolve(standin), 0x5757, "the build did not hear that a submit waits for it"); + let _ = released(standin); + } + /// A worker's build hears that a bind waits for it (and only its own build does). #[test] fn a_waiting_bind_makes_the_build_wanted() { @@ -1212,17 +1234,12 @@ pub fn is_pending(pso: usize) -> bool { entry(pso).is_some_and(|p| !*p.done.lock().unwrap()) } -/// One of the title's threads is about to wait for `pso`. -pub fn want(pso: usize) { - if let Some(p) = entry(pso) { - p.want(); - } -} - -/// A call with `pso` was put off to the submit: its build goes before the workers' queue. +/// A call with `pso` was put off to the submit, which will wait for it: its build goes before the +/// workers' queue, as a wanted one. pub fn need_by_submit(pso: usize) { let Some(p) = entry(pso) else { return }; if !std::mem::replace(&mut p.demand.lock().unwrap().by_submit, true) { + p.want(); NEEDED.lock().unwrap().push_back(p); let _ = queue().lock().unwrap().send(Box::new(|| ())); }