This commit is contained in:
ivall
2026-11-23 22:20:32 +01:00
3 changed files with 34 additions and 11 deletions
+6 -2
View File
@@ -226,13 +226,17 @@ impl CsInterface {
if threads.iter().any(|&t| t == 0 || t > 1024) || threads.iter().product::<u32>() > 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,
})
}
}
}
+5 -9
View File
@@ -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<u32> {
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();
+23
View File
@@ -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=<folder>`: every `*.bin` there that is an FSPX (driver) compute container –
/// e.g. the FSR4 pipelines XCL dumps to `<data>\shaders` – translates and compiles.
#[test]