From 8aef2946818bf7547a34efae7fc5133773d9b591 Mon Sep 17 00:00:00 2001 From: einfachama Date: Tue, 24 Nov 2026 05:58:25 +0100 Subject: [PATCH] D3D12.X: only a title's run reads and writes used-pipelines.txt The list of the pipelines a title used was kept out of tests with cfg!(test), which only the crate's own unit tests have: the integration tests in tests/ link the crate without it, so they read the user's used-pipelines.txt and add their pipelines to it. After full test runs with XCL_SAMPLE_RPF on an RTX 4060, the user's list held 10 keys (gpu_pso_e2e, run alone into an empty cache, writes 9 keys, 4 of them among those 10), and every later run of my retail title built its pipelines of those shaders ahead: 228 translated pipelines at its first menu instead of 6. The list is now read and written only when a title runs (state::boot set). The new integration test fails without the change: the pipeline of a key in the list was built ahead. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/pso_async.rs | 7 +++-- crates/xcl/tests/used_pipelines.rs | 36 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 crates/xcl/tests/used_pipelines.rs diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs index 3bc4ad2d6..cdff76f75 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -276,8 +276,11 @@ mod used { fn get() -> &'static Used { static U: OnceLock = OnceLock::new(); U.get_or_init(|| { - // (a test neither reads nor writes the user's file) - if cfg!(test) { + // Only a title's run reads and writes the user's file. A test does neither: the + // crate's own (`cfg(test)`), and one in `tests/`, which links the crate without + // `cfg(test)` – the retail pipeline tests' keys made the title build their + // pipelines ahead in its next run. + if cfg!(test) || crate::state::boot().is_none() { return Used { earlier: RwLock::new(HashSet::new()), now: Mutex::new((HashSet::new(), None)) }; } let path = crate::gpu::recomp::dxc::cache_dir().join("used-pipelines.txt"); diff --git a/crates/xcl/tests/used_pipelines.rs b/crates/xcl/tests/used_pipelines.rs new file mode 100644 index 000000000..3fd4c54e5 --- /dev/null +++ b/crates/xcl/tests/used_pipelines.rs @@ -0,0 +1,36 @@ +//! The list of the pipelines a title used (`used-pipelines.txt`, beside the DXIL cache) belongs +//! to title runs. A test binary links the crate without `cfg(test)`, and it must neither build +//! pipelines ahead from the list nor add its own pipelines to it: the retail pipeline tests' +//! keys made a title build those pipelines ahead in its next run. + +use std::time::Duration; +use xcl::hle::d3d12x::pso_async; + +#[test] +fn a_test_binary_neither_reads_nor_writes_the_used_pipelines_list() { + let dir = std::env::temp_dir().join(format!("xcl-used-pipelines-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let list = dir.join("used-pipelines.txt"); + // a list an earlier run wrote (this binary's first pipeline call reads it, if anything does) + let earlier = "000000005eed0003\n"; + std::fs::write(&list, earlier).unwrap(); + std::env::set_var("XCL_DXIL_CACHE", &dir); + + // a pipeline of the shaders in the list: not built ahead, only when used + let (known, unknown) = (0x7E57_8001usize, 0x7E57_8002usize); + pso_async::submit_lazy(known, false, Box::new(|| 0x4323), 0x5EED_0003); + std::thread::sleep(Duration::from_millis(500)); + let built_ahead = !pso_async::is_pending(known); + // a pipeline used for the first time: not added to the list + pso_async::submit_lazy(unknown, false, Box::new(|| 0x4324), 0x5EED_0004); + assert_eq!(pso_async::resolve_wait(unknown), 0x4324); + assert_eq!(pso_async::resolve_wait(known), 0x4323); + pso_async::released(known); + pso_async::released(unknown); + let after = std::fs::read_to_string(&list).unwrap_or_default(); + let _ = std::fs::remove_dir_all(&dir); + + assert!(!built_ahead, "a test binary built a pipeline ahead from the user's list"); + assert_eq!(after, earlier, "a test binary added its pipelines to the user's list"); +}