From 1e28011782dd52bdbe245885cc1cb2a4baee9810 Mon Sep 17 00:00:00 2001 From: Enrique Villa Date: Thu, 26 Nov 2026 03:44:26 +0800 Subject: [PATCH] D3D12.X: ExecuteIndirect skips a stand-in whose build ends during the call `execute_indirect` resolved the bound pipeline (`resolve_wait`) and then asked `is_pending` again to decide whether what it got is a stand-in of a pipeline still being built. A build that ended between the two calls made `is_pending` false while `pso` was still the stand-in (or the shared stand-in driver pipeline). With a signature that is not a Dispatch one the call then went to the PC ExecuteIndirect with the stand-in and the list's root signature, the pair the skip exists to avoid (debug layer 953, a retail title's GPU hang 0x887a0006). `pso_async::bound_unbuilt(raw, pso)` answers for what the bind got: `pso` is the stand-in and the build did not fail. A build that ended since does not change that; a failed build's stand-in still goes on to the console compute check below. The window is reached when a bind does not wait for the build to the end: `XCL_PSO_WAIT_MS`, `XCL_PSO_IMAGE_SKIP=1`, and without any wait if a bind stops building cold pipelines itself. Assisted-by: Claude Code (Claude Opus 5.5) --- crates/xcl/src/hle/d3d12x/bind.rs | 2 +- crates/xcl/src/hle/d3d12x/pso_async.rs | 49 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs index 3f31c48b43..1f578019a7 100644 --- a/crates/xcl/src/hle/d3d12x/bind.rs +++ b/crates/xcl/src/hle/d3d12x/bind.rs @@ -283,7 +283,7 @@ pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: us // call with that pair is invalid (debug layer 953, "the currently set Root Signature // doesn't match the currently set Pipeline State Object"; a retail title's world then // hung the GPU, 0x887a0006). Skipped, like a draw or dispatch of such a pipeline. - if super::pso_async::is_pending(raw_pso) { + if super::pso_async::bound_unbuilt(raw_pso, pso) { count(DRAWS_SKIPPED); static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); if N.fetch_add(1, Ordering::Relaxed) < 4 { diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs index 63d62a7df4..ca3f07594b 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -713,6 +713,44 @@ mod used_tests { } } + /// What a bind got before its pipeline was built stays "not built" for it after the build + /// ends (`bound_unbuilt`), where `is_pending` already says built: `ExecuteIndirect` skipped + /// on that and sent the stand-in to the PC call. A failed build's stand-in and a pipeline that + /// is no stand-in are not unbuilt. + #[test] + fn a_stand_in_bound_before_its_build_ended_stays_unbuilt_for_that_bind() { + let (standin, failed) = (0x7E57_B0D1usize, 0x7E57_B0D2usize); + let (go, finish) = mpsc::channel::<()>(); + submit_lazy(standin, true, Box::new(move || { + let _ = finish.recv(); + 0x6161 + }), 0); + // (a bind that does not wait: the stand-in while it is built) + image_only(standin); + let bound = resolve_wait_for(standin, None); + assert_eq!(bound, standin); + assert!(is_pending(standin) && bound_unbuilt(standin, bound)); + go.send(()).unwrap(); + let start = std::time::Instant::now(); + while is_pending(standin) && start.elapsed() < std::time::Duration::from_secs(10) { + std::thread::sleep(std::time::Duration::from_millis(5)); + } + assert_eq!(resolve(standin), 0x6161); + assert!(!is_pending(standin), "built"); + assert!(bound_unbuilt(standin, bound), "the bind got the stand-in, not the pipeline built after it"); + assert!(!bound_unbuilt(standin, resolve_wait_for(standin, None)), "a bind after the build gets the real pipeline"); + submit(failed, true, Box::new(|| 0)); + let start = std::time::Instant::now(); + while is_pending(failed) && start.elapsed() < std::time::Duration::from_secs(10) { + std::thread::sleep(std::time::Duration::from_millis(5)); + } + assert_eq!(resolve(failed), failed); + assert!(!bound_unbuilt(failed, failed), "a failed build's stand-in is not waiting for a build"); + assert!(!bound_unbuilt(0x7E57_B0D3, 0x7E57_B0D3), "no stand-in"); + let _ = released(standin); + let _ = released(failed); + } + /// A bind waits for a pipeline still being built no longer than its budget and goes on with /// the stand-in; later binds do not wait for it again; once built it is the real one. #[test] @@ -1228,6 +1266,17 @@ pub fn need_by_submit(pso: usize) { } } +/// `bound` – what `resolve_wait(standin)` gave a bind – is the stand-in of a pipeline that was not +/// built yet then: still being built, or built since. Not after a failed build (that one is the +/// stand-in for good). Unlike `is_pending(standin)` after the bind, a build that ends between +/// the two does not make the stand-in look like the title's pipeline. +pub fn bound_unbuilt(standin: usize, bound: usize) -> bool { + entry(standin).is_some_and(|p| { + let done = p.done.lock().unwrap(); + bound == p.stand(standin) && !(*done && p.real.load(Ordering::Acquire) == 0) + }) +} + /// (built in the background, failed, still building) pub fn counts() -> (usize, usize, usize) { let pending = PENDING.lock().unwrap().as_ref().map_or(0, |m| m.values().filter(|p| !*p.done.lock().unwrap()).count());