shader: lower gfx1013 byte and bit funnel VOP3 instructions in pixel_aot #525

Open
Vonsek wants to merge 1 commit from upstream-pr/531 into main
Vonsek commented 2026-11-22 09:51:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-22T09:51:11Z.


Change

tools/pixel_aot.py lowers six VOP3-only byte and bit instructions through the existing INTEGER table, following the AMD RDNA 2 ISA reference: v_alignbit_b32, v_alignbyte_b32, v_perm_b32 (helper perm_b32), v_lerp_u8 (helper lerp_u8), v_sad_u8 (helper sad_u8) and v_sad_u16 (helper sad_u16). Alignbit/alignbyte lower to (S1 >> n) | ((S0 << 1u) << (31u - n)) so no shift reaches 32 at n = 0. Perm selectors: 0-3 bytes of S1, 4-7 bytes of S0, 8-11 replicate bit 15/31/47/63 of the pair, 12 gives 0x00, 13-255 give 0xff. SAD sums wrap modulo 2^32. Source modifiers, op_sel, clamp, wrong operand counts, 33-bit immediates, unwritten registers, outstanding loads and WQM are rejected. tools/scan_unsupported_shaders.py recognises the new forms from the same table. v_sad_u32 is left out and stays rejected (see below).

Tests: tests/pixel_aot_check.py adds bytes_program(k) with 10 results over SGPR, VGPR, inline and literal operands, exported byte-exact through v_cvt_f32_ubyte0-3, checked against Python models of the ISA definitions over two input sets. New mode draw-bytes, registered as pixel_aot_bytes_hardware and pixel_aot_bytes_warp (60 s, FORM_COVERAGE_RECORD, hardware skips with 77): 20 positive draws plus nine negative draws (five program mutations, four wrong reference models) that must report pixel_mismatch. Controls cover the exact HLSL, helper emission, the selector table, all rejected modifiers and the neighbouring v_sad_u32, v_sad_hi_u8, v_msad_u8, v_mqsad_u32_u8, v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8, v_permlane16_b32, v_permlanex16_b32. tests/form_coverage_check.py asserts exactly 6 new forms in gfx1013.tsv and rdna2.tsv; tests/rdna2_tools_check.py covers the scanner. docs/experiments.md#offline-pixel-shader-recompilation documents it.

Verification

  • Linux, LLVM 18: tests/pixel_aot_check.py binary ..., the controls, form_coverage_check.py, rdna2_tools_check.py, pso_readiness_check.py, docs_links_check.py, bidi_controls_check.py and git diff --check pass. With tools/pixel_aot.py from main the new tests fail with Unsupported instruction ... v_alignbit_b32.
  • The helpers compiled as C matched the Python reference on 20,000 random operand triples.
  • Windows, RTX 5080 and WARP: ctest --preset dev --no-tests=error -R '^pixel_aot_(bytes_(hardware|warp)|hardware|warp)$' -V at fd1ff6f on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, DXC 1.9.2602.17: 4/4 passed. DXC compiled every bytes_program variant; all 20 positive draws matched the reference and all nine negative draws reported pixel_mismatch, on an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) and on WARP. pixel_aot_bytes_hardware took 7.9-8.1 s and pixel_aot_bytes_warp 2.0 s, well under the 60 s timeout; pixel_aot_hardware (20.2 s) and pixel_aot_warp (5.8 s) still pass. The D3D12 debug layer was not available. The full ctest --preset dev --no-tests=error passed 245/245, with bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp skipped.

