mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:55:52 +01:00
[PR #1047] [MERGED] rdna2spirv: the binary64 roundings keep a NaN's bits and round a subnormal without the driver (SHADER-ROUND-F64-SPECIALS) #1084
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1084
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1047
Author: @milk4sale
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142
Base:
main← Head:shader/round-f64-specials📝 Commits (8)
355c8c9tests: GPU readback for the binary64 roundings, v_trunc_f64, v_ceil_f64, v_rndne_f64 and v_floor_f64 (GPU-ROUND-F64)26d010brdna2spirv: the binary64 roundings keep a NaN's bits and round a subnormal without the driver (SHADER-ROUND-F64-SPECIALS)60c2ed9tests: cs_w32_round_f64 allows llvmpipe's float path for Trunc and RoundEven (GPU-ROUND-F64)88785d0Merge gpu-test/round-f64 into shader/round-f64-specials: the exact judge keeps llvmpipe's float-path allowancee040dceMerge main into gpu-test/round-f647998d65Merge main into shader/round-f64-specials69935f8Merge main into gpu-test/round-f647fb019fMerge gpu-test/round-f64 into shader/round-f64-specials: main6558d5318, with #1012 merged📊 Changes
9 files changed (+724 additions, -7 deletions)
View changed files
📝
docs/design.md(+1 -1)📝
docs/testing.md(+42 -0)📝
runtime/test/shaders/check.py(+138 -2)➕
runtime/test/shaders/cs_w32_round_f64.asm(+56 -0)📝
scripts/run_gpu_tests.py(+5 -0)📝
tests/semantic/test_f64_round.py(+109 -0)➕
tests/test_gpu_round_f64.py(+320 -0)📝
tests/test_shader_checks.py(+10 -2)📝
tools/rdna2spirv.py(+43 -2)📄 Description
Claimed in the coordination issue as: SHADER-ROUND-F64-SPECIALS (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7138652249)
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
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.