fix(shader): apply the output modifier only in the float modes where the hardware does #1851

Merged
adriadam10 merged 1 commit from upstream-pr/1851 into main 2026-10-08 22:18:27 +00:00
adriadam10 commented 2026-10-08 22:02:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T22:02:13Z.


What

Part of #981 (FLOAT_MODE family). The output modifier (mul:2, mul:4, div:2) was always applied to f32 results and always ignored on f16/f64 results, whatever the shader's float mode. It now follows GuestContext::floatMode (#1816).

Measured on RDNA2 (gfx1035) with the HW oracle, for every combination of IEEE on/off and each of the four denormal values (FLOAT_MODE bits 5:4 for f32, 7:6 for f16/f64):

  • The hardware applies omod only with IEEE=0 and output denormals of the result's precision flushed (bit 1 of the denormal field clear, i.e. values 0 and 1). With IEEE=1, or with output denormals kept (2, 3), the result is the same as without the modifier: 1444/1444 rows for v_mul_f32 mul:2/mul:4/div:2 in each of those modes. The same rule holds for v_mul_f16 and v_mul_f64.
  • This matches LLVM's SIFoldOperands: "omod is ignored by hardware if IEEE bit is enabled. omod also does not correctly handle denormals".
  • When it is applied, the existing bit-level f32 code on main already matches the hardware (0 mismatches over 1444 rows × 3 modifiers in IEEE=0 with f32 denormals flushed).

