Shader fract f64 #1477

Open
github-bot wants to merge 2 commits from github-bot/gh-1477 into main AGit
Owner

@⁠vsking2000 on GitHub · 2026-11-25 01:12 UTC · original
vsking2000:shader-fract-f64 → main · +407 −4 · 6 files · 2 commits · open

Claimed in the coordination issue as:

Depends on:

Fixes:

What and why

Tested

GPUs tested:

AI-assisted:

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
**@⁠vsking2000** on GitHub · 2026-11-25 01:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1477) `vsking2000:shader-fract-f64` → `main` · +407 −4 · 6 files · 2 commits · open Claimed in the coordination issue as: <!-- the item ID from the open "Coordinating who works on what" issue, for example TEST-17, or a link to your claim --> Depends on: <!-- #N for every pull request this one builds on or conflicts with (the coordination issue's Commands section, AGENTS.md); delete the line if it builds on none and conflicts with none --> Fixes: <!-- #N for each issue this closes (GitHub closes it on merge); delete the line if it closes none --> ### What and why <!-- What this changes and the problem it solves. --> ### Tested <!-- What you ran and on which GPU and driver (CONTRIBUTING.md). For the shader translator: how many shaders translate and pass spirv-val, before and after. --> GPUs tested: <!-- vendor, model, driver and OS of each GPU the GPU tests ran on, or n/a --> AI-assisted: <!-- yes or no (AGENTS.md asks a coding agent to say so) --> ### Checklist - [ ] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [ ] One topic; follow-up work goes in a new pull request. - [ ] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
v_fract_f64 was refused by name. It is now D = S0 - floor(S0) as OpFSub of the
source and GLSL.std.450 Floor on the double, with the edges of v_fract_f32 and
v_fract_f16 selected from the operand's words so the driver does not decide them:

- a result that rounds to 1.0 (a tiny negative source) is 0x3fefffffffffffff;
- -0, an exact integer and |x| >= 2^52 give +0;
- a positive subnormal is itself, a negative one gives 0x3fefffffffffffff;
- +-inf gives the negative quiet NaN 0xfff8000000000000, a NaN is unchanged.

Source modifiers, literals, inline constants and SGPR pairs go through
f64_source_words as for v_add_f64. mul:2/mul:4/div:2 are ignored (a binary64
result under denorm_mode_16_64 = 3) and clamp is applied through
clamp_mods_f64. None of the edges is measured on hardware for binary64;
docs/design.md has the contract row with what each part rests on.

tools/shader_ir.py flags its literal as an f64 one, tools/f64_diff.py no longer
lists it as not translated, and tests/semantic/test_fract_f64.py checks the
words through the translator (also under a driver model that quiets a NaN, reads
a subnormal as zero and makes the positive NaN of inf - inf).

AI-assisted.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y7fbZYVY7EtLknWBZUfSLf
docs/design.md: LLVM's constant fold of llvm.amdgcn.fract (ConstantFolding.cpp;
test InstSimplify/ConstProp/AMDGPU/fract.ll) is added as a source: its finite,
cap, signed-zero and subnormal words match bit for bit; its +-inf and NaN
results (+qnan, a quieted sNaN) differ because it is a generic compile-time
APFloat model, and the row follows the measured f32/f16 words. LLVM's
min(V_FRACT, 0x3fefffffffffffff) workaround is GFX6 (SI) only and no evidence
about gfx10. The row says which ISA text was read (RDNA3, RDNA4, CDNA3,
identical for this op), that the RDNA2 document was not, and that the text has
no cap, inf or NaN rule.

tools/rdna2spirv.py: v_fract_f64 is refused in a program that writes
MODE.FP_ROUND (the result for a negative non-integer is rounded and whether the
instruction follows the mode is not measured; only v_add_f64 models it), as the
f64 mul/fma refusal does. A zero source of either sign is selected from the
operand's words, so the result no longer depends on the driver's Floor(-0.0).

tests/semantic/test_fract_f64.py (23 tests, was 20): the eight finite f64 words
of LLVM's fract.ll as literals; the MODE.FP_ROUND refusal and the same program
without the write; both zeros under a driver whose Floor(-0.0) is +0; a comment
on which tests would pass without the infinity select because of the
interpreter's inf - inf NaN and which one does not.

AI-assisted.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y7fbZYVY7EtLknWBZUfSLf
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:53:22 +00:00
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-25 01:45 UTC · original

I tested translated v_fract_f64 at 3c359c50 on an RTX 4090 (Windows 11, NVIDIA 616.64). All 81,910 checked GPU outputs matched the PR's specified result bit for bit.

I used 20,480 distinct binary64 inputs loaded from a buffer at dispatch: both signs, all 2,048 exponent fields, and five fraction fields per exponent (zero, one, the high fraction bit, all ones, and a varying pattern). For finite values I computed the fractional part with exact rational arithmetic, rounded to binary64, then applied the specified cap below 1. Special values were compared as raw words.

Hand-written compute shader Exact matches
Plain v_fract_f64 20,480 / 20,480
Negated absolute source 20,480 / 20,480
mul:4 output modifier 20,480 / 20,480
clamp, finite inputs 20,470 / 20,470

The plain instruction returned positive zero for negative zero, preserved the sign and payload of the sampled signalling NaNs, returned 0xfff8000000000000 for both infinities, and mapped the smallest negative subnormal to 0x3fefffffffffffff. I excluded the ten nonfinite inputs from the clamp comparison because that result is outside this PR's contract.

The branch point 364ab4ea refused all four shader variants at v_fract_f64. At the head, all four passed Vulkan 1.2 SPIR-V validation and ran with vk_compute_test built from the head. Separately, test_fract_f64 and test_f64_literal_whole passed 28/28 on CPU, with no skips. This verifies the translated Vulkan behavior on NVIDIA. Native RDNA2 fractional-part edge semantics remain unmeasured here. AI-assisted verification.

**@⁠ecox982745** on GitHub · 2026-11-25 01:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1477#issuecomment-7149920406) I tested translated `v_fract_f64` at `3c359c50` on an RTX 4090 (Windows 11, NVIDIA 616.64). All **81,910 checked GPU outputs** matched the PR's specified result bit for bit. I used 20,480 distinct binary64 inputs loaded from a buffer at dispatch: both signs, all 2,048 exponent fields, and five fraction fields per exponent (zero, one, the high fraction bit, all ones, and a varying pattern). For finite values I computed the fractional part with exact rational arithmetic, rounded to binary64, then applied the specified cap below 1. Special values were compared as raw words. | Hand-written compute shader | Exact matches | | --- | ---: | | Plain `v_fract_f64` | 20,480 / 20,480 | | Negated absolute source | 20,480 / 20,480 | | `mul:4` output modifier | 20,480 / 20,480 | | `clamp`, finite inputs | 20,470 / 20,470 | The plain instruction returned positive zero for negative zero, preserved the sign and payload of the sampled signalling NaNs, returned `0xfff8000000000000` for both infinities, and mapped the smallest negative subnormal to `0x3fefffffffffffff`. I excluded the ten nonfinite inputs from the clamp comparison because that result is outside this PR's contract. The branch point `364ab4ea` refused all four shader variants at `v_fract_f64`. At the head, all four passed Vulkan 1.2 SPIR-V validation and ran with `vk_compute_test` built from the head. Separately, `test_fract_f64` and `test_f64_literal_whole` passed 28/28 on CPU, with no skips. This verifies the translated Vulkan behavior on NVIDIA. Native RDNA2 fractional-part edge semantics remain unmeasured here. AI-assisted verification.
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 06:13 UTC · original · approved these changes

Approving. Merged into current main with no conflicts; the PR's tests pass and the full translator suite gives 488 files / 6,302 tests with only test_int32_to_f64 failing, the same baseline failure as main here (Linux, Python 3.13). I read the diff: the new lowering and its refusals match the ISA behaviour, and the tests cover both the folded and refused shapes.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-25 06:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1477#pullrequestreview-6052691308) · **approved these changes** Approving. Merged into current main with no conflicts; the PR's tests pass and the full translator suite gives 488 files / 6,302 tests with only `test_int32_to_f64` failing, the same baseline failure as main here (Linux, Python 3.13). I read the diff: the new lowering and its refusals match the ISA behaviour, and the tests cover both the folded and refused shapes. AI-assisted (Claude).
Author
Owner

@⁠qhukz13 on GitHub · 2026-11-26 01:19 UTC · original

I checked 3c359c50 on Linux (Python 3.14), CPU only. I did not use a GPU.

Merge state. The branch merges into main (88479ff6) without conflicts. It conflicts with #1374 in two lines:

  • the parse_line f64 list in tools/shader_ir.py;
  • the --list-ops "Excluded" line in tools/f64_diff.py.

Whichever lands second has to take the other's opcodes out of that line. v_ldexp_f64 is still listed there as
excluded, but main translates it.

Tests. On the merge, test_fract_f64 passes, 23 tests with 1 skipped. test_f64_literal_whole and the old
test_valu_fract_f64 oracle also pass. The full translator suite on the merge gives
496 files, 6,356 tests, 0 files failed.

Edge cases. I translated hand-written listings and ran them through spirv_interp. They give the words in the row:

Case Result
-1e-300 and the negative subnormal 0x8000000000000001 0x3fefffffffffffff
-2.25 0.75
2^53 + 2 +0
-|0.25| in the e64 form 0.75
mul:2 ignored

The selects build every edge from the operand's words, so none of it depends on how a driver handles Floor(-0.0)
or binary64 subnormals. That is the right call.

One gap, shared with #1374. v_fract_f64_e64 v[4:5], inf clamp returns 0xfff8000000000000:

  • the select gives the NaN of fract(±inf);
  • clamp_mods_f64 then applies a bare FClamp to it, which GLSL.std.450 leaves undefined;
  • the hardware gives +0 with DX10_CLAMP set, the game's MODE.

A NaN passed with clamp takes the same path. The f32 and f16 clamps select +0 for a NaN since 2026-11-24 ("Float
min/max/med3 with NaN"), and that row already lists the f64 clamp as still bare. Since this op picks its own words for
every other edge, selecting +0 before the clamp here, or fixing clamp_mods_f64 once for all f64 ops, would close it.
Otherwise the row could say the clamp of the infinity and NaN cases is left to the driver.

For scale: docs/isa_coverage.md puts the f64 ops among the groups the 1.0.2.1 corpus does not need. This does not
block merging.

AI-assisted (Claude).

**@⁠qhukz13** on GitHub · 2026-11-26 01:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1477#issuecomment-7179667040) I checked `3c359c50` on Linux (Python 3.14), CPU only. I did not use a GPU. **Merge state.** The branch merges into main (`88479ff6`) without conflicts. It conflicts with #1374 in two lines: - the `parse_line` f64 list in `tools/shader_ir.py`; - the `--list-ops` "Excluded" line in `tools/f64_diff.py`. Whichever lands second has to take the other's opcodes out of that line. `v_ldexp_f64` is still listed there as excluded, but main translates it. **Tests.** On the merge, `test_fract_f64` passes, 23 tests with 1 skipped. `test_f64_literal_whole` and the old `test_valu_fract_f64` oracle also pass. The full translator suite on the merge gives 496 files, 6,356 tests, 0 files failed. **Edge cases.** I translated hand-written listings and ran them through `spirv_interp`. They give the words in the row: | Case | Result | |---|---| | -1e-300 and the negative subnormal `0x8000000000000001` | `0x3fefffffffffffff` | | -2.25 | 0.75 | | 2^53 + 2 | +0 | | `-\|0.25\|` in the e64 form | 0.75 | | `mul:2` | ignored | The selects build every edge from the operand's words, so none of it depends on how a driver handles `Floor(-0.0)` or binary64 subnormals. That is the right call. **One gap, shared with #1374.** `v_fract_f64_e64 v[4:5], inf clamp` returns `0xfff8000000000000`: - the select gives the NaN of fract(±inf); - `clamp_mods_f64` then applies a bare `FClamp` to it, which GLSL.std.450 leaves undefined; - the hardware gives +0 with DX10_CLAMP set, the game's MODE. A NaN passed with `clamp` takes the same path. The f32 and f16 clamps select +0 for a NaN since 2026-11-24 ("Float min/max/med3 with NaN"), and that row already lists the f64 clamp as still bare. Since this op picks its own words for every other edge, selecting +0 before the clamp here, or fixing `clamp_mods_f64` once for all f64 ops, would close it. Otherwise the row could say the clamp of the infinity and NaN cases is left to the driver. For scale: `docs/isa_coverage.md` puts the f64 ops among the groups the 1.0.2.1 corpus does not need. This does not block merging. AI-assisted (Claude).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1477/head:github-bot/gh-1477'
git switch 'github-bot/gh-1477'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1477'
git switch 'github-bot/gh-1477'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1477'
git switch 'github-bot/gh-1477'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1477'
git switch 'main'
git merge --squash 'github-bot/gh-1477'
git switch 'main'
git merge --ff-only 'github-bot/gh-1477'
git switch 'main'
git merge 'github-bot/gh-1477'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.