From 033a6d1fdf5ecb62fa45a6e865601c20ca53012d Mon Sep 17 00:00:00 2001 From: Kalmarv <59708937+Kalmarv@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:13:01 -0500 Subject: [PATCH] Recompiler: preserve the FSPX compute user SGPR count --- crates/xcl/src/gpu/recomp/mod.rs | 8 ++++++-- crates/xcl/src/gpu/recomp/pso.rs | 14 +++++--------- crates/xcl/src/gpu/recomp/tests.rs | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/crates/xcl/src/gpu/recomp/mod.rs b/crates/xcl/src/gpu/recomp/mod.rs index 30c33e9..34ac919 100644 --- a/crates/xcl/src/gpu/recomp/mod.rs +++ b/crates/xcl/src/gpu/recomp/mod.rs @@ -226,13 +226,17 @@ impl CsInterface { if threads.iter().any(|&t| t == 0 || t > 1024) || threads.iter().product::() > 1024 { return None; } - Some(CsInterface { + Some(Self::from_rsrc2(threads, r)) + } + + fn from_rsrc2(threads: [u32; 3], r: u32) -> Self { + Self { threads, user_sgprs: (r >> 1) & 31, tgid: [(r >> 7) & 1 == 1, (r >> 8) & 1 == 1, (r >> 9) & 1 == 1], tg_size: (r >> 10) & 1 == 1, tid_components: ((r >> 11) & 3) + 1, - }) + } } } diff --git a/crates/xcl/src/gpu/recomp/pso.rs b/crates/xcl/src/gpu/recomp/pso.rs index d8b692f..08abf60 100644 --- a/crates/xcl/src/gpu/recomp/pso.rs +++ b/crates/xcl/src/gpu/recomp/pso.rs @@ -431,10 +431,13 @@ fn cache_allowed(stage: Stage, present: impl Fn(&str) -> bool) -> bool { .any(|name| present(name))) } -/// User SGPRs of a console compute shader (COMPUTE_PGM_RSRC2 in its FSSM stage descriptor): +/// User SGPRs of a console compute shader (COMPUTE_PGM_RSRC2 in FSPX or FSSM): /// s0…s3 are the driver's, so what is above 4 is the root arguments its compiler passed in /// registers. None: not a console compute shader. pub fn compute_user_sgprs(blob: &[u8]) -> Option { + if let Some(f) = fspx(blob) { + return Some(super::CsInterface::from_rsrc2(f.threads, f.rsrc2).user_sgprs); + } let sh = xbox::parse(blob)?; let f = sh.fssm.iter().find(|f| f.stages.first().is_some_and(|s| s.hw == 6))?; match interface(blob, &sh, f)? { @@ -448,14 +451,7 @@ fn console_translation(blob: &[u8], stage: Stage, sampler_base: u32, windows: u3 if stage != Stage::Compute { return Err("an FSPX (driver) container in a graphics slot".into()); } - let r = f.rsrc2; - let cs = super::CsInterface { - threads: f.threads, - user_sgprs: (r >> 1) & 31, - tgid: [(r >> 7) & 1 == 1, (r >> 8) & 1 == 1, (r >> 9) & 1 == 1], - tg_size: (r >> 10) & 1 == 1, - tid_components: ((r >> 11) & 3) + 1, - }; + let cs = super::CsInterface::from_rsrc2(f.threads, f.rsrc2); let t = translate(f.code, &Options { mode: Mode::Compute(cs), wave64: super::detect_wave64(f.code), split_wave64, static_sampler_base: sampler_base, mem_windows: windows, ..Default::default() })?; if !t.complete() { let missing: Vec<&String> = t.unsupported.keys().collect(); diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index e609a34..af7efef 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -6835,6 +6835,29 @@ fn gpu_sdwa_f16_inline_constants() { } } +#[test] +fn fspx_compute_user_sgprs_from_rsrc2() { + use crate::gpu::xbox::tests::container; + + let counts = [4u32, 8].map(|count| { + // Two directory entries: type 0 holds the compute registers, type 6 holds the code. + let mut part = Vec::from(*b"FSPX"); + for word in [1u32, 2, 0x74, 0, 0x30, 0x1c, 0, 6, 0x4c, 0x28, 0] { + part.extend_from_slice(&word.to_le_bytes()); + } + part.resize(0x74, 0); + let header = &mut part[0x30..0x4c]; + header[0x0c..0x12].copy_from_slice(&[1, 0, 1, 0, 1, 0]); // numthreads(1, 1, 1) + let rsrc2 = (count << 1) | 0x81; // set unrelated bits on both sides of USER_SGPR + header[0x18..0x1c].copy_from_slice(&rsrc2.to_le_bytes()); + part[0x70..].copy_from_slice(&0xbf81_0000u32.to_le_bytes()); // s_endpgm + let blob = container(&[(b"ACCC", &part)]); + assert_eq!(super::pso::fspx(&blob).unwrap().rsrc2, rsrc2); + super::pso::compute_user_sgprs(&blob) + }); + assert_eq!(counts, [Some(4), Some(8)]); +} + /// `XCL_SAMPLE_FSPX=`: every `*.bin` there that is an FSPX (driver) compute container – /// e.g. the FSR4 pipelines XCL dumps to `\shaders` – translates and compiles. #[test]