shader: lower v_perm_b32 and v_lerp_u8 in the direct C++ compute path #3016
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3016"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_b32andv_lerp_u8withdirect DXIL lowering for <name>. Both now follow the RDNA 2 ISA definitions, as thegfx2hlsl.pylowerings in #2875 and #2873 state them.v_perm_b32: each result byte i takes the selector s = S2[8i+7:8i].v_lerp_u8: each byte is (S0 + S1 + S2[8i]) >> 1. Only the low bit of each S2 byte rounds.direct ALU operand modifiers), which I checked for both opcodes.op_selbits 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.inland isn't part of this change. On999e17cdit 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).v_perm_b32: S0 = 0x1b6c9e37, S1 = 0x80f07ad5, and the S2 bytes are 4G .. 4G+3, so the 64 lanes cover all 256 selectors. A secondv_perm_b32exchanges 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.Results
cpp-migration999e17cdplus this change, Windows 10 build 19045, NVIDIA GeForce RTX 3080, driver 32.0.15.9174.native_perm_lerp_controlsnative_perm_lerp_hardware(local Agility replay, see below)native_align_bfm_hardware(neighbour, same local replay)docs_links_check,bidi_controls_checkCapability skip. The registered
native_store_replayuses the inbox D3D12 runtime. On Windows 10 that runtime doesn't report shader model 6.6, sonative_perm_lerp_hardwarereports a skip (77) here, asnative_align_bfm_hardwaredoes. The readback rows above used a local copy of the replay linked with the app-local Agility SDK exports (D3D12SDKVersion620, as inoffscreen_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
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T05:37:34Z.
Review: COMMENTED
What works
v_lerp_u8) that the direct compute frontend previously refused.
The RDNA 2 ISA semantics match the gfx2hlsl.py lowerings in #2875
and #2873.
byte(x, at)for extracting per-bytecomponents 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).
selectors once; controls check mutant references for each key pattern.
Issues
ir.invoke("i32", "unaryBits.i32", ...)pattern from thepreceding block isn't used here -- this is fine, the byte-level logic
is simpler and correct without it.
op_selon these opcodes (the existingrule for 32-bit operations ignores op_sel and this doesn't change
that). This could be noted in the experiment doc for clarity.
Recommendations
behavior for these two opcodes.
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.
Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-27T10:31:47Z.
Confirmed the registered Windows 11 replay at
d5dc12c65a34a6ced85907629116e1c28bc037f6without an app-local Agility change. I builtcompile_dxil native_store_replaywith MSVC 19.52 x64 Release on Windows26300.10075, SDK DXC1.9.2602.17, then ranctest --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 lanes32..32. This in-box WARP reports SM 6.6 but only4..4lanes, so it cannot run this wave32 replay. The registered replay uses the ordinary inbox D3D12 path.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T12:48:32Z.
Independent review after retargeting to
main: I checkedd5dc12c65a34a6ced85907629116e1c28bc037f6integrated with232ae71e(treeae55b08e97ecdf0bda9944200836dc0e40ec535c). 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 forv_lerp_u8rounding. The four changed paths belong to this PR.I built
compile_dxil native_store_replayfrom that tree and ranctest --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/O2job is skipped by design on pull requests.