shader: lower v_perm_b32 and v_lerp_u8 in the direct C++ compute path #3016

Manually merged
github merged 1 commit from github-bot/gh-3016 into gh-pr/3016/base 2026-11-27 12:58:30 +00:00 AGit
Owner

@⁠archielcqp-a11y on GitHub · 2026-11-27 05:23 UTC · original
archielcqp-a11y:cpp/direct-perm-lerp → main · +215 −0 · 4 files · 1 commits · merged 2026-11-27 12:48 UTC

Fixes #3015 on cpp-migration (part of #2935, instruction coverage: integer ALU).

Summary

The direct compute frontend refused v_perm_b32 and v_lerp_u8 with direct DXIL lowering for <name>. Both now follow the RDNA 2 ISA definitions, as the gfx2hlsl.py lowerings in #2875 and #2873 state them.

  • v_perm_b32: each result byte i takes the selector s = S2[8i+7:8i].
    • s 0..7 picks byte s of {S0, S1}; S1 holds bytes 0..3.
    • s 8..11 gives 0xff or 0x00 from bit 15 of S1, bit 31 of S1, bit 15 of S0 or bit 31 of S0.
    • s 12 gives 0x00, and s 13..255 give 0xff.
  • v_lerp_u8: each byte is (S0 + S1 + S2[8i]) >> 1. Only the low bit of each S2 byte rounds.
  • Modifiers: neg, abs and clamp stay refused (direct ALU operand modifiers), which I checked for both opcodes. op_sel bits are ignored, as the path's existing rule does for the other 32-bit operations; this change doesn't alter that.

A local probe found both names. It compiles one instruction per VOP3 name of src/gfx1013_isa_tables.inl and isn't part of this change. On 999e17cd it refused 68 of 120 names.

Fixture

tests/native_perm_lerp_check.py controls|hardware (tests/cmake/native_perm_lerp.cmake). The words were assembled with LLVM 15 (llvm-mc -mcpu=gfx1013).

  • Dispatch: two groups of 32 lanes. G = L + 32g is the lane's global index.
  • v_perm_b32: S0 = 0x1b6c9e37, S1 = 0x80f07ad5, and the S2 bytes are 4G .. 4G+3, so the 64 lanes cover all 256 selectors. A second v_perm_b32 exchanges S0 and S1. The words differ at bits 15 and 31, and their bits 7 and 23 differ from 15 and 31.
  • v_lerp_u8: S1 = G * 0x9e3779b9, S0 = S1 ^ 0xff80017f, and S2 = G * 0x01030507.
  • Readback: the 192 results and the guard words are compared with a CPU reference.
  • Controls: spot values of both definitions. These references must each differ from the expected words:
    • S0 and S1 exchanged;
    • the sign read from bits 7 and 23;
    • selector 12 as 0xff;
    • the lerp rounding bit dropped, or taken from the whole S2 byte.

Results

cpp-migration 999e17cd plus this change, Windows 10 build 19045, NVIDIA GeForce RTX 3080, driver 32.0.15.9174.

Check Result
native_perm_lerp_controls pass
native_perm_lerp_hardware (local Agility replay, see below) pass: 192 words and the guards matched
Lowering mutated: sign always from S0 readback fails (words 16, 18)
Lowering mutated: lerp rounding bit dropped readback fails (word 13 first)
Lowering mutated: selector 12 as 0xff readback fails (words 20, 22)
native_align_bfm_hardware (neighbour, same local replay) pass
docs_links_check, bidi_controls_check pass
ctest --preset dev --no-tests=error -R '^native_perm_lerp_' -V

