feat(shader): accept clamp on v_div_fmas/fixup and omod on their f64 forms #610
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/610"
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-05T03:20:34Z.
What
The decoder refused
clampandomodonv_div_fmas_f32/f64andv_div_fixup_f32/f64("VOP3 source modifiers are not implemented"). llvm-mc accepts both modifiers on all four ops for gfx1013. This PR accepts the ones that the recompiler can do exactly:clampon all four. The f32 forms go through the shared f32 result path (applyF32ResultModifiers→FPSaturate32), like every other f32 op. The f64 forms now go throughFPSaturate64, like the other f64 ops. Before this PR,vDivFmasF64andvDivFixupF64wrote their result without looking at clamp. That code was unreachable because the decoder refused clamp.omodon the f64 forms. The hardware ignores it, so it's dropped, asfloat64Operationalready does for every other f64 op.omodon the f32 forms still throws. On the hardware it follows the f32 output modifier rule from #567, which isn't onmainyet. The test checks that both opcodes still refuse it. Once #567 is in, the follow-up only has to change the decoder.To keep one place for the f64 rule, the clamp/omod handling of
float64Operationmoved intowriteF64Result, and the two division ops call it too.v_div_scale_f32/f64(VOP3b) still refuses both modifiers; #563 edits the same check forv_mad_u64_u32.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, the mode the recompiler assumes. There were 4096 random and special rows: f32 fmas (VCC from the row) and fixup with clamp, mul:2/mul:4 and div:2; f64 fmas and fixup with the same modifiers, both operand orders. Every cell matches these rules, applied to the hardware's own unmodified result of the same op:
FPSaturate64).With f32 denormals enabled, the f32 omod is ignored, so the f32 omod rule depends on the mode. That is one more reason to keep it refused here.
Tested
New
agc_driver_division_result_modifierstest (tests/execution/DivisionResultModifiers.cpp). It has 10 forms: f32 fmas/fixup with clamp, also with-a/|b|sources and swapped operands; f64 fmas/fixup with clamp, mul:2, div:2, clamp mul:4 and a negated source. There are 32 rows of expected values from the hardware. They were picked so that every combination of form, class of the result before and after the modifier, and VCC that appears in 6000 HW rows is covered (147 classes). This includes NaN, −0, negative, below 1, above 1 and inf before the clamp. A cell is checked only when AnyPS5's result is defined on every driver:Fmagives the same value.NaN results are chosen on the bits by the existing division code and clamped to +0, so no cell depends on the driver's NaN payload. The test also checks that f32 omod is still refused on both opcodes.
Without the change, the test fails at the decoder refusal. Mutations that each fail the test:
writeF64Result("lane 3 v_div_fmas_f64 ... clamp lo");v_div_fmas_f32("VOP3 opcode 0x0000016f with omod was not refused").One mutation passes: replacing
FPSaturate32with a plain GLSLFClamppasses on RADV and lavapipe. Both drivers already give +0 for NaN and −0 there, and Dean found the same on NVIDIA in #500. The spec leaves those cases undefined, which #500 fixes for every f32 clamp.Passes on RADV (Mesa 26.2), local lavapipe and CI's lavapipe (Mesa 25.2.8, cold run 1 s). Full Release ctest on Linux: everything passes except
agc_driver_pixel_helper_lanesandagc_driver_pixel_lds, which also fail onmainon this RADV.Known gap, already on
mainand not changed here:FPSaturate64compares withOpFOrdGreaterThan, so a driver that flushes f64 denormals (lavapipe) clamps a positive subnormal result to +0, where the hardware keeps it. The test has no subnormal f64 rows.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-05T05:03:54Z.
Thanks, this checks out. I disassembled the test kernel with
llvm-mc -mcpu=gfx1013and it matches the names table:v_div_fmas_f32andv_div_fixup_f32withclamp(also with-v4,|v5|and swapped operands), and the f64 forms withclamp,mul:2,div:2,clamp mul:4and a negated source. The two refusal words decode tov_div_fmas_f32 ... mul:2andv_div_fixup_f32 ... mul:2.The decoder change is narrow: the f32 forms only get clamp (through
supportsNativeVop3Clamp), so their omod is still refused, while the f64 forms get both. Their omod is then dropped inwriteF64Result, as for the other f64 ops. Both f32 forms write an F32 value throughwriteOperand, so clamp goes throughapplyF32ResultModifiersandFPSaturate32. Moving the f64 handling intowriteF64Resultdoesn't changefloat64Operation. The newagc_driver_division_result_modifiersfails on main at the decoder refusal and passes here, and the full ctest passes with it merged (with #323, #537 and #567 too).PPSA21564 has no
v_div_*and no f64 op in the 5,688 shaders I have dumped, so this doesn't need my PPSA21564 check.One note for the merge order: this conflicts with your #507 and #508 on the
supportsNativeVop3Clampreturn line, since each PR adds a term there (and #507 renamesusesSignedSaturateClamptousesIntegerSaturateClamp). Keeping all the terms fixes it, whichever lands second. Ready to merge from my side.