Skip to content
Open
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
23 changes: 13 additions & 10 deletions crates/xcl/src/hle/d3d12x/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ 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)
// a pipeline still being built in the background: its stand-in, which draws nothing
// (`resolve_wait` waits for it only up to `XCL_PSO_WAIT_MS`)
let real = super::pso_async::resolve_wait(pso);
if !super::real::is_translated_graphics(real) {
// A finished two-pass MS/GS pipeline is a PC mesh shader pipeline (MS+PS) registered in
Expand Down Expand Up @@ -1026,7 +1027,7 @@ unsafe fn bind_abi(this: *mut c_void, list: &ID3D12GraphicsCommandList, pso: usi
std::ptr::copy_nonoverlapping(bytes.as_ptr(), p, bytes.len());
Ok(p as usize)
};
// a pipeline still being built in the background is waited for
// (only reached with a translated pipeline: built, `resolve_wait` returns it at once)
let real = super::pso_async::resolve_wait(pso);
// a compute shader takes no more arguments from registers than it has (`inline_for`)
let user_sgprs = if gfx { None } else { super::real::pso_user_sgprs(real) };
Expand Down Expand Up @@ -1111,8 +1112,8 @@ mod tests {
pso_async::submit_lazy(built, false, Box::new(|| 0x1235), 0);
pso_async::submit_lazy(failed, false, Box::new(|| 0), 0);
assert!(pso_async::is_pending(building));
assert_eq!(pso_async::resolve_wait(built), 0x1235);
assert_eq!(pso_async::resolve_wait(failed), failed);
assert_eq!(pso_async::wait_built(built), 0x1235);
assert_eq!(pso_async::wait_built(failed), failed);
assert!(!pso_async::is_pending(built) && !pso_async::is_pending(failed));
// never resolved: still pending (the skip case), then forgotten
assert!(pso_async::is_pending(building));
Expand Down Expand Up @@ -1447,7 +1448,7 @@ void main(uint t : SV_GroupIndex) {
real_ok
}),
);
assert_eq!(pso_async::resolve_wait(standin_ok), real_ok);
assert_eq!(pso_async::wait_built(standin_ok), real_ok);
assert!(!real::is_translated_compute(standin_ok));
assert!(real::is_translated_compute(real_ok));

