fix(shader): v_mullit_f32 legacy rules, v_cvt_pk_u8_f32 rounding and VOP3 neg/abs #501
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/501"
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-04T10:27:31Z.
What
VOP3
neg/absonv_mullit_f32(all three sources) andv_cvt_pk_u8_f32(src0) used to throw. Enabling them showed that both ops differed from hardware even without modifiers, so this PR fixes that as well:v_mullit_f32was a plainv_mul_f32that ignored src2. It now follows the measured rules.v_cvt_pk_u8_f32truncated. It now rounds to nearest even, like the hardware (1.5 → 2, 2.5 → 2, 3.5 → 4).Anything still unmodelled keeps throwing: clamp/omod on both ops, and neg/abs on src1/src2 of
v_cvt_pk_u8_f32(llvm-mc rejects those too).Behaviour measured on HW
The ISA guide doesn't spell these out, so I measured them on an RDNA2 GPU (gfx1035; llvm-mc gives the same VOP3 opcode 0x150/0x15e on gfx1013). Modifiers apply before every check below.
v_mullit_f32 d, s0, s1, s2:0xff7fffff(−MAX_FLOAT). The −MAX test is exact:0xff7ffffemultiplies normally.| 0x400000), sign kept.v_cvt_pk_u8_f32: NaN and values ≤ 0 → 0, values ≥ 255 → 255, otherwise round to nearest even.These results don't depend on the IEEE or DENORM mode, with two exceptions: IEEE=0 keeps sNaN s0 unquieted, and flushed f32 denormals make a positive-denormal s2 count as 0. The implementation follows the default compute mode (IEEE=1, denormals kept), and the test has no sNaN or denormal rows.
To stay exact on any driver, everything is done on the bits:
RoundEvenisn't in Vulkan's precision table.v_mad_legacy_f32is not included: on gfx1030+ its opcode 0x140 isv_fma_legacy_f32, so I can't measure it on my GPU, and its translation stays as it is on main.Tested
Linux, RADV + lavapipe (local Mesa and CI's Ubuntu Mesa 25.2.8):
agc_driver_vop3_legacy_source_modifiers_tests: 32 lanes × 10 forms, expected values taken from the hardware. The rows cover the specials (±0, ±inf, qNaN with payloads, ±MAX, −MAX−1ulp), rounding ties, and both clamp edges.agc_driver_pixel_helper_lanes, which already fails on main with local RADV (not touched here).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:07:56Z.
Thanks, checked against the RDNA2 ISA guide (V_MULLIT_F32 only says "specific INF, NaN, overflow rules", and the older GCN description has the same -MAX_FLOAT conditions you measured) and the code follows your rules exactly: the -MAX test catches -MAX, -inf and negative NaNs, the FMul never sees a NaN or zero operand, and the u8 rounding is exact (truncate, exact fraction, ties to even, 255 guard). The new modifier block for
v_cvt_pk_u8_f32sits before the generic path, so src1/src2 modifiers, clamp and omod still throw. A small note, not blocking: the sNaN s0 quieting and the positive-denormal s2 case follow IEEE=1 with denormals kept, while the recompiler doesn't read the mode; a TechnicalDebt line would make that visible. This changes results of unmodifiedv_cvt_pk_u8_f32andv_mullit_f32, so I'll run it through my PPSA21564 check before merging; ready to merge from my side.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T21:09:33Z.
Added the TechnicalDebt line under "Functional":
v_mullit_f32follows the hardware measured at IEEE=1 with denormals kept (sNaN src0 quieted, positive denormal src2 counts as positive), and the recompiler does not read MODE. Also rebased on current main;agc_driver_vop3_legacy_source_modifiers_testsstill passes on RADV and lavapipe.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:38:10Z.
Thanks, the TechnicalDebt line says exactly what the code assumes (IEEE=1 with denormals kept, sNaN src0 quieted, positive denormal src2 positive) and the rebase left the fix commit unchanged.
agc_driver_vop3_legacy_source_modifiersstill passes on my NVIDIA machine with the new head on current main, and fails on main's code.I'll run it through my PPSA21564 check next and merge it after that if it's clean.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T07:26:30Z.
#498 landed today, and it now conflicts with this one in
checkNativeVop3Modifiers: #498 added anif (opcode == RdnaOpcode::VLdexpF16)block in the same place as yourVCvtPkU8F32block, and the two bodies are identical. Keeping both fixes it, either as two blocks or as one condition:I tried the combined form here on current main and the full ctest passes,
agc_driver_vop3_legacy_source_modifiersincluded. Could you rebase? I also checked the 5,688 PPSA21564 shaders I have dumped: none usev_mullit_f32orv_cvt_pk_u8_f32, so this doesn't need my PPSA21564 check after all, and I'll merge it once it's rebased.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T08:57:16Z.
Rebased on current
mainafter #498:checkNativeVop3Modifiers: kept both opcodes in one condition,VLdexpF16 || VCvtPkU8F32, as suggested.agc_driver_vop3_legacy_source_modifiersand the otheragc_driver_vop3*/agc_shader*tests pass on RADV.