From 79b199410de232bc6372e070f466e051ca3e0a74 Mon Sep 17 00:00:00 2001 From: bmjask <> Date: Wed, 25 Nov 2026 21:47:45 -0800 Subject: [PATCH] D3D12.X: avoid deferred segments for bounded pipeline waits When XCL_PSO_WAIT_MS is positive, record a dispatch immediately and use the same bounded bind wait instead of splitting one deferred command-list segment per call. This prevents bounded mode from exhausting command-list memory during large cold-pipeline bursts. Unset, zero, and malformed values preserve the default deferred-submit path. The change is stacked on atomic ExecuteIndirect stand-in classification. GNU Windows-target cargo check passed. Windows/MSVC, GPU, and title smoke execution were not available on this host. Adapted from PR #2581. Assisted-by: Codex (GPT-5.6-sol) Assisted-by: Codex (GPT-5.6-sol) --- crates/xcl/src/hle/d3d12x/list_x.rs | 19 ++++++++++++++++++- crates/xcl/src/hle/d3d12x/pso_async.rs | 6 ++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/hle/d3d12x/list_x.rs b/crates/xcl/src/hle/d3d12x/list_x.rs index a9e03cffc5..ea4559f505 100644 --- a/crates/xcl/src/hle/d3d12x/list_x.rs +++ b/crates/xcl/src/hle/d3d12x/list_x.rs @@ -3087,7 +3087,11 @@ fn wait_target_after_split(list: *mut c_void, placement: WaitPlacement, continua /// Gives a dispatch whose pipeline is still being built a segment of its own, recorded at the submit. pub(super) unsafe fn defer(list: *mut c_void, what: Deferred) -> bool { - if split_recording(list, SegmentReason::DeferredDispatch(what)).is_none() { + // A bounded bind records now and waits for the same bound. Deferring it only adds a segment; + // thousands of these exhausted command-list memory in a retail title with a 1 ms budget. + if !defer_pipeline_wait(super::pso_async::waits_bounded(), || { + split_recording(list, SegmentReason::DeferredDispatch(what)).is_some() + }) { return false; } static N: AtomicU64 = AtomicU64::new(0); @@ -3098,6 +3102,10 @@ pub(super) unsafe fn defer(list: *mut c_void, what: Deferred) -> bool { true } +fn defer_pipeline_wait(waits_bounded: bool, split: impl FnOnce() -> bool) -> bool { + !waits_bounded && split() +} + /// Records the deferred dispatches of `wrapper`'s recording, waiting for their pipelines as a bind did. pub(super) unsafe fn record_deferred(wrapper: *mut c_void) { let mut segs = Vec::new(); @@ -5814,6 +5822,15 @@ mod tests { assert_eq!(SegmentReason::DeferredDispatch(Deferred::Dispatch(1, 2, 3)).extra_segments(), 2); } + #[test] + fn bounded_pipeline_wait_does_not_allocate_a_deferred_segment() { + let mut splits = 0; + assert!(!defer_pipeline_wait(true, || { splits += 1; true })); + assert_eq!(splits, 0); + assert!(defer_pipeline_wait(false, || { splits += 1; true })); + assert_eq!(splits, 1, "the default still defers to the submit"); + } + #[test] fn failed_split_preflight_does_not_consume_recording_state() { let query = (0x7000, 2); diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs index 80bdd854c8..21b15df15e 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -1797,6 +1797,12 @@ fn wait_budget() -> Option { *B.get_or_init(|| std::env::var("XCL_PSO_WAIT_MS").ok().and_then(|v| v.trim().parse::().ok()).filter(|&ms| ms > 0).map(std::time::Duration::from_millis)) } +/// Whether binds have an explicit time bound. A dispatch is then recorded immediately instead of +/// deferred to the submit, where it would only wait for the same bound. +pub(super) fn waits_bounded() -> bool { + wait_budget().is_some() +} + /// `resolve_wait` for at most `budget`: the build goes to the workers (not this thread), and a /// pipeline not built by then is `late` – it and later binds of it get the stand-in (their /// dispatches are skipped) until a worker has built it.