From 4e59a81438057887c62fe3ef4f03b77acfe747d2 Mon Sep 17 00:00:00 2001 From: bmjask <> Date: Thu, 26 Nov 2026 00:24:32 -0800 Subject: [PATCH] D3D12.X: reuse pending pipeline entries on bind A bind looked up the same stand-in twice in the global pending map. Completed compute pipelines also entered the wait path, taking completion and demand locks and trying to promote work whose real pointer was already published. Adapt #1708 to the integrated shared Build model: resolve through the first retained Pending entry and return a completed real pipeline after one acquire load. Zero still takes the existing budget, spared, wait, and failed-build paths. The Windows GNU library/test cross-check passed with the existing warnings. Windows MSVC runtime, GPU, and smoke tests were not available here. Source implementation and measurements: #1708 by CallMeBrado, written with OpenAI Codex (GPT-6). Assisted-by: Codex (GPT-5.6-sol) --- crates/xcl/src/hle/d3d12x/pso_async.rs | 27 ++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs index 2f75d7ca04..8280b1a1c9 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -1505,6 +1505,19 @@ mod used_tests { assert_eq!(released(standin), 0x5757); } + #[test] + fn binding_a_completed_compute_pipeline_neither_relooks_it_up_nor_requests_work() { + let standin = 0x7E57_B00Ausize; + submit(standin, true, Box::new(|| 0x5455)); + let p = entry(standin).unwrap(); + drop(p.build.cv.wait_while(p.build.done.lock().unwrap(), |done| !*done).unwrap()); + + assert_eq!(resolve_for_bind(standin), 0x5455); + assert_eq!(resolve_wait_for(standin, None), 0x5455); + assert!(!p.build.wanted.load(Ordering::Acquire)); + assert_eq!(released(standin), 0x5455); + } + /// 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] @@ -1949,6 +1962,10 @@ pub fn shared(standin: usize, driver: usize) { /// pipeline (`pso` itself when it is one). pub fn resolve(pso: usize) -> usize { let Some(p) = entry(pso) else { return pso }; + resolve_pending(&p, pso) +} + +fn resolve_pending(p: &Pending, pso: usize) -> usize { p.note_use(); match p.build.real.load(Ordering::Acquire) { 0 => { @@ -1988,6 +2005,9 @@ fn resolve_wait_bound_for(pso: usize, budget: Option) -> (u } fn resolve_wait_pending(p: &Arc, pso: usize, budget: Option) -> usize { + if let real @ 1.. = p.build.real.load(Ordering::Acquire) { + return real; + } let bound = if p.spared.load(Ordering::Acquire) { resolve_spared(p, pso) } else { @@ -2104,8 +2124,11 @@ fn resolve_spared(p: &Arc, pso: usize) -> usize { /// For binding: compute pipelines are waited for, graphics ones are not. pub fn resolve_for_bind(pso: usize) -> usize { match entry(pso) { - Some(p) if p.compute => resolve_wait(pso), - Some(_) => resolve(pso), + Some(p) if p.compute => { + p.note_use(); + resolve_wait_pending(&p, pso, wait_budget()) + } + Some(p) => resolve_pending(&p, pso), None => pso, } }