feat(shader): accept SDWA clamp and omod on integer VOP1 and VOP2 ops #19566

Merged
Nawid3333 merged 1 commit from upstream-pr/19566 into main 2026-11-21 20:00:39 +00:00
Nawid3333 commented 2026-11-13 15:06:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nawid3333 on 2026-11-13T15:06:42Z.


What

The RDNA decoder accepts the SDWA clamp and omod bits 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.

  • VOP1 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_b32 would take its f32 path and clamp to [0, 1] or scale the bits.
  • VOP2 opcodes with the integer SDWA profile (isVop2SdwaIntegerOpcode, replacing supportsVop2SdwaIntegerClamp): omod is accepted and dropped, and clamp is now accepted on v_cndmask_b32 too. 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 or v_mul_hi_*24. On v_add/sub/subrev_nc_u32 and the v_add/sub/subrev_co_ci_u32 results it saturates unsigned, on v_mul_u32_u24 unsigned and on v_mul_i32_i24 signed. 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 the co_ci carry-out. The translator already does exactly this (vAddSubNcU32, addU32, subbU32, integer24; integer results never get an output modifier in writeOperand), so only the decoder changes. DPP16 has no clamp or omod field.

docs/dev/debt/shader.md gets 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):

  • every opcode above and every other opcode with the integer SDWA profile;
  • clamp/omod 0/0, 1/0, 0/1, 0/2, 0/3, 1/1 and 1/3 on each;
  • clamp on the saturating opcodes with WORD_1 sign-extended and BYTE_0 sources, and with WORD_0, BYTE_0 and WORD_1 pad destinations and a WORD_1 preserve destination;
  • the co_ci carry-out read back.

The v_cndmask_b32 and co_ci cases set VCC with s_mov_b32 vcc_lo first. 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 that main refuses, 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 -V with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1, on the Radeon Graphics iGPU and on the RX 9070 XT. No log reports was not found but was requested by env var VK_INSTANCE_LAYERS, and none has a VUID- line:

run Radeon Graphics (RDNA2) RX 9070 XT (RDNA4)
agc_driver_integer_sdwa_output_modifiers, this PR passed passed
same test on main fails: VOP1 SDWA output modifiers are not supported fails: same message
same test, this PR with the VOP1 opcodes keeping clamp and omod instead of dropping them fails: v_mov_b32 clamp mul:2 of 0x00000001, 0xffffffff is 0x00000000, expected 0x00000001 fails: same
34 tests: every SDWA and DPP execution test, agc_decoder_modifiers, agc_dpp_write, agc_vop1_sdwa_move_decode; this PR 34/34 passed 33/34 passed
same 34 tests on main 33/34 passed (the new test fails) 32/34 passed (the new test and agc_driver_sdwa_ldexp_f16 fail)

