Repository navigation
Shaders: size-based admission for big compute driver compiles - #1774
Conversation
60443ff to
a239e35
Compare
|
I found a reproducible cap bypass on exact head 3090 negative control and local fix check: With an isolated cache, I wrote an intentionally invalid PSO blob for public synthetic 2,816-byte compute DXIL, set the diagnostic cap to 2,815 bytes, and dispatched the same shader to check GPU output. Unchanged head plus test-only fixture: The narrow fix point is immediately after Portable patch follow-up: I replaced the environment-specific diagnostic with a private cache-path injection seam and a test-owned scratch directory. The same regression on 3090 still fails before the fix ( Separately, the PR-description check currently fails because its head smoke block names Portable one-file patch against a239e35diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs
index 69f4413..8061b2c 100644
--- a/crates/xcl/src/shaders.rs
+++ b/crates/xcl/src/shaders.rs
@@ -1039,6 +1039,48 @@ mod pipeline_cap_tests {
// not a number: the default, not a crash
assert_eq!(pipeline_cap_kb(Some("off")), 8192);
}
+
+ #[test]
+ fn stale_blob_cannot_bypass_the_offline_pipeline_cap() {
+ use super::{Pipelines, recomp, Ordering};
+ use std::time::{Instant, SystemTime, UNIX_EPOCH};
+
+ struct Scratch(std::path::PathBuf);
+ impl Drop for Scratch {
+ fn drop(&mut self) { let _ = std::fs::remove_dir_all(&self.0); }
+ }
+ if let Err(reason) = recomp::dxc::location() {
+ recomp::runner::skip_test(&format!("no DXC: {reason}"));
+ return;
+ }
+ let mut pipelines = match Pipelines::new() {
+ Ok(pipelines) => pipelines,
+ Err(reason) => {
+ recomp::runner::skip_test(&format!("no D3D12 device: {reason}"));
+ return;
+ }
+ };
+ let nonce = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_nanos();
+ let scratch = Scratch(std::env::temp_dir().join(format!("xcl-stale-pso-{}-{nonce}", std::process::id())));
+ std::fs::create_dir(&scratch.0).expect("scratch cache directory");
+ let hlsl = "RWByteAddressBuffer mem : register(u2); [numthreads(1,1,1)] void main() { mem.Store(0, 42); }";
+ let dxil = recomp::dxc::compile(hlsl, "main", "cs_6_6", &[]).expect("DXC compile");
+ let path = scratch.0.join("stale.pso");
+ std::fs::write(&path, b"deliberately invalid cached PSO").expect("stale blob");
+
+ pipelines.max_dxil = dxil.len() - 1;
+ let start = Instant::now();
+ pipelines.make_with_cache_path(&recomp::pso::Compiled { dxil: dxil.clone(), samplers: vec![] }, Some(path.clone()));
+ let elapsed = start.elapsed();
+ let capped = pipelines.capped.load(Ordering::Relaxed);
+ let made = pipelines.made.load(Ordering::Relaxed);
+ let refused = pipelines.refused.load(Ordering::Relaxed);
+ let output = recomp::runner::dispatch(&dxil, [1, 1, 1], &[], &[0; 64]).expect("runtime GPU dispatch");
+ println!("adapter={} dxil_bytes={} offline_ms={} capped={} made={} refused={} gpu_word0={}", recomp::runner::adapter().unwrap_or_default(), dxil.len(), elapsed.as_millis(), capped, made, refused, output[0]);
+ assert_eq!(output[0], 42);
+ assert_eq!((capped, made, refused), (1, 0, 0));
+ assert!(!path.exists(), "rejected blob should not be retried next run");
+ }
}
// D3D12 devices and root signatures are free-threaded
@@ -1061,6 +1103,10 @@ impl Pipelines {
/// The compute pipeline of `c` (made and released).
fn make(&self, c: &recomp::pso::Compiled) {
+ self.make_with_cache_path(c, None);
+ }
+
+ fn make_with_cache_path(&self, c: &recomp::pso::Compiled, path_override: Option<PathBuf>) {
use windows::Win32::Graphics::Direct3D12::*;
let key: Vec<u32> = c.samplers.iter().flat_map(|(w, cmp)| w.iter().copied().chain([*cmp as u32])).collect();
let rs = {
@@ -1085,12 +1131,13 @@ impl Pipelines {
..Default::default()
};
use crate::hle::d3d12x::real::driver_cache;
- let path = driver_cache::path(&c.dxil, desc.Flags.0);
+ let path = path_override.or_else(|| driver_cache::path(&c.dxil, desc.Flags.0));
let cached = path.as_deref().and_then(driver_cache::load);
+ let over_cap = self.max_dxil != 0 && c.dxil.len() > self.max_dxil;
// over the cap and no blob from an earlier run: the driver's compile of this one takes
// tens of minutes and gigabytes; the pass finishes without it, and the runtime builds it
// when a title needs the pipeline. `XCL_PIPELINE_MAX_KB` 0 turns the cap off.
- if cached.is_none() && self.max_dxil != 0 && c.dxil.len() > self.max_dxil {
+ if cached.is_none() && over_cap {
self.capped.fetch_add(1, Ordering::Relaxed);
self.capped_bytes.fetch_add(c.dxil.len(), Ordering::Relaxed);
drop(std::mem::ManuallyDrop::into_inner(desc.pRootSignature));
@@ -1107,6 +1154,19 @@ impl Pipelines {
desc.CachedPSO = D3D12_CACHED_PIPELINE_STATE { pCachedBlob: bytes.as_ptr().cast(), CachedBlobSizeInBytes: bytes.len() };
unsafe { self.dev.CreateComputePipelineState::<ID3D12PipelineState>(&desc) }.ok()
});
+ // A stale blob is not a usable cache hit. Do not let its presence bypass the offline
+ // size cap and start the expensive uncached driver compile.
+ if cached.is_some() && from_cache.is_none() && over_cap {
+ if let Some(path) = path.as_deref() {
+ let _ = std::fs::remove_file(path);
+ }
+ *self.running.0.lock().unwrap() -= 1;
+ self.running.1.notify_one();
+ self.capped.fetch_add(1, Ordering::Relaxed);
+ self.capped_bytes.fetch_add(c.dxil.len(), Ordering::Relaxed);
+ drop(std::mem::ManuallyDrop::into_inner(desc.pRootSignature));
+ return;
+ }
let r = if let Some(pso) = from_cache {
self.reused.fetch_add(1, Ordering::Relaxed);
Ok(pso) |
Hardware test report — commit
|
…DXIL The 3 GB floor was measured on the 256 KiB class (~1.5 GB each in the driver). The programs at the other end are a different order: the driver compile of a 29.8 MB program grew past 14 GB of free commit before it was stopped, and ~1 MB programs took several GB each on an 8 GB card (xcl-dev#1269). Ask for max(3 GB, 512x DXIL size), so a giant program waits for headroom instead of exhausting commit next to a loading title. Programs up to 6 MiB of DXIL wait for exactly what they waited for before. Part of xcl-dev#1269 (A19). Co-Authored-By: Claude Code <noreply@anthropic.com>
… runtime The precompile pass stopped advancing on the biggest compute programs: their driver compile takes tens of minutes and gigabytes (three of 29-30 MB DXIL hung --precompile --only cs --pipelines for 33+ minutes on three machines, xcl-dev#744). Skip programs whose DXIL is over XCL_PIPELINE_MAX_KB (8 MiB by default; 0 turns the cap off) when no blob exists yet, count them, and report the total; the runtime still builds one when a title needs the pipeline. 8 MiB sits above the largest program that ever completes (~2.2 MB, the optimized class) and below the smallest that hangs (14.1 MB), so the pass now finishes. Part of xcl-dev#1269 (A19). Co-Authored-By: Claude Code <noreply@anthropic.com>
a239e35 to
cbff0b8
Compare
|
I checked the new head |
The --pipelines cap only gated programs with no saved blob: a blob the driver rejects (after an adapter or driver change) fell through to the uncached compile, recompiling exactly the giant programs the cap exists to skip. NVIDIA drivers showed both faces: a hard reject (Err) when cold, and an Ok with an internal recompile when their own cache had the result - the latter looked like a blob hit and bypassed the cap too. A blob attempt now counts as a hit only when the pipeline carries a blob of the size handed to it; a miss over the cap removes the stale file, counts the program as capped, and returns before the uncached compile. Diagnosis, regression test and the first version of the fix from WebIdentity1 in xcl-dev#1774 (tested on an RTX 3090); the hit-detection filter and the Ok-with-internal-fallback case added here (RTX 4090). Co-Authored-By: Claude Code <noreply@anthropic.com>
|
Tested On RTX 3080 Ti / 621.35, Windows 11 build 26300, Ryzen 7 9800X3D, Rust 1.99.1 MSVC debug, DXC 1.8.2502.11. Not tested This checks cold admission and warm reuse through AI-assisted. Codex (GPT-6 family, exact variant unavailable) wrote and ran the local fixture and drafted this report. Post-merge stale-cache check on On the RTX 3080 Ti (621.35), Windows 11 build 26300, Rust 1.99.1 MSVC and DXC 1.8.2502.11, AI-assisted. Codex (GPT-6 family, exact variant unavailable) ran the tests and drafted this update. |
|
@WebIdentity1 confirmed on RTX 4090 and merged as |
|
@eizispark thanks for the AMD run - first RDNA4 coverage on this PR. Heads-up: the head moved to |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
Tested commit Tested
Regression run ( Base ( PR ( Not tested
AI use
|
) Brings main to full parity with upstream/main (de36462): - xcl-dev#1969: official upstream merge of 64-bit icmp 32-bit lowering and MIMG heap guards - xcl-dev#1774: size-based commit headroom admission for big driver compiles and XCL_PIPELINE_MAX_KB cap for offline --pipelines precompile Conflicts resolved by keeping HEAD's already-merged xcl-dev#1969 emit.rs (with heap_index), combining xcl-dev#1996 + xcl-dev#1774 comments in real.rs, and combining xcl-dev#1871 + xcl-dev#1774 in shaders.rs. Assisted-by: Antigravity (Gemini 4)
…ving wanted slots Hard-cap concurrent huge (>= 256 KB) wanted driver compiles via XCL_HUGE_PSO_WANTED_CONCURRENCY (default 2; giant >= 4 MiB capped at 1) to prevent bursts of lazy binds from spiking commit into OOM. Check commit_free() inside the wait loop before taking SlotGuard so an unwanted commit-blocked compile never holds a slot and deadlocks wanted builds under low free commit, and remove the unreachable no-slot arm in gate_note. Rebased onto xcl-dev#1774 (656c0e8).
Bounds what a big compute driver compile may spend. The commit headroom a background
compile waits for now scales with the program's DXIL size, and
xcl shaders --pipelinesleaves programs over a DXIL cap to the runtime instead of hanging the pass on them.
Measured on the retail pack (#1269): the driver's compile of a 29.8 MB program grew past
14 GB of free commit before it was stopped, and programs of ~1 MB took several GB each on
an 8 GB card; three programs of 29–30 MB DXIL hung
--precompile --only cs --pipelinesfor 33+ minutes on three machines (#744). The 3 GB headroom floor was measured on the
256 KiB class (~1.5 GB each); above 6 MiB of DXIL it now asks for 512× the DXIL size, and
the offline pass skips what it cannot afford. The title path is unchanged for everything
up to 6 MiB (the floor), and the runtime still builds a capped program when a title needs
the pipeline.
Part of #1269 (campaign task A19).
What is in it
crates/xcl/src/hle/d3d12x/real.rs:big_compile_headroom(dxil_len)= max(3 GB, 512× DXIL size);big_compile_commit_freewaits for that much, through main'sdriver_compile_identifiedgate (both the big and the giant lane); headroom testcrates/xcl/src/shaders.rs:XCL_PIPELINE_MAX_KB(KiB of DXIL, 8 MiB default, 0 turns the cap off) caps the--pipelinesstage; capped programs counted and reported; cap-resolution testcrates/xcl/src/shaders.rs: a stale driver blob no longer bypasses the cap — a blob the driver rejects (or accepts while recompiling internally) is removed, the program counts as capped, and the uncached compile is skipped; regression test from Shaders: size-based admission for big compute driver compiles #1774 (WebIdentity1)README.md: the cap documentedTested
cargo test --workspace -- --test-threads=4on6b9b14f: 963 passed, 0 failed, 43 ignored; 22 SKIPPED, all adapter limits of this wave32 card: the wave64 lowering/comparison GPU tests (gpu::recomp::lower::tests::*,gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware) andheap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows)--precompile --only cs --pipelineswithXCL_PIPELINE_MAX_KB=1: the pipeline stage compiled only the programs at or under the cap (375 made, 0 refused) and capped the rest; the pass was interrupted before its final count (it is resumable). The same pass showed the DXC leg stalling ~176 s over records 22600–22800 (the > 8 MB HLSL programs at-O0) — that leg is not capped here and still finishesRegression run
Both runs below reached the same screen (post-EULA world load) on the same profile; both
stall there identically — 0 presents in the last 6 s at ~33 GB commit — which is the
pre-existing world-load freeze on main (see #1269), not something this PR introduces or
fixes. No crash, no device removal on either.
Not tested
--pipelinespass run to completion at the 8 MiB default on the retail pack (resumable; the capped line is unit-tested, the full-pass finish is not yet measured here)AI use
🤖 Generated with Claude Code