Capability skip. The registered native_store_replay uses the inbox D3D12 runtime. On Windows 10 that runtime doesn't report shader model 6.6, so native_perm_lerp_hardware reports a skip (77) here, as native_align_bfm_hardware does. The readback rows above used a local copy of the replay linked with the app-local Agility SDK exports (D3D12SDKVersion 620, as in offscreen_check). That copy isn't part of this change. A run on Windows 11 or with Agility would confirm the registered test.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠archielcqp-a11y** on GitHub · 2026-11-27 05:23 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3016) `archielcqp-a11y:cpp/direct-perm-lerp` → `main` · +215 −0 · 4 files · 1 commits · merged 2026-11-27 12:48 UTC Fixes #3015 on `cpp-migration` (part of #2935, instruction coverage: integer ALU). ## Summary The direct compute frontend refused `v_perm_b32` and `v_lerp_u8` with `direct DXIL lowering for <name>`. Both now follow the RDNA 2 ISA definitions, as the `gfx2hlsl.py` lowerings in #2875 and #2873 state them. - **`v_perm_b32`:** each result byte i takes the selector s = S2[8i+7:8i]. - s 0..7 picks byte s of {S0, S1}; S1 holds bytes 0..3. - s 8..11 gives 0xff or 0x00 from bit 15 of S1, bit 31 of S1, bit 15 of S0 or bit 31 of S0. - s 12 gives 0x00, and s 13..255 give 0xff. - **`v_lerp_u8`:** each byte is (S0 + S1 + S2[8i]) >> 1. Only the low bit of each S2 byte rounds. - **Modifiers:** neg, abs and clamp stay refused (`direct ALU operand modifiers`), which I checked for both opcodes. `op_sel` bits are ignored, as the path's existing rule does for the other 32-bit operations; this change doesn't alter that. A local probe found both names. It compiles one instruction per VOP3 name of `src/gfx1013_isa_tables.inl` and isn't part of this change. On `999e17cd` it refused 68 of 120 names. ## Fixture `tests/native_perm_lerp_check.py controls|hardware` (`tests/cmake/native_perm_lerp.cmake`). The words were assembled with LLVM 15 (`llvm-mc -mcpu=gfx1013`). - **Dispatch:** two groups of 32 lanes. G = L + 32g is the lane's global index. - **`v_perm_b32`:** S0 = 0x1b6c9e37, S1 = 0x80f07ad5, and the S2 bytes are 4G .. 4G+3, so the 64 lanes cover all 256 selectors. A second `v_perm_b32` exchanges S0 and S1. The words differ at bits 15 and 31, and their bits 7 and 23 differ from 15 and 31. - **`v_lerp_u8`:** S1 = G * 0x9e3779b9, S0 = S1 ^ 0xff80017f, and S2 = G * 0x01030507. - **Readback:** the 192 results and the guard words are compared with a CPU reference. - **Controls:** spot values of both definitions. These references must each differ from the expected words: - S0 and S1 exchanged; - the sign read from bits 7 and 23; - selector 12 as 0xff; - the lerp rounding bit dropped, or taken from the whole S2 byte. ## Results `cpp-migration` `999e17cd` plus this change, Windows 10 build 19045, NVIDIA GeForce RTX 3080, driver 32.0.15.9174. | Check | Result | |---|---| | `native_perm_lerp_controls` | pass | | `native_perm_lerp_hardware` (local Agility replay, see below) | pass: 192 words and the guards matched | | Lowering mutated: sign always from S0 | readback fails (words 16, 18) | | Lowering mutated: lerp rounding bit dropped | readback fails (word 13 first) | | Lowering mutated: selector 12 as 0xff | readback fails (words 20, 22) | | `native_align_bfm_hardware` (neighbour, same local replay) | pass | | `docs_links_check`, `bidi_controls_check` | pass | ```powershell ctest --preset dev --no-tests=error -R '^native_perm_lerp_' -V ``` **Capability skip.** The registered `native_store_replay` uses the inbox D3D12 runtime. On Windows 10 that runtime doesn't report shader model 6.6, so `native_perm_lerp_hardware` reports a skip (77) here, as `native_align_bfm_hardware` does. The readback rows above used a local copy of the replay linked with the app-local Agility SDK exports (`D3D12SDKVersion` 620, as in `offscreen_check`). That copy isn't part of this change. A run on Windows 11 or with Agility would confirm the registered test. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The direct compute frontend refused these two VOP3 byte operations. They
now follow the RDNA 2 ISA definitions, as the gfx2hlsl.py lowerings in
#2875 and #2873 state them. v_perm_b32 builds each byte from selector
byte S2[8i+7:8i]: 0..7 pick a byte of {S0, S1} (S1 low), 8..11 give 0xff
or 0x00 from bit 15 or 31 of S1 or S0, 12 gives 0x00 and 13..255 give
0xff. v_lerp_u8 is (S0 + S1 + S2[8i]) >> 1 for each byte. Source
modifiers and clamp stay refused.

