startup: draw the gfx2hlsl three-source integer vector operations #1706

Manually merged
github merged 2 commits from gh-pr/1706/head into gh-pr/1706/base 2026-11-26 23:27:40 +00:00
Owner

@⁠Asimmimx on GitHub · 2026-11-24 17:28 UTC · original
Asimmimx:startup/gfx2hlsl-int3-alu-check → main · +119 −0 · 4 files · 2 commits · merged 2026-11-26 02:17 UTC

Refs #1149.

Change

No check ran the ten three-source integer operations of the VEC_U table in tools/startup/gfx2hlsl.py: v_bfe_u32, v_mad_u32_u24, v_lshl_add_u32, v_add_lshl_u32, v_add3_u32, v_or3_b32, v_and_or_b32, v_lshl_or_b32, v_xad_u32 and v_bfi_b32. All ten are VOP3 only.

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

tests/startup_gfx2hlsl_int3_alu_check.py draws them with the per-lane runner tests/startup_gfx2hlsl_lane_alu.py. The runner is byte-identical to the copy in #1703, so the two PRs merge in either order without a conflict. In each draw:

  • a flat-input pixel fixture applies one operation per lane;
  • the four result words are compared exactly;
  • the recorded llvm-mc bodies are checked by a binary mode;
  • the controls cover accepted forms and refused modifiers (clamp, -v, |v|, op_sel) and operand counts.

The references follow the AMD RDNA 2 ISA reference with plain integer arithmetic:

  • v_bfe_u32: an unsigned field of width S2[4:0] at offset S1[4:0];
  • v_mad_u32_u24: the product of the low 24 bits of S0 and S1;
  • shift counts come from bits 4:0;
  • sums wrap at 32 bits;
  • v_bfi_b32: the insert (S0 & S1) | (~S0 & S2).

Each operation has eight input sets, which is two draws. They include widths and counts above 31 (33, 40), sources with bits above bit 23, and sums that wrap.

Mutations, one per operation. The first draw with the mutated lowering must read the mutation's own reference words:

  • the bfe mask without - 1;
  • a full-width first factor in v_mad_u32_u24;
  • add and OR exchanged in v_lshl_add_u32 and v_lshl_or_b32;
  • a 4-bit shift count in v_add_lshl_u32;
  • a + b - c for v_add3_u32;
  • XOR for v_or3_b32;
  • XOR for the OR in v_and_or_b32;
  • OR for the XOR in v_xad_u32;
  • an insert without the complement.

Results

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

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

There were no skips.

One observation. My first bfe mutation masked the width to 4 bits, (1u << (w & 15)) - 1. FXC ps_5_1 compiled that mutated shader to one that read 00000000 in all four channels on WARP. Lane 0 had width 8, where the mask makes no difference, and the correct lowering read 00000067 there. I replaced the mutation because it no longer tested only the lowering. The correct lowering matched through both compilers on both adapters.

AI-assisted (Claude Code).