Evidence and follow-up

  • Semantics follow the RDNA 2 ISA reference, not measured on Scarlett.
  • v_sad_u32: the ISA text gives a signed difference, while the AMDGPU backend selects it for an unsigned one (umax - umin + c). They disagree for operands of different sign (e.g. 0xf3a1b8eb, 0x17272174), so the form stays a rejected neighbour until measured.
  • Interaction with #526: whichever merges second must drop v_alignbit_b32, v_alignbyte_b32, v_perm_b32 and v_lerp_u8 from #526's rejected-neighbour lists; v_sad_u32 stays rejected in both. The hunks do not overlap.
  • Still uncovered nearby: v_msad_u8, v_sad_hi_u8, v_qsad_pk_u16_u8, v_mqsad_*, v_permlane16_b32, v_permlanex16_b32.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5437826712 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/531). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-22T09:51:11Z. --- ## Change `tools/pixel_aot.py` lowers six VOP3-only byte and bit instructions through the existing `INTEGER` table, following the AMD RDNA 2 ISA reference: `v_alignbit_b32`, `v_alignbyte_b32`, `v_perm_b32` (helper `perm_b32`), `v_lerp_u8` (helper `lerp_u8`), `v_sad_u8` (helper `sad_u8`) and `v_sad_u16` (helper `sad_u16`). Alignbit/alignbyte lower to `(S1 >> n) | ((S0 << 1u) << (31u - n))` so no shift reaches 32 at n = 0. Perm selectors: 0-3 bytes of S1, 4-7 bytes of S0, 8-11 replicate bit 15/31/47/63 of the pair, 12 gives 0x00, 13-255 give 0xff. SAD sums wrap modulo 2^32. Source modifiers, `op_sel`, `clamp`, wrong operand counts, 33-bit immediates, unwritten registers, outstanding loads and WQM are rejected. `tools/scan_unsupported_shaders.py` recognises the new forms from the same table. `v_sad_u32` is left out and stays rejected (see below). Tests: `tests/pixel_aot_check.py` adds `bytes_program(k)` with 10 results over SGPR, VGPR, inline and literal operands, exported byte-exact through `v_cvt_f32_ubyte0`-`3`, checked against Python models of the ISA definitions over two input sets. New mode `draw-bytes`, registered as `pixel_aot_bytes_hardware` and `pixel_aot_bytes_warp` (60 s, `FORM_COVERAGE_RECORD`, hardware skips with 77): 20 positive draws plus nine negative draws (five program mutations, four wrong reference models) that must report `pixel_mismatch`. Controls cover the exact HLSL, helper emission, the selector table, all rejected modifiers and the neighbouring `v_sad_u32`, `v_sad_hi_u8`, `v_msad_u8`, `v_mqsad_u32_u8`, `v_qsad_pk_u16_u8`, `v_mqsad_pk_u16_u8`, `v_permlane16_b32`, `v_permlanex16_b32`. `tests/form_coverage_check.py` asserts exactly 6 new forms in `gfx1013.tsv` and `rdna2.tsv`; `tests/rdna2_tools_check.py` covers the scanner. `docs/experiments.md#offline-pixel-shader-recompilation` documents it. ## Verification - Linux, LLVM 18: `tests/pixel_aot_check.py binary ...`, the controls, `form_coverage_check.py`, `rdna2_tools_check.py`, `pso_readiness_check.py`, `docs_links_check.py`, `bidi_controls_check.py` and `git diff --check` pass. With `tools/pixel_aot.py` from `main` the new tests fail with `Unsupported instruction ... v_alignbit_b32`. - The helpers compiled as C matched the Python reference on 20,000 random operand triples. - Windows, RTX 5080 and WARP: `ctest --preset dev --no-tests=error -R '^pixel_aot_(bytes_(hardware|warp)|hardware|warp)$' -V` at fd1ff6f on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, DXC 1.9.2602.17: 4/4 passed. DXC compiled every `bytes_program` variant; all 20 positive draws matched the reference and all nine negative draws reported `pixel_mismatch`, on an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) and on WARP. `pixel_aot_bytes_hardware` took 7.9-8.1 s and `pixel_aot_bytes_warp` 2.0 s, well under the 60 s timeout; `pixel_aot_hardware` (20.2 s) and `pixel_aot_warp` (5.8 s) still pass. The D3D12 debug layer was not available. The full `ctest --preset dev --no-tests=error` passed 245/245, with `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp` skipped. ## Evidence and follow-up - Semantics follow the RDNA 2 ISA reference, not measured on Scarlett. - `v_sad_u32`: the ISA text gives a signed difference, while the AMDGPU backend selects it for an unsigned one (`umax - umin + c`). They disagree for operands of different sign (e.g. `0xf3a1b8eb`, `0x17272174`), so the form stays a rejected neighbour until measured. - Interaction with #526: whichever merges second must drop `v_alignbit_b32`, `v_alignbyte_b32`, `v_perm_b32` and `v_lerp_u8` from #526's rejected-neighbour lists; `v_sad_u32` stays rejected in both. The hunks do not overlap. - Still uncovered nearby: `v_msad_u8`, `v_sad_hi_u8`, `v_qsad_pk_u16_u8`, `v_mqsad_*`, `v_permlane16_b32`, `v_permlanex16_b32`.
