startup: draw the gfx2hlsl two-source integer vector operations #1696

Merged
Asimmimx merged 3 commits from upstream-pr/1703 into main 2026-11-26 02:27:31 +00:00
Asimmimx commented 2026-11-24 17:25:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T17:25:24Z.


Refs #1149.

Change

The VEC_U table of tools/startup/gfx2hlsl.py lowers 16 two- and one-source integer vector operations to single HLSL expressions. No check ran any of them: no startup test names any of these mnemonics.

v_add_nc_u32, v_sub_nc_u32, v_subrev_nc_u32, v_mul_lo_u32, v_and_b32, v_or_b32, v_xor_b32, v_not_b32, v_lshlrev_b32, v_lshrrev_b32, v_ashrrev_i32, v_min_u32, v_max_u32, v_min_i32, v_max_i32, v_mul_u32_u24

This PR adds a check only. The translator does not change.

  • tests/startup_gfx2hlsl_lane_alu.py is a small runner for table families. It reuses the pixel fixture of startup_gfx2hlsl_bit_alu_check.py, which reads three flat parameters per pixel, applies one operation per lane and exports v12..v15 to mrt0, so the renderer compares four exact words. Per family it provides:
    • the recorded llvm-mc -mcpu=gfx1013 pixel bodies, plus a binary mode that reassembles them;
    • controls for accepted and refused forms;
    • a draw per four input sets;
    • one mutated lowering per operation, whose first draw must read the words the mutation's own reference gives.
  • tests/startup_gfx2hlsl_int_alu_check.py is the first family. Lanes alternate the _e32 and _e64 spellings; v_mul_lo_u32 exists only as VOP3. The references follow the AMD RDNA 2 ISA reference with plain integer arithmetic, not the lowering's expressions:
    • 32-bit wrapping arithmetic;
    • the rev shifts take S1 shifted by S0[4:0];
    • v_ashrrev_i32 is an arithmetic shift;
    • comparisons are signed or unsigned as the name says;
    • v_mul_u32_u24 takes the product of the low 24 bits.

Each operation has eight input sets, which is two draws. They include shift counts above 31 (33, 32, 0xffffffe1), sign-bit values for the signed and unsigned pairs, products that wrap, and sources with bits above bit 23.

The mutations (one per operation):

  • add as subtract;
  • both subtract orders exchanged;
  • a 24-bit v_mul_lo_u32, a full-width v_mul_u32_u24;
  • AND as OR, OR as XOR, XOR as OR, NOT dropped;
  • shift operands exchanged, the count masked to 4 bits, a logical shift for the arithmetic one;
  • min and max exchanged, unsigned comparisons for the signed pair.

The tests are registered as startup_gfx2hlsl_int_alu_controls and startup_gfx2hlsl_int_alu_{warp,hardware} next to the bit-operation tests. The check is added to the LLVM 15 binary list and to the platform-independent Python job, and docs/experiments.md gets a section.

Results

Commit 63e73fc8 on origin/main. Windows 11 26300.9974, DXC 1.8.2502.11, FXC 10.0.26100, debug layer on.

python -B tests/startup_gfx2hlsl_int_alu_check.py                       # controls: all ok
python -B tests/startup_gfx2hlsl_int_alu_check.py binary <llvm-mc 19.1.1>  # fixture words match llvm-mc
python -B tests/startup_gfx2hlsl_int_alu_check.py draw <dxc> <offscreen_check> warp <fxc>
...
warp: 64 draws matched, 32 mutated draws read their mutated words
Adapter Driver Draws (FXC ps_5_1 + DXC ps_6_0) Mutated draws
WARP 10.0.26100.9818 64/64 match 32/32 read the mutated words
AMD Radeon RX 6600 (RDNA 2) 32.0.21045.29003 64/64 match 32/32 read the mutated words

There were no skips. The existing startup_gfx2hlsl_bit_alu_check.py controls still pass, and so do docs_links_check.py and bidi_controls_check.py. ctest --preset dev -N -R int_alu lists the three tests.

I also ran the existing startup_gfx2hlsl_bit_alu draw on both adapters, which docs/experiments.md says has not been run on WARP or hardware yet. 46 draws matched and 12 mutated draws failed as expected on each. That is outside this PR's diff; I can record it separately.