tests/native_perm_lerp_check.py dispatches 64 lanes that cover all 256
selectors, an exchanged-source v_perm_b32 and per-lane v_lerp_u8
operands against a CPU reference. Its controls check that the exchanged,
sign-bit, selector-12 and lerp-rounding references differ.

AI-assisted (Claude Code); reviewed and run locally.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 05:27:16 +00:00
Author
Owner

@⁠KelboLive on GitHub · 2026-11-27 05:37 UTC · original · reviewed

What works

  1. Clean lowering of two VOP3 byte operations (v_perm_b32 and
    v_lerp_u8) that the direct compute frontend previously refused.
    The RDNA 2 ISA semantics match the gfx2hlsl.py lowerings in #2875
    and #2873.
  2. The byte-lambda helper byte(x, at) for extracting per-byte
    components is clean. The v_perm_b32 selector logic correctly handles
    all 256 selector values (0..7: byte pick, 8..11: sign extension, 12:
    zero, 13..255: ones).
  3. Good test fixture: two groups of 32 lanes cover all 256 v_perm
    selectors once; controls check mutant references for each key pattern.

Issues

  1. The ir.invoke("i32", "unaryBits.i32", ...) pattern from the
    preceding block isn't used here -- this is fine, the byte-level logic
    is simpler and correct without it.
  2. No explicit handling of op_sel on these opcodes (the existing
    rule for 32-bit operations ignores op_sel and this doesn't change
    that). This could be noted in the experiment doc for clarity.

Recommendations

  • Consider adding a note to the experiment doc about the op_sel
    behavior for these two opcodes.
  • The 4-byte loop could benefit from a comment explaining why i goes
    0..3 (one DWORD = 4 bytes, each result is a single 32-bit DWORD).

Overall

Good instruction coverage for byte-level VOP3 ops. The test fixture
correctly validates all 256 perm selectors. Approvable.

**@⁠KelboLive** on GitHub · 2026-11-27 05:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3016#pullrequestreview-6083924362) · **reviewed** ## What works 1. Clean lowering of two VOP3 byte operations (v_perm_b32 and v_lerp_u8) that the direct compute frontend previously refused. The RDNA 2 ISA semantics match the gfx2hlsl.py lowerings in #2875 and #2873. 2. The byte-lambda helper `byte(x, at)` for extracting per-byte components is clean. The v_perm_b32 selector logic correctly handles all 256 selector values (0..7: byte pick, 8..11: sign extension, 12: zero, 13..255: ones). 3. Good test fixture: two groups of 32 lanes cover all 256 v_perm selectors once; controls check mutant references for each key pattern. ## Issues 1. The `ir.invoke("i32", "unaryBits.i32", ...)` pattern from the preceding block isn't used here -- this is fine, the byte-level logic is simpler and correct without it. 2. No explicit handling of `op_sel` on these opcodes (the existing rule for 32-bit operations ignores op_sel and this doesn't change that). This could be noted in the experiment doc for clarity. ## Recommendations - Consider adding a note to the experiment doc about the op_sel behavior for these two opcodes. - The 4-byte loop could benefit from a comment explaining why i goes 0..3 (one DWORD = 4 bytes, each result is a single 32-bit DWORD). ## Overall Good instruction coverage for byte-level VOP3 ops. The test fixture correctly validates all 256 perm selectors. Approvable.
Author
Owner

@⁠RonLogic on GitHub · 2026-11-27 10:31 UTC · original

