gcn: MIMG lowering passes TFE/R128/LWE bits through, but RDNA2 reinterprets them as D16/A16/reserved #114

Closed
opened 2026-11-26 06:10:34 +00:00 by github-bot · 1 comment
Owner

@⁠Trwthh on GitHub · 2026-11-22 10:23 UTC · original

Bug

In crates/tombox-xshader/src/gcn.rs:388-391, the GCN MIMG→RDNA2 conversion only clears bit 14 (DA) and injects the dim field. All other control bits are passed through verbatim:

Enc::Mimg => {
    let da = (w >> 14) & 1;
    let dim = if da != 0 { 5 } else { 1 };
    vec![(w & !(1 << 14)) | dim << 3, ins.words[1]]
}

Problem

GCN GFX7 and RDNA2 have different bit semantics at the same positions:

Bit GCN GFX7 RDNA2
14 DA (array) SLC (system-level cache)
15 R128 (256-bit return) A16 (16-bit addresses)
16 TFE (texture fail enable) D16 (16-bit data)
17 LWE (LOD warn enable) Reserved
5:3 Reserved (zero) DIM (dimensionality)

If a GCN shader sets:

  • TFE=1: RDNA2 interprets D16=1, causing the texture load to expect 16-bit data instead of 32-bit, corrupting results
  • R128=1: RDNA2 interprets A16=1, truncating texture coordinates to 16-bit
  • LWE=1: sets a reserved bit, potentially causing undefined GPU behavior

Fix

After clearing DA and writing dim, also clear bits 15, 16, and 17, and handle TFE/R128 appropriately (TFE needs an extra VGPR for the status; R128 affects return width; both are uncommon in Xbox One shaders but valid).

Impact

Medium. TFE and LWE are rare in real shaders, but R128 is used by cubemap samplers on some titles. Any Trackmania or future Xbox One title shader that sets one of these bits will produce silently wrong texture loads.

**@⁠Trwthh** on GitHub · 2026-11-22 10:23 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/114) ## Bug In `crates/tombox-xshader/src/gcn.rs:388-391`, the GCN MIMG→RDNA2 conversion only clears bit 14 (DA) and injects the dim field. All other control bits are passed through verbatim: ```rust Enc::Mimg => { let da = (w >> 14) & 1; let dim = if da != 0 { 5 } else { 1 }; vec![(w & !(1 << 14)) | dim << 3, ins.words[1]] } ``` ### Problem GCN GFX7 and RDNA2 have different bit semantics at the same positions: | Bit | GCN GFX7 | RDNA2 | |-----|----------|-------| | 14 | DA (array) | SLC (system-level cache) | | 15 | R128 (256-bit return) | A16 (16-bit addresses) | | 16 | TFE (texture fail enable) | D16 (16-bit data) | | 17 | LWE (LOD warn enable) | Reserved | | 5:3 | Reserved (zero) | DIM (dimensionality) | If a GCN shader sets: - **TFE=1**: RDNA2 interprets D16=1, causing the texture load to expect 16-bit data instead of 32-bit, corrupting results - **R128=1**: RDNA2 interprets A16=1, truncating texture coordinates to 16-bit - **LWE=1**: sets a reserved bit, potentially causing undefined GPU behavior ### Fix After clearing DA and writing dim, also clear bits 15, 16, and 17, and handle TFE/R128 appropriately (TFE needs an extra VGPR for the status; R128 affects return width; both are uncommon in Xbox One shaders but valid). ### Impact **Medium.** TFE and LWE are rare in real shaders, but R128 is used by cubemap samplers on some titles. Any Trackmania or future Xbox One title shader that sets one of these bits will produce silently wrong texture loads.
github-bot 2026-11-26 06:10:34 +00:00
  • closed this issue
  • added the
    bug
    label
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:10:34 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 14:05 UTC · original

Fix details: d585b945 (batch commit). The bit table in the report does not match RDNA2: R128, TFE and LWE sit at the same dword-0 bits 15/16/17 on GFX7 and on RDNA2. D16 and A16 are dword-1 bits 31/30 (our decoder reads D16 there), and SLC is bit 25. So the lowering never turned TFE into D16 or R128 into A16. But the translator did ignore all three bits. Now both the GFX7->RDNA2 lowering (gcn.rs) and the RDNA2 emitter (emit_mimg) refuse them with a named error. None of the 3515 cached title shaders sets any of them, so no current title changes. Implementing them is tracked in docs/BLOCKERS.md. Tests: mimg_r128_tfe_lwe_are_refused_instead_of_passed_through and image_ops_with_status_or_r128_bits_are_refused. Thanks.

**@⁠omonkeyz** on GitHub · 2026-11-22 14:05 UTC · [original](https://github.com/omonkeyz/xbox-emulator/issues/114#issuecomment-7080283177) Fix details: d585b945 (batch commit). The bit table in the report does not match RDNA2: R128, TFE and LWE sit at the same dword-0 bits 15/16/17 on GFX7 and on RDNA2. D16 and A16 are dword-1 bits 31/30 (our decoder reads D16 there), and SLC is bit 25. So the lowering never turned TFE into D16 or R128 into A16. But the translator did ignore all three bits. Now both the GFX7->RDNA2 lowering (gcn.rs) and the RDNA2 emitter (emit_mimg) refuse them with a named error. None of the 3515 cached title shaders sets any of them, so no current title changes. Implementing them is tracked in docs/BLOCKERS.md. Tests: mimg_r128_tfe_lwe_are_refused_instead_of_passed_through and image_ops_with_status_or_r128_bits_are_refused. Thanks.
This discussion has been locked. Commenting is limited to contributors.
No description provided.