The runner is meant for the remaining table families (three-source integer forms, conversions, float and scalar operations). Each would come as its own PR.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587559724 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1703). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T17:25:24Z. --- Refs #1149. ## Change The `VEC_U` table of `tools/startup/gfx2hlsl.py` lowers 16 two- and one-source integer vector operations to single HLSL expressions. No check ran any of them: no startup test names any of these mnemonics. `v_add_nc_u32`, `v_sub_nc_u32`, `v_subrev_nc_u32`, `v_mul_lo_u32`, `v_and_b32`, `v_or_b32`, `v_xor_b32`, `v_not_b32`, `v_lshlrev_b32`, `v_lshrrev_b32`, `v_ashrrev_i32`, `v_min_u32`, `v_max_u32`, `v_min_i32`, `v_max_i32`, `v_mul_u32_u24` This PR adds a check only. The translator does not change. - **`tests/startup_gfx2hlsl_lane_alu.py`** is a small runner for table families. It reuses the pixel fixture of `startup_gfx2hlsl_bit_alu_check.py`, which reads three flat parameters per pixel, applies one operation per lane and exports v12..v15 to mrt0, so the renderer compares four exact words. Per family it provides: - the recorded `llvm-mc -mcpu=gfx1013` pixel bodies, plus a `binary` mode that reassembles them; - controls for accepted and refused forms; - a draw per four input sets; - one mutated lowering per operation, whose first draw must read the words the mutation's own reference gives. - **`tests/startup_gfx2hlsl_int_alu_check.py`** is the first family. Lanes alternate the `_e32` and `_e64` spellings; `v_mul_lo_u32` exists only as VOP3. The references follow the AMD RDNA 2 ISA reference with plain integer arithmetic, not the lowering's expressions: - 32-bit wrapping arithmetic; - the `rev` shifts take S1 shifted by S0[4:0]; - `v_ashrrev_i32` is an arithmetic shift; - comparisons are signed or unsigned as the name says; - `v_mul_u32_u24` takes the product of the low 24 bits. Each operation has eight input sets, which is two draws. They include shift counts above 31 (33, 32, `0xffffffe1`), sign-bit values for the signed and unsigned pairs, products that wrap, and sources with bits above bit 23. The mutations (one per operation): - add as subtract; - both subtract orders exchanged; - a 24-bit `v_mul_lo_u32`, a full-width `v_mul_u32_u24`; - AND as OR, OR as XOR, XOR as OR, NOT dropped; - shift operands exchanged, the count masked to 4 bits, a logical shift for the arithmetic one; - min and max exchanged, unsigned comparisons for the signed pair. The tests are registered as `startup_gfx2hlsl_int_alu_controls` and `startup_gfx2hlsl_int_alu_{warp,hardware}` next to the bit-operation tests. The check is added to the LLVM 15 `binary` list and to the platform-independent Python job, and `docs/experiments.md` gets a section. ## Results Commit `63e73fc8` on `origin/main`. Windows 11 26300.9974, DXC 1.8.2502.11, FXC 10.0.26100, debug layer on. ``` python -B tests/startup_gfx2hlsl_int_alu_check.py # controls: all ok python -B tests/startup_gfx2hlsl_int_alu_check.py binary <llvm-mc 19.1.1> # fixture words match llvm-mc python -B tests/startup_gfx2hlsl_int_alu_check.py draw <dxc> <offscreen_check> warp <fxc> ... warp: 64 draws matched, 32 mutated draws read their mutated words ``` | Adapter | Driver | Draws (FXC ps_5_1 + DXC ps_6_0) | Mutated draws | |---|---|---|---| | WARP | 10.0.26100.9818 | 64/64 match | 32/32 read the mutated words | | AMD Radeon RX 6600 (RDNA 2) | 32.0.21045.29003 | 64/64 match | 32/32 read the mutated words | There were no skips. The existing `startup_gfx2hlsl_bit_alu_check.py` controls still pass, and so do `docs_links_check.py` and `bidi_controls_check.py`. `ctest --preset dev -N -R int_alu` lists the three tests. I also ran the existing `startup_gfx2hlsl_bit_alu` draw on both adapters, which `docs/experiments.md` says has not been run on WARP or hardware yet. 46 draws matched and 12 mutated draws failed as expected on each. That is outside this PR's diff; I can record it separately. The runner is meant for the remaining table families (three-source integer forms, conversions, float and scalar operations). Each would come as its own PR. AI-assisted (Claude Code).
tedin7 commented 2026-11-24 18:02:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:28:18Z.

