Skip to content

fix(shader): honor f64 min and max input denormal mode - #6760

Merged
adriadam10 merged 4 commits into
boykopovar:mainfrom
Ondra97:codex/fix-f64-minmax-denormals
Oct 19, 2026
Merged

adriadam10 merged 4 commits into
boykopovar:mainfrom
Ondra97:codex/fix-f64-minmax-denormals

Conversation

@Ondra97

@Ondra97 Ondra97 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What

v_min_f64 and v_max_f64 now flush subnormal inputs to signed zero when FLOAT_DENORM16_64 disables input preservation (modes 0 and 2), before comparison and NaN selection. For example, v_max_f64(0x0000000000000001, +0) returns +0 in 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, head 01b1664eb47b90a6d5dc568a9d4f1671fb003063. 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.

  • Full Windows app/libs build with BUILD_TESTING=ON passed. The supported execution-fixture selection builds the f64 fixtures, VopcCompareF64 and F16MinMaxNan; other execution fixtures use selection stubs and were not tested.
  • 17 targeted CTest groups passed, zero failures/skips: ten hardware GPU tests (eight f64 arithmetic/conversion/rounding groups, f64 comparisons and f16 min/max), f64 SPIR-V denormal-mode verification, shader mode/memory/control-flow/structurizer/constant-phi checks, and patched-library validation. Every test finished below 1 s with a 30 s limit.
  • Five further agc_driver_f64_arithmetic runs passed. No min/max result words were skipped on this NVIDIA device, which reports no f64 DenormPreserve but satisfies these checks.
  • Conventions and whitespace checks passed.

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:

Metric Before (base shader sources) After (PR head)
agc_driver_f64_arithmetic, same native NVIDIA host and inputs 1/1 fails: mode 0, IEEE off, max low word 0x00000001, expected zero 6/6 passes; zero skipped words

Additional 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 30 with the targeted group filter, ctest --test-dir build -R '^agc_driver_f64_arithmetic$' --repeat until-fail:5 -V --timeout 30, and python 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

  • 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: NVIDIA GeForce RTX 4070 Ti SUPER, driver 617.42, Windows 11 Pro 10.0.26300
  • AI-assisted: yes, Codex

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7042 core/shader/recompiler/Translation/src/Float64Instructions.cpp L35-37
PR 7446 docs/dev/debt/libSceAgcDriver.md L112-113
PR 7683 docs/dev/debt/libSceAgcDriver.md L111-112

Some 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.

Pull request Shared files not compared
PR 4072 core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp
PR 4448 docs/dev/debt/libSceAgcDriver.md
PR 4449 docs/dev/debt/libSceAgcDriver.md
PR 5058 docs/dev/debt/libSceAgcDriver.md
PR 5499 docs/dev/debt/libSceAgcDriver.md
PR 5925 docs/dev/debt/libSceAgcDriver.md
PR 5941 core/shader/recompiler/Translation/src/VectorInstructions.cpp
PR 6009 core/shader/recompiler/Translation/src/VectorInstructions.cpp
PR 6146 docs/dev/debt/libSceAgcDriver.md
PR 6194 docs/dev/debt/libSceAgcDriver.md
PR 6218 docs/dev/debt/libSceAgcDriver.md
PR 6223 docs/dev/debt/libSceAgcDriver.md
PR 6300 docs/dev/debt/libSceAgcDriver.md
PR 6548 docs/dev/debt/libSceAgcDriver.md
PR 6549 docs/dev/debt/libSceAgcDriver.md
PR 6612 docs/dev/debt/libSceAgcDriver.md
PR 6636 docs/dev/debt/libSceAgcDriver.md
PR 6683 docs/dev/debt/libSceAgcDriver.md
PR 6727 docs/dev/debt/libSceAgcDriver.md
PR 6741 docs/dev/debt/libSceAgcDriver.md
PR 6762 docs/dev/debt/libSceAgcDriver.md
PR 6808 docs/dev/debt/libSceAgcDriver.md
PR 6867 docs/dev/debt/libSceAgcDriver.md
PR 6868 docs/dev/debt/libSceAgcDriver.md
PR 6941 docs/dev/debt/libSceAgcDriver.md
PR 6946 docs/dev/debt/libSceAgcDriver.md
PR 6947 docs/dev/debt/libSceAgcDriver.md
PR 6958 docs/dev/debt/libSceAgcDriver.md
PR 6966 docs/dev/debt/libSceAgcDriver.md
PR 6977 docs/dev/debt/libSceAgcDriver.md
PR 7008 docs/dev/debt/libSceAgcDriver.md
PR 7254 docs/dev/debt/libSceAgcDriver.md
PR 7256 docs/dev/debt/libSceAgcDriver.md
PR 7258 docs/dev/debt/libSceAgcDriver.md
PR 7332 docs/dev/debt/libSceAgcDriver.md
PR 7390 docs/dev/debt/libSceAgcDriver.md
PR 7432 docs/dev/debt/libSceAgcDriver.md
PR 7449 docs/dev/debt/libSceAgcDriver.md
PR 7505 docs/dev/debt/libSceAgcDriver.md
PR 7604 docs/dev/debt/libSceAgcDriver.md
PR 7642 docs/dev/debt/libSceAgcDriver.md
PR 7659 docs/dev/debt/libSceAgcDriver.md
PR 7729 docs/dev/debt/libSceAgcDriver.md
PR 7800 docs/dev/debt/libSceAgcDriver.md
PR 7803 docs/dev/debt/libSceAgcDriver.md

