Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
adriadam10:feat/sdwa-vop2-float-selectors
Oct 5, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
adriadam10:feat/sdwa-vop2-float-selectors

Conversation

@adriadam10

@adriadam10 adriadam10 commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

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: feat(shader): accept every SDWA selector on VOP2 integer ops #509
  • AI-assisted: yes

@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Oct 4, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

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
adriadam10 force-pushed the feat/sdwa-vop2-float-selectors branch from 21bed75 to a911e79 Compare October 4, 2026 21:13
@adriadam10

Copy link
Copy Markdown
Collaborator Author

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 fix(shader): apply clamp but not omod to f16 results, as RDNA does #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

Copy link
Copy Markdown
Collaborator

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 5, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator Author

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
adriadam10 force-pushed the feat/sdwa-vop2-float-selectors branch from a911e79 to 6183940 Compare October 5, 2026 08:58
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 5, 2026
Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator Author

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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants