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
8 changes: 4 additions & 4 deletions crates/xcl/src/hle/d3d12x/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: us
let pc: F = std::mem::transmute(super::real::orig_fn(this, 59));
let raw_pso = with(this, |s| s.pso);
let unbuilt_compute = signature_dispatches(sig) && super::pso_async::is_pending(raw_pso) && super::real::is_console_compute(raw_pso);
if unbuilt_compute && super::list_x::defer(this, super::list_x::Deferred::Indirect(sig, max, args, args_off, count_buf, count_off)) {
return super::pso_async::need_by_submit(raw_pso);
if unbuilt_compute && super::list_x::defer(this, raw_pso, super::list_x::Deferred::Indirect(sig, max, args, args_off, count_buf, count_off)) {
return;
}
let (pso, bound_unbuilt) = super::pso_async::resolve_wait_bound(raw_pso);
let (gfx, compute) = (super::real::is_translated_graphics(pso), super::real::is_translated_compute(pso));
Expand Down Expand Up @@ -938,8 +938,8 @@ fn dispatch_groups(pso: usize, dims: [u32; 3], flags: u32) -> Option<([u32; 3],
/// `Dispatch` / `DispatchX(x, y, z, flags)`.
pub(super) unsafe fn dispatch_flags(this: *mut c_void, x: u32, y: u32, z: u32, flags: u32) {
let pso = with(this, |s| s.pso);
if super::pso_async::is_pending(pso) && super::list_x::defer(this, super::list_x::Deferred::Dispatch(x, y, z, flags)) {
return super::pso_async::need_by_submit(pso);
if super::pso_async::is_pending(pso) && super::list_x::defer(this, pso, super::list_x::Deferred::Dispatch(x, y, z, flags)) {
return;
}
let pso = super::pso_async::resolve_wait(pso);
let Some(list) = ID3D12GraphicsCommandList::from_raw_borrowed(&this) else { return };
Expand Down
34 changes: 25 additions & 9 deletions crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3202,12 +3202,14 @@ 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 {
pub(super) unsafe fn defer(list: *mut c_void, pso: usize, what: Deferred) -> bool {
// 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()
}) {
if !defer_pipeline_wait(
super::pso_async::waits_bounded(),
|| super::pso_async::need_by_submit(pso),
|| split_recording(list, SegmentReason::DeferredDispatch(what)).is_some(),
) {
return false;
}
static N: AtomicU64 = AtomicU64::new(0);
Expand All @@ -3218,8 +3220,15 @@ 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()
fn defer_pipeline_wait(waits_bounded: bool, demand: impl FnOnce(), split: impl FnOnce() -> bool) -> bool {
if waits_bounded {
return false;
}
// The split can allocate and reset native objects. Let the worker and its compiler/driver
// admission run concurrently with that preparation; a failed split waits for the same build
// immediately in the caller.
demand();
split()
}

/// Records the deferred dispatches of `wrapper`'s recording, waiting for their pipelines as a bind did.
Expand Down Expand Up @@ -6052,11 +6061,18 @@ mod tests {
}

#[test]
fn bounded_pipeline_wait_does_not_allocate_a_deferred_segment() {
fn bounded_wait_skips_defer_and_unbounded_demand_precedes_split() {
let demanded = std::cell::Cell::new(0);
let mut splits = 0;
assert!(!defer_pipeline_wait(true, || { splits += 1; true }));
assert!(!defer_pipeline_wait(true, || demanded.set(demanded.get() + 1), || { splits += 1; true }));
assert_eq!(demanded.get(), 0);
assert_eq!(splits, 0);
assert!(defer_pipeline_wait(false, || { splits += 1; true }));
assert!(defer_pipeline_wait(false, || demanded.set(demanded.get() + 1), || {
assert_eq!(demanded.get(), 1, "pipeline demand must be visible before split preparation");
splits += 1;
true
}));
assert_eq!(demanded.get(), 1);
assert_eq!(splits, 1, "the default still defers to the submit");
}

Expand Down