fix(shader): apply clamp on v_div_scale_f64 and accept omod on the f32 division steps and v_div_scale #663
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/663"
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-05T12:32:18Z.
What
Finishes the result modifiers of the division helper ops:
v_div_scale_f64withclampwas decoded since #563 but the clamp was dropped (the result was written withoutFPSaturate64). It now goes throughwriteF64Result, likev_div_fmas_f64/v_div_fixup_f64since #610.omod(mul:2,mul:4,div:2) is accepted onv_div_fmas_f32,v_div_fixup_f32andv_div_scale_f32(applied with the #567 rule throughwriteOperand), and onv_div_scale_f64(ignored, as on the hardware and as on the other f64 ops).DivisionResultModifiers.cpp(added by #610) is removed, since those forms are now translated.Every other modifier on these ops keeps throwing.
Behaviour measured on HW
gfx1035 (Radeon 660M),
IEEE=0 DENORM=0(the mode the recompiler assumes, as in #567/#610). 4096 rows per op (special values, random bits, exponents near the scaling thresholds):v_div_scale_f32(denominator and numerator forms):clamp= the #500 f32 clamp rule,omod= the #567 rule. 0 mismatches.v_div_scale_f64:clamp=FPSaturate64on the result,omodignored. 0 mismatches.v_div_fmas_f32/v_div_fixup_f32withmul:2/mul:4/div:2: the #567 rule, 0 mismatches over 4096 rows (same data as #610).DENORM=3the hardware ignores f32omodon these ops, as onv_mul_f32; already noted in TechnicalDebt ("output modifier"), unchanged.Tested
Linux (CachyOS), RADV and lavapipe (local and CI's Ubuntu lavapipe 25.2.8, cold 0 s).
DivisionOutputModifiers.cppexecution test: 12 instructions (f32 fmas/fixup omod, f32/f64 div_scale clamp/omod, both operand forms), 32 rows, expected values from the hardware. Cells with denormal inputs/results, or whose unmodified result depends on the denormal mode, or whose f32 fmas product is inexact (theFmasplit on lavapipe) are not checked.v_div_scale_f64clamp dropped (main), f32div_scaleomod dropped, and each omod form refused (main).ctest: all pass exceptagc_driver_pixel_helper_lanes,agc_driver_pixel_ldsandagc_driver_pixel_lds_lane_slots, which fail on RADV onmaintoo (wave32 pixel tests, no division ops).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-05T19:45:37Z.
Thanks. The decoder change and the routing through
writeF64Result/writeOperandlook right to me.agc_driver_division_output_modifiersfails on main's code as expected. But with the change it also fails here on NVIDIA (Linux, GCC), with or without #638:Lane 10 has
v5 = 0x7ff00000, a quiet NaN with a payload. The hardware result keeps that NaN unchanged underdiv:2, but here it comes back as NVIDIA's canonical NaN, so the payload is lost somewhere in the fixup or omod path. Lavapipe keeps NaN payloads, which is probably why CI is green. Could the NaN case select the operand's bits explicitly, the way #567 keeps NaNs on the omod path, instead of relying on the arithmetic to carry the payload? The rest of the suite passes with the change merged.Imported from boykopovar/AnyPS5. Originally posted by khasinski on 2026-10-05T22:04:47Z.
The payload is lost before
v_div_fixup_f32runs, in the|v5|source modifier, not in the fixup or omod path.vDivFixupF32works on integer bits only and already returnsdenominator | 0x400000for a NaN denominator. ButreadOperandappliesabsandnegon F32 operands asFPAbs32/FPNeg32(FAbs/OpFNegate), and on NVIDIAFAbsof0x7ff00000returns the driver's canonical NaN0x7fffffff. The bits that reach the fixup are already canonical. RADV and lavapipe keep the payload.This is a bug on
main, independent of this PR, so I opened #765:readOperandapplies both modifiers to the sign bit for F32 operands too, as it already does for U32 operands (+3/−10). On an RTX 5090 (595.91.07), this PR alone fails with the lane 10 mismatch above, and this PR merged with #765 passes. The fullctestwith #765 on NVIDIA, RADV and lavapipe has no new failures; details are in #765.(AI-assisted: Claude Code; tested on my hardware.)
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T22:56:57Z.
Following up on my NaN payload question: khasinski tracked it down to the
|v5|source modifier, not to this PR's fixup or omod path, and fixed it separately in #765. I checked both on NVIDIA: with this PR aloneagc_driver_division_output_modifiersstill fails at lane 10 (0x7fffffff), and with this PR and #765 merged it passes. So no change is needed on your side; this can go in once #765 has landed.