feat(shader): accept float modifiers on v_cndmask_b32, v_mul_legacy_f32 and v_ldexp_f16 #498
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/498"
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-04T09:46:26Z.
What
v_cndmask_b32,v_mul_legacy_f32andv_ldexp_f16now accept the float modifiers thatllvm-mc -mcpu=gfx1013accepts for them and that were still rejected. The modifier sweep over decoded opcodes found them:v_cndmask_b32v_mul_legacy_f32v_ldexp_f16Translation changes:
v_cndmask_b32applies neg/abs on the bits (sign flip and clear). Before this, when a modifier was set, the operands went throughOpFNegate/FAbsandSelectF32. RADV flushes the denormal there (-0x00000001came out as0x80000000). On hardware the select keeps every bit, denormals and NaN payloads included, in every float mode.v_ldexp_f16reads src0 withreadF16Bits(bit modifiers, asv_frexp_*_f16already 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_f32keeps its translation. Clamp and omod go throughapplyF32ResultModifiers, the same asv_mul_f32.v_ldexp_f16clamp/omod stays rejected: f16 result modifiers are what #323 changes.v_mac_legacy_f32is 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_b32neg/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; SDWAdst_sel:DWORDzeroes it.v_mul_f32), f16 denormal and signalling NaN ldexp inputs, and clamp of −0/NaN.FPSaturate32is GLSLFClamp, which leaves those unspecified, the same as every f32 clamp today.Side finding while picking this batch:
tfeon 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
Vop2ModifierFormsruns 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 inv_ldexp_f16, dropping omod or clamp inv_mul_legacy_f32, and removingv_mul_legacy_f32from the VOP2 float list (decoder error). Taking the NaN result from the driver inv_ldexp_f16still 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 exceptagc_driver_pixel_helper_lanes, which also fails onmainon local RADV since #305.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 adriadam10 on 2026-10-04T10:08:58Z.
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.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T23:09:24Z.
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_b32now reads both sources withreadU32, which applies abs/neg as bit operations, and selects the raw bits. That's the hardware behaviour.v_ldexp_f16takes 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_f32produces an F32 value, so clamp/omod reachapplyF32ResultModifiersthroughwriteOperand, the same asv_mul_f32.The
v_cndmask_b32fix 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_logives 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_b32with 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:supportsNativeVop3SourceModifiersclashes by one line with #447/#474 (both add a case at the end of the list; keep both).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T02:59:54Z.
Rebased on current main after #447/#474:
supportsNativeVop3SourceModifierskeeps bothVTrigPreopF64andVLdexpF16. Commit otherwise unchanged;agc_driver_vop2_modifier_formsandagc_driver_f64_transcendentalpass on RADV and lavapipe.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:04:01Z.
Gated on PPSA21564: no visual or FPS change.