feat(shader): accept every SDWA selector on VOP2 float ops #511

Merged
adriadam10 merged 1 commit from upstream-pr/511 into main 2026-10-05 18:13:45 +00:00
adriadam10 commented 2026-10-04 11:51:24 +00:00 (Migrated from github.com)

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


What

VOP2 SDWA on float ops threw for most selector combinations:

  • v_add_f32, v_sub_f32 and v_mul_f32 only accepted DWORD selectors.
  • v_add/sub/subrev/mul_f16 and v_min/max_f16 accepted word selectors but threw on byte selectors (source or destination).
  • v_subrev_f32, v_min_f32, v_max_f32 and v_mul_legacy_f32 had no SDWA rule, so any non-DWORD selector threw VOP2 SDWA modifier is not supported for opcode.

All of them now take every src0_sel/src1_sel (with sext, neg and abs) and every dst_sel with UNUSED_PAD, UNUSED_SEXT or UNUSED_PRESERVE, like v_cvt_pkrtz_f16_f32 already did. The three float profiles in the decoder are merged into one. The translator needed no change: the selected source field goes through applyBitSourceModifiers before neg/abs, and the result goes through writeRawU32, which places it in the destination field.

The reserved dst_unused value 3 still throws. v_ldexp_f16 is not in this PR: its second source is an integer.

Stacked on #509 (first commit), which merges the integer profiles in the same table.

Behaviour measured on HW (RDNA2, gfx1035)

I ran 78 random forms (all 13 ops, every selector, sext, neg, abs and clamp) on 1024 rows each, with f32 denormals preserved and flushed (DENORM=3 and 0). The Python model matches every result that isn't NaN. The model:

  • extracts the selected source field, zero- or sign-extends it to 32 bits, and reads those bits as the f32 operand (f32 ops) or the low 16 bits as the f16 operand (f16 ops), then applies abs and neg;
  • computes the op, then writes the destination field like on integer ops.

sext is honoured on float ops, although llvm-mc doesn't accept the syntax there. Its only visible effect is that a byte or word field with its top bit set becomes a quiet NaN. v_min/max_f32 then return the other operand. Byte selectors on f32 and f16 ops give denormals or zero, so most of those results depend on the denormal mode.

Tested

New execution test agc_driver_sdwa_float_selectors_tests: 16 forms × 32 rows with expected values from the hardware. A cell is checked only when its result is not NaN and is the same with denormals preserved or flushed. Vulkan lets drivers choose NaN payloads and flush denormals. There are 8 to 30 checked rows per form. The sext cases are checked through v_min/max_f32 and v_min/max_f16, which choose the NaN operand on the bits.

It passes on RADV, local lavapipe and CI's lavapipe (Ubuntu Mesa 25.2.8). It fails without each part of the change (4 mutations):

  • with the old full-width-only float rule, or with no rule for v_max_f32, it throws again;
  • dropping sext on the sources, or treating UNUSED_SEXT as UNUSED_PAD, gives wrong values.

The full Release ctest passes except agc_driver_pixel_helper_lanes, which also fails on main on local RADV.