**@⁠Asimmimx** on GitHub · 2026-11-24 17:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1706) `Asimmimx:startup/gfx2hlsl-int3-alu-check` → `main` · +119 −0 · 4 files · 2 commits · merged 2026-11-26 02:17 UTC Refs #1149. ## Change No check ran the ten three-source integer operations of the `VEC_U` table in `tools/startup/gfx2hlsl.py`: `v_bfe_u32`, `v_mad_u32_u24`, `v_lshl_add_u32`, `v_add_lshl_u32`, `v_add3_u32`, `v_or3_b32`, `v_and_or_b32`, `v_lshl_or_b32`, `v_xad_u32` and `v_bfi_b32`. All ten are VOP3 only. This PR adds a check only. The translator does not change. `tests/startup_gfx2hlsl_int3_alu_check.py` draws them with the per-lane runner `tests/startup_gfx2hlsl_lane_alu.py`. The runner is byte-identical to the copy in #1703, so the two PRs merge in either order without a conflict. In each draw: - a flat-input pixel fixture applies one operation per lane; - the four result words are compared exactly; - the recorded llvm-mc bodies are checked by a `binary` mode; - the controls cover accepted forms and refused modifiers (`clamp`, `-v`, `|v|`, `op_sel`) and operand counts. The references follow the AMD RDNA 2 ISA reference with plain integer arithmetic: - `v_bfe_u32`: an unsigned field of width S2[4:0] at offset S1[4:0]; - `v_mad_u32_u24`: the product of the low 24 bits of S0 and S1; - shift counts come from bits 4:0; - sums wrap at 32 bits; - `v_bfi_b32`: the insert `(S0 & S1) | (~S0 & S2)`. Each operation has eight input sets, which is two draws. They include widths and counts above 31 (33, 40), sources with bits above bit 23, and sums that wrap. **Mutations, one per operation.** The first draw with the mutated lowering must read the mutation's own reference words: - the bfe mask without `- 1`; - a full-width first factor in `v_mad_u32_u24`; - add and OR exchanged in `v_lshl_add_u32` and `v_lshl_or_b32`; - a 4-bit shift count in `v_add_lshl_u32`; - `a + b - c` for `v_add3_u32`; - XOR for `v_or3_b32`; - XOR for the OR in `v_and_or_b32`; - OR for the XOR in `v_xad_u32`; - an insert without the complement. ## Results Commit `b5b8168e` on `origin/main`. Windows 11 26300.9974, DXC 1.8.2502.11, FXC 10.0.26100, debug layer on. ``` python -B tests/startup_gfx2hlsl_int3_alu_check.py # controls: all ok python -B tests/startup_gfx2hlsl_int3_alu_check.py binary <llvm-mc 19.1.1> # fixture words match llvm-mc python -B tests/startup_gfx2hlsl_int3_alu_check.py draw <dxc> <offscreen_check> <adapter> <fxc> ``` | Adapter | Driver | Draws (FXC ps_5_1 + DXC ps_6_0) | Mutated draws | |---|---|---|---| | WARP | 10.0.26100.9818 | 40/40 match | 20/20 read the mutated words | | AMD Radeon RX 6600 (RDNA 2) | 32.0.21045.29003 | 40/40 match | 20/20 read the mutated words | There were no skips. **One observation.** My first bfe mutation masked the width to 4 bits, `(1u << (w & 15)) - 1`. FXC `ps_5_1` compiled that mutated shader to one that read `00000000` in all four channels on WARP. Lane 0 had width 8, where the mask makes no difference, and the correct lowering read `00000067` there. I replaced the mutation because it no longer tested only the lowering. The correct lowering matched through both compilers on both adapters. AI-assisted (Claude Code).
The VEC_U table lowers v_bfe_u32, v_mad_u32_u24, v_lshl_add_u32,
v_add_lshl_u32, v_add3_u32, v_or3_b32, v_and_or_b32, v_lshl_or_b32,
v_xad_u32 and v_bfi_b32, and no check ran any of them.

tests/startup_gfx2hlsl_int3_alu_check.py draws them with the shared
per-lane runner (tests/startup_gfx2hlsl_lane_alu.py, byte-identical to the
copy in the two-source family PR): one operation per lane on flat inputs,
exact result words, against references written from the RDNA 2 ISA
(field extract with S1[4:0]/S2[4:0], 24-bit products, shift counts from
bits 4:0, wrapping sums, bitfield insert), with widths and counts above 31,
bits above bit 23 and wrapping sums. Each operation has one mutated
lowering whose first draw must read its own mutated words.

All 40 draws match on WARP and an RX 6600 through FXC ps_5_1 and DXC
ps_6_0; the 20 mutated draws read their mutated words.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:27:34 +00:00
github manually merged commit 4efb99c462 into gh-pr/1706/base 2026-11-26 23:27:40 +00:00
Author
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-24 22:28 UTC · original

Hardware run of head b5b8168e. 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_int3_alu_controls Passed
startup_gfx2hlsl_int3_alu_warp Passed
startup_gfx2hlsl_int3_alu_hardware on the Quadro M1000M Passed
startup_gfx2hlsl_int3_alu_hardware on the HD 530 Passed

No changes made.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-24 22:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1706#issuecomment-7146264450) Hardware run of head b5b8168e. 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_int3_alu_controls` | Passed | | `startup_gfx2hlsl_int3_alu_warp` | Passed | | `startup_gfx2hlsl_int3_alu_hardware` on the Quadro M1000M | Passed | | `startup_gfx2hlsl_int3_alu_hardware` on the HD 530 | Passed | No changes made.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 12:52 UTC · original

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

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

Files that conflict with current main (4aaea119):

  • tests/startup_gfx2hlsl_lane_alu.py

Commands run locally:

git fetch origin main pull/1706/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1706 --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.

**@⁠tedin7** on GitHub · 2026-11-25 12:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1706#issuecomment-7162986669) @⁠Asimmimx could you rebase this branch onto current `main` and force-push? GitHub reports head `b5b8168e` as conflicting with `main`, so it cannot be merged as is. Files that conflict with current `main` (`4aaea119`): - `tests/startup_gfx2hlsl_lane_alu.py` Commands run locally: ``` git fetch origin main pull/1706/head git merge-tree --write-tree --name-only origin/main FETCH_HEAD gh pr view 1706 --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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 02:15 UTC · original

Pushed one merge commit (4efb99c46, no force, no rebase) that merges current main into this branch. This clears the only conflict GitHub reported, tests/startup_gfx2hlsl_lane_alu.py (add/add).

