fix(shader): flush f64 floor, ceil, fract and frexp denormal inputs #7036
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7036"
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-17T06:54:58Z.
What
v_floor_f64,v_ceil_f64,v_fract_f64,v_frexp_mant_f64andv_frexp_exp_i32_f64ignored theFLOAT_MODEf16/f64 denormal field (bits 7:6). On the GPU:v_ceil_f64 2^-1074is0wheremaingives1.0,v_floor_f64 -2^-1074is-0wheremaingives-1.0,v_fract_f64 -2^-1074is0wheremaingives0x3fefffffffffffff, and both frexp forms give 0;v_fract_f64flushes the denormal result it gives for a positive denormal input to +0.float64Unarynow flushes the source of those four opcodes, and thev_fract_f64result, through a newflushF64Bits(the f64 counterpart offlushF16Bits, by the same keep bits);float64Operationflushes the source ofv_frexp_exp_i32_f64.v_trunc_f64andv_rndne_f64give the same results with or without the flush and are unchanged. Modes that keep denormals, and shaders without a known float mode, are translated as before. The other f64 arithmetic still ignores the field; min/max and the compares are covered by #6760 and #6850, which this PR does not touch.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 23 f64 values (±0, ±2^-1074, ±0x000fffffffffffff, 0x0008000000000000, ±2^-1022, 0x0010000000000001, ±0.5, ±1, 0x3feffffffffffffe, 0x3ff0000000000001, 2^-52, 2^-1021, 0x7fefffffffffffff, ±inf, a quiet and a signaling NaN):mainvs GPU (floor / ceil / fract / frexp_mant / frexp_exp)With this change every mode also matches for
-v[4:5](floor, frexp_mant, frexp_exp),|v[4:5]|(ceil) and-|v[4:5]|(fract) over 16 of those values, andv_trunc_f64andv_rndne_f64match before and after.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_rounding_denormal_modes: the five instructions over 18 finite values (zeros, denormals, minimum normals, 0.5, -1.5, 2.75, values next to ±1, ±0x7fefffffffffffff and 2^52 + 1) in f64 denormal modes 0 to 3 at IEEE 0 and 1 and without a known float mode, againststd::floor,std::ceil,std::frexpandmin(x - floor(x), 0x3fefffffffffffff)of the flushed input, with the fract result flushed when bit 7 is clear. That model matched the GPU on those 18 values in every mode. Onmainit fails:v_ceil_f64 f64 denormal mode 0, IEEE mode on of 0x0000000000000001 is 0x3ff0000000000000, expected 0x0000000000000000. With this change it passes.ctest --parallel 4 --timeout 120onmain6e7ba928awith this change: 1368 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_conversionsand the other f64 tests pass.python tools/check_conventions.py --base origin/mainwith this title and body passes.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:10:58Z.
Full CI on 5bc68b1cc (run 39012021072): Linux fails the test this PR adds, agc_driver_f64_rounding_denormal_modes (llvmpipe, LLVM 20.1.2):
Windows shows success only because its runner has no Vulkan device, so the test is skipped there; Linux is the only CI job that runs it. Could you look at the frexp path when the float mode isn't known?
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T07:30:26Z.
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.mdImported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-17T08:09:00Z.
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_rounding_denormal_modes: fails onmain, passes 3 of 3 with this change (and with #7042, which extends it).AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T13:35:37Z.
Review: COMMENTED
An NVIDIA run, and the full list of rows that fail on lavapipe, for the CI failure @oneandonlydean reported.
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(10 tests)agc_driver_f64_rounding_denormal_modesfails with the CI message:v_frexp_mant_f64 without a known float mode of 0x0000000000000001 is 0x3fe0000000000001, expected 0x3fe0000000000000Float64Instructions.cpp/SubwordPacking.cpp/TranslationContext.hppfrommainv_ceil_f64 f64 denormal mode 0, IEEE mode on of 0x0000000000000001 is 0x3ff0000000000000, expected 0x0000000000000000To see every failing row and not only the first one, I changed the test's
Requirelocally to log and count instead of throwing:v_frexp_mant_f64andv_frexp_exp_i32_f64of a denormal input, in the modes that keep f64 denormals (1, 3 and no known float mode), 8 per mode.floor,ceilandfractmatch in every mode, and in modes 0 and 2 (input flushed first)frexpmatches too. The rows for no known float mode:frexp_mantlavapipe / expectedfrexp_explavapipe / expected0x00000000000000010x3fe0000000000001/0x3fe00000000000000x000fffffffffffff0x3fefffffffffffff/0x3feffffffffffffe0x00080000000000000x3fe8000000000000/0x3fe0000000000000(plus the negative inputs, same pattern). These rows translate as on
main, so this is lavapipe's f64frexpnot normalizing a denormal input (it reads the mantissa bits as if the exponent were -1022), not this PR's flush.One note on gating these rows on
shaderDenormPreserveFloat64: the 3070 reports itfalse, the same as this lavapipe, and passes all of them. A gate on that feature would skip the kept-denormal rows on NVIDIA too, and thefloor/ceil/fractrows that lavapipe gets right. On this lavapipe only thefrexprows with a denormal input need to be skipped.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 Dextroid17 on 2026-10-17T17:46:26Z.
@jotitadev's review found only the
frexprows failing on lavapipe with Mesa 26.0.3, and suggested skipping just those because the RTX 3070 reportsshaderDenormPreserveFloat64false and still passes every row. On a newer lavapipe that narrower skip is not enough.Linux, lavapipe (Mesa 26.2.4, LLVM 23.1.1,
GALLIUM_OVERRIDE_CPU_CAPS=avxas in CI), Release, PR head5bc68b1cc. With the test'sRequirechanged locally to log and count instead of throwing, there are 114 mismatches. All are in the modes that keep f64 denormals (no known float mode, 1 and 3), none in modes 0 and 2. Besidesfrexp,floor,ceilandfractof a denormal input fail here too, for examplev_ceil_f64 without a known float mode of 0x0000000000000001 is 0x0000000000000000, expected 0x3ff0000000000000. WithFloat64Instructions.cpp,SubwordPacking.cppandTranslationContext.hppfrommainand the test kept, the same 114 kept-mode rows fail, row for row. So these rows depend on the device, not on this PR's change.Lavapipe hard-codes
shaderDenormPreserveFloat64 = false(lvp_device.c, line 1043 atmesa-25.2.8, CI's version, and line 1122 atmesa-26.2.4), so these shaders get noDenormPreserve 64, and Vulkan then allows the driver to flush f64 denormals. Which rows fail changes with the Mesa version, so a list of rows to skip would need to follow it.This is the gate @oneandonlydean suggested on #7042, applied per mode with the same
float64DenormPreservecheckF64FmaSubnormals.cppuses:ctest -R '^agc_driver_f64_rounding_denormal_modes$', 3 runs each, lavapipe:The failure in the second column is
v_frexp_mant_f64 f64 denormal mode 0, IEEE mode on of 0x0000000000000001 is 0x3fe0000000000001, expected 0x0000000000000000, so with the gate the test still fails without the fix, in modes 0 and 2.The cost is the one @jotitadev named: on a device that reports the feature false but keeps denormals, like the RTX 3070, the kept-mode rows are skipped too. Keeping them there would need the recompiler to compute these results from the bits when
DenormPreserveis not available, or the rows to report a mismatch as a skip instead of a failure on such devices. I have not tried either.Not tested: Windows, NVIDIA, or any AMD GPU.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-17T19:00:23Z.
Thanks for the lavapipe runs.
b55d41151adds the gate, with the ruleF64FmaSubnormals.cppuses: on a device whose target reports no f64DenormPreserve, a mismatch in a mode that keeps f64 denormals (1, 3 and no known float mode) is printed as skipped instead of failing; modes 0 and 2, the ones this change fixes, are checked on every device. Rows that pass are still checked, so a device like the RTX 3070 keeps covering the kept modes. The branch is rebased ontomainf219248f0.RX 6700 XT, Windows: the test passes with no skipped mode, and with
core/shader/recompilerfrommainit still fails:v_ceil_f64 f64 denormal mode 0, IEEE mode on of 0x0000000000000001 is 0x3ff0000000000000, expected 0x0000000000000000. I have not run lavapipe here.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T00:05:17Z.
Review: COMMENTED
A rerun of the gate in
b55d41151on the two devices from my earlier run. It does what the commit says on both: the RTX 3070 still checks every kept-denormal row, and lavapipe skips only the rows it gets wrong.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. #7042 at3221feb5a, which carries this PR's headb55d41151, merged ontomain5de7a46e0(clean).ANYPS5_NO_SHADER_CACHE=1,-j1 --timeout 30.^agc_driver_f64(11 tests)skippedlines inagc_driver_f64_rounding_denormal_modesv_frexp_mant_f64of0x0000000000000001Float64Instructions.cpp,SubwordPacking.cppandTranslationContext.hppfrommainv_ceil_f64 f64 denormal mode 0, IEEE mode on of 0x0000000000000001 is 0x3ff0000000000000, expected 0x0000000000000000Both devices report
shaderDenormPreserveFloat64 = false. On the 3070 none of the kept-mode rows mismatch, so nothing is reported as skipped and those rows are still checked there. That answers the point from my earlier comment. Modes 0 and 2 are checked on both devices and still catch the missing flush.Not run: Windows, AMD, a newer Mesa.
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.