feat(shader): accept every SDWA selector on VOP2 float ops #511
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/511"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_f32andv_mul_f32only accepted DWORD selectors.v_add/sub/subrev/mul_f16andv_min/max_f16accepted word selectors but threw on byte selectors (source or destination).v_subrev_f32,v_min_f32,v_max_f32andv_mul_legacy_f32had no SDWA rule, so any non-DWORD selector threwVOP2 SDWA modifier is not supported for opcode.All of them now take every
src0_sel/src1_sel(withsext, neg and abs) and everydst_selwithUNUSED_PAD,UNUSED_SEXTorUNUSED_PRESERVE, likev_cvt_pkrtz_f16_f32already did. The three float profiles in the decoder are merged into one. The translator needed no change: the selected source field goes throughapplyBitSourceModifiersbefore neg/abs, and the result goes throughwriteRawU32, which places it in the destination field.The reserved
dst_unusedvalue 3 still throws.v_ldexp_f16is 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=3and0). The Python model matches every result that isn't NaN. The model:sextis 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_f32then 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. Thesextcases are checked throughv_min/max_f32andv_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):
v_max_f32, it throws again;sexton the sources, or treatingUNUSED_SEXTasUNUSED_PAD, gives wrong values.The full Release ctest passes except
agc_driver_pixel_helper_lanes, which also fails onmainon local RADV.f16 results still ignore
clampon the word and DWORD formsmainalready accepted. #323 fixes that. The byte-selector f16 forms this PR adds still throw whenclampis 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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)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, thendst_sel) matches all 376 checked cells of the test, including thesextcases 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(float16Binarywrites throughwriteF16, which never looks atdestination.clamp). Main already has that gap for word and DWORD selectors, but this PR newly accepts the byte-selector f16 forms withclamp, so those would now run and give unclamped results instead of throwing. Could you keep refusingclampon 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.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T21:13:33Z.
Thanks, went with keeping the refusal:
v_add/sub/subrev/mul/min/max_f16) now throwVOP2 SDWA clamp with byte selectors is not implementedwhenclampis set and any selector (src0, src1 or dst) is a byte. Word and DWORD forms behave as onmain, so #323 stays the fix for those; it can lift this refusal once it lands.main; the test passes on RADV and lavapipe.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:38:13Z.
Thanks, the refusal is in the right place.
validateVop2Sdwathrows only for the newFloat16profile 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_selectorspasses 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.
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*andagc_shader*tests pass on RADV.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_testspasses on RADV and lavapipe.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.