fix(shader): apply the f32 output modifier on the bits like the hardware #567
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/567"
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-04T21:55:53Z.
What
The VOP3 output modifier (
mul:2,mul:4,div:2) on f32 results was a plainFMulby 2, 4 or 0.5. That differs from the hardware in three places, and the NaN result was left to the driver:v_mul_f32_e64 v, -0, 1.0 mul:2);div:2, a result that drops below the smallest normal becomes a zero with the sign of the result (0x80800000→0x80000000, and0x00ffffff→+0where round to nearest gives0x00800000);FMulon a NaN lets the driver choose the payload (NVIDIA returns0x7fffffff).applyF32ResultModifiersnow picks these cases on the bits of the unmodified result. Other results still go throughFMul, which is exact for these factors, overflow to infinity included. Clamp is still applied after the output modifier.f16 results follow #323:
applyF16ResultModifiersignores omod, as the hardware does while f16 denormals are enabled (the LLVM default), so this PR only changes the f32 path. I added a line to TechnicalDebt for the mode assumption of the f32 rule and for the f16 case with denormals flushed, which isn't modelled.packedFloat16(VOP3P) has no output modifier field, so its call sites don't change.Behaviour measured on HW
The measurements were taken on a gfx1035 GPU through the HSA runtime, with MODE set to IEEE=0 and f32 denormals flushed. That is the mode the recompiler already assumes for f32 (the LLVM graphics default). With IEEE=1, or with f32 output denormals on, the hardware ignores the output modifier.
v_mul/add/fma/min/max/fract/cvt_f32_i32and each of the three modifiers. Every cell matches the rule above when it is applied to the hardware's own unmodified result:0x00800000: +0;div:2with magnitude below0x01000000: signed zero;v_mul_f32 2.0, 0xff61b1e6 div:2overflows to -inf and stays -inf.Tested
agc_driver_f32_output_modifiertest (tests/execution/F32OutputModifier.cpp): 16 forms (mul, add, sub, fma, min, max, floor, cvt_f32_i32 with each modifier, and clamp after the modifier), with 32 rows of expected values from the hardware. A cell is checked only when AnyPS5's result without the modifier is defined on every driver: no subnormal inputs or results, and fma only where the product is exact. For max with two identical NaN sources the NaN bits are chosen by our code, so those cells are checked bit for bit (sNaN included). For add/mul/fma NaN cells the driver chooses the NaN, so they only require a NaN.agc_driver_pixel_helper_lanes,agc_driver_global_load_addtidandagc_driver_vop3_carry_out, which also fail onmainon this RADV (wave32 lane 32 on RADV's 64-wide subgroup).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-04T22:38:22Z.
Thanks, this is the follow-up from #508. The rule reads right to me: the picks are made on the bits of the unmodified result, the
div:2underflow select runs before the general "below 0x00800000 gives +0" select (so a zero input still gives +0), NaN is kept as is, consistent with IEEE=0 as in #508, and everything else goes through an FMul that is exact for these factors. Clamp after the modifier matches the ISA's order, and the TechnicalDebt line states the mode assumption.The one thing to sort out is the order with #323 and #537, which change the same three files:
applyF16ResultModifiers, which applies clamp and ignores omod on f16 results, and drops the result modifiers fromv_cvt_pkrtz_f16_f32. That is the hardware rule in the LLVM default mode (f16 denormals on), which your TechnicalDebt line describes too, so the two PRs agree on the hardware but the code collides: after #323 the f16 call sites no longer reachapplyF32ResultModifiers, so thefloat16Resultparameter has no callers, and the TechnicalDebt sentence "On f16 results it is still a plain multiply" would no longer be true.float16Resultand rewording the f16 sentence to match #323 (omod ignored on f16 results; the flushed-denormal +0 case is the gap)?agc_driver_f32_output_modifierpasses on my NVIDIA machine at this head, and on main's code it fails at lane 0 (v_mul_f32 ... mul:2gives 0x80000000 where 0x00000000 is expected).Output modifiers are on PPSA21564's shader path, so once it's rebased I'll run it through my PPSA21564 check before merging.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T01:34:26Z.
Rebased on current main: the only conflict was the neighbouring TechnicalDebt line (now
sceAjmDecMp3ParseFrame); the omod line is unchanged.agc_driver_f32_output_modifier_testspasses on RADV and lavapipe, full ctest green on RADV apart from the knownagc_driver_pixel_helper_lanes.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T02:47:18Z.
Thanks for the rebase. The TechnicalDebt conflict is resolved the right way, and the commit is otherwise the same as before.
One thing I noticed while merging the open shader PRs together: this now conflicts with #323 (and so with #537, which carries #323's commits) in
TranslationContext.hpp,FloatInstructions.cppandConvertInstructions.cpp, and it isn't only textual. #323 addsapplyF16ResultModifiers, which applies clamp but not omod to f16 results, while this PR adds afloat16Resultflag toapplyF32ResultModifiersand your TechnicalDebt line says omod on f16 results "is still a plain multiply". Whichever lands second has to pick one rule for f16 (and the TechnicalDebt line should match it). Since #323 and #537 are ahead of this one, could you rebase it onto #537 and keep #323's f16 handling?The f32 part is unchanged and still looks right to me. PPSA21564 uses
mul:2,mul:4anddiv:2in about 2,500 of its shaders, so this one goes through my PPSA21564 check before merging.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T03:01:21Z.
Rebased onto #537 (carries #323's commits unchanged) and kept #323's f16 rule:
float16Resultflag; f16 paths use #323'sapplyF16ResultModifiers(clamp, no omod) andv_cvt_pkrtz_f16_f32keeps #323's unmodified inputs.agc_driver_f32_output_modifier,agc_driver_float16_result_modifiersandagc_driver_vop1_float_unarypass on RADV and lavapipe; full ctest green exceptagc_driver_pixel_helper_lanes(fails on main on RADV).Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:03:51Z.
Thanks, this is what I was after. The branch is now #537's head (
f3b74e2, with #323's three commits unchanged) plus only this commit, and the range-diff against the previous version shows just the f16 parts gone: nofloat16Resultflag, the f16 unary and trig paths andv_cvt_pkrtz_f16_f32keep #323's handling (applyF16ResultModifiers, unmodified inputs for pkrtz), and the f32 bit rule is the same as before. The TechnicalDebt line now matches #323's rule.#323, then #537, then this one merges cleanly at every step here, and the full ctest passes on main with the stack merged (
agc_driver_f32_output_modifier,agc_driver_float16_result_modifiersandagc_driver_vop1_float_unaryincluded).As before, PPSA21564 uses
mul:2,div:2andmul:4in about 2,500 of the 5,688 shaders I have dumped, so the stack goes through my PPSA21564 check before merging. Ready to merge from my side after #537 once that's done.Gated on PPSA21564 on top of #537: no visual or FPS change.