shader: lower the SDWA v_movrel* forms in pixel_aot #1927

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/1934 into main 2026-11-24 22:02:34 +00:00
legacy-code-archaeologist commented 2026-11-24 21:42:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T21:42:10Z.


Refs #1917. I built this before the issue had a maintainer reply; if you want the scope narrowed, I'll adjust. This completes the VGPR movrel encodings: plain (#1785), DPP (already there), SDWA (here), swaprel (#1844) and scalar (#1894).

What

tools/pixel_aot.py lowers v_movreld_b32_sdwa, v_movrels_b32_sdwa, v_movrelsd_b32_sdwa and v_movrelsd_2_b32_sdwa through the existing movrel block. LLVM 15 spells them identically for gfx1013 and gfx1030, for example 7e1886f9 00001518 as v_movrels_b32_sdwa v12, v24 dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE src0_sel:BYTE_0.

  • Unchanged: the m0 rules, the refusals and the source-before-destination reads.

  • Selections, applied as v_mov_b32_sdwa applies them (sdwa_source, sdwa_dest):

    • the source selection, with an optional sext(...), applies to the indexed source word;
    • the destination selection applies to each indexed destination;
    • UNUSED_PRESERVE keeps the unselected bits from that destination's own tracked old value, so under a dynamic m0 each reachable destination merges its own word.
    • This order is an assumption: it follows the RDNA 2 naming and the other movrel forms, and has not been measured on RDNA hardware.
  • Refused:

    • UNUSED_SEXT;
    • UNUSED_PRESERVE into an untracked destination;
    • clamp;
    • 16-bit (low-half) values as the source or as the kept destination;
    • SGPR sources;
    • the movrel refusals.

    Under a dynamic m0, every reachable destination must hold a tracked numeric word, also for UNUSED_PAD, as for the other movrel forms.

Evidence

SDWA_MOVREL_BODY (tests/pixel_aot_check.py) runs each move with a dynamic and then a static m0 over integer banks. It mixes BYTE, WORD and DWORD selections, sext, UNUSED_PAD and UNUSED_PRESERVE, and exports four words through the bit-exact R32G32B32A32_UINT target, where they must equal an independent SDWA model. The expected words on the two DPP_MOVREL_SETS:

0x008856aa 0x3600ffbb 0xffffffdd 0x332143bb
0x00cc56aa 0x3600ffb9 0x0048ffdd 0x887743bb
  • Draw controls (pixel_mismatch required):
    • a dropped source selection;
    • UNUSED_PRESERVE turned into UNUSED_PAD;
    • an ignored dynamic m0;
    • the wrong source byte;
    • a missing sext.
  • Translation controls: nine refusals, the entry mask, and a dynamic UNUSED_PRESERVE move inside one bank in which each reachable register merges its own old word.

Windows 11 Pro 26100.9168, DXC 10.0.26100, debug layer unavailable:

ctest --preset dev --no-tests=error -R "^pixel_aot_sdwa_movrel_" -V
Adapter Driver Result
WARP 10.0.26100.8972 bit-exact on both sets; all 5 controls mismatched
NVIDIA Quadro M1000M 32.0.15.7371 same

