shader: lower v_cvt_pk_u16_u32 and v_cvt_pk_i16_i32 (saturating) #78
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr!78
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-78"
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?
@lcg007xd-c on GitHub · 2026-11-25 22:00 UTC · original
lcg007xd-c:shader-cvt-pk-16→main· +93 −0 · 2 files · 1 commits · openWhat is broken
v_cvt_pk_u16_u32(VOP3 0x36A) andv_cvt_pk_i16_i32(VOP3 0x36B) decode, but a program using either fails to translate withv_cvt_pk_u16_u32 is not supported(orv_cvt_pk_i16_i32 …). I found them by translating a one-instruction program for every VOP3 opcode the decoder names.Semantics
D.u16_lo = u32_to_u16(S0.u32); D.u16_hi = u32_to_u16(S1.u32), and the same withi32_to_i16.pack_uint_2x16/pack_sint_2x16(aco_select_nir_alu.cpp).nir_opcodes.pydefines those as_mesa_unsigned_to_unsigned(x, 16)/_mesa_signed_to_signed(x, 16), described as "Convert two unsigned integers into a packed unsigned short (clamp is applied)".nir_op_ldexp, ACO usesv_cvt_pk_i16_i32 … , 0to "Convert the exponent to 16bit int with saturation" beforev_ldexp_f16.min(x, 0xFFFF)unsigned,clamp(x, −32768, 32767)signed.The change (
emit/lower.rs, ininteger)Each source is clamped to its 16-bit range and masked. Then src0 goes to the low half and src1 to the high half.
Tests
emit::lower::tests::saturating_16_bit_packs_translate(every host): both encodings decode to their names, and a program that stores the result translates. Without thelower.rschange it fails:v_cvt_pk_u16_u32: GFX10 code at 0x24: v_cvt_pk_u16_u32 is not supported.valu_tests::v_cvt_pk_u16_u32_and_i16_i32_saturate_each_half(Windows/GPU): four hand-computed cases each. They cover in-range values,0x10000/0xFFFFFFFF/0x80000000saturating, and −1, 32768, −32768,i32::MIN,i32::MAXand a small negative for the signed form.lli. I compared all 169 pairs of 13 edge values against Rust'smin/clamp. All match.Run here (Linux, Rust 1.98.1):
cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run here: the GPU case, since I have no Windows machine. The saturation comes from Mesa's definition and use, not from a run on RDNA2 hardware.
🤖 Generated with Claude Code
VOP3 0x36A and 0x36B decoded but failed to translate ("v_cvt_pk_u16_u32 is not supported"). Each packs two 32-bit integers into 16-bit halves (src0 low, src1 high; AMD's RDNA2 ISA), saturating each to the 16-bit range: Mesa's ACO selects them for NIR's pack_uint_2x16/pack_sint_2x16, defined as "clamp is applied", and uses v_cvt_pk_i16_i32 to saturate an ldexp exponent to 16 bits. Co-Authored-By: Claude Opus 5.5 <[email protected]>View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.