From ec538f118a185eda91bdd7da6e63e6d0d40ed5df Mon Sep 17 00:00:00 2001 From: grahamster2 <128315603+grahamster2@users.noreply.github.com> Date: Wed, 25 Nov 2026 17:10:08 -0500 Subject: [PATCH 1/2] D3D12.X: a dispatch put off to the submit waits there until it is built With XCL_PSO_WAIT_MS set, a Dispatch or dispatching ExecuteIndirect put off to the submit (#2118) was recorded through resolve_wait, with the same budget a bind has as the title records. A pipeline a bind had already found late got the stand-in at once, one still building got it after the budget, and the dispatch was counted as skipped and left out. Its segment lies between the list's other work, so the list's Write64 labels, EOP writes and fence signals still fired: the title saw the work as done while its UAV outputs, counters and indirect argument buffers were never written. record_deferred now waits for the segment's compute pipeline (pso_async::wait_for_submit) before it records the call, whether a bind found it late or not. Without the budget this is the wait the submit already made. With it, the submit leaves the build to the workers for the budget first, as a bind does, so big compiles keep their turns on the workers; one no worker has started by then is built on the submitting thread, so a submit never waits for a free worker. One a worker builds is waited for at most 30 s (SUBMIT_WAIT_MOST, the time a retail title's watchdog lets its main thread stand still, #891): title_held stops kernelx::Sleep and the GPU-wait watchdog, not every clock a title reads. Past that the call goes on with the stand-in as before, with a WARN ("deferred dispatch skipped after waiting 30 s for its pipeline") and a count of its own. A worker's build that panics now ends as a failed build (catch_unwind around the job), so whoever waits for it goes on instead of waiting for a done flag nobody sets. Tests: a put-off dispatch of a translated console program whose build ends 400 ms into the submit, with a 50 ms budget and the pipeline already late, has its store and the Write64 after it in the list reach memory (without the change the label is written and the store is not); a submit's wait for a late pipeline no worker can start builds it itself; a submit waits for a worker's build no longer than its bound and counts it; a panicking build ends as failed. --- crates/xcl/src/hle/d3d12x/bind.rs | 15 ++ crates/xcl/src/hle/d3d12x/list_x.rs | 147 +++++++++++++++++- crates/xcl/src/hle/d3d12x/pso_async.rs | 200 ++++++++++++++++++++++++- 3 files changed, 359 insertions(+), 3 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs index 3f31c48b43..25eaee367b 100644 --- a/crates/xcl/src/hle/d3d12x/bind.rs +++ b/crates/xcl/src/hle/d3d12x/bind.rs @@ -126,6 +126,12 @@ pub(super) fn want_bound(this: *mut c_void) { super::pso_async::want(with(this, |s| s.pso)); } +/// A submit records a put-off call of `this`: it waits until the pipeline `this` has bound is +/// built (`pso_async::wait_for_submit`). +pub(super) fn wait_for_bound(this: *mut c_void) { + super::pso_async::wait_for_submit(with(this, |s| s.pso)); +} + /// A put-off dispatch that could not be recorded. pub(super) fn dispatch_dropped() { count(DISPATCHES_SKIPPED); @@ -1068,6 +1074,15 @@ pub(super) fn last_draw_args() -> (bool, u32, u32, u32, i32) { DRAW_ARGS.with(|d| d.get()) } +/// `list`'s compute arguments without a title root signature: `args` is the whole argument table. +#[cfg(test)] +pub(super) fn set_args_for_test(list: *mut c_void, args: Vec) { + with(list, |s| { + s.layout = None; + s.args = args; + }); +} + #[cfg(test)] pub(super) fn counts_snapshot() -> [u64; 5] { std::array::from_fn(|k| COUNTS[k].load(Ordering::Relaxed)) diff --git a/crates/xcl/src/hle/d3d12x/list_x.rs b/crates/xcl/src/hle/d3d12x/list_x.rs index ee544dec22..0dccab1a97 100644 --- a/crates/xcl/src/hle/d3d12x/list_x.rs +++ b/crates/xcl/src/hle/d3d12x/list_x.rs @@ -2664,7 +2664,8 @@ pub(super) unsafe fn defer(list: *mut c_void, what: Deferred) -> bool { /// Builds of a submit's put-off calls that go on without the commit headroom, as a title thread's own do: about what the title's threads had in the driver at once before. const WANTED_AT_ONCE: usize = 4; -/// Records the deferred dispatches of `wrapper`'s recording, waiting for their pipelines as a bind did. +/// Records the deferred dispatches of `wrapper`'s recording, each once its pipeline is built +/// (`pso_async::wait_for_submit`: not bounded by `XCL_PSO_WAIT_MS`). pub(super) unsafe fn record_deferred(wrapper: *mut c_void) { let mut segs = Vec::new(); super::title_list::push_segments(wrapper, &mut segs); @@ -2706,6 +2707,7 @@ pub(super) unsafe fn record_deferred(wrapper: *mut c_void) { super::bind::pass_arena(last, seg); real::dispatch_chain::list_follows(last as usize, seg as usize); } + super::bind::wait_for_bound(seg); match what { Deferred::Dispatch(x, y, z) => super::bind::dispatch(seg, x, y, z), Deferred::Indirect(sig, max, args, args_off, count_buf, count_off) => super::bind::execute_indirect(seg, sig, max, args, args_off, count_buf, count_off), @@ -7079,6 +7081,149 @@ mod tests { } } + /// With `XCL_PSO_WAIT_MS`, a dispatch put off to the submit whose pipeline is built after the + /// budget (and that a bind already found `late`) is recorded with the built pipeline: its + /// output is written, as is the `Write64` after it in the list. Before, the submit's bind gave + /// up after the budget and left the dispatch out while the label still fired. + #[test] + fn a_put_off_dispatch_runs_at_the_submit_when_its_build_outlasts_the_wait_budget() { + use super::super::{bind, pso_async, title_list}; + use crate::gpu::recomp::runner; + use crate::gpu::xbox::tests::{fssm, sample}; + use std::time::{Duration, Instant}; + + if crate::gpu::recomp::dxc::location().is_err() { + return runner::skip_test("no DXC"); + } + if super::super::backend() != super::super::Backend::Real { + return runner::skip_test("no GPU"); + } + if runner::wave64_programs_supported() != Ok(true) { + return runner::skip_test("no wave64"); + } + if real::uma_window_vas().is_empty() { + return runner::skip_test("no unified memory on the GPU"); + } + const MARK: u32 = 0x600D_F00D; + const LABEL: u64 = 0x1AB_E15E_7000_0001; + unsafe { + let raw = real::device_raw(); + let dev = ID3D12Device::from_raw_borrowed(&raw).unwrap().clone(); + // s[0:1]: the argument table; its first 8 bytes say where the program stores MARK + let code: Vec = [ + ("S_LOAD_DWORDX2", "ENC_SMEM", &[("SDATA", 4), ("SBASE", 0), ("OFFSET", 0), ("SOFFSET", 0x7D)][..], None), + ("S_WAITCNT", "ENC_SOPP", &[("SIMM16", 0)][..], None), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 2), ("SRC0", 4)][..], None), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 3), ("SRC0", 5)][..], None), + ("V_MOV_B32", "ENC_VOP1", &[("VDST", 1), ("SRC0", 255)][..], Some(MARK)), + ("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 2), ("DATA", 1), ("SADDR", 0x7D)][..], None), + ("S_ENDPGM", "ENC_SOPP", &[][..], None), + ] + .iter() + .flat_map(|(n, e, f, l)| crate::gpu::rdna2::encode(n, e, f, *l).unwrap_or_else(|x| panic!("{n}: {x}"))) + .collect(); + let mut f = fssm(&code, &[(6, 1)]); + // COMPUTE_PGM_RSRC2 (2 user SGPRs) and numthreads + for (k, x) in [2u32 << 1, 64, 1, 1].into_iter().enumerate() { + f[0x138 + 4 * k..0x13C + 4 * k].copy_from_slice(&x.to_le_bytes()); + } + let blob = sample(5, &[f]); + let game_rs: ID3D12RootSignature = { + let mut ser = None; + D3D12SerializeRootSignature(&D3D12_ROOT_SIGNATURE_DESC::default(), D3D_ROOT_SIGNATURE_VERSION_1, &mut ser, None).unwrap(); + let ser = ser.unwrap(); + dev.CreateRootSignature(0, std::slice::from_raw_parts(ser.GetBufferPointer() as *const u8, ser.GetBufferSize())).unwrap() + }; + let mut desc = D3D12_COMPUTE_PIPELINE_STATE_DESC { + pRootSignature: std::mem::ManuallyDrop::new(Some(game_rs)), + CS: D3D12_SHADER_BYTECODE { pShaderBytecode: blob.as_ptr() as _, BytecodeLength: blob.len() }, + ..Default::default() + }; + let made: windows::core::Result = dev.CreateComputePipelineState(&desc); + std::mem::ManuallyDrop::drop(&mut desc.pRootSignature); + let made = made.expect("CreateComputePipelineState through the backend hook"); + let built = pso_async::resolve_wait(made.as_raw() as usize); + assert!(real::is_translated_compute(built), "not translated: {:?}", real::stats().translation_errors); + + // the title's pipeline: a stand-in whose build ends once the submit has begun + let standin = 0x7E57_D0F1usize; + static BUILD: AtomicBool = AtomicBool::new(false); + BUILD.store(false, Ordering::Release); + pso_async::submit( + standin, + true, + Box::new(move || { + let t = Instant::now(); + while !BUILD.load(Ordering::Acquire) && t.elapsed() < Duration::from_secs(10) { + std::thread::sleep(Duration::from_millis(5)); + } + ID3D12PipelineState::from_raw_borrowed(&(built as *mut c_void)).unwrap().clone().into_raw() as usize + }), + ); + pso_async::set_wait_budget_for_test(Some(Duration::from_millis(50))); + assert_eq!(pso_async::resolve_wait(standin), standin, "a bind as the title records: past the budget, late"); + + let u = crate::gpu::uma::get().unwrap(); + let out = u.alloc(256, 256).unwrap(); + std::ptr::write_bytes(out, 0, 256); + let label = out.add(64) as *mut u64; + + let ty = D3D12_COMMAND_LIST_TYPE_DIRECT; + let alloc: ID3D12CommandAllocator = dev.CreateCommandAllocator(ty).unwrap(); + let a = alloc.as_raw() as usize; + let pc0 = real::create_raw_pc_command_list(raw, ty, a, 0).expect("a PC command list"); + on_create(pc0, a, 0, ty); + bind::reset(pc0, a, standin); + let wrap = title_list::wrap(pc0); + bind::set_args_for_test(pc0, (out as u64).to_le_bytes().to_vec()); + + bind::dispatch(pc0, 1, 1, 1); + let mut segs = Vec::new(); + assert!(title_list::push_segments(wrap, &mut segs)); + assert_eq!(segs.len(), 3, "the dispatch was not put off"); + write64_bottom_x(*segs.last().unwrap(), label as u64, LABEL, 0, 0); + 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); + + let build = std::thread::spawn(|| { + std::thread::sleep(Duration::from_millis(400)); + BUILD.store(true, Ordering::Release); + }); + let t = Instant::now(); + record_deferred(wrap); + let took = t.elapsed(); + pso_async::set_wait_budget_for_test(None); + build.join().unwrap(); + + let queue: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC { Type: ty, ..Default::default() }).unwrap(); + let done: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap(); + segs.clear(); + assert!(title_list::push_segments(wrap, &mut segs)); + type ExecFn = unsafe extern "system" fn(*mut c_void, u32, *const *mut c_void); + let q = queue.as_raw(); + let exec: ExecFn = if real::is_adopted(q) { + std::mem::transmute(real::orig_fn(q, PC_QUEUE_EXECUTE_COMMAND_LISTS)) + } else { + std::mem::transmute(*(*(q as *const *const usize)).add(PC_QUEUE_EXECUTE_COMMAND_LISTS)) + }; + exec(q, segs.len() as u32, segs.as_ptr()); + queue.Signal(&done, 1).unwrap(); + crate::gpu::fence::wait(&done, 1, &dev, None, 5000).expect("the list runs"); + let (mark, labelled) = (std::ptr::read_volatile(out as *const u32), std::ptr::read_volatile(label)); + let removed = dev.GetDeviceRemovedReason(); + + let rel_fn: unsafe extern "system" fn(*mut c_void) -> u32 = std::mem::transmute(*(*(wrap as *const *const usize)).add(2)); + rel_fn(wrap); + pso_async::release(pso_async::released(standin)); + drop(made); + + assert!(removed.is_ok()); + assert_eq!(labelled, LABEL, "the Write64 after the dispatch"); + assert_eq!(mark, MARK, "the put-off dispatch was left out (the submit waited {took:?})"); + assert!(took >= Duration::from_millis(300), "the submit did not wait for the build ({took:?})"); + } + } + /// Reproduces the exact intra-list fork-join pattern seen on retail compute queues: /// q_compute list O_c: Write64(cell_A, frame) -> Wait64(cell_B >= frame) -> Write64(cell_C, frame) /// q_direct list O_d: Wait64(cell_A >= frame) -> Write64(cell_B, frame) diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs index 63d62a7df4..daa755866c 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -79,7 +79,8 @@ fn build(p: &Arc, job: Job, preload: bool) { unsafe { SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL) }; } } - complete(p, job()); + // (a panic in a build ends it as a failed one: whoever waits for it is not left waiting) + complete(p, std::panic::catch_unwind(std::panic::AssertUnwindSafe(job)).unwrap_or(0)); if preload { // (under the lock: `want` does not raise this thread after it) let mut d = p.demand.lock().unwrap(); @@ -914,6 +915,112 @@ mod used_tests { calls.end(5, 9, t_stale); } + /// With `XCL_PSO_WAIT_MS`, a submit's wait for a late pipeline that no worker can start (all + /// are busy) neither ends with the stand-in nor waits for a free worker: after the budget it + /// builds the pipeline itself. + #[test] + fn a_submit_builds_a_late_pipeline_no_worker_has_started() { + let _sat = WORKER_SATURATION_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + use std::time::{Duration, Instant}; + let n = crate::gpu::recomp::dxc::compile_threads(); + let (started_tx, started_rx) = mpsc::channel(); + let gate = Arc::new((Mutex::new(false), Condvar::new())); + let mut blockers = Vec::with_capacity(n); + for k in 0..n { + let standin = 0x7E57_A500usize + k; + let (tx, g) = (started_tx.clone(), gate.clone()); + submit(standin, false, Box::new(move || { + let _ = tx.send(()); + let mut open = g.0.lock().unwrap(); + while !*open { + open = g.1.wait(open).unwrap(); + } + 0xA500 + k + })); + blockers.push(standin); + } + for _ in 0..n { + started_rx.recv_timeout(Duration::from_secs(10)).expect("workers saturated"); + } + let target = 0x7E57_A5FFusize; + submit(target, true, Box::new(|| 0xA5FF)); + set_wait_budget_for_test(Some(Duration::from_millis(30))); + assert_eq!(resolve_wait(target), target, "a bind as the title records: past the budget, late"); + let t = Instant::now(); + wait_for_submit(target); + let took = t.elapsed(); + set_wait_budget_for_test(None); + let built = resolve(target); + *gate.0.lock().unwrap() = true; + gate.1.notify_all(); + for standin in blockers { + let start = Instant::now(); + while is_pending(standin) && start.elapsed() < Duration::from_secs(10) { + std::thread::sleep(Duration::from_millis(2)); + } + let _ = released(standin); + } + let _ = released(target); + assert_eq!(built, 0xA5FF, "the submit's wait ended without the pipeline"); + assert!(took < Duration::from_secs(5), "the submit waited for a free worker ({took:?})"); + } + + /// With `XCL_PSO_WAIT_MS`, a submit waits for a pipeline a worker is building at most + /// `SUBMIT_WAIT_MOST`, then goes on (with the stand-in) and counts it. + #[test] + fn a_submit_waits_for_a_build_on_a_worker_no_longer_than_its_bound() { + let _sat = WORKER_SATURATION_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + use std::time::{Duration, Instant}; + let standin = 0x7E57_A600usize; + let (started_tx, started_rx) = mpsc::channel(); + let gate = Arc::new((Mutex::new(false), Condvar::new())); + let g = gate.clone(); + submit(standin, true, Box::new(move || { + let _ = started_tx.send(()); + let mut open = g.0.lock().unwrap(); + while !*open { + open = g.1.wait(open).unwrap(); + } + 0xA600 + })); + started_rx.recv_timeout(Duration::from_secs(10)).expect("a worker builds it"); + set_wait_budget_for_test(Some(Duration::from_millis(20))); + set_submit_wait_for_test(Some(Duration::from_millis(300))); + let gave_up = SUBMIT_GAVE_UP.load(Ordering::Relaxed); + let t = Instant::now(); + wait_for_submit(standin); + let took = t.elapsed(); + let pending = is_pending(standin); + let counted = SUBMIT_GAVE_UP.load(Ordering::Relaxed) > gave_up; + set_wait_budget_for_test(None); + set_submit_wait_for_test(None); + *gate.0.lock().unwrap() = true; + gate.1.notify_all(); + let start = Instant::now(); + while is_pending(standin) && start.elapsed() < Duration::from_secs(10) { + std::thread::sleep(Duration::from_millis(2)); + } + let _ = released(standin); + assert!(pending, "the build ended before the bound"); + assert!(took >= Duration::from_millis(300) && took < Duration::from_secs(5), "the submit waited {took:?}"); + assert!(counted, "the submit that went on without its pipeline was not counted"); + } + + /// A build that panics on a worker ends as a failed one: binds and submits waiting for it go on. + #[test] + fn a_build_that_panics_on_a_worker_ends_as_failed() { + use std::time::{Duration, Instant}; + let standin = 0x7E57_A700usize; + submit(standin, true, Box::new(|| panic!("a build that panics (test)"))); + let start = Instant::now(); + while is_pending(standin) && start.elapsed() < Duration::from_secs(10) { + std::thread::sleep(Duration::from_millis(2)); + } + let pending = is_pending(standin); + let _ = released(standin); + assert!(!pending, "the panicked build never ended"); + } + #[test] fn released_queued_pipeline_drops_job_immediately_before_workers_drain() { let _sat = WORKER_SATURATION_LOCK.lock().unwrap_or_else(|e| e.into_inner()); @@ -1070,6 +1177,78 @@ pub fn resolve_wait(pso: usize) -> usize { resolve_wait_for(pso, wait_budget()) } +/// A call put off to the submit is recorded now: wait for its compute pipeline to be built, +/// whether a bind already found it `late` or not. Its segment lies between the list's other work, +/// whose labels and fence signals the title reads as "done": recorded with the stand-in, the +/// dispatch is left out while they still fire. The submitting thread is held for that time +/// (`title_held`), as a bind's wait holds it. A build that fails still gives the stand-in, and a +/// program binds do not wait for (`image_only`) is not waited for. +/// +/// Unset `XCL_PSO_WAIT_MS`: until the pipeline is built, as a bind waits. Set: the build is left +/// to the workers for that long first, as a bind leaves it (their turns for big compiles); one no +/// worker has started by then is built here. One a worker builds is waited for at most +/// `SUBMIT_WAIT_MOST`, and the call then goes on with the stand-in (logged and counted): +/// `title_held` stops only `kernelx::Sleep` and the GPU-wait watchdog, not every clock a title +/// reads. +pub fn wait_for_submit(pso: usize) { + let Some(budget) = wait_budget() else { + let _ = resolve_wait_for(pso, None); + return; + }; + let Some(p) = entry(pso) else { return }; + if !p.compute || p.spared.load(Ordering::Acquire) || *p.done.lock().unwrap() { + return; + } + p.note_use(); + let _held = Held::new(); + if !p.sent.swap(true, Ordering::AcqRel) { + enqueue(p.clone()); + } + p.want(); + let built = |p: &Pending, most: std::time::Duration| *p.cv.wait_timeout_while(p.done.lock().unwrap(), most, |d| !*d).unwrap().0; + if built(&p, budget) { + return; + } + // no worker has started it: built here, as without the budget + let job = p.job.lock().unwrap().take(); + if let Some(job) = job { + return complete(&p, job()); + } + let most = submit_wait_most(); + if !built(&p, most) { + let n = SUBMIT_GAVE_UP.fetch_add(1, Ordering::Relaxed) + 1; + if n <= 16 || n.is_power_of_two() { + crate::xlog_warn!("D3D12.X: deferred dispatch skipped after waiting {} s for its pipeline ({n} so far)", most.as_secs_f32()); + } + } +} + +/// put-off calls that went on with the stand-in after `SUBMIT_WAIT_MOST` +static SUBMIT_GAVE_UP: AtomicUsize = AtomicUsize::new(0); + +/// How long a submit waits for a pipeline a worker builds, with `XCL_PSO_WAIT_MS` set: as long as +/// a retail title's watchdog lets its main thread stand still (30 s, #891). +const SUBMIT_WAIT_MOST: std::time::Duration = std::time::Duration::from_secs(30); + +fn submit_wait_most() -> std::time::Duration { + #[cfg(test)] + if let Some(b) = SUBMIT_WAIT_FOR_TEST.with(|b| b.get()) { + return b; + } + SUBMIT_WAIT_MOST +} + +#[cfg(test)] +thread_local! { + /// `SUBMIT_WAIT_MOST` for the submits of this test thread + static SUBMIT_WAIT_FOR_TEST: std::cell::Cell> = const { std::cell::Cell::new(None) }; +} + +#[cfg(test)] +fn set_submit_wait_for_test(most: Option) { + SUBMIT_WAIT_FOR_TEST.with(|b| b.set(most)); +} + /// `resolve_wait`, waiting at most `budget` (None: until the pipeline is built). fn resolve_wait_for(pso: usize, budget: Option) -> usize { let Some(p) = entry(pso) else { return pso }; @@ -1100,12 +1279,29 @@ fn resolve_wait_for(pso: usize, budget: Option) -> usize { /// How long a bind waits for a pipeline still being built (`XCL_PSO_WAIT_MS`; unset or 0: until /// it is built). A retail game builds compute programs on its own threads: the driver takes up to /// 30 s for the biggest translated ones, and the title's watchdog ends it when its main thread -/// has been held 30 s. +/// has been held 30 s. It bounds binds as the title records; a call put off to the submit waits +/// there until its pipeline is built (`wait_for_submit`). fn wait_budget() -> Option { + #[cfg(test)] + if let Some(b) = BUDGET_FOR_TEST.with(|b| b.get()) { + return Some(b); + } static B: OnceLock> = OnceLock::new(); *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)) } +#[cfg(test)] +thread_local! { + /// `XCL_PSO_WAIT_MS` for the binds of this test thread + static BUDGET_FOR_TEST: std::cell::Cell> = const { std::cell::Cell::new(None) }; +} + +/// Binds on this thread wait at most `budget` (None: as `XCL_PSO_WAIT_MS` says). +#[cfg(test)] +pub(super) fn set_wait_budget_for_test(budget: Option) { + BUDGET_FOR_TEST.with(|b| b.set(budget)); +} + /// `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. From 60349e51011d8fd4295c00776b2617b229b32d27 Mon Sep 17 00:00:00 2001 From: grahamster2 <128315603+grahamster2@users.noreply.github.com> Date: Wed, 25 Nov 2026 20:02:17 -0500 Subject: [PATCH 2/2] D3D12.X: list_x tests drop the allocator types they leave in alloc_pool The put-off dispatch test forgets its allocator, and the two older tests that reset an allocator at a reused address (mid_list_write64_wait64_split, cross_queue_cycle) forget theirs before use, so a stale type left by another test no longer makes them reset a compute list on a direct allocator. --- crates/xcl/src/hle/d3d12x/list_x.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/xcl/src/hle/d3d12x/list_x.rs b/crates/xcl/src/hle/d3d12x/list_x.rs index 0dccab1a97..3b754028a6 100644 --- a/crates/xcl/src/hle/d3d12x/list_x.rs +++ b/crates/xcl/src/hle/d3d12x/list_x.rs @@ -6257,6 +6257,9 @@ mod tests { let da: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap(); let ca1: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE).unwrap(); let ca2: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE).unwrap(); + for a in [&da, &ca1, &ca2] { + super::super::alloc_pool::forget(a.as_raw() as usize); + } let dl: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &da, None).unwrap(); let cl1: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, &ca1, None).unwrap(); let cl2: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, &ca2, None).unwrap(); @@ -7216,6 +7219,9 @@ mod tests { rel_fn(wrap); pso_async::release(pso_async::released(standin)); drop(made); + // the allocator's type must not outlive the test: a stale one makes a later list_x test + // reset a compute list on a direct backing allocator + super::super::alloc_pool::forget(alloc.as_raw() as usize); assert!(removed.is_ok()); assert_eq!(labelled, LABEL, "the Write64 after the dispatch"); @@ -7256,6 +7262,9 @@ mod tests { let q_dir: ID3D12CommandQueue = dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC { Type: D3D12_COMMAND_LIST_TYPE_DIRECT, ..Default::default() }).unwrap(); let a_comp: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE).unwrap(); let a_dir: ID3D12CommandAllocator = dev.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT).unwrap(); + // a freed allocator of an earlier test may have had these addresses: drop its stale type + super::super::alloc_pool::forget(a_comp.as_raw() as usize); + super::super::alloc_pool::forget(a_dir.as_raw() as usize); let raw_c: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, &a_comp, None).unwrap(); let raw_d: ID3D12GraphicsCommandList = dev.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &a_dir, None).unwrap(); let done_c: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).unwrap();