fix(shader): compute v_rcp_f64, v_rsq_f64 and v_sqrt_f64 of denormal operands on scaled values #27859
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27859"
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 GiannisG1 on 2026-11-27T15:47:33Z.
What
agc_driver_float64_transcendental_denormals(#22384) fails on Intel ANV (HD Graphics 630, Mesa 25.2.8):v_rsq_f64 of 0x0000000000000001 with FLOAT_MODE 0x70 is 0x63041cfe99c5bfa8, expected the RDNA 2 value 0x6180000000000000. That device reportsshaderDenormPreserveFloat64, so the test checks the denormal rows there. The GTX 1050 Ti and llvmpipe report it false and skip them.The translation computes the three instructions with the host's
SqrtandFDivon the operand as it is. Mesa lowers f64 sqrt, rsq and reciprocal insrc/compiler/nir/nir_lower_double_ops.c(lower_sqrt_rsqandlower_rcp; withnir_lower_ddiv,fdivbecomes a multiply byfrcp). Both build their first estimate from the exponent field as if the operand were normal. For a denormal, whose field is 0 and which has no implicit bit, that estimate is wrong. On top of that,fix_inv_resultflushes a reciprocal whose exponent comes out at or below zero, so a denormal result becomes ±0 even underDenormPreserve. On the HD 630 this gives 10 wrong rows (listed under Tested).EmitFPRcp64,EmitFPRsq64andEmitFPSqrt64now give the host only normal operands and results:FrexpFields) and scaled by 2^128. It reaches the emitter only when bit 0 of the field keeps it, because the translation flushes it otherwise. Sqrt scales the result back by 2^-64, rsq by 2^64 and rcp by 2^128, so the rcp overflows to ±inf where it should. Multiplying a normal value by a power of two is exact, so the result is the host's value for the operand with its exponent moved.v_rcp_f64of a finite operand with exponent field 0x7fd or above (|x| ≥ 2^1022, whose reciprocal is at most 2^-1022) divides x·2^-128 and multiplies the quotient by 2^-128, so a denormal result comes from a multiply. That rounds twice in the last place of a denormal result. JJenkx measured at most 1 ULP against exact-rational references, over 49,176 inputs from the normal-result cutoff up to the largest finite value; one example is0x7fd0005b5e3ca0de→0x000fffa4a3cd159c, where a single rounding gives0x000fffa4a3cd159b(review). RDNA2's own results are approximations (see the shader debt entry for these instructions), and the test allows 4 ulp.The test now checks kept denormal inputs on every device, because they no longer depend on the host's f64 denormal support. Devices without
shaderDenormPreserveFloat64still skip denormal results, which their drivers may flush.Tested
Linux Mint 22.3, kernel 7.0.0-38, GCC 13.3.0, Release,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=ON. Head onmain4cb7752e50; it merges cleanly withmain10c3156e1c, where none of the three files has changed.main's emitter: the HD 630 fails. A local copy of the test that prints every mismatch instead of stopping at the first shows these 10 rows. The GTX 1050 Ti and llvmpipe pass, with their 4 denormal results skipped:v_rsq_f640x00000000000000010x63041cfe99c5bfa80x6180000000000000v_rcp_f640x00080000000000000x7fdf9add3da12f660x7fe0000000000000v_rcp_f640x80080000000000000xffdf9add3da12f660xffe0000000000000v_rcp_f640x7fe00000000000000x00000000000000000x0008000000000000v_rcp_f640xffe00000000000000x80000000000000000x800800000000000083bf6c1eec): a second table of 16v_rcp_f64operands, from just below the 2^1022 threshold up to the largest finite values, both signs, in all four modes, checked against the exactly rounded reciprocal. Withmain's emitter the HD 630 returns ±0 for 20 of them: every operand above 2^1022, in the two modes that keep denormal results. With this PR all pass 3/3 on the four devices, with no VUIDs. The GTX 1050 Ti and llvmpipe skip the 24 denormal results.main8b40357971on the same machine (every test once on the GTX 1050 Ti, the 2089 GPU tests on all three devices). GTX: no failure. HD 630: 13. llvmpipe: 4. These are the failuresmain4cb7752e50has on this machine, minusfloat64_transcendental_denormalson the HD 630.check_conventions.py,check_test_registration.py,check_compile.py(2 translation units),check_main_sync.py(merges cleanly) and the source-scanning tests (162) are clean.tools/pr_overlap.py --branch: no conflict with the 7 pull requests it compared. It could not compare #19710 and #26100, which conflict withmain. Both changeSpirvAluEmitterFloat64.cpparound lines 344-535 and 1411, away from the three emitters (lines 1016-1060).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
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-27T16:04:42Z.
Review: COMMENTED
I checked the scaling formulas at
01532ad9cagainst exact-rational and 150-digit Decimal CPU references. The integer normalization was exact for 8,345 positive subnormals, including neighbors of every possible leading-one position, and preserved the sign in every negative counterpart. All 16,690 signed subnormal-input reciprocals matched the rounded reference. The largest observed differences were 0 ULP for sqrt and 1 ULP for rsq.Across 49,176 signed inputs around the normal-result cutoff and up to maximum finite, reciprocal differed by at most 1 ULP. One double-rounding example is
0x7fd0005b5e3ca0de→0x000fffa4a3cd159cafter scaling, versus0x000fffa4a3cd159bwith one exact-rational rounding. This checks the arithmetic independently of Vulkan and the guest hardware measurements.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T16:05:53Z.
Review: COMMENTED
Reviewed — comments
Nothing blocks this review; the points below are optional.
What I ran
Reviewed head
01532ad9cac36e1b8f595a61f0d3625ef8813b38usingrepo_read.py. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
huge(core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterFloat64.cpp:1039).Not verified
Build, tests, runtime behavior, and author-reported results were not independently verified. Read
description.md,commits.md,manifest.json,diff.patch,core/libs/prx/libSceAgcDriver/tests/execution/Float64TranscendentalDenormals.cpp, andcore/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterFloat64.cpp.files.jsonwas not available in the review bundle;list_filesshowed both changed files as included, with no excluded changed files.To get this to a good state
Nothing is required. The optional test suggestion above is the only review comment.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T00:38:32Z.
Review: APPROVED
Reviewed — looks good
The reviewed change is sound at head
83bf6c1eec1fcd0aabf1cf43b5e92b3c3a3aca19; I found no verified blocking defects.What I ran
Reviewed the source at the exact head above using
repo_read.py. No base merge preview or automated checks were run. The two changed files listed as reviewed were both read;files.jsonlists no excluded files.Results
Negative control
Not run; no tests were run during this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
No tests, builds, merged-preview checks, GPU runs, or validation-layer runs were performed during this review. The description reports those results, but they were not independently verified. No files were excluded from the review.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T09:28:28Z.
Review: COMMENTED
Paired Linux CTest runs of
agc_driver_float64_transcendental_denormalsandagc_driver_gcn_scalar_buffer_basepassed onb97867d3ce6band this patch. The patched fixture includes the added reciprocal assertions. It reported the same 28 device-dependent results skipped as main. Both Mesa lavapipe logs show Khronos validation 1.4.369 inserted and zeroVUID-errors.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T10:42:09Z.
Review: APPROVED
I read the diff at
83bf6c1eec. Windows 11, GCC 15.2, merged intomainatb97867d3ce6together with other open PRs (so not an isolated build), withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1andVK_LAYER_KHRONOS_validationon an RTX 5080 (621.24) and a Radeon iGPU (26.11.2).agc_driver_float64_transcendental_denormals: pass on both GPUs. The loader log shows the layer inserted and no "was not found" line, and neither run has aVUID-orSYNC-HAZARDline.main's): passes too, because neither of these GPUs shows the fault. So this shows the scaled values give the same results here, not that the fault is gone.Not checked: a GPU that shows it.
AI-assisted: yes (Claude Code)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.