Review: COMMENTED


Review of head 63e73fc8c405865e0a74d5c8fa9ac5cd79fa7828 (1 commit; 5 files, +306/-0: .github/workflows/windows.yml +2, CMakeLists.txt +10, docs/experiments.md +17, two new tests; no change to tools/startup/gfx2hlsl.py).

Linux limits. Linux x86_64 only. No CMake configure and no ctest (the new startup_gfx2hlsl_int_alu_* registrations are unexercised), no Windows, no DXC or FXC, no WARP or GPU. The draw mode and the quoted "64 draws matched / 32 mutated draws" on WARP and an RX 6600 are therefore not reproduced by me.

What I ran

  • python3 -B tests/startup_gfx2hlsl_int_alu_check.py (translation controls): PASS, all 16 operations.
  • ... binary llvm-mc-19: fixture words match llvm-mc. The recorded body words are byte-identical to llvm-mc 19 output (CI passes llvm-mc 15; I did not run 15).
  • git diff --check origin/main...HEAD: clean. tests/bidi_controls_check.py and tests/docs_links_check.py: pass.
  • Workflow diff: the two added lines mirror startup_gfx2hlsl_bit_alu_check.py exactly (the binary llvm-mc-15 entry in the pixel-binary list, and the plain script entry in the Linux Python list). No permission, trigger, action or secret line is touched.
  • Independent semantic check (no GPU): I translated every operation with the repo's Pipeline.hlsl_ps(), took the four lane expressions, evaluated them in Python with 32-bit wrap (uint(), int() as signed, min, max), and compared them with the test's references on all 128 input sets. 128 of 128 match. The lowerings in VEC_U agree with the RDNA 2 semantics the test states (subrev is S1 - S0, "rev" shifts use S0[4:0], v_ashrrev_i32 is arithmetic, v_mul_u32_u24 masks both sources to 24 bits).
  • Three local mutations of VEC_U, each run and restored (git status clean):
    • v_subrev_nc_u32 as {0} - {1}: the PR's Linux controls still PASS (exit 0); my evaluation reports 6 wrong words.
    • v_mul_u32_u24 without the 24-bit masks: controls exit 1, but only because the test's own mutation regex no longer matches (count == 4 assertion), not because the lowering is judged wrong; my evaluation reports 4 wrong words.
    • v_lshrrev_b32 with & 15: same, exit 1 through the regex assertion; evaluation reports 2 wrong words.

Findings

  1. The no-argument controls (the only part that runs on Linux CI and in startup_gfx2hlsl_int_alu_controls) never compare the emitted HLSL with the reference. They check lane naming, set sizes, that each mutation changes the first draw, and the accepted/refused forms. A wrong lowering such as the subrev swap passes them; only the warp and hardware draws can catch it, and those skip (exit 77) without DXC or a device. The same holds for the sibling bit-operation check, so I do not block on it. A cheap addition would be a pure-Python evaluation of the emitted lane expressions against ops, like the one I ran, so the semantics are guarded without a GPU.
  2. Minor. The docs say these operations had no check before. Other tests do name them (pixel_aot_check.py, compute_store_check.py), but those cover other translators, so the claim holds for gfx2hlsl.py. A few words ("in the startup translator") would remove the doubt.
  3. Not verified here: the WARP and RX 6600 numbers, FXC ps_5_1, and the llvm-mc 15 CI path.

No defect found in the lowerings or the workflow change.

