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

Merged
Asimmimx merged 2 commits from upstream-pr/1706 into main 2026-11-26 02:17:34 +00:00
Asimmimx commented 2026-11-24 17:28:57 +00:00 (Migrated from github.com)

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


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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587623616 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1706). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T17:28:57Z. --- 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).
tedin7 commented 2026-11-24 18:02:41 +00:00 (Migrated from github.com)

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

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044284708 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1706#pullrequestreview-6044284708). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:35:14Z. **Review:** COMMENTED --- 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.
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:03Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7146264450 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1706#issuecomment-7146264450). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-24T22:28:03Z. --- 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.
stan495 commented 2026-11-25 06:01:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-25T05:48:22Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6052478013 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1706#pullrequestreview-6052478013). Originally posted by [stan495](https://github.com/stan495) on 2026-11-25T05:48:22Z. **Review:** APPROVED --- 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`.
tedin7 commented 2026-11-25 13:01:01 +00:00 (Migrated from github.com)

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


@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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7162986669 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1706#issuecomment-7162986669). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:52:56Z. --- @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.
upstream-sync closed this pull request 2026-11-26 03:02:47 +00:00
tedin7 commented 2026-11-26 03:03:21 +00:00 (Migrated from github.com)

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


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7180623534 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1706#issuecomment-7180623534). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:15:45Z. --- 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.
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!1699
No description provided.