Changes:

  • f32: applyF32ResultModifiers applies omod only in those modes. A shader with no known float mode keeps the current behaviour (IEEE=0, f32 denormals flushed, the mode titles use: 0xc0 in every Astro's Playroom shader but ten).
  • f16/f64: omod stays ignored, which is right with f16/f64 denormals kept (0xc0) or IEEE=1. In the modes where the hardware applies it, translation now throws instead of silently ignoring it.
  • The IEEE=1 min/max/med3 path from #1826 no longer throws on omod, because the hardware ignores it there.
  • TechnicalDebt: the output modifier line now states the measured rule; the float mode line lists the output modifier as a reader of IEEE_MODE/FLOAT_MODE.

Tested

Linux (CachyOS, GCC), RADV (gfx1035) and CI's lavapipe (Mesa 25.2.8).

  • agc_driver_f32_output_modifier: the existing table (unchanged; it matches the hardware at IEEE=0 with f32 denormals flushed, 0 mismatches) now runs with no mode and with IEEE=0/0xc0. Two new tables captured on hardware cover IEEE=0 with f32 denormals kept (ExpectedKept) and IEEE=1 (ExpectedIeee, run with 0xc0 and 0xf0; they are equal on hardware for these rows). No row of the new tables has a denormal result, so they don't depend on the driver's denormal mode.
  • agc_driver_float16_modifiers: the existing table matches the hardware at IEEE=1 and at IEEE=0/0xc0 (checked with the oracle). It now also runs with IEEE=1, and checks that a mode with f16 output denormals flushed is refused.
  • Negative checks, each fails: omod applied in every mode, IEEE ignored, the denormal bit ignored, the f16/f64 refusal removed.
  • Full Release ctest: 491/491 (on main after #697).

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 (#1816 and #1826 are merged). Touches the same files as #1850 (f32 denormal flush) without conflicting
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4793312105 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1851). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T22:02:13Z. --- ### What Part of #981 (FLOAT_MODE family). The output modifier (`mul:2`, `mul:4`, `div:2`) was always applied to f32 results and always ignored on f16/f64 results, whatever the shader's float mode. It now follows `GuestContext::floatMode` (#1816). Measured on RDNA2 (gfx1035) with the HW oracle, for every combination of IEEE on/off and each of the four denormal values (`FLOAT_MODE` bits 5:4 for f32, 7:6 for f16/f64): - The hardware applies omod **only with IEEE=0 and output denormals of the result's precision flushed** (bit 1 of the denormal field clear, i.e. values 0 and 1). With IEEE=1, or with output denormals kept (2, 3), the result is the same as without the modifier: 1444/1444 rows for `v_mul_f32 mul:2/mul:4/div:2` in each of those modes. The same rule holds for `v_mul_f16` and `v_mul_f64`. - This matches LLVM's `SIFoldOperands`: "omod is ignored by hardware if IEEE bit is enabled. omod also does not correctly handle denormals". - When it is applied, the existing bit-level f32 code on `main` already matches the hardware (0 mismatches over 1444 rows × 3 modifiers in IEEE=0 with f32 denormals flushed). Changes: - f32: `applyF32ResultModifiers` applies omod only in those modes. A shader with no known float mode keeps the current behaviour (IEEE=0, f32 denormals flushed, the mode titles use: 0xc0 in every Astro's Playroom shader but ten). - f16/f64: omod stays ignored, which is right with f16/f64 denormals kept (0xc0) or IEEE=1. In the modes where the hardware applies it, translation now throws instead of silently ignoring it. - The IEEE=1 min/max/med3 path from #1826 no longer throws on omod, because the hardware ignores it there. - TechnicalDebt: the output modifier line now states the measured rule; the float mode line lists the output modifier as a reader of `IEEE_MODE`/`FLOAT_MODE`. ### Tested Linux (CachyOS, GCC), RADV (gfx1035) and CI's lavapipe (Mesa 25.2.8). - `agc_driver_f32_output_modifier`: the existing table (unchanged; it matches the hardware at IEEE=0 with f32 denormals flushed, 0 mismatches) now runs with no mode and with IEEE=0/0xc0. Two new tables captured on hardware cover IEEE=0 with f32 denormals kept (`ExpectedKept`) and IEEE=1 (`ExpectedIeee`, run with 0xc0 and 0xf0; they are equal on hardware for these rows). No row of the new tables has a denormal result, so they don't depend on the driver's denormal mode. - `agc_driver_float16_modifiers`: the existing table matches the hardware at IEEE=1 and at IEEE=0/0xc0 (checked with the oracle). It now also runs with IEEE=1, and checks that a mode with f16 output denormals flushed is refused. - Negative checks, each fails: omod applied in every mode, IEEE ignored, the denormal bit ignored, the f16/f64 refusal removed. - Full Release ctest: 491/491 (on `main` after #697). ### 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 (#1816 and #1826 are merged). Touches the same files as #1850 (f32 denormal flush) without conflicting - [x] AI-assisted: yes
SleglJan commented 2026-10-08 22:07:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T22:07:59Z.


One result type falls between the two rules here: the f32-typed results of the f64 instructions. float64Operation now rejects the modifier by the f16/f64 field and then still clears it (destination.omod = 0u), so v_cvt_f32_f64 mul:2 keeps its result unmodified in the titles' mode, and would throw with f16/f64 denormals flushed. Measured on RDNA2 (gfx1036, Ryzen 7950X3D iGPU) with the hardware oracle, the hardware applies it by the f32 field: v_cvt_f32_f64 v10, v[4:5] mul:2 of 1.0 gives 0x40000000 with IEEE 0 and f32 denormals flushed (the f16/f64 field kept or flushed), and 0x3f800000 with IEEE 1 or with f32 denormals kept; 2.5 gives 0x40a00000 and 0x40200000 the same way. F64Rounding's column 12 is that instruction over its 32 rows: the pinned 0x3f800000-style values are the IEEE 1 results, and the hardware differs from the table in 28 of the 32 rows in the titles' mode (the audit on #981, pinned-vs-hardware.txt). So the f32 results of float64Operation want applyF32ResultModifiers rather than the f16/f64 rejection, and F64Rounding's column 12 the titles'-mode values. Rows and results: https://gist.github.com/SleglJan/30456e5687240f0b639a78e5477f2f91 (verify-bodies.s, verify-rows.txt, audit.json).

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6069985704 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1851#issuecomment-6069985704). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-10-08T22:07:59Z. --- One result type falls between the two rules here: the f32-typed results of the f64 instructions. `float64Operation` now rejects the modifier by the f16/f64 field and then still clears it (`destination.omod = 0u`), so `v_cvt_f32_f64 mul:2` keeps its result unmodified in the titles' mode, and would throw with f16/f64 denormals flushed. Measured on RDNA2 (gfx1036, Ryzen 7950X3D iGPU) with the hardware oracle, the hardware applies it by the f32 field: `v_cvt_f32_f64 v10, v[4:5] mul:2` of 1.0 gives `0x40000000` with IEEE 0 and f32 denormals flushed (the f16/f64 field kept or flushed), and `0x3f800000` with IEEE 1 or with f32 denormals kept; 2.5 gives `0x40a00000` and `0x40200000` the same way. F64Rounding's column 12 is that instruction over its 32 rows: the pinned `0x3f800000`-style values are the IEEE 1 results, and the hardware differs from the table in 28 of the 32 rows in the titles' mode (the audit on #981, `pinned-vs-hardware.txt`). So the f32 results of `float64Operation` want `applyF32ResultModifiers` rather than the f16/f64 rejection, and F64Rounding's column 12 the titles'-mode values. Rows and results: https://gist.github.com/SleglJan/30456e5687240f0b639a78e5477f2f91 (`verify-bodies.s`, `verify-rows.txt`, `audit.json`). AI-assisted: yes (Claude Code).
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!1851
No description provided.