f16 results still ignore clamp on the word and DWORD forms main already accepted. #323 fixes that. The byte-selector f16 forms this PR adds still throw when clamp is set (VOP2 SDWA clamp with byte selectors is not implemented), so no new form gives an unclamped result; the test checks that refusal on all six f16 ops (byte selector on the destination, src0 or src1), and it fails if the refusal is dropped or only looks at the destination.

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: #509
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4734119215 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/511). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T11:51:24Z. --- ### What VOP2 SDWA on float ops threw for most selector combinations: - `v_add_f32`, `v_sub_f32` and `v_mul_f32` only accepted DWORD selectors. - `v_add/sub/subrev/mul_f16` and `v_min/max_f16` accepted word selectors but threw on byte selectors (source or destination). - `v_subrev_f32`, `v_min_f32`, `v_max_f32` and `v_mul_legacy_f32` had no SDWA rule, so any non-DWORD selector threw `VOP2 SDWA modifier is not supported for opcode`. All of them now take every `src0_sel`/`src1_sel` (with `sext`, neg and abs) and every `dst_sel` with `UNUSED_PAD`, `UNUSED_SEXT` or `UNUSED_PRESERVE`, like `v_cvt_pkrtz_f16_f32` already did. The three float profiles in the decoder are merged into one. The translator needed no change: the selected source field goes through `applyBitSourceModifiers` before neg/abs, and the result goes through `writeRawU32`, which places it in the destination field. The reserved `dst_unused` value 3 still throws. `v_ldexp_f16` is not in this PR: its second source is an integer. Stacked on #509 (first commit), which merges the integer profiles in the same table. #### Behaviour measured on HW (RDNA2, gfx1035) I ran 78 random forms (all 13 ops, every selector, `sext`, neg, abs and clamp) on 1024 rows each, with f32 denormals preserved and flushed (`DENORM=3` and `0`). The Python model matches every result that isn't NaN. The model: - extracts the selected source field, zero- or sign-extends it to 32 bits, and reads those bits as the f32 operand (f32 ops) or the low 16 bits as the f16 operand (f16 ops), then applies abs and neg; - computes the op, then writes the destination field like on integer ops. `sext` is honoured on float ops, although llvm-mc doesn't accept the syntax there. Its only visible effect is that a byte or word field with its top bit set becomes a quiet NaN. `v_min/max_f32` then return the other operand. Byte selectors on f32 and f16 ops give denormals or zero, so most of those results depend on the denormal mode. ### Tested New execution test `agc_driver_sdwa_float_selectors_tests`: 16 forms × 32 rows with expected values from the hardware. A cell is checked only when its result is not NaN and is the same with denormals preserved or flushed. Vulkan lets drivers choose NaN payloads and flush denormals. There are 8 to 30 checked rows per form. The `sext` cases are checked through `v_min/max_f32` and `v_min/max_f16`, which choose the NaN operand on the bits. It passes on RADV, local lavapipe and CI's lavapipe (Ubuntu Mesa 25.2.8). It fails without each part of the change (4 mutations): - with the old full-width-only float rule, or with no rule for `v_max_f32`, it throws again; - dropping `sext` on the sources, or treating `UNUSED_SEXT` as `UNUSED_PAD`, gives wrong values. The full Release ctest passes except `agc_driver_pixel_helper_lanes`, which also fails on `main` on local RADV. f16 results still ignore `clamp` on the word and DWORD forms `main` already accepted. #323 fixes that. The byte-selector f16 forms this PR adds still throw when `clamp` is set (`VOP2 SDWA clamp with byte selectors is not implemented`), so no new form gives an unclamped result; the test checks that refusal on all six f16 ops (byte selector on the destination, src0 or src1), and it fails if the refusal is dropped or only looks at the destination. ### 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: #509 - [x] AI-assisted: yes
oneandonlydean commented 2026-10-04 21:08:06 +00:00 (Migrated from github.com)

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


Thanks, the selector handling is right: my own model (selected field, sext, then abs/neg on the f32 or low f16 bits, then dst_sel) matches all 376 checked cells of the test, including the sext cases on min/max that llvm-mc can't print. Leaving out the NaN and denormal-dependent cells keeps it host-independent, and it passes on my machine.

One thing before it can go in. As you say in the body, f16 results ignore clamp (float16Binary writes through writeF16, which never looks at destination.clamp). Main already has that gap for word and DWORD selectors, but this PR newly accepts the byte-selector f16 forms with clamp, so those would now run and give unclamped results instead of throwing. Could you keep refusing clamp on the f16 ops for the selector forms main didn't accept, or mark this as depending on #323 so the new forms land with clamp honoured? Either is fine with me.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984397019 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/511#issuecomment-5984397019). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T21:08:06Z. --- Thanks, the selector handling is right: my own model (selected field, `sext`, then abs/neg on the f32 or low f16 bits, then `dst_sel`) matches all 376 checked cells of the test, including the `sext` cases on min/max that llvm-mc can't print. Leaving out the NaN and denormal-dependent cells keeps it host-independent, and it passes on my machine. One thing before it can go in. As you say in the body, f16 results ignore `clamp` (`float16Binary` writes through `writeF16`, which never looks at `destination.clamp`). Main already has that gap for word and DWORD selectors, but this PR newly accepts the byte-selector f16 forms with `clamp`, so those would now run and give unclamped results instead of throwing. Could you keep refusing `clamp` on the f16 ops for the selector forms main didn't accept, or mark this as depending on #323 so the new forms land with clamp honoured? Either is fine with me.
adriadam10 commented 2026-10-04 21:13:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T21:13:33Z.