Other runs:

  • LLVM 15 round trip: tests/pixel_aot_check.py binary passes. llvm-mc is clang 15.0.7's integrated assembler, with llvm-objcopy and LLVM-C.dll from the same build.
  • Full ctest --preset dev -E '_hardware$': 854/854.
  • After the rebase onto #1875:
    • the sdwa/plain/swaprel/smovrel movrel draws pass, 8/8;
    • the no-argument controls exit 0;
    • tests/form_coverage_check.py passes;
    • tools/form_coverage.py --gaps gfx1030 no longer lists any v_movrel* form.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6591986008 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1934). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-24T21:42:10Z. --- Refs #1917. I built this before the issue had a maintainer reply; if you want the scope narrowed, I'll adjust. This completes the VGPR movrel encodings: plain (#1785), DPP (already there), SDWA (here), swaprel (#1844) and scalar (#1894). ## What `tools/pixel_aot.py` lowers `v_movreld_b32_sdwa`, `v_movrels_b32_sdwa`, `v_movrelsd_b32_sdwa` and `v_movrelsd_2_b32_sdwa` through the existing movrel block. LLVM 15 spells them identically for gfx1013 and gfx1030, for example `7e1886f9 00001518` as `v_movrels_b32_sdwa v12, v24 dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE src0_sel:BYTE_0`. - **Unchanged:** the `m0` rules, the refusals and the source-before-destination reads. - **Selections**, applied as `v_mov_b32_sdwa` applies them (`sdwa_source`, `sdwa_dest`): - the source selection, with an optional `sext(...)`, applies to the indexed source word; - the destination selection applies to each indexed destination; - `UNUSED_PRESERVE` keeps the unselected bits from that destination's own tracked old value, so under a dynamic `m0` each reachable destination merges its own word. - **This order is an assumption:** it follows the RDNA 2 naming and the other movrel forms, and has not been measured on RDNA hardware. - **Refused:** - `UNUSED_SEXT`; - `UNUSED_PRESERVE` into an untracked destination; - `clamp`; - 16-bit (low-half) values as the source or as the kept destination; - SGPR sources; - the movrel refusals. Under a dynamic `m0`, every reachable destination must hold a tracked numeric word, also for `UNUSED_PAD`, as for the other movrel forms. ## Evidence `SDWA_MOVREL_BODY` (`tests/pixel_aot_check.py`) runs each move with a dynamic and then a static `m0` over integer banks. It mixes BYTE, WORD and DWORD selections, `sext`, `UNUSED_PAD` and `UNUSED_PRESERVE`, and exports four words through the bit-exact `R32G32B32A32_UINT` target, where they must equal an independent SDWA model. The expected words on the two `DPP_MOVREL_SETS`: ``` 0x008856aa 0x3600ffbb 0xffffffdd 0x332143bb 0x00cc56aa 0x3600ffb9 0x0048ffdd 0x887743bb ``` - **Draw controls** (`pixel_mismatch` required): - a dropped source selection; - `UNUSED_PRESERVE` turned into `UNUSED_PAD`; - an ignored dynamic `m0`; - the wrong source byte; - a missing `sext`. - **Translation controls:** nine refusals, the entry mask, and a dynamic `UNUSED_PRESERVE` move inside one bank in which each reachable register merges its own old word. Windows 11 Pro 26100.9168, DXC 10.0.26100, debug layer unavailable: ``` ctest --preset dev --no-tests=error -R "^pixel_aot_sdwa_movrel_" -V ``` | Adapter | Driver | Result | |---|---|---| | WARP | 10.0.26100.8972 | bit-exact on both sets; all 5 controls mismatched | | NVIDIA Quadro M1000M | 32.0.15.7371 | same | **Other runs:** - **LLVM 15 round trip:** `tests/pixel_aot_check.py binary` passes. `llvm-mc` is clang 15.0.7's integrated assembler, with `llvm-objcopy` and `LLVM-C.dll` from the same build. - Full `ctest --preset dev -E '_hardware$'`: 854/854. - After the rebase onto #1875: - the sdwa/plain/swaprel/smovrel movrel draws pass, 8/8; - the no-argument controls exit 0; - `tests/form_coverage_check.py` passes; - `tools/form_coverage.py --gaps gfx1030` no longer lists any `v_movrel*` form. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tedin7 commented 2026-11-24 22:00:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:45:42Z.

Review: COMMENTED


Review of head bc03f191030951c765c8d1af26f415b6041fdb7a.

Result: 0 P1, 0 P2. The change is correct and clean-room. I am not merging it, because older open PRs already cover the same files (see "Merge note").

What I read:

  • tools/pixel_aot.py: SDWA v_movreld/movrels/movrelsd/movrelsd_2 are lowered through the existing movrel block. sdwa_source applies to the indexed source word. sdwa_dest applies to each reachable destination, merging that destination's own tracked old value for UNUSED_PRESERVE. UNUSED_SEXT and an unbalanced sext( are refused.
  • CMakeLists.txt: only registers pixel_aot_sdwa_movrel_${adapter}.
  • docs/experiments.md: describes the behavior and says the operand order is not measured on RDNA hardware.
  • No copied vendor code.

Commands run locally (exit codes):

  • python3 -B tests/pixel_aot_check.py: 0
  • python3 tests/docs_links_check.py: 0 (18 files, 386 links)
  • python3 tests/bidi_controls_check.py: 0
  • git diff --check origin/main...HEAD: 0
  • git merge-tree --write-tree --name-only origin/main HEAD: no conflicts
  • Windows Server 2025 node, x2w_pipe.py win2025 1934 scoped to ^pixel_aot_(sdwa_movrel|swaprel|smovrel)_: Debug 6/6 and Release /O2 6/6 passed. form_coverage_check.py passed there.

Mutations (each reverted afterwards):

  1. Dropped sdwa_source(...) in the movrel block. pixel_aot_check.py on Linux still passes, so the translation checks do not pin the source selection. The pixel_aot_sdwa_movrel_warp and pixel_aot_sdwa_movrel_hardware draws on Windows fail, so the GPU test kills it.
  2. Replaced the dynamic-m0 sdwa_dest(...) merge with the raw value. pixel_aot_check.py fails, so it is killed.

