fix(agc): compare NaN results bit for bit in the f32 flush probe #17588

Merged
Gonic0 merged 1 commit from upstream-pr/17588 into main 2026-11-15 20:00:59 +00:00
Gonic0 commented 2026-11-09 00:07:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gonic0 on 2026-11-09T00:07:48Z.


What

ProbeFloat32FlushToZero counted any two NaN results as a match. On KosmicKrisp the hardware flush returns the canonical NaN 0x7fc00000 where the exact f32 rules keep a sign or payload, so the probe passed. Since #15859, compute shaders on KosmicKrisp have therefore run with the hardware flush and lost those NaN results.

Compare now counts a NaN that differs in its bits as a mismatch, like any other value. With APS5_FAST_F32, where NaN bits are not kept anyway, any two NaN results still count as a match. ExactF32Arithmetic is added to shaderCacheReviewedNames. It already selects the disk cache source version (ShaderDiskCache.cpp), and the probe's outcome reaches recompiles through SpirvTarget::float32FlushToZero, which the cache key includes.

On KosmicKrisp the probe now fails, so compute shaders go back to the emulated flush they had before #15859. ARCHITECTURE.md and the KosmicKrisp debt entry say so.

Tested

macOS 27.3, Apple M5 Pro, Apple clang, x86-64 Release under Rosetta 2. Tree: main 095ff72367 with #16591, #17425 and #17532, which macOS needs to build, and this change.

Startup probe line:

driver before after
KosmicKrisp, Mesa main 94ff826188c hardware (0 of 5472) emulated (24 of 5472)
KosmicKrisp, same, with APS5_FAST_F32=1 hardware (0 of 5472) hardware (0 of 5472)
MoltenVK hardware (0 of 5472) hardware (0 of 5472)

