rdna2spirv: the binary64 roundings keep a NaN's bits and round a subnormal without the driver (SHADER-ROUND-F64-SPECIALS) #1047
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1047
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1047/head"
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?
@milk4sale on GitHub · 2026-11-24 17:18 UTC · original
milk4sale:shader/round-f64-specials→main· +724 −7 · 9 files · 8 commits · merged 2026-11-24 23:20 UTCClaimed in the coordination issue as: SHADER-ROUND-F64-SPECIALS (#14)
Depends on: #1034, which depends on #1012 (this branch is one commit on top of them; the last commit is the one to review. #1034 adds the fixture that found this and that this makes exact.)
What and why
v_trunc_f64,v_ceil_f64,v_rndne_f64andv_floor_f64bitcast their source pair to%doubleand call the driver's GLSL.std.450Trunc,Ceil,RoundEvenorFloor. For two kinds of source the driver's answer is not RDNA2's (the finding linked above, measured withcs_w32_round_f64):0x7ff0000000000001gave0x7ff8000000000001), on an RTX 4070 Ti (NVIDIA 620.70.06) and on llvmpipe. The hardware returns a NaN unchanged (row indocs/design.md, gfx1036, IEEE=0).DenormPreservefor 64 bits, so a driver may read one as zero, and llvmpipe did:v_ceil_f64of0x0000000000000001gave +0 andv_floor_f64of its negative -0, where the hardware gives 1 and -1. Declaring the mode is not a way out: neither device reportsshaderDenormPreserveFloat64, and adding it by hand changed nothing on either.The translator now selects those two sources with integer ops on the words, after the source modifiers and before the output ones:
v_ceil_f64of a positive one,v_floor_f64of a negative one);With that,
cs_w32_round_f64drops the two allowances #1034 gave it and compares all 1152 heap words exactly.tests/semantic/test_f64_round.pygetsF64RoundSpecialSources, which runs the four ops in the interpreter under a model of a driver that quiets a NaN and reads a subnormal as zero. The row indocs/design.mddescribes the rule and how it was confirmed, and no longer lists the approximation #1034 recorded.Tested
At this head, llvm-mc 23.1.4, SPIRV-Tools v2026.4:
python -I scripts/run_gpu_tests.py --build runtime/build --filter cs_w32_round_f64 --require-pass: PASS ("1152 words exact") on the RTX 4070 Ti natively and withLEONIDA_W64_EMULATE=1, and on llvmpipe. One commit below, compared exactly, 15 of the 512 results differ on the 4070 Ti and 20 on llvmpipe.--filter f64on the 4070 Ti: 7/7 (cs_div_fmas_f64,cs_div_fmas_f64_rt,cs_f64_add,cs_w32_cmp_f64,cs_w32_round_f64,ps_f64_mods,ps_f64_round). The module passesspirv-val.v_ceil_f64lifting the negative subnormal (word 34),v_floor_f64lifting the positive one (word 38), a subnormal's result losing its sign (word 40), a NaN's low word dropped (word 784),rndnelowered asfloor(x + 0.5)(word 20),truncorceillowered asFloor, thenegor theabssource modifier ignored (words 8 and 26), the two result words swapped (word 8), the fixture without itsv_cmpx(word 30). Two are not caught everywhere and are not counted: a subnormal left to the driver fails on llvmpipe and passes on the 4070 Ti, which keeps binary64 denormals, andRoundEvenreplaced by GLSLRoundpasses on both, since both send a tie to the even integer.python -m unittest discover -s tests/semantic -p test_f64_round.py: 10 tests. Withtools/rdna2spirv.pyput back to the commit below,F64RoundSpecialSourcesfails in 18 subtests (the signalling NaNs for all four ops,ceilandfloorof a subnormal) and the other tests pass.python -I scripts/run_semantic_tests.py tests/semantic -j 8: 470 files, 6,169 tests, 0 files failed._f64op), so no game shader's translation changes.tests/test_gpu_round_f64.py(14 tests),tests/test_shader_checks.py(87),tests/test_run_gpu_tests.py(64),tests/test_semantic_translator_use.py,tests/test_docs_design_rows.py,tests/test_docs_links.py,tests/test_docs_repo_paths.py,tests/test_text_write_line_endings.py: OK.python -m compileall -q make_game.py tools testsandscripts/check_no_game_data.pyon the changed files: OK.Not run: the whole GPU suite at this head (the change is confined to the four ops, and every fixture that uses a binary64 op was run); llvm-mc 19; Windows; AMD hardware. The hardware's words are the row's gfx1036 measurement, which this does not repeat: the 4070 Ti and llvmpipe runs show that the translated module now gives those words on two drivers that used to differ.
Merge of #1034's
60c2ed910(88785d0f3). The redlinux-gpu-toolshere was #1034's fixture on a runner without AVX-512, where llvmpipe computesTruncandRoundEvenof a double with its float code (48 of the 512 results; details in #1034). #1034 now lets llvmpipe, and only llvmpipe, return what that path gives forv_trunc_f64andv_rndne_f64. This branch merges that commit; the one conflict was inround_f64_problem, where the judge stays exact for every other word and device, a NaN and a subnormal included, and takes that one allowance. The translator change is as reviewed at26d010b41. On the merge: the fixture passes on llvmpipe (Mesa 26.2.6) natively and underGALLIUM_OVERRIDE_CPU_CAPS=avxandsse2, and on the RTX 4070 Ti natively and withLEONIDA_W64_EMULATE=1;tests/test_gpu_round_f64.py,tests/test_shader_checks.py,tests/test_run_gpu_tests.pyandtests/semantic/test_f64_round.pypass, also on the tree merged withmain4a50cafc7.GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 620.70.06, Linux (CachyOS, kernel 7.3.3); Mesa llvmpipe 26.2.6 (LLVM 23.1.4), same machine
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.🤖 Generated with Claude Code
6558d5318, with #1012 merged 7fb019f220@whoalin1 on GitHub · 2026-11-24 17:48 UTC · original
Independent hardware verification from a second Windows box (Ryzen 5 7600 RDNA2 iGPU, gfx1035, AMD proprietary driver 24.10.24, Vulkan 1.3.280, 128-byte push constants, LEONIDA_VK_VALIDATION=1, LEONIDA_PC_TAIL_UBO=1; plus NVIDIA RTX 4070 SUPER, driver 610.88):
run_gpu_tests.py --filter round_f64on the AMD iGPU against this PR's SPIR-V: PASS, 1152/1152 words exact (cs_w32_round_f64).origin/maintranslator output on the same AMD iGPU also passes bit-exact — AMD's driver already implements RDNA2 f64 rounding semantics (NaN passthrough, subnormals kept), so the deviation does not reproduce on AMD hardware.word 784 (thread 49): trunc of 0x7ff0000000000001 gave 0x7ff8000000000001, expected 0x7ff0000000000001(sNaN quieted). With this PR's fixed SPIR-V the same check passes on NVIDIA.python -m unittest discover -s tests/semantic -p test_f64_round.py: 10 tests OK (1 skip, optional spirv-tools absent).So the finding is a driver-conformance gap (NVIDIA quiets sNaNs; llvmpipe also flushes f64 subnormals), not an RDNA2 hardware bug, and this PR removes the driver dependence. AMD RDNA2 + NVIDIA both verified clean. AI-assisted verification.
@iFeyz on GitHub · 2026-11-24 19:40 UTC · original
AMD run (the "Windows; AMD hardware" gap): RX 9070 XT (RDNA4, GFX1201), AMD proprietary Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11,
scripts/run_gpu_tests.py --filter _f64with the test programs of a currentmainbuild.26d010b41: 7 of 7 pass, native and withLEONIDA_W64_EMULATE=1.cs_w32_round_f64: 1152 words exact.cs_w32_cmp_f64: 1536 words exact.tests/semantic/test_f64_round.py: 10 tests OK.355c8c9c2, no translator change) under this PR's strictround_f64_problem. It fails at word 784:truncof the signalling NaN0x7ff0000000000001gives0x7ff8000000000001, the same quieting you measured on NVIDIA. Native and wave64 alike. So without this PR the proprietary AMD driver does not give RDNA2's words for a signalling NaN either, and with it every word matches.@aslan2142 on GitHub · 2026-11-24 23:20 UTC · original
Merged, after #1012 and #1034. Checked locally on
main3a73ce11a+7fb019f22:SHADER-ROUND-F64-SPECIALSwas posted at 17:04 UTC, before this PR, and is unedited.neg/absand before the output modifiers. A subnormal goes to ±0 undertruncandrndne;ceilgives 1 for a positive one and −0 for a negative one;floorgives +0 and −1. That is IEEE 754. Passing a signalling NaN through unchanged follows the gfx1036 measurement in the row, as the PR says.tests/semantic/test_f64_round.py:F64RoundSpecialSourcesfails in 18 subtests onmain's translator and passes with this change.--filter f64: 7 of 7 on llvmpipe (Mesa 26.3.1) and on an RDNA2 iGPU (RADV). Without the change, llvmpipe failscs_w32_round_f64at word 34 (ceilof the smallest subnormal), while RADV already returns the hardware's words.test_gpu_round_f64,test_run_gpu_tests,test_shader_checkspass; the 13 docs and writer tests pass;check_no_game_data.pyis clean on the 8 changed files.AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).