feat(shader): accept every SDWA selector on VOP2 integer ops #509

Merged
adriadam10 merged 1 commit from upstream-pr/509 into main 2026-10-05 08:32:56 +00:00
adriadam10 commented 2026-10-04 11:29:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T11:29:55Z.


What

VOP2 SDWA on integer ops threw for most selector combinations:

  • v_min_i32, v_max_i32, v_sub_co_ci_u32, v_subrev_co_ci_u32 had no SDWA rule, so any non-DWORD selector threw VOP2 SDWA modifier is not supported for opcode.
  • On v_mul_{i32_i24,hi_i32_i24,u32_u24,hi_u32_u24}, v_max_u32, v_lshrrev_b32, v_ashrrev_i32, v_lshlrev_b32, v_add_co_ci_u32 and v_subrev_nc_u32, any dst_sel other than DWORD threw. On v_and/or/xor/xnor_b32, byte dst_sel threw.

All of them now take every src0_sel/src1_sel (with sext) and every dst_sel with UNUSED_PAD, UNUSED_SEXT or UNUSED_PRESERVE, like v_add_nc_u32 and v_min_u32 already did. The five integer profiles in the decoder are merged into one. The translator needed no change: these ops already read their sources through applyBitSourceModifiers and write through writeRawU32, which apply the selectors. On the carry ops, the carry is computed from the selected 32-bit operands. Only the VGPR write depends on dst_sel.

clamp on these ops and the reserved dst_unused value 3 still throw.

Behaviour measured on HW (RDNA2, gfx1035)

I ran the 13 forms in the test (all 13 ops, with byte and word selectors, sext on either source, and all three dst_unused modes, plus the carry-out of the three carry ops) on 2048 rows of edge words and random values. The Python model matches all 32768 results. The model zero- or sign-extends the selected source field, computes the 32-bit op, then writes the destination field: zero the rest, sign-extend upward with the lower bits zero, or keep the rest.

Tested

New execution test agc_driver_sdwa_integer_selectors_tests: 32 rows with expected values from the hardware (the model matches every cell). Rows are picked so each op gets both signs of each selected source, both values of the carry and the top bit of the written field. For min/max both comparison outcomes are covered, and for shifts the counts 0, 1-15 and 16-31.

It passes on RADV and lavapipe. It fails without each part of the change: no rule for v_min_i32, no rule for v_sub_co_ci_u32 and a DWORD-only destination for the integer profile all throw again, and dropping sext on the sources gives wrong values (4 mutations). The full Release ctest passes except agc_driver_pixel_helper_lanes, which also fails on main on local RADV.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4733978528 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/509). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T11:29:55Z. --- ### What VOP2 SDWA on integer ops threw for most selector combinations: - `v_min_i32`, `v_max_i32`, `v_sub_co_ci_u32`, `v_subrev_co_ci_u32` had no SDWA rule, so any non-DWORD selector threw `VOP2 SDWA modifier is not supported for opcode`. - On `v_mul_{i32_i24,hi_i32_i24,u32_u24,hi_u32_u24}`, `v_max_u32`, `v_lshrrev_b32`, `v_ashrrev_i32`, `v_lshlrev_b32`, `v_add_co_ci_u32` and `v_subrev_nc_u32`, any `dst_sel` other than DWORD threw. On `v_and/or/xor/xnor_b32`, byte `dst_sel` threw. All of them now take every `src0_sel`/`src1_sel` (with `sext`) and every `dst_sel` with `UNUSED_PAD`, `UNUSED_SEXT` or `UNUSED_PRESERVE`, like `v_add_nc_u32` and `v_min_u32` already did. The five integer profiles in the decoder are merged into one. The translator needed no change: these ops already read their sources through `applyBitSourceModifiers` and write through `writeRawU32`, which apply the selectors. On the carry ops, the carry is computed from the selected 32-bit operands. Only the VGPR write depends on `dst_sel`. `clamp` on these ops and the reserved `dst_unused` value 3 still throw. #### Behaviour measured on HW (RDNA2, gfx1035) I ran the 13 forms in the test (all 13 ops, with byte and word selectors, `sext` on either source, and all three `dst_unused` modes, plus the carry-out of the three carry ops) on 2048 rows of edge words and random values. The Python model matches all 32768 results. The model zero- or sign-extends the selected source field, computes the 32-bit op, then writes the destination field: zero the rest, sign-extend upward with the lower bits zero, or keep the rest. ### Tested New execution test `agc_driver_sdwa_integer_selectors_tests`: 32 rows with expected values from the hardware (the model matches every cell). Rows are picked so each op gets both signs of each selected source, both values of the carry and the top bit of the written field. For min/max both comparison outcomes are covered, and for shifts the counts 0, 1-15 and 16-31. It passes on RADV and lavapipe. It fails without each part of the change: no rule for `v_min_i32`, no rule for `v_sub_co_ci_u32` and a DWORD-only destination for the integer profile all throw again, and dropping `sext` on the sources gives wrong values (4 mutations). The full Release ctest passes except `agc_driver_pixel_helper_lanes`, which also fails on `main` on local RADV. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
oneandonlydean commented 2026-10-04 21:08:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:08:03Z.


Thanks, checked against the RDNA2 ISA SDWA description: the source field is extracted (sign-extended with sext), the op runs at 32 bits, and dst_sel/dst_unused place the low bits of the result. The translator already reads these ops through applyBitSourceModifiers and writes through writeRawU32, so the decoder change is all that was missing, and forms main already accepted decode the same way. I disassembled the test with llvm-mc and wrote my own model of it; it matches all 512 expected values, including the carry-outs. The new test fails on main and the full ctest passes with it on my machine. Ready to merge from my side; I'll run it through my PPSA21564 check before merging, together with #510.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984396632 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/509#issuecomment-5984396632). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T21:08:03Z. --- Thanks, checked against the RDNA2 ISA SDWA description: the source field is extracted (sign-extended with `sext`), the op runs at 32 bits, and `dst_sel`/`dst_unused` place the low bits of the result. The translator already reads these ops through `applyBitSourceModifiers` and writes through `writeRawU32`, so the decoder change is all that was missing, and forms main already accepted decode the same way. I disassembled the test with llvm-mc and wrote my own model of it; it matches all 512 expected values, including the carry-outs. The new test fails on main and the full ctest passes with it on my machine. Ready to merge from my side; I'll run it through my PPSA21564 check before merging, together with #510.
oneandonlydean commented 2026-10-05 08:31:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T08:31:20Z.


Gated on PPSA21564 with #510 on top: no visual or FPS change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5990921699 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/509#issuecomment-5990921699). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T08:31:20Z. --- Gated on PPSA21564 with #510 on top: no visual or FPS change.
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!509
No description provided.