emu: implement all 16 RDNA 2 MIMG image_atomic_* instructions #309

Manually merged
github merged 2 commits from github-bot/gh-309 into gh-pr/309/base 2026-11-26 11:04:00 +00:00 AGit
Owner

@⁠Lewandox on GitHub · 2026-11-26 02:07 UTC · original
Lewandox:feat/rdna2-mimg-image-atomics → main · +557 −16 · 5 files · 2 commits · merged 2026-11-26 11:03 UTC

Summary

Implements all 16 RDNA 2 MIMG image_atomic_* 2D instructions in both the reference interpreter and the HLSL recompiler, plus the corresponding 32-bit and 64-bit integer image formats (FORMAT_32_UINT, FORMAT_32_SINT, FORMAT_32_32_UINT, FORMAT_32_32_SINT), bringing rdna2_exec.coverage() from 1,285/1,490 to 1,301/1,490 (+16 instructions):

  • image_atomic_swap, image_atomic_cmpswap
  • image_atomic_add, image_atomic_sub
  • image_atomic_smin, image_atomic_umin, image_atomic_smax, image_atomic_umax
  • image_atomic_and, image_atomic_or, image_atomic_xor
  • image_atomic_inc, image_atomic_dec
  • image_atomic_fcmpswap, image_atomic_fmin, image_atomic_fmax

Details

  • PrototypeScarlett/emu/rdna2_image.py:
    • Added ATOMIC_OPS, ATOMIC_CMPSWAP_OPS, ATOMIC_FORMATS_32, ATOMIC_FORMATS_64, and FORMAT_32_UINT/FORMAT_32_SINT/FORMAT_32_32_UINT/FORMAT_32_32_SINT (TEXEL_BYTES).
    • Extracted the MIMG glc bit (bit 13) in instruction_fields().
    • Added atomic_width(name, dmask) validating dmask (0x1/0x3 for 32/64-bit atomics; 0x3/0xF for cmpswap/fcmpswap) and updated address_count() (2 VGPRs in 2D) and check_instruction().
  • PrototypeScarlett/emu/rdna2_exec_image.py:
    • Implemented 32-bit and 64-bit 2D image_atomic_* execution reusing emu.rdna2_exec_atomic.operation(kind, width), enforcing format/width compatibility, glc return-old behavior (leaving vdata untouched when glc=0 and preserving cmp VGPRs), out-of-bounds guards (no memory write, 0 returned when glc=1), and safe vdata/vaddr overlap.
    • Added raw integer format handling (32_UINT, 32_SINT, 32_32_UINT, 32_32_SINT) to texel() and _store_texel().
  • PrototypeScarlett/emu/rdna2_hlsl_image.py:
    • Added ImageAtomic32() HLSL helper using native RWByteAddressBuffer Interlocked* for swap, cmpswap, add, sub, umin, umax, and, or, xor, and a bounded InterlockedCompareExchange CAS loop for smin, smax, inc, dec, fcmpswap, fmin, and fmax matching IEEE NaN/±0 semantics bit-for-bit with rdna2_exec_atomic.py, followed by AllMemoryBarrierWithGroupSync().
    • Refuses 64-bit image atomics cleanly with Untranslatable (matching SM 6.0 RWByteAddressBuffer 32-bit atomic limits).
    • Works in wave32, wave64, and graphics shader helpers.
  • tests/test_rdna2_image_atomic.py & tests/test_rdna2_exec.py:
    • Added unit, refusal, NSA/overlap/OOB/contention, integer format round-trip, wave32/wave64/graphics HLSL translation, and @gpu parity tests for all 16 instructions.
    • Updated test_untranslated_instruction_is_named in tests/test_rdna2_exec.py to use image_sample_b (since image_atomic_swap is now supported).

Verification

  • python -m pytest -q: 1352 passed, 322 skipped (0 failed, including test_readme_sync.py; @gpu tests skip locally because dxc / anyxboxx_gpu_run.exe are not installed on this host).
  • ruff check --select W605,F,E9 PrototypeScarlett tests tools: All checks passed!
  • rdna2_exec.coverage(): (1301, 1490)

Clean-room note

All encodings and semantics are based solely on public AMD RDNA 2 ISA documentation, LLVM MIMGInstructions.td, and synthetic tests. No proprietary game or SDK files were used.