Expand All @@ -1468,7 +1469,7 @@ void main(uint t : SV_GroupIndex) {
// onto S_fail, and ExecuteIndirect must not enter bind_abi either.
let standin_fail = 0x7200_0003usize;
pso_async::submit(standin_fail, true, Box::new(|| 0));
assert_eq!(pso_async::resolve_wait(standin_fail), standin_fail);
assert_eq!(pso_async::wait_built(standin_fail), standin_fail);
assert!(!real::is_translated_compute(standin_fail));

reset(list_ptr, 0x7200_0100, standin_fail);
Expand Down Expand Up @@ -1562,7 +1563,7 @@ void main(uint t : SV_GroupIndex) {
let list_ptr = &*fake as *const FakeAdoptedList as *mut c_void;

// With shared stand-ins (`standin::shell`), `dev_create_compute_pso` registers the
// title-facing shell in `CONSOLE_COMPUTE`, while `pso_async::resolve_wait` returns the
// title-facing shell in `CONSOLE_COMPUTE`, while `pso_async::wait_built` returns the
// shared driver pipeline when the background build fails.
let shell_fail = 0x7210_0001usize;
let shell_ok = 0x7210_0002usize;
Expand All @@ -1589,7 +1590,7 @@ void main(uint t : SV_GroupIndex) {
pso_async::shared(shell_ok, shared_driver);
real::register_console_compute_for_test(shell_ok);

assert_eq!(pso_async::resolve_wait(shell_fail), shared_driver);
assert_eq!(pso_async::wait_built(shell_fail), shared_driver);
assert!(!pso_async::is_pending(shell_fail));
assert!(real::is_console_compute(shell_fail));
assert!(!real::is_console_compute(shared_driver));
Expand All @@ -1611,6 +1612,8 @@ void main(uint t : SV_GroupIndex) {

// 2. Another shell sharing the same driver pipeline whose build succeeds still takes the
// translated path (caught here by the root-changing guard rather than falling through to PC).
// (built first: a bind does not build it, `resolve_wait`)
assert_eq!(pso_async::wait_built(shell_ok), real_ok);
reset(list_ptr, 0x7210_0100, shell_ok);
unsafe {
execute_indirect(list_ptr, sig_root_changing, 1, 0, 0, 0, 0);
Expand Down Expand Up @@ -1699,7 +1702,7 @@ void main(uint t : SV_GroupIndex) {
real_tp
}),
);
assert_eq!(pso_async::resolve_wait(standin_tp), real_tp);
assert_eq!(pso_async::wait_built(standin_tp), real_tp);
assert!(real::two_pass_of(real_tp).is_some());
assert!(!real::is_translated_graphics(real_tp));

Expand Down Expand Up @@ -1779,7 +1782,7 @@ void main(uint t : SV_GroupIndex) {
let standin = 0x7300_0001usize;
let pso1_raw = pso1.as_raw() as usize;
pso_async::submit(standin, true, Box::new(move || pso1_raw));
assert_eq!(pso_async::resolve_wait(standin), pso1_raw);
assert_eq!(pso_async::wait_built(standin), pso1_raw);

let mut raw_list: *mut c_void = std::ptr::null_mut();
let iid = windows_sys::core::GUID::from_u128(0x5b160d0f_ac1b_4185_8ba8_b3ae42a5a455);
Expand Down
6 changes: 3 additions & 3 deletions crates/xcl/src/hle/d3d12x/console_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,9 @@ pub unsafe fn close(obj: *mut c_void) -> Result<Translation, String> {
at += 4;
match pso {
Some(p) if (*p).translated => {
// a pipeline still being built in the background is waited for; if
// the background translation failed, skip instead of binding XCL's
// ABI root signature onto the stand-in
// a pipeline still being built in the background (waited for only up
// to `XCL_PSO_WAIT_MS`) or whose background translation failed: skip
// instead of binding XCL's ABI root signature onto the stand-in
let real = super::pso_async::resolve_wait((*p).pc);
if !super::real::is_translated_compute(real) {
out.skipped_dispatches += 1;
Expand Down
36 changes: 22 additions & 14 deletions crates/xcl/src/hle/d3d12x/list_x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2650,6 +2650,13 @@ unsafe fn try_split_for_wait(list: *mut c_void) -> Option<*mut c_void> {

/// 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 {
// Not while no bind or submit waits for a pipeline until it is built (`pso_async::resolve_wait`
// waits at most `XCL_PSO_WAIT_MS`): the call would only be skipped later, at the submit, and
// each put-off call costs a segment (a PC command list). Thousands of them ran a retail title
// out of command lists (#2581). It is recorded now and skipped as a stand-in's.
if !super::pso_async::waits_until_built() {
return false;
}
if split(list, Some(what)).is_none() {
return false;
}
Expand Down Expand Up @@ -7001,7 +7008,7 @@ mod tests {
}

#[test]
fn a_dispatch_with_a_pipeline_still_building_waits_at_the_submit() {
fn a_dispatch_with_a_pipeline_still_building_is_recorded_at_once_and_skipped() {
use super::super::{bind, pso_async, title_list};
use std::time::{Duration, Instant};
use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0;
Expand Down Expand Up @@ -7041,31 +7048,32 @@ mod tests {
bind::reset(pc0, alloc.as_raw() as usize, standin);
let wrap = title_list::wrap(pc0);

// (no `XCL_PSO_WAIT_MS`: nothing waits for the build, so no dispatch is put off to the
// submit; each is recorded at once and skipped as a stand-in's)
const DISPATCHES: usize = 210;
let mut segs = vec![pc0];
let skipped = bind::counts_snapshot()[4];
for n in 1..=DISPATCHES {
let t = Instant::now();
bind::dispatch(*segs.last().unwrap(), 1, 1, 1);
bind::dispatch(pc0, 1, 1, 1);
assert!(t.elapsed() < Duration::from_millis(700), "dispatch {n} waited for the build ({:?})", t.elapsed());
segs.clear();
assert!(title_list::push_segments(wrap, &mut segs));
}
assert_eq!(segs.len(), 1 + 2 * DISPATCHES, "the list before each dispatch, the dispatch, the list after it");
let mut segs = Vec::new();
assert!(title_list::push_segments(wrap, &mut segs));
assert_eq!(segs.len(), 1, "a dispatch was put off to the submit");
assert!(bind::counts_snapshot()[4] >= skipped + DISPATCHES as u64, "each dispatch is skipped at the bind");
assert!(pso_async::is_pending(standin));

let close_fn: unsafe extern "system" fn(*mut c_void) -> i32 = std::mem::transmute(*(*(wrap as *const *const usize)).add(9));
assert_eq!(close_fn(wrap), 0);
assert!(pso_async::is_pending(standin), "Close waited for the build");

let skipped = bind::counts_snapshot()[4];
let build = std::thread::spawn(|| {
std::thread::sleep(Duration::from_millis(300));
BUILD.store(true, Ordering::Release);
});
record_deferred(wrap);
assert!(!pso_async::is_pending(standin), "the submit waits for the build");
assert!(bind::counts_snapshot()[4] > skipped, "the dispatch of a build that failed is skipped, at the submit");
build.join().unwrap();
assert!(pso_async::is_pending(standin), "the submit waited for the build");
BUILD.store(true, Ordering::Release);
let t = Instant::now();
while pso_async::is_pending(standin) && t.elapsed() < Duration::from_secs(10) {
std::thread::sleep(Duration::from_millis(5));
}

type ExecFn = unsafe extern "system" fn(*mut c_void, u32, *const *mut c_void);
let exec: ExecFn = std::mem::transmute(*(*(queue.as_raw() as *const *const usize)).add(PC_QUEUE_EXECUTE_COMMAND_LISTS));
Expand Down
Loading
Loading