Resolution: kept main's copy of that file. Against the branch's copy it differs in three places only: the pipeline: docstring line and the **family.get('pipeline', {}) keyword arguments passed to G.Pipeline in translate() and in the draw loop. No other file in the PR conflicted, and nothing in tools/ changed.

Commands executed:

  • git merge origin/main, then git checkout --theirs tests/startup_gfx2hlsl_lane_alu.py (add/add)
  • python3 tests/startup_gfx2hlsl_int3_alu_check.py (Linux, translation controls, mutations, refused/accepted forms): all ok
  • Windows Server 2025, MSVC 14.44.35207, D3D12 WARP, at b5b8168e plus the one-file diff of lane_alu.py above: ctest -R startup_gfx2hlsl_int3_alu -> 3/3 passed on dev and 3/3 passed on release

The merged tree itself was checked on Linux only; the Windows run used the PR head with the resolved lane_alu.py applied.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-26 02:15 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1706#issuecomment-7180623534) Pushed one merge commit (`4efb99c46`, no force, no rebase) that merges current `main` into this branch. This clears the only conflict GitHub reported, `tests/startup_gfx2hlsl_lane_alu.py` (add/add). Resolution: kept `main`'s copy of that file. Against the branch's copy it differs in three places only: the `pipeline:` docstring line and the `**family.get('pipeline', {})` keyword arguments passed to `G.Pipeline` in `translate()` and in the draw loop. No other file in the PR conflicted, and nothing in `tools/` changed. Commands executed: - `git merge origin/main`, then `git checkout --theirs tests/startup_gfx2hlsl_lane_alu.py` (add/add) - `python3 tests/startup_gfx2hlsl_int3_alu_check.py` (Linux, translation controls, mutations, refused/accepted forms): all ok - Windows Server 2025, MSVC 14.44.35207, D3D12 WARP, at `b5b8168e` plus the one-file diff of `lane_alu.py` above: `ctest -R startup_gfx2hlsl_int3_alu` -> 3/3 passed on `dev` and 3/3 passed on `release` The merged tree itself was checked on Linux only; the Windows run used the PR head with the resolved `lane_alu.py` applied. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 17:35 UTC · original · reviewed

Review of head b5b8168e669f66114538d64d57b431cfea81134e. Tests, CMake, CI list and docs only; no change to tools/startup/gfx2hlsl.py. Verdict: 0 P1, 0 P2.

Linux limits. Linux x86_64, llvm-mc-19 (the new CI entry pins llvm-mc-15), Python 3.14. No Windows, no DXC/FXC, no GPU: I could NOT run the draw mode, so the claimed WARP and RX 6600 results, the 40 matching draws and the 20 mutated draws are not verified by me.

What I ran

  • python3 -B tests/startup_gfx2hlsl_int3_alu_check.py (controls): passes, exit 0. ... binary llvm-mc-19: fixture words match llvm-mc, exit 0.
  • Semantics, independent of the PR: I wrote references for the ten operations from the ISA text and compared them with the VEC_U expressions in tools/startup/gfx2hlsl.py (formatted and evaluated in Python with 32-bit masking) on 6000 input triples each (edge values 0, 1, 31, 32, 33, 0xffffff, 0x1000000, 0x7fffffff, 0x80000000, all-ones, plus random): 0 mismatches for v_bfe_u32, v_mad_u32_u24, v_lshl_add_u32, v_add_lshl_u32, v_add3_u32, v_or3_b32, v_and_or_b32, v_lshl_or_b32, v_xad_u32, v_bfi_b32. The test's own references agree with the ISA wording (width and offset from bits 4:0, 24-bit multiply inputs, (S0 & S1) | (~S0 & S2)). Not covered by my check: how FXC/DXC compile these expressions.
  • Mutations (restored with git checkout -- .):
    • test fixture opcode of v_add3_u32 0x6d -> 0x6c: FAILED in binary mode (assembled words differ), as intended.
    • production v_bfi_b32 without the complement, and v_add3_u32 with - {2}: the controls FAILED, but only because the mutation regex of the control no longer matches the changed text (count == 4 and mutated != text), not because a value was compared.
    • production v_add_lshl_u32 with operands exchanged (({0} + {2}) << ({1} & 31), same shape): controls PASSED, not caught.

Notes

  • On Linux the controls prove that the ten bodies translate, that four lanes come out, that accepted and refused forms behave, and that each mutation changes the reference; wrong operand order or a wrong operator that keeps the text's shape is detected only by the draws on a Windows adapter. Please make sure those ran for this head.
  • CI wiring (windows.yml CHECKS entry with binary llvm-mc-15, the no-argument step, three ctest entries with the same SKIP/timeout conventions as the neighbours) looks consistent; I did not run Actions.
  • git diff --check, docs_links_check, bidi_controls_check: clean.

