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

Closed
QuentinDanblon wants to merge 1 commit from upstream-pr/302 into main
QuentinDanblon commented 2026-11-23 17:07:25 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-23T17:07:25Z.


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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6564585102 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/302). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-23T17:07:25Z. --- **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)
SchmashinPrunes commented 2026-11-24 14:34:52 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by SchmashinPrunes on 2026-11-24T14:34:52Z.

Review: COMMENTED


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.)

<!-- greyfinch-sync:omonkeyz/xbox-emulator:review:6041181503 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/302#pullrequestreview-6041181503). Originally posted by [SchmashinPrunes](https://github.com/SchmashinPrunes) on 2026-11-24T14:34:52Z. **Review:** COMMENTED --- 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.)
omonkeyz commented 2026-11-25 13:48:59 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-25T13:48:59Z.


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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7164331040 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/302#issuecomment-7164331040). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-25T13:48:59Z. --- Applied on main in 06e683f (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

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!302
No description provided.