@keravyn-ops

Copy link
Copy Markdown
Contributor

AMD / Windows run of this PR at 5356078: 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).

@nicolasfalesy

Copy link
Copy Markdown
Contributor

Tested on Linux (Arch), c++ (GCC) 16.2.1 20260810, Release, BUILD_TESTING=ON, main at e3838332ee31af787ad311b7eadbe53d8d012e95. GPU tests ran on lavapipe (llvmpipe, LLVM 22.1.8).

This PR breaks the existing test agc_driver_f64_arithmetic on lavapipe, which is what CI uses. On main it passes (2 of 2 full ctest -j8 runs). On main plus this PR it fails (2 of 2):

AGC graphics: f64 min/max denormal mode -1 IEEE 0 abs 0 neg 0 lane 0 max lo is 0x00000000, expected 0x00000001

The failing check is the Require at F64Arithmetic.cpp:256 of the new CheckMinMaxDenormals. 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 input 0x1, so the max of {0x1, 0x0} is flushed. The PR's AMD Windows run passes, so this depends on the device. The target here evidently reports no f64 DenormPreserve (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:138 uses on #7036's head:

if (actual != expectedWord && (denormals < 0 || (denormals & 1) != 0) && !device.Target().float64DenormPreserve) continue;

placed in front of the Require at line 256. With that line agc_driver_f64_arithmetic passes on lavapipe (2 of 2). Modes 0 and 2, which the change fixes, are still checked on every device.

AI-assisted: yes

@Ondra97

Ondra97 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @nicolasfalesy for the reproducer and tested suggestion. I pushed the test fix; current head 01b1664eb4 includes main f1af6c5915.

The fixture skips only mismatching kept-denormal words when float64DenormPreserve is 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_arithmetic and your ctest -j8 run on Arch/lavapipe with this head, and share any skipped-mode output or remaining failures?

AI-assisted: yes (Codex).

@nicolasfalesy

Copy link
Copy Markdown
Contributor

Reran on Linux (Arch), c++ (GCC) 16.2.1 20260810, Release, BUILD_TESTING=ON, head 01b1664eb47b90a6d5dc568a9d4f1671fb003063 (includes main f1af6c5915). GPU tests on lavapipe (llvmpipe, LLVM 22.1.8).

  • agc_driver_f64_arithmetic: passes, 2 of 2.
  • Full 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:

skipped 18 f64 min/max result words in denormal mode -1 IEEE 0 abs 0 neg 0: device has no f64 DenormPreserve
skipped 18 f64 min/max result words in denormal mode 3 IEEE 0 abs 0 neg 0: device has no f64 DenormPreserve
skipped 18 f64 min/max result words in denormal mode 3 IEEE 1 abs 0 neg 0: device has no f64 DenormPreserve
skipped 17 f64 min/max result words in denormal mode -1 IEEE 0 abs 1 neg 2: device has no f64 DenormPreserve
skipped 17 f64 min/max result words in denormal mode 3 IEEE 0 abs 1 neg 2: device has no f64 DenormPreserve
skipped 17 f64 min/max result words in denormal mode 3 IEEE 1 abs 1 neg 2: device has no f64 DenormPreserve
skipped 17 f64 min/max result words in denormal mode -1 IEEE 0 abs 2 neg 1: device has no f64 DenormPreserve
skipped 17 f64 min/max result words in denormal mode 3 IEEE 0 abs 2 neg 1: device has no f64 DenormPreserve
skipped 17 f64 min/max result words in denormal mode 3 IEEE 1 abs 2 neg 1: device has no f64 DenormPreserve
skipped 12 f64 min/max result words in denormal mode -1 IEEE 0 abs 3 neg 3: device has no f64 DenormPreserve
skipped 12 f64 min/max result words in denormal mode 3 IEEE 0 abs 3 neg 3: device has no f64 DenormPreserve
skipped 12 f64 min/max result words in denormal mode 3 IEEE 1 abs 3 neg 3: device has no f64 DenormPreserve

AI-assisted: yes

@thuanquang

Copy link
Copy Markdown
Contributor

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_f64 and v_max_f64 run 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:

modes 0 and 2 modes 1 and 3
v_min_f64 132 of 132 match the flushed inputs 132 of 132 match the kept inputs
v_max_f64 132 of 132 match the flushed inputs 132 of 132 match the kept inputs

The 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.

@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@adriadam10
adriadam10 merged commit 118266a into boykopovar:main Oct 19, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants