Recompiler rejects clamp on VOP3 v_add_nc_u32, v_sub_nc_u32 and the 16-bit add/sub ops #1897
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?
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T22:57:53Z.
A VOP3
clampon unsigned 32-bit add/sub, or on any 16-bit integer add/sub, stops the recompile withShaderRecompiler::Recompile: VOP3 source modifiers are not implemented. The affected ops are:v_add_nc_u32,v_sub_nc_u32,v_subrev_nc_u32v_add_nc_u16,v_sub_nc_u16,v_add_nc_i16,v_sub_nc_i16LLVM emits these with
clampfor saturating adds and subtracts on gfx10 (uadd.sat,usub.sat, and the i16/u16 forms), so they can appear in real shaders.The signed 32-bit versions already work (
v_add_nc_i32/v_sub_nc_i32clamp,e144f43f). The u32 saturation is also already invAddSubNcU32, added for the SDWA form inc5effd40. The VOP3 form is refused in the decoder because those three opcodes are missing fromusesIntegerSaturateClamp. For the 16-bit ops,checkNativeVop3Modifiersrejects clamp, andinteger16Binarydoesn't saturate.Hardware behaviour, measured with
tools/hw-oracleon a Ryzen 5 7600X iGPU (gfx1036, RDNA2, wave32):v_add_nc_u320xffffffffv_sub_nc_u32,v_subrev_nc_u32v_add_nc_u16,v_sub_nc_u160xffff/ 0v_add_nc_i16,v_sub_nc_i160x7fff/0x8000Bits 31:16 of the 16-bit results were 0 in these runs.
Float settings: IEEE=0, DX10_CLAMP=1, denorm32=0, denorm16=3, round32=0, round16=0, fp16_overflow=0. A second run with IEEE=1, DX10_CLAMP=0, denorm 3/3, round toward zero and fp16_overflow=1 gave identical results.
Out of scope: the carry ops (
v_add_co_u32,v_sub_co_u32,v_add_co_ci_u32, ...) with clamp still throw. LLVM only emits that form for gfx8. On the iGPU they saturate the result and still write the carry-out. I can do them separately if anyone needs them.I have a fix with a test built from the measured rows, and I'll open the PR now: https://github.com/fisherjoey/AnyPS5/tree/fix/vop3-add-sub-clamp
AI-assisted: yes