Skip to content

rdna2spirv: add binary64 round-to-integral VALU ops (SHADER-379) - #2273

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
yoraudev:shader-f64-round-to-integral
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
yoraudev:shader-f64-round-to-integral

Conversation

@yoraudev

@yoraudev yoraudev commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as SHADER-379 (#2078; original claim).

What and why

Translate v_trunc_f64, v_ceil_f64, v_rndne_f64 and v_floor_f64 directly in binary64. The lowering preserves both destination words under EXEC, assembles register pairs low-word first, distinguishes a separate hex literal dword from inline constants, and uses the existing f64 result-modifier path for VOP3. This is an ISA coverage change, not a claim that the known retail corpus needed these instructions to translate. It does not change the existing v_add_f64 / v_cvt_f32_f64 paths in #2057.

Tested

  • LLVM MC 21.1.8 accepted the hand-written VOP1 fixture and representative VOP3 modifier cases on both gfx1013 and gfx1030.

  • The semantic fixture is rejected by baseline 4eb6155d and translates, executes with the expected words, and passes spirv-val (Vulkan 1.2) on this branch. The focused suite covers ties, values that distinguish f64 from f32, a high-word literal, operand modifiers, and inactive lanes.

  • Translated SPIR-V on Windows, Radeon RX 580 (driver 31.0.21925.1001): 24,576/24,576 pixels exact across six synthetic draws. The stock harness requires 144 push-constant bytes; the local test runner used a 128-byte range after checking that all actual accesses were inside the first 128 bytes. No repository harness changes. This is a Vulkan output check, not a native RDNA2 hardware measurement.

  • Public RDNA2 XML: exact matches 484 → 488, unknown instructions 238 → 234. The full semantic suite passed (1,677 tests). Retail gfx1013 slice: 200/200 translated and 200/200 spirv-val-valid both before and after. A scan over all 26,503 local retail listings found zero occurrences of these four instructions. The full before/after assembly and validation is running locally; only aggregate results will be reported.

  • Rebased onto main ec8ec4c9 as 9205c009 after the f64 work landed there: main's v_rcp_f64/v_rsq_f64/v_sqrt_f64 design row and code paths are kept, this PR's rows and branch sit next to them, and shader_ir.py now uses main's generalized f64_literal marking with this PR's four op prefixes added. After the rebase: compileall clean, tests/semantic 4,143 tests OK, tests/test_f64_conversion.py / test_f64_output_modifiers.py / test_f64_transcendentals.py OK. The translator changes are unchanged from the reviewed ab285087 modulo placement.

  • Native RDNA2 hardware confirmation by @timelery on gfx1036 (Windows driver 32.0.21042.62, tools/hw_oracle, wave32 and wave64 identical): all four ops round exactly per IEEE-754 keeping signed zeros and binary64 subnormals, NaNs pass through under IEEE=0, the hex literal dword lands in bits 63:32, and omod is applied under denorm16_64=0 / ignored under denorm16_64=3 as for v_add_f64/v_sqrt_f64. Recorded in the design.md row in 9fb6c6f2.

  • Independent post-rebase runs: @bielfreedom (RX 9070 XT, RDNA4, Windows, validation on) — semantic suite 4,143 OK, GPU suite 0 failures, ctest 119/119.

  • Independent Vulkan verification by @tylerstraub on Linux / RTX 5090, driver 595.99.02: 8,192/8,192 pixels exact with the stock harness, including nonzero low words that distinguish f64 from f32. See the PR discussion.

Checklist

  • No game data, keys or decryption in the patch or report.
  • Added the translator contract to docs/design.md with AMD ISA and LLVM evidence.

AI-assisted (Codex).

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested ab285087ce614d8c83a5ef642c95586267efa51e on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

Independent Vulkan check of ab285087ce614d8c83a5ef642c95586267efa51e on NVIDIA GeForce RTX 5090 (595.99.02, Linux 7.0.0-43-generic, LLVM 21.1.8, SPIRV-Tools v2026.1). AI-assisted. Synthetic input only.

I used the stock Vulkan harness to read one 64×64 target per draw. In operation order trunc, ceil, floor, rndne:

  • The high-word draw derived from the checked-in fixture matched bff00000 c0000000 c0000000 c0000000, covering a register pair, an SGPR pair, the separate literal, and a negative nearest-even tie.
  • The low-word draw on the binary64 input 4294967297.75 matched 00100000 00200000 00100000 00200000. This covers nonzero low words that would be lost if the input were narrowed to f32.

Both draws matched all 4,096 pixels each, and all three shader modules passed SPIR-V validation. All six targeted CPU semantic tests passed.

AI-assisted verification.

@yoraudev

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (ec8ec4c9) as 9205c009; the conflict was with the f64 work that landed meanwhile:

  • docs/design.md: main's new v_rcp_f64/v_rsq_f64/v_sqrt_f64 row and this PR's v_trunc/ceil/rndne/floor_f64 row are both kept, in that order.
  • tools/shader_ir.py: adopted main's generalized f64_literal marking (any source, hex spelling or out-of-inline-range decimal) and added this PR's four op prefixes to its tuple; the PR's narrower one-source special case is dropped in favour of it. Hex-literal-as-high-word and sign-extended inline behavior is unchanged for the round ops.
  • tools/rdna2spirv.py: this PR's v_trunc_f64/v_ceil_f64/v_rndne_f64/v_floor_f64 branch is unchanged; the following elif now carries main's extended tuple (v_rcp_f64, v_rsq_f64, v_sqrt_f64). The v_add_f64/v_cvt_f32_f64 paths are untouched.

Verified after the rebase: python -m compileall -q make_game.py tools tests clean; python -m unittest discover -s tests/semantic — 4,143 tests, OK (includes test_f64_round.py); python -I tests/test_f64_conversion.py, test_f64_output_modifiers.py and test_f64_transcendentals.py all OK, so main's f64 paths are unchanged by the shader_ir.py merge. CPU-only; no GPU re-run (the commit's translator changes are identical to the reviewed ab285087 modulo placement, and the Vulkan output was verified independently on RTX 5090/580 before the rebase).

