From c3fe7f4e6ff7c7f3eed330e8ee79c9a218ff8c6d Mon Sep 17 00:00:00 2001 From: Kalmarv <59708937+Kalmarv@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:41:33 -0500 Subject: [PATCH 1/3] D3D12.X: scale huge pipeline compile slots with available CPUs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Seven cold cascade-shadow pipelines on an RTX 5070 Ti took 87.5 s at one build at a time and 26.3 s at seven. Default the ordinary huge-build gate to one slot per four available logical CPUs, bounded to 1–4: on a 16-thread machine seven huge programs took 604 s at four builds at once and 656 s at seven. Keep the explicit override and existing free-commit check. Co-Authored-By: Claude Opus 5.5 --- README.md | 12 +++++++++--- crates/xcl/src/hle/d3d12x/real.rs | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0af03d753c..9924e449c6 100644 --- a/README.md +++ b/README.md @@ -247,10 +247,16 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder target gets its own piece, up to four times the target. Larger components and indirect dispatches use the whole pipeline. - Huge pipelines (translated DXIL of `XCL_HUGE_PSO_BYTES` or more, default 262144) built on the - background `xcl-pso*` workers take turns in the driver's compiler: `XCL_HUGE_PSO_CONCURRENCY` - at once (default 1, maximum 64). Pipelines of 4 MiB or more use a separate one-wide lane so + background `xcl-pso*` workers default to one concurrent driver compile per four available logical + CPUs, rounded down, with at least one slot and at most four. `XCL_HUGE_PSO_CONCURRENCY` + overrides this (1–64). On an RTX 5070 Ti, seven cascade-shadow pipelines took 87.5, 56.0, 38.8 + and 26.3 seconds to build cold at concurrency 1, 2, 4 and 7 respectively. Peak process commit + rose from 0.81 to 2.86 GiB (about 0.34 GiB per additional build), with at least 67 GiB of + system commit available throughout. On a 16-thread machine, seven huge programs took 604 s at + four builds at once and 656 s at seven, so the default stops at four. Pipelines of 4 MiB or more + use a separate one-wide lane so they cannot occupy the ordinary huge-pipeline slot; one of them can therefore run next to the - ordinary ones, and each gated compile starts only with 3 GB of commit free. Smaller pipelines + ordinary ones, and each gated compile checks for at least 3 GiB of free commit. Smaller pipelines and those a game thread waits for never wait. `xcl.log` shows each huge one as a numbered `driver compile start #K` / `driver compile finish #K: … PSO, N B DXIL, M ms` pair (compute ones with `record HASH`, the console record's hash that `--measure-pso` and diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 4ea6374885..26203968d8 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -3938,10 +3938,17 @@ fn huge_pso_bytes() -> usize { *V.get_or_init(|| env_count(std::env::var("XCL_HUGE_PSO_BYTES").ok().as_deref(), 256 << 10, 1, usize::MAX)) } -/// Huge driver compiles at once on the workers (default 1, `XCL_HUGE_PSO_CONCURRENCY`). +/// Allow one huge driver compile per four available logical CPUs, up to four by default. +fn default_huge_pso_concurrency(cpus: usize) -> usize { + (cpus / 4).clamp(1, 4) +} + fn huge_pso_concurrency() -> usize { static V: std::sync::OnceLock = std::sync::OnceLock::new(); - *V.get_or_init(|| env_count(std::env::var("XCL_HUGE_PSO_CONCURRENCY").ok().as_deref(), 1, 1, 64)) + *V.get_or_init(|| { + let cpus = std::thread::available_parallelism().map_or(1, |n| n.get()); + env_count(std::env::var("XCL_HUGE_PSO_CONCURRENCY").ok().as_deref(), default_huge_pso_concurrency(cpus), 1, 64) + }) } /// Hard cap on concurrent huge (`>= 256 KB`) driver compiles even when wanted by a title bind @@ -4176,6 +4183,13 @@ mod big_compile_tests { assert_eq!(*S.n.lock().unwrap(), 0); } + #[test] + fn default_huge_pso_slots_scale_with_available_cpus() { + for (cpus, slots) in [(1, 1), (4, 1), (7, 1), (8, 2), (15, 3), (16, 4), (32, 4), (64, 4)] { + assert_eq!(default_huge_pso_concurrency(cpus), slots, "{cpus} available CPUs"); + } + } + #[test] fn env_counts_parse() { assert_eq!(env_count(None, 2, 1, 64), 2); From f22f2396cbed5fca6bdecb5d1aadac57d8b8bfed Mon Sep 17 00:00:00 2001 From: Kalmarv <59708937+Kalmarv@users.noreply.github.com> Date: Wed, 25 Nov 2026 17:04:04 -0500 Subject: [PATCH 2/3] D3D12.X: huge driver compiles reserve their commit headroom With several huge compiles allowed at once, each checked only that 3 GiB was free when it was admitted. The workers could all see the same free commit before any driver allocation showed, then take about 2.3 GiB each. Each admitted compile now reserves its headroom (big_compile_headroom) in a pool shared by the ordinary and the giant lane until it finishes, and a background compile is admitted only when its headroom plus the pool is free: same-size compiles need headroom * (in flight + 1). The check and the reservation are taken under one lock. A wanted compile still skips the check, but reserves. Once a compile's own allocations show, they are counted twice: on a machine with little commit, fewer huge compiles run at once. The README now says which compiles check for commit and that wanted ones may run up to XCL_HUGE_PSO_WANTED_CONCURRENCY. Co-Authored-By: Claude Opus 5.5 --- README.md | 8 +- crates/xcl/src/hle/d3d12x/real.rs | 151 ++++++++++++++++++++++++------ 2 files changed, 128 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 9924e449c6..4cd712fe14 100644 --- a/README.md +++ b/README.md @@ -256,8 +256,12 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder four builds at once and 656 s at seven, so the default stops at four. Pipelines of 4 MiB or more use a separate one-wide lane so they cannot occupy the ordinary huge-pipeline slot; one of them can therefore run next to the - ordinary ones, and each gated compile checks for at least 3 GiB of free commit. Smaller pipelines - and those a game thread waits for never wait. `xcl.log` shows each huge one as a numbered + ordinary ones. A background compile starts only when its commit headroom (3 GiB, or 512 times + its DXIL above 6 MiB) is free on top of what the huge compiles already running reserved, and it + reserves that headroom until it finishes. One that a game thread waits for skips the commit + check (it still reserves), and up to `XCL_HUGE_PSO_WANTED_CONCURRENCY` of the lane's compiles + run at once then (default: the concurrency above, at least 2). Smaller pipelines and those + built on a game thread never wait. `xcl.log` shows each huge one as a numbered `driver compile start #K` / `driver compile finish #K: … PSO, N B DXIL, M ms` pair (compute ones with `record HASH`, the console record's hash that `--measure-pso` and `--export-hlsl --record-hash` take), with whether it was gated and how long it waited; diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 26203968d8..6e9a54ad72 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -3969,13 +3969,24 @@ fn env_count(v: Option<&str>, default: usize, min: usize, max: usize) -> usize { v.and_then(|v| v.trim().parse::().ok()).unwrap_or(default).clamp(min, max) } +/// Commit reserved by the huge driver compiles admitted and not yet finished, over both lanes: +/// what a compile takes in the driver is not yet in the free commit when the next one is +/// admitted, so each admission counts the reservations of those before it. Once a compile's +/// own allocations show, they are counted twice – on purpose: on a machine with little commit +/// fewer huge compiles run at once, never more. +struct Reserved(Mutex); + +static COMPILE_COMMIT_RESERVED: Reserved = Reserved(Mutex::new(0)); + /// A counting semaphore: background driver compiles of big programs at once (`most` 0: the -/// `huge_pso_concurrency` of the environment; `wanted_most` 0: `huge_pso_wanted_concurrency`). +/// `huge_pso_concurrency` of the environment; `wanted_most` 0: `huge_pso_wanted_concurrency`), +/// with the commit they reserve in `reserved` (shared by both lanes). struct Slots { n: Mutex, cv: std::sync::Condvar, most: usize, wanted_most: usize, + reserved: &'static Reserved, } impl Slots { @@ -3988,18 +3999,20 @@ impl Slots { } } -struct SlotGuard(&'static Slots); +/// A slot and the commit its compile reserved. +struct SlotGuard(&'static Slots, u64); impl Drop for SlotGuard { fn drop(&mut self) { + *self.0.reserved.0.lock().unwrap() -= self.1; *self.0.n.lock().unwrap() -= 1; self.0.cv.notify_all(); } } -static BIG_COMPILES: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 0, wanted_most: 0 }; +static BIG_COMPILES: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 0, wanted_most: 0, reserved: &COMPILE_COMMIT_RESERVED }; const GIANT_DRIVER_COMPILE: usize = 4 << 20; -static GIANT_COMPILES: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 1, wanted_most: 1 }; +static GIANT_COMPILES: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 1, wanted_most: 1, reserved: &COMPILE_COMMIT_RESERVED }; fn compile_slots(bytes: usize) -> &'static Slots { if bytes >= GIANT_DRIVER_COMPILE { &GIANT_COMPILES } else { &BIG_COMPILES } @@ -4024,7 +4037,7 @@ fn pso_trace() -> bool { fn driver_compile_identified(kind: &str, bytes: usize, gate: bool, record: Option<(u64, bool)>, build: impl FnOnce() -> R) -> (R, std::time::Duration) { let huge = gate && bytes >= huge_pso_bytes() && std::thread::current().name().is_some_and(|n| n.starts_with("xcl-pso")); let waited = std::time::Instant::now(); - let _slot = huge.then(|| big_compile_turn(compile_slots(bytes), || big_compile_commit_free(big_compile_headroom(bytes)), super::pso_async::build_is_wanted)); + let _slot = huge.then(|| big_compile_turn(compile_slots(bytes), big_compile_headroom(bytes), big_compile_commit_free, super::pso_async::build_is_wanted)); let waited = waited.elapsed(); static SEQUENCE: AtomicU64 = AtomicU64::new(0); let sequence = SEQUENCE.fetch_add(1, Ordering::Relaxed) + 1; @@ -4060,21 +4073,28 @@ fn gate_compute_driver_compile(has_cached_blob: bool) -> bool { } /// Before a big driver compile in the background: its turn – unwanted builds wait for both -/// `slots.most()` and commit headroom (`commit_free`, from `big_compile_headroom`) before taking a -/// slot so an unwanted commit-blocked compile never starves a wanted build. When a title thread +/// `slots.most()` and commit headroom before taking a slot: `commit_free` of their own `need` +/// (`big_compile_headroom`) plus what the compiles admitted before them reserved, checked and +/// reserved under one lock, so several workers cannot all see the same free commit. An unwanted +/// commit-blocked compile never starves a wanted build. Every admitted compile reserves its +/// `need` until it finishes, a wanted one too. When a title thread /// waits for the pipeline (`wanted`), it bypasses the commit wait and can use up to /// `slots.wanted_most()` (default 2 for `>= 256 KB`, 1 for `>= 4 MiB` giant shaders) so a wanted /// build is not stuck behind 1 background build while a burst of lazy binds still cannot spike /// driver compiler commit into OOM. -fn big_compile_turn(slots: &'static Slots, commit_free: impl Fn() -> bool, wanted: impl Fn() -> bool) -> SlotGuard { +fn big_compile_turn(slots: &'static Slots, need: u64, commit_free: impl Fn(u64) -> bool, wanted: impl Fn() -> bool) -> SlotGuard { const LOOK: std::time::Duration = std::time::Duration::from_millis(50); let mut n = slots.n.lock().unwrap(); loop { let is_wanted = wanted(); let cap = if is_wanted { slots.wanted_most() } else { slots.most() }; - if *n < cap && (is_wanted || commit_free()) { - *n += 1; - return SlotGuard(slots); + if *n < cap { + let mut reserved = slots.reserved.0.lock().unwrap(); + if is_wanted || commit_free(need + *reserved) { + *reserved += need; + *n += 1; + return SlotGuard(slots, need); + } } n = slots.cv.wait_timeout(n, LOOK).unwrap().0; } @@ -4103,18 +4123,21 @@ mod big_compile_tests { use std::sync::atomic::AtomicBool; use std::time::{Duration, Instant}; + /// The pool of the tests' own lanes: they reserve nothing unless a test says so. + static TEST_RESERVED: Reserved = Reserved(Mutex::new(0)); + #[test] fn wanted_builds_bypass_commit_and_unwanted_slot_but_respect_hard_cap() { - static S: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 1, wanted_most: 2 }; - let held = big_compile_turn(&S, || true, || false); + static S: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 1, wanted_most: 2, reserved: &TEST_RESERVED }; + let held = big_compile_turn(&S, 0, |_| true, || false); assert_eq!(*S.n.lock().unwrap(), 1); // Unwanted slot is full, but a wanted build immediately takes the 2nd (wanted) slot and // bypasses the commit-free check. - let held_wanted = big_compile_turn(&S, || false, || true); + let held_wanted = big_compile_turn(&S, 0, |_| false, || true); assert_eq!(*S.n.lock().unwrap(), 2); // A 3rd wanted build MUST wait while both slots are occupied (hard cap = 2). let t = std::thread::spawn(|| { - let _g = big_compile_turn(&S, || false, || true); + let _g = big_compile_turn(&S, 0, |_| false, || true); }); std::thread::sleep(Duration::from_millis(120)); assert!(!t.is_finished(), "3rd concurrent wanted huge compile must wait for hard cap"); @@ -4127,7 +4150,7 @@ mod big_compile_tests { static WANTED2: AtomicBool = AtomicBool::new(false); let t0 = Instant::now(); let t = std::thread::spawn(|| { - let _g = big_compile_turn(&S, || false, || WANTED2.load(Ordering::Acquire)); + let _g = big_compile_turn(&S, 0, |_| false, || WANTED2.load(Ordering::Acquire)); }); std::thread::sleep(Duration::from_millis(120)); assert!(!t.is_finished(), "no commit free: unwanted build waits"); @@ -4143,16 +4166,16 @@ mod big_compile_tests { // Mirrors GIANT_COMPILES (`most == 1, wanted_most == 1`) under low commit (< 3 GiB): // an unwanted compile waiting on commit headroom must never hold the slot and deadlock a // wanted compile. - static S: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 1, wanted_most: 1 }; + static S: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 1, wanted_most: 1, reserved: &TEST_RESERVED }; static FREE: AtomicBool = AtomicBool::new(false); let bg = std::thread::spawn(|| { - let _g = big_compile_turn(&S, || FREE.load(Ordering::Acquire), || false); + let _g = big_compile_turn(&S, 0, |_| FREE.load(Ordering::Acquire), || false); }); std::thread::sleep(Duration::from_millis(120)); assert!(!bg.is_finished(), "unwanted compile waits for commit"); assert_eq!(*S.n.lock().unwrap(), 0, "unwanted compile must not hold slot while commit-blocked"); let t0 = Instant::now(); - let wanted = big_compile_turn(&S, || false, || true); + let wanted = big_compile_turn(&S, 0, |_| false, || true); assert!(t0.elapsed() < Duration::from_secs(1), "wanted compile must acquire slot immediately"); assert_eq!(*S.n.lock().unwrap(), 1); drop(wanted); @@ -4164,13 +4187,13 @@ mod big_compile_tests { #[test] fn wanted_burst_is_hard_capped_to_wanted_most() { use std::sync::atomic::AtomicUsize; - static S: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 1, wanted_most: 2 }; + static S: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 1, wanted_most: 2, reserved: &TEST_RESERVED }; static IN: AtomicUsize = AtomicUsize::new(0); static PEAK: AtomicUsize = AtomicUsize::new(0); let t: Vec<_> = (0..12) .map(|_| { std::thread::spawn(|| { - let _g = big_compile_turn(&S, || false, || true); + let _g = big_compile_turn(&S, 0, |_| false, || true); let now = IN.fetch_add(1, Ordering::SeqCst) + 1; PEAK.fetch_max(now, Ordering::SeqCst); std::thread::sleep(Duration::from_millis(15)); @@ -4223,7 +4246,7 @@ mod big_compile_tests { #[test] fn the_concurrency_limit_holds_and_all_finish() { use std::sync::atomic::AtomicUsize; - static S: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 2, wanted_most: 2 }; + static S: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 2, wanted_most: 2, reserved: &TEST_RESERVED }; static IN: AtomicUsize = AtomicUsize::new(0); static PEAK: AtomicUsize = AtomicUsize::new(0); // the two holders of the slots meet here: both are inside at once, deterministically @@ -4231,7 +4254,7 @@ mod big_compile_tests { let t: Vec<_> = (0..8) .map(|_| { std::thread::spawn(|| { - let _g = big_compile_turn(&S, || true, || false); + let _g = big_compile_turn(&S, 0, |_| true, || false); let now = IN.fetch_add(1, Ordering::SeqCst) + 1; PEAK.fetch_max(now, Ordering::SeqCst); BOTH.wait(); @@ -4252,8 +4275,8 @@ mod big_compile_tests { // every slot taken: a small compile on a worker, and a huge one on an unnamed (title) // thread, both go on at once // (both lanes: a huge compile of any size would block on a gate it should bypass) - let mut held: Vec<_> = (0..huge_pso_concurrency()).map(|_| big_compile_turn(&BIG_COMPILES, || true, || false)).collect(); - held.push(big_compile_turn(&GIANT_COMPILES, || true, || false)); + let mut held: Vec<_> = (0..huge_pso_concurrency()).map(|_| big_compile_turn(&BIG_COMPILES, 0, |_| true, || false)).collect(); + held.push(big_compile_turn(&GIANT_COMPILES, 0, |_| true, || false)); let small = std::thread::Builder::new() .name("xcl-pso-test".into()) .spawn(|| driver_compile("test", huge_pso_bytes() - 1, true, || 7)) @@ -4280,10 +4303,10 @@ mod big_compile_tests { #[test] fn unwanted_builds_go_one_at_a_time_when_the_commit_is_there() { - static S: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 1, wanted_most: 2 }; - let first = big_compile_turn(&S, || true, || false); + static S: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 1, wanted_most: 2, reserved: &TEST_RESERVED }; + let first = big_compile_turn(&S, 0, |_| true, || false); let t = std::thread::spawn(|| { - let _g = big_compile_turn(&S, || true, || false); + let _g = big_compile_turn(&S, 0, |_| true, || false); }); std::thread::sleep(Duration::from_millis(120)); assert!(!t.is_finished(), "one at a time"); @@ -4291,6 +4314,76 @@ mod big_compile_tests { t.join().unwrap(); assert_eq!(*S.n.lock().unwrap(), 0); } + #[test] + fn admitted_compiles_reserve_their_commit_over_both_lanes() { + // 7 GiB of free commit that the admitted compiles' own allocations have not reached yet + const GIB: u64 = 1 << 30; + static POOL: Reserved = Reserved(Mutex::new(0)); + static BIG: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 4, wanted_most: 4, reserved: &POOL }; + static GIANT: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 1, wanted_most: 1, reserved: &POOL }; + let free = |need: u64| need <= 7 * GIB; + let reserved = || *POOL.0.lock().unwrap(); + let waits = |t: &std::thread::JoinHandle<()>| { + std::thread::sleep(Duration::from_millis(120)); + !t.is_finished() + }; + // two 3 GiB compiles fit; the third would need 9 GiB, though four slots are open + let a = big_compile_turn(&BIG, 3 * GIB, free, || false); + let b = big_compile_turn(&BIG, 3 * GIB, free, || false); + assert_eq!(reserved(), 6 * GIB); + let t = std::thread::spawn(move || drop(big_compile_turn(&BIG, 3 * GIB, free, || false))); + assert!(waits(&t), "a third compile waits for the commit the first two reserved"); + assert_eq!(*BIG.n.lock().unwrap(), 2, "and does not hold a slot meanwhile"); + drop(a); + t.join().unwrap(); + drop(b); + assert_eq!(reserved(), 0, "a finished compile gives its reservation back"); + // the giant lane's reservation counts in the ordinary lane + let g = big_compile_turn(&GIANT, 5 * GIB, free, || false); + let t = std::thread::spawn(move || drop(big_compile_turn(&BIG, 3 * GIB, free, || false))); + assert!(waits(&t), "5 GiB reserved by a giant compile leaves no room for 3 GiB more"); + drop(g); + t.join().unwrap(); + // a wanted compile skips the check but reserves, and a background one counts it + let w = big_compile_turn(&BIG, 3 * GIB, |_| false, || true); + assert_eq!(reserved(), 3 * GIB); + let t = std::thread::spawn(|| drop(big_compile_turn(&BIG, 3 * GIB, |need| need <= 5 * GIB, || false))); + assert!(waits(&t), "3 GiB wanted + 3 GiB more do not fit in 5 GiB"); + drop(w); + t.join().unwrap(); + assert_eq!(reserved(), 0); + assert_eq!(*BIG.n.lock().unwrap() + *GIANT.n.lock().unwrap(), 0); + } + + #[test] + fn workers_racing_for_low_commit_never_overcommit() { + // eight workers at once, four slots, 7 GiB free, 3 GiB each: at most two are ever inside + use std::sync::atomic::AtomicUsize; + const GIB: u64 = 1 << 30; + static POOL: Reserved = Reserved(Mutex::new(0)); + static S: Slots = Slots { n: Mutex::new(0), cv: std::sync::Condvar::new(), most: 4, wanted_most: 4, reserved: &POOL }; + static IN: AtomicUsize = AtomicUsize::new(0); + static PEAK: AtomicUsize = AtomicUsize::new(0); + static GO: std::sync::Barrier = std::sync::Barrier::new(8); + let t: Vec<_> = (0..8) + .map(|_| { + std::thread::spawn(|| { + GO.wait(); + let _g = big_compile_turn(&S, 3 * GIB, |need| need <= 7 * GIB, || false); + let now = IN.fetch_add(1, Ordering::SeqCst) + 1; + PEAK.fetch_max(now, Ordering::SeqCst); + std::thread::sleep(Duration::from_millis(20)); + IN.fetch_sub(1, Ordering::SeqCst); + }) + }) + .collect(); + let t0 = Instant::now(); + t.into_iter().for_each(|t| t.join().unwrap()); + assert!(t0.elapsed() < Duration::from_secs(10), "all eight finish"); + assert!(PEAK.load(Ordering::SeqCst) <= 2, "peak {} compiles in 7 GiB", PEAK.load(Ordering::SeqCst)); + assert_eq!(*POOL.0.lock().unwrap(), 0); + assert_eq!(*S.n.lock().unwrap(), 0); + } } unsafe fn translated_compute_pso(this: *mut c_void, f: PsoFn, desc: *const c_void, riid: *const GUID, ppv: *mut *mut c_void) -> Option> { @@ -5821,7 +5914,7 @@ unsafe fn finish_two_pass(this: *mut c_void, stream: &StreamOut, tp: crate::gpu: let bytes = stream.shader_bytes() + tp.cs.len(); let gate = bytes >= huge_pso_bytes() && std::thread::current().name().is_some_and(|n| n.starts_with("xcl-pso")); let waited = std::time::Instant::now(); - let _slot = gate.then(|| big_compile_turn(compile_slots(bytes), || big_compile_commit_free(big_compile_headroom(bytes)), super::pso_async::build_is_wanted)); + let _slot = gate.then(|| big_compile_turn(compile_slots(bytes), big_compile_headroom(bytes), big_compile_commit_free, super::pso_async::build_is_wanted)); if gate { crate::xlog_info!("D3D12.X: two-pass {kind} PSO ({bytes} B DXIL) gated, waited {} ms", waited.elapsed().as_millis()); } From d27d471b93737b318f1bffb5fde2677365efc042 Mon Sep 17 00:00:00 2001 From: Kalmarv <59708937+Kalmarv@users.noreply.github.com> Date: Thu, 26 Nov 2026 00:41:42 -0500 Subject: [PATCH 3/3] D3D12.X: a wanted huge compile keeps a slot above the background ones With the CPU-scaled default, huge_pso_concurrency is 4 on a 16-thread machine while huge_pso_wanted_concurrency stayed base.max(2), also 4: with four background huge compiles running, a build a title thread waits for had no slot of its own and queued behind them. The wanted default is now one more than the background concurrency, as it was when that was 1. Found by #2633's a_title_thread_does_not_wait_behind_a_background_whole_ build_waiting_for_its_turn, which fails with this branch merged and passes with XCL_HUGE_PSO_CONCURRENCY=1 or XCL_HUGE_PSO_WANTED_CONCURRENCY=5. Co-Authored-By: Claude Opus 5.5 (1M context) --- README.md | 2 +- crates/xcl/src/hle/d3d12x/real.rs | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4cd712fe14..719a25953f 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,7 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder its DXIL above 6 MiB) is free on top of what the huge compiles already running reserved, and it reserves that headroom until it finishes. One that a game thread waits for skips the commit check (it still reserves), and up to `XCL_HUGE_PSO_WANTED_CONCURRENCY` of the lane's compiles - run at once then (default: the concurrency above, at least 2). Smaller pipelines and those + run at once then (default: one more than the concurrency above). Smaller pipelines and those built on a game thread never wait. `xcl.log` shows each huge one as a numbered `driver compile start #K` / `driver compile finish #K: … PSO, N B DXIL, M ms` pair (compute ones with `record HASH`, the console record's hash that `--measure-pso` and diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 6e9a54ad72..ca9e571f1b 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -3952,17 +3952,23 @@ fn huge_pso_concurrency() -> usize { } /// Hard cap on concurrent huge (`>= 256 KB`) driver compiles even when wanted by a title bind -/// (`XCL_HUGE_PSO_WANTED_CONCURRENCY`, default 2, always `>= huge_pso_concurrency()`). Prevents a -/// burst of lazy compute binds from launching 10+ huge driver compiles simultaneously and spiking -/// process commit into OOM, while still letting a wanted build overtake 1 background build. +/// (`XCL_HUGE_PSO_WANTED_CONCURRENCY`, default one more than `huge_pso_concurrency()`, always +/// `>=` it). Prevents a burst of lazy compute binds from launching 10+ huge driver compiles +/// simultaneously and spiking process commit into OOM, while still letting a wanted build +/// overtake 1 background build. fn huge_pso_wanted_concurrency() -> usize { static V: std::sync::OnceLock = std::sync::OnceLock::new(); *V.get_or_init(|| { let base = huge_pso_concurrency(); - env_count(std::env::var("XCL_HUGE_PSO_WANTED_CONCURRENCY").ok().as_deref(), base.max(2), base, 64) + env_count(std::env::var("XCL_HUGE_PSO_WANTED_CONCURRENCY").ok().as_deref(), default_huge_pso_wanted_concurrency(base), base, 64) }) } +/// One slot above the background ones: with `base` of them busy, a wanted build still starts. +fn default_huge_pso_wanted_concurrency(base: usize) -> usize { + base + 1 +} + /// A count from the environment: `default` when unset or not a number, clamped to the /// inclusive range `min..=max`. fn env_count(v: Option<&str>, default: usize, min: usize, max: usize) -> usize { @@ -4213,6 +4219,14 @@ mod big_compile_tests { } } + #[test] + fn a_wanted_huge_compile_has_a_slot_above_the_background_ones() { + for cpus in 1..=64 { + let base = default_huge_pso_concurrency(cpus); + assert!(default_huge_pso_wanted_concurrency(base) > base, "{cpus} available CPUs: {base} background slots"); + } + } + #[test] fn env_counts_parse() { assert_eq!(env_count(None, 2, 1, 64), 2);