tombox-xshader: translate the remaining 32-bit image atomics and honour GLC #147

Closed
MiguelMatMar wants to merge 1 commit from upstream-pr/147 into main
MiguelMatMar commented 2026-11-22 15:56:31 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by MiguelMatMar on 2026-11-22T15:56:31Z.


Library / area: tombox-xshader (RDNA2 MIMG decoder + HLSL translation). Covers the image-atomic part of #103.

Exports changed (exports.txt rows): none.

Source of the behaviour: opcode numbers from the public GFX10/RDNA2 MIMG opcode table (0x0f swap, 0x10 cmpswap, 0x12 sub, 0x14 smin, 0x15 umin, 0x16 smax, 0x18 and, 0x19 or, 0x1a xor, 0x1b inc, 0x1c dec; 0x11 add and 0x17 umax were already mapped). Operation semantics (cmpswap DATA[0] = src, DATA[1] = cmp; inc/dec wrap rules; GLC returns the pre-op value) from the RDNA2 ISA manual, identical to the MUBUF atomics the translator already implements.

Changes

  • rdna2/mnem.rs: decode the 11 missing 32-bit integer image atomics.
  • hlsl/atomic.rs (new): the Interlocked* / compare-exchange-loop lowering that the MUBUF atomics used inline, keyed by the op suffix. MUBUF atomics now call it, and their output is unchanged (buffer_mubuf and the opcodes string checks still pass).
  • hlsl.rs: image atomics go through the same helper on the RWTexture<uint> texel.
  • Behaviour fix: image atomics wrote the pre-op value back to vdata every time. They now do it only when GLC (MIMG dword0 bit 13) is set, as MUBUF atomics already do. With GLC = 0, vdata keeps its input.
  • A dmask other than 0x1 (0x3 for cmpswap), i.e. a 64-bit image atomic, is now refused with an explicit error instead of being translated as 32-bit.
  • Not covered: the float image atomics (fcmpswap/fmin/fmax 0x1d-0x1f), the 64-bit variants and the _pck loads/stores. They stay unmapped or refused.

Tests

  • New exec_mem::mimg::image_mimg_atomics: 13 mnemonics × 8 operand/compare pairs × GLC on/off (208 cases, each also rerun with runtime inputs). Each case checks the returned vdata, the texel result and two untouched neighbours on an R32_UINT UAV (adds R32_UINT to the exec_mem image helper).

  • Passes on WARP and on hardware (TOMBOX_EXEC_HW=1, NVIDIA).

  • I also checked that the test catches the bug: forcing the old always-write-vdata behaviour makes 52 cases fail.

  • Full cargo test -p tombox-xshader passes. pr_gate.py reports 0 problems.

  • cargo test -p tombox-xshader passes

  • No game or console files and no binaries included

  • No fake success; anything not possible is left missing with a note

🤖 Generated with Claude Code

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6544483425 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/147). Originally posted by [MiguelMatMar](https://github.com/MiguelMatMar) on 2026-11-22T15:56:31Z. --- **Library / area:** `tombox-xshader` (RDNA2 MIMG decoder + HLSL translation). Covers the image-atomic part of #103. **Exports changed (exports.txt rows):** none. **Source of the behaviour:** opcode numbers from the public GFX10/RDNA2 MIMG opcode table (0x0f swap, 0x10 cmpswap, 0x12 sub, 0x14 smin, 0x15 umin, 0x16 smax, 0x18 and, 0x19 or, 0x1a xor, 0x1b inc, 0x1c dec; 0x11 add and 0x17 umax were already mapped). Operation semantics (cmpswap DATA[0] = src, DATA[1] = cmp; inc/dec wrap rules; GLC returns the pre-op value) from the RDNA2 ISA manual, identical to the MUBUF atomics the translator already implements. ### Changes - `rdna2/mnem.rs`: decode the 11 missing 32-bit integer image atomics. - `hlsl/atomic.rs` (new): the Interlocked* / compare-exchange-loop lowering that the MUBUF atomics used inline, keyed by the op suffix. MUBUF atomics now call it, and their output is unchanged (`buffer_mubuf` and the `opcodes` string checks still pass). - `hlsl.rs`: image atomics go through the same helper on the `RWTexture<uint>` texel. - **Behaviour fix:** image atomics wrote the pre-op value back to vdata every time. They now do it only when GLC (MIMG dword0 bit 13) is set, as MUBUF atomics already do. With GLC = 0, vdata keeps its input. - A dmask other than 0x1 (0x3 for cmpswap), i.e. a 64-bit image atomic, is now refused with an explicit error instead of being translated as 32-bit. - Not covered: the float image atomics (fcmpswap/fmin/fmax 0x1d-0x1f), the 64-bit variants and the `_pck` loads/stores. They stay unmapped or refused. ### Tests - New `exec_mem::mimg::image_mimg_atomics`: 13 mnemonics × 8 operand/compare pairs × GLC on/off (208 cases, each also rerun with runtime inputs). Each case checks the returned vdata, the texel result and two untouched neighbours on an R32_UINT UAV (adds `R32_UINT` to the exec_mem image helper). - Passes on WARP and on hardware (`TOMBOX_EXEC_HW=1`, NVIDIA). - I also checked that the test catches the bug: forcing the old always-write-vdata behaviour makes 52 cases fail. - Full `cargo test -p tombox-xshader` passes. `pr_gate.py` reports 0 problems. - [x] `cargo test -p tombox-xshader` passes - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note 🤖 Generated with [Claude Code](https://claude.com/claude-code)
omonkeyz commented 2026-11-22 16:27:59 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T16:27:59Z.


Applied in 4160c9a (merged in 604b5a1) with your authorship kept, thanks, and thanks for checking that the test catches the old GLC bug!

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7082094779 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/147#issuecomment-7082094779). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T16:27:59Z. --- Applied in 4160c9a (merged in 604b5a1) with your authorship kept, thanks, and thanks for checking that the test catches the old GLC bug!

Pull request closed

Sign in to join this conversation.
No reviewers
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!147
No description provided.