tedin7 commented 2026-11-27 09:37:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T09:37:34Z.


This PR now conflicts with main. Conflicting files:

  • CMakeLists.txt
  • docs/experiments.md
  • tests/form_coverage_check.py
  • tests/pixel_aot_check.py
  • tests/rdna2_tools_check.py
  • tools/pixel_aot.py

Could you merge main into your branch (a merge commit, no force push needed) and resolve these? Thank you.

AI-assisted; commands listed were executed locally. (git merge-tree origin/main <head>)

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7214901860 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/531#issuecomment-7214901860). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T09:37:34Z. --- This PR now conflicts with `main`. Conflicting files: - `CMakeLists.txt` - `docs/experiments.md` - `tests/form_coverage_check.py` - `tests/pixel_aot_check.py` - `tests/rdna2_tools_check.py` - `tools/pixel_aot.py` Could you merge `main` into your branch (a merge commit, no force push needed) and resolve these? Thank you. AI-assisted; commands listed were executed locally. (`git merge-tree origin/main <head>`)
Leyukaka commented 2026-11-29 10:10:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T10:10:53Z.


@Vonsek status of the six forms against main c3259f27 (tools/pixel_aot.py):

Already on main:

  • v_alignbit_b32, v_alignbyte_b32: INTEGER table, lines 857-858 (#692, 4d7eb03f).
  • v_sad_u8, v_sad_u16: lines 882 and 884 (#1656, 86ffc079). v_sad_hi_u8, v_sad_u32 and v_msad_u8 are also there (lines 883, 885, 886; #779, dc893933).

Not on main:

  • v_perm_b32, v_lerp_u8: no match in tools/pixel_aot.py or tests/pixel_aot_check.py.

Could you narrow the branch to v_perm_b32 and v_lerp_u8 and merge main? It conflicts in CMakeLists.txt, docs/experiments.md, tests/form_coverage_check.py, tests/pixel_aot_check.py, tests/rdna2_tools_check.py and tools/pixel_aot.py.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7254261971 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/531#issuecomment-7254261971). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T10:10:53Z. --- @Vonsek status of the six forms against main `c3259f27` (`tools/pixel_aot.py`): Already on main: - `v_alignbit_b32`, `v_alignbyte_b32`: `INTEGER` table, lines 857-858 (#692, `4d7eb03f`). - `v_sad_u8`, `v_sad_u16`: lines 882 and 884 (#1656, `86ffc079`). `v_sad_hi_u8`, `v_sad_u32` and `v_msad_u8` are also there (lines 883, 885, 886; #779, `dc893933`). Not on main: - `v_perm_b32`, `v_lerp_u8`: no match in `tools/pixel_aot.py` or `tests/pixel_aot_check.py`. Could you narrow the branch to `v_perm_b32` and `v_lerp_u8` and merge main? It conflicts in `CMakeLists.txt`, `docs/experiments.md`, `tests/form_coverage_check.py`, `tests/pixel_aot_check.py`, `tests/rdna2_tools_check.py` and `tools/pixel_aot.py`.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/531:upstream-pr/531'
git switch 'upstream-pr/531'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/531'
git switch 'upstream-pr/531'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/531'
git switch 'upstream-pr/531'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/531'
git switch 'main'
git merge --squash 'upstream-pr/531'
git switch 'main'
git merge --ff-only 'upstream-pr/531'
git switch 'main'
git merge 'upstream-pr/531'
git push origin 'main'
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!525
No description provided.