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

Open
github-bot wants to merge 1 commit from github-bot/gh-531 into main AGit
Owner

@⁠Vonsek on GitHub · 2026-11-22 09:51 UTC · original
Vonsek:pixel-aot-align-perm → main · +312 −0 · 6 files · 1 commits · draft

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.
**@⁠Vonsek** on GitHub · 2026-11-22 09:51 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/531) `Vonsek:pixel-aot-align-perm` → `main` · +312 −0 · 6 files · 1 commits · draft ## 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`.
Lower v_alignbit_b32, v_alignbyte_b32, v_perm_b32, v_lerp_u8, v_sad_u8
and v_sad_u16 to HLSL uint expressions or small helpers that follow the
RDNA 2 ISA definitions. Source modifiers, op_sel, clamp and the
neighbouring byte forms, including v_sad_u32, stay rejected.

A new fixture exports each of 10 results byte by byte through
v_cvt_f32_ubyte0-3 for two input sets in its own CTest pair,
pixel_aot_bytes_{hardware,warp}, with mutated programs and wrong
reference models as negative controls. Form coverage and the shader
scanner count the six forms.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:59:20 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-27 09:37 UTC · original

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

**@⁠tedin7** on GitHub · 2026-11-27 09:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/531#issuecomment-7214901860) 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>`)
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-29 10:10 UTC · original

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

**@⁠Leyukaka** on GitHub · 2026-11-29 10:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/531#issuecomment-7254261971) @⁠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 has changes conflicting with the target branch.
  • CMakeLists.txt
  • docs/experiments.md
  • tests/form_coverage_check.py
  • tests/pixel_aot_check.py
  • tests/rdna2_tools_check.py
  • tools/pixel_aot.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/531/head:github-bot/gh-531'
git switch 'github-bot/gh-531'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-531'
git switch 'github-bot/gh-531'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-531'
git switch 'github-bot/gh-531'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-531'
git switch 'main'
git merge --squash 'github-bot/gh-531'
git switch 'main'
git merge --ff-only 'github-bot/gh-531'
git switch 'main'
git merge 'github-bot/gh-531'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.