Skip to content
Closed
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
57 changes: 51 additions & 6 deletions crates/xcl/src/hle/d3d12x/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ pub(super) fn note_root_changing_signature(sig: usize) {
pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: usize, max: u32, args: usize, args_off: u64, count_buf: usize, count_off: u64) {
type F = unsafe extern "system" fn(*mut c_void, usize, u32, usize, u64, usize, u64);
let pc: F = std::mem::transmute(super::real::orig_fn(this, 59));
let pso = super::pso_async::resolve_wait(with(this, |s| s.pso));
let raw_pso = with(this, |s| s.pso);
let pso = super::pso_async::resolve_for_indirect(raw_pso);
let (gfx, compute) = (super::real::is_translated_graphics(pso), super::real::is_translated_compute(pso));
let (args_off, count_off) = (args_off + super::real::buffer_delta(args), count_off + super::real::buffer_delta(count_buf));
if !gfx && !compute {
Expand All @@ -244,8 +245,8 @@ pub(super) unsafe extern "system" fn execute_indirect(this: *mut c_void, sig: us
// call with that pair is invalid (debug layer 953, "the currently set Root Signature
// doesn't match the currently set Pipeline State Object"; a retail title's world then
// hung the GPU, 0x887a0006). Skipped, like a draw or dispatch of such a pipeline.
if super::pso_async::is_pending(with(this, |s| s.pso)) {
count(DRAWS_SKIPPED);
if super::pso_async::is_pending(raw_pso) {
count(if super::pso_async::is_pending_compute(raw_pso) { DISPATCHES_SKIPPED } else { DRAWS_SKIPPED });
static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
if N.fetch_add(1, Ordering::Relaxed) < 4 {
crate::xlog_warn!("D3D12.X: ExecuteIndirect with a pipeline that is still being built skipped");
Expand Down Expand Up @@ -406,8 +407,9 @@ pub(super) unsafe fn emit_prepared_indexed_draw(
unsafe fn graphics_bound(this: *mut c_void) -> Option<ID3D12GraphicsCommandList> {
let list = ID3D12GraphicsCommandList::from_raw_borrowed(&this)?.clone();
let pso = with(this, |s| s.pso);
// a pipeline still being built in the background is waited for (its stand-in draws nothing)
if !super::real::is_translated_graphics(super::pso_async::resolve_wait(pso)) {
// a pipeline still being built in the background is waited for up to the frame's budget,
// then drawn with its stand-in (nothing) while the build goes on
if !super::real::is_translated_graphics(super::pso_async::resolve_bounded(pso)) {
count(DRAWS_PC);
if super::present::trace_frame() {
// which pipelines draw without a translation (first 12 distinct)
Expand Down Expand Up @@ -712,7 +714,7 @@ pub(super) unsafe extern "system" fn set_pipeline_state(this: *mut c_void, pso:

/// #14 Dispatch: with a translated pipeline, on XCL's ABI with the kept root arguments
pub(super) unsafe extern "system" fn dispatch(this: *mut c_void, x: u32, y: u32, z: u32) {
let pso = super::pso_async::resolve_wait(with(this, |s| s.pso));
let pso = super::pso_async::resolve_for_indirect(with(this, |s| s.pso));
let Some(list) = ID3D12GraphicsCommandList::from_raw_borrowed(&this) else { return };
if !super::real::is_translated_compute(pso) {
// a console pipeline without a translation (including a background build that
Expand Down Expand Up @@ -1183,10 +1185,53 @@ mod tests {
"failed async compute stand-in must not enter translated ExecuteIndirect path"
);

// 3. Background compute build is still PENDING after timeout: ExecuteIndirect must skip
// cleanly (like Dispatch) rather than forwarding the stand-in to PC ExecuteIndirect.
let standin_pending = 0x7200_0005usize;
let real_pending = 0x7200_0006usize;
let (tx, rx) = std::sync::mpsc::channel::<()>();
pso_async::submit_lazy(
standin_pending,
true,
Box::new(move || {
let _ = rx.recv_timeout(std::time::Duration::from_secs(5));
real::register_translated_compute_for_test(real_pending);
real_pending
}),
0,
);
assert_eq!(
pso_async::resolve_compute_with_limit_for_test(standin_pending, std::time::Duration::from_millis(20)),
standin_pending
);
assert!(pso_async::is_pending_compute(standin_pending));

reset(list_ptr, 0x7200_0100, standin_pending);
let before_pending = counts_snapshot();
unsafe {
execute_indirect(list_ptr, 0x7200_00F1, 1, 0, 0, 0, 0);
}
let after_pending = counts_snapshot();
assert!(after_pending[DISPATCHES_SKIPPED] > before_pending[DISPATCHES_SKIPPED]);
assert_eq!(
fake.execute_indirect_calls.load(Ordering::Relaxed),
1,
"pending async compute stand-in must be skipped, not forwarded to PC ExecuteIndirect"
);

tx.send(()).unwrap();
let wait = std::time::Instant::now();
while pso_async::is_pending_compute(standin_pending) {
assert!(wait.elapsed() < std::time::Duration::from_secs(5), "pending compute PSO never completed");
std::thread::sleep(std::time::Duration::from_millis(10));
}

forget(list_ptr);
let _ = pso_async::released(standin_ok);
let _ = pso_async::released(standin_fail);
let _ = pso_async::released(standin_pending);
real::forget_pso_for_test(real_ok);
real::forget_pso_for_test(real_pending);
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions crates/xcl/src/hle/d3d12x/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub unsafe extern "system" fn present_x(queue: *mut c_void, plane_count: u32, pl
}

unsafe fn present_x_frame(queue: *mut c_void, plane_count: u32, planes: *const u8) {
super::pso_async::reset_frame_budget();
let frames = BOUNDARIES.fetch_add(1, Ordering::Relaxed) + 1;
if frames % 300 == 0 {
// the title's frame rate, for comparing runs (every 300 frames)
Expand Down
Loading
Loading