feat(shader): accept neg/abs on 32-bit integer DPP and SDWA sources #19577

Merged
Nawid3333 merged 4 commits from upstream-pr/19577 into main 2026-11-26 01:38:21 +00:00
Nawid3333 commented 2026-11-13 15:13:21 +00:00 (Migrated from github.com)

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


What

The RDNA decoder accepts the DPP16 and SDWA neg and abs source bits on VOP1 and VOP2 instructions whose sources are 32-bit integers, instead of throwing.

  • VOP1: v_cvt_f32_i32, v_cvt_f32_u32, v_cvt_off_f32_i4, v_cvt_f32_ubyte0..3, v_not_b32, v_bfrev_b32, v_ffbh_u32, v_ffbl_b32, v_ffbh_i32 (isVop1IntegerSourceOpcode).
  • VOP2: every opcode with the integer SDWA profile (isVop2IntegerOpcode): v_cndmask_b32, v_mul_i32_i24, v_mul_hi_i32_i24, v_mul_u32_u24, v_mul_hi_u32_u24, v_min_i32, v_max_i32, v_min_u32, v_max_u32, v_lshrrev_b32, v_ashrrev_i32, v_lshlrev_b32, v_and_b32, v_or_b32, v_xor_b32, v_xnor_b32, 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.

On RDNA2 hardware these bits act on bit 31 of the 32-bit operand: NEG flips it, ABS clears it, both set it. There is no two's-complement negate or integer absolute value. The bit is changed after the DPP lane move (with bound_ctrl:1 an out-of-row lane reads 0, so NEG gives 0x80000000) and after the SDWA select and zero/sign extension (NEG on a zero-extended WORD_1 gives 0x80000000 | field). v_cvt_f32_i32 and v_cvt_f32_u32 convert the changed integer: v_cvt_f32_i32 with DPP NEG of 1 converts 0x80000001 and gives 0xcf000000, where a two's-complement negate would give -1.0.

TranslationContext::readOperand already reads 32-bit operands in this order (DPP move, SDWA extract, AND 0x7fffffff, XOR 0x80000000), and every opcode above reads its sources through it, so only the decoder changes. The integer SDWA rule no longer needs its own source-modifier check in validateVop2Sdwa, so that check and Vop2SdwaRule::sourceModifiers are removed (only the integer rule had it false: the float rule allowed the bits, and an opcode without an SDWA profile is refused before the rule lookup).

The fragment docs/dev/debt/changes/feat-integer-dpp-sdwa-source-modifiers-r2.md adds a shader debt entry for the modifiers: the PS5's gfx1013 is not measured.

SdwaCvtOffSatPk no longer requires v_cvt_off_f32_i4 SDWA with neg or abs to be refused. It runs them, and both, over all seven source selects with and without sign extension and expects the unmodified result. The modifier changes bit 31 of the selected and extended source, and the instruction reads bits 3:0. On the RDNA2 iGPU, 576 results with the modifier (DPP16, and SDWA DWORD, and BYTE_0 and WORD_1 each with and without sign extension, 32 lanes each) all equal the result without it; the other selects were not run with the modifier on hardware. Its v_sat_pk_u8_i16 refusals stay.

Still rejected: 16-bit integer sources (v_cvt_f16_u16, v_cvt_f16_i16, where the hardware uses bit 15), v_sat_pk_u8_i16, v_dot4c_i32_i8 and v_mov_b32 with a byte or word source. Clamp and omod handling does not change.

Tested

Windows 11 Pro, no title.

