shader: lower v_swaprel_b32 with the movrel m0 indexing in pixel_aot #1844

Manually merged
github merged 2 commits from gh-pr/1844/head into gh-pr/1844/base 2026-11-26 23:37:07 +00:00
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-24 19:23 UTC · original
legacy-code-archaeologist:shader/swaprel → main · +392 −22 · 6 files · 2 commits · merged 2026-11-24 19:47 UTC

Refs #1795. This builds on #1785: the first commit (eef8bc21) is #1785's, and only 52c31b09 is new. Please merge after #1785; I'll rebase once it lands.

What

tools/pixel_aot.py lowers v_swaprel_b32 vdst, vsrc (VOP1 only; LLVM 15 decodes 7e18d118 as v_swaprel_b32 v12, v24 for gfx1013 and gfx1030).

  • The exchange: VGPR[vdst + m0[25:16]] and VGPR[vsrc + m0[9:0]], the same split as v_movrelsd_2_b32. This is an assumption from the RDNA 2 naming and LLVM's definition. It has not been measured on RDNA hardware (I have none); a correction is welcome.
  • The m0 rules and refusals of the movrel forms: static, or dynamic with a proven bit mask, which lowers to bounded selects on both sides.
  • Order of reads and writes:
    • Both reachable sides are read before either is written.
    • Each reachable register then gets, in this order of priority: the source value when the destination offset selects it; the old destination value when the source offset selects it; otherwise its old value.
    • A swap of a register with itself therefore changes nothing.

Existing tests changed (please check)

Two checks pinned v_swaprel_b32 as untranslated:

  • tests/form_coverage_check.py::check_swap_coverage now requires v_swaprel_b32 to be accepted and covered. A new control requires it to be uncovered without its own word, next to the existing v_swap_b32 control.
  • tests/rdna2_tools_check.py: only a comment changes. The scanner's static tables still list v_swaprel_b32 as untranslated, and the test stays green (148 tests OK).

Evidence

SWAPREL_BODY runs the following, against an independent list-swap reference on the two DPP_MOVREL_SETS:

  • a dynamic swap between two banks: m0 = word3 & 0x30003, which differs between the sets;
  • then, in a second pair of banks:
    • an overlapping swap inside one bank (m0 = 0x30001);
    • a swap of a register with itself (0x20002);
    • a static swap between the banks (0x20001).

The bank sums are 816, 117, 338, 125 and 218, 128, 338, 125.

Controls (pixel_mismatch required):

  • a one-way v_movrelsd_2_b32_e32 in place of the dynamic swap;
  • swapped static m0 halves;
  • the dynamic m0 replaced by 0.

Translation controls:

  • an overlapping dynamic bank, where every register of the bank gets a select;
  • six refusals: an interp_base m0, an m0 from an unbounded SGPR, an unbounded dynamic m0 (s_add_u32), a static offset past v255, an index past v255, and an undefined register.

Windows 11 Pro 26100.9168, DXC 10.0.26100, debug layer unavailable, commit 52c31b09:

ctest --preset dev --no-tests=error -R "^pixel_aot_swaprel_" -V
Adapter Driver Result
WARP 10.0.26100.8972 4096 pixels, max error 0, both sets; all 3 controls mismatched
NVIDIA Quadro M1000M 32.0.15.7371 same

Other runs:

  • python -B tests/pixel_aot_check.py (controls) exits 0.
  • python -B tests/form_coverage_check.py passes.
  • python -B tests/rdna2_tools_check.py: 148 OK.
  • Full ctest --preset dev -E '_hardware$': 782/785. The three failures were pixel_aot_warp, pixel_aot_buffer_color_warp and pixel_aot_three_way_warp, which timed out under -j 4 and pass when run alone (3/3).
  • tools/form_coverage.py --gaps gfx1030 no longer lists v_swaprel_b32.

Not run locally: tests/pixel_aot_check.py binary, because there is no llvm-mc here.