Thanks, went with keeping the refusal:

  • The six f16 ops (v_add/sub/subrev/mul/min/max_f16) now throw VOP2 SDWA clamp with byte selectors is not implemented when clamp is set and any selector (src0, src1 or dst) is a byte. Word and DWORD forms behave as on main, so #323 stays the fix for those; it can lift this refusal once it lands.
  • The test checks the refusal on all six ops, with the byte selector on the destination, src0 and src1. It fails if the refusal is removed or only checks the destination.
  • Rebased on current main; the test passes on RADV and lavapipe.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984442028 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/511#issuecomment-5984442028). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T21:13:33Z. --- Thanks, went with keeping the refusal: - The six f16 ops (`v_add/sub/subrev/mul/min/max_f16`) now throw `VOP2 SDWA clamp with byte selectors is not implemented` when `clamp` is set and any selector (src0, src1 or dst) is a byte. Word and DWORD forms behave as on `main`, so #323 stays the fix for those; it can lift this refusal once it lands. - The test checks the refusal on all six ops, with the byte selector on the destination, src0 and src1. It fails if the refusal is removed or only checks the destination. - Rebased on current `main`; the test passes on RADV and lavapipe.
oneandonlydean commented 2026-10-04 22:38:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:38:13Z.


Thanks, the refusal is in the right place. validateVop2Sdwa throws only for the new Float16 profile when clamp is set and any of src0, src1 or dst selects a byte (selector values 0 to 3), so word and DWORD forms behave as on main, and #323 can lift it later. I checked the six test encodings: they are v_add, v_sub, v_subrev, v_mul, v_max and v_min_f16 with clamp, with the byte selector on the destination, src0 and src1 between them, as you describe.

The first commit is #509's commit, patch-identical to #509's head, so this lands after #509.

agc_driver_sdwa_float_selectors passes on my NVIDIA machine on current main, and fails on main's code.

I'll run it through my PPSA21564 check with #509 next and merge both if it's clean.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985220710 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/511#issuecomment-5985220710). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T22:38:13Z. --- Thanks, the refusal is in the right place. `validateVop2Sdwa` throws only for the new `Float16` profile when clamp is set and any of src0, src1 or dst selects a byte (selector values 0 to 3), so word and DWORD forms behave as on main, and #323 can lift it later. I checked the six test encodings: they are v_add, v_sub, v_subrev, v_mul, v_max and v_min_f16 with clamp, with the byte selector on the destination, src0 and src1 between them, as you describe. The first commit is #509's commit, patch-identical to #509's head, so this lands after #509. `agc_driver_sdwa_float_selectors` passes on my NVIDIA machine on current main, and fails on main's code. I'll run it through my PPSA21564 check with #509 next and merge both if it's clean.
adriadam10 commented 2026-10-05 08:58:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T08:58:46Z.


Rebased on current main; #509 dropped out as already merged and there were no conflicts left. agc_driver_sdwa* and agc_shader* tests pass on RADV.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5991306004 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/511#issuecomment-5991306004). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T08:58:46Z. --- Rebased on current `main`; #509 dropped out as already merged and there were no conflicts left. `agc_driver_sdwa*` and `agc_shader*` tests pass on RADV.
adriadam10 commented 2026-10-05 12:49:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T12:49:53Z.


Rebased on current main (no conflicts); agc_driver_sdwa_float_selectors_tests passes on RADV and lavapipe.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5994785625 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/511#issuecomment-5994785625). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T12:49:53Z. --- Rebased on current `main` (no conflicts); `agc_driver_sdwa_float_selectors_tests` passes on RADV and lavapipe.
oneandonlydean commented 2026-10-05 18:13:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T18:13:02Z.


Ran PPSA21564 with this rebase on my integration branch (VOP2 float SDWA is in nearly every shader there): 4 runs, renders the same, no frame rate change. Ready to merge from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6000352906 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/511#issuecomment-6000352906). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T18:13:02Z. --- Ran PPSA21564 with this rebase on my integration branch (VOP2 float SDWA is in nearly every shader there): 4 runs, renders the same, no frame rate change. Ready to merge from my side.
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!511
No description provided.