Hardware reference: each opcode above ran on an RDNA2 GPU (Ryzen 5 7600X integrated graphics, gfx1036, AMD Windows driver 32.0.21045.16010) through tools/hw-oracle, wave32: 1,296 one-instruction cases (572 in a first sweep of six VOP1 opcodes, v_mov_b32 among them, and ten VOP2 opcodes, 724 for the rest), each over 32 lanes of edge values (0, 1, -1, 0x80000000, 0x7fffffff, byte and word sign bits, float specials, shift counts). Each case used DPP16 (quad_perm identity and row_shl:1) or SDWA (DWORD, WORD_1 and BYTE_0 with and without sign extension), with no modifier (the baselines) or with neg, abs or both on src0 or src1. The v_cndmask_b32 and carry cases set VCC with s_mov_b32 vcc_lo first; the carry-out of the three co_ci opcodes was read back too. 462 more cases cover the remaining forms the decoder now accepts: v_cndmask_b32 SDWA with sign extension, the BYTE_1, BYTE_2, BYTE_3 and WORD_0 selects on v_not_b32, v_cvt_f32_i32, v_xor_b32 and v_add_nc_u32, and SDWA sources vcc_lo, -1 and 64, in wave32 and (except the VCC-masked v_cndmask_b32) in wave64. Every case with a modifier matched the bit-31 rule above, and every case without one matched the plain operation. llvm-mc 21 (gfx1030) disassembles the words of every case to the intended opcode, selects and DPP control with the modifier bits cleared, since LLVM rejects them on integer opcodes, except v_cndmask_b32 SDWA with sign extension, which LLVM rejects as well. The PS5's gfx1013 is not measured.

agc_driver_integer_source_modifiers (new, IntegerSourceModifiers.cpp) runs 16 DPP16 and 16 SDWA cases of these opcodes over 16 input rows in 32 lanes. Its expected values are the hardware results of the same instruction words.

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_source_modifiers, this PR passed passed
same test on main fails: VOP1 DPP integer source modifiers are not supported fails: same message
same test, this PR with the NEG XOR removed from the 32-bit readOperand path fails: v_not_b32 dpp neg of 0x00000000 ... is 0xffffffff, expected 0x7fffffff fails: same
-R "sdwa|dpp|integer_source_modifiers|decoder_modifiers" (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
the 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)

The one failure on the RX 9070 XT is agc_driver_sdwa_ldexp_f16 (lane 0 BYTE_2/BYTE_1 -> WORD_0 is 0x00000000, expected 0xffff8000). main fails the same way on that GPU and passes on the iGPU; v_ldexp_f16 has the float SDWA profile, whose decoding this PR does not change.

