From 9e4ff7607ae6c0451cf3756ccca8ac584f424476 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 (measured on Nov 24's main, before #3203). 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. It turns off building ahead the pipelines no run used (XCL_PSO_AHEAD=0), which main does since #3203 and which would hide that. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/pso_async.rs | 7 +++-- crates/xcl/tests/used_pipelines.rs | 40 ++++++++++++++++++++++++++ 2 files changed, 45 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 99f1d58b26..f2b6cd1034 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -4717,8 +4717,11 @@ mod used { fn get() -> &'static Used { 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(HashMap::new()), now: Journal::memory(HashSet::new()), diff --git a/crates/xcl/tests/used_pipelines.rs b/crates/xcl/tests/used_pipelines.rs new file mode 100644 index 0000000000..85cd5fd448 --- /dev/null +++ b/crates/xcl/tests/used_pipelines.rs @@ -0,0 +1,40 @@ +//! 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); + // Since #3203 (69a48a24) every lazy pipeline no run used is built ahead of its first use too, + // which would hide a build ahead from the list: only the list's builds ahead stay. (Read once, + // at the first pipeline; this binary's only test sets it before that.) + std::env::set_var("XCL_PSO_AHEAD", "0"); + + // 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"); +}