Skip to content

rdna2spirv: lower v_fract_f64 (gfx1036 measured) - #2952

Open
TheAirborneCoder wants to merge 1 commit into
ItsNotRexed:mainfrom
TheAirborneCoder:shader-f64-round
Open

TheAirborneCoder wants to merge 1 commit into
ItsNotRexed:mainfrom
TheAirborneCoder:shader-f64-round

Conversation

@TheAirborneCoder

@TheAirborneCoder TheAirborneCoder commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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.)

Claimed in #2716: #2716 (comment)

Changes

  • tools/rdna2spirv.py:
    • Added v_fract_f64 (_e32 / _e64) to the %double (OpCapability Float64 / shaderFloat64) lowering block via GLSL.std.450 Fract, 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):

  • 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 under IEEE=0.
  • omod (mul:2/mul:4/div:2): applies under denorm16_64=0, IEEE=0 and is ignored on hardware under denorm16_64=3, IEEE=0 (same as v_add_f64/v_sqrt_f64).

Testing & Disclosure

  • AI-assisted: Yes (authored and verified with coding-agent assistance).
  • GPU / Driver: AMD Radeon(TM) Graphics (gfx1036), Windows driver 32.0.21042.62 (hardware oracle measurements).
  • 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.

@Doffi4

Doffi4 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

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.

@Marukooh

Copy link
Copy Markdown
Contributor

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.

@TheAirborneCoder TheAirborneCoder changed the title rdna2spirv: lower v_{ceil,floor,trunc,rndne,fract}_f64 (gfx1036 measured) rdna2spirv: lower v_fract_f64 (gfx1036 measured) Nov 22, 2026
@Koro4e

Koro4e commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

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.

AI-assisted.

@iurysf

iurysf commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

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.

@Yourrespawn

Copy link
Copy Markdown
Contributor

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_mods 4096/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.

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown

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.

No game files. AI-assisted.

@iurysf

iurysf commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 8c8f2e2 alone (it still conflicts with main, so I did not merge) with tools/f64_diff.py from #4536 plus extra references only on the local branch leonida/FUZZ-f64-ext, not published. --ops v_fract_f64 --programs 300 --seed 1: 111 match, 0 mismatch on the exact rules.

Judging the unmeasured rules, v_fract_f64 v[8:9], -0.0 mismatches on the CPU interpreter only (actual 00000000 80000000, expected +0). On an RTX 4070 the same program matches (+0). That is a CPU-interpreter artifact, not a PR bug. Results are for this head, not for a merge with current main. Nothing measured on AMD hardware by me.

AI-assisted (OpenBot team).

@bunbeans2-arch

Copy link
Copy Markdown

RDNA4 on AMD's Windows driver, for the gfx1036 words above: AMD Radeon RX 9070 XT (gfx1201), AMD 26.10.1 (32.0.32015.7029), head 8c8f2e21.

Native hardware. tools/hw_oracle kernels (IEEE is fixed on gfx12), 26 operands, all of the PR body's edge words included:

  • denorm16_64=3, no omod: 24/26 equal to the gfx1036 words. The two differences are signalling NaNs, which gfx1201 quiets (0x7ff4000000000000 -> 0x7ffc000000000000, 0xfff0000000000001 -> 0xfff8000000000001).
  • omod under denorm16_64=3 is not ignored on gfx1201. mul:2 gives fract(1.25) = 0.5 (0x3fe0000000000000) and fract(-1e-20) = 0x3fffffffffffffff, and flushes +sub_min/+sub_max to +0.

This head's translation on the same GPU and driver (wave32, vk_compute_test). spirv-val isn't installed here, so the module was assembled with this head's tools/spirv_asm.py and not validated.

  • Plain results: 26/26 equal to gfx1201's own words. The driver's Fract quiets sNaN the way the hardware does.
  • With mul:2: 24/26 equal. The two differences are +sub_min/+sub_max: translation 0x0000000000000002 / 0x001ffffffffffffe, hardware +0.

So the "omod is ignored under denorm16_64=3" behaviour in the contract row is gfx1036-specific. Not run: wave64, mul:4/div:2, clamp, 26.11.x drivers.

Synthetic operands only. AI-assisted (Claude Code). No game files.

@TheAirborneCoder

Copy link
Copy Markdown
Contributor Author

Rebased onto main 561b65a (now 576d5d9, mergeable). Conflicts were in docs/design.md, tools/rdna2spirv.py and tools/shader_ir.py; I kept main's f64 helpers (dst_f64 / f64_source_words) and added v_fract_f64 on top. Main still had no v_fract_f64 lowering.

Thanks @bunbeans2-arch for the gfx1201 words. I added a cross-check sentence to the contract row:

  • With denorm16_64=3 and no omod, 24 of 26 operands equal the gfx1036 words. The 2 exceptions are signalling NaNs, which gfx12 quiets.
  • omod is applied on gfx1201. Ignoring it under denorm16_64=3 is gfx1036-specific, and the row already lists that as not modelled. The lowering applies omod, as gfx1036 does under denorm16_64=0 and gfx1201 does here, so the rule doesn't change.

Tested 576d5d9 on Windows 11, CPU only, no GPU: compileall clean, tests/test_v_fract_f64.py 4/4. tests/semantic run per file: 433/433 files, 6,150 tests, 0 failures, the same as main. AI-assisted (Claude Code).

@TG0000

TG0000 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 576d5d9 on AMD Radeon RX 6800 (RDNA2 gfx1030, AMD 26.11.2, Windows 11): pass

Native 32-wide device, Vulkan 1.4.363, llvm-mc 23.1.5, SPIRV-Tools v2026.4, Python 3.12 (venv with tests/requirements.txt). GPU test programs built from this head with llvm-mingw clang 23.1.6 + Ninja (-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF; only the Vulkan test programs were needed). No game files.

  • python -I scripts/run_gpu_tests.py --llvm-mc <llvm-mc> --build runtime/build --filter f64: 3 translated, 3/3 pass spirv-val; 3/3 GPU PASS (cs_f64_add, ps_f64_mods 4096/4096 exact, ps_f64_round 4096/4096 exact).
  • ... --filter fract: 1/1 pass spirv-val; 1/1 GPU PASS (ps_fnan_fract 4096/4096 exact).
  • python -m pytest -q tests/test_v_fract_f64.py tests/test_shader_checks.py tests/test_docs_design_rows.py: 94 passed, 317 subtests passed (4.2 s).
  • Negative control: with tools/rdna2spirv.py and tools/shader_ir.py reset to the parent commit (main), tests/test_v_fract_f64.py gives 6 failed, 3 passed; with the PR's files, 4 passed, 27 subtests passed.

The PR adds no GPU fixture of its own, so the GPU side here is a no-regression check of the existing f64/fract fixtures on native wave32 hardware; the new opcode itself is covered by the CPU test above (its expected values were measured on gfx1036).

AI-assisted (Claude Code).

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.

9 participants