AI-assisted review; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044184201 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1703#pullrequestreview-6044184201). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:28:18Z. **Review:** COMMENTED --- Review of head `63e73fc8c405865e0a74d5c8fa9ac5cd79fa7828` (1 commit; 5 files, +306/-0: `.github/workflows/windows.yml` +2, `CMakeLists.txt` +10, `docs/experiments.md` +17, two new tests; no change to `tools/startup/gfx2hlsl.py`). **Linux limits.** Linux x86_64 only. No CMake configure and no `ctest` (the new `startup_gfx2hlsl_int_alu_*` registrations are unexercised), no Windows, no DXC or FXC, no WARP or GPU. The `draw` mode and the quoted "64 draws matched / 32 mutated draws" on WARP and an RX 6600 are therefore not reproduced by me. **What I ran** - `python3 -B tests/startup_gfx2hlsl_int_alu_check.py` (translation controls): PASS, all 16 operations. - `... binary llvm-mc-19`: `fixture words match llvm-mc`. The recorded body words are byte-identical to llvm-mc 19 output (CI passes llvm-mc 15; I did not run 15). - `git diff --check origin/main...HEAD`: clean. `tests/bidi_controls_check.py` and `tests/docs_links_check.py`: pass. - Workflow diff: the two added lines mirror `startup_gfx2hlsl_bit_alu_check.py` exactly (the `binary llvm-mc-15` entry in the pixel-binary list, and the plain script entry in the Linux Python list). No permission, trigger, action or secret line is touched. - Independent semantic check (no GPU): I translated every operation with the repo's `Pipeline.hlsl_ps()`, took the four lane expressions, evaluated them in Python with 32-bit wrap (`uint()`, `int()` as signed, `min`, `max`), and compared them with the test's references on all 128 input sets. 128 of 128 match. The lowerings in `VEC_U` agree with the RDNA 2 semantics the test states (subrev is S1 - S0, "rev" shifts use S0[4:0], `v_ashrrev_i32` is arithmetic, `v_mul_u32_u24` masks both sources to 24 bits). - Three local mutations of `VEC_U`, each run and restored (`git status` clean): - `v_subrev_nc_u32` as `{0} - {1}`: the PR's Linux controls still PASS (exit 0); my evaluation reports 6 wrong words. - `v_mul_u32_u24` without the 24-bit masks: controls exit 1, but only because the test's own mutation regex no longer matches (`count == 4` assertion), not because the lowering is judged wrong; my evaluation reports 4 wrong words. - `v_lshrrev_b32` with `& 15`: same, exit 1 through the regex assertion; evaluation reports 2 wrong words. **Findings** 1. The no-argument controls (the only part that runs on Linux CI and in `startup_gfx2hlsl_int_alu_controls`) never compare the emitted HLSL with the reference. They check lane naming, set sizes, that each mutation changes the first draw, and the accepted/refused forms. A wrong lowering such as the subrev swap passes them; only the `warp` and `hardware` draws can catch it, and those skip (exit 77) without DXC or a device. The same holds for the sibling bit-operation check, so I do not block on it. A cheap addition would be a pure-Python evaluation of the emitted lane expressions against `ops`, like the one I ran, so the semantics are guarded without a GPU. 2. Minor. The docs say these operations had no check before. Other tests do name them (`pixel_aot_check.py`, `compute_store_check.py`), but those cover other translators, so the claim holds for `gfx2hlsl.py`. A few words ("in the startup translator") would remove the doubt. 3. Not verified here: the WARP and RX 6600 numbers, FXC `ps_5_1`, and the llvm-mc 15 CI path. No defect found in the lowerings or the workflow change. AI-assisted review; commands listed were executed locally.
legacy-code-archaeologist commented 2026-11-24 23:03:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T22:28:02Z.


Hardware run of head 63e73fc8. Windows 11 Pro 26100.9168, DXC/FXC from Windows SDK 10.0.26100, dev preset, debug layer unavailable here. Adapter selected with XBOX2WINDOWS_ADAPTER: WARP 10.0.26100.8972, NVIDIA Quadro M1000M (Maxwell, 10de:13b1) 32.0.15.7371, Intel HD Graphics 530 (Gen9, 8086:191b) 31.0.101.2111.

Test Result
startup_gfx2hlsl_int_alu_controls Passed
startup_gfx2hlsl_int_alu_warp Passed
startup_gfx2hlsl_int_alu_hardware on the Quadro M1000M Passed
startup_gfx2hlsl_int_alu_hardware on the HD 530 Passed

