fix(shader): apply clamp on v_div_scale_f64 and accept omod on the f32 division steps and v_div_scale #663

Merged
adriadam10 merged 1 commit from upstream-pr/663 into main 2026-10-06 02:13:36 +00:00
adriadam10 commented 2026-10-05 12:32:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T12:32:18Z.


What

Finishes the result modifiers of the division helper ops:

  • Bug: v_div_scale_f64 with clamp was decoded since #563 but the clamp was dropped (the result was written without FPSaturate64). It now goes through writeF64Result, like v_div_fmas_f64/v_div_fixup_f64 since #610.
  • omod (mul:2, mul:4, div:2) is accepted on v_div_fmas_f32, v_div_fixup_f32 and v_div_scale_f32 (applied with the #567 rule through writeOperand), and on v_div_scale_f64 (ignored, as on the hardware and as on the other f64 ops).
  • The refusal check for f32 omod in 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 = FPSaturate64 on the result, omod ignored. 0 mismatches.
  • v_div_fmas_f32/v_div_fixup_f32 with mul:2/mul:4/div:2: the #567 rule, 0 mismatches over 4096 rows (same data as #610).
  • With DENORM=3 the hardware ignores f32 omod on these ops, as on v_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).

  • New DivisionOutputModifiers.cpp execution 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 (the Fma split on lavapipe) are not checked.
  • The test fails without the fix: v_div_scale_f64 clamp dropped (main), f32 div_scale omod dropped, and each omod form refused (main).
  • Release build, full ctest: all pass except agc_driver_pixel_helper_lanes, agc_driver_pixel_lds and agc_driver_pixel_lds_lane_slots, which fail on RADV on main too (wave32 pixel tests, no division ops).

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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4744944580 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/663). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T12:32:18Z. --- ### What Finishes the result modifiers of the division helper ops: - **Bug:** `v_div_scale_f64` with `clamp` was decoded since #563 but the clamp was dropped (the result was written without `FPSaturate64`). It now goes through `writeF64Result`, like `v_div_fmas_f64`/`v_div_fixup_f64` since #610. - `omod` (`mul:2`, `mul:4`, `div:2`) is accepted on `v_div_fmas_f32`, `v_div_fixup_f32` and `v_div_scale_f32` (applied with the #567 rule through `writeOperand`), and on `v_div_scale_f64` (ignored, as on the hardware and as on the other f64 ops). - The refusal check for f32 omod in `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` = `FPSaturate64` on the result, `omod` ignored. 0 mismatches. - `v_div_fmas_f32`/`v_div_fixup_f32` with `mul:2`/`mul:4`/`div:2`: the #567 rule, 0 mismatches over 4096 rows (same data as #610). - With `DENORM=3` the hardware ignores f32 `omod` on these ops, as on `v_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). - New `DivisionOutputModifiers.cpp` execution 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 (the `Fma` split on lavapipe) are not checked. - The test fails without the fix: `v_div_scale_f64` clamp dropped (main), f32 `div_scale` omod dropped, and each omod form refused (main). - Release build, full `ctest`: all pass except `agc_driver_pixel_helper_lanes`, `agc_driver_pixel_lds` and `agc_driver_pixel_lds_lane_slots`, which fail on RADV on `main` too (wave32 pixel tests, no division ops). ### 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 - [x] AI-assisted: yes
oneandonlydean commented 2026-10-05 19:45:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T19:45:37Z.


Thanks. The decoder change and the routing through writeF64Result / writeOperand look right to me. agc_driver_division_output_modifiers fails on main's code as expected. But with the change it also fails here on NVIDIA (Linux, GCC), with or without #638:

division output modifiers: lane 10 v_div_fixup_f32 v13, -v4, |v5|, v6 div:2 is 0x7fffffff, expected 0x7ff00000

Lane 10 has v5 = 0x7ff00000, a quiet NaN with a payload. The hardware result keeps that NaN unchanged under div: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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6001771306 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/663#issuecomment-6001771306). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T19:45:37Z. --- Thanks. The decoder change and the routing through `writeF64Result` / `writeOperand` look right to me. `agc_driver_division_output_modifiers` fails on main's code as expected. But with the change it also fails here on NVIDIA (Linux, GCC), with or without #638: ``` division output modifiers: lane 10 v_div_fixup_f32 v13, -v4, |v5|, v6 div:2 is 0x7fffffff, expected 0x7ff00000 ``` Lane 10 has `v5 = 0x7ff00000`, a quiet NaN with a payload. The hardware result keeps that NaN unchanged under `div: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.
khasinski commented 2026-10-05 22:04:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by khasinski on 2026-10-05T22:04:47Z.


The payload is lost before v_div_fixup_f32 runs, in the |v5| source modifier, not in the fixup or omod path.

vDivFixupF32 works on integer bits only and already returns denominator | 0x400000 for a NaN denominator. But readOperand applies abs and neg on F32 operands as FPAbs32/FPNeg32 (FAbs / OpFNegate), and on NVIDIA FAbs of 0x7ff00000 returns the driver's canonical NaN 0x7fffffff. 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: readOperand applies 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 full ctest with #765 on NVIDIA, RADV and lavapipe has no new failures; details are in #765.

(AI-assisted: Claude Code; tested on my hardware.)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6004019717 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/663#issuecomment-6004019717). Originally posted by [khasinski](https://github.com/khasinski) on 2026-10-05T22:04:47Z. --- The payload is lost before `v_div_fixup_f32` runs, in the `|v5|` source modifier, not in the fixup or omod path. `vDivFixupF32` works on integer bits only and already returns `denominator | 0x400000` for a NaN denominator. But `readOperand` applies `abs` and `neg` on F32 operands as `FPAbs32`/`FPNeg32` (`FAbs` / `OpFNegate`), and on NVIDIA `FAbs` of `0x7ff00000` returns the driver's canonical NaN `0x7fffffff`. 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: `readOperand` applies 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 full `ctest` with #765 on NVIDIA, RADV and lavapipe has no new failures; details are in #765. (AI-assisted: Claude Code; tested on my hardware.)
oneandonlydean commented 2026-10-05 22:56:57 +00:00 (Migrated from github.com)

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 alone agc_driver_division_output_modifiers still 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6004895537 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/663#issuecomment-6004895537). Originally posted by [oneandonlydean](https://github.com/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 alone `agc_driver_division_output_modifiers` still 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.
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!663
No description provided.