On a device whose subgroups hold fewer than 32 lanes the test is skipped, as Dpp16Operands is: its row_shl:1 cases read the neighbouring lane, which is in another subgroup there (lavapipe with 8-lane subgroups, reported in the comments).

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:5297965191 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19577). Originally posted by [Nawid3333](https://github.com/Nawid3333) on 2026-11-13T15:13:21Z. --- ### What The RDNA decoder accepts the DPP16 and SDWA `neg` and `abs` source bits on VOP1 and VOP2 instructions whose sources are 32-bit integers, instead of throwing. - VOP1: `v_cvt_f32_i32`, `v_cvt_f32_u32`, `v_cvt_off_f32_i4`, `v_cvt_f32_ubyte0`..`3`, `v_not_b32`, `v_bfrev_b32`, `v_ffbh_u32`, `v_ffbl_b32`, `v_ffbh_i32` (`isVop1IntegerSourceOpcode`). - VOP2: every opcode with the integer SDWA profile (`isVop2IntegerOpcode`): `v_cndmask_b32`, `v_mul_i32_i24`, `v_mul_hi_i32_i24`, `v_mul_u32_u24`, `v_mul_hi_u32_u24`, `v_min_i32`, `v_max_i32`, `v_min_u32`, `v_max_u32`, `v_lshrrev_b32`, `v_ashrrev_i32`, `v_lshlrev_b32`, `v_and_b32`, `v_or_b32`, `v_xor_b32`, `v_xnor_b32`, `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`. On RDNA2 hardware these bits act on bit 31 of the 32-bit operand: NEG flips it, ABS clears it, both set it. There is no two's-complement negate or integer absolute value. The bit is changed after the DPP lane move (with `bound_ctrl:1` an out-of-row lane reads 0, so NEG gives 0x80000000) and after the SDWA select and zero/sign extension (NEG on a zero-extended WORD_1 gives `0x80000000 | field`). `v_cvt_f32_i32` and `v_cvt_f32_u32` convert the changed integer: `v_cvt_f32_i32` with DPP NEG of 1 converts 0x80000001 and gives 0xcf000000, where a two's-complement negate would give -1.0. `TranslationContext::readOperand` already reads 32-bit operands in this order (DPP move, SDWA extract, AND 0x7fffffff, XOR 0x80000000), and every opcode above reads its sources through it, so only the decoder changes. The integer SDWA rule no longer needs its own source-modifier check in `validateVop2Sdwa`, so that check and `Vop2SdwaRule::sourceModifiers` are removed (only the integer rule had it false: the float rule allowed the bits, and an opcode without an SDWA profile is refused before the rule lookup). The fragment `docs/dev/debt/changes/feat-integer-dpp-sdwa-source-modifiers-r2.md` adds a `shader` debt entry for the modifiers: the PS5's gfx1013 is not measured. `SdwaCvtOffSatPk` no longer requires `v_cvt_off_f32_i4` SDWA with `neg` or `abs` to be refused. It runs them, and both, over all seven source selects with and without sign extension and expects the unmodified result. The modifier changes bit 31 of the selected and extended source, and the instruction reads bits 3:0. On the RDNA2 iGPU, 576 results with the modifier (DPP16, and SDWA DWORD, and BYTE_0 and WORD_1 each with and without sign extension, 32 lanes each) all equal the result without it; the other selects were not run with the modifier on hardware. Its `v_sat_pk_u8_i16` refusals stay. Still rejected: 16-bit integer sources (`v_cvt_f16_u16`, `v_cvt_f16_i16`, where the hardware uses bit 15), `v_sat_pk_u8_i16`, `v_dot4c_i32_i8` and `v_mov_b32` with a byte or word source. Clamp and omod handling does not change. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Pro, no title. Hardware reference: each opcode above ran on an RDNA2 GPU (Ryzen 5 7600X integrated graphics, gfx1036, AMD Windows driver 32.0.21045.16010) through `tools/hw-oracle`, wave32: 1,296 one-instruction cases (572 in a first sweep of six VOP1 opcodes, `v_mov_b32` among them, and ten VOP2 opcodes, 724 for the rest), each over 32 lanes of edge values (0, 1, -1, 0x80000000, 0x7fffffff, byte and word sign bits, float specials, shift counts). Each case used DPP16 (quad_perm identity and `row_shl:1`) or SDWA (DWORD, WORD_1 and BYTE_0 with and without sign extension), with no modifier (the baselines) or with neg, abs or both on src0 or src1. The `v_cndmask_b32` and carry cases set VCC with `s_mov_b32 vcc_lo` first; the carry-out of the three `co_ci` opcodes was read back too. 462 more cases cover the remaining forms the decoder now accepts: `v_cndmask_b32` SDWA with sign extension, the BYTE_1, BYTE_2, BYTE_3 and WORD_0 selects on `v_not_b32`, `v_cvt_f32_i32`, `v_xor_b32` and `v_add_nc_u32`, and SDWA sources `vcc_lo`, -1 and 64, in wave32 and (except the VCC-masked `v_cndmask_b32`) in wave64. Every case with a modifier matched the bit-31 rule above, and every case without one matched the plain operation. llvm-mc 21 (gfx1030) disassembles the words of every case to the intended opcode, selects and DPP control with the modifier bits cleared, since LLVM rejects them on integer opcodes, except `v_cndmask_b32` SDWA with sign extension, which LLVM rejects as well. The PS5's gfx1013 is not measured. `agc_driver_integer_source_modifiers` (new, `IntegerSourceModifiers.cpp`) runs 16 DPP16 and 16 SDWA cases of these opcodes over 16 input rows in 32 lanes. Its expected values are the hardware results of the same instruction words. `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_source_modifiers`, this PR | passed | passed | | same test on `main` | fails: `VOP1 DPP integer source modifiers are not supported` | fails: same message | | same test, this PR with the NEG XOR removed from the 32-bit `readOperand` path | fails: `v_not_b32 dpp neg of 0x00000000 ... is 0xffffffff, expected 0x7fffffff` | fails: same | | `-R "sdwa\|dpp\|integer_source_modifiers\|decoder_modifiers"` (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 | | the 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) | The one failure on the RX 9070 XT is `agc_driver_sdwa_ldexp_f16` (`lane 0 BYTE_2/BYTE_1 -> WORD_0 is 0x00000000, expected 0xffff8000`). `main` fails the same way on that GPU and passes on the iGPU; `v_ldexp_f16` has the float SDWA profile, whose decoding this PR does not change. On a device whose subgroups hold fewer than 32 lanes the test is skipped, as `Dpp16Operands` is: its `row_shl:1` cases read the neighbouring lane, which is in another subgroup there (lavapipe with 8-lane subgroups, reported in the comments). ### 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-18 16:11:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T16:11:33Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the PR’s reported hardware and test results support the new integer source modifier behavior.

What I ran

Reviewed head 0ac1bdcf6d8e53125c9f658c3fdbae06422b4047 using the prepared review bundle and repo_read.py. No commands or tests were run.

Results

Check Result Note
Diff and changed files passed All four changed files read
Runtime checks not run Results supplied in the PR description

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run the reported tests or verify their output independently. PS5 gfx1013 behavior is not measured, as the PR description notes. The prepared bundle excluded no changed files (files.json was not available; the manifest lists all four changed files as included).

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5960494532 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19577#pullrequestreview-5960494532). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T16:11:33Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the PR’s reported hardware and test results support the new integer source modifier behavior. ## What I ran Reviewed head `0ac1bdcf6d8e53125c9f658c3fdbae06422b4047` using the prepared review bundle and `repo_read.py`. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | All four changed files read | | Runtime checks | not run | Results supplied in the PR description | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not run the reported tests or verify their output independently. PS5 gfx1013 behavior is not measured, as the PR description notes. The prepared bundle excluded no changed files (`files.json` was not available; the manifest lists all four changed files as included). ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-22 14:06:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T14:06:51Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change based on the changed decoder logic and tests reviewed; the reported execution runs are author supplied.

What I ran

  • Reviewed head ee62e408b33bfcf5050816d0c5949469f9567d47 using the prepared diff and pinned reader.
  • No test commands were run.

Results

Check Result Note
Diff and decoder review passed Changed validation paths inspected
Tests in this review not run Hardware and CI results are author reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • Did not run the reported Vulkan tests or hardware oracle; the test results in the description were not independently confirmed.
  • Read all changed files: IntegerSourceModifiers.cpp, SdwaCvtOffSatPk.cpp, RdnaVectorOpDecoder.cpp, and shader.md. No changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6012631065 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19577#pullrequestreview-6012631065). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T14:06:51Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change based on the changed decoder logic and tests reviewed; the reported execution runs are author supplied. ## What I ran - Reviewed head `ee62e408b33bfcf5050816d0c5949469f9567d47` using the prepared diff and pinned reader. - No test commands were run. ## Results | Check | Result | Note | |---|---|---| | Diff and decoder review | passed | Changed validation paths inspected | | Tests in this review | not run | Hardware and CI results are author reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - Did not run the reported Vulkan tests or hardware oracle; the test results in the description were not independently confirmed. - Read all changed files: `IntegerSourceModifiers.cpp`, `SdwaCvtOffSatPk.cpp`, `RdnaVectorOpDecoder.cpp`, and `shader.md`. No changed files were excluded. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-25 20:21:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T20:21:52Z.

Review: APPROVED


Reviewed — looks good

The changed decoder and both updated execution tests are included and read at head 38fd7514b40a9e48d13eda72d722678a34952a9b; no verified defect was found in the inspected changes.

What I ran

  • Read the prepared description, commits, manifest, diff, and all four changed files listed in the manifest.
  • Used repo_read.py to inspect the changed decoder and test code at the pinned head. No tests were run.

Results

Check Result Note
Changed code review passed Four changed files read
Automated tests not run Test results in the description are author reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

No test execution was performed. Hardware results and CI outcomes in the PR description were not independently verified. No changed files were excluded; files.json was unavailable in the review bundle.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6064405766 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19577#pullrequestreview-6064405766). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T20:21:52Z. **Review:** APPROVED --- # Reviewed — looks good The changed decoder and both updated execution tests are included and read at head `38fd7514b40a9e48d13eda72d722678a34952a9b`; no verified defect was found in the inspected changes. ## What I ran - Read the prepared description, commits, manifest, diff, and all four changed files listed in the manifest. - Used `repo_read.py` to inspect the changed decoder and test code at the pinned head. No tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Four changed files read | | Automated tests | not run | Test results in the description are author reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No test execution was performed. Hardware results and CI outcomes in the PR description were not independently verified. No changed files were excluded; `files.json` was unavailable in the review bundle. ## 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!19577
No description provided.