feat(shader): accept every SDWA selector, clamp and omod on v_ldexp_f16 #666

Merged
adriadam10 merged 2 commits from upstream-pr/666 into main 2026-10-06 05:35:47 +00:00
adriadam10 commented 2026-10-05 13:00:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T13:00:32Z.


What

v_ldexp_f16 was the only VOP2 f16 op left out of #511: any SDWA selector, clamp or omod threw (VOP2 SDWA modifier is not supported for opcode / output modifiers are not supported). It now takes the Float16 SDWA profile from #511:

  • every src0_sel/src1_sel (with sext) and every dst_sel with UNUSED_PAD, UNUSED_SEXT or UNUSED_PRESERVE;
  • neg/abs on src0;
  • clamp, applied by #664's clampF16Bits; with a byte selector it throws VOP2 SDWA clamp with byte selectors is not implemented, like the other f16 ops in #511;
  • omod, which the hardware ignores on this op (below).

Neg/abs on src1 (the integer exponent) still throw. That check used to run only for full-width SDWA; it now runs for every selector, so -v5 with src1_sel:BYTE_0 doesn't get through. For every other op the result is the same as before: their rules already refuse those modifiers, or the ops are float ops that accept them.

No translator change: the selected fields go through applyBitSourceModifiers and writeRawU32 as in #511, and vLdexpF16 already reads the exponent as the low 16 bits of src1, sign-extended.

Stacked on #511 (first commit) and #664 (second commit). This PR is only the third commit.

Behaviour measured on HW (RDNA2, gfx1035)

96 random SDWA forms (all selectors, sext on both sources, neg/abs on src0, clamp with word/dword selectors) × 1024 rows, with f16 denormals preserved and flushed (DENORM16=3 and 0): the model matches all 196,608 results. The model:

  • src0 = selected field, zero- or sign-extended, low 16 bits read as f16, then abs/neg;
  • exponent = selected src1 field (zero- or sign-extended), then its low 16 bits as a signed i16, clamped to [-64, 64]. The other reading (the field taken as an i32) gives 2,000+ mismatches, for example WORD_1 without sext and the top bit set.
  • result = src0 × 2^exponent rounded to f16; NaN input → input | 0x200; clamp → [+0, 1.0], NaN → +0, -0 → +0;
  • destination field written like on the other SDWA ops.

omod (mul:2, mul:4, div:2) on 3 forms × 1024 rows: the result is the same as with no omod, in both denormal modes.

Tested

New execution test agc_driver_sdwa_ldexp_f16_tests: 16 SDWA forms × 32 rows with expected values from the hardware, two with omod, five with clamp. A cell is checked when its result is the same with f16 denormals preserved and flushed (NaN results are chosen on the bits, so they are checked too). It also checks that clamp with a byte selector in src0, src1 or dst, and neg/abs on src1, still throw.

It passes on RADV, local lavapipe and CI's lavapipe (Ubuntu Mesa 25.2.8, 1 s cold). It fails without each part of the change (5 mutations): without the SDWA profile, clamp or omod it throws; with the src1 modifier check only at full width the refusal check fails; with clampF16Bits removed from vLdexpF16 (#664) the clamp rows fail.

Full Release ctest passes except agc_driver_pixel_helper_lanes, agc_driver_pixel_lds and agc_driver_pixel_lds_lane_slots, which also fail on main on local RADV (wave32 lane 32 on RADV's 64-wide subgroup).

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: #511, #664
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4745280470 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/666). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T13:00:32Z. --- ### What `v_ldexp_f16` was the only VOP2 f16 op left out of #511: any SDWA selector, `clamp` or `omod` threw (`VOP2 SDWA modifier is not supported for opcode` / `output modifiers are not supported`). It now takes the `Float16` SDWA profile from #511: - every `src0_sel`/`src1_sel` (with `sext`) and every `dst_sel` with `UNUSED_PAD`, `UNUSED_SEXT` or `UNUSED_PRESERVE`; - neg/abs on src0; - `clamp`, applied by #664's `clampF16Bits`; with a byte selector it throws `VOP2 SDWA clamp with byte selectors is not implemented`, like the other f16 ops in #511; - `omod`, which the hardware ignores on this op (below). Neg/abs on src1 (the integer exponent) still throw. That check used to run only for full-width SDWA; it now runs for every selector, so `-v5` with `src1_sel:BYTE_0` doesn't get through. For every other op the result is the same as before: their rules already refuse those modifiers, or the ops are float ops that accept them. No translator change: the selected fields go through `applyBitSourceModifiers` and `writeRawU32` as in #511, and `vLdexpF16` already reads the exponent as the low 16 bits of src1, sign-extended. Stacked on #511 (first commit) and #664 (second commit). This PR is only the third commit. #### Behaviour measured on HW (RDNA2, gfx1035) 96 random SDWA forms (all selectors, `sext` on both sources, neg/abs on src0, clamp with word/dword selectors) × 1024 rows, with f16 denormals preserved and flushed (`DENORM16=3` and `0`): the model matches all 196,608 results. The model: - src0 = selected field, zero- or sign-extended, low 16 bits read as f16, then abs/neg; - exponent = selected src1 field (zero- or sign-extended), then its low 16 bits as a signed i16, clamped to [-64, 64]. The other reading (the field taken as an i32) gives 2,000+ mismatches, for example `WORD_1` without `sext` and the top bit set. - result = src0 × 2^exponent rounded to f16; NaN input → input | 0x200; `clamp` → [+0, 1.0], NaN → +0, -0 → +0; - destination field written like on the other SDWA ops. `omod` (mul:2, mul:4, div:2) on 3 forms × 1024 rows: the result is the same as with no omod, in both denormal modes. ### Tested New execution test `agc_driver_sdwa_ldexp_f16_tests`: 16 SDWA forms × 32 rows with expected values from the hardware, two with `omod`, five with `clamp`. A cell is checked when its result is the same with f16 denormals preserved and flushed (NaN results are chosen on the bits, so they are checked too). It also checks that clamp with a byte selector in src0, src1 or dst, and neg/abs on src1, still throw. It passes on RADV, local lavapipe and CI's lavapipe (Ubuntu Mesa 25.2.8, 1 s cold). It fails without each part of the change (5 mutations): without the SDWA profile, clamp or omod it throws; with the src1 modifier check only at full width the refusal check fails; with `clampF16Bits` removed from `vLdexpF16` (#664) the clamp rows fail. Full Release ctest passes except `agc_driver_pixel_helper_lanes`, `agc_driver_pixel_lds` and `agc_driver_pixel_lds_lane_slots`, which also fail on `main` on local RADV (wave32 lane 32 on RADV's 64-wide subgroup). ### 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: #511, #664 - [x] AI-assisted: yes
adriadam10 commented 2026-10-05 17:08:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T17:08:14Z.


