feat(shader): accept clamp on v_div_fmas/fixup and omod on their f64 forms #610

Merged
adriadam10 merged 1 commit from upstream-pr/610 into main 2026-10-05 05:05:38 +00:00
adriadam10 commented 2026-10-05 03:20:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T03:20:34Z.


What

The decoder refused clamp and omod on v_div_fmas_f32/f64 and v_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:

  • clamp on all four. The f32 forms go through the shared f32 result path (applyF32ResultModifiers → FPSaturate32), like every other f32 op. The f64 forms now go through FPSaturate64, like the other f64 ops. Before this PR, vDivFmasF64 and vDivFixupF64 wrote their result without looking at clamp. That code was unreachable because the decoder refused clamp.
  • omod on the f64 forms. The hardware ignores it, so it's dropped, as float64Operation already does for every other f64 op.
  • omod on the f32 forms still throws. On the hardware it follows the f32 output modifier rule from #567, which isn't on main yet. 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 float64Operation moved into writeF64Result, and the two division ops call it too. v_div_scale_f32/f64 (VOP3b) still refuses both modifiers; #563 edits the same check for v_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:

  • f32 clamp: results from the smallest positive value up to +inf are capped at 1.0. Everything else becomes +0: NaN, −0 and negative results. This is the rule from #500.
  • f32 omod: the #567 rule.
  • f64 clamp: the same rule on the 64-bit pattern (FPSaturate64).
  • f64 omod: ignored, as the other f64 ops do (#446).

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_modifiers test (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:

    • no subnormal inputs or results;
    • f32 results equal with denormals on and off;
    • for f32 fmas, only rows where the product is exact in f32, so a split Fma gives 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:

    • writing the f64 fmas result without writeF64Result ("lane 3 v_div_fmas_f64 ... clamp lo");
    • the same for f64 fixup;
    • accepting omod on v_div_fmas_f32 ("VOP3 opcode 0x0000016f with omod was not refused").

    One mutation passes: replacing FPSaturate32 with a plain GLSL FClamp passes 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_lanes and agc_driver_pixel_lds, which also fail on main on this RADV.

  • Known gap, already on main and not changed here: FPSaturate64 compares with OpFOrdGreaterThan, 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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (f32 omod follow-up after #567; NaN/−0 clamp exactness on every driver comes with #500)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4739760708 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/610). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T03:20:34Z. --- ### What The decoder refused `clamp` and `omod` on `v_div_fmas_f32/f64` and `v_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: - `clamp` on all four. The f32 forms go through the shared f32 result path (`applyF32ResultModifiers` → `FPSaturate32`), like every other f32 op. The f64 forms now go through `FPSaturate64`, like the other f64 ops. Before this PR, `vDivFmasF64` and `vDivFixupF64` wrote their result without looking at clamp. That code was unreachable because the decoder refused clamp. - `omod` on the f64 forms. The hardware ignores it, so it's dropped, as `float64Operation` already does for every other f64 op. - `omod` on the f32 forms still throws. On the hardware it follows the f32 output modifier rule from #567, which isn't on `main` yet. 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 `float64Operation` moved into `writeF64Result`, and the two division ops call it too. `v_div_scale_f32/f64` (VOP3b) still refuses both modifiers; #563 edits the same check for `v_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: - f32 clamp: results from the smallest positive value up to +inf are capped at 1.0. Everything else becomes +0: NaN, −0 and negative results. This is the rule from #500. - f32 omod: the #567 rule. - f64 clamp: the same rule on the 64-bit pattern (`FPSaturate64`). - f64 omod: ignored, as the other f64 ops do (#446). 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_modifiers` test (`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: - no subnormal inputs or results; - f32 results equal with denormals on and off; - for f32 fmas, only rows where the product is exact in f32, so a split `Fma` gives 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: - writing the f64 fmas result without `writeF64Result` ("lane 3 v_div_fmas_f64 ... clamp lo"); - the same for f64 fixup; - accepting omod on `v_div_fmas_f32` ("VOP3 opcode 0x0000016f with omod was not refused"). One mutation passes: replacing `FPSaturate32` with a plain GLSL `FClamp` passes 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_lanes` and `agc_driver_pixel_lds`, which also fail on `main` on this RADV. - Known gap, already on `main` and not changed here: `FPSaturate64` compares with `OpFOrdGreaterThan`, 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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none (f32 omod follow-up after #567; NaN/−0 clamp exactness on every driver comes with #500) - [x] AI-assisted: yes
oneandonlydean commented 2026-10-05 05:03:54 +00:00 (Migrated from github.com)

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=gfx1013 and it matches the names table: v_div_fmas_f32 and v_div_fixup_f32 with clamp (also with -v4, |v5| and swapped operands), and the f64 forms with clamp, mul:2, div:2, clamp mul:4 and a negated source. The two refusal words decode to v_div_fmas_f32 ... mul:2 and v_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 in writeF64Result, as for the other f64 ops. Both f32 forms write an F32 value through writeOperand, so clamp goes through applyF32ResultModifiers and FPSaturate32. Moving the f64 handling into writeF64Result doesn't change float64Operation. The new agc_driver_division_result_modifiers fails 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 supportsNativeVop3Clamp return line, since each PR adds a term there (and #507 renames usesSignedSaturateClamp to usesIntegerSaturateClamp). Keeping all the terms fixes it, whichever lands second. Ready to merge from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5988441094 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/610#issuecomment-5988441094). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T05:03:54Z. --- Thanks, this checks out. I disassembled the test kernel with `llvm-mc -mcpu=gfx1013` and it matches the names table: `v_div_fmas_f32` and `v_div_fixup_f32` with `clamp` (also with `-v4`, `|v5|` and swapped operands), and the f64 forms with `clamp`, `mul:2`, `div:2`, `clamp mul:4` and a negated source. The two refusal words decode to `v_div_fmas_f32 ... mul:2` and `v_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 in `writeF64Result`, as for the other f64 ops. Both f32 forms write an F32 value through `writeOperand`, so clamp goes through `applyF32ResultModifiers` and `FPSaturate32`. Moving the f64 handling into `writeF64Result` doesn't change `float64Operation`. The new `agc_driver_division_result_modifiers` fails 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 `supportsNativeVop3Clamp` return line, since each PR adds a term there (and #507 renames `usesSignedSaturateClamp` to `usesIntegerSaturateClamp`). Keeping all the terms fixes it, whichever lands second. Ready to merge from my side.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!610
No description provided.