AI-assisted.

@bielfreedom

Copy link
Copy Markdown

Tested 9205c009 (on its base ec8ec4c9) on AMD Radeon RX 9070 XT (RDNA4), AMD driver 32.0.32029.2010 (subgroup 32..64), Windows 11 Pro build 26200, with Vulkan validation on (LEONIDA_VK_VALIDATION=1, Vulkan SDK 1.4.363): pass, no regression. First AMD run here.

  • tests/semantic/test_f64_round.py: OK. python -m unittest discover -s tests/semantic: 4143 tests OK.
  • scripts/run_gpu_tests.py: 194 shaders, 194 translated, 194 pass spirv-val; 175/189 passed, 14 skipped, 0 failures. The skips are the shaders run by the d3d12 tests and ps_w64x_readlane.
  • Full ctest: 119/119 pass, 0 validation errors.

ps_f64_round.asm is a CPU (interpreter) fixture under tests/semantic/fixtures, not a GPU test, so the new v_rndne/trunc/floor/ceil_f64 paths were not run on hardware here. This run shows they break nothing else.

AI-assisted (Claude Code). No game files.

@yoraudev
yoraudev force-pushed the shader-f64-round-to-integral branch from 9205c00 to c002e63 Compare November 22, 2026 18:51
@yoraudev

Copy link
Copy Markdown
Contributor Author

Rebased onto main 89c2d9ac as c002e634. Only docs/design.md conflicted this time: main had meanwhile rewritten the "Floating-point class compare" row with the v_cmp_class_f32 hardware measurements, and this PR's insertion point sat right before it. Resolution keeps both: this PR's v_trunc/ceil/rndne/floor_f64 row, then main's updated class-compare row (the old short version is dropped). tools/rdna2spirv.py and tools/shader_ir.py auto-merged; the translator changes are byte-identical to the full-suite-validated 9205c009 (re-checked after the rebase: compileall clean, tests/test_f64_conversion.py, test_f64_output_modifiers.py and test_f64_transcendentals.py all OK).

AI-assisted.

TheAirborneCoder added a commit to TheAirborneCoder/Leonida that referenced this pull request Nov 22, 2026
@TheAirborneCoder

Copy link
Copy Markdown
Contributor

