Skip to content

D3D12.X: offload PSO builds, defer lazy compile-on-draw, and wire mmap ID3D12PipelineLibrary1 - #2001

Open
raylitebull wants to merge 6 commits into
xcl-dev:mainfrom
raylitebull:feat/pso-mmap-lib-and-lazy
Open

raylitebull wants to merge 6 commits into
xcl-dev:mainfrom
raylitebull:feat/pso-mmap-lib-and-lazy

Conversation

@raylitebull

@raylitebull raylitebull commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Offloads all PSO compilation off title threads with a shared per-frame wait budget (pso_async), defers lazy PSO builds until first Draw / Dispatch / ExecuteIndirect (XCL_LAZY_ON_DRAW), deduplicates used-only startup prewarm (XCL_PSO_PREWARM_USED), and wires a generational memory-mapped ID3D12PipelineLibrary1 cache (pso_library, pso_lib in real.rs, flushed on clean exit via present.rs) into compute, graphics, and mesh PSO creation paths.

Part of #1833 (addresses Gaps #1–#5: off-thread PSO builds, bounded per-frame bind wait, deferred compile-on-draw, deduplicated used-only prewarm, and persistent memory-mapped ID3D12PipelineLibrary1 reuse).

What is in it

  • crates/xcl/src/hle/d3d12x/pso_async.rs, list_x.rs, frame.rs, & mod.rs:
    • resolve_wait never compiles synchronously on calling title threads unless XCL_PSO_TITLE_BUILD=1; checks frame_rem.is_zero() before begin_wait() and uses an RAII WaitWantGuard so skipped/timed-out PSOs never stay wanted = true (eliminating multi-worker huge-compile commit ballooning), limits the implicit default AfterFirstPresent(500 ms) frame budget to graphics PSOs (!p.compute) so compute dispatches are never deferred unless XCL_PSO_FRAME_WAIT_MS=<ms> (Always) is explicitly set, and sets *p.done = true + notify_all() on orphaned/released pending entries.
    • lazy_on_draw / resolve_for_bind (XCL_LAZY_ON_DRAW, default on when XCL_LAZY_PSO != 0) defers building lazy pipelines past SetPipelineState (passive resolve_if_ready lookup) until first draw/dispatch.
    • prewarm_used_enabled (XCL_PSO_PREWARM_USED / XCL_PSO_PRELOAD) deduplicates duplicate shader keys.
  • crates/xcl/src/hle/d3d12x/pso_library.rs: generational memory-mapped ID3D12PipelineLibrary1 (MmapPipelineLibrary) synchronizing Load* + StorePipeline (lib_rw.read()) vs serialization (write) via RwLock, waiting for in-flight saves during flush(), and removing rejected/corrupt .plib files on open_or_create.
  • crates/xcl/src/hle/d3d12x/real.rs & present.rs: pso_lib wiring into compute, graphics, stream, and mesh PSO paths (flush_pipeline_library on clean close), deterministic stream_key content hashing for pointer-bearing subobjects, PC ID3D12PipelineState adoption (deliver_adopted), and debounced background save scheduler (should_background_save).
  • Unit tests (pso_async, pso_library, pso_lib::tests, including default_frame_budget_only_defers_graphics_and_never_leaves_skipped_psos_wanted).

Tested

  • Toolchain: Windows 11 x64, rustc 1.99.1 (58cf8f9c3 2026-10-13), base 656c0e8 (1f1d681).
  • Release compilation verified locally (cargo build --release, 0 errors) on 1f1d681; GitHub Actions Build and test is running on this pushed head (1f1d681).
  • Earlier commit 4d53a2c passed cargo check --workspace --tests, pso_async (14/14), pso_library (3/3), and pso_lib::tests (2/2).

Regression run

  • Standalone scripts/smoke.ps1 pair on 1f1d681 vs 656c0e8 has not been run locally. AMD and NVIDIA reviewers are invited to test on 1f1d681 vs 656c0e8 (including scripts/smoke.ps1, cold/warm XCL_PSO_LIBRARY=1 world loads, and XCL_LAZY_PSO=1) and post results in the comments.

Not tested

  • cargo test suite and 60 s scripts/smoke.ps1 pair on 1f1d681, full cargo test --workspace suite, runtime GPU execution across AMD / NVIDIA / Intel hardware, and Linux/Wine/vkd3d-proton.

AI use

  • Antigravity assisted with implementation, root-cause fixes, and unit tests; the author reviewed the diff and test output.

@WebIdentity1

WebIdentity1 commented Nov 25, 2026 •

Copy link
Copy Markdown

Confirmed a bind-only escape from XCL_LAZY_ON_DRAW on 7244baadcf009af2a79e94c9fd9c6e7b41d89ab9. The sequence is SetPipelineState(A) followed by SetPipelineState(B), with no draw/dispatch. list_x::on_set_pipeline_state compares B against pso_async::resolve(s.bound_pso). That lookup queues A and calls note_use(), defeating the new deferral policy for a discarded binding. The existing unit test only calls resolve_for_bind, so it misses this bookkeeping path.

The small candidate below adds a passive peek for this identity comparison. It retains the real-PSO identity once built, without scheduling or recording use.

Tested — native Windows 10 19045, Ryzen 7 7800X3D, Rust 1.98.1 MSVC, debug; XCL_LAZY_PSO=1, XCL_LAZY_ON_DRAW=1:

cargo test --locked -p xcl --lib -- pso_async:: --test-threads=1 --show-output
  • Exact head + new regression: 12 passed / 1 failed / 0 ignored, zero skips. After A then B, queued=[true,false], used=[true,false].
  • Same head + candidate and test: 13 passed / 0 failed / 0 ignored, zero skips. Both arrays are [false,false]. The fixture then explicitly requests and completes both synthetic jobs before assertions/cleanup, checking that later demand still builds them.
  • This exercises the real on_set_pipeline_state tracking routine with synthetic list/pipeline identities and job closures; it performs no COM draw or GPU driver compilation. Both builds recompiled XCL, and all 312 source-file hashes matched before/after.
Candidate fix and deterministic regression (36 additions, 1 deletion)
diff --git a/crates/xcl/src/hle/d3d12x/list_x.rs b/crates/xcl/src/hle/d3d12x/list_x.rs
index a4bc5d2..ee28774 100644
--- a/crates/xcl/src/hle/d3d12x/list_x.rs
+++ b/crates/xcl/src/hle/d3d12x/list_x.rs
@@ -836,7 +836,7 @@ pub(super) unsafe fn on_set_pipeline_state(list: *mut c_void, pso: usize) {
         let mut g = LISTS.lock().unwrap();
         let s = g.get_or_insert_with(HashMap::new).entry(key).or_default();
         // Keep the title-visible base PSO key when `bind_abi` re-binds its resolved background PSO.
-        if s.bound_pso == 0 || pso == s.bound_pso || super::pso_async::resolve(s.bound_pso) != pso {
+        if s.bound_pso == 0 || pso == s.bound_pso || super::pso_async::peek(s.bound_pso) != pso {
             s.bound_pso = pso;
         }
         let effective = s.bound_pso;
diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs
index a21bb90..307d5e2 100644
--- a/crates/xcl/src/hle/d3d12x/pso_async.rs
+++ b/crates/xcl/src/hle/d3d12x/pso_async.rs
@@ -704,6 +704,33 @@ mod used_tests {
         assert!(!parse_prewarm_used(None, Some("0")));
     }
 
+    #[test]
+    fn switching_bound_pipelines_does_not_compile_the_unused_one() {
+        let list = 0x7E57_B401usize;
+        let a = 0x7E57_B402usize;
+        let b = 0x7E57_B403usize;
+        let ka = 0x5EED_B402u64;
+        let kb = 0x5EED_B403u64;
+        assert!(lazy_on_draw());
+        submit_lazy(a, false, Box::new(|| 0x6402), ka);
+        submit_lazy(b, false, Box::new(|| 0x6403), kb);
+        assert_eq!(resolve_for_bind(a), a);
+        unsafe { super::super::list_x::on_set_pipeline_state(list as *mut _, a) };
+        assert_eq!(resolve_for_bind(b), b);
+        unsafe { super::super::list_x::on_set_pipeline_state(list as *mut _, b) };
+        let queued = [a, b].map(|p| entry(p).unwrap().sent.load(Ordering::Acquire));
+        let used = [used::noted(ka), used::noted(kb)];
+        // Finish both synthetic jobs before assertions so the failing control leaves no worker behind.
+        let built = [resolve_wait_for(a, None), resolve_wait_for(b, None)];
+        super::super::list_x::on_release(list);
+        let _ = released(a);
+        let _ = released(b);
+        println!("bind A then B, no draw: queued={queued:?}, used={used:?}");
+        assert_eq!(built, [0x6402, 0x6403]);
+        assert_eq!(queued, [false, false], "bind bookkeeping queued an unused pipeline");
+        assert_eq!(used, [false, false], "bind bookkeeping polluted the used-pipeline ledger");
+    }
+
     #[test]
     fn lazy_on_draw_defers_build_past_bind_until_first_draw_or_dispatch() {
         let compute_standin = 0x7E57_B301usize;
@@ -816,6 +843,14 @@ fn entry(pso: usize) -> Option<Arc<Pending>> {
     PENDING.lock().unwrap().as_ref()?.get(&pso).cloned()
 }
 
+/// The available pipeline identity, without scheduling a build or recording use.
+pub(super) fn peek(pso: usize) -> usize {
+    entry(pso).map_or(pso, |p| match p.real.load(Ordering::Acquire) {
+        0 => pso,
+        r => r,
+    })
+}
+
 /// The pipeline to use for `pso` now: the real one once built, else `pso` itself.
 pub fn resolve(pso: usize) -> usize {
     let Some(p) = entry(pso) else { return pso };

Not tested: full workspace suite, this PR's pipeline-library changes, GPU output, retail smoke, or game-scale compilation-time/memory savings. This is a scheduling/usage-ledger finding, not a merge-readiness claim. No competing PR or source push.

AI use: Codex with GPT-6 Astra traced the hook, wrote the candidate and regression, ran the Windows comparison, and drafted this report.

@gsucristo

Copy link
Copy Markdown
Contributor

Technical review findings:

Blocking

  1. XCL_LAZY_ON_DRAW is bypassed by list_x::on_set_pipeline_state (list_x.rs:839): on_set_pipeline_state calls super::pso_async::resolve(s.bound_pso) when switching away from a bound PSO, which still calls p.note_use() and enqueues s.bound_pso for compilation even if nothing was ever drawn with it. Needs a passive lookup in on_set_pipeline_state.
  2. Permanent deadlock when a pending PSO is released() while a thread waits without a budget (pso_async.rs, workers() & resolve_wait_with_budgets): In workers(), if p.orphan.load(Ordering::Acquire) is true, the worker does continue; without setting *p.done = true and calling p.cv.notify_all(). Any thread blocked in while !*done { done = p.cv.wait(done).unwrap(); } (e.g. before first present or with XCL_PSO_FRAME_WAIT_MS=0) will hang forever.
  3. Race & D3D12 API violation between StorePipeline and GetSerializedSize/Serialize (pso_library.rs, store & save_if_dirty): save_if_dirty calls GetSerializedSize(), allocates a fixed-size MappedWriteFile, and calls Serialize(buf) without synchronizing against concurrent store() calls on worker threads. A concurrent StorePipeline grows the serialized size mid-save (E_INVALIDARG / driver UB). Needs an RwLock or mutex synchronizing store vs GetSerializedSize+Serialize.
  4. flush_pipeline_library() on WM_CLOSE drops the final save if background saver is active (pso_library.rs:save_if_dirty, present.rs:wndproc): save_if_dirty returns immediately if self.saving is already true, so WM_CLOSE proceeds straight to ExitProcess(0) and kills xcl-plib-save mid-write, losing unsaved pipelines and leaving an orphaned .tmp file. flush_now() should wait on save_lock for any active save to finish and then flush remaining dirty entries.

Major

  • open_or_create (pso_library.rs) only deletes stale .plib files on DRIVER_VERSION_MISMATCH/ADAPTER_NOT_FOUND; a corrupt .plib returning E_INVALIDARG stays as the latest generation and fails on every subsequent launch.
  • pso_lib::stream_key (real.rs) hashes raw subobject payloads for non-RS/non-shader subobjects, which would hash transient pointers if called on streams containing INPUT_LAYOUT/STREAM_OUTPUT/VIEW_INSTANCING/CACHED_PSO.
  • deliver_adopted (real.rs) passes a console riid to PC COM QueryInterface (which fails with E_NOINTERFACE and falls back to raw).

Switching bound pipelines A -> B via SetPipelineState previously called side-effecting pso_async::resolve(s.bound_pso) on the outgoing binding A, enqueueing lazy compilation and recording usage for a pipeline that was never drawn. Add passive pso_async::resolve_if_ready for bind-time identity comparison in list_x::on_set_pipeline_state and add an A-to-B bind regression test.
…, and stream key hashing

Address review findings on xcl-dev#2001: wake unbounded waiters on orphaned/released pending PSOs in workers, preload, and released(); synchronize StorePipeline against GetSerializedSize+Serialize with an RwLock; make shutdown flush() wait on save_lock for any active background save; remove any rejected .plib file on open_or_create; hash pointer-bearing pipeline stream subobjects by pointed-to content; and return ID3D12PipelineState directly in deliver_adopted without querying console IIDs.
@WebIdentity1

WebIdentity1 commented Nov 25, 2026 •

Copy link
Copy Markdown

Both demand-lifecycle repairs are available as small commits

For adoption on 1f1d681439db77ea01a656dc8fc65aa4eabc7d1b, apply these in order:

  1. 8be0af7 — restore worker priority after abandoned waits: 2 added / 3 removed runtime lines plus its regression.
  2. 21bfbb0 — count unbounded waiters: one runtime line changed plus its regression, stacked on the first fix.

The second repair keeps wanted_here() true while an unbounded title thread still waits, even if another bounded wait times out. Both fixes reuse the existing demand lock/guard. No competing PR and no cache-accounting or Wine library-creation changes.

Combined validation: native Windows 10 Home 19045, Ryzen 7 7800X3D, RTX 3090 driver 591.74, Rust/Cargo 1.98.1 MSVC, DXC/DXIL 1.8.2502.11, debug. XCL_ADAPTER=3090, XCL_PSO_TITLE_BUILD=0.

cargo build --locked --workspace
cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output
Snapshot Build Passed / failed / ignored across 20 harness summaries
Priority fix 8be0af7 + mixed-waiter regression only passed 1075 / 3 / 45
Both fixes + same regressions, committed as 21bfbb0 passed 1077 / 1 / 45

The control's mixed-waiter regression reports an active unbounded waiter but wanted_after_timeout=false waiters=0. The candidate reports true / 1, then zero after completion. The priority regression passes on both snapshots: bases -1/-2, boost to 0, restored -1/-2 after the build and inside the next unwanted job.

Both retain the identical CLAMP mismatch (gpu_clamp_and_omod_per_instruction, lane-0 v_pk_add_i16, actual 2146467856, expected 2147516415). The control additionally fails d32s8_targets_take_their_own_size_of_video_memory at list.Close() with 0x80004005; the candidate passes it. That D32S8 difference is not credited to the scheduling fix. No candidate-only failures; both Cargo test commands exit 101, so this is not an all-green suite.

The same 26 explicit SKIPPED notices occur in each run: 19 native-wave64 subcases, three refused wave32 per-lane cases, two missing-debug-layer checks, one unavailable driver-cache-control check and one unavailable heap-window check. Data-dependent early returns do not establish retail coverage. All 314 source hashes match before/after execution and locally; the published tree matches the tested candidate exactly. XCL rebuilt for each snapshot.

Not tested: retail smoke, current-main integration, real driver-admission effects, compilation throughput, stutter or memory savings. The two native-thread regression fixtures check production demand/priority behavior with synthetic jobs. Required merge checks remain outstanding. Earlier isolated evidence and patches are preserved below.

AI use: Codex (GPT-6) prepared the fixes/tests, performed and verified the native Windows runs, and wrote this report.

Earlier isolated comparisons and patches

Priority cleanup: workspace comparison and cherry-pickable fix

The verified priority-lifecycle repair below is now available as commit 8be0af7, based directly on 1f1d681439db77ea01a656dc8fc65aa4eabc7d1b. Runtime change: 2 added / 3 removed lines, plus the regression. It restores the worker's base priority after the build finishes, under the existing demand lock. It does not include the separate mixed-waiter fix or PortBridge's cache-accounting change. No competing PR.

Tested: native Windows 10 Home 19045, Ryzen 7 7800X3D, RTX 3090 driver 591.74, Rust/Cargo 1.98.1 MSVC, DXC/DXIL 1.8.2502.11, debug. XCL_ADAPTER=3090, XCL_PSO_TITLE_BUILD=0.

cargo build --locked --workspace
cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output
Snapshot Workspace build Passed / failed / ignored across 20 harness summaries
PR head + regression passed 1075 / 2 / 45
PR head + priority fix + same regression passed 1076 / 1 / 45

Both retain gpu_clamp_and_omod_per_instruction: lane-0 v_pk_add_i16 clamp, actual 2146467856, expected 2147516415. Both Cargo test commands exit 101. No candidate-only failure observed; not an all-green suite. The repaired regression again checks actual Windows thread priority: base -1/-2 → boost 0 during the build; control stays 0 after completion and in the next unwanted job, while the fix restores -1/-2 for both observations.

Both runs emit the same 26 explicit SKIPPED notices: 19 unavailable native-wave64 subcases, three refused wave32 per-lane cases (f16 arithmetic, f16 packed, f32 conversions), two missing-debug-layer checks, one unavailable driver-cache-control check and one unavailable heap-window check. Data-dependent tests can return successfully without sample files, so raw pass counts are not retail coverage. All 314 source files matched before/after the Windows runs, locally, and in the published commit; XCL rebuilt each snapshot.

Not tested: retail smoke, actual driver-load scheduling benefit, stutter/throughput/CPU-use improvements, or current-main integration. The native priority probe uses dedicated test-owned threads calling production build() twice, rather than taking over shared queue workers. This completes the local workspace check for the priority patch; required merge and retail checks remain outstanding.

AI use: Codex (GPT-6) prepared the fix/test, ran and verified the Windows comparisons, and wrote this report.


Follow-up on 1f1d681: restore worker priority after an abandoned wait

Verified a separate priority-lifecycle bug on exact 1f1d681439db77ea01a656dc8fc65aa4eabc7d1b. A wait boosts the compile worker to normal priority. The new timeout guard can then clear d.wanted, but build() restores the worker's base priority only if d.wanted is still true. The next unwanted job inherits normal priority.

Small candidate in pso_async::build: always restore base_priority after clearing worker_thread, under the existing demand lock. This preserves the lock ordering that prevents a late want() from boosting a worker after cleanup. It restores priority when the build ends, not immediately on abandonment. This candidate is independent of the mixed-waiter fix below; neither comparison includes that patch.

Tested — native Windows 10 Home 19045, Ryzen 7 7800X3D, Rust/Cargo 1.98.1 x64 MSVC, debug; XCL_PSO_TITLE_BUILD=0.

cargo test --locked -p xcl --lib -- hle::d3d12x::pso_async --test-threads=1 --show-output

Snapshot Passed / failed / ignored / skipped After first build / inside next unwanted job
Head + regression 15 / 1 / 0 / 0 Normal / normal for both worker modes
Head + candidate + same regression 16 / 0 / 0 / 0 Below-normal / below-normal, and lowest / lowest

The regression uses test-owned native threads invoking production build() twice. It checks the actual Windows GetThreadPriority: initial bases -1 and -2, boosted priority 0 inside the first channel-gated job, then abandonment before releasing that job. Baseline records after=0 next=0 for both; candidate records after=-1 next=-1 and after=-2 next=-2. Both modes are checked before the final failure assertion. Pending entries are removed and threads joined before the result assertions. Existing 15 controls still pass. Both 314-file source manifests matched before/after and local snapshots; XCL recompiled both.

Not tested — actual shared-worker queue dispatch or driver compilation in this probe, GPU output, full workspace suite, retail smoke, stutter, CPU utilization or compilation throughput. This proves the priority leak and its cleanup fix, not a measured performance gain or resolution of the retail world-loading symptoms. No commit/push or competing PR; required merge checks remain separate.

AI use — Codex (GPT-6) identified the cleanup gap, wrote the candidate and regression, ran/verified the native comparison and prepared this update.

Independent candidate and regression
diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs
index 58147a9..46e46a6 100644
--- a/crates/xcl/src/hle/d3d12x/pso_async.rs
+++ b/crates/xcl/src/hle/d3d12x/pso_async.rs
@@ -84,9 +84,8 @@ fn build(p: &Arc<Pending>, job: Job, base_priority: i32) {
         // (under the lock: `want` does not raise this thread after it)
         let mut d = p.demand.lock().unwrap();
         d.worker_thread = 0;
-        if d.wanted {
-            unsafe { SetThreadPriority(GetCurrentThread(), base_priority) };
-        }
+        // A timed-out waiter can clear wanted after this worker was boosted.
+        unsafe { SetThreadPriority(GetCurrentThread(), base_priority) };
     }
     BUILDING.with(|b| *b.borrow_mut() = None);
 }
@@ -866,6 +865,55 @@ mod used_tests {
         gate.1.notify_all();
     }
 
+    #[test]
+    fn an_abandoned_wait_restores_worker_priority_before_its_next_job() {
+        use windows_sys::Win32::System::Threading::{GetCurrentThread, GetThreadPriority, SetThreadPriority, THREAD_PRIORITY_BELOW_NORMAL, THREAD_PRIORITY_LOWEST, THREAD_PRIORITY_NORMAL};
+        let mut failures = Vec::new();
+        for (i, base) in [THREAD_PRIORITY_BELOW_NORMAL, THREAD_PRIORITY_LOWEST].into_iter().enumerate() {
+            let standin = 0x7E57_B530usize + 2 * i;
+            let (started, building) = mpsc::channel();
+            let (go, finish) = mpsc::channel::<()>();
+            submit_lazy(standin, false, Box::new(move || {
+                started.send(unsafe { GetThreadPriority(GetCurrentThread()) }).unwrap();
+                let _ = finish.recv_timeout(Duration::from_secs(10));
+                0
+            }), 0);
+            submit_lazy(standin + 1, false, Box::new(|| 0), 0);
+            let p = entry(standin).unwrap();
+            let q = entry(standin + 1).unwrap();
+            let job = p.job.lock().unwrap().take().unwrap();
+            let _ = q.job.lock().unwrap().take();
+            let guard = p.begin_wait();
+            let worker_p = p.clone();
+            // Dedicated test-owned thread, using the production build lifecycle twice.
+            let worker = std::thread::spawn(move || unsafe {
+                assert_ne!(SetThreadPriority(GetCurrentThread(), base), 0);
+                let initial = GetThreadPriority(GetCurrentThread());
+                build(&worker_p, job, base);
+                let after = GetThreadPriority(GetCurrentThread());
+                let (tx, rx) = mpsc::channel();
+                build(&q, Box::new(move || {
+                    tx.send(GetThreadPriority(GetCurrentThread())).unwrap();
+                    0
+                }), base);
+                (initial, after, rx.recv().unwrap())
+            });
+            let during = building.recv_timeout(Duration::from_secs(10)).expect("boosted build started");
+            guard.abandon();
+            let abandoned = !p.demand.lock().unwrap().wanted;
+            let _ = go.send(());
+            let (initial, after, next) = worker.join().unwrap();
+            let _ = released(standin);
+            let _ = released(standin + 1);
+            println!("WORKER_PRIORITY base={base} initial={initial} during={during} abandoned={abandoned} after={after} next={next}");
+            assert_eq!(initial, base);
+            assert_eq!(during, THREAD_PRIORITY_NORMAL);
+            assert!(abandoned);
+            if after != base || next != base { failures.push(base); }
+        }
+        assert!(failures.is_empty(), "workers kept boosted priority after abandonment: {failures:?}");
+    }
+
     #[test]
     fn default_frame_budget_only_defers_graphics_and_never_leaves_skipped_psos_wanted() {
         let cap = Duration::from_millis(500);

Follow-up on 1f1d681: keep unbounded waits in the new demand count

Verified one remaining scheduling bug in exact 1f1d681439db77ea01a656dc8fc65aa4eabc7d1b. resolve_within uses begin_wait(), but the unbounded path in resolve_wait_with_budgets still calls p.want() directly. When a bounded waiter abandons the same pending pipeline, its guard sees zero counted waiters and clears wanted, even while the unbounded title thread remains blocked. wanted_here() then falsely tells the compile scheduler that nobody needs the build.

A possible policy transition is a graphics wait begun before the first Present (uncapped), followed by a second wait after the implicit frame cap activates. The test supplies these two budget modes directly; I have not observed this sequence in a retail title or proved a resulting watchdog/OOM.

Candidate: replace the unbounded path's p.want() with let _want_guard = p.begin_wait();. It joins the same existing lifetime/count mechanism, leaving timeout and frame policy unchanged. One runtime line changed, plus a 32-line regression in the same file (33 additions / 1 deletion overall).

Tested

Native Windows 10 Home19045, Ryzen7800X3D, Rust/Cargo1.98.1 x64 MSVC, debug. This is a real CPU-thread/worker test with a synthetic blocked job, not a GPU or driver compilation test. XCL_PSO_TITLE_BUILD=0 ensures the worker path.

cargo test --locked -p xcl --lib -- hle::d3d12x::pso_async --test-threads=1 --show-output

  • Head + same regression: 15 passed / 1 failed / 0 ignored / 0 skipped. Recorded initial=true unbounded_active=true wanted_after_timeout=false waiters=0.
  • Head + candidate + regression: 16 / 0 / 0 / 0. Recorded initial=true unbounded_active=true wanted_after_timeout=true waiters=1; final count is zero after completion.

The worker sends its actual wanted_here() callback, then stays behind a channel gate. The test observes active demand before making the second wait expire on a1ms frame budget. It records that the first waiter is still blocked, then opens the gate, joins it, and removes the pending entry before assertions, including on baseline failure. It checks the scheduler's callback as well as the counter. Existing lazy-bind, default-frame-budget, orphan-release, prewarm, bounded-wait and worker-demand tests all pass with the candidate.

Both314-file manifests matched before/after and the local snapshots; XCL recompiled both. No source commit/push or competing PR.

Not tested — full workspace, real GPU compile admission, retail world loading/watchdogs, actual commit-memory or performance effects, and other platforms. This fixes the false demand state; it does not establish that the earlier retail symptoms are resolved. Existing full-suite/retail requirements remain separate.

AI use — Codex (GPT-6) identified the uncounted path, wrote the one-line candidate and controlled regression, ran/verified the native comparison, and prepared this update.

Candidate and regression
diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs
index 58147a9..c3b3b11 100644
--- a/crates/xcl/src/hle/d3d12x/pso_async.rs
+++ b/crates/xcl/src/hle/d3d12x/pso_async.rs
@@ -866,6 +866,38 @@ mod used_tests {
         gate.1.notify_all();
     }
 
+    #[test]
+    fn a_timed_out_waiter_does_not_cancel_an_unbounded_waiters_demand() {
+        let standin = 0x7E57_B522usize;
+        let (started, building) = mpsc::channel();
+        let (go, finish) = mpsc::channel::<()>();
+        submit_lazy(standin, false, Box::new(move || {
+            started.send(wanted_here()).unwrap();
+            let _ = finish.recv_timeout(Duration::from_secs(10));
+            0
+        }), 0);
+        let bind = std::thread::spawn(move || resolve_wait_with_budgets(standin, None, None, &FrameWaitBudget::new()));
+        let wanted = building.recv_timeout(Duration::from_secs(10)).expect("worker started");
+        let start = Instant::now();
+        while !wanted() && start.elapsed() < Duration::from_secs(5) { std::thread::yield_now(); }
+        let initial = wanted();
+        let timed = resolve_wait_with_budgets(standin, None, Some(Duration::from_millis(1)), &FrameWaitBudget::new());
+        let pending = entry(standin).unwrap();
+        let still_waiting = !bind.is_finished();
+        let wanted_after_timeout = wanted();
+        let waiters = pending.demand.lock().unwrap().waiters;
+        // Release the worker and join the waiter before asserting, including on the negative control.
+        let _ = go.send(());
+        let resolved = bind.join().unwrap();
+        let _ = released(standin);
+        println!("MIXED_WAIT initial={initial} unbounded_active={still_waiting} wanted_after_timeout={wanted_after_timeout} waiters={waiters}");
+        assert!(initial && still_waiting, "unbounded waiter must be active during the timeout");
+        assert_eq!((timed, resolved), (standin, standin));
+        assert!(wanted_after_timeout, "an unbounded waiter still needs the compile");
+        assert_eq!(waiters, 1);
+        assert_eq!(pending.demand.lock().unwrap().waiters, 0);
+    }
+
     #[test]
     fn default_frame_budget_only_defers_graphics_and_never_leaves_skipped_psos_wanted() {
         let cap = Duration::from_millis(500);
@@ -1156,7 +1188,7 @@ fn resolve_wait_with_budgets(
     } else {
         enqueue(&p, true);
     }
-    p.want();
+    let _want_guard = p.begin_wait();
     let mut done = p.done.lock().unwrap();
     while !*done {
         done = p.cv.wait(done).unwrap();

Confirmed @gsucristo's blocking finding 2 on 7244baadcf009af2a79e94c9fd9c6e7b41d89ab9, with a small cancellation fix and deterministic reproducer.

The worker's orphan branch skips the job without calling complete, leaving an existing resolve_wait_for(..., None) waiter blocked on Pending::done. The candidate marks cancellation done and notifies waiters in released(), under the existing done mutex, after setting orphan. It does not depend on either worker queue progressing. An already-running build still reaches complete, sees orphan, and releases its result instead of publishing it. No failed-build counter is incremented just for cancellation.

The regression holds the worker queue while the waiter captures the pending entry, releases that entry, then opens the queue. It checks the waiter returns the existing stand-in fallback and the compiler closure never runs. On old code, a bounded test timeout captures the failure and the fixture explicitly wakes/joins the thread before failing; it does not leave a hung test process. A synthetic COM release counter separately verifies that complete still releases a late result exactly once and does not publish it.

Tested — native Windows 10 19045, Ryzen 7 7800X3D, Rust 1.98.1 MSVC, debug. Thread scheduling / fake object tests; no GPU dispatch or real driver compilation.

XCL_DXC_THREADS=2 XCL_PSO_TITLE_BUILD=0
cargo test --locked -p xcl --lib -- pso_async --test-threads=1 --show-output
  • Exact head + regression: 12 passed / 1 failed / 0 ignored, failure released job was skipped but its waiter never completed (Err(Timeout)).
  • Same head + regression + cancellation change: 13 passed / 0 failed / 0 ignored.
  • Zero skips. Both builds recompiled XCL; all 312 source hashes matched before/after.

This patch is independent of the earlier passive-bind lookup patch. It is offered here for the author's integration, with credit for the finding above; #978 already covers not executing released jobs, and is not duplicated.

Not tested — full workspace suite, the two fixes combined, actual title object-lifetime races, real COM/driver builds, dedicated preload-cancellation ordering, retail smoke or whether this stall occurs during world loading. A returned stand-in is the existing resolver fallback; the test does not establish that using an object after another thread releases it is valid. Required main/head retail smoke remains outstanding.

AI use — Codex (GPT-6) implemented the candidate and regression, ran the native tests, reviewed the cancellation/late-completion ordering and prepared this report.

Candidate and regression: one file, 50 additions / 2 deletions
diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs
index a21bb90..c719e9c 100644
--- a/crates/xcl/src/hle/d3d12x/pso_async.rs
+++ b/crates/xcl/src/hle/d3d12x/pso_async.rs
@@ -485,6 +485,51 @@ mod used_tests {
     use super::*;
     use std::sync::mpsc;
 
+    #[test]
+    fn releasing_a_queued_pipeline_wakes_its_unbounded_waiter() {
+        let standin = 0x7E57_B620usize;
+        let ran = Arc::new(AtomicBool::new(false));
+        let job_ran = ran.clone();
+        submit_lazy(standin, true, Box::new(move || {
+            job_ran.store(true, Ordering::Release);
+            0
+        }), 0x5EED_B620);
+        let p = entry(standin).unwrap();
+        // Hold dequeue/enqueue until resolve has retained this Pending. The nonzero
+        // key makes note_use publish that observation before it reaches the queue.
+        let queue = workers().q.lock().unwrap();
+        let (tx, rx) = mpsc::channel();
+        let waiter = std::thread::spawn(move || { tx.send(resolve_wait_for(standin, None)).unwrap(); });
+        let limit = std::time::Instant::now() + Duration::from_secs(5);
+        while !p.used.load(Ordering::Acquire) && std::time::Instant::now() < limit {
+            std::thread::yield_now();
+        }
+        let retained = p.used.load(Ordering::Acquire);
+        assert_eq!(released(standin), 0);
+        drop(queue);
+        let result = rx.recv_timeout(Duration::from_secs(1));
+        // Clean up even on the old code: never leave a hung thread behind a failing test.
+        *p.done.lock().unwrap() = true;
+        p.cv.notify_all();
+        waiter.join().unwrap();
+        assert!(retained, "waiter did not retain the pending pipeline");
+        assert_eq!(result, Ok(standin), "released job was skipped but its waiter never completed");
+        assert!(!ran.load(Ordering::Acquire), "released pipeline reached its compiler");
+
+        // Cancellation must still release a real result from a build already in flight.
+        static RELEASES: AtomicUsize = AtomicUsize::new(0);
+        unsafe extern "system" fn count_release(_: *mut std::ffi::c_void) -> u32 {
+            RELEASES.fetch_add(1, Ordering::SeqCst);
+            0
+        }
+        RELEASES.store(0, Ordering::SeqCst);
+        let vtable = [0usize, 0, count_release as usize];
+        let object = [vtable.as_ptr() as usize];
+        complete(&p, object.as_ptr() as usize);
+        assert_eq!(RELEASES.load(Ordering::SeqCst), 1);
+        assert_eq!(p.real.load(Ordering::Acquire), 0);
+    }
+
     /// While a bind waits for a pipeline still being built, the title is held (`title_held`):
     /// `kernelx::Sleep` does not count that time.
     #[test]
@@ -1095,12 +1140,15 @@ pub fn resolve_for_bind(pso: usize) -> usize {
 /// the worker's result is then released when it arrives).
 pub fn released(pso: usize) -> usize {
     let Some(p) = PENDING.lock().unwrap().as_mut().and_then(|m| m.remove(&pso)) else { return 0 };
-    let done = p.done.lock().unwrap();
+    let mut done = p.done.lock().unwrap();
     if *done {
         p.real.swap(0, Ordering::AcqRel)
     } else {
-        // the worker stores its result into a Pending nobody will read: mark it orphaned
+        // An in-flight result is still released by complete. A skipped queued job
+        // never calls complete, so cancellation must also wake existing waiters.
         p.orphan.store(true, Ordering::Release);
+        *done = true;
+        p.cv.notify_all();
         0
     }
 }

@raylitebull
raylitebull force-pushed the feat/pso-mmap-lib-and-lazy branch from 7244baa to 4d53a2c Compare November 25, 2026 01:14
@raylitebull

Copy link
Copy Markdown
Member Author

Thanks for all the detailed catches, @WebIdentity1 and @gsucristo!

Updated #2001 cleanly onto 656c0e8 (4d53a2c):

  • Passive switch lookup (list_x::on_set_pipeline_state): switched from pso_async::resolve to passive pso_async::resolve_if_ready so A -> B SetPipelineState switches no longer enqueue or mark-used a bound-but-never-drawn PSO (XCL_LAZY_ON_DRAW preserved).
  • Orphaned waiter wakeup (pso_async.rs): workers(), preload(), and released() now set *p.done = true and call cv.notify_all() on orphaned/released pending PSOs so unbounded resolve_wait callers never hang.
  • Library serialization & shutdown sync (real.rs, pso_library.rs): added RwLock synchronizing StorePipeline (read) against GetSerializedSize/Serialize (write), changed flush() on shutdown (WM_CLOSE) to wait on save_lock for any active background save instead of returning early, and removed rejected/corrupt .plib files on open_or_create.
  • Stream keys & adoption (real.rs): stream_key hashes pointer-bearing pipeline stream subobjects (INPUT_LAYOUT, STREAM_OUTPUT, VIEW_INSTANCING; skips CACHED_PSO) by pointed-to content, and deliver_adopted returns ID3D12PipelineState directly without querying console IIDs.

Verified locally (cargo check --workspace --tests, pso_async 14 passed, 0 failed, pso_library 3 passed, 0 failed, pso_lib::tests 2 passed, 0 failed).

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

World-loading test of 7244baa merged onto main 279d3ea, on the retail title, XCL_DIRECT_DXIL=1, otherwise this PR's defaults. Two 15-minute runs in a row: the pipeline library cold, then warm. The XCL DXIL cache was warm for every compute program, from a full --precompile --only cs --pipelines of main 177cd40 (#1269).

run last presents presents after 82 s skipped draws / dispatches queue waits that did not complete end
1 (library cold) 170 s 55 36 054 / 20 692 144, from 115 s stopped by my memory guard (process commit 37.3 GB, 6 GB of system commit left)
2 (library warm) 108 s 23 10 241 / 4 096 32, from 91 s the title's watchdog at 137 s; the process then hung until the 15-minute limit

For comparison, main 177cd40 with the same caches (compute warm, no pipeline library, one run): last presents at 94 s, then 82 graphics PSO builds in the driver and no further frames, but no watchdog in 900 s and commit at 31 GB.

What I saw of the PR's own parts:

  • The library works as described. Run 2 opened gen-00000009 (47 MiB, memory-mapped) at 3 s and saved six more generations up to 73 MiB, the largest with 62 new pipelines (at 87 s).
  • The shared 500 ms per-frame budget runs out from 80 s on ("deferring bind to next frame").
  • With the warm library, run 2 got less far than run 1 and ended at the watchdog, which neither run 1 nor main hit within their runs. One run each, so this may be run-to-run variation, but it is the opposite of what a warm library should do. A second warm run, or XCL_PSO_LIBRARY=0 on a warm DXIL cache, would show which.
  • Run 1 is the furthest any run on this machine has got (presents to 170 s), with about 2.5 times more skipped draws than run 2. Its commit climbed past 37 GB, where my guard stopped it.

Tested: RTX 4080 16 GB (32-lane waves), i9-12900K, 64 GB (commit limit 68 GB), Windows 11 26300, release build; no input after the menus.
Not tested: the suite on this head, a main run at the same commit (279d3ea), repeat runs, AMD, XCL_PSO_LIBRARY=0 / XCL_PSO_TITLE_BUILD=1.

AI use: Claude Code (Claude Opus 5.5): ran the tests and wrote this; the diff was read for safety by a Claude Opus 5.5 sub-agent before it was built.

…n budget skips

Address world-loading findings on xcl-dev#2001: (1) apply the implicit default 500 ms AfterFirstPresent frame-wait cap only to graphics pipelines so compute dispatches writing GPU sync/indirect buffers are not skipped mid-frame (explicit XCL_PSO_FRAME_WAIT_MS still applies to both); (2) do not mark deferred pipelines as wanted when the frame budget is already exhausted, and clear wanted on budget/timeout abandonment so skipped huge pipelines cannot bypass big_compile_turn's commit/slot gate and spike process commit; (3) take the shared lib_rw read lock in MmapPipelineLibrary::load_{compute,graphics,stream} so Load*Pipeline never races with Serialize.
@Anon64

Anon64 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run for this PR: head 7244baa, based on main 80f4819. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, in one batch with the main run.

main 80f4819:

xcl-smoke v1
commit: 80f4819098e921f2e1ab371144d4832f68ffedd6
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1588 (PresentX 1589)
presents per 2 s (last 3): 47 56 27
device removals: 0
crashes: 0
peak commit: 25184 MB

this PR:

xcl-smoke v1
commit: 7244baadcf009af2a79e94c9fd9c6e7b41d89ab9
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1612 (PresentX 1612)
presents per 2 s (last 3): 60 60 40
device removals: 0
crashes: 0
peak commit: 23635 MB

No device removals or crashes; 101 % of main's frames, 93 % of its peak commit.

Not tested: the whole suite; world loading; whether the title reaches all of the changed code in these 60 s (default settings: XCL_DIRECT_DXIL and XCL_HEAP_WINDOWS unset).

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

@raylitebull

Copy link
Copy Markdown
Member Author

Thanks for the detailed RTX 4080 world-load report, @throny! Your run exposed two real root causes on 7244baa, now fixed in 1f1d681:

  1. Commit climb (37.3 GB) under skipped draws: resolve_within was calling p.want() before checking frame_rem == 0 and never cleared demand.wanted after a budget skip or timeout — allowing deferred cold huge PSOs to bypass big_compile_turn gates concurrently across workers. 1f1d681 now checks frame_rem.is_zero() before begin_wait() and uses an RAII WaitWantGuard that resets wanted = false if a waiter abandons on budget exhaustion or timeout.
  2. Warm-library skipped compute dispatches + queue waits/watchdog: besides 4d53a2c's RwLock + orphan wakeup fix (previously missing on 7244baa when the 73 MiB save ran), the implicit default AfterFirstPresent(500 ms) frame budget was capping compute dispatches (4,096–20,692 skipped dispatches -> Wait64BitValueX stalls). 1f1d681 now applies the implicit default AfterFirstPresent(500 ms) cap ONLY to graphics PSOs (!p.compute, while explicit XCL_PSO_FRAME_WAIT_MS=<ms> still covers both), and also takes self.lib_rw.read() around MmapPipelineLibrary::load_{compute,graphics,stream} for concurrent Load* vs Serialize safety + adds default_frame_budget_only_defers_graphics_and_never_leaves_skipped_psos_wanted.

Compiled cleanly in release (0 errors) and pushed 1f1d681 for GitHub Actions Build and test + re-testing.

@JJAutoCompare

Copy link
Copy Markdown

PR #2001 verification on STOR-WINLAB

Tested detached head 1f1d681439db77ea01a656dc8fc65aa4eabc7d1b with a clean tracked worktree.

Environment

  • Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X.
  • Intel Arc A770 16 GiB, driver 32.0.101.9175, wave range 8–32, DoublePrecisionFloatShaderOps=0.
  • DXC/DXIL 1.9.2609.5 from %LOCALAPPDATA%\XclTooling\dxc-1.9.2609\bin\x64. Rust rustc 1.100.0 (0ef1bc386 2026-11-09). Unoptimized Cargo dev/test profiles with debug info and incremental compilation disabled.

Tested

  • cargo build --workspace and cargo test --workspace --no-run both exited 0 outside the GPU lock.
  • cargo test -p xcl --lib <filter> -- --nocapture passed for all three filters. Each had zero failures, ignores, and skip markers.
    • hle::d3d12x::pso_async:: — 15 passed. Covered off-thread PSO construction, lazy bind-to-first-use deferral, frame wait budgeting, release waking orphaned waiters, and used-only prewarm deduplication.
    • hle::d3d12x::pso_library:: — 3 passed. Covered latest-generation selection, empty/missing file handling, and preserving an open Windows mapping while saving a new generation.
    • hle::d3d12x::real::pso_lib::tests:: — 2 passed. Covered deterministic compute/graphics/stream keys and background save scheduling.
  • The workspace run passed async_compute_pso_registers_real_pso_and_not_standin and console_wave64_compute_through_the_pso_hook_dispatch_and_read_back without skip markers. These exercised asynchronous compute PSO registration and synthetic compute dispatch/readback.

Workspace suite

cargo test --workspace --no-fail-fast -- --test-threads=4 ran once inside L:/XclTooling/Invoke-ArcTest.ps1 and exited 101. Combined output is in L:\XclTooling\neon-slot-2\tmp\pr2001-suite.log.

Test target Passed Failed Ignored SKIPPED lines
xcl library unit tests 1002 25 25 22
xcl binary unit tests 0 0 0 0
tests\bcpack_parity.rs 1 0 0 0
tests\console_dlls_e2e.rs 13 0 0 0
tests\console_shaders.rs 3 0 4 0
tests\disasm_e2e.rs 1 0 0 0
tests\e2e.rs 2 1 0 0
tests\gpu_compute_e2e.rs 4 0 0 1
tests\gpu_pso_e2e.rs 7 0 0 0
tests\heap_probe.rs 0 0 4 0
tests\low_va.rs 1 0 0 0
tests\pls_quota.rs 1 0 0 0
tests\predication_e2e.rs 1 0 0 0
tests\rpf_e2e.rs 2 0 0 0
tests\shaders_e2e.rs 4 0 0 0
tests\sparse_reinit.rs 1 0 0 0
tests\texture_states.rs 1 0 0 0
tests\xg_oracle.rs 6 0 12 0
xcl-testtitle binary unit tests 0 0 0 0
Doc-tests xcl 0 0 0 0
Total 1050 26 45 23

All 20 harnesses reported results. The counts above are libtest totals. The 23 emitted SKIPPED lines span 13 test names and mark whole tests or individual subcases excluded from coverage.

  • 18 for unavailable wave64 execution.
  • 3 for refused per-lane shader instructions (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32).
  • 1 for unavailable driver-cache control (0x887A002D).
  • 1 for unavailable heap windows.

Failures

25 unrelated by code path. These DXIL and recompiler unit tests use the direct D3D12 test runner and bypass the changed XCL PSO hooks. The 21 tests below failed at CreateComputePipelineState with 0x80070057 (E_INVALIDARG). The f64 cases are consistent with the adapter's lack of FP64 shader support.

  • gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0
  • gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1
  • gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_2
  • gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_3
  • gpu::dxil::ops_tests::doubles_match_cpu
  • gpu::dxil::ops_tests::groupshared_barrier_and_atomics_run
  • gpu::dxil::round_tests::gpu_direct_f32_round_modes_dynamic_and_denormals
  • gpu::dxil::round_tests::gpu_direct_f32_round_modes_static
  • gpu::dxil::round_tests::gpu_direct_f32_round_preserved_denormal_times_inf_is_inf
  • gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu
  • gpu::recomp::tests::gpu_clamp_and_omod_per_instruction
  • gpu::recomp::tests::gpu_f64_class_compare
  • gpu::recomp::tests::gpu_f64_compares_with_nan
  • gpu::recomp::tests::gpu_f64_literal_high_word
  • gpu::recomp::tests::gpu_f64_math_random
  • gpu::recomp::tests::gpu_f64_roots
  • gpu::recomp::tests::gpu_f64_rounding_and_conversions
  • gpu::recomp::tests::gpu_float_compares_random
  • gpu::recomp::tests::gpu_frexp_f64_exp_and_mant
  • gpu::recomp::tests::gpu_ldexp_f64
  • gpu::recomp::tests::gpu_rndne_f64

Four more direct-runner tests reported shader result mismatches.

  • gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contraction — fused overflow control returned infinity.
  • gpu::recomp::tests::gpu_ps_image_sample_offset_implicit_lod_between_mips — got 25.609375, expected 26.
  • gpu::recomp::tests::gpu_valu_16_and_64_bit — v_add_f16 did not preserve the high half.
  • gpu::recomp::tests::gpu_wave64_ps_whole_wave_reductions — one channel read 217, expected 216.

1 confirmed pre-existing. test_title_runs_and_game_folder_is_untouched reached the synthetic title's RSSetDepthBiasX(-1000.5) check and saw blue [0, 0, 255, 255] where green was expected. The identical failure reproduced on the PR merge base 656c0e8ca070bdc9d7cb197d264792ef49304865 under the same Arc lock with cargo test -p xcl --test e2e test_title_runs_and_game_folder_is_untouched -- --exact. The baseline recorded 0 passed, 1 failed, 0 ignored, and 2 filtered out in pr2001-baseline-e2e.log.

Not tested

  • Retail Xbox title smoke runs, title-level graphics/mesh lazy compilation, and retail shader pack paths (XCL_SAMPLE_RPF unset). Sample-gated early returns can appear as passes.
  • D3D12 debug layer (d3d12SDKLayers.dll absent). The debug-layer test returns early under libtest capture, so that return is outside the 23 emitted markers.
  • Driver-backed ID3D12PipelineLibrary1 persistence across title runs, including verified cache hits and shutdown flushing. Unit tests covered mapped-file generation and save scheduling.
  • AMD/NVIDIA adapters and full native wave64 execution.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified the counts against pr2001-suite.log and published this report.

@akimfomin

Copy link
Copy Markdown

raylitebull, PortBridge followed up on victory-fork's duplicate pipeline work by checking XCL's driver blob cache. The compute and graphics publish and removal routines are unchanged between your 1f1d6814 head and main cbc296ab.

A CPU fixture forces four publishers of the same 16-byte key through those exact routines. Both caches charge 64 bytes with 16 present, then retain 48 bytes of charge after removal. Checking the vacant entry under the existing map lock makes both report 16 before removal and zero afterward. Under a 64-byte test budget, all four independent 16-byte keys then fit.

Exact patch, method and result. The patch only changes in-memory publishing and accounting. The fixture mocks blob retrieval and does not measure driver work or startup time.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

Linux (Wine + vkd3d-proton) + NVIDIA test of 1f1d681 on main 2bdf047 + #684: with no library file yet, the pipeline library was not created, so nothing was saved. The empty library is asked for with a non-null pointer and length 0, which vkd3d-proton refuses with E_INVALIDARG. With a null pointer it was created, saved, and read back in the next run.

Setup: Fedora 44, Wine 11.21 Staging, vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch (neither touches cache.c), RTX 4070 12 GB (driver 615.71.09), release build, XCL_PSO_PRELOAD=0 and no other switch. Retail title 1.0.2.1, the first-run screens completed once and no story progress, A pressed when the title presents steadily. One run per column, in this order.

Tested

main + #684 with 1f1d681 with the three lines below, run 1 the same, run 2
seconds 120 120 100 100
pipeline library lines in the log – 0 5 saved (gen 1 to 5, 160 pipelines) opened … gen-00000005, graphics PSO loaded from memory-mapped pipeline library from 5.1 s, 2 saved
draws skipped / dispatches skipped 0 / 0 64 to 127 / 0, the draws from 118.3 s 0 / 0 64 to 127 / 0, the draws from 88.0 s
last 2 s with a present 82.6 s 74.5 s 90.6 s 88.2 s
faults / device removals 0 / 0 0 / 0 0 / 0 0 / 0
  • A second run of 1f1d681 as it is, made after the last column, opened the file those runs had left (gen-00000007). So only the first, empty creation fails.
  • Native Windows (RTX 5070 Ti 16 GB, driver 621.24), 1 run of 120 s of the earlier head 4d53a2c on the same main + XG: fix CopyFromSubresource 7-argument ABI and guard destination span #684, preload on: 6 generations saved from gen 1 and no opened line, so there the empty library is created as it is.

Read

  • pso_library.rs:409: CreatePipelineLibrary::<ID3D12PipelineLibrary1>(&[]) passes the empty slice's pointer with length 0. vkd3d-proton refuses that (libs/vkd3d/cache.c:2534, if (!blob_length && blob); a probe of the one call on this prefix: 0x80070057 with a non-null pointer, 0 with NULL), .ok()? drops it and nothing is logged. What I ran in its place:
let mut lib: Option<ID3D12PipelineLibrary1> = None;
(Interface::vtable(&dev1).CreatePipelineLibrary)(Interface::as_raw(&dev1), std::ptr::null(), 0, &ID3D12PipelineLibrary1::IID, &mut lib as *mut _ as *mut _).ok().ok()?;
let lib = lib?;

Not tested: a world load (no run presented after 91 s); whether the library saves time here; scripts/smoke.ps1; XCL_LAZY_PSO=1; its unit tests at this head; 1f1d681 itself and the three lines on native Windows; AMD and Intel.

AI use: Claude Code (Claude Fable 5.2) read the diff, wrote and ran the probe and the three lines, ran the title and wrote this comment.

Posted without review by a person: the account owner was away and reads replies later.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@PracticalStudios

Copy link
Copy Markdown

Test report for 1f1d681 in the retail title, RTX 3090 (Ampere, 32-lane waves): the world-load stop is unchanged, because the title waits in a compute bind.

  • RTX 3090 24 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 26200, release. main cbc296a + XG: fix CopyFromSubresource 7-argument ABI and guard destination span #684, with and without this PR (local merge), 300 s, XCL_PRESS_A_AT through the menus, DXIL and most driver blobs already cached, XCL_THREAD_DUMP_AT=100,140.
  • Without: last frame at 84 s, 1 566 shown. With: last frame at 82 s, 1 691 shown. No device removal in either.
  • With this PR, at 100 s and 140 s two title threads are in resolve_wait_with_budgets, from bind::dispatch and bind::execute_indirect. The pipeline they wait for is still building on a preload worker: record 56c0cd3b82a00c6e (22 089 020 B DXIL, no driver blob), started at 9.5 s, not finished at 300 s (the case of Pipeline preload (#690) starts a compute build that never ends at the title screen; memory grows until it runs out (Linux: #611) #1035).
  • Since the default frame wait cap is graphics-only (1f1d681), compute binds still wait without a limit, so this stop isn't covered.
  • Not tested: AMD; a cap for compute binds.

AI use: Claude Code (Claude Opus 5.5) ran the runs, read the symbolized dumps and wrote this report.

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of 1f1d6814 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on cbc296ab, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1623 (PresentX 1623)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14648 MB
xcl-smoke v1
commit: 1f1d681439db77ea01a656dc8fc65aa4eabc7d1b
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1633 (PresentX 1633)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14808 MB

Against the limits in CONTRIBUTING.md: 101 % of main's frames, 101 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.