Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions crates/xcl/src/hle/d3d12x/pso_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,12 @@ fn wait_budget() -> Option<std::time::Duration> {
*B.get_or_init(|| std::env::var("XCL_PSO_WAIT_MS").ok().and_then(|v| v.trim().parse::<u64>().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.
Expand Down
Loading