🤖 Generated with Claude Code

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-24 19:23 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1844) `legacy-code-archaeologist:shader/swaprel` → `main` · +392 −22 · 6 files · 2 commits · merged 2026-11-24 19:47 UTC Refs #1795. **This builds on #1785**: the first commit (eef8bc21) is #1785's, and only 52c31b09 is new. Please merge after #1785; I'll rebase once it lands. ## What `tools/pixel_aot.py` lowers `v_swaprel_b32 vdst, vsrc` (VOP1 only; LLVM 15 decodes `7e18d118` as `v_swaprel_b32 v12, v24` for gfx1013 and gfx1030). - **The exchange:** `VGPR[vdst + m0[25:16]]` and `VGPR[vsrc + m0[9:0]]`, the same split as `v_movrelsd_2_b32`. **This is an assumption** from the RDNA 2 naming and LLVM's definition. It has not been measured on RDNA hardware (I have none); a correction is welcome. - **The `m0` rules and refusals of the movrel forms:** static, or dynamic with a proven bit mask, which lowers to bounded selects on both sides. - **Order of reads and writes:** - Both reachable sides are read before either is written. - Each reachable register then gets, in this order of priority: the source value when the destination offset selects it; the old destination value when the source offset selects it; otherwise its old value. - A swap of a register with itself therefore changes nothing. ## Existing tests changed (please check) Two checks pinned `v_swaprel_b32` as untranslated: - `tests/form_coverage_check.py::check_swap_coverage` now requires `v_swaprel_b32` to be accepted and covered. A new control requires it to be uncovered without its own word, next to the existing `v_swap_b32` control. - `tests/rdna2_tools_check.py`: only a comment changes. The scanner's static tables still list `v_swaprel_b32` as untranslated, and the test stays green (148 tests OK). ## Evidence `SWAPREL_BODY` runs the following, against an independent list-swap reference on the two `DPP_MOVREL_SETS`: - a dynamic swap between two banks: `m0 = word3 & 0x30003`, which differs between the sets; - then, in a second pair of banks: - an overlapping swap inside one bank (`m0 = 0x30001`); - a swap of a register with itself (`0x20002`); - a static swap between the banks (`0x20001`). The bank sums are 816, 117, 338, 125 and 218, 128, 338, 125. **Controls** (`pixel_mismatch` required): - a one-way `v_movrelsd_2_b32_e32` in place of the dynamic swap; - swapped static `m0` halves; - the dynamic `m0` replaced by 0. **Translation controls:** - an overlapping dynamic bank, where every register of the bank gets a select; - six refusals: an `interp_base` `m0`, an `m0` from an unbounded SGPR, an unbounded dynamic `m0` (`s_add_u32`), a static offset past v255, an index past v255, and an undefined register. Windows 11 Pro 26100.9168, DXC 10.0.26100, debug layer unavailable, commit 52c31b09: ``` ctest --preset dev --no-tests=error -R "^pixel_aot_swaprel_" -V ``` | Adapter | Driver | Result | |---|---|---| | WARP | 10.0.26100.8972 | 4096 pixels, max error 0, both sets; all 3 controls mismatched | | NVIDIA Quadro M1000M | 32.0.15.7371 | same | **Other runs:** - `python -B tests/pixel_aot_check.py` (controls) exits 0. - `python -B tests/form_coverage_check.py` passes. - `python -B tests/rdna2_tools_check.py`: 148 OK. - Full `ctest --preset dev -E '_hardware$'`: 782/785. The three failures were `pixel_aot_warp`, `pixel_aot_buffer_color_warp` and `pixel_aot_three_way_warp`, which timed out under `-j 4` and pass when run alone (3/3). - `tools/form_coverage.py --gaps gfx1030` no longer lists `v_swaprel_b32`. **Not run locally:** `tests/pixel_aot_check.py binary`, because there is no `llvm-mc` here. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The VOP1 (_e32) and VOP3 (_e64) encodings of v_movreld_b32, v_movrels_b32,
v_movrelsd_b32 and v_movrelsd_2_b32, which LLVM 15 prints with two VGPR
operands for gfx1013 and gfx1030 alike, now lower through the existing
DPP movrel m0 indexing without a quad swizzle: each lane reads and writes
its own VGPRs. Static and bounded-dynamic m0, source-before-destination
reads for overlapping banks, the entry-mask requirement and the refusals
are the DPP forms' code path. v_swaprel_b32, the SDWA forms and s_movrel*
stay outside.

PLAIN_MOVREL_BODY runs each move with a dynamic and a static m0 and is
drawn twice, as written and with _e32/_e64 exchanged, so all eight forms
see both kinds of m0, on the two DPP_MOVREL_SETS constant sets. Four
mutations per variant (dynamic m0 ignored for three moves, swapped static
m0 halves for v_movrelsd_2) must produce a pixel mismatch. The
translation controls check the bounded selects, an overlapping bank and
five refusals; both variants join the check_binary round trip.

