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

Merged
archielcqp-a11y merged 1 commit from upstream-pr/3016 into main 2026-11-27 12:48:44 +00:00
archielcqp-a11y commented 2026-11-27 05:23:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by archielcqp-a11y on 2026-11-27T05:23:25Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5521668784 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3016). Originally posted by [archielcqp-a11y](https://github.com/archielcqp-a11y) on 2026-11-27T05:23:25Z. --- 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)
KelboLive commented 2026-11-27 05:37:34 +00:00 (Migrated from github.com)

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

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6083924362 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3016#pullrequestreview-6083924362). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T05:37:34Z. **Review:** COMMENTED --- ## 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.
RonLogic commented 2026-11-27 10:31:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-27T10:31:47Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7215992902 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3016#issuecomment-7215992902). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-27T10:31:47Z. --- 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.
R0Y00 commented 2026-11-27 12:48:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T12:48:32Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7218697803 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3016#issuecomment-7218697803). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T12:48:32Z. --- 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.
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!3016
No description provided.