From 7716b4cf9198871a7c387f19844d437f1a9f3ced Mon Sep 17 00:00:00 2001 From: Prime <215761102+Prime1997@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:33:27 -0800 Subject: [PATCH] D3D12.X: a build the title already draws without waits for half the commit headroom With a wait budget (XCL_GFX_PSO_WAIT_MS, XCL_CS_PSO_WAIT_MS) a bind gives up on a pipeline after its budget and the build is no longer wanted, so its huge driver compile waits at the gate for the full commit headroom (3 GB). On a machine with 4.5 GB of commit left (44.6 of 49.1 GB) 33 such builds stood there, one for 129 s, while 44,596 draws of a retail title's world were left out for want of them and 2 frames were presented in 200 s. A late build now waits for half the headroom: 1.5 GB for the class from 256 KB, what one such compile takes. Builds ahead of first use and builds nobody used wait as before. Co-Authored-By: Claude Fable 5.2 --- crates/xcl/src/hle/d3d12x/pso_async.rs | 7 +++++++ crates/xcl/src/hle/d3d12x/real.rs | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs index 51e0453f17..beaea17c61 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -119,6 +119,13 @@ pub(super) fn build_is_wanted() -> bool { BUILDING.with(|b| b.borrow().as_ref().is_some_and(|p| p.demand.lock().unwrap().wanted())) } +/// This thread is a worker building a pipeline a bind waited for and went on without +/// (`resolve_within`): nobody waits for it now, but the title's draws or dispatches with it are +/// left out until it is built (`real::huge_compile_turn`). +pub(super) fn build_is_late() -> bool { + BUILDING.with(|b| b.borrow().as_ref().is_some_and(|p| p.late.load(Ordering::Acquire))) +} + /// This thread is a backlog worker building a pipeline nobody has used yet: its huge driver /// compile gives its turn to any other (`real::big_compile_turn`). pub(super) fn build_is_ahead() -> bool { diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 4fc883bf4e..570ef64a10 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -4680,7 +4680,17 @@ pub(super) fn huge_compile_turn(bytes: usize) -> SlotGuard { if !slots.ahead && super::pso_async::build_is_ahead() { super::pso_async::build_parks(); } - big_compile_turn(slots, || big_compile_commit_free(big_compile_headroom(bytes)), super::pso_async::build_is_wanted, super::pso_async::build_is_ahead) + big_compile_turn(slots, || big_compile_commit_free(headroom_for(bytes, super::pso_async::build_is_late())), super::pso_async::build_is_wanted, super::pso_async::build_is_ahead) +} + +/// The commit headroom a huge compile of `bytes` waits for (`big_compile_headroom`), halved for +/// one whose pipeline the title already uses and draws without (`late`): with a wait budget no +/// build stays wanted, and on a machine short of commit every one of them then stood at the gate +/// for the full headroom while the frames that needed them were left out (33 builds held, one for +/// 129 s, with 4.5 GB of commit free and 44,596 draws skipped meanwhile). +fn headroom_for(bytes: usize, late: bool) -> u64 { + let full = big_compile_headroom(bytes); + if late { full / 2 } else { full } } /// Commit headroom a big driver compile waits for: 3 GB for the class that starts at @@ -4706,6 +4716,18 @@ mod big_compile_tests { use std::sync::atomic::AtomicBool; use std::time::{Duration, Instant}; + #[test] + fn a_late_build_waits_for_half_the_headroom() { + let bytes = huge_pso_bytes(); + assert_eq!(headroom_for(bytes, false), big_compile_headroom(bytes)); + assert_eq!(headroom_for(bytes, true), big_compile_headroom(bytes) / 2); + // (the class's floor: 3 GB, 1.5 GB for a late one - what one such compile takes) + assert_eq!(headroom_for(1 << 20, false), 3 << 30); + assert_eq!(headroom_for(1 << 20, true), 3 << 29); + // a giant program keeps a headroom that grows with it + assert_eq!(headroom_for(32 << 20, true), (32u64 << 20) * 256); + } + #[test] fn wanted_builds_bypass_commit_and_unwanted_slot_but_respect_hard_cap() { static S: Slots = Slots::new(1, 2);