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 2a7be716a1..36c522ffbe 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -1690,6 +1690,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.