Non-blocking suggestion: pin a source-selection text in the Linux translation controls too. Then mutation 1 fails without a GPU.

CI at the time of review: the Linux Python job passed. The two Windows jobs and the fixtures job were still pending.

Merge note: #1923, #1790, #1612, #1670 and #1572 are older, open and not drafts. They rewrite CMakeLists.txt, docs/experiments.md, tests/pixel_aot_check.py and tools/pixel_aot.py in the same regions. They have no CHANGES_REQUESTED, so the competing-PR gate stays closed. This one will need a rebase after any of them lands.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047915854 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1934#pullrequestreview-6047915854). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T21:45:42Z. **Review:** COMMENTED --- Review of head `bc03f191030951c765c8d1af26f415b6041fdb7a`. Result: 0 P1, 0 P2. The change is correct and clean-room. I am not merging it, because older open PRs already cover the same files (see "Merge note"). What I read: - `tools/pixel_aot.py`: SDWA `v_movreld/movrels/movrelsd/movrelsd_2` are lowered through the existing movrel block. `sdwa_source` applies to the indexed source word. `sdwa_dest` applies to each reachable destination, merging that destination's own tracked old value for `UNUSED_PRESERVE`. `UNUSED_SEXT` and an unbalanced `sext(` are refused. - `CMakeLists.txt`: only registers `pixel_aot_sdwa_movrel_${adapter}`. - `docs/experiments.md`: describes the behavior and says the operand order is not measured on RDNA hardware. - No copied vendor code. Commands run locally (exit codes): - `python3 -B tests/pixel_aot_check.py`: 0 - `python3 tests/docs_links_check.py`: 0 (18 files, 386 links) - `python3 tests/bidi_controls_check.py`: 0 - `git diff --check origin/main...HEAD`: 0 - `git merge-tree --write-tree --name-only origin/main HEAD`: no conflicts - Windows Server 2025 node, `x2w_pipe.py win2025 1934` scoped to `^pixel_aot_(sdwa_movrel|swaprel|smovrel)_`: Debug 6/6 and Release /O2 6/6 passed. `form_coverage_check.py` passed there. Mutations (each reverted afterwards): 1. Dropped `sdwa_source(...)` in the movrel block. `pixel_aot_check.py` on Linux still passes, so the translation checks do not pin the source selection. The `pixel_aot_sdwa_movrel_warp` and `pixel_aot_sdwa_movrel_hardware` draws on Windows fail, so the GPU test kills it. 2. Replaced the dynamic-`m0` `sdwa_dest(...)` merge with the raw value. `pixel_aot_check.py` fails, so it is killed. Non-blocking suggestion: pin a source-selection text in the Linux translation controls too. Then mutation 1 fails without a GPU. CI at the time of review: the Linux Python job passed. The two Windows jobs and the fixtures job were still pending. Merge note: #1923, #1790, #1612, #1670 and #1572 are older, open and not drafts. They rewrite `CMakeLists.txt`, `docs/experiments.md`, `tests/pixel_aot_check.py` and `tools/pixel_aot.py` in the same regions. They have no CHANGES_REQUESTED, so the competing-PR gate stays closed. This one will need a rebase after any of them lands. AI-assisted; commands listed were executed locally.
ChazY11 commented 2026-11-24 22:01:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T21:57:34Z.


Ran it, and found one lowering effect the fixture does not pin

Windows 11 build 26300.9974, device-free path only:

out/pe-env/Scripts/python.exe -B tests/pixel_aot_check.py
exit 0

(pixel_aot_check.py binary needs <llvm-mc> <llvm-objcopy> <libLLVM> on this machine and exits 1 with a usage line, so the
LLVM round trip did not run for me — that is my environment, not your branch.)

Mutations

mutation result
SDWA_MOVREL_PATTERN no longer matched (plain forms only) caught
UNUSED_SEXT refusal disabled caught
the first sdwa_dest(...) call replaced by pass caught
swizzled = sdwa_source(swizzled, sdwa_sel[0], sdwa_sel[1]) replaced by pass not caught

The last one is a real behavioural change, not an equivalent mutant. With SDWA_MOVREL_BODY:

unmutated:  uint dpp_val49 = ((asuint(dpp_src49) >> 0u) & 0xffffu);
mutated:    uint dpp_val49 = asuint(dpp_src49);

i.e. the source selection (src0_sel) stops being applied and the raw word flows into the destination write. The check still
passes.

