Skip to content

feat(shader): accept float modifiers on v_cndmask_b32, v_mul_legacy_f32 and v_ldexp_f16 - #498

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

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

Conversation

@adriadam10

Copy link
Copy Markdown
Collaborator

What

v_cndmask_b32, v_mul_legacy_f32 and v_ldexp_f16 now accept the float modifiers that llvm-mc -mcpu=gfx1013 accepts for them and that were still rejected. The modifier sweep over decoded opcodes found them:

Op Newly accepted Still throws
v_cndmask_b32 neg/abs on DPP (VOP3 and SDWA already accepted them) clamp
v_mul_legacy_f32 neg/abs on DPP and SDWA, clamp/omod on SDWA and VOP3 sub-dword SDWA selectors
v_ldexp_f16 neg/abs on src0 for VOP3, DPP and SDWA neg/abs on src1 (integer exponent), clamp/omod, op_sel

Translation changes:

  • v_cndmask_b32 applies neg/abs on the bits (sign flip and clear). Before this, when a modifier was set, the operands went through OpFNegate/FAbs and SelectF32. RADV flushes the denormal there (-0x00000001 came out as 0x80000000). On hardware the select keeps every bit, denormals and NaN payloads included, in every float mode.
  • v_ldexp_f16 reads src0 with readF16Bits (bit modifiers, as v_frexp_*_f16 already does). A NaN input now returns the NaN chosen on the bits (input with modifiers applied, quiet bit set) instead of whatever the driver's f16→f32→f16 path gives.
  • v_mul_legacy_f32 keeps its translation. Clamp and omod go through applyF32ResultModifiers, the same as v_mul_f32.

v_ldexp_f16 clamp/omod stays rejected: f16 result modifiers are what #323 changes. v_mac_legacy_f32 is unchanged because gfx1035 doesn't have it, so I can't measure it.

Behaviour measured on HW

Ran on a Radeon 660M (gfx1035; same VOP2/VOP3 encodings as gfx1013 for these ops) with the 15 forms in the test, over 1836 (a, b, condition) rows: zeros of both signs, denormals, infinities, quiet and signalling NaNs, values around 1.0, overflow, f16 values in the low half with garbage in the high half, and f16 exponents up to ±64 and beyond. 17624 checked cells match the model, 0 mismatches:

  • v_cndmask_b32 neg/abs on DPP, SDWA and VOP3 are bit operations. They keep denormals and NaN payloads, with f32 denormals both on and flushed.
  • v_mul_legacy_f32: either source ±0 after modifiers → +0, otherwise IEEE multiply, then omod, then clamp. omod only applies with IEEE=0 and f32 denormals flushed (default compute mode ignores it, as for every f32 op). The recompiler already models omod as applied, so the omod rows come from that mode.
  • v_ldexp_f16: modifiers on the f16 bits, result rounded once to f16, NaN → input bits with quiet bit set (IEEE mode). VOP3/DPP keep the high half of the destination; SDWA dst_sel:DWORD zeroes it.
  • Not modelled, so excluded from the test: products that underflow (their sign depends on flush mode), mul_legacy NaN rows (the driver picks the payload, as for v_mul_f32), f16 denormal and signalling NaN ldexp inputs, and clamp of −0/NaN. FPSaturate32 is GLSL FClamp, which leaves those unspecified, the same as every f32 clamp today.

Side finding while picking this batch: tfe on MUBUF/MTBUF loads leaves the extra status VGPR unchanged on hardware, both in bounds and out of bounds, so the current decode (ignore it) is already right for non-sparse buffers.

Tested

Arch Linux, RADV (Radeon 660M) plus lavapipe (local Mesa and the CI version, Ubuntu Mesa 25.2.8). New execution test Vop2ModifierForms runs the 15 forms on 32 HW rows (382 checked cells, the rest are the excluded classes above).

Negative checks, each making the test fail: the old float select in v_cndmask_b32 (RADV), dropping src0 modifiers in v_ldexp_f16, dropping omod or clamp in v_mul_legacy_f32, and removing v_mul_legacy_f32 from the VOP2 float list (decoder error). Taking the NaN result from the driver in v_ldexp_f16 still passes on RADV and lavapipe, because they keep the payload. The bit-level NaN is there for drivers that return a canonical NaN.
Full Release build plus ctest: everything passes except agc_driver_pixel_helper_lanes, which also fails on main on local RADV since #305.

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

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

Copy link
Copy Markdown
Collaborator Author

Rebased on current main (conflict with the f64 entries of #446 in the VOP3 float-modifier list; both kept). Vop2ModifierForms and F64Arithmetic pass on RADV and lavapipe.

@adriadam10
adriadam10 force-pushed the feat/vop2-dpp-sdwa-float-mods branch from e0d6cb3 to 0e94b46 Compare October 4, 2026 10:08
@github-actions github-actions Bot added shader core/shader agc libSceAgc* and removed needs rebase Conflicts with main, rebase needed labels Oct 4, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks. I checked the 15 forms in the test kernel with llvm-mc, and they are the DPP, SDWA and VOP3 forms the table lists. The decoder changes do what the table says: src1 modifiers are still refused on v_ldexp_f16, along with op_sel, clamp and omod. The translation is right too:

  • v_cndmask_b32 now reads both sources with readU32, which applies abs/neg as bit operations, and selects the raw bits. That's the hardware behaviour.
  • v_ldexp_f16 takes the NaN on the modified f16 bits with the quiet bit set. Otherwise the result is rounded once to f16, which is exact since the f16 value times 2^k fits in f32 for the clamped k.
  • v_mul_legacy_f32 produces an F32 value, so clamp/omod reach applyF32ResultModifiers through writeOperand, the same as v_mul_f32.

The v_cndmask_b32 fix matters on NVIDIA too, not just RADV. With main's float select put back into this head, the test fails on my NVIDIA machine at lane 17: v_cndmask_b32_sdwa v13, -|v4|, -v5, vcc_lo gives 0x80000000 where 0x80000001 is expected. That SDWA form is already accepted on main, so main flushes the denormal there today. At this head the test passes. With only the test file on main's code it fails earlier, at the DPP decode ("VOP2 DPP integer source modifiers are not supported").

v_cndmask_b32 with neg/abs (e64 and SDWA) appears in most of the PPSA21564 shaders I have dumped, so this changes results on its path, though only for denormal and NaN inputs. I'll run it through my PPSA21564 check before merging. One small thing for the merge order: supportsNativeVop3SourceModifiers clashes by one line with #447/#474 (both add a case at the end of the list; keep both).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 5, 2026
…32 and v_ldexp_f16

- v_cndmask_b32: neg/abs on DPP; neg/abs applied on the bits, as the hardware does
- v_mul_legacy_f32: neg/abs on DPP and SDWA, clamp/omod on SDWA and VOP3
- v_ldexp_f16: neg/abs on src0 for VOP3, DPP and SDWA; NaN result chosen on the bits

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator Author

Rebased on current main after #447/#474: supportsNativeVop3SourceModifiers keeps both VTrigPreopF64 and VLdexpF16. Commit otherwise unchanged; agc_driver_vop2_modifier_forms and agc_driver_f64_transcendental pass on RADV and lavapipe.

@adriadam10
adriadam10 force-pushed the feat/vop2-dpp-sdwa-float-mods branch from 0e94b46 to e58e2f0 Compare October 5, 2026 02:59
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 5, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Gated on PPSA21564: no visual or FPS change.

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