From 0364b388c60719f24e9043321f2c162e87a4ef5d Mon Sep 17 00:00:00 2001 From: Raul Paiva <63853678+Raul-Paiva@users.noreply.github.com> Date: Sat, 28 Nov 2026 12:05:39 +0000 Subject: [PATCH] D3D12.X: two-pass stages never bind a memory window at GPU VA 0 prepare_two_pass_stage bound windows 1-3 with `uma_window_va(k).unwrap_or(first)`. uma_window_va returns Some(0) for a window without a buffer on the GPU (real.rs starts every window at 0 and only committed or sparse windows get one), so such a window was bound as a null root UAV. Direct DXIL compute reads every window slot (with_mem_raw_loads), and the two-pass compute pass is one of those shaders, so the read goes to GPU VA 0: a page fault and a device removal. 4a69d806 added the window 0 check (first_window) but not the `!= 0` filter that bind_abi has had since c685e122. amd-dev has the same filter in its two-pass bind (0e19dc1d). window_view() now holds the lookup, and both binds use it. Co-Authored-By: Claude Opus 5.5 --- crates/xcl/src/hle/d3d12x/bind.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs index 0c064f8f93..9f7b996392 100644 --- a/crates/xcl/src/hle/d3d12x/bind.rs +++ b/crates/xcl/src/hle/d3d12x/bind.rs @@ -3105,7 +3105,7 @@ unsafe fn prepare_two_pass_stage( if pso == 0 { return Err(if compute_pass { "two-pass compute pipeline" } else { "two-pass mesh pipeline" }.into()); } - let w = |k: usize| super::real::uma_window_va(k).unwrap_or(first); + let w = |k: usize| window_view(super::real::uma_window_va(k), first); Ok(StageBind { rs, pso, views: [va(io_at), res_va, w(0), w(1), w(2), w(3)] }) } @@ -5051,6 +5051,14 @@ fn first_window(window0: Option, shadowed: bool) -> Result { Ok(first) } +/// The root view a bind on XCL's ABI gives memory window `k` (`window`: `real::uma_window_va(k)`): +/// its buffer, or `first` when it has none (no window, or no buffer on the GPU: 0). Direct DXIL +/// compute reads every window slot (`with_mem_raw_loads`), so a null root view is a read of GPU +/// VA 0, a page fault that removes the device. +fn window_view(window: Option, first: u64) -> u64 { + window.filter(|&v| v != 0).unwrap_or(first) +} + /// Whether dispatches pass `recomp::dispatch_loop_budget` (`XCL_DISPATCH_LOOP_BUDGET=0`, read /// once: they leave `IO_LOOP_BUDGET` at 0 and every loop has the lane's 65 536 passes in both /// translators, as before, to compare). Here, not in `recomp`: that module's source is part of @@ -5286,7 +5294,7 @@ unsafe fn bind_abi_with_root_resolved( views[1] = va(res_at); // (every window slot gets a buffer: direct DXIL compute reads all four, `with_mem_raw_loads`) for k in 0..4 { - views[2 + k] = super::real::uma_window_va(k).filter(|&v| v != 0).unwrap_or(first); + views[2 + k] = window_view(super::real::uma_window_va(k), first); } let pc = ID3D12PipelineState::from_raw_borrowed(&(pso as *mut c_void)).ok_or("pipeline")?.clone(); let b = Bound { rs, views, original, pso: pc, io: views[0], allocator }; @@ -7944,6 +7952,16 @@ void main(uint t : SV_GroupIndex) { assert_eq!(first_window(Some(0x7_0000_0000), true), Ok(0x7_0000_0000)); } + /// A window without a buffer on the GPU (address 0) gets window 0's buffer in both binds on + /// XCL's ABI (`bind_abi` and the two-pass stages), never a null root view. + #[test] + fn windows_without_a_buffer_take_window_0() { + let first = 0x7_0000_0000; + assert_eq!(window_view(Some(0), first), first); + assert_eq!(window_view(None, first), first); + assert_eq!(window_view(Some(0x8_0000_0000), first), 0x8_0000_0000); + } + /// The two passes get the addresses of the heaps set after their arguments, the view heap's /// first, as `bind_abi`'s stages do (`console_list::with_heaps`): for the console's most /// common mesh layout (three tables, a root view, two constants) the compute pass's s23 /