From 398acfe7d8f126722663e76a90178fe5c0b00282 Mon Sep 17 00:00:00 2001 From: raylitebull <287713799+raylitebull@users.noreply.github.com> Date: Tue, 1 Dec 2026 14:22:51 +0000 Subject: [PATCH] D3D12.X: retained binds wait by the graphics and compute PSO budgets resolve_retained_for_emission, which bind.rs resolve_pipeline uses for retained draws and dispatches, waited for a pipeline still being built by XCL_PSO_WAIT_MS alone. XCL_GFX_PSO_WAIT_MS and XCL_CS_PSO_WAIT_MS, which resolve_wait honours, did not apply there: with only those set, a retained bind held the title's thread until its pipeline was built. resolve_wait_pending_budgets applies resolve_wait_budgets' policy to the retained Pending, without looking its title address up again. Nothing changes while the budgets are unset (the default). Ported from amd-dev 4d6d4a77; its kept-pipeline override has no counterpart on main. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --- crates/xcl/src/hle/d3d12x/pso_async.rs | 61 +++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs index 99f1d58b26..62b6f2e611 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -12406,6 +12406,27 @@ fn resolve_wait_bound_and_pin(pso: usize) -> ((usize, bool), Option, + pso: usize, + all: Option, + gfx: Option, + cs: Option, +) -> usize { + match gfx.filter(|_| !p.compute) { + Some(budget) => { + let start = std::time::Instant::now(); + let r = resolve_wait_pending(p, pso, Some(gfx_wait_left(budget, start))); + gfx_wait_spent(start.elapsed()); + r + } + None => resolve_wait_pending(p, pso, budget_for(p.compute, all, gfx, cs)), + } +} + /// Resolve one retained Pending to an exactly owned generation without consulting its title /// address. One-shot and recipe-backed builds share the same wait policy at this boundary. fn resolve_retained_for_emission(pso: usize, p: &Arc) -> PipelineChoice { @@ -12415,7 +12436,7 @@ fn resolve_retained_for_emission(pso: usize, p: &Arc) -> PipelineChoice return PipelineChoice::Unavailable; } p.note_use(); - let bound = resolve_wait_pending(p, pso, wait_budget()); + let bound = resolve_wait_pending_budgets(p, pso, wait_budget(), gfx_wait_budget(), cs_wait_budget()); let bound_unbuilt = p.bound_unbuilt(pso, bound); let (raw, generation, _) = pin_resolved(pso, p, bound, bound_unbuilt); match generation { @@ -12935,4 +12956,42 @@ mod backlog_tests { released(standin); } } + + /// A retained bind (`resolve_retained_for_emission`) waits for a pipeline still being built + /// by the budget of its kind, as `resolve_wait` does: `XCL_GFX_PSO_WAIT_MS` for a graphics + /// one, `XCL_CS_PSO_WAIT_MS` for a compute one. Before, it waited by `XCL_PSO_WAIT_MS` alone + /// (unset: until the pipeline was built). + #[test] + fn a_retained_bind_waits_by_the_budget_of_its_kind() { + use std::time::{Duration, Instant}; + let (short, long) = (Some(Duration::from_millis(20)), Some(Duration::from_secs(30))); + let mut builds = Vec::new(); + for (standin, compute, built) in [(0x7E57_C090usize, false, 0x6F6Fusize), (0x7E57_C091, true, 0x6F70)] { + let (go, finish) = mpsc::channel::<()>(); + submit_lazy( + standin, + compute, + Box::new(move || { + let _ = finish.recv_timeout(Duration::from_secs(5)); + built + }), + 0x5EED_C090 + compute as u64, + ); + let p = entry(standin).expect("pending pipeline registered"); + let (gfx, cs) = if compute { (long, short) } else { (short, long) }; + let t0 = Instant::now(); + assert_eq!(resolve_wait_pending_budgets(&p, standin, None, gfx, cs), standin, "compute {compute}: the stand-in past its budget"); + assert!(t0.elapsed() < Duration::from_secs(1), "compute {compute}: waited {:?}", t0.elapsed()); + builds.push((standin, built, go)); + } + for (standin, built, go) in builds { + let _ = go.send(()); + // (built before it is released: the worker does not release the made-up pipeline) + let deadline = Instant::now() + Duration::from_secs(5); + while is_pending(standin) && Instant::now() < deadline { + std::thread::sleep(Duration::from_millis(5)); + } + assert_eq!(released(standin), built); + } + } }