Why it passes

The positive case is asserted at line 16481:

sdwa_hlsl = translate_int(uncompressed_export(SDWA_MOVREL_BODY))
assert "dpp_soff" in sdwa_hlsl and "dpp_doff" in sdwa_hlsl and "QuadRead" not in sdwa_hlsl

which establishes the instruction is accepted and does not become a quad read, but says nothing about the two selections being
applied. Everything else added in this area is a refusal case (UNUSED_PRESERVE, UNUSED_SEXT, clamp, dynamic m0, the
v24, v25 pair, missing m0), so the accepted path is only tested by presence of two identifiers.

Suggested fix, one line each, in the same style the DPP cases already use:

assert "((asuint(dpp_src27) >> 24u) & 0xffu)" in sdwa_hlsl      # src0_sel:BYTE_3 with sext
assert "((asuint(alu30) & 0xffff0000u) | ((dpp_val37 & 0xffffu) << 0u))" in sdwa_hlsl   # dst_sel:WORD_0

(Those two substrings come from the unmutated output above; pick whichever cases your body actually contains — the point is that
one substring per selection should be required, so dropping either call fails.)

What is good here

The refusal set is thorough, the m0 rules are shared with the plain forms rather than copied, and UNUSED_SEXT/UNUSED_PRESERVE
being refused rather than guessed is the right call — UNUSED_PRESERVE needs a tracked numeric destination and the error says so.

Verdict

One blocking-ish gap: the source selection is unpinned. Everything else I could break was caught.

Notes

  • AI-assisted review.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7145615627 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1934#issuecomment-7145615627). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T21:57:34Z. --- ## Ran it, and found one lowering effect the fixture does not pin Windows 11 build 26300.9974, device-free path only: ```powershell out/pe-env/Scripts/python.exe -B tests/pixel_aot_check.py exit 0 ``` (`pixel_aot_check.py binary` needs `<llvm-mc> <llvm-objcopy> <libLLVM>` on this machine and exits 1 with a usage line, so the LLVM round trip did not run for me — that is my environment, not your branch.) ## Mutations | mutation | result | |---|---| | `SDWA_MOVREL_PATTERN` no longer matched (plain forms only) | **caught** | | `UNUSED_SEXT` refusal disabled | **caught** | | the first `sdwa_dest(...)` call replaced by `pass` | **caught** | | **`swizzled = sdwa_source(swizzled, sdwa_sel[0], sdwa_sel[1])` replaced by `pass`** | **not caught** | The last one is a real behavioural change, not an equivalent mutant. With `SDWA_MOVREL_BODY`: ```text unmutated: uint dpp_val49 = ((asuint(dpp_src49) >> 0u) & 0xffffu); mutated: uint dpp_val49 = asuint(dpp_src49); ``` i.e. the source selection (`src0_sel`) stops being applied and the raw word flows into the destination write. The check still passes. ## Why it passes The positive case is asserted at line 16481: ```python sdwa_hlsl = translate_int(uncompressed_export(SDWA_MOVREL_BODY)) assert "dpp_soff" in sdwa_hlsl and "dpp_doff" in sdwa_hlsl and "QuadRead" not in sdwa_hlsl ``` which establishes the instruction is *accepted* and does not become a quad read, but says nothing about the two selections being *applied*. Everything else added in this area is a refusal case (`UNUSED_PRESERVE`, `UNUSED_SEXT`, clamp, dynamic `m0`, the `v24, v25` pair, missing `m0`), so the accepted path is only tested by presence of two identifiers. Suggested fix, one line each, in the same style the DPP cases already use: ```python assert "((asuint(dpp_src27) >> 24u) & 0xffu)" in sdwa_hlsl # src0_sel:BYTE_3 with sext assert "((asuint(alu30) & 0xffff0000u) | ((dpp_val37 & 0xffffu) << 0u))" in sdwa_hlsl # dst_sel:WORD_0 ``` (Those two substrings come from the unmutated output above; pick whichever cases your body actually contains — the point is that one substring per selection should be required, so dropping either call fails.) ## What is good here The refusal set is thorough, the `m0` rules are shared with the plain forms rather than copied, and `UNUSED_SEXT`/`UNUSED_PRESERVE` being refused rather than guessed is the right call — `UNUSED_PRESERVE` needs a tracked numeric destination and the error says so. ## Verdict One blocking-ish gap: the source selection is unpinned. Everything else I could break was caught. ## Notes - AI-assisted review.
upstream-sync closed this pull request 2026-11-24 23:03:06 +00:00
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
R0Y00/Xbox2Windows!1927
No description provided.