diff --git a/README.md b/README.md index 4d1932d2a..446c79f2f 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,8 @@ next steps: | **Ray tracing** | ✅ | BLAS / TLAS built on the GPU by the game's own XboxBvhBuilder; RDNA2 BVH node format; BVH intersection instructions emulated in shaders | GPU traversal = brute force reference; the game's builder output checked on the GPU | | **Upscaling** | ✅ | the game's AMD FSR 4 console DLL (`amd_fidelityfx_upscaler_xbox.dll`): context, the 29 pipelines in the console driver's own container (FSPX) translated, a frame's 20 passes recorded and run on the GPU | end-to-end with the real DLL: a 1280×720 → 1920×1080 frame on an RX 9070, the input's gradient in the output | +Relative VGPR access accounts for non-sequential image address registers when determining the register range. + ### Media and tools | Feature | State | What it does | Verified by | diff --git a/crates/xcl/src/gpu/rdna2.rs b/crates/xcl/src/gpu/rdna2.rs index 9c60d3d38..d1419a880 100644 --- a/crates/xcl/src/gpu/rdna2.rs +++ b/crates/xcl/src/gpu/rdna2.rs @@ -476,6 +476,16 @@ pub fn vgpr_uses(d: &Decoded) -> (Vec, Vec) { if f == "VADDR" && matches!(d.enc.name, "ENC_MUBUF" | "ENC_MTBUF") { n = field_value(d.enc, &d.words, "IDXEN").unwrap_or(0) + field_value(d.enc, &d.words, "OFFEN").unwrap_or(0); } + if f == "VADDR" && d.enc.name == "ENC_MIMG" { + let nsa = field_value(d.enc, &d.words, "NSA").unwrap_or(0); + if let Some(enc) = encoding(&format!("MIMG_NSA{nsa}")) { + // Include all encoded addresses conservatively, including padding slots. + // The emitter reads these fields instead of a range starting at VADDR. + r.extend(enc.fields.iter().filter(|field| field.name.starts_with("VADDR")) + .filter_map(|field| field_value(enc, &d.words, field.name))); + continue; + } + } let dst = if o.output { &mut w } else { &mut r }; dst.extend(v..v + n); } @@ -748,6 +758,35 @@ mod tests { assert_eq!(decode(&[0xff, 0x03, 0x80, 0xbe], 0).err(), Some(DecodeError::Truncated)); } + #[test] + fn image_nsa_address_registers_are_not_a_contiguous_range() { + for nsa in 1..=3u64 { + let mut bytes = encode("IMAGE_SAMPLE", "ENC_MIMG", + &[("NSA", nsa), ("VADDR", 4), ("VDATA", 16), ("DMASK", 15)], None).unwrap(); + let mut registers: Vec = (0..nsa * 4).map(|i| 100 + i as u8).collect(); + *registers.last_mut().unwrap() = 255; + bytes.extend(®isters); + let d = decode(&bytes, 0).unwrap(); + let (reads, writes) = vgpr_uses(&d); + assert!(reads.contains(&4)); + for ®ister in ®isters { + assert!(reads.contains(&(register as u64)), "NSA{nsa} lost v{register}"); + } + assert_eq!(reads.iter().max(), Some(&255)); + assert!(!reads.contains(&5), "NSA{nsa} invented a sequential address"); + assert_eq!(writes, vec![16, 17, 18, 19]); + } + } + + #[test] + fn image_sequential_address_registers_keep_the_operand_range() { + let bytes = encode("IMAGE_SAMPLE", "ENC_MIMG", + &[("VADDR", 4), ("VDATA", 16), ("DMASK", 15)], None).unwrap(); + let (reads, writes) = vgpr_uses(&decode(&bytes, 0).unwrap()); + assert_eq!(reads, vec![4, 5, 6]); + assert_eq!(writes, vec![16, 17, 18, 19]); + } + /// Normalise an LLVM mnemonic to the AMD spec name (lower case, no encoding suffix). fn llvm_base(m: &str) -> String { let mut s = m.to_ascii_lowercase();