fix(shader): round v_fma_mixlo_f16 and v_fma_mixhi_f16 in every f16 rounding mode #3512

Merged
LeandroLP23 merged 3 commits from upstream-pr/3512 into main 2026-10-11 21:36:15 +00:00
LeandroLP23 commented 2026-10-11 12:05:32 +00:00 (Migrated from github.com)

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


Carrying @AlxcBTW's fix for #2631 (AlxcBTW/AnyPS5#19, afba6fe4 and a83dadf9; they can't open PRs yet). The change is theirs, cherry-picked onto current main without conflicts, authorship kept.

What

v_fma_mixlo_f16 and v_fma_mixhi_f16 threw "not implemented" in any FLOAT_MODE whose f16 rounding isn't to nearest even. They now round the exact product-sum once in the mode's f16 direction: the sum is already computed in f64 with round to odd, then scaled by the f16 step, truncated, floored or ceiled, and scaled back; an exact zero sum gives -0 toward -infinity unless both product and addend are +0. With f16 denormals flushed they still throw, and packed f16 is unchanged. Details in AlxcBTW's comment on #2631.

The PS5 OpenGL Showcase (PPSA99005) and PokeMMO Prospero (PPSA98001) stop on it at their first draw (FLOAT_MODE 0xcc, f16 rounding toward zero).

Tested

  • @SleglJan compared it with RDNA 2 hardware through tools/hw-oracle: 0 of 2,233 rows differ in any of the four f16 rounding modes, for all four instruction forms, on RADV and on an RTX 3080 (comment).
  • AlxcBTW: RTX 5070 Laptop and Radeon 880M, Windows; PokeMMO draws its start screen with it.
  • My run on a Radeon 860M (RDNA 3.5), Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, caches emptied: agc_driver_mix_precision and vector_fused_multiply_add pass 3/3 and fail with main's SpirvAluEmitterFloat64.cpp and FloatInstructions.cpp (the "not implemented" throw); ctest -R agc_ 372/373 and ctest -E agc_ 459/460, the two failures (agc_driver_f32_compare_constant, windows_exceptions) failing the same way on plain main. The OpenGL Showcase gets past the shader that stopped it, compiles its pipelines and then ends at its own [ps5-agc] submission retirement failed.

Fork CI: https://github.com/LeandroLP23/AnyPS5/actions/runs/38136074002 (Windows fails only windows_exceptions and Linux only agc_driver_image_address_dimension, agc_driver_image_plane_address_on_line_implicit_lod, guest_kernel_stack_protect and the intermittent agc_driver_depth_fast_clear_submit segfault, as on main)

Fixes #2631

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 (Claude Code, for carrying and the RDNA 3.5 run; see #2631 for the author's disclosure)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818918663 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3512). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-11T12:05:32Z. --- Carrying @AlxcBTW's fix for #2631 (AlxcBTW/AnyPS5#19, `afba6fe4` and `a83dadf9`; they can't open PRs yet). The change is theirs, cherry-picked onto current `main` without conflicts, authorship kept. ### What `v_fma_mixlo_f16` and `v_fma_mixhi_f16` threw "not implemented" in any FLOAT_MODE whose f16 rounding isn't to nearest even. They now round the exact product-sum once in the mode's f16 direction: the sum is already computed in f64 with round to odd, then scaled by the f16 step, truncated, floored or ceiled, and scaled back; an exact zero sum gives -0 toward -infinity unless both product and addend are +0. With f16 denormals flushed they still throw, and packed f16 is unchanged. Details in [AlxcBTW's comment on #2631](https://github.com/boykopovar/AnyPS5/issues/2631#issuecomment-6096804041). The PS5 OpenGL Showcase (PPSA99005) and PokeMMO Prospero (PPSA98001) stop on it at their first draw (FLOAT_MODE 0xcc, f16 rounding toward zero). ### Tested - @SleglJan compared it with RDNA 2 hardware through `tools/hw-oracle`: 0 of 2,233 rows differ in any of the four f16 rounding modes, for all four instruction forms, on RADV and on an RTX 3080 ([comment](https://github.com/boykopovar/AnyPS5/issues/2631#issuecomment-6098596549)). - AlxcBTW: RTX 5070 Laptop and Radeon 880M, Windows; PokeMMO draws its start screen with it. - My run on a Radeon 860M (RDNA 3.5), Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, caches emptied: `agc_driver_mix_precision` and `vector_fused_multiply_add` pass 3/3 and fail with `main`'s `SpirvAluEmitterFloat64.cpp` and `FloatInstructions.cpp` (the "not implemented" throw); `ctest -R agc_` 372/373 and `ctest -E agc_` 459/460, the two failures (`agc_driver_f32_compare_constant`, `windows_exceptions`) failing the same way on plain `main`. The OpenGL Showcase gets past the shader that stopped it, compiles its pipelines and then ends at its own `[ps5-agc] submission retirement failed`. Fork CI: https://github.com/LeandroLP23/AnyPS5/actions/runs/38136074002 (Windows fails only `windows_exceptions` and Linux only `agc_driver_image_address_dimension`, `agc_driver_image_plane_address_on_line_implicit_lod`, `guest_kernel_stack_protect` and the intermittent `agc_driver_depth_fast_clear_submit` segfault, as on `main`) Fixes #2631 ### 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 (Claude Code, for carrying and the RDNA 3.5 run; see #2631 for the author's disclosure)
AlxcBTW commented 2026-10-11 12:06:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T12:06:11Z.


@LeandroLP23 thanks for carrying it, and for the RDNA 3.5 run. Both commits match AlxcBTW/AnyPS5#19. If review questions about the rounding come up, I can answer them here.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108841299 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3512#issuecomment-6108841299). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-11T12:06:11Z. --- @LeandroLP23 thanks for carrying it, and for the RDNA 3.5 run. Both commits match AlxcBTW/AnyPS5#19. If review questions about the rounding come up, I can answer them here. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-11 12:13:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T12:13:19Z.

Review: COMMENTED


One TechnicalDebt consistency point: the new entry says the f16 round-toward-+∞ and round-toward-zero cases are “not measured,” while the linked #2631 sweep reports zero differences in all four f16 rounding modes across 2,233 rows. Could you clarify whether “not measured” means not measured on PS5 hardware, or adjust that sentence to match the RDNA2 measurement? That would keep the limitation precise.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5483252241 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3512#pullrequestreview-5483252241). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T12:13:19Z. **Review:** COMMENTED --- One TechnicalDebt consistency point: the new entry says the f16 round-toward-`+∞` and round-toward-zero cases are “not measured,” while the linked #2631 sweep reports zero differences in all four f16 rounding modes across 2,233 rows. Could you clarify whether “not measured” means not measured on PS5 hardware, or adjust that sentence to match the RDNA2 measurement? That would keep the limitation precise.
AlxcBTW commented 2026-10-11 12:15:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T12:15:40Z.


@MarcZX100 you're right, that sentence is stale. I wrote it before SleglJan's sweep on #2631, and it never got updated. The sweep was on RDNA2 (gfx1036, through tools/hw-oracle), not on the PS5's gfx1013.

@LeandroLP23 a replacement for the end of the entry, if you want to take it:

With f16 denormals kept, every f16 rounding mode is translated: the exact product-sum is rounded once in the mode's direction. All four modes match RDNA2 (gfx1036) on the 2,233 rows of the #2631 sweep, including FLOAT_MODE 0xcc (toward zero, used by ps5-opengl) and the exact cancellations toward -infinity; the PS5's gfx1013 is not measured.

The sentences after it (beyond 65504, flushed denormals, packed f16, FP16_OVFL) stay as they are.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108917471 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3512#issuecomment-6108917471). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-11T12:15:40Z. --- @MarcZX100 you're right, that sentence is stale. I wrote it before SleglJan's sweep on #2631, and it never got updated. The sweep was on RDNA2 (gfx1036, through `tools/hw-oracle`), not on the PS5's gfx1013. @LeandroLP23 a replacement for the end of the entry, if you want to take it: > With f16 denormals kept, every f16 rounding mode is translated: the exact product-sum is rounded once in the mode's direction. All four modes match RDNA2 (gfx1036) on the 2,233 rows of the #2631 sweep, including `FLOAT_MODE` 0xcc (toward zero, used by ps5-opengl) and the exact cancellations toward -infinity; the PS5's gfx1013 is not measured. The sentences after it (beyond 65504, flushed denormals, packed f16, `FP16_OVFL`) stay as they are. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-11 12:35:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T12:35:42Z.


Thanks, that clarifies the distinction I was asking about: the four rounding modes were measured in the RDNA2 sweep, while gfx1013/PS5 behavior remains unmeasured. The proposed wording captures that accurately.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109081330 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3512#issuecomment-6109081330). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T12:35:42Z. --- Thanks, that clarifies the distinction I was asking about: the four rounding modes were measured in the RDNA2 sweep, while gfx1013/PS5 behavior remains unmeasured. The proposed wording captures that accurately.
LeandroLP23 commented 2026-10-11 12:47:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-11T12:47:29Z.


Thanks @MarcZX100 and @AlxcBTW. Took AlxcBTW's wording as is in 3f4db6eab: the four modes are recorded as matching RDNA2 (gfx1036) on the #2631 sweep, and gfx1013 as not measured. The sentences after it are unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109178441 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3512#issuecomment-6109178441). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-11T12:47:29Z. --- Thanks @MarcZX100 and @AlxcBTW. Took AlxcBTW's wording as is in 3f4db6eab: the four modes are recorded as matching RDNA2 (gfx1036) on the #2631 sweep, and gfx1013 as not measured. The sentences after it are unchanged.
orishamir commented 2026-10-11 13:16:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-11T13:16:22Z.


A third title stops here on main, on desktop NVIDIA: ProsperoStore (PPSA99000, catalog 1.000.050, sha256 checked, eboot.bin and sce_module/libc.prx unwrapped), relinked with --windows on main a11c8f7f; Windows 11, RTX 4080 (driver 616.56), WinLibs GCC 15.2.0 r7, Release. Only this PR's three non-test files (23dad485) differ between the runs.

  • main: the store UI starts ([HUI] gl 4.6 ... Mesa 26.2.0, its GL programs build, [STORE] interactive width=3840 height=2160), then after 19 s it aborts with
    ShaderRecompiler::Recompile: v_fma_mixlo/mixhi_f16 at pc 348 in FLOAT_MODE 204 (f16 denormals not kept or rounding not to nearest even) is not implemented
  • with this PR: past that shader; after 23 s it stops at [videoout] presentation failed: AGC graphics: last provoking vertex with explicit per-vertex flat interpolation is unsupported (Pipeline.cpp:104), the stop ProsperoTV (#3521) and Stremio Plus (#3493) reach once their imports are in.

AI-assisted: yes (Claude Code Opus 5.5 xhigh)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109421521 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3512#issuecomment-6109421521). Originally posted by [orishamir](https://github.com/orishamir) on 2026-10-11T13:16:22Z. --- A third title stops here on `main`, on desktop NVIDIA: ProsperoStore (PPSA99000, catalog 1.000.050, sha256 checked, `eboot.bin` and `sce_module/libc.prx` unwrapped), relinked with `--windows` on `main` a11c8f7f; Windows 11, RTX 4080 (driver 616.56), WinLibs GCC 15.2.0 r7, Release. Only this PR's three non-test files (23dad485) differ between the runs. - `main`: the store UI starts (`[HUI] gl 4.6 ... Mesa 26.2.0`, its GL programs build, `[STORE] interactive width=3840 height=2160`), then after 19 s it aborts with `ShaderRecompiler::Recompile: v_fma_mixlo/mixhi_f16 at pc 348 in FLOAT_MODE 204 (f16 denormals not kept or rounding not to nearest even) is not implemented` - with this PR: past that shader; after 23 s it stops at `[videoout] presentation failed: AGC graphics: last provoking vertex with explicit per-vertex flat interpolation is unsupported` (`Pipeline.cpp:104`), the stop ProsperoTV (#3521) and Stremio Plus (#3493) reach once their imports are in. AI-assisted: yes (Claude Code Opus 5.5 xhigh)
adriadam10 commented 2026-10-11 21:36:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:36:12Z.


Checked on RDNA2 (gfx1035, IEEE=0) with the HW oracle: 1792 rows (incl. the 16 directed test rows) × the 7 mix forms of RoundingCode × FLOAT_MODE 0xc0/0xc4/0xc8/0xcc/0xcf/0xf9, bit for bit against the PR's recompiled shader: 0 differences on RADV and on CI's lavapipe. The tests fail with main's lowering, and dropping the -0 rule, the overflow limit or swapping toward-zero for toward -infinity each fails agc_driver_mix_precision. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114041539 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3512#issuecomment-6114041539). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:36:12Z. --- Checked on RDNA2 (gfx1035, IEEE=0) with the HW oracle: 1792 rows (incl. the 16 directed test rows) × the 7 mix forms of `RoundingCode` × FLOAT_MODE 0xc0/0xc4/0xc8/0xcc/0xcf/0xf9, bit for bit against the PR's recompiled shader: 0 differences on RADV and on CI's lavapipe. The tests fail with `main`'s lowering, and dropping the -0 rule, the overflow limit or swapping toward-zero for toward -infinity each fails `agc_driver_mix_precision`. Merging.
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!3512
No description provided.