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

Closed
opened 2026-11-22 10:23:28 +00:00 by Trwthh · 1 comment
Trwthh commented 2026-11-22 10:23:28 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by Trwthh on 2026-11-22T10:23:28Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6541247474 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/issues/114). Originally posted by [Trwthh](https://github.com/Trwthh) on 2026-11-22T10:23:28Z. --- ## 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.
omonkeyz commented 2026-11-22 14:05:24 +00:00 (Migrated from github.com)
Author

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T14:05:24Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7080283177 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/issues/114#issuecomment-7080283177). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T14:05:24Z. --- 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.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
omonkeyz/xbox-emulator#114
No description provided.