tombox-xshader: decode MIMG pck and float-atomic opcodes, translate pck on atomic images #302

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

@⁠QuentinDanblon on GitHub · 2026-11-23 17:07 UTC · original
QuentinDanblon:pr/mimg-pck-atomics → main · +172 −3 · 3 files · 1 commits · closed without merging

Library / area: tombox-xshader, MIMG (src/rdna2/mnem.rs, src/hlsl.rs, tests/exec_mem/mimg.rs). Follows the MIMG gaps of #103 / #114.

Exports changed (exports.txt rows): none

Source of the behaviour: AMD RDNA2 ISA document, section 12.16, and LLVM AMDGPU MIMGInstructions.td (Apache-2.0) for names, numbers and semantics; tests/isa_table/gfx1013.txt agrees. No third-party code.

What was actually unmapped

The 32-bit integer image atomics are already mapped on main (0x0f to 0x1c, from #147 and #195), so the BLOCKERS line "every image atomic except add and umax" is out of date. There is no 0x13 on RDNA2. What was left: the pck forms 0x02 to 0x05, 0x0a, 0x0b, and the float atomics 0x1d to 0x1f.

What this PR does

  • Decodes image_load_pck, image_load_pck_sgn, image_load_mip_pck, image_load_mip_pck_sgn, image_store_pck, image_store_mip_pck, image_atomic_fcmpswap, image_atomic_fmin, image_atomic_fmax.
  • Translates the 6 pck opcodes on one case only: an image the same shader also uses with image atomics, 32-bit (dmask 0x1) or 64-bit (dmask 0x3). The ISA defines pck as no format conversion, 8- and 16-bit elements zero- or sign-extended. On those images every element is a 32-bit or 64-bit integer word, already declared RWTexture<uint> / RWTexture<uint64_t>, so pck and pck_sgn give the same bits as the plain load/store and reuse that path, per-mip UAV views included. This rests on the assumption the translator already makes for atomic images.

Refused, each with a named error

  • pck on any other image or dmask, SRVs included: a DXIL typed load or store converts through the view format, which comes from the title's descriptor at runtime, so the conversion cannot be undone here. Covering it would need d3d12_xs to create an integer cast view of the image.
  • pck with D16: LLVM gives the pck opcodes no D16 form.
  • image_atomic_fcmpswap / fmin / fmax: the ISA only says the float compare "handles NaN/INF/denorm", DXIL has no float min/max image atomic, and no RDNA2-recorded results pin the NaN, signed-zero and denormal cases (the gfx1036 vectors from #195 are integer only).
  • R128 / TFE / LWE: unchanged refusal (no DXIL equivalent of the texture-fail / LOD-warning status VGPR; R128 needs the 128-bit descriptor).

Tests

  • image_mimg_pck_on_atomic_images (group mimg_pck): 22 cases, 6 mnemonics, R32_UINT image with 3 mips; texels carry sign bits (0x80000080, 0xffff8000, 0x0000ff80) so a wrong extension would show.
  • image_mimg_pck_on_64bit_atomic_images (mimg_pck_64bit): 7 cases, 3 mnemonics, R32G32_UINT.
  • image_mimg_pck_and_float_atomic_refusals: SRV, UAV without atomics, dmask 0xf, D16, the three float atomics.

On 68e32b8 (base f89e410, r32l): the three pass on WARP (all cases also with runtime inputs) and with TOMBOX_EXEC_HW=1 on an RTX 5090. Full tombox-xshader suite on WARP: lib 116 passed 3 ignored, exec 131 passed 2 ignored, all other targets pass. Mutations, each failing as expected then restored: _mip_pck loads ignoring the mip (12 cases fail), image_store_mip_pck writing mip 0 (4 fail), the atomic-image condition removed (refusal test fails), the float-atomic check removed (refusal test fails). pr_gate.py --base origin/main: 0 problems.

Questions for you

  1. pck is translated only on images that also carry atomics, a narrow case. Do you want a follow-up with a runtime-side integer cast view so pck works on UNORM and float images? That would touch d3d12_xs.
  2. The float atomics are decoded only to be refused, which turns "unknown opcode" into a named error. If your progress generator counts a decoded mnemonic as supported, those three names may need to come out of mnem.rs; tell me and I'll drop them.
  3. The #103 entry of docs/BLOCKERS.md (atomic list, pck note) is now out of date; I did not edit it.
  • cargo test -p tombox-xshader passes (see above)
  • No game or console files and no binaries included
  • No fake success; what cannot be translated faithfully is refused with a named error

🤖 Generated with Claude Code

**@⁠QuentinDanblon** on GitHub · 2026-11-23 17:07 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/302) `QuentinDanblon:pr/mimg-pck-atomics` → `main` · +172 −3 · 3 files · 1 commits · closed without merging **Library / area:** `tombox-xshader`, MIMG (`src/rdna2/mnem.rs`, `src/hlsl.rs`, `tests/exec_mem/mimg.rs`). Follows the MIMG gaps of #103 / #114. **Exports changed (exports.txt rows):** none **Source of the behaviour:** AMD RDNA2 ISA document, section 12.16, and LLVM AMDGPU `MIMGInstructions.td` (Apache-2.0) for names, numbers and semantics; `tests/isa_table/gfx1013.txt` agrees. No third-party code. ### What was actually unmapped The 32-bit integer image atomics are already mapped on main (0x0f to 0x1c, from #147 and #195), so the BLOCKERS line "every image atomic except add and umax" is out of date. There is no 0x13 on RDNA2. What was left: the pck forms 0x02 to 0x05, 0x0a, 0x0b, and the float atomics 0x1d to 0x1f. ### What this PR does - **Decodes** `image_load_pck`, `image_load_pck_sgn`, `image_load_mip_pck`, `image_load_mip_pck_sgn`, `image_store_pck`, `image_store_mip_pck`, `image_atomic_fcmpswap`, `image_atomic_fmin`, `image_atomic_fmax`. - **Translates the 6 pck opcodes on one case only:** an image the same shader also uses with image atomics, 32-bit (dmask 0x1) or 64-bit (dmask 0x3). The ISA defines pck as no format conversion, 8- and 16-bit elements zero- or sign-extended. On those images every element is a 32-bit or 64-bit integer word, already declared `RWTexture<uint>` / `RWTexture<uint64_t>`, so pck and pck_sgn give the same bits as the plain load/store and reuse that path, per-mip UAV views included. This rests on the assumption the translator already makes for atomic images. ### Refused, each with a named error - pck on any other image or dmask, SRVs included: a DXIL typed load or store converts through the view format, which comes from the title's descriptor at runtime, so the conversion cannot be undone here. Covering it would need d3d12_xs to create an integer cast view of the image. - pck with D16: LLVM gives the pck opcodes no D16 form. - `image_atomic_fcmpswap` / `fmin` / `fmax`: the ISA only says the float compare "handles NaN/INF/denorm", DXIL has no float min/max image atomic, and no RDNA2-recorded results pin the NaN, signed-zero and denormal cases (the gfx1036 vectors from #195 are integer only). - R128 / TFE / LWE: unchanged refusal (no DXIL equivalent of the texture-fail / LOD-warning status VGPR; R128 needs the 128-bit descriptor). ### Tests - `image_mimg_pck_on_atomic_images` (group `mimg_pck`): 22 cases, 6 mnemonics, R32_UINT image with 3 mips; texels carry sign bits (0x80000080, 0xffff8000, 0x0000ff80) so a wrong extension would show. - `image_mimg_pck_on_64bit_atomic_images` (`mimg_pck_64bit`): 7 cases, 3 mnemonics, R32G32_UINT. - `image_mimg_pck_and_float_atomic_refusals`: SRV, UAV without atomics, dmask 0xf, D16, the three float atomics. On `68e32b8` (base `f89e410`, r32l): the three pass on WARP (all cases also with runtime inputs) and with `TOMBOX_EXEC_HW=1` on an RTX 5090. Full `tombox-xshader` suite on WARP: lib 116 passed 3 ignored, `exec` 131 passed 2 ignored, all other targets pass. Mutations, each failing as expected then restored: `_mip_pck` loads ignoring the mip (12 cases fail), `image_store_mip_pck` writing mip 0 (4 fail), the atomic-image condition removed (refusal test fails), the float-atomic check removed (refusal test fails). `pr_gate.py --base origin/main`: 0 problems. ### Questions for you 1. pck is translated only on images that also carry atomics, a narrow case. Do you want a follow-up with a runtime-side integer cast view so pck works on UNORM and float images? That would touch d3d12_xs. 2. The float atomics are decoded only to be refused, which turns "unknown opcode" into a named error. If your progress generator counts a decoded mnemonic as supported, those three names may need to come out of `mnem.rs`; tell me and I'll drop them. 3. The #103 entry of `docs/BLOCKERS.md` (atomic list, pck note) is now out of date; I did not edit it. - [x] `cargo test -p tombox-xshader` passes (see above) - [x] No game or console files and no binaries included - [x] No fake success; what cannot be translated faithfully is refused with a named error 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Decode (rdna2/mnem.rs): image_load_pck 0x02, image_load_pck_sgn 0x03,
image_load_mip_pck 0x04, image_load_mip_pck_sgn 0x05, image_store_pck 0x0a,
image_store_mip_pck 0x0b, image_atomic_fcmpswap 0x1d, image_atomic_fmin 0x1e,
image_atomic_fmax 0x1f (names and numbers as in the AMD RDNA2 ISA, section
12.16, and LLVM AMDGPU MIMGInstructions.td, Apache-2.0).

Translate: the RDNA2 ISA defines the pck forms as loads/stores without format
conversion, 8- and 16-bit elements zero-extended (pck) or sign-extended
(pck_sgn). DXIL typed loads and stores always convert through the view format,
which the translator does not know, so raw bits are only exact where the
element is a 32-bit or 64-bit integer word: an image the same shader also uses
with 32-bit (dmask 0x1) or 64-bit (dmask 0x3) image atomics, already declared
RWTexture<uint> / RWTexture<uint64_t>. There pck and pck_sgn equal the plain
load/store (no 8/16-bit element to extend) and reuse that path, including the
per-mip UAV views for the _mip forms.

Refused with named errors:
- pck on any other image, or with another dmask: the view format conversion
  cannot be undone without the format.
- pck with D16: LLVM gives the pck opcodes no D16 form.
- image_atomic_fcmpswap/fmin/fmax: the ISA only says the float compare
  "handles NaN/INF/denorm", DXIL has no float min/max image atomic, and no
  RDNA2-recorded results pin NaN, signed-zero and denormal behaviour.
- R128/TFE/LWE stay refused (no DXIL equivalent of the AMD fail/LOD-warning
  status VGPR or the 128-bit descriptor).

Tests (tests/exec_mem/mimg.rs, exact bits): mimg_pck 22 cases / 6 mnemonics
on an R32_UINT 3-mip image with sign-bit texels; mimg_pck_64bit 7 cases on
R32G32_UINT; refusal test for SRV/UAV without atomics, dmask 0xf, D16 and the
three float atomics. Pass on WARP and on hardware (TOMBOX_EXEC_HW=1).
No gfx1036 silicon vectors exist for these opcodes.

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

@⁠omonkeyz on GitHub · 2026-11-25 13:48 UTC · original

Applied on main in 06e683f (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:48 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/302#issuecomment-7164331040) Applied on main in 06e683f (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.
Author
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-24 14:34 UTC · original · reviewed

I checked this on RDNA2 silicon: a gfx1036 iGPU (Ryzen 5 9600X), ROCm/HIP 5.7.1, raw wave32 kernels, so RDNA2, not gfx1013. Each kernel ran twice with identical results, and I compared against the semantics this PR implements (my own port; I didn't run the PR's code).

This checks the case the PR translates: image_load_pck and image_load_mip_pck on a 32-bit format return the same bits as image_load / image_load_mip. That held for 192 of 192 cases each (R32_UINT view, a 16×4 image, levels 0..2). So reusing the plain path for 32-bit elements matches the hardware.

I didn't check 64-bit images or the float atomics, and I didn't look at 8- or 16-bit formats, where pck would differ from a converting load.

(Measured with an AI assistant, Claude.)

**@⁠SchmashinPrunes** on GitHub · 2026-11-24 14:34 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/302#pullrequestreview-6041181503) · **reviewed** I checked this on RDNA2 silicon: a gfx1036 iGPU (Ryzen 5 9600X), ROCm/HIP 5.7.1, raw wave32 kernels, so RDNA2, not gfx1013. Each kernel ran twice with identical results, and I compared against the semantics this PR implements (my own port; I didn't run the PR's code). This checks the case the PR translates: `image_load_pck` and `image_load_mip_pck` on a 32-bit format return the same bits as `image_load` / `image_load_mip`. That held for 192 of 192 cases each (R32_UINT view, a 16×4 image, levels 0..2). So reusing the plain path for 32-bit elements matches the hardware. I didn't check 64-bit images or the float atomics, and I didn't look at 8- or 16-bit formats, where pck would differ from a converting load. (Measured with an AI assistant, Claude.)

Pull request closed

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