From c1e6807941d8951c111900b14cce7cef2c2543c6 Mon Sep 17 00:00:00 2001 From: joeypercia <81598667+joeypercia@users.noreply.github.com> Date: Wed, 25 Nov 2026 03:18:27 -0800 Subject: [PATCH] Recompiler: direct DXIL geometry shaders read ES inputs from window 0's heap view With the memory windows in the descriptor heap (XCL_HEAP_WINDOWS=1), `mems` holds placeholders whose handle is the constant 0, and only counts the windows. The GS entry (`geom_init`) loaded the ES outputs it reads (v9..) through `mems[0]` directly, so the raw load took an i32 as its handle. The DXIL builder refuses that ("function dx.op.rawBufferLoad.i32 redeclared with another type"), and the direct route gives up on the shader. On the newer retail title's shader pack that is 158 of its 390 geometry shaders (`xcl shaders --direct --sample 0 --windows 260`): 232 translated before, 390 now, all of them validating. Window 0 now comes from the heap (`MEM_HEAP_BASE`), as every other access takes it in this mode. --- crates/xcl/src/gpu/dxil/geometry_tests.rs | 17 +++++++++++++++++ crates/xcl/src/gpu/dxil/kernel.rs | 9 ++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/gpu/dxil/geometry_tests.rs b/crates/xcl/src/gpu/dxil/geometry_tests.rs index 57d4cce9a9..e11e3963cc 100644 --- a/crates/xcl/src/gpu/dxil/geometry_tests.rs +++ b/crates/xcl/src/gpu/dxil/geometry_tests.rs @@ -88,6 +88,23 @@ fn geometry_forms_validate() { } } +/// A GS that reads its ES inputs (v9..) translates with the windows in the descriptor heap: +/// `mems` only counts them there, the inputs come from window 0's view in the heap. +#[test] +fn geometry_inputs_with_heap_windows_validate() { + let (mut code, mut g) = branchy_program(); + // v53 = v9 (input 0, x) before the GS ends: the inputs are fetched + let end = code.len() - 8; + let mv = encode("V_MOV_B32", "ENC_VOP1", &[("VDST", 53), ("SRC0", 256 + 9)], None).unwrap(); + code.splice(end..end, mv); + g.es_inputs = vec![sig("TEXCOORD", 0, 0, 3)]; + for split in [false, true] { + for windows in [1, 4, 4 | crate::gpu::recomp::HEAP_WINDOWS] { + translate_geometry(&code, opts(split, windows), &g).unwrap_or_else(|e| panic!("split {split}, windows {windows:#x}: {e}")); + } + } +} + /// The records of `branchy_program` for `prims` primitives: (group, record dwords). fn expected_records(g: &GsInterface, prims: usize) -> Vec { let rec = g.record(); diff --git a/crates/xcl/src/gpu/dxil/kernel.rs b/crates/xcl/src/gpu/dxil/kernel.rs index 8687e4807a..f140f4dde4 100644 --- a/crates/xcl/src/gpu/dxil/kernel.rs +++ b/crates/xcl/src/gpu/dxil/kernel.rs @@ -823,7 +823,14 @@ fn geom_init(lw: &mut Lw, g: &GsInterface, _tid: Value, io: super::shader::RawUa let nreg = g.input_registers(); let fetched = fetched_registers(&g.es_inputs); let in_nv = lw.cmp(Pred::ULt, lane, nv); - let mem = lw.mems[0]; + // window 0; with the windows in the descriptor heap `mems` only counts them (`mem_windows`) + let mem = match lw.heap_mem { + Some(coherent) => { + let i = lw.c(crate::gpu::recomp::MEM_HEAP_BASE); + lw.s.heap_raw_buffer_uav(i, coherent) + } + None => lw.mems[0], + }; for &v in used.iter().filter(|&&v| (9..256).contains(&v)) { let k = ((v - 9) / 4) as usize; if k >= fetched.len() || fetched[k] >= nreg {