What the hardware flush does to NaN results on KosmicKrisp: agc_driver_f32_arithmetic_nan builds its program with VulkanDevice::Target(), which on KosmicKrisp leaves the flush off, so it never saw this. With the flush on, and the test changed locally to list every lane instead of stopping at the first one, 398 results differ from the expected value, against 52 with APS5_NO_HW_F32_FLUSH=1. The extra ones are v_add_f32, v_sub_f32, v_subrev_f32, v_mul_f32, v_fma_f32, v_fmac_f32, v_fmaak_f32 and v_fmamk_f32 returning 0x7fc00000 instead of, for example, 0xffc00000 or 0x7f812345. On MoltenVK the same count is 0 with the flush on and 0 with it off.

  • ctest -R 'f32|f16|denorm|float32|mullit' (70 tests, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1):
    • KosmicKrisp: 59 pass, 4 skip, 7 fail. These are the same 7 tests that fail without this change, and the same 7 #15859 listed.
    • MoltenVK: 68 pass, 2 fail (agc_driver_f32_constant_factor_tininess and agc_driver_f32_denormal_flush). The probe's outcome on MoltenVK is the same with and without this change, so its modules are unchanged.
  • PPSA21564 01.007.000 on KosmicKrisp, main 73f84ebbc5-based lab tree with this change, cold shader cache: 360 s with no crash, and the startup line reads emulated (24 of 5472 ...). Compute shaders lose the hardware flush gain #15859 measured (about 2 % frame time in one window).
  • Linux, Windows and NVIDIA: not run. A driver whose hardware flush changes NaN bits now keeps the emulated flush.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: Apple M5 Pro, KosmicKrisp (Mesa main 94ff826188c, with MESA_KK_DISABLE_WORKAROUNDS=10) and MoltenVK, macOS 27.3
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5216571561 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17588). Originally posted by [Gonic0](https://github.com/Gonic0) on 2026-11-09T00:07:48Z. --- ### What `ProbeFloat32FlushToZero` counted any two NaN results as a match. On KosmicKrisp the hardware flush returns the canonical NaN `0x7fc00000` where the exact f32 rules keep a sign or payload, so the probe passed. Since #15859, compute shaders on KosmicKrisp have therefore run with the hardware flush and lost those NaN results. `Compare` now counts a NaN that differs in its bits as a mismatch, like any other value. With `APS5_FAST_F32`, where NaN bits are not kept anyway, any two NaN results still count as a match. `ExactF32Arithmetic` is added to `shaderCacheReviewedNames`. It already selects the disk cache source version (`ShaderDiskCache.cpp`), and the probe's outcome reaches recompiles through `SpirvTarget::float32FlushToZero`, which the cache key includes. On KosmicKrisp the probe now fails, so compute shaders go back to the emulated flush they had before #15859. `ARCHITECTURE.md` and the KosmicKrisp debt entry say so. ### Tested macOS 27.3, Apple M5 Pro, Apple clang, x86-64 Release under Rosetta 2. Tree: `main` `095ff72367` with #16591, #17425 and #17532, which macOS needs to build, and this change. Startup probe line: | driver | before | after | |---|---|---| | KosmicKrisp, Mesa `main` `94ff826188c` | hardware (0 of 5472) | emulated (24 of 5472) | | KosmicKrisp, same, with `APS5_FAST_F32=1` | hardware (0 of 5472) | hardware (0 of 5472) | | MoltenVK | hardware (0 of 5472) | hardware (0 of 5472) | What the hardware flush does to NaN results on KosmicKrisp: `agc_driver_f32_arithmetic_nan` builds its program with `VulkanDevice::Target()`, which on KosmicKrisp leaves the flush off, so it never saw this. With the flush on, and the test changed locally to list every lane instead of stopping at the first one, 398 results differ from the expected value, against 52 with `APS5_NO_HW_F32_FLUSH=1`. The extra ones are `v_add_f32`, `v_sub_f32`, `v_subrev_f32`, `v_mul_f32`, `v_fma_f32`, `v_fmac_f32`, `v_fmaak_f32` and `v_fmamk_f32` returning `0x7fc00000` instead of, for example, `0xffc00000` or `0x7f812345`. On MoltenVK the same count is 0 with the flush on and 0 with it off. - `ctest -R 'f32|f16|denorm|float32|mullit'` (70 tests, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`): - KosmicKrisp: 59 pass, 4 skip, 7 fail. These are the same 7 tests that fail without this change, and the same 7 #15859 listed. - MoltenVK: 68 pass, 2 fail (`agc_driver_f32_constant_factor_tininess` and `agc_driver_f32_denormal_flush`). The probe's outcome on MoltenVK is the same with and without this change, so its modules are unchanged. - PPSA21564 01.007.000 on KosmicKrisp, `main` `73f84ebbc5`-based lab tree with this change, cold shader cache: 360 s with no crash, and the startup line reads `emulated (24 of 5472 ...)`. Compute shaders lose the hardware flush gain #15859 measured (about 2 % frame time in one window). - Linux, Windows and NVIDIA: not run. A driver whose hardware flush changes NaN bits now keeps the emulated flush. ### Checklist - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: Apple M5 Pro, KosmicKrisp (Mesa `main` `94ff826188c`, with `MESA_KK_DISABLE_WORKAROUNDS=10`) and MoltenVK, macOS 27.3 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
milescoviello commented 2026-11-09 09:33:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-09T09:33:31Z.

Review: APPROVED


NVIDIA result for the question in the description: on proprietary NVIDIA on Linux the bitwise NaN compare doesn't change the probe's outcome, so NVIDIA keeps the hardware flush.

Setup: Ubuntu 26.04.1, RTX 4070 Ti, NVIDIA 615.71.09, GCC 15.2, Release. The merge base 972b77046f and head 4c214c6603 were each built and run with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (layer 1.4.341, VK_LOADER_DEBUG=layer), ctest -V.

merge base this head
startup probe hardware (0 of 5472 probe results differ from the emulated flush, 331 ms) hardware (0 of 5472 probe results differ from the emulated flush, 292 ms)
agc_driver_f32_arithmetic_nan, _fast, agc_driver_f32_denormal_flush, agc_driver_f32_min_max_nan 4 of 4 pass 4 of 4 pass
VUID- lines 0 0

The loader inserted the layer in all 4 tests on each side, and 4 Vulkan devices were created on each side, so the layer had something to check. The probe line is the same on both sides in the re-run: f32 denormal flush: hardware (0 of 5472 probe results differ from the emulated flush).

From reading:

  • Compare: ExactF32Arithmetic() is read once per call, so APS5_FAST_F32 keeps the old NaN-insensitive match. Without it, a NaN pair with different bits now counts as one mismatch, like any other differing word.
  • Cache: the probe's outcome reaches the shader cache key through SpirvTarget::float32FlushToZero, which CacheKey.hpp:377 appends, so a KosmicKrisp cache built before this change isn't reused with the other flush mode. Adding ExactF32Arithmetic to shaderCacheReviewedNames matches the existing source-version use.

This complements DonRyuzaki's AMD/Windows run: AMD, NVIDIA and MoltenVK all still pass the probe, and KosmicKrisp is the one that fails it, as intended.

Edited 11-09: the validation numbers above come from a re-run with layer 1.4.341, where VK_LOADER_DEBUG=layer shows the loader inserting it in every test. The 1.4.363 layer my first run pointed at wasn't installed, and these test programs don't print the loader's "not found" error, so that run validated nothing (#17896).

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5823968069 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17588#pullrequestreview-5823968069). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-09T09:33:31Z. **Review:** APPROVED --- NVIDIA result for the question in the description: on proprietary NVIDIA on Linux the bitwise NaN compare doesn't change the probe's outcome, so NVIDIA keeps the hardware flush. **Setup:** Ubuntu 26.04.1, RTX 4070 Ti, NVIDIA 615.71.09, GCC 15.2, Release. The merge base `972b77046f` and head `4c214c6603` were each built and run with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (layer 1.4.341, `VK_LOADER_DEBUG=layer`), `ctest -V`. | | merge base | this head | |---|---|---| | startup probe | `hardware (0 of 5472 probe results differ from the emulated flush, 331 ms)` | `hardware (0 of 5472 probe results differ from the emulated flush, 292 ms)` | | `agc_driver_f32_arithmetic_nan`, `_fast`, `agc_driver_f32_denormal_flush`, `agc_driver_f32_min_max_nan` | 4 of 4 pass | 4 of 4 pass | | `VUID-` lines | 0 | 0 | The loader inserted the layer in all 4 tests on each side, and 4 Vulkan devices were created on each side, so the layer had something to check. The probe line is the same on both sides in the re-run: `f32 denormal flush: hardware (0 of 5472 probe results differ from the emulated flush)`. From reading: - **`Compare`:** `ExactF32Arithmetic()` is read once per call, so `APS5_FAST_F32` keeps the old NaN-insensitive match. Without it, a NaN pair with different bits now counts as one mismatch, like any other differing word. - **Cache:** the probe's outcome reaches the shader cache key through `SpirvTarget::float32FlushToZero`, which `CacheKey.hpp:377` appends, so a KosmicKrisp cache built before this change isn't reused with the other flush mode. Adding `ExactF32Arithmetic` to `shaderCacheReviewedNames` matches the existing source-version use. This complements DonRyuzaki's AMD/Windows run: AMD, NVIDIA and MoltenVK all still pass the probe, and KosmicKrisp is the one that fails it, as intended. *Edited 11-09: the validation numbers above come from a re-run with layer 1.4.341, where `VK_LOADER_DEBUG=layer` shows the loader inserting it in every test. The 1.4.363 layer my first run pointed at wasn't installed, and these test programs don't print the loader's "not found" error, so that run validated nothing (#17896).* 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!17588
No description provided.