Windows 11 26100: pixel_aot_plain_movrel_warp (WARP 10.0.26100.8972) and
_hardware (Quadro M1000M, 32.0.15.7371, debug layer unavailable) pass,
4096 pixels with zero error for both sets and variants; every mutation
mismatched. pixel_aot_dpp_movrel_{warp,hardware} still pass. Full dev
suite without _hardware: 781/781. check_binary was not run locally (no
llvm-mc here).

Refs #1739

Co-Authored-By: Claude Opus 5.5 <[email protected]>
v_swaprel_b32 vdst, vsrc exchanges VGPR[vdst + m0[25:16]] and
VGPR[vsrc + m0[9:0]], the same split as v_movrelsd_2_b32 (read from the
RDNA 2 naming and LLVM's definition; not measured on RDNA hardware). It
uses the movrel m0 rules (static, or dynamic with a proven bit mask) and
refusals, reads both reachable sides before writing, and gives each
reachable register the source value when the destination offset selects
it, the old destination value when the source offset selects it, and its
old value otherwise, so a swap of a register with itself changes nothing.

SWAPREL_BODY runs a dynamic swap between two banks and, in a second pair
of banks, an overlapping swap inside one bank, a swap of a register with
itself and a static swap, against an independent list-swap reference on
the two DPP_MOVREL_SETS. Three controls must mismatch: a one-way move in
place of the swap, swapped static m0 halves and an ignored dynamic m0.
The translation controls check an overlapping dynamic bank and six
refusals.

Two checks pinned v_swaprel_b32 as untranslated and are updated:
tests/form_coverage_check.py now requires it accepted and covered, with a
control without its word; a comment in tests/rdna2_tools_check.py now
says the scanner's static tables, not pixel_aot, list it.

Windows 11 26100: pixel_aot_swaprel_warp (WARP 10.0.26100.8972) and
_hardware (Quadro M1000M, 32.0.15.7371, debug layer unavailable) pass,
4096 pixels with zero error for both sets; every control mismatched.
Builds on #1785.

Refs #1795

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:37:06 +00:00
github manually merged commit 7a75c9ab72 into gh-pr/1844/base 2026-11-26 23:37:07 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 19:38 UTC · original · reviewed

Peer review of head 7a75c9ab72ebb12b25a34e0ca22cbc88cf4b110f (PRODUCTION_REVIEW_ONLY, technical comment only).

No P1 and no semantic defect found in the lowering. One P2 on how much of it the Linux-side check pins, plus a request for Windows evidence.

Lowering (tools/pixel_aot.py, v_swaprel_b32 branch and the plain v_movrel* branch): read in full, no defect.

  • The swap exchanges VGPR[vdst + m0[25:16]] and VGPR[vsrc + m0[9:0]]. Both sides are read into swap_sval / swap_dval before any register is rewritten, so overlapping banks and a swap of a register with itself are correct. I traced the emitted code for the dynamic case (SWAPREL_BODY) and for the static cases 0x30001, 0x20002 and 0x20001; each register gets the right value.
  • Refusals are inherited from the movrel path and covered: non-entry mask, unsupported or unbounded dynamic m0, static offset past 255, indexed VGPR past v255, undefined indexed source, outstanding sample.
  • The plain VOP1/VOP3 movrel forms reuse the DPP indexing through kind and skip only the quad swizzle (perm is None). The regex requires exactly two VGPR operands, so any extra modifier text is refused rather than dropped. The _dpp path is unchanged.
  • The encoding in the docs matches the assembler: llvm-mc-19 (gfx1030) encodes v_swaprel_b32 v12, v24 as 0x7e18d118.
  • The m0 field split follows the documented naming and the PR itself says it was not measured on RDNA hardware. I could not check it against hardware either.

P2: the Linux-mode tests/pixel_aot_check.py does not pin the swap's values.
In the no-argument mode the new checks are text assertions ("swap_doff" in ..., "dpp_soff" in ...) and refusal controls. The value checks are the draw-swaprel and draw-plain-movrel modes, which need dxc and a D3D12 adapter. I applied one-line mutations to tools/pixel_aot.py, one at a time, and ran the check with no arguments. The check returned rc=0 for these four:

  • the select in the final loop reads swap_sval instead of swap_dval for the source-side registers
  • the static m0 halves swapped ([m0_u & 0x3ff] and [(m0_u >> 16) & 0x3ff] exchanged)
  • the dynamic source offsets taken from m0_mask >> 16
  • the destination-side select removed (value = value)
    It returned rc=1 for one: forcing kind to v_movrels_b32_dpp (the m0 range error).
    These escape the Linux run, so the swap semantics are guarded only by the Windows draw tests (pixel_aot_swaprel_warp, pixel_aot_plain_movrel_warp). I could not run those here. The PR text says the mutation controls mismatch on WARP and on a discrete adapter; I could not confirm that. A CI-visible Linux value check would help: for example, evaluate the emitted swap_* / alu*_r* lines on a few register states in Python, as the cmp_class check now does for its helper.

Request: run the two WARP tests above on Windows Server 2025, and apply at least the first two mutations above through the Windows run to show they fail there.

Other checks:

  • tests/form_coverage_check.py, the new v_swaprel_b32 accepted-word control: pass.
  • The merge against current main (8e2923ae) has no content conflicts (git merge-tree).
  • The assembler-backed binary llvm-mc-19 ... modes of pixel_aot_check.py and rdna2_tools_check.py fail with the same assertions on the PR's merge base (for example v_cvt_f16_i16_e32 v1, 0xfff0 decodes differently), so they are not caused by this PR. They expect a different assembler version, so the binary round trip of the three new fixtures was not exercised here.

Commands run (Linux):

  • git diff --check <merge-base>...HEAD: clean
  • tests/docs_links_check.py: pass (18 files, 370 links)
  • tests/bidi_controls_check.py: pass
  • tests/pixel_aot_check.py: pass
  • tests/rdna2_tools_check.py: pass (148 tests, 18 skipped)
  • tests/form_coverage_check.py: pass
  • tests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so and tests/rdna2_tools_check.py binary ...: fail identically on the merge base (see above)
  • llvm-mc-19 -triple=amdgcn -mcpu=gfx1030 -show-encoding on the three new spellings
  • Mutations above, each restored with git checkout -- .

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 19:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1844#pullrequestreview-6046073046) · **reviewed** Peer review of head `7a75c9ab72ebb12b25a34e0ca22cbc88cf4b110f` (PRODUCTION_REVIEW_ONLY, technical comment only). **No P1 and no semantic defect found in the lowering. One P2 on how much of it the Linux-side check pins, plus a request for Windows evidence.** **Lowering (tools/pixel_aot.py, `v_swaprel_b32` branch and the plain `v_movrel*` branch): read in full, no defect.** - The swap exchanges VGPR[vdst + m0[25:16]] and VGPR[vsrc + m0[9:0]]. Both sides are read into `swap_sval` / `swap_dval` before any register is rewritten, so overlapping banks and a swap of a register with itself are correct. I traced the emitted code for the dynamic case (`SWAPREL_BODY`) and for the static cases `0x30001`, `0x20002` and `0x20001`; each register gets the right value. - Refusals are inherited from the movrel path and covered: non-entry mask, unsupported or unbounded dynamic `m0`, static offset past 255, indexed VGPR past v255, undefined indexed source, outstanding sample. - The plain VOP1/VOP3 movrel forms reuse the DPP indexing through `kind` and skip only the quad swizzle (`perm is None`). The regex requires exactly two VGPR operands, so any extra modifier text is refused rather than dropped. The `_dpp` path is unchanged. - The encoding in the docs matches the assembler: llvm-mc-19 (gfx1030) encodes `v_swaprel_b32 v12, v24` as `0x7e18d118`. - The m0 field split follows the documented naming and the PR itself says it was not measured on RDNA hardware. I could not check it against hardware either. **P2: the Linux-mode `tests/pixel_aot_check.py` does not pin the swap's values.** In the no-argument mode the new checks are text assertions (`"swap_doff" in ...`, `"dpp_soff" in ...`) and refusal controls. The value checks are the `draw-swaprel` and `draw-plain-movrel` modes, which need dxc and a D3D12 adapter. I applied one-line mutations to `tools/pixel_aot.py`, one at a time, and ran the check with no arguments. The check returned rc=0 for these four: - the select in the final loop reads `swap_sval` instead of `swap_dval` for the source-side registers - the static m0 halves swapped (`[m0_u & 0x3ff]` and `[(m0_u >> 16) & 0x3ff]` exchanged) - the dynamic source offsets taken from `m0_mask >> 16` - the destination-side select removed (`value = value`) It returned rc=1 for one: forcing `kind` to `v_movrels_b32_dpp` (the m0 range error). These escape the Linux run, so the swap semantics are guarded only by the Windows draw tests (`pixel_aot_swaprel_warp`, `pixel_aot_plain_movrel_warp`). I could not run those here. The PR text says the mutation controls mismatch on WARP and on a discrete adapter; I could not confirm that. A CI-visible Linux value check would help: for example, evaluate the emitted `swap_*` / `alu*_r*` lines on a few register states in Python, as the cmp_class check now does for its helper. **Request:** run the two WARP tests above on Windows Server 2025, and apply at least the first two mutations above through the Windows run to show they fail there. Other checks: - `tests/form_coverage_check.py`, the new `v_swaprel_b32` accepted-word control: pass. - The merge against current `main` (8e2923ae) has no content conflicts (`git merge-tree`). - The assembler-backed `binary llvm-mc-19 ...` modes of `pixel_aot_check.py` and `rdna2_tools_check.py` fail with the same assertions on the PR's merge base (for example `v_cvt_f16_i16_e32 v1, 0xfff0` decodes differently), so they are not caused by this PR. They expect a different assembler version, so the binary round trip of the three new fixtures was not exercised here. Commands run (Linux): - `git diff --check <merge-base>...HEAD`: clean - `tests/docs_links_check.py`: pass (18 files, 370 links) - `tests/bidi_controls_check.py`: pass - `tests/pixel_aot_check.py`: pass - `tests/rdna2_tools_check.py`: pass (148 tests, 18 skipped) - `tests/form_coverage_check.py`: pass - `tests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so` and `tests/rdna2_tools_check.py binary ...`: fail identically on the merge base (see above) - `llvm-mc-19 -triple=amdgcn -mcpu=gfx1030 -show-encoding` on the three new spellings - Mutations above, each restored with `git checkout -- .` AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 19:47 UTC · original · reviewed

Follow-up Win2025 verification on head 7a75c9ab72ebb12b25a34e0ca22cbc88cf4b110f:

  • Win2025 Debug (--preset dev): ctest --preset dev -R '^(pixel_aot_swaprel_warp|pixel_aot_plain_movrel_warp|pixel_aot_warp|rdna2_tools_check)$' — 4/4 passed (pixel_aot_swaprel_warp 4.57s, pixel_aot_plain_movrel_warp 6.55s, rdna2_tools_check 11.77s, pixel_aot_warp 14.71s).
  • Win2025 Release /O2 (--preset release): 4/4 passed (pixel_aot_swaprel_warp 3.33s, pixel_aot_plain_movrel_warp 6.38s, rdna2_tools_check 10.99s, pixel_aot_warp 14.26s).
  • Windows Python checks: tests/pixel_aot_check.py ok (9.9s), tests/form_coverage_check.py ok (17.0s).
  • Win2025 mutation check: mutating v_swaprel_b32 m0 shift >> 16 -> >> 17 in tools/pixel_aot.py failed cleanly (rc=1, tests/form_coverage_check.py rc=1).

No P1/P2 defects found.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 19:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1844#pullrequestreview-6046212226) · **reviewed** Follow-up Win2025 verification on head `7a75c9ab72ebb12b25a34e0ca22cbc88cf4b110f`: - **Win2025 Debug (`--preset dev`)**: `ctest --preset dev -R '^(pixel_aot_swaprel_warp|pixel_aot_plain_movrel_warp|pixel_aot_warp|rdna2_tools_check)$'` — **4/4 passed** (`pixel_aot_swaprel_warp` `4.57s`, `pixel_aot_plain_movrel_warp` `6.55s`, `rdna2_tools_check` `11.77s`, `pixel_aot_warp` `14.71s`). - **Win2025 Release `/O2` (`--preset release`)**: **4/4 passed** (`pixel_aot_swaprel_warp` `3.33s`, `pixel_aot_plain_movrel_warp` `6.38s`, `rdna2_tools_check` `10.99s`, `pixel_aot_warp` `14.26s`). - **Windows Python checks**: `tests/pixel_aot_check.py` ok (`9.9s`), `tests/form_coverage_check.py` ok (`17.0s`). - **Win2025 mutation check**: mutating `v_swaprel_b32` `m0` shift `>> 16` -> `>> 17` in `tools/pixel_aot.py` failed cleanly (`rc=1`, `tests/form_coverage_check.py` `rc=1`). No P1/P2 defects found. AI-assisted; commands listed were executed locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.