Rebased on main, restacked on #511 and the rebased #664 (no conflict in this PR's own commit). SdwaLdexpF16, SdwaFloatSelectors, Float16Modifiers, Float16TernaryClamp and Vop3LegacySourceModifiers pass on RADV and lavapipe.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5999295878 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/666#issuecomment-5999295878). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T17:08:14Z. --- Rebased on main, restacked on #511 and the rebased #664 (no conflict in this PR's own commit). SdwaLdexpF16, SdwaFloatSelectors, Float16Modifiers, Float16TernaryClamp and Vop3LegacySourceModifiers pass on RADV and lavapipe.
adriadam10 commented 2026-10-05 18:18:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T18:18:32Z.


Rebased on main after #511 merged (its commit dropped from this branch, the rest unchanged). The SDWA, float16 and ternary clamp execution tests pass on RADV and on CI's lavapipe.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6000441535 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/666#issuecomment-6000441535). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T18:18:32Z. --- Rebased on main after #511 merged (its commit dropped from this branch, the rest unchanged). The SDWA, float16 and ternary clamp execution tests pass on RADV and on CI's lavapipe.
adriadam10 commented 2026-10-05 18:31:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T18:31:56Z.


Rebased on main (#511 merged) and on the rebased #664; agc_driver_sdwa_ldexp_f16 passes again. Now only #664's commit + this one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6000655502 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/666#issuecomment-6000655502). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T18:31:56Z. --- Rebased on main (#511 merged) and on the rebased #664; `agc_driver_sdwa_ldexp_f16` passes again. Now only #664's commit + this one.
oneandonlydean commented 2026-10-05 19:45:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T19:45:40Z.


Thanks for the rebase. #507 has since renamed usesSignedSaturateClamp to usesIntegerSaturateClamp, so ab58ce709 conflicts again on the same return line in supportsNativeVop3Clamp. Once #664 is rebased (I suggested the resolution there), rebasing this on it should only need main's name on that line. I tested that combination: agc_driver_sdwa_ldexp_f16 fails on main's code, passes with the change, and passes 20 times in a row. It has to land after #664, since without clampF16Bits a clamp on v_ldexp_f16 would be accepted and dropped.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6001772059 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/666#issuecomment-6001772059). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T19:45:40Z. --- Thanks for the rebase. #507 has since renamed `usesSignedSaturateClamp` to `usesIntegerSaturateClamp`, so ab58ce709 conflicts again on the same return line in `supportsNativeVop3Clamp`. Once #664 is rebased (I suggested the resolution there), rebasing this on it should only need main's name on that line. I tested that combination: `agc_driver_sdwa_ldexp_f16` fails on main's code, passes with the change, and passes 20 times in a row. It has to land after #664, since without `clampF16Bits` a clamp on `v_ldexp_f16` would be accepted and dropped.
oneandonlydean commented 2026-10-05 20:07:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T20:07:58Z.


Sorry, please ignore my rebase note above: this branch is already on top of #507 (and #664), and I was looking at an older head. It merges cleanly with main as it is, and still needs to land after #664.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6002070833 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/666#issuecomment-6002070833). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T20:07:58Z. --- Sorry, please ignore my rebase note above: this branch is already on top of #507 (and #664), and I was looking at an older head. It merges cleanly with main as it is, and still needs to land after #664.
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!666
No description provided.