shader: lower the 64-bit VOP3 shifts (v_lshlrev_b64, v_lshrrev_b64, v_ashrrev_i64) in pixel_aot #928
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#928
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@MasterDomino on GitHub · 2026-11-23 17:34 UTC · original
Problem
tools/pixel_aot.pyrejects the three 64-bit VOP3 shifts:v_lshlrev_b64,v_lshrrev_b64andv_ashrrev_i64. A pixel program that contains any of them fails withUnsupported instruction. All three are listed under VOP3 indocs/coverage/gfx1013.tsv, and no fixture covers them.I checked the open pull requests and issues. No diff or thread mentions these three mnemonics. The nearby open integer work (#526, #531, #532) covers other VOP3 forms.
Proposal
I'd like to take these as one small PR, with the same structure as the 64-bit comparisons:
Semantics. The AMD "RDNA 2" ISA reference guide, section 12.12 "VOP3A & VOP3B Instructions" (p. 177 of 283), defines them as:
V_LSHLREV_B64:D.u64 = S1.u64 << S0.u[5:0]V_LSHRREV_B64:D.u64 = S1.u64 >> S0.u[5:0]V_ASHRREV_I64:D.u64 = signext(S1.u64) >> S0.u[5:0]Each entry also says "Only one scalar broadcast constant is allowed." This is the RDNA 2 guide, not a gfx1013-specific document. The opcode numbers match the gfx1013 encodings that LLVM 15.0.7
llvm-mc -mcpu=gfx1013produces (VOP3 opcodes0x2ff,0x300and0x301). LLVM 15 also enforces the one-scalar limit for gfx1013:v_lshlrev_b64 v[12:13], s44, s[46:47]andv_lshlrev_b64 v[12:13], s44, 0x41both fail withviolates constant bus restrictions, andv_lshlrev_b64 v[12:13], 0x41, v[12:13]assembles.Lowering. Read the 64-bit
src1through the existingint64_operandpath as two 32-bit words, and emit the shift as two-worduintarithmetic. Then no 64-bit HLSL type orInt64shader capability is needed. The 64-bit comparisons inlower()already work this way. The amountsrc0uses the existing 32-bit operand rules: VGPR, SGPR, inline constant or literal. At most one ofsrc0andsrc1may be an SGPR or literal, matching the ISA note.Destination. The destination is a VGPR pair. Both words become defined 32-bit values that the existing readers accept.
Refusals. Keep VOP3 modifiers (
clamp,op_sel,abs,neg) refused, and refuse a destination pair that overlaps a pending sample.A second, independent check of the 6-bit amount, from the LLVM 15 compiler model rather than hardware. With LLVM 15.0.7
llc -march=amdgcn -mcpu=gfx1013 -O2, an IR shift byand i32 %s, 63compiles to the barev_lshlrev_b64/v_lshrrev_b64/v_ashrrev_i64, with theandremoved. The same shift byand i32 %s, 31keeps thev_and_b32_e32 v2, 31, v2. So LLVM treats the instructions as reading exactly bits [5:0] of the amount, which agrees with the ISA text. I haven't checked this on gfx1013 hardware.Alternatives
uint64_t. That is simpler HLSL, but it needs theInt64capability and doesn't match how the translator already handles 64-bit values.Verification
pixel_aot_check.py binarypath), including all three mnemonics.draw-shift64mode, registered with aFORM_COVERAGE_RECORDlike the other draw tests, exports through the bit-exactR32G32B32A32_UINTtarget. It compares both result words with a Python reference on WARP.0xffffffc1) to prove the 6-bit masking.v_ashrrev_i64sign-fills andv_lshrrev_b64zero-fills.v_ashrrev_i64lowered as a logical shift.I'll write and check the lowering on Linux with LLVM 15 (binary round-trip and HLSL output). The WARP draws will come from the Windows CI run on the PR. I can't run D3D12 locally, so I won't report hardware results.
AI-assisted.
@R0Y00 on GitHub · 2026-11-23 18:37 UTC · original
Please proceed with the three VOP3 shifts. Use the existing two-word integer representation, mask the amount to six bits, and use sign fill only for ASHR. Read both source words before writing the destination pair so the in-place LLVM form keeps the original value. Keep your refusal scope, including pending sample destinations and unsupported modifiers.
The proposed source-built LLVM 15 round-trip and WARP integer readback are the right checks. Include an in-place case, and keep 0/31/32/33/63/64/65 so the two-word implementation never relies on a 32-bit HLSL shift by 32. The bit-mask, sign-fill and swapped-word controls should each produce a mismatch.
@MasterDomino on GitHub · 2026-11-23 18:52 UTC · original
Thanks, taking this now. It will be a PR from my fork shortly, following your notes: the two-word representation; a 6-bit amount; sign fill only for
v_ashrrev_i64; both source words read before the pair is written; the in-place case; and the 0/31/32/33/63/64/65 amounts. It will include the LLVM 15 round trip, the WARP integer readback and the three mismatch controls.AI-assisted.
@MasterDomino on GitHub · 2026-11-23 19:02 UTC · original
Up as #964, following your notes above: the two-word representation, a six-bit amount, sign fill only for
v_ashrrev_i64, both source words read before the pair is written, the in-place case, and 0/31/32/33/63/64/65 plus wide amounts through theR32G32B32A32_UINTreadback. The bit-mask, sign-fill and swapped-word mutations must each mismatch. The LLVM 15 round trip and controls pass locally; the WARP draws run first in the PR's CI.AI-assisted.
@R0Y00 on GitHub · 2026-11-23 19:52 UTC · original
Completed by #964. Both Windows and both Linux jobs passed. The full LLVM 15 binary check and both WARP and RTX readback passed for the combined candidate, including count masking, cross-word boundaries and the distinguishing shift mutations.