Confirmed the registered Windows 11 replay at d5dc12c65a34a6ced85907629116e1c28bc037f6 without an app-local Agility change. I built compile_dxil native_store_replay with MSVC 19.52 x64 Release on Windows 26300.10075, SDK DXC 1.9.2602.17, then ran ctest --preset release --no-tests=error -j 1 -R '^native_(perm_lerp|align_bfm)_' -V. All four entries passed, zero skips. The new replay matched all 192 words, the 256 selectors and the guards; the adjacent align/BFM replay also matched all 192 words and guards.

A separate DXGI probe using the replay's default-device creation confirmed RTX 4070 (10de:2786), SM 6.6 and wave lanes 32..32. This in-box WARP reports SM 6.6 but only 4..4 lanes, so it cannot run this wave32 replay. The registered replay uses the ordinary inbox D3D12 path.

**@⁠RonLogic** on GitHub · 2026-11-27 10:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3016#issuecomment-7215992902) Confirmed the registered Windows 11 replay at `d5dc12c65a34a6ced85907629116e1c28bc037f6` without an app-local Agility change. I built `compile_dxil native_store_replay` with MSVC 19.52 x64 Release on Windows `26300.10075`, SDK DXC `1.9.2602.17`, then ran `ctest --preset release --no-tests=error -j 1 -R '^native_(perm_lerp|align_bfm)_' -V`. All four entries passed, zero skips. The new replay matched all 192 words, the 256 selectors and the guards; the adjacent align/BFM replay also matched all 192 words and guards. A separate DXGI probe using the replay's default-device creation confirmed RTX 4070 (`10de:2786`), SM 6.6 and wave lanes `32..32`. This in-box WARP reports SM 6.6 but only `4..4` lanes, so it cannot run this wave32 replay. The registered replay uses the ordinary inbox D3D12 path.
github-bot changed target branch from cpp-migration to gh-pr/3016/base 2026-11-27 12:58:28 +00:00
github manually merged commit d5dc12c65a into gh-pr/3016/base 2026-11-27 12:58:30 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 12:48 UTC · original

Independent review after retargeting to main: I checked d5dc12c65a34a6ced85907629116e1c28bc037f6 integrated with 232ae71e (tree ae55b08e97ecdf0bda9944200836dc0e40ec535c). The 23-line lowering keeps the dynamic byte shift in range, selects S1 first, uses bits 15 and 31 for sign fill, and reads only each selector byte's low bit for v_lerp_u8 rounding. The four changed paths belong to this PR.

I built compile_dxil native_store_replay from that tree and ran ctest --test-dir <build> --no-tests=error -V -R '^native_(perm_lerp|align_bfm)_' in Debug and Release /O2. Each build passed all four tests, with zero skips. The new replay matched 192 words, all 256 selectors and all guards. The adjacent align/BFM replay also matched its 192 words and guards. Windows 11 build 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, Windows SDK DXC 10.0.26100, replay debug layer off. This fixture requires wave32 hardware; it has no WARP test. The hosted Windows Debug and both Linux jobs passed; the hosted /O2 job is skipped by design on pull requests.

**@⁠R0Y00** on GitHub · 2026-11-27 12:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3016#issuecomment-7218697803) Independent review after retargeting to `main`: I checked `d5dc12c65a34a6ced85907629116e1c28bc037f6` integrated with `232ae71e` (tree `ae55b08e97ecdf0bda9944200836dc0e40ec535c`). The 23-line lowering keeps the dynamic byte shift in range, selects S1 first, uses bits 15 and 31 for sign fill, and reads only each selector byte's low bit for `v_lerp_u8` rounding. The four changed paths belong to this PR. I built `compile_dxil native_store_replay` from that tree and ran `ctest --test-dir <build> --no-tests=error -V -R '^native_(perm_lerp|align_bfm)_'` in Debug and Release `/O2`. Each build passed all four tests, with zero skips. The new replay matched 192 words, all 256 selectors and all guards. The adjacent align/BFM replay also matched its 192 words and guards. Windows 11 build 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, Windows SDK DXC 10.0.26100, replay debug layer off. This fixture requires wave32 hardware; it has no WARP test. The hosted Windows Debug and both Linux jobs passed; the hosted `/O2` job is skipped by design on pull requests.
This discussion has been locked. Commenting is limited to contributors.
No description provided.