Not approving (comment only).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 17:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1706#pullrequestreview-6044284708) · **reviewed** Review of head `b5b8168e669f66114538d64d57b431cfea81134e`. Tests, CMake, CI list and docs only; no change to `tools/startup/gfx2hlsl.py`. **Verdict: 0 P1, 0 P2.** **Linux limits.** Linux x86_64, `llvm-mc-19` (the new CI entry pins `llvm-mc-15`), Python 3.14. No Windows, no DXC/FXC, no GPU: I could NOT run the `draw` mode, so the claimed WARP and RX 6600 results, the 40 matching draws and the 20 mutated draws are not verified by me. **What I ran** - `python3 -B tests/startup_gfx2hlsl_int3_alu_check.py` (controls): passes, exit 0. `... binary llvm-mc-19`: `fixture words match llvm-mc`, exit 0. - Semantics, independent of the PR: I wrote references for the ten operations from the ISA text and compared them with the `VEC_U` expressions in `tools/startup/gfx2hlsl.py` (formatted and evaluated in Python with 32-bit masking) on 6000 input triples each (edge values 0, 1, 31, 32, 33, 0xffffff, 0x1000000, 0x7fffffff, 0x80000000, all-ones, plus random): 0 mismatches for `v_bfe_u32`, `v_mad_u32_u24`, `v_lshl_add_u32`, `v_add_lshl_u32`, `v_add3_u32`, `v_or3_b32`, `v_and_or_b32`, `v_lshl_or_b32`, `v_xad_u32`, `v_bfi_b32`. The test's own references agree with the ISA wording (width and offset from bits 4:0, 24-bit multiply inputs, `(S0 & S1) | (~S0 & S2)`). Not covered by my check: how FXC/DXC compile these expressions. - Mutations (restored with `git checkout -- .`): - test fixture opcode of `v_add3_u32` 0x6d -> 0x6c: FAILED in `binary` mode (assembled words differ), as intended. - production `v_bfi_b32` without the complement, and `v_add3_u32` with `- {2}`: the controls FAILED, but only because the mutation regex of the control no longer matches the changed text (`count == 4 and mutated != text`), not because a value was compared. - production `v_add_lshl_u32` with operands exchanged (`({0} + {2}) << ({1} & 31)`, same shape): controls PASSED, not caught. **Notes** - On Linux the controls prove that the ten bodies translate, that four lanes come out, that accepted and refused forms behave, and that each mutation changes the reference; wrong operand order or a wrong operator that keeps the text's shape is detected only by the draws on a Windows adapter. Please make sure those ran for this head. - CI wiring (`windows.yml` CHECKS entry with `binary llvm-mc-15`, the no-argument step, three ctest entries with the same SKIP/timeout conventions as the neighbours) looks consistent; I did not run Actions. - `git diff --check`, `docs_links_check`, `bidi_controls_check`: clean. Not approving (comment only). AI-assisted; commands listed were executed locally.
Author
Owner

@⁠stan495 on GitHub · 2026-11-25 05:48 UTC · original · approved these changes

Verified head b5b8168e on Windows x64 (dev preset, MSVC 19.44.35228.0, SDK 10.0.26100.0, DXC/FXC 10.0.26100.0):

  • cmake --build --preset dev --target offscreen_check -> succeeded
  • ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_int3_alu' -V -> 3/3 passed (startup_gfx2hlsl_int3_alu_controls, startup_gfx2hlsl_int3_alu_warp, startup_gfx2hlsl_int3_alu_hardware)
    • Hardware: AMD Radeon RX 7900 XTX (vendor=1002 device=744c, driver 32.0.32029.2010)
    • WARP: Microsoft Basic Render Driver (vendor=1414 device=008c, driver 10.0.26100.9818)

Verdict: Approved at b5b8168e.

**@⁠stan495** on GitHub · 2026-11-25 05:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1706#pullrequestreview-6052478013) · **approved these changes** Verified head `b5b8168e` on Windows x64 (`dev` preset, MSVC `19.44.35228.0`, SDK `10.0.26100.0`, DXC/FXC `10.0.26100.0`): - `cmake --build --preset dev --target offscreen_check` -> succeeded - `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_int3_alu' -V` -> 3/3 passed (`startup_gfx2hlsl_int3_alu_controls`, `startup_gfx2hlsl_int3_alu_warp`, `startup_gfx2hlsl_int3_alu_hardware`) - Hardware: `AMD Radeon RX 7900 XTX` (`vendor=1002 device=744c`, driver `32.0.32029.2010`) - WARP: `Microsoft Basic Render Driver` (`vendor=1414 device=008c`, driver `10.0.26100.9818`) Verdict: Approved at `b5b8168e`.
This discussion has been locked. Commenting is limited to contributors.
No description provided.