[PR #633] [MERGED] rdna2_decode: align MIMG addr, atomic TFE/cmpswap, and r128 widths with LLVM (DECODE-MIMG-PARITY) #674

Closed
opened 2026-11-26 20:18:40 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/633
Author: @jarvixaiassistant-glitch
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: fix/decode-mimg-llvm-parity


📝 Commits (1)

  • 450cd81 rdna2_decode: align MIMG addr, atomic TFE/cmpswap, and r128 widths with LLVM

📊 Changes

2 files changed (+109 additions, -44 deletions)

View changed files

📝 tests/test_rdna2_decode.py (+72 -0)
📝 tools/rdna2_decode.py (+37 -44)

📄 Description

Claimed in the coordination issue as: DECODE-MIMG-PARITY

What and why

Fixes 72 MIMG disassembly mismatches in the pure-Python RDNA2 decoder (tools/rdna2_decode.py) uncovered by cross-checking against all 291 image_* test vectors in upstream LLVM's official GFX10/GFX1030 disassembler suites (gfx10_mimg.txt, gfx10_mimg_features.txt, gfx1030_new.txt) and AMDGPU::getAddrSizeMIMGOp (llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp):

  1. _mimg_addr_count() — matches LLVM AMDGPU::getAddrSizeMIMGOp on GFX10:
    • image_bvh_intersect_ray / image_bvh64_intersect_ray: return 8 / 9 VGPRs when a16=True (previously always 11 / 12).
    • image_msaa_load: no longer falsely matches "_l" inside "_load", removing a spurious +1 address VGPR (and spurious trailing v0 in NSA lists).
    • image_load_mip_pck, image_load_mip_pck_sgn, image_store_mip_pck, *_mip_pck2/4, *_mip_by2/4: include the mip VGPR (previously only exact image_load_mip / image_store_mip matched).
    • image_load_by2/by4 / image_store_by2/by4: no longer falsely match "_b" as bias.
    • image_sample_*cd* (all 16 coarse-derivative opcodes): tokenize underscore-delimited suffixes (parts = set(name.split("_")[2:])) so "cd" is counted as derivatives instead of falsely triggering z-compare "c" and dropping all derivative VGPRs.
    • image_sample_*_g16 (all 16 G16 opcodes): recognize "cl" and "o" before "g16", and pack 16-bit gradients as alignTo<2>(grad_coords) ((grad_coords + 1) & ~1: 2 / 2 / 4 VGPRs for 1D / 2D / 3D instead of 2 / 4 / 6).
    • image_get_lod: respects a16 coordinate packing.
    • Odd-coordinate a16 packing: computes (coords + has_lod_or_cl_or_mip + 1) // 2 (LLVM divideCeil(AddrComponents, 2)) instead of (coords + 1) // 2 + extra, fixing 1D/3D/2D-array/cube + lod/cl/mip overcounts by 1 VGPR.
  2. _mimg_data_count() — atomic tfe and cmpswap dmask:0x1:
    • Adds + (1 if tfe else 0) on image_atomic_* instead of returning early before TFE (fixing all 26 image_atomic_* ... tfe vectors in gfx10_mimg_features.txt).
    • image_atomic_cmpswap / image_atomic_fcmpswap return 2 VGPRs for dmask:0x1 (and 0x3) and 4 for dmask:0xf, matching LLVM (which has no 1-VGPR cmpswap variant).
  3. Non-BVH r128 resource width (rsrc_w):
    • Uses 4 SGPRs (SReg_128_XNULL) only for image_bvh*_intersect_ray and 8 SGPRs (SReg_256_XNULL) for all non-BVH MIMG instructions even when r128 is set, matching MIMGInstructions.td and gfx10_mimg.txt.

Adds test_mimg_addr_data_and_rsrc_widths_match_llvm in tests/test_rdna2_decode.py covering all fixed categories with hand-encoded GFX10/GFX1030 words (zero game data), round-trip checked through both decode_bytes() and disasm_bytes() → shader_ir.parse_line().

Tested

All synthetic CPU/stdlib/docs/CI checks on Windows 11 x64, Python 3.12.14, Node v24.19.0 (no game files, no llvm-mc installed locally):

  • python -I tests/test_rdna2_decode.py -v — 20/20 passed (1 skipped: llvm-mc not installed)
  • Cross-check against upstream LLVM GFX10/GFX1030 MIMG disassembler test vectors:
    • gfx1030_new.txt: 12/12 PASS (was 5/12, 7 mismatches)
    • gfx10_mimg.txt: 253/253 PASS (was 214/253, 39 mismatches)
    • gfx10_mimg_features.txt: 26/26 PASS (was 0/26, 26 mismatches)
    • Total: 291/291 PASS (72 mismatches → 0 mismatches)
  • python -I tests/test_ci_registration.py — 15/15 passed
  • python -I tests/test_runtime_paths.py — 5/5 passed
  • python -I scripts/check_no_game_data.py — passed (0 forbidden tracked extensions)
  • python -m compileall -q make_game.py tools tests — passed
  • python -I tests/test_text_write_line_endings.py, tests/test_report_paths.py, tests/test_i18n_index.py, and all tests/test_docs_*.py — passed
  • node --test tests/test_viewer_streaming.cjs — passed

GPUs tested: n/a (pure-Python ISA binary decoder / unit tests only)

AI-assisted: yes (JARVIX multi-model team: Antigravity + DeepSeek V4 Flash + NVIDIA NIM Nemotron-3.5-Lightning & Nemotron-3-Ultra-550B)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A — binary ISA decoder parity with LLVM llvm-mc only; no SPIR-V shader-translator rule changed.)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/633 **Author:** [@jarvixaiassistant-glitch](https://github.com/jarvixaiassistant-glitch) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `fix/decode-mimg-llvm-parity` --- ### 📝 Commits (1) - [`450cd81`](https://github.com/ubiquitarianism/leonida/commit/450cd810545937fb9880b486b7bbf5a8ae2e37b1) rdna2_decode: align MIMG addr, atomic TFE/cmpswap, and r128 widths with LLVM ### 📊 Changes **2 files changed** (+109 additions, -44 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_rdna2_decode.py` (+72 -0) 📝 `tools/rdna2_decode.py` (+37 -44) </details> ### 📄 Description Claimed in the coordination issue as: DECODE-MIMG-PARITY ### What and why Fixes **72 MIMG disassembly mismatches** in the pure-Python RDNA2 decoder (`tools/rdna2_decode.py`) uncovered by cross-checking against all 291 `image_*` test vectors in upstream LLVM's official GFX10/GFX1030 disassembler suites (`gfx10_mimg.txt`, `gfx10_mimg_features.txt`, `gfx1030_new.txt`) and `AMDGPU::getAddrSizeMIMGOp` (`llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp`): 1. **`_mimg_addr_count()` — matches LLVM `AMDGPU::getAddrSizeMIMGOp` on GFX10:** - `image_bvh_intersect_ray` / `image_bvh64_intersect_ray`: return `8` / `9` VGPRs when `a16=True` (previously always `11` / `12`). - `image_msaa_load`: no longer falsely matches `"_l"` inside `"_load"`, removing a spurious `+1` address VGPR (and spurious trailing `v0` in NSA lists). - `image_load_mip_pck`, `image_load_mip_pck_sgn`, `image_store_mip_pck`, `*_mip_pck2/4`, `*_mip_by2/4`: include the mip VGPR (previously only exact `image_load_mip` / `image_store_mip` matched). - `image_load_by2/by4` / `image_store_by2/by4`: no longer falsely match `"_b"` as bias. - `image_sample_*cd*` (all 16 coarse-derivative opcodes): tokenize underscore-delimited suffixes (`parts = set(name.split("_")[2:])`) so `"cd"` is counted as derivatives instead of falsely triggering z-compare `"c"` and dropping all derivative VGPRs. - `image_sample_*_g16` (all 16 G16 opcodes): recognize `"cl"` and `"o"` before `"g16"`, and pack 16-bit gradients as `alignTo<2>(grad_coords)` (`(grad_coords + 1) & ~1`: `2 / 2 / 4` VGPRs for 1D / 2D / 3D instead of `2 / 4 / 6`). - `image_get_lod`: respects `a16` coordinate packing. - Odd-coordinate `a16` packing: computes `(coords + has_lod_or_cl_or_mip + 1) // 2` (LLVM `divideCeil(AddrComponents, 2)`) instead of `(coords + 1) // 2 + extra`, fixing 1D/3D/2D-array/cube + `lod`/`cl`/`mip` overcounts by 1 VGPR. 2. **`_mimg_data_count()` — atomic `tfe` and `cmpswap` `dmask:0x1`:** - Adds `+ (1 if tfe else 0)` on `image_atomic_*` instead of returning early before TFE (fixing all 26 `image_atomic_* ... tfe` vectors in `gfx10_mimg_features.txt`). - `image_atomic_cmpswap` / `image_atomic_fcmpswap` return `2` VGPRs for `dmask:0x1` (and `0x3`) and `4` for `dmask:0xf`, matching LLVM (which has no 1-VGPR `cmpswap` variant). 3. **Non-BVH `r128` resource width (`rsrc_w`):** - Uses `4` SGPRs (`SReg_128_XNULL`) only for `image_bvh*_intersect_ray` and `8` SGPRs (`SReg_256_XNULL`) for all non-BVH MIMG instructions even when `r128` is set, matching `MIMGInstructions.td` and `gfx10_mimg.txt`. Adds `test_mimg_addr_data_and_rsrc_widths_match_llvm` in `tests/test_rdna2_decode.py` covering all fixed categories with hand-encoded GFX10/GFX1030 words (zero game data), round-trip checked through both `decode_bytes()` and `disasm_bytes()` → `shader_ir.parse_line()`. ### Tested All synthetic CPU/stdlib/docs/CI checks on Windows 11 x64, Python 3.12.14, Node v24.19.0 (no game files, no `llvm-mc` installed locally): - `python -I tests/test_rdna2_decode.py -v` — 20/20 passed (1 skipped: `llvm-mc` not installed) - Cross-check against upstream LLVM GFX10/GFX1030 MIMG disassembler test vectors: - `gfx1030_new.txt`: 12/12 PASS (was 5/12, 7 mismatches) - `gfx10_mimg.txt`: 253/253 PASS (was 214/253, 39 mismatches) - `gfx10_mimg_features.txt`: 26/26 PASS (was 0/26, 26 mismatches) - **Total: 291/291 PASS (72 mismatches → 0 mismatches)** - `python -I tests/test_ci_registration.py` — 15/15 passed - `python -I tests/test_runtime_paths.py` — 5/5 passed - `python -I scripts/check_no_game_data.py` — passed (0 forbidden tracked extensions) - `python -m compileall -q make_game.py tools tests` — passed - `python -I tests/test_text_write_line_endings.py`, `tests/test_report_paths.py`, `tests/test_i18n_index.py`, and all `tests/test_docs_*.py` — passed - `node --test tests/test_viewer_streaming.cjs` — passed GPUs tested: n/a (pure-Python ISA binary decoder / unit tests only) AI-assisted: yes (JARVIX multi-model team: Antigravity + DeepSeek V4 Flash + NVIDIA NIM Nemotron-3.5-Lightning & Nemotron-3-Ultra-550B) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. *(N/A — binary ISA decoder parity with LLVM `llvm-mc` only; no SPIR-V shader-translator rule changed.)* --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:40 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#674
No description provided.