Skip to content

rdna2spirv: lower v_fract_f64 (gfx1036 measured) - #2952

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

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

Conversation

@timelery

@timelery timelery 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.

@timelery 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
@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.

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.

7 participants