You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implements RDNA2 -> SPIR-V lowering for v_fract_f64 (_e32 VOP1 and _e64 VOP3 forms), verified natively on RDNA2 (gfx1036, wave32 & wave64).
(Narrowed from the initial commit to v_fract_f64 only after spotting that open PR #2273 (SHADER-379) already covers v_ceil_f64/v_floor_f64/v_trunc_f64/v_rndne_f64; native gfx1036 hardware measurements for those 4 ops have been shared on #2273. #2619 adds standalone semantic tests for v_fract_f64 only.)
Added v_fract_f64 (_e32 / _e64) to the %double (OpCapability Float64 / shaderFloat64) lowering block via GLSL.std.450Fract, VOP3 abs/neg, SGPR/VGPR pairs, inline constants, f64_literal, and clamp_mods_f64 (mul:2/mul:4/div:2 then clamp to [0, 1]).
Added two explicit hardware-measured guards matching v_fract_f32:
OpFOrdEqual %bool <raw> 1.0 -> 0x3FEFFFFFFFFFFFFF (largest binary64 below 1.0, for tiny negative inputs where x - floor(x) rounds up to 1.0).
OpIsInf %bool <x> -> 0xFFF8000000000000 (canonical negative qNaN, for fract(±inf)).
Tightened the f64 pair destination check to reject non-pair VGPR operands (d["k"] != "vgpr" or d.get("n") != 2).
tools/shader_ir.py:
Added v_fract_f64 to the f64_literal op list so 32-bit hex literals (e.g. 0x3ff80000) populate bits 63:32 with low 32 bits zero.
tests/test_v_fract_f64.py:
Added SPIR-V lowering/dataflow tests (_e32 and _e64), v_fract_f64 boundary guards, input/output modifiers, SGPR pairs, inline constants, f64_literal, non-pair destination rejection, optional spirv-as/spirv-val checks, and formula checks against all 22 gfx1036-measured 64-bit edge words.
docs/design.md:
Added a v_fract_f64 contract-table row documenting the gfx1036 hardware measurements, omod vs denorm16_64 behavior, and unmodelled edge cases.
Native RDNA2 Hardware Measurements
Measured natively on AMD Radeon(TM) Graphics (gfx1036), Windows driver 32.0.21042.62, using tools/hw_oracle (wave32 and wave64 identical on every case; also verified valid on gfx1013 via AMD clang -mcpu=gfx1013):
Unit & regression tests run locally (no game files):
python -I tests/test_v_fract_f64.py -v — 4/4 OK (including 22/22 gfx1036 edge word checks)
python -I tests/test_docs_repo_paths.py, tests/test_docs_links.py, tests/test_shader_ir.py — all OK
python -m compileall -q make_game.py tools tests — OK
Note: spirv-as / spirv-val are not installed on this machine, so the optional spirv-val branch in test_v_fract_f64.py was skipped locally and will run in CI.
No game data: All inputs and test fixtures are hand-written synthetic values.
Independent Windows check of 85c28463: python -I tests/test_f64_rounding.py -v passed all 6 tests with SPIRV-Tools 2026.4 on PATH. This exercised the optional spirv-as and spirv-val --target-env vulkan1.2 checks that were skipped on the author's machine, as well as the measured-word interpreter cases. Synthetic inputs only. CPU/validator check, no new hardware measurements. AI-assisted testing and reporting.
Tested 85c28463 on CachyOS Linux, RTX 5070 Ti, NVIDIA 620.73.04. I packed all 76 gfx1036-measured ceil/floor/trunc/rndne inputs into a synthetic 1×1 fragment draw, then compared the 64-bit results written to the harness heap as integer words. All 76 matched bit for bit, including subnormals, signed zero, ties, infinities and NaNs. The module passed Vulkan 1.2 SPIR-V validation and all six CPU lowering tests passed, including the fract tests. AI-assisted, synthetic inputs only.
timelery
changed the title
rdna2spirv: lower v_{ceil,floor,trunc,rndne,fract}_f64 (gfx1036 measured)
rdna2spirv: lower v_fract_f64 (gfx1036 measured)
Nov 22, 2026
Tested d5762877 on Windows 11 (build 26200), Python 3.13, no game files, no GPU.
python -I tests/test_v_fract_f64.py: 4 tests OK (0.17 s).
Negative control: tools/rdna2spirv.py and tools/shader_ir.py restored from the parent of 85c28463 with the PR test unchanged — 1 failure plus 5 errors (AssertionError: None is not true, the lowering is absent); restoring the PR files gives 4/4.
Re-tested 15b7f871 (head moved since the earlier results) on Windows 11, Python 3.14, llvm-mc 23.1.6, CPU only: pass. pytest tests/test_v_fract_f64.py: 4 passed, 27 subtests passed; with only tools/rdna2spirv.py restored to main: 6 failed, 3 passed. Not run: GPU tests, full semantic suite. Tested with AI assistance (Claude); synthetic shaders only, no game data.
Tested 15b7f871 on NVIDIA GeForce RTX 4080 (Ada, subgroup 32..32), driver 617.14, Vulkan API 1.4.351, Windows 11 Pro 10.0.26200: pass.
tests/test_v_fract_f64.py: 4/4 OK (Python 3.12.10) — the SPIR-V lowering/dataflow checks, including the two hardware-measured guards (1.0 → 0x3FEFFFFFFFFFFFFF for tiny negatives, ±inf → 0xFFF8000000000000)
Semantic suite: 7322 OK, 1 expected failure
run_gpu_tests.py on real shaderFloat64 hardware: 153/199 passed, 0 failed, 46 skipped — the f64 fixtures cs_f64_add PASS and ps_f64_mods4096/4096 pixels exact on the RTX 4080, so the new f64 rounding/fract lowerings coexist with the existing f64 paths on NVIDIA (no new GPU fixture for the five ops themselves; the reference is the author's gfx1036 run).
AI-assisted (ZCode agent): builds and runs executed by a coding agent on this machine.
Tested 8c8f2e2 (a re-test at the new head) on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.
Full python -I scripts/run_gpu_tests.py (Linux build of this branch's runtime/, LEONIDA_VK_DEVICE per GPU): 196/210 passed, 14 skipped, 0 failed on both GPUs, with every test's result the same as at the merge base aa2988c.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements RDNA2 -> SPIR-V lowering for
v_fract_f64(_e32VOP1 and_e64VOP3 forms), verified natively on RDNA2 (gfx1036, wave32 & wave64).(Narrowed from the initial commit to
v_fract_f64only after spotting that open PR #2273 (SHADER-379) already coversv_ceil_f64/v_floor_f64/v_trunc_f64/v_rndne_f64; nativegfx1036hardware measurements for those 4 ops have been shared on #2273. #2619 adds standalone semantic tests forv_fract_f64only.)Claimed in #2716: #2716 (comment)
Changes
tools/rdna2spirv.py:v_fract_f64(_e32/_e64) to the%double(OpCapability Float64/shaderFloat64) lowering block viaGLSL.std.450Fract, VOP3abs/neg, SGPR/VGPR pairs, inline constants,f64_literal, andclamp_mods_f64(mul:2/mul:4/div:2thenclampto[0, 1]).v_fract_f32:OpFOrdEqual %bool <raw> 1.0->0x3FEFFFFFFFFFFFFF(largest binary64 below1.0, for tiny negative inputs wherex - floor(x)rounds up to1.0).OpIsInf %bool <x>->0xFFF8000000000000(canonical negative qNaN, forfract(±inf)).d["k"] != "vgpr" or d.get("n") != 2).tools/shader_ir.py:v_fract_f64to thef64_literalop list so 32-bit hex literals (e.g.0x3ff80000) populate bits63:32with low 32 bits zero.tests/test_v_fract_f64.py:_e32and_e64),v_fract_f64boundary guards, input/output modifiers, SGPR pairs, inline constants,f64_literal, non-pair destination rejection, optionalspirv-as/spirv-valchecks, and formula checks against all 22gfx1036-measured 64-bit edge words.docs/design.md:v_fract_f64contract-table row documenting thegfx1036hardware measurements,omodvsdenorm16_64behavior, and unmodelled edge cases.Native RDNA2 Hardware Measurements
Measured natively on AMD Radeon(TM) Graphics (
gfx1036), Windows driver32.0.21042.62, usingtools/hw_oracle(wave32 and wave64 identical on every case; also verified valid ongfx1013via AMDclang -mcpu=gfx1013):v_fract_f64:±0.0 -> +0.0,+sub_min -> +sub_min,+sub_max -> +sub_max,-sub_min/-sub_max/-norm_min/-1e-20 -> 0x3FEFFFFFFFFFFFFF,-1.0+ulp -> 0x3CA0000000000000, integers (±1.0,-2.0,±2^52,±2^53,±1e300)-> +0.0,±inf -> 0xFFF8000000000000, NaNs unchanged underIEEE=0.omod(mul:2/mul:4/div:2): applies underdenorm16_64=0, IEEE=0and is ignored on hardware underdenorm16_64=3, IEEE=0(same asv_add_f64/v_sqrt_f64).Testing & Disclosure
gfx1036), Windows driver32.0.21042.62(hardware oracle measurements).python -I tests/test_v_fract_f64.py -v— 4/4 OK (including 22/22gfx1036edge word checks)python -I tests/test_docs_repo_paths.py,tests/test_docs_links.py,tests/test_shader_ir.py— all OKpython -m compileall -q make_game.py tools tests— OKspirv-as/spirv-valare not installed on this machine, so the optionalspirv-valbranch intest_v_fract_f64.pywas skipped locally and will run in CI.