Native RDNA2 hardware confirmation for these 4 instructions (measured on AMD Radeon(TM) Graphics (gfx1036), Windows driver 32.0.21042.62, tools/hw_oracle, wave32 and wave64 identical on every case):

  • v_ceil_f64, v_floor_f64, v_trunc_f64, v_rndne_f64: exact IEEE-754 rounding preserving signed zeros and binary64 subnormals (ceil(+sub_min) = +1.0, ceil(-sub_min) = -0.0, floor(+sub_min) = +0.0, floor(-sub_min) = -1.0, trunc(±sub) = ±0.0, rndne(±0.5) = ±0.0, rndne(±1.5) = ±2.0, rndne(±2.5) = ±2.0, ±inf -> ±inf, ±qNaN/±sNaN pass unchanged under IEEE=0).
  • 32-bit hex literal (f64_literal): v_floor_f64 v[4:5], 0x3ff80000 -> 0x3ff0000000000000 (floor(1.5) = 1.0), confirming the 32-bit literal populates bits 63:32 with low 32 bits zero.
  • VOP3 omod (mul:2/mul:4/div:2): applies on all 4 ops under denorm16_64=0, IEEE=0 and is ignored on hardware under denorm16_64=3, IEEE=0 (matching v_add_f64/v_sqrt_f64).

(I narrowed #2952 to v_fract_f64 only so there is no overlap with this PR. AI-assisted, no game data.)

@yoraudev

Copy link
Copy Markdown
Contributor Author

Thanks @timelery — that is exactly the measurement the row was missing. Recorded in 9fb6c6f2: the design.md row now replaces "Native GPU handling of special values and denormal modes is not measured here" with your results (exact IEEE-754 rounding keeping signed zeros and binary64 subnormals, ±NaN passthrough under IEEE=0, the hex literal dword in bits 63:32, and omod applied under denorm16_64=0 / ignored under denorm16_64=3 as for v_add_f64/v_sqrt_f64), with you credited. Docs checkers (test_docs_links.py, test_docs_repo_paths.py, test_docs_list_items.py) pass; no code change.

Also noted the #2952 narrowing to v_fract_f64 — no overlap with this PR.

AI-assisted.

yoraudev and others added 2 commits November 22, 2026 23:03
@timelery measured v_trunc/ceil/rndne/floor_f64 natively on gfx1036
(tools/hw_oracle, wave32 and wave64 identical): exact IEEE-754 rounding
that keeps signed zeros and binary64 subnormals, NaNs unchanged under
IEEE=0, the hex literal dword in bits 63:32, and omod ignored under
denorm16_64=3 as for v_add_f64/v_sqrt_f64. The row said 'not measured
here'.
@yoraudev
yoraudev force-pushed the shader-f64-round-to-integral branch from 9fb6c6f to 52384f9 Compare November 22, 2026 20:07
@yoraudev

Copy link
Copy Markdown
Contributor Author

Rebased onto main f847748c (64f17899 + 52384f93). Only docs/design.md conflicted, and this time the conflict exposed broken text on main itself: the "Floating-point class compare" row at f847748c is a mangled merge — the old row's tail (cs_cmpx_class_f32 checks both encodings ... RTX 4070 SUPER (driver 616.92)) is spliced into the middle of the hardware-measured row, and the |v|/-|v| modifier forms are misplaced (1942 characters vs the clean row's 1735). Looks like another casualty of the round-40 merges.

The rebase resolves to the clean, fully-measured row (the text this branch already carried from the earlier rebase), so this PR's diff now also restores that one row on main. Found a finding in the coordination issue for the case where this PR does not merge first. tools/ auto-merged; verified after the rebase: compileall clean, tests/test_f64_conversion.py, test_f64_output_modifiers.py, test_f64_transcendentals.py, test_docs_links.py, test_docs_repo_paths.py and test_docs_list_items.py all OK. The translator changes are unchanged from the full-suite-validated 9205c009/c002e634 line.

AI-assisted.

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 52384f93 on AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), AMD 26.11.2, Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM), Python 3.12.10: pass.

Runtime and test programs built from this head (MSVC 14.51, Ninja, RelWithDebInfo), native Windows llvm-mc 21.1.8, Vulkan SDK 1.4.363.0. No game files.

run result
run_gpu_tests.py (whole suite, native wave64) 185/199, 14 skipped, 0 failed (main 49475796: 170/185)
same with LEONIDA_W64_EMULATE=1 185/199, 14 skipped, 0 failed
pytest tests/test_translate.py 562 passed, 4 skipped in 65.50s (0:01:05)
unittest discover -s tests/semantic -p test_f64_round.py 6 OK
tests/semantic/regen_fixtures.py --check clean

ps_f64_round is a semantic fixture and not part of the GPU suite, so the GPU rows show no regression; they don't show the f64 rounding ops on RDNA4. The suite count is higher than main's because this head includes a newer main.

AI-assisted (Claude Code); I checked the results.

@ItsNotRexed
ItsNotRexed merged commit 242d355 into ItsNotRexed:main Nov 22, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants