fix(shader): honor f64 min and max input denormal mode #6760
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6760"
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 Ondra97 on 2026-10-16T10:07:48Z.
What
v_min_f64andv_max_f64now flush subnormal inputs to signed zero whenFLOAT_DENORM16_64disables input preservation (modes 0 and 2), before comparison and NaN selection. For example,v_max_f64(0x0000000000000001, +0)returns+0in mode 0. Both instructions share the translation path; the existing IEEE/NaN policy and result modifiers remain in use. Input-preserving and unknown modes retain their existing lowering.The fully flushed/preserved f64 behavior was measured on gfx1036 in #2036. Split modes and sign-preserving flushing follow LLVM's AMDGPU denormal-mode documentation. I did not perform a new AMD or PS5 hardware measurement. The debt entry records the corrected scope; other f64 arithmetic's denormal controls remain outside this change.
The regression checks 32 input pairs, four source-modifier combinations, unknown mode and modes 0/2/3, with IEEE off/on for known modes. Following the lavapipe report, a mismatching word in an input-preserving mode is explicitly counted as skipped only when the target lacks f64
DenormPreserve, using the same capability rule as #7036. Passing words are still checked. Modes 0 and 2 always fail on a mismatch, regardless of that capability.#7036 covers different instructions and is independent. #7042 has a text conflict at the min/max function boundary; its add/mul change is not duplicated here and will need conflict resolution when combined with this PR.
Tested
Base
f1af6c591588b257437f51e5ac1740fb788b231d, head01b1664eb47b90a6d5dc568a9d4f1671fb003063. Test capability fix:397f43d042d210f090f9748f4d66ed9b472c6d56. Current main is merged into the original branch without rewriting its history.Windows (native host): AMD Ryzen 9 7900X, 32 GB RAM, NVIDIA GeForce RTX 4070 Ti SUPER / driver 617.42; Windows 11 Pro 10.0.26300, supported WinLibs GCC 15.2.0 r7, Release.
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_GPU=NVIDIA GeForce RTX 4070 Ti SUPER,ANYPS5_NO_SHADER_CACHE=1. The selected physical GPU was verified in every GPU process; driver caches were not controlled.BUILD_TESTING=ONpassed. The supported execution-fixture selection builds the f64 fixtures,VopcCompareF64andF16MinMaxNan; other execution fixtures use selection stubs and were not tested.agc_driver_f64_arithmeticruns passed. No min/max result words were skipped on this NVIDIA device, which reports no f64DenormPreservebut satisfies these checks.The original shader regression remains detectable with the final fixture and the three production shader files temporarily replaced by their exact base blobs, then restored:
agc_driver_f64_arithmetic, same native NVIDIA host and inputs0x00000001, expected zeroAdditional temporary fault-injection controls reproduced the reported unknown-mode mismatch in the old fixture. The fixed fixture explicitly skipped 12 injected words across unknown/mode-3 configurations without preservation support; the same mismatch failed when preservation was required. Injected mismatches in modes 0 and 2 also failed. All injections and base-source substitutions were removed before the final build and test runs. These controls simulate results and are not a lavapipe run.
Final commands included
cmake --build build --parallel 8,ctest --test-dir build -V -j1 --timeout 30with the targeted group filter,ctest --test-dir build -R '^agc_driver_f64_arithmetic$' --repeat until-fail:5 -V --timeout 30, andpython tools/check_conventions.py --base origin/main.Linux (VirtualBox) was intentionally not run for this update. Native Linux/lavapipe and other GPUs were not rerun locally; the reported lavapipe failure needs a retest of this head. No title, performance measurement or full CTest-suite run is claimed.
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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T10:24:28Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/shader/recompiler/Translation/src/Float64Instructions.cppL35-37docs/dev/debt/libSceAgcDriver.mdL112-113docs/dev/debt/libSceAgcDriver.mdL111-112Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/shader/recompiler/Translation/include/Translation/TranslationContext.hppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/shader/recompiler/Translation/src/VectorInstructions.cppcore/shader/recompiler/Translation/src/VectorInstructions.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by keravyn-ops on 2026-10-17T09:21:37Z.
AMD / Windows run of this PR at
5356078ec: Radeon 780M (RDNA 3, 0x15bf), AMD driver 25.10.20.01 (32.0.21020.1007), Windows 11 Home 10.0.26100, WinLibs GCC 15.2.0 r7, Release.agc_driver_f64_arithmetic: pass (f64 min/max denormal input cases passed,f64 arithmetic tests passed, 1.53 s)AI-assisted: yes (runs made on the device above).
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-18T00:09:47Z.
Tested on Linux (Arch),
c++ (GCC) 16.2.1 20260810, Release,BUILD_TESTING=ON,mainate3838332ee31af787ad311b7eadbe53d8d012e95. GPU tests ran on lavapipe (llvmpipe, LLVM 22.1.8).This PR breaks the existing test
agc_driver_f64_arithmeticon lavapipe, which is what CI uses. Onmainit passes (2 of 2 fullctest -j8runs). Onmainplus this PR it fails (2 of 2):The failing check is the
RequireatF64Arithmetic.cpp:256of the newCheckMinMaxDenormals. It runs the rows that keep f64 denormals (no known float mode, and modes 1 and 3) on every device. Lavapipe returns 0 for the denormal input0x1, so themaxof{0x1, 0x0}is flushed. The PR's AMD Windows run passes, so this depends on the device. The target here evidently reports no f64DenormPreserve(Target().float64DenormPreserve), since the gate below takes effect.Suggested fix, tried on the merge: skip a mismatch in a keeping mode when the device cannot preserve f64 denormals, the same rule
F64RoundingDenormalModes.cpp:138uses on #7036's head:placed in front of the
Requireat line 256. With that lineagc_driver_f64_arithmeticpasses on lavapipe (2 of 2). Modes 0 and 2, which the change fixes, are still checked on every device.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-18T00:46:05Z.
Thanks @nicolasfalesy for the reproducer and tested suggestion. I pushed the test fix; current head
01b1664eb4includes mainf1af6c5915.The fixture skips only mismatching kept-denormal words when
float64DenormPreserveis false and reports their count. Passing words and modes 0/2 remain checked, using the same capability distinction as #7036.On Windows / RTX 4070 Ti SUPER (617.42), the full app/libs build, 17 targeted CTest groups and five extra arithmetic-test runs passed, with no min/max words skipped. The original shader negative control still fails in mode 0; injected-result controls confirmed the gate also keeps modes 0/2 strict. I did not run lavapipe locally.
Could you rerun
agc_driver_f64_arithmeticand yourctest -j8run on Arch/lavapipe with this head, and share any skipped-mode output or remaining failures?AI-assisted: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-18T02:04:18Z.
Reran on Linux (Arch),
c++ (GCC) 16.2.1 20260810, Release,BUILD_TESTING=ON, head01b1664eb47b90a6d5dc568a9d4f1671fb003063(includes mainf1af6c5915). GPU tests on lavapipe (llvmpipe, LLVM 22.1.8).agc_driver_f64_arithmetic: passes, 2 of 2.ctest -j8, one run: 1399 of 1399 pass.Skipped words, the same 12 lines in both runs (192 words in all). They are only in mode -1 and mode 3. Mode 1 skips nothing here, and modes 0 and 2 skip nothing, as intended:
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-19T07:43:10Z.
Native data for the split modes and the sign-preserving flush, which the description says weren't measured: RX 6700 XT (gfx1031, RDNA 2),
v_min_f64andv_max_f64run directly through HIP, all four f16/f64 denormal modes, IEEE 0 and 1. Inputs are the 196 pairs of 14 f64 values: ±0, the smallest and largest denormals, a mid denormal, ±the smallest normal, ±1 and ±infinity. 132 pairs contain a denormal. For each mode I compared every result with the mode-3 (kept) result for the same pair after flushing each denormal input to its signed zero:v_min_f64v_max_f64The same in IEEE 0 and 1. So the inputs are flushed to signed zero exactly when bit 0 of the field is clear, split modes included, and a denormal result is not flushed in mode 1 (it matches the kept result there). That is the rule this PR implements. Desktop RDNA 2, not gfx1013.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T10:28:18Z.
Checked the diff against the f64 min/max translation: inputs are flushed to signed zero before the compare and NaN selection when bit 0 of the f16/f64 denormal field is clear (modes 0 and 2), the IEEE path keeps its previous result, and modes 1/3 and unknown modes are unchanged. The new fixture covers 32 input pairs x 4 source-modifier combinations x modes -1/0/2/3 x IEEE 0/1, and fails on mode 0 without the change. The split modes and sign-preserving flush match the native RDNA2 data from @thuanquang and the earlier gfx1036 measurement (#2036); AMD/Windows (@keravyn-ops) and lavapipe (@nicolasfalesy) runs pass. Merged.