fix(shader): flush v_add_f64 and v_mul_f64 denormals by the f64 field #7042
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7042"
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 thuanquang on 2026-10-17T07:23:17Z.
What
v_add_f64andv_mul_f64ignored theFLOAT_MODEf16/f64 denormal field (bits 7:6). On the GPU:v_add_f64 2^-1074, 0is+0wheremaingives2^-1074, andv_add_f64 2^-1022, -2^-1074is2^-1022wheremaingives the denormal0x000fffffffffffff;v_mul_f32andv_mul_f16follow. So0x2000000000000001 * 0x1ffffffffffffffe(exactly 2^-1022 - 2^-1126) rounds to 2^-1022 and is kept; detecting tininess before rounding flushes it and disagrees with the GPU on 4 (mode 0) and 8 (mode 1) of 484 rows.float64Operationnow flushes the sources of these two opcodes withflushF64Bits, andflushTinyF64Resultflushes a tiny result: a sum is tested directly (tiny sums are exact), a product by multiplying one source by 2^64 on the host and comparing the magnitude with 2^-958, which is the 53-bit rounding of the exact product scaled into the normal range. Modes that keep denormals, and shaders without a known float mode, are translated as before.v_fma_f64andv_div_fmas_f64(recorded as a separate gap in the technical debt), min/max (#6760) and the compares (#6850) are not touched.This builds on #7036, which adds
flushF64Bitsand changes the same lines offloat64Operation; until it merges, this diff includes its commit.Measured
The same instructions were run directly on the GPU with the
tools/hw-oracletemplate, launched through the driver's HIP runtime, and through the recompiler on Vulkan, at IEEE 0 and 1, over the 576 pairs of 24 f64 values (±0, ±2^-1074, ±0x000fffffffffffff, 0x0008000000000000, ±2^-1022, 0x0010000000000001, ±0.5, ±1, 0x3ff0000000000001, 0x3feffffffffffffe, 0x2000000000000001, 0x1ffffffffffffffe, 2^-1021, 0x7fefffffffffffff, ±inf, 2^52, 2^-53):mainvs GPU, add / mulWith this change every mode also matches for
-src0, |src1|(add),|src0|, -src1(mul) andclampon both. Over a second set of 529 pairs with quiet and signaling NaNs, add and mul match in every mode except 44 rows per instruction that differ only in NaN payload at IEEE=0, in all four modes and the same onmain(f64 NaN bits are left to the driver, as the technical debt records).Tested
Windows 11 26200, AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON,ANYPS5_REQUIRE_VULKAN=1:agc_driver_f64_add_mul_denormal_modes: both instructions over 16 pairs (denormal inputs, tiny sums, products at 2^-1022 before and after rounding, signed zeros) in f64 denormal modes 0 to 3 at IEEE 0 and 1 and without a known float mode, against the GPU's results for each mode. Onmainit fails:v_add_f64 f64 denormal mode 0, IEEE mode on of 0x0000000000000001 and 0x0000000000000000 is 0x0000000000000001, expected 0x0000000000000000. With this change it passes.ctest --parallel 4 --timeout 120onmainf8b22edfbwith #7036 and this change: 1369 tests, 2 fail, both failing onmainon this GPU too:agc_driver_lds_mixed_width_atomics(#5271) andagc_driver_layered_volume_vertex_no_gpl(#4768).agc_driver_f64_arithmetic,agc_driver_f64_rounding_denormal_modesand the other f64 tests pass.python tools/check_conventions.py --base origin/mainwith this title and body passes.main7a36de66bon 2026-10-19, after #6760 (f64 min and max input denormal mode) merged. The only conflict was inFloat64Instructions.cpp, where #6760 renamednonIeeeMinMaxF64tominMaxF64and added its input flush;flushTinyF64Resultnow sits beforemain's function, which is unchanged.On the RX 6700 XT, all 11
agc_driver_f64_*tests pass 2 of 2 on the rebased code (head9c048ee16; the last rebase step only shortened this PR's debt entry to fit the new 1000-character limit), includingagc_driver_f64_arithmetic(#6760's min/max denormal rows),agc_driver_f64_add_mul_denormal_modesandagc_driver_f64_rounding_denormal_modes. The full suite was not rerun on it.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T07:30:06Z.
This branch includes #7036's current head (5bc68b1cc), so it inherits that PR's Linux CI failure in agc_driver_f64_rounding_denormal_modes (llvmpipe, see https://github.com/boykopovar/AnyPS5/pull/7036#issuecomment-6231058756). The new F64AddMulDenormalModes test looks exposed to the same thing: its kept-denormal rows (modes 1/3/unknown) do host f64 arithmetic on denormals, and lavapipe may flush f64 subnormals.
Suggestion for both tests: gate the kept-denormal rows on shaderDenormPreserveFloat64, the way the existing f64 subnormal test does, then rebase this PR onto the fixed #7036. We would merge them as a pair, #7036 first.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T07:40:29Z.
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.
core/shader/recompiler/Translation/include/Translation/TranslationContext.hppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/shader/recompiler/Translation/include/Translation/TranslationContext.hppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdImported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-17T08:09:05Z.
Another AMD driver, since the description lists other AMD drivers as untested.
Windows 11 (26300), Radeon 860M (RDNA 3.5,
1002:1114), driver 32.0.13058.8001, WinLibs GCC 15.2.0, Release,ANYPS5_REQUIRE_VULKAN=1. Tree:main17cfb1f4cwith #7018, #7034, #7036, #7038, #7040, #7041 and #7042 merged together (onlydocs/dev/debt/shader.mdconflicted, for #7040); "main" is the same tree with the six recompiler files reverted tomainand the tests kept.agc_driver_f64_add_mul_denormal_modesand the extendedagc_driver_f64_rounding_denormal_modes: both fail onmain, and pass 3 of 3 with this change.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T13:35:39Z.
Review: COMMENTED
An NVIDIA run, and lavapipe for the exposure @oneandonlydean raised about the new add/mul test.
Machine: Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same host. PR merged ontomain12a71f3f5(clean).ANYPS5_NO_SHADER_CACHE=1,-j1 --timeout 30.^agc_driver_f64(11 tests)agc_driver_f64_rounding_denormal_modes, inherited from #7036 (frexpof denormal inputs, details there)agc_driver_f64_add_mul_denormal_modeswith the recompiler files frommainv_add_f64 f64 denormal mode 0, IEEE mode on of 0x0000000000000001 and 0x0000000000000000 is 0x0000000000000001, expected 0x0000000000000000With the test's
Requirechanged locally to log and count instead of throwing,agc_driver_f64_add_mul_denormal_modeshas 0 mismatches in every mode on both devices, including the kept-denormal rows (modes 1, 3 and no known float mode). Onmainit has 58 on each. So on this lavapipe the add/mul rows do not need a gate. Both devices reportshaderDenormPreserveFloat64 = false, so a gate on that feature would skip these rows on NVIDIA too, where they pass.Not run: Windows, AMD, any title.
GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02) and lavapipe (Mesa 26.0.3), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by UmillD on 2026-10-17T13:45:13Z.
Windows/NVIDIA validation of this PR, including its #7036 prerequisite.
10de:2f04, subgroup 32), driver 617.42 / 32.0.16.1742; Windows 11 Home Single Language 10.0.26300. CPU: Ryzen 7 9700X.4369547aaf04f56b82d1cc580946d7b5d9c56f8bmerged cleanly intomainaa6424184adb46e60ae45c5593290c25eb52824b; integrated tree09a57400a24482320e5bdad5d4132646c348be3b. No other PRs or local Astro Bot changes included.BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=OFF, offscreen test driver. Both selected-target builds succeeded.ANYPS5_GPU="NVIDIA GeForce RTX 5070",ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,APS5_NO_PIPELINE_JOURNAL=1; CTest serial, 30 s timeout per case. Candidate used--repeat until-fail:3. The selected NVIDIA device is confirmed in every GPU run's full console log.agc_driver_div_fixup_f64_denormal_modesagc_driver_f64_add_mul_denormal_modesagc_driver_f64_arithmeticagc_driver_f64_conversionsagc_driver_f64_divisionagc_driver_f64_division_modifiersagc_driver_f64_fma_subnormalsagc_driver_f64_nan_conversionsagc_driver_f64_roundingagc_driver_f64_rounding_denormal_modesagc_driver_f64_transcendentalagc_driver_vopc_compare_f64The control failures were:
Candidate: 36/36 GPU executions passed, zero skipped. The other ten selected GPU cases also passed on the control.
agc_driver_graphics,agc_shader_memory,agc_shader_disk_cacheandagc_recorder_device_selectionpassed once on each phase (4/4 per phase). No timeouts or memory-guard terminations occurred.Scope: focused synthetic Windows/NVIDIA testing. This does not test games, performance, console hardware, the full suite, SPIRV-Tools validation, or the lavapipe issue raised above. The #7036/lavapipe follow-up remains outside this result; driver caches were not controlled.
AI-assisted testing and report: yes (Codex).
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-17T19:00:25Z.
Rebased onto #7036's new head (which now gates its kept-denormal rows, see there), and 3221feb5a applies the same gate to
agc_driver_f64_add_mul_denormal_modes: a mismatch in a kept-denormal mode is printed as skipped only when the device reports no f64DenormPreserve, so on lavapipe and the RTX 3070, where @jotitadev saw those rows pass, they are still checked. RX 6700 XT, Windows: all 11agc_driver_f64tests pass. Merge order unchanged: #7036 first.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T00:05:19Z.
Review: COMMENTED
A rerun of head
3221feb5a(rebased onto #7036's gate) on the RTX 3070 and lavapipe from my earlier run.Machine: Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8). Merged ontomain5de7a46e0(clean).ANYPS5_NO_SHADER_CACHE=1,-j1 --timeout 30.^agc_driver_f64(11 tests): RTX 3070 11/11 (3 runs), lavapipe 11/11 (2 runs).agc_driver_f64_add_mul_denormal_modesprints noskippedline on either device, so the gate in3221feb5adoesn't hide any row here. All add/mul rows are still checked.main, it fails on both devices:v_add_f64 f64 denormal mode 0, IEEE mode on of 0x0000000000000001 and 0x0000000000000000 is 0x0000000000000001, expected 0x0000000000000000.The rounding test is covered in my rerun on #7036.
GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02) and lavapipe (Mesa 26.0.3), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T15:44:21Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
main43a2abaf7(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8): 1638/1640 with this PR, against 1636/1638 onmain. The failures are the same two on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784). The newagc_driver_f64_add_mul_denormal_modesandagc_driver_f64_rounding_denormal_modesran (not skipped) and passed.GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes