Skip to content

rdna2spirv: the f64 VALU ops keep only clamp, not their omod - #4371

Open
fiestorra wants to merge 1 commit into
ItsNotRexed:mainfrom
fiestorra:f64-omod-clamp-only
Open

fiestorra wants to merge 1 commit into
ItsNotRexed:mainfrom
fiestorra:f64-omod-clamp-only

Conversation

@fiestorra

Copy link
Copy Markdown

Coordinated as SHADER-721 in #4084.

What changes

docs/design.md said v_add_f64 scales its result by mul:2/mul:4/div:2 before clamping, and the rows for
v_rcp_f64, v_rsq_f64, v_sqrt_f64 and for the four f64 rounding ops repeated the same. On RDNA2 that omod does
nothing while f64 denormals are kept, which is the MODE this port assumes, so the translator was applying a modifier
the hardware drops. Both f64 call sites in tools/rdna2spirv.py now pass clamp_mods_f64 only the clamp they
actually apply; clamp is unchanged, and v_div_fixup_f64, v_div_fmas_f64 and v_frexp_mant_f64 are left as
they are (not measured here, and none of them occurs in the corpus).

How it was confirmed

tools/hw_oracle raw kernels, wave32 and wave64, on the Radeon iGPU (gfx1036) of a Ryzen 7 7800X3D, Windows driver
31.0.24002.92, code object v5, AMD clang 23 from rocm-sdk-core 10.0.0: 23 cases across the four MODE combinations
of IEEE × denorm_mode_16_64, covering v_add_f64, v_rcp_f64, v_rsq_f64, v_sqrt_f64, v_trunc_f64,
v_ceil_f64, v_floor_f64 and v_rndne_f64. Wave32 and wave64 agreed on every case.

  • denorm_mode_16_64 = 3 (denormals kept): no omod changed anything, with MODE.IEEE on or off.
  • denorm_mode_16_64 = 0 with IEEE on: still nothing.
  • denorm_mode_16_64 = 0 with IEEE off: the omod applied.
  • clamp applied in every run: 1.25 → 1.0, sqrt(2.00003) → 1.0, ceil(1.75) → 1.0, ceil(-1.75) → 0.0,
    floor(-0.25) → 0.0.
  • v_add_f64 2^-1074 + 0 mul:2 kept 0x0000000000000001 in the two denormals-kept MODEs. With denormals flushed
    the operand is already 0, so that case separates nothing; the normal sums are what show the second half.

@Vonsek measured the same split on a different gfx1036 in #3896 (1.5 + 1.5 mul:2 → 3.0, and 6.0 only with IEEE off
and denormals flushed) and left this op as a finding asking for exactly this fix. The rounding row here was already
measured by @timelery on gfx1036; this makes the translator agree with it instead of writing that it applies the omod.

Separately recorded and not fixed here: v_sqrt_f64 on this part is not the correctly rounded root —
sqrt(4.0) stored 0x4000000004000000 (2.0000000298), sqrt(9.0) 0x4008000004000000, sqrt(0.25)
0x3fe0000004000000 and sqrt(2.0) 0x3ff6a09e64000000 (1.4142135531 against 1.4142135624), each off by 2^26
ulps of its own result, so only about 26 of the 53 significand bits are right. Four samples only, and the exact
v_rcp_f64/v_rsq_f64 results prove nothing because those inputs are powers of two. No v_sqrt_f64 occurs in the
corpus, so it is written down as a finding rather than fixed.

Counted over the corpus

Counting every mnemonic that contains f64 in all 26 503 listings: 216 v_add_f64 in 5 shaders and 36
v_cvt_f32_f64 in 5, none with an omod and none with clamp, and no other f64 op appears at all. So this
changes no game shader's output; it is a contract fix, not a rendering fix.

Translating all 26 503 listings twice with the same flags (--wave64-emulate, 8 shards, --no-asm) — once with the
translator at main aa2988cc, once with this branch — gives 26 503 translated in both runs and 26 473 passing
spirv-val in both, with the same 30 rejected
(Operand 'NNN[%NNN]' requires a previous definition, all of them
compute shaders, none of the 30 containing any f64 instruction: they come from what main merged after my earlier
build, not from this change). Comparing the two output trees file by file, the 26 473 .spv are identical in size
and SHA-256. So this changes no game shader's output; it is a contract fix, not a rendering fix.

Tested

  • runtime/test/shaders/ps_f64_mods.asm, cs_f64_add.asm and ps_f64_round.asm: 3/3 pass on the RTX 4090
    (driver 32.0.16.2124) and on the gfx1036 iGPU (driver 31.0.24002.92)
    , with the words this rule predicts
    (ps_f64_mods 0x3ff40000, 0x3ff00000, 0x3ff00000, 0x3fd00000 — 1.25, 1.0, 1.0, 0.25). Their inputs are
    unchanged; only the expected words and their comments moved.
  • tests/semantic/test_valu_add_f64.py, tests/semantic/test_f64_round.py, tests/test_f64_output_modifiers.py,
    tests/test_f64_transcendentals.py: expectations flipped to clamp-only and passing.
  • python -m unittest discover -s tests/semantic: 7456 tests, 7 failures and 2 errors — the same count and the same
    tests main already has
    (test_mutations ×2 for the v_mul_legacy_f32 anchor, test_loop_ballot_barrier ×3
    failures + 2 errors, test_cmp_class_f64 ×2), skipped=1, expected failures=1. Nothing in an f64 module fails,
    and no new failure appears.
  • tests/semantic/regen_fixtures.py --check, scripts/check_no_game_data.py,
    python -m compileall -q make_game.py tools tests: clean.

Related, not dependencies

AI-assisted: an agent ran the measurements and wrote the change; the doc rows and test expectations follow from them.

RDNA2 ignores the VOP3 output modifier of the f64 VALU ops while f64
denormals are kept, which is the MODE this translator assumes. Measured with
tools/hw_oracle raw kernels on a gfx1036 iGPU (Radeon iGPU of a Ryzen
7 7800X3D, Windows driver 31.0.24002.92, code object v5), wave32 and wave64
identical, over the four combinations of MODE.IEEE and denorm_mode_16_64:
mul:2 / mul:4 / div:2 changed nothing for v_add_f64, v_rcp_f64, v_rsq_f64,
v_sqrt_f64, v_trunc_f64, v_ceil_f64, v_floor_f64 and v_rndne_f64 while
denormals were kept, applied only with MODE.IEEE off and denormals flushed,
and clamp applied in every run. Both f64 call sites now hand clamp_mods_f64
only the clamp they actually apply.

Coordinated as SHADER-721. The v_add_f64, v_rcp_f64/v_rsq_f64/v_sqrt_f64 and
f64 rounding rows of docs/design.md now carry the measured rule and how it was
confirmed, and the rows that said the translator applies the omod are corrected.
Counted over the whole corpus: 216 v_add_f64 in 5 of the 26 503 listings, none
of them with an omod or a clamp, and no f64 mnemonic in the corpus carries one,
so no game shader changes.

Expectations flipped in tests/semantic/test_valu_add_f64.py,
tests/semantic/test_f64_round.py, tests/test_f64_output_modifiers.py and
tests/test_f64_transcendentals.py, and in the GPU fixtures
runtime/test/shaders/ps_f64_mods.asm and cs_f64_add.asm with their runners.
ps_f64_mods, cs_f64_add and ps_f64_round pass on an NVIDIA RTX 4090 (driver
32.0.16.2124) and on that gfx1036 iGPU.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at f2d33415 on Windows 11:

  • tests/semantic/test_valu_add_f64.py -> 8 tests, OK.
  • tests/semantic/test_f64_round.py -> 2 tests, OK.
  • tests/test_f64_output_modifiers.py -> 2 tests, OK.
  • tests/test_f64_transcendentals.py -> 2 tests, OK.
  • git diff --check clean.

The change records that the f64 VALU ops keep clamp but not their omod, and updates the CPU/GPU fixtures accordingly; all affected tests pass. I cannot reproduce the hardware measurement here. No blocking issue.

@MKmajster

MKmajster commented Nov 23, 2026 •

Copy link
Copy Markdown

Tested f2d3341 on NVIDIA GeForce RTX 3070 (Ampere, shaderFloat64), driver 617.42, Windows 11 24H2: pass, and the updated fixtures do separate the two behaviours on this driver.

run_gpu_tests.py --filter f64:

cs_f64_add ps_f64_mods ps_f64_round
this branch (its fixtures and translator) PASS 0x0 0x3ff40000 PASS 4096/4096 PASS 4096/4096
main aa2988c (its own fixtures) PASS 0x0 0x40040000 PASS PASS
this branch's fixtures + main's rdna2spirv.py FAIL 0x40040000 FAIL 4096/4096, e.g. got 0x40040000 0x3ff00000 0x3fe40000 0x3ff00000, want 0x3ff40000 0x3ff00000 0x3ff00000 0x3fd00000 PASS

So the omod-dropping result (1.25 instead of 2.5 for the mul:2 add, and so on) comes out of the translated SPIR-V on NVIDIA too. The old translation fails the new fixtures there, rather than both readings happening to agree. ps_f64_round passes either way, as expected: it uses no mul:/div: omod, so it can't tell the two apart.

No game files. AI-assisted (Claude).

@2-CD

2-CD commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Windows + GPU check: NVIDIA GeForce RTX 5080 (driver 621.01) + AMD Radeon 610M iGPU (driver 32.0.13018.6, RDNA2-class), Windows 11, MSVC (VS BuildTools 18) + Ninja, RelWithDebInfo, llvm-mc 21.1.8 (gfx1013), spirv-as/spirv-val. Tested head f2d33415 (base 03b09a08). This head also carries #4362's large-module-gate / preflight removals.

Build: clean, 20 targets.

GPU shader fixtures (scripts/run_gpu_tests.py --filter f64, assemble with llvm-mc 21.1.8 -> translate -> spirv-val -> GPU):

  • NVIDIA RTX 5080: 3/3 PASS - cs_f64_add (0x0 0x3ff40000), ps_f64_mods (4096/4096 pixels exact), ps_f64_round (4096/4096 exact).
  • AMD Radeon 610M iGPU (LEONIDA_VK_DEVICE=Radeon): 3/3 PASS, identical readbacks. The iGPU is RDNA2-class, so this exercises the f64 VALU omod/clamp change on the same ISA family the translator targets.

Python:

  • tests/test_f64_output_modifiers.py, tests/test_f64_transcendentals.py: 5 tests OK.
  • tests/semantic/test_f64_round.py (6 OK, 1 skip) and tests/semantic/test_valu_add_f64.py (8 OK).

Full suite (ctest -C RelWithDebInfo -j 6, excluding the 4 window-showing tests dxgi_swapchain|d3d12_present|vk_presenter_sync|xbox_present):

  • NVIDIA RTX 5080: 149/149 passed, 0 failed.
  • AMD Radeon 610M iGPU: 149/149 passed, 0 failed.

The PR's unstable CI state did not reproduce locally.

Synthetic fixtures only, no game files. AI-assisted (opencode); runs on my machine.

@Flyander Flyander left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The translator now preserves only the measured clamp behavior for the covered f64 VALU and rounding operations, while leaving unmeasured f64 ops untouched. The updated semantic and GPU fixtures exercise the changed output, and the reported hardware runs agree across wave sizes and vendor backends.

@theswiss24

Copy link
Copy Markdown

Tested f2d33415 merged onto main 03b09a08 (clean) on two NVIDIA GPUs, test programs built from main 03b09a08: pass on both.

GPU driver, OS llvm-mc run_gpu_tests.py
RTX 4070 (Ada) 621.24, Windows 11 21.1.8 195/210 passed, 15 skipped, 0 failed
RTX 2060 SUPER (Turing) 580.178.04, Ubuntu 24.04 20.1.2 195/210 passed, 15 skipped, 0 failed

Every test has the same result as on main on both cards, including the two changed fixtures:

PASS  cs_f64_add            0x0 0x3ff40000
PASS  cs_f64_add            0x0 0x40040000
PASS  ps_f64_mods           4096/4096 pixels exact

LEONIDA_W64_EMULATE=1 on both. I did not run the PR's tests/semantic changes separately. No game files.

Tested and written by Claude (Claude Code), posting from @theswiss24's account.

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown

Tested f2d3341 on AMD Radeon RX 9070 XT (RADV GFX1201) 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