No changes made.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7146264058 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1703#issuecomment-7146264058). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-24T22:28:02Z. --- Hardware run of head 63e73fc8. Windows 11 Pro 26100.9168, DXC/FXC from Windows SDK 10.0.26100, `dev` preset, debug layer unavailable here. Adapter selected with `XBOX2WINDOWS_ADAPTER`: WARP 10.0.26100.8972, NVIDIA Quadro M1000M (Maxwell, 10de:13b1) 32.0.15.7371, Intel HD Graphics 530 (Gen9, 8086:191b) 31.0.101.2111. | Test | Result | |---|---| | `startup_gfx2hlsl_int_alu_controls` | Passed | | `startup_gfx2hlsl_int_alu_warp` | Passed | | `startup_gfx2hlsl_int_alu_hardware` on the Quadro M1000M | Passed | | `startup_gfx2hlsl_int_alu_hardware` on the HD 530 | Passed | No changes made.
tedin7 commented 2026-11-25 13:01:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:53:31Z.


@Asimmimx could you rebase this branch onto current main and force-push?

GitHub reports head 63e73fc8 as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (cf97bee1):

  • .github/workflows/windows.yml
  • CMakeLists.txt
  • docs/experiments.md
  • tests/startup_gfx2hlsl_lane_alu.py

Commands run locally:

git fetch origin main pull/1703/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1703 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7163000162 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1703#issuecomment-7163000162). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:53:31Z. --- @Asimmimx could you rebase this branch onto current `main` and force-push? GitHub reports head `63e73fc8` as conflicting with `main`, so it cannot be merged as is. Files that conflict with current `main` (`cf97bee1`): - `.github/workflows/windows.yml` - `CMakeLists.txt` - `docs/experiments.md` - `tests/startup_gfx2hlsl_lane_alu.py` Commands run locally: ``` git fetch origin main pull/1703/head git merge-tree --write-tree --name-only origin/main FETCH_HEAD gh pr view 1703 --json mergeable # CONFLICTING ``` Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 03:02:46 +00:00
tedin7 commented 2026-11-26 03:03:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:24:31Z.


Merged origin/main into this branch (two commits, head b1a7d6d6a, fast-forward from 63e73fc8c) so the PR no longer conflicts. No author test code was changed.

Conflicts, all mechanical:

  • .github/workflows/windows.yml (two blocks), CMakeLists.txt and docs/experiments.md: kept both sides.
  • tests/startup_gfx2hlsl_lane_alu.py: add/add, because #1706 added the same helper. Took main's version, which is a superset (it adds the optional pipeline keyword argument); startup_gfx2hlsl_int_alu_check.py runs unchanged against it.
  • Keeping both sides in CMakeLists.txt left this PR's foreach(adapter ...) unclosed, so the second commit adds the missing endforeach().

Verification:

  • python3 -B tests/startup_gfx2hlsl_int_alu_check.py and tests/startup_gfx2hlsl_lane_alu.py: PASS (Linux)
  • x2w_pipe.py win2025 1703 --patch <merge diff> --targets offscreen_check --regex startup_gfx2hlsl_int_alu: dev 3/3 and release 3/3 passed (startup_gfx2hlsl_int_alu_controls, _warp, _hardware).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7180776730 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1703#issuecomment-7180776730). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:24:31Z. --- Merged `origin/main` into this branch (two commits, head `b1a7d6d6a`, fast-forward from `63e73fc8c`) so the PR no longer conflicts. No author test code was changed. Conflicts, all mechanical: - `.github/workflows/windows.yml` (two blocks), `CMakeLists.txt` and `docs/experiments.md`: kept both sides. - `tests/startup_gfx2hlsl_lane_alu.py`: add/add, because #1706 added the same helper. Took main's version, which is a superset (it adds the optional `pipeline` keyword argument); `startup_gfx2hlsl_int_alu_check.py` runs unchanged against it. - Keeping both sides in `CMakeLists.txt` left this PR's `foreach(adapter ...)` unclosed, so the second commit adds the missing `endforeach()`. Verification: - `python3 -B tests/startup_gfx2hlsl_int_alu_check.py` and `tests/startup_gfx2hlsl_lane_alu.py`: PASS (Linux) - `x2w_pipe.py win2025 1703 --patch <merge diff> --targets offscreen_check --regex startup_gfx2hlsl_int_alu`: dev 3/3 and release 3/3 passed (`startup_gfx2hlsl_int_alu_controls`, `_warp`, `_hardware`). AI-assisted; commands listed were executed locally.
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!1696
No description provided.