**@⁠Lewandox** on GitHub · 2026-11-26 02:07 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/309) `Lewandox:feat/rdna2-mimg-image-atomics` → `main` · +557 −16 · 5 files · 2 commits · merged 2026-11-26 11:03 UTC ## Summary Implements all 16 RDNA 2 `MIMG` `image_atomic_*` 2D instructions in both the reference interpreter and the HLSL recompiler, plus the corresponding 32-bit and 64-bit integer image formats (`FORMAT_32_UINT`, `FORMAT_32_SINT`, `FORMAT_32_32_UINT`, `FORMAT_32_32_SINT`), bringing `rdna2_exec.coverage()` from `1,285/1,490` to **`1,301/1,490`** (+16 instructions): - `image_atomic_swap`, `image_atomic_cmpswap` - `image_atomic_add`, `image_atomic_sub` - `image_atomic_smin`, `image_atomic_umin`, `image_atomic_smax`, `image_atomic_umax` - `image_atomic_and`, `image_atomic_or`, `image_atomic_xor` - `image_atomic_inc`, `image_atomic_dec` - `image_atomic_fcmpswap`, `image_atomic_fmin`, `image_atomic_fmax` ## Details - **`PrototypeScarlett/emu/rdna2_image.py`**: - Added `ATOMIC_OPS`, `ATOMIC_CMPSWAP_OPS`, `ATOMIC_FORMATS_32`, `ATOMIC_FORMATS_64`, and `FORMAT_32_UINT`/`FORMAT_32_SINT`/`FORMAT_32_32_UINT`/`FORMAT_32_32_SINT` (`TEXEL_BYTES`). - Extracted the MIMG `glc` bit (`bit 13`) in `instruction_fields()`. - Added `atomic_width(name, dmask)` validating `dmask` (`0x1`/`0x3` for 32/64-bit atomics; `0x3`/`0xF` for `cmpswap`/`fcmpswap`) and updated `address_count()` (`2` VGPRs in 2D) and `check_instruction()`. - **`PrototypeScarlett/emu/rdna2_exec_image.py`**: - Implemented 32-bit and 64-bit 2D `image_atomic_*` execution reusing `emu.rdna2_exec_atomic.operation(kind, width)`, enforcing format/width compatibility, `glc` return-old behavior (leaving `vdata` untouched when `glc=0` and preserving `cmp` VGPRs), out-of-bounds guards (no memory write, `0` returned when `glc=1`), and safe `vdata`/`vaddr` overlap. - Added raw integer format handling (`32_UINT`, `32_SINT`, `32_32_UINT`, `32_32_SINT`) to `texel()` and `_store_texel()`. - **`PrototypeScarlett/emu/rdna2_hlsl_image.py`**: - Added `ImageAtomic32()` HLSL helper using native `RWByteAddressBuffer` `Interlocked*` for `swap`, `cmpswap`, `add`, `sub`, `umin`, `umax`, `and`, `or`, `xor`, and a bounded `InterlockedCompareExchange` CAS loop for `smin`, `smax`, `inc`, `dec`, `fcmpswap`, `fmin`, and `fmax` matching IEEE NaN/`±0` semantics bit-for-bit with `rdna2_exec_atomic.py`, followed by `AllMemoryBarrierWithGroupSync()`. - Refuses 64-bit image atomics cleanly with `Untranslatable` (matching SM 6.0 `RWByteAddressBuffer` 32-bit atomic limits). - Works in wave32, wave64, and graphics shader helpers. - **`tests/test_rdna2_image_atomic.py`** & **`tests/test_rdna2_exec.py`**: - Added unit, refusal, NSA/overlap/OOB/contention, integer format round-trip, wave32/wave64/graphics HLSL translation, and `@gpu` parity tests for all 16 instructions. - Updated `test_untranslated_instruction_is_named` in `tests/test_rdna2_exec.py` to use `image_sample_b` (since `image_atomic_swap` is now supported). ## Verification - `python -m pytest -q`: **1352 passed, 322 skipped** (0 failed, including `test_readme_sync.py`; `@gpu` tests skip locally because `dxc` / `anyxboxx_gpu_run.exe` are not installed on this host). - `ruff check --select W605,F,E9 PrototypeScarlett tests tools`: **All checks passed!** - `rdna2_exec.coverage()`: `(1301, 1490)` ## Clean-room note All encodings and semantics are based solely on public AMD RDNA 2 ISA documentation, LLVM `MIMGInstructions.td`, and synthetic tests. No proprietary game or SDK files were used.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:42:38 +00:00
github-bot changed target branch from main to gh-pr/309/base 2026-11-26 11:03:59 +00:00
github manually merged commit cf465e60ea into gh-pr/309/base 2026-11-26 11:04:00 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.