diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs index df9fabd0da..d0471054e9 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -6332,7 +6332,7 @@ mod used_tests { assert!(resolution.clone().is_compute(), "a clone lost the retained pipeline kind"); assert!(matches!( - resolution.resolve_for_indirect_with_budget(Some(std::time::Duration::ZERO)), + resolution.resolve_for_indirect_with_budget((Some(std::time::Duration::ZERO), None, None)), IndirectPipelineChoice::InitialFallback { raw, bound_unbuilt: true } if raw == original )); assert!(!*replacement.build.done.lock().unwrap()); @@ -6394,7 +6394,7 @@ mod used_tests { let pending = structured_pending(build.clone(), true); assert!(PENDING.insert(original, pending.clone()).is_none()); let resolution = begin_pipeline_resolution(original).unwrap(); - let waiter = std::thread::spawn(move || resolution.resolve_for_indirect_with_budget(None)); + let waiter = std::thread::spawn(move || resolution.resolve_for_indirect_with_budget((None, None, None))); while !started.load(Ordering::Acquire) { std::thread::yield_now(); } assert_eq!(released(original), 0); assert_eq!(build.owners.load(Ordering::Acquire), 0); @@ -10516,6 +10516,41 @@ mod used_tests { std::thread::sleep(Duration::from_millis(5)); } assert_eq!(resolve_wait_budgets(gfx, None, budget, None), 0x6565, "built by a worker"); + // A recorded draw's retained pipeline (`resolve_retained_for_emission`) waits by the + // same budgets as a bind: a graphics pipeline only for the thread's share. + let (gfx2, cs2) = (0x7E57_C023usize, 0x7E57_C024usize); + submit(gfx2, false, slow(0x6767)); + submit(cs2, true, slow(0x6868)); + let (p, c) = (entry(gfx2).unwrap(), entry(cs2).unwrap()); + let t = Instant::now(); + assert_eq!(resolve_pending_budgets(&p, gfx2, None, budget, None), gfx2, "a retained draw is not waited for past the budget"); + assert!(t.elapsed() < Duration::from_millis(400), "waited {:?}", t.elapsed()); + assert_eq!(resolve_pending_budgets(&c, cs2, None, budget, None), 0x6868, "a retained dispatch is waited for"); + // (released once built: a build released before it ends is orphaned, and its worker + // releases the result, which these fakes are not) + let start = Instant::now(); + while is_pending(gfx2) && start.elapsed() < Duration::from_secs(10) { + std::thread::sleep(Duration::from_millis(5)); + } + released(gfx2); + released(cs2); + // So does a graphics bind or indirect draw that pins its pipeline + // (`resolve_and_pin_pending`, `resolve_for_indirect`), which used to wait by + // `XCL_PSO_WAIT_MS` alone; a pinned dispatch still does (`pinned_wait_budgets`). + let gfx3 = 0x7E57_C025usize; + submit(gfx3, false, slow(0x6969)); + let p = entry(gfx3).unwrap(); + let t = Instant::now(); + assert_eq!(resolve_and_pin_pending_budgets(gfx3, &p, ResolveMode::Wait, (None, budget, None)).0, gfx3, "a pinned bind is not waited for past the budget"); + assert!(t.elapsed() < Duration::from_millis(400), "waited {:?}", t.elapsed()); + let start = Instant::now(); + while is_pending(gfx3) && start.elapsed() < Duration::from_secs(10) { + std::thread::sleep(Duration::from_millis(5)); + } + released(gfx3); + let (pinned_all, pinned_gfx, pinned_cs) = pinned_wait_budgets(); + assert_eq!((pinned_all, pinned_gfx), (wait_budget(), gfx_wait_budget())); + assert_eq!(pinned_cs, None, "a pinned dispatch is not skipped by XCL_CS_PSO_WAIT_MS"); let all = Some(Duration::from_secs(5)); assert_eq!(budget_for(true, all, budget, None), all, "XCL_PSO_WAIT_MS still holds for compute"); assert_eq!(budget_for(false, all, None, None), all); @@ -10858,16 +10893,24 @@ fn resolve_wait_bound_for(pso: usize, budget: Option) -> (u /// `resolve_wait` with the budget of every pipeline (`XCL_PSO_WAIT_MS`), the one of graphics /// pipelines (`XCL_GFX_PSO_WAIT_MS`) and the one of compute pipelines (`XCL_CS_PSO_WAIT_MS`). fn resolve_wait_budgets(pso: usize, all: Option, gfx: Option, cs: Option) -> usize { - let Some(compute) = entry(pso).map(|p| p.compute) else { return resolve_wait_for(pso, None) }; - match gfx.filter(|_| !compute) { + let Some(p) = entry(pso) else { return resolve_wait_for(pso, None) }; + p.note_use(); + resolve_pending_budgets(&p, pso, all, gfx, cs) +} + +/// `resolve_wait_budgets` for a `Pending` already in hand: what a draw's exact retained +/// pipeline (`resolve_retained_for_emission`) waits by as well, so `XCL_GFX_PSO_WAIT_MS` and +/// `XCL_CS_PSO_WAIT_MS` bound the waits of recorded draws and dispatches, not only of binds. +fn resolve_pending_budgets(p: &Arc, pso: usize, all: Option, gfx: Option, cs: Option) -> usize { + match gfx.filter(|_| !p.compute) { // the graphics budget is a thread's for a second, not one for each pipeline Some(budget) => { let start = std::time::Instant::now(); - let r = resolve_wait_for(pso, Some(gfx_wait_left(budget, start))); + let r = resolve_wait_pending(p, pso, Some(gfx_wait_left(budget, start))); gfx_wait_spent(start.elapsed()); r } - None => resolve_wait_for(pso, budget_for(compute, all, gfx, cs)), + None => resolve_wait_pending(p, pso, budget_for(p.compute, all, gfx, cs)), } } @@ -11206,6 +11249,10 @@ pub(super) fn resolve_and_pin_for_bind(pso: usize) -> (usize, Option, Option, Option); + /// One retained resolver decision. Bind state snapshots it without waiting; a later emission /// stage can consume it without looking up a possibly reused title address. #[allow(dead_code)] @@ -11479,11 +11526,11 @@ impl PipelineResolution { #[allow(dead_code)] // consumed by the ExecuteIndirect integration stage pub(super) fn resolve_for_indirect(&self) -> IndirectPipelineChoice { - self.resolve_for_indirect_with_budget(wait_budget()) + self.resolve_for_indirect_with_budget(pinned_wait_budgets()) } fn resolve_for_indirect_with_budget( - &self, budget: Option, + &self, (all, gfx, cs): WaitBudgets, ) -> IndirectPipelineChoice { if let StructuredResolve::Initial { original, pending, promoted, .. } = &self.0 { if let Some(generation) = promoted.get() { @@ -11498,7 +11545,7 @@ impl PipelineResolution { return IndirectPipelineChoice::Unavailable; } pending.note_use(); - let bound = resolve_wait_pending(pending, *original, budget); + let bound = resolve_pending_budgets(pending, *original, all, gfx, cs); let bound_unbuilt = pending.bound_unbuilt(*original, bound); let (raw, generation, stale_fallback) = pin_resolved( *original, pending, bound, bound_unbuilt, @@ -12261,17 +12308,32 @@ fn resolve_and_pin_mode(pso: usize, mode: ResolveMode) -> (usize, Option, mode: ResolveMode) -> (usize, Option) { + resolve_and_pin_pending_budgets(pso, p, mode, pinned_wait_budgets()) +} + +/// The budgets of a bind that pins its pipeline: a graphics pipeline's `XCL_GFX_PSO_WAIT_MS` +/// share, but a compute pipeline only `XCL_PSO_WAIT_MS`, as before. Skipping a pinned dispatch +/// after `XCL_CS_PSO_WAIT_MS` left out ~300 compute passes a session in a retail world on an +/// RTX 3060 Ti (2-12 before), and one run ended in a GPU hang (device removed, no page fault). +fn pinned_wait_budgets() -> WaitBudgets { + (wait_budget(), gfx_wait_budget(), None) +} + +/// `resolve_and_pin_pending` with the budgets of every, graphics and compute pipeline +/// (`resolve_pending_budgets`): `XCL_GFX_PSO_WAIT_MS` and `XCL_CS_PSO_WAIT_MS` bound these +/// waits too, not only `XCL_PSO_WAIT_MS`. +fn resolve_and_pin_pending_budgets(pso: usize, p: &Arc, mode: ResolveMode, (all, gfx, cs): WaitBudgets) -> (usize, Option) { // Resolve directly against this retained Pending: a concurrent release/address reuse cannot // make selection consult a new registry entry while validation still uses the old recipe. let resolved = match mode { ResolveMode::Lazy => resolve_pending(p, pso), ResolveMode::Wait => { p.note_use(); - resolve_wait_pending(p, pso, wait_budget()) + resolve_pending_budgets(p, pso, all, gfx, cs) } ResolveMode::ForBind if p.compute => { p.note_use(); - resolve_wait_pending(p, pso, wait_budget()) + resolve_pending_budgets(p, pso, all, gfx, cs) } ResolveMode::ForBind => resolve_pending(p, pso), }; @@ -12347,7 +12409,8 @@ pub(super) fn resolve_and_pin_if_enabled_identity(pso: usize) -> (usize, Option< fn resolve_wait_bound_and_pin(pso: usize) -> ((usize, bool), Option) { let Some(p) = entry(pso) else { return ((pso, false), None) }; p.note_use(); - let bound = resolve_wait_pending(&p, pso, wait_budget()); + let (all, gfx, cs) = pinned_wait_budgets(); + let bound = resolve_pending_budgets(&p, pso, all, gfx, cs); let choice = (bound, p.bound_unbuilt(pso, bound)); let (resolved, generation, stale_fallback) = pin_resolved(pso, &p, choice.0, choice.1); ((resolved, choice.1 || stale_fallback), generation) @@ -12362,7 +12425,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_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 {