fix(shader): VOP3P integer clamp on v_pk_mad/add/sub_{i16,u16} #502
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/502"
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 boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T10:34:09Z.
What
The VOP3P
clampbit threwVOP3P integer clamp is not implementedon every packed integer op. It now saturates each 16-bit half onv_pk_mad_i16,v_pk_mad_u16,v_pk_add_i16,v_pk_add_u16,v_pk_sub_i16andv_pk_sub_u16: the result is computed at full width (signed sources sign-extended, unsigned zero-extended) and limited to[-32768, 32767]or[0, 65535]. Onv_pk_mul_lo_u16the bit is accepted and has no effect, as on the hardware. Clamp on the other packed integer ops (min/max/shifts) and on the integer dot ops still throws.Behaviour measured on HW (RDNA2, gfx1035)
clamp: per-half saturation of the exact result (0xffff * 0xffff + c→0xffff,0 - 1→0on u16,-32768 * -1 + 0→0x7fffon i16);op_sel/op_sel_hipick the halves as without clamp.v_pk_mul_lo_u16withclamp: low 16 bits of the product, same as without it.Tested
New execution test
agc_driver_packed_integer_clamp_tests: the six ops withclamp,v_pk_mul_lo_u16withclamp, mad withoutclamp, andop_sel/op_sel_hivariants (16 instructions, 32 rows picked so each half reaches above-range, in-range and below-range results). Expected values come from the hardware, and the Python model matches them in all 512 cells.Passes on RADV and lavapipe. The test fails without the fix: dropping the clamp, zero-extending the signed sources, not bounding the u16 product before the add (the 32-bit sum wraps), wrong unsigned bounds, and throwing on
v_pk_mul_lo_u16all fail. Full Release ctest is green exceptagc_driver_pixel_helper_lanes, which also fails onmainon local RADV.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:07:57Z.
Thanks, checked the bounds: add and sub fit in 32 bits for both signednesses, the u16 mad bounds the product to 0xffff first (needed, since u16 times u16 can pass 2^31), and the i16 mad stays below 2^31. LLVM selects
v_pk_add/sub_{u,i}16with clamp foruaddsat/saddsat/usubsat/ssubsat(VOP3PSatPatin VOP3PInstructions.td), which matches the per-half saturation. Without clamp the sign-extended sources give the same low 16 bits andpackU16Lanesmasks them, so existing results don't change. Ready to merge from my side.