feat(shader): accept SDWA clamp and omod on integer VOP1 and VOP2 ops #19566
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19566"
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 Nawid3333 on 2026-11-13T15:06:42Z.
What
The RDNA decoder accepts the SDWA
clampandomodbits on integer VOP1 and VOP2 instructions where it threw "VOP1/VOP2 SDWA output modifiers are not supported". It drops the bits that the hardware ignores and the translation would otherwise apply: clamp and omod on the VOP1 opcodes below, omod on the VOP2 ones.v_mov_b32,v_not_b32,v_bfrev_b32,v_ffbh_u32,v_ffbl_b32,v_ffbh_i32(ignoresVop1SdwaOutputModifiers): clamp and omod are accepted and dropped. Without the drop,v_mov_b32would take its f32 path and clamp to [0, 1] or scale the bits.isVop2SdwaIntegerOpcode, replacingsupportsVop2SdwaIntegerClamp): omod is accepted and dropped, and clamp is now accepted onv_cndmask_b32too. Clamp handling on the other integer opcodes does not change.On RDNA2 hardware, SDWA omod has no effect on any of these opcodes, alone or together with clamp. Clamp has no effect on the VOP1 opcodes above,
v_cndmask_b32, min/max, the logic ops, shifts orv_mul_hi_*24. Onv_add/sub/subrev_nc_u32and thev_add/sub/subrev_co_ci_u32results it saturates unsigned, onv_mul_u32_u24unsigned and onv_mul_i32_i24signed. The saturation is to 32 bits, before the SDWA destination write: with a WORD/BYTE destination it is not a saturation to the field width. Clamp does not change theco_cicarry-out. The translator already does exactly this (vAddSubNcU32,addU32,subbU32,integer24; integer results never get an output modifier inwriteOperand), so only the decoder changes. DPP16 has no clamp or omod field.docs/dev/debt/shader.mdgets an entry for these bits: the PS5's gfx1013 is not measured, nor the opcodes that still throw.Still rejected: omod on the f32-source integer-result VOP1 opcodes (
v_cvt_i32_f32,v_cvt_rpi_i32_f32,v_frexp_exp_*and others), which this PR does not measure.Tested
Windows 11 Pro, no title.
Hardware reference: an RDNA2 GPU (Ryzen 5 7600X integrated graphics, gfx1036, AMD Windows driver 32.0.21045.16010) through
tools/hw-oracle, wave32, IEEE 0, DX10_CLAMP 1. 294 one-instruction SDWA cases, each over 32 lanes of edge values (0, 1, -1, 0x80000000, 0x7fffffff, byte and word sign bits, float specials, shift counts):co_cicarry-out read back.The
v_cndmask_b32andco_cicases set VCC withs_mov_b32 vcc_lofirst. All 294 cases matched the rule above. llvm-mc 21 (gfx1030) disassembles every case to the intended opcode, selects and destination, with clamp/omod cleared since LLVM rejects them on most integer opcodes.agc_driver_integer_sdwa_output_modifiers(new,IntegerSdwaOutputModifiers.cpp) runs 16 of these SDWA cases thatmainrefuses, over 16 input rows in 32 lanes. Its expected values are the hardware results of the same instruction words. In each case at least one lane differs from an f32 clamp/omod of the integer result, and in the saturating cases at least one lane also differs from the result without clamp.ctest -VwithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1, on the Radeon Graphics iGPU and on the RX 9070 XT. No log reportswas not found but was requested by env var VK_INSTANCE_LAYERS, and none has aVUID-line:agc_driver_integer_sdwa_output_modifiers, this PRmainVOP1 SDWA output modifiers are not supportedv_mov_b32 clamp mul:2 of 0x00000001, 0xffffffff is 0x00000000, expected 0x00000001agc_decoder_modifiers,agc_dpp_write,agc_vop1_sdwa_move_decode; this PRmainagc_driver_sdwa_ldexp_f16fail)Apart from the new test, every test has the same result on
mainand on this PR, on both GPUs.agc_driver_sdwa_ldexp_f16also fails onmainon the RX 9070 XT.v_ldexp_f16has the float SDWA profile, whose decoding this PR does not change.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T04:04:46Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reviewed decoder behavior is consistent with the stated scope and the supplied hardware test results support merging.
What I ran
Reviewed head
85f35d0bd8096d7b34a7cd35f89e977f0670115cagainst the prepared diff. No tests were run in this review; the test results below are author-reported.Results
Negative control
Not run by this reviewer. The description reports the new test failed on
mainand when the VOP1 modifiers were not dropped.Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
I did not run the build, tests, or hardware oracle. Author-reported results cover Windows 11 on an RDNA2 iGPU and an RX 9070 XT; PS5 gfx1013 behavior remains unmeasured. Read all three changed files:
IntegerSdwaOutputModifiers.cpp,RdnaVectorOpDecoder.cpp, anddocs/dev/debt/shader.md. The prepared bundle excluded no changed files; its diff omits lockfiles, minified files,dist/,build/, and.svgfiles.To get this to a good state
Nothing is required.