Repository navigation
fix(shader): flush f64 floor, ceil, fract and frexp denormal inputs - #7036
Conversation
|
Full CI on 5bc68b1 (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? |
|
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.
|
|
Another AMD driver, since the description lists other AMD drivers as untested. Windows 11 (26300), Radeon 860M (RDNA 3.5,
AI-assisted: yes (Claude Code). |
jotitadev
left a comment
There was a problem hiding this comment.
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 onto main 12a71f3f5 (clean). ANYPS5_NO_SHADER_CACHE=1, -j1 --timeout 30.
| Run | RTX 3070 | lavapipe |
|---|---|---|
^agc_driver_f64 (10 tests) |
pass 3/3 | 9/10; agc_driver_f64_rounding_denormal_modes fails with the CI message: v_frexp_mant_f64 without a known float mode of 0x0000000000000001 is 0x3fe0000000000001, expected 0x3fe0000000000000 |
new test, Float64Instructions.cpp/SubwordPacking.cpp/TranslationContext.hpp from main |
fails: v_ceil_f64 f64 denormal mode 0, IEEE mode on of 0x0000000000000001 is 0x3ff0000000000000, expected 0x0000000000000000 |
fails |
To see every failing row and not only the first one, I changed the test's Require locally to log and count instead of throwing:
- RTX 3070: 0 mismatches in all 9 modes.
- lavapipe: 40 mismatches. All are
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:
| input | frexp_mant lavapipe / expected |
frexp_exp lavapipe / expected |
|---|---|---|
0x0000000000000001 |
0x3fe0000000000001 / 0x3fe0000000000000 |
-1022 / -1073 |
0x000fffffffffffff |
0x3fefffffffffffff / 0x3feffffffffffffe |
match |
0x0008000000000000 |
0x3fe8000000000000 / 0x3fe0000000000000 |
match |
(plus the negative inputs, same pattern). These rows translate as on main, so this is lavapipe's f64 frexp not 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 it false, 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 the floor/ceil/fract rows that lavapipe gets right. On this lavapipe only the frexp rows 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.
|
@jotitadev's review found only the Linux, lavapipe (Mesa 26.2.4, LLVM 23.1.1, Lavapipe hard-codes This is the gate @oneandonlydean suggested on #7042, applied per mode with the same + const bool canPreserveDenormals = device->Target().float64DenormPreserve;
for (const Mode& mode : modes) {
+ const bool keepsDenormals = !mode.value.has_value() || ((mode.value->floatMode >> 6u) & 1u) != 0u;
+ if (keepsDenormals && !canPreserveDenormals) {
+ std::cout << "skipped " << mode.name << ", the device does not report f64 DenormPreserve\n";
+ continue;
+ }
Run(*device, mode);
The failure in the second column is 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 Not tested: Windows, NVIDIA, or any AMD GPU. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine. |
v_floor_f64, v_ceil_f64, v_fract_f64, v_frexp_mant_f64 and v_frexp_exp_i32_f64 ignored the FLOAT_MODE f16/f64 denormal field. On RDNA2 (gfx1031) bit 6 clear flushes a denormal input to a zero of its sign, so v_ceil_f64 of 2^-1074 is 0 instead of 1, and bit 7 clear flushes the denormal result v_fract_f64 gives for a positive denormal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lavapipe reports no f64 DenormPreserve, so the shaders get no DenormPreserve 64 and it may flush f64 denormals; the rows of modes that keep them then fail with or without the recompiler change (frexp, floor, ceil and fract of 2^-1074 on Mesa 25 and 26). As in F64FmaSubnormals, a mismatch in those modes is reported as skipped on such a device. The modes that flush f64 denormals are still checked on every device. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5bc68b1 to
b55d411
Compare
|
Thanks for the lavapipe runs. b55d411 adds the gate, with the rule RX 6700 XT, Windows: the test passes with no skipped mode, and with |
jotitadev
left a comment
There was a problem hiding this comment.
A rerun of the gate in b55d41151 on 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 at 3221feb5a, which carries this PR's head b55d41151, merged onto main 5de7a46e0 (clean). ANYPS5_NO_SHADER_CACHE=1, -j1 --timeout 30.
| RTX 3070 | lavapipe | |
|---|---|---|
^agc_driver_f64 (11 tests) |
11/11, 3 runs | 11/11, 2 runs |
skipped lines in agc_driver_f64_rounding_denormal_modes |
none | 5: no known float mode and modes 1 and 3 (IEEE on/off), all on v_frexp_mant_f64 of 0x0000000000000001 |
same, with Float64Instructions.cpp, SubwordPacking.cpp and TranslationContext.hpp from main |
fails: v_ceil_f64 f64 denormal mode 0, IEEE mode on of 0x0000000000000001 is 0x3ff0000000000000, expected 0x0000000000000000 |
fails with the same message, after the same skip for no known float mode |
Both 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.
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(agc_* tests: 3 of 483 fail on AMD Radeon RX 6400, pass on NVIDIA RTX 4080 SUPER #5271) andagc_driver_layered_volume_vertex_no_gpl(AMD Windows: GPL-mode cache failures (alpha/wave32 pass after local driver update) #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