feat(shader): saturate VOP2 integer SDWA results on clamp #510
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/510"
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-04T11:37:47Z.
What
clampon VOP2 SDWA integer ops threwVOP2 SDWA output modifiers are not supported. It is now accepted on every op with an integer SDWA rule exceptv_cndmask_b32, with the result measured on hardware:v_add_nc_u32,v_sub_nc_u32,v_subrev_nc_u32,v_add_co_ci_u32,v_sub_co_ci_u32,v_subrev_co_ci_u32,v_mul_u32_u24: unsigned saturation of the 32-bit result (0xffffffffon carry-out,0on borrow-out).v_mul_i32_i24: signed saturation of the 48-bit product to[0x80000000, 0x7fffffff].v_mul_hi_{i32_i24,u32_u24},v_min/max_{i32,u32},v_lshrrev_b32,v_ashrrev_i32,v_lshlrev_b32,v_and/or/xor/xnor_b32:clamphas no effect, so the translator leaves them unchanged.The carry-out written to VCC is the same as without
clamp. The saturation applies to the 32-bit result, beforedst_selpicks the bits that get written. It is not done at the width of the destination field.v_cndmask_b32withclampandomodon integer ops still throw. So do the VOP3 forms of these ops withclamp; that's a separate PR.Behaviour measured on HW (RDNA2, gfx1035)
First, all 22 integer VOP2 SDWA ops with
clampand DWORD selectors, on 256 rows: the 8 ops above saturate and the other 14 match the unclamped result. Then the 12 forms in the test (byte and word selectors,sext, all threedst_unusedmodes, the three carry-outs) on 2048 rows: the Python model matches all 30720 results. The model saturates the full-width result and then appliesdst_sel. The alternative, saturating to the destination field width, mismatches 1958 of them.Tested
New execution test
agc_driver_sdwa_integer_clamp_tests: 32 rows with expected values from the hardware. For each op, the rows cover a result below, inside and above the clamped range, the exact bounds, and both carry-in values. It passes on RADV and lavapipe.It fails without each part of the change (7 mutations): the decoder refusing
clamp, no saturation on the_ncops, onv_add_co_ci_u32, on the borrow ops or on the 24-bit multiplies, unsigned saturation forv_mul_i32_i24, and saturatingv_mul_hi_*. The full Release ctest passes 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:08:05Z.
Thanks. The unsigned saturation on the add/sub forms matches what LLVM selects for
uaddsat/usubsat(v_add_u32/v_sub_u32with clamp), and the 48-bit saturation for the 24-bit multiplies is right arithmetically. My own model with "saturate the 32-bit result, then applydst_sel" matches all 480 expected values in the test. I also checked that the new clamp branches inaddU32,subbU32andinteger24can't be reached from VOP3, VOP3B or scalar forms, since the decoder still refuses clamp there, and that theinteger24branch stays out of the way of #507's mad saturation. The new test fails on main and the full ctest passes on my machine. Ready to merge from my side after #509. Sincev_add_nc_u32and the subtracts now go throughvAddSubNcU32, I'll run it through my PPSA21564 check before merging.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T08:31:21Z.
Gated on PPSA21564 on top of #509: no visual or FPS change.