fix(agc): compare NaN results bit for bit in the f32 flush probe #17588
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17588"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Gonic0 on 2026-11-09T00:07:48Z.
What
ProbeFloat32FlushToZerocounted any two NaN results as a match. On KosmicKrisp the hardware flush returns the canonical NaN0x7fc00000where 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.Comparenow counts a NaN that differs in its bits as a mismatch, like any other value. WithAPS5_FAST_F32, where NaN bits are not kept anyway, any two NaN results still count as a match.ExactF32Arithmeticis added toshaderCacheReviewedNames. It already selects the disk cache source version (ShaderDiskCache.cpp), and the probe's outcome reaches recompiles throughSpirvTarget::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.mdand the KosmicKrisp debt entry say so.Tested
macOS 27.3, Apple M5 Pro, Apple clang, x86-64 Release under Rosetta 2. Tree:
main095ff72367with #16591, #17425 and #17532, which macOS needs to build, and this change.Startup probe line:
main94ff826188cAPS5_FAST_F32=1What the hardware flush does to NaN results on KosmicKrisp:
agc_driver_f32_arithmetic_nanbuilds its program withVulkanDevice::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 withAPS5_NO_HW_F32_FLUSH=1. The extra ones arev_add_f32,v_sub_f32,v_subrev_f32,v_mul_f32,v_fma_f32,v_fmac_f32,v_fmaak_f32andv_fmamk_f32returning0x7fc00000instead of, for example,0xffc00000or0x7f812345. 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):agc_driver_f32_constant_factor_tininessandagc_driver_f32_denormal_flush). The probe's outcome on MoltenVK is the same with and without this change, so its modules are unchanged.main73f84ebbc5-based lab tree with this change, cold shader cache: 360 s with no crash, and the startup line readsemulated (24 of 5472 ...). Compute shaders lose the hardware flush gain #15859 measured (about 2 % frame time in one window).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)main94ff826188c, withMESA_KK_DISABLE_WORKAROUNDS=10) and MoltenVK, macOS 27.3🤖 Generated with Claude Code
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
972b77046fand head4c214c6603were each built and run withANYPS5_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.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_nanVUID-linesThe 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, soAPS5_FAST_F32keeps the old NaN-insensitive match. Without it, a NaN pair with different bits now counts as one mismatch, like any other differing word.SpirvTarget::float32FlushToZero, whichCacheKey.hpp:377appends, so a KosmicKrisp cache built before this change isn't reused with the other flush mode. AddingExactF32ArithmetictoshaderCacheReviewedNamesmatches 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=layershows 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)