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

Closed
github-bot wants to merge 1 commit from gh-pr/147/head into gh-pr/147/base
Owner

@⁠MiguelMatMar on GitHub · 2026-11-22 15:56 UTC · original
MiguelMatMar:image-atomics → main · +117 −67 · 5 files · 1 commits · closed without merging

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

**@⁠MiguelMatMar** on GitHub · 2026-11-22 15:56 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/147) `MiguelMatMar:image-atomics` → `main` · +117 −67 · 5 files · 1 commits · closed without merging **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)
Decode image_atomic_swap, cmpswap, sub, smin, umin, smax, and, or, xor,
inc and dec (MIMG 0x0f-0x1c, GFX10 opcode table) alongside the existing
add and umax, and translate them on RWTexture<uint> texels through the
same Interlocked*/compare-exchange lowering the buffer atomics use, now
shared in hlsl/atomic.rs.

Image atomics wrote the pre-op value back to vdata unconditionally; they
now return it only when GLC (MIMG dword0 bit 13) is set, as the buffer
atomics already do. Non-32-bit dmasks (64-bit atomics) are refused.

Verified by exec_mem::mimg::image_mimg_atomics: 13 mnemonics x 8 operand
pairs x GLC on/off, previous value, texel result and untouched neighbours,
on WARP and on hardware (TOMBOX_EXEC_HW=1).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:11:46 +00:00
github-bot closed this pull request 2026-11-26 06:11:46 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 16:27 UTC · original

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

**@⁠omonkeyz** on GitHub · 2026-11-22 16:27 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/147#issuecomment-7082094779) 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

This discussion has been locked. Commenting is limited to contributors.
No description provided.