Apart from the new test, every test has the same result on main and on this PR, on both GPUs. agc_driver_sdwa_ldexp_f16 also fails on main on the RX 9070 XT. v_ldexp_f16 has the float SDWA profile, whose decoding this PR does not change.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon Graphics (Ryzen 5 7600X iGPU, RDNA2), AMD Windows driver 32.0.21045.16010; AMD Radeon RX 9070 XT (RDNA4), AMD Windows driver 32.0.32015.7029; Windows 11 Pro
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5297857650 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19566). Originally posted by [Nawid3333](https://github.com/Nawid3333) on 2026-11-13T15:06:42Z. --- ### What The RDNA decoder accepts the SDWA `clamp` and `omod` bits 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. - VOP1 `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_b32` would take its f32 path and clamp to [0, 1] or scale the bits. - VOP2 opcodes with the integer SDWA profile (`isVop2SdwaIntegerOpcode`, replacing `supportsVop2SdwaIntegerClamp`): omod is accepted and dropped, and clamp is now accepted on `v_cndmask_b32` too. 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 or `v_mul_hi_*24`. On `v_add/sub/subrev_nc_u32` and the `v_add/sub/subrev_co_ci_u32` results it saturates unsigned, on `v_mul_u32_u24` unsigned and on `v_mul_i32_i24` signed. 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 the `co_ci` carry-out. The translator already does exactly this (`vAddSubNcU32`, `addU32`, `subbU32`, `integer24`; integer results never get an output modifier in `writeOperand`), so only the decoder changes. DPP16 has no clamp or omod field. `docs/dev/debt/shader.md` gets 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): - every opcode above and every other opcode with the integer SDWA profile; - clamp/omod 0/0, 1/0, 0/1, 0/2, 0/3, 1/1 and 1/3 on each; - clamp on the saturating opcodes with WORD_1 sign-extended and BYTE_0 sources, and with WORD_0, BYTE_0 and WORD_1 pad destinations and a WORD_1 preserve destination; - the `co_ci` carry-out read back. The `v_cndmask_b32` and `co_ci` cases set VCC with `s_mov_b32 vcc_lo` first. 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 that `main` refuses, 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 -V` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`, on the Radeon Graphics iGPU and on the RX 9070 XT. No log reports `was not found but was requested by env var VK_INSTANCE_LAYERS`, and none has a `VUID-` line: | run | Radeon Graphics (RDNA2) | RX 9070 XT (RDNA4) | |---|---|---| | `agc_driver_integer_sdwa_output_modifiers`, this PR | passed | passed | | same test on `main` | fails: `VOP1 SDWA output modifiers are not supported` | fails: same message | | same test, this PR with the VOP1 opcodes keeping clamp and omod instead of dropping them | fails: `v_mov_b32 clamp mul:2 of 0x00000001, 0xffffffff is 0x00000000, expected 0x00000001` | fails: same | | 34 tests: every SDWA and DPP execution test, `agc_decoder_modifiers`, `agc_dpp_write`, `agc_vop1_sdwa_move_decode`; this PR | 34/34 passed | 33/34 passed | | same 34 tests on `main` | 33/34 passed (the new test fails) | 32/34 passed (the new test and `agc_driver_sdwa_ldexp_f16` fail) | Apart from the new test, every test has the same result on `main` and on this PR, on both GPUs. `agc_driver_sdwa_ldexp_f16` also fails on `main` on the RX 9070 XT. `v_ldexp_f16` has the float SDWA profile, whose decoding this PR does not change. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon Graphics (Ryzen 5 7600X iGPU, RDNA2), AMD Windows driver 32.0.21045.16010; AMD Radeon RX 9070 XT (RDNA4), AMD Windows driver 32.0.32015.7029; Windows 11 Pro - [x] AI-assisted: yes
MarcZX10 commented 2026-11-21 04:04:46 +00:00 (Migrated from github.com)

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 85f35d0bd8096d7b34a7cd35f89e977f0670115c against the prepared diff. No tests were run in this review; the test results below are author-reported.

Results

Check Result Note
Decoder logic passed Modifier validation and clearing match the described integer profiles.
New execution test passed Setup, outputs and CMake registration reviewed; hardware runs are author-reported.
Tests run in this review not run No local test execution was available.

Negative control

Not run by this reviewer. The description reports the new test failed on main and 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, and docs/dev/debt/shader.md. The prepared bundle excluded no changed files; its diff omits lockfiles, minified files, dist/, build/, and .svg files.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6002711953 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19566#pullrequestreview-6002711953). Originally posted by [MarcZX10](https://github.com/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 `85f35d0bd8096d7b34a7cd35f89e977f0670115c` against the prepared diff. No tests were run in this review; the test results below are author-reported. ## Results | Check | Result | Note | |---|---|---| | Decoder logic | passed | Modifier validation and clearing match the described integer profiles. | | New execution test | passed | Setup, outputs and CMake registration reviewed; hardware runs are author-reported. | | Tests run in this review | not run | No local test execution was available. | ## Negative control Not run by this reviewer. The description reports the new test failed on `main` and when the VOP1 modifiers were not dropped. ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [Decoder changes at the reviewed commit](https://github.com/boykopovar/AnyPS5/blob/85f35d0bd8096d7b34a7cd35f89e977f0670115c/core/shader/recompiler/RdnaDecoder/src/RdnaVectorOpDecoder.cpp#L1082-L1092) - [Execution test at the reviewed commit](https://github.com/boykopovar/AnyPS5/blob/85f35d0bd8096d7b34a7cd35f89e977f0670115c/core/libs/prx/libSceAgcDriver/tests/execution/IntegerSdwaOutputModifiers.cpp#L110-L164) - [Execution test registration](https://github.com/boykopovar/AnyPS5/blob/85f35d0bd8096d7b34a7cd35f89e977f0670115c/core/libs/prx/libSceAgcDriver/CMakeLists.txt#L689-L734) ## 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`, and `docs/dev/debt/shader.md`. The prepared bundle excluded no changed files; its diff omits lockfiles, minified files, `dist/`, `build/`, and `.svg` files. ## To get this to a good state Nothing is required.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!19566
No description provided.