rdna2spirv: v_mul/fma/min/max_f64 and the f64 <-> f32/int conversions… #1374

Closed
leonida/mandy
vsking2000 wants to merge 0 commits from shader-f64-valu-ops into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

vsking2000 commented 2026-11-24 22:49:27 +00:00

… (SHADER-F64-VALU-OPS)

The translator refused seven binary64 VALU ops by name. Gen.f64_valu now lowers them:

  • v_mul_f64: OpFMul; v_fma_f64: one rounding through Gen.emit_fma64
  • v_min_f64/v_max_f64: NMin/NMax with S0 selected when S1 is a NaN, the rule measured for the f32/f16 forms (one NaN gives the other operand, two give S0)
  • v_cvt_f64_f32: exact OpFConvert; an f32 denormal source reads as a signed zero under the game's MODE, as the measured v_floor/ceil/fract_f32 do
  • v_cvt_i32_f64/v_cvt_u32_f64: truncate, saturate (infinities included), NaN -> 0, per the RDNA2 ISA, as the f32 forms do

Source abs/neg apply; f64 results take clamp/omod through clamp_mods_f64 as v_add_f64 does; integer results take no output modifier. v_mul/v_fma_f64 are refused under a directed MODE.FP_ROUND, which only v_add_f64 models.

shader_ir flags their hex literal sources as f64 literals (bits 63:32); spirv_mini_interp gets OpFConvert; docs/design.md gets a contract row. tests/semantic/test_valu_f64_ops.py is new, and test_valu_cvt_int_f64.py, which asserted the integer conversions are refused until implemented, now runs them through the translator. CPU interpreter and spirv-val only; not GPU-checked.

AI-assisted.

Claude-Session: https://claude.ai/code/session_01Y7fbZYVY7EtLknWBZUfSLf

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.
… (SHADER-F64-VALU-OPS) The translator refused seven binary64 VALU ops by name. Gen.f64_valu now lowers them: - v_mul_f64: OpFMul; v_fma_f64: one rounding through Gen.emit_fma64 - v_min_f64/v_max_f64: NMin/NMax with S0 selected when S1 is a NaN, the rule measured for the f32/f16 forms (one NaN gives the other operand, two give S0) - v_cvt_f64_f32: exact OpFConvert; an f32 denormal source reads as a signed zero under the game's MODE, as the measured v_floor/ceil/fract_f32 do - v_cvt_i32_f64/v_cvt_u32_f64: truncate, saturate (infinities included), NaN -> 0, per the RDNA2 ISA, as the f32 forms do Source abs/neg apply; f64 results take clamp/omod through clamp_mods_f64 as v_add_f64 does; integer results take no output modifier. v_mul/v_fma_f64 are refused under a directed MODE.FP_ROUND, which only v_add_f64 models. shader_ir flags their hex literal sources as f64 literals (bits 63:32); spirv_mini_interp gets OpFConvert; docs/design.md gets a contract row. tests/semantic/test_valu_f64_ops.py is new, and test_valu_cvt_int_f64.py, which asserted the integer conversions are refused until implemented, now runs them through the translator. CPU interpreter and spirv-val only; not GPU-checked. AI-assisted. Claude-Session: https://claude.ai/code/session_01Y7fbZYVY7EtLknWBZUfSLf 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.
ecox982745 commented 2026-11-24 23:16:02 +00:00

On an RTX 4090 (Windows, driver 616.64), all 31 compute readbacks with runtime operands matched the expected bits on 2e6fc3c6. I found one precision difference when the FMA operands are constants.

I used the cancellation case from test_one_rounding, with a = 1 + 2^-30 and c = -(1 + 2^-29). The exact result of v_fma_f64(a, a, c) is 2^-60 (binary64 bits 0x3c30000000000000). I ran two hand-written compute shaders and read the low and high output words directly from the Vulkan buffer.

Operand source Default GLSL Fma --fma khr
Loaded from the buffer at dispatch 2^-60 2^-60
Same bits set with v_mov_b32 in the shader +0.0 2^-60

This reproduces the caveat already documented in emit_fma64 for this newly supported opcode. I'd qualify the new design-table row's fused-result claim for the default mode and include this constant-input case alongside the runtime case in GPU coverage.

The seven synthetic modules covered multiply, FMA, min, max, f32 widening and both saturating integer conversions. The parent d4de3a7d refused all seven by opcode. The PR head translated and validated all seven. The 31 runtime cases included a binary64 subnormal product, two NaNs with distinct payloads, signed flushing of f32 subnormals and saturation at integer limits. I built vk_compute_test from the PR head. Separately, the two focused CPU suites passed 23/23. These results cover translated Vulkan compute on one NVIDIA device. AI-assisted verification.

On an RTX 4090 (Windows, driver 616.64), all **31 compute readbacks with runtime operands** matched the expected bits on `2e6fc3c6`. I found one precision difference when the FMA operands are constants. I used the cancellation case from `test_one_rounding`, with `a = 1 + 2^-30` and `c = -(1 + 2^-29)`. The exact result of `v_fma_f64(a, a, c)` is `2^-60` (binary64 bits `0x3c30000000000000`). I ran two hand-written compute shaders and read the low and high output words directly from the Vulkan buffer. | Operand source | Default GLSL Fma | `--fma khr` | | --- | --- | --- | | Loaded from the buffer at dispatch | `2^-60` | `2^-60` | | Same bits set with `v_mov_b32` in the shader | `+0.0` | `2^-60` | This reproduces the caveat already documented in `emit_fma64` for this newly supported opcode. I'd qualify the new design-table row's fused-result claim for the default mode and include this constant-input case alongside the runtime case in GPU coverage. The seven synthetic modules covered multiply, FMA, min, max, f32 widening and both saturating integer conversions. The parent `d4de3a7d` refused all seven by opcode. The PR head translated and validated all seven. The 31 runtime cases included a binary64 subnormal product, two NaNs with distinct payloads, signed flushing of f32 subnormals and saturation at integer limits. I built `vk_compute_test` from the PR head. Separately, the two focused CPU suites passed **23/23**. These results cover translated Vulkan compute on one NVIDIA device. AI-assisted verification.
ecox982745 commented 2026-11-24 23:45:39 +00:00

I tested the output-modifier and NaN changes in a44423b8 against its parent 2e6fc3c6 on the RTX 4090 (Windows 11, NVIDIA 616.64). The same 28 synthetic compute shaders passed SPIR-V validation on each revision. I loaded the operands from a buffer at dispatch and compared the raw 64-bit results with the new CPU tests' expectations.

GPU readback Parent Updated head
Output modifiers on multiply, FMA, min, max and f32-to-f64 conversion 5/25 25/25
Min/max with signalling NaN in source 0, quiet NaN in source 1, and neg/abs/neg-abs on source 0 0/6 6/6
Min/max of opposite signed zeros, both operand orders 4/4 4/4

For all five arithmetic/conversion ops, an unscaled result of 0.25 stayed 0.25 under mul:2, mul:4, div:2, and clamp mul:4 on the updated head. A separate above-one input still clamped to 1 on both revisions. For min(-sNaN, qNaN), the parent returned 0x7ff8000000000123; the updated head returned 0xfff0000000000123, preserving the signalling bit pattern and applying the sign change.

The two focused CPU suites also passed, 29/29 on the updated head. These measurements verify the translated Vulkan output on this NVIDIA driver. Native RDNA2 results for these five instructions with output modifiers remain open.

I tested the output-modifier and NaN changes in `a44423b8` against its parent `2e6fc3c6` on the RTX 4090 (Windows 11, NVIDIA 616.64). The same 28 synthetic compute shaders passed SPIR-V validation on each revision. I loaded the operands from a buffer at dispatch and compared the raw 64-bit results with the new CPU tests' expectations. | GPU readback | Parent | Updated head | | --- | ---: | ---: | | Output modifiers on multiply, FMA, min, max and f32-to-f64 conversion | 5/25 | 25/25 | | Min/max with signalling NaN in source 0, quiet NaN in source 1, and neg/abs/neg-abs on source 0 | 0/6 | 6/6 | | Min/max of opposite signed zeros, both operand orders | 4/4 | 4/4 | For all five arithmetic/conversion ops, an unscaled result of 0.25 stayed 0.25 under `mul:2`, `mul:4`, `div:2`, and `clamp mul:4` on the updated head. A separate above-one input still clamped to 1 on both revisions. For `min(-sNaN, qNaN)`, the parent returned `0x7ff8000000000123`; the updated head returned `0xfff0000000000123`, preserving the signalling bit pattern and applying the sign change. The two focused CPU suites also passed, 29/29 on the updated head. These measurements verify the translated Vulkan output on this NVIDIA driver. Native RDNA2 results for these five instructions with output modifiers remain open.
tiguan26 approved these changes 2026-11-25 06:18:16 +00:00
tiguan26 left a comment

Approving. Merged into current main with no conflicts; the PR's tests pass and the full translator suite gives 488 files / 6,306 tests with only test_int32_to_f64 failing, the same baseline failure as main here (Linux, Python 3.13). I read the diff and the change matches the ISA behaviour it claims, with tests for the new path and its refusals.

AI-assisted (Claude).

Approving. Merged into current main with no conflicts; the PR's tests pass and the full translator suite gives 488 files / 6,306 tests with only `test_int32_to_f64` failing, the same baseline failure as main here (Linux, Python 3.13). I read the diff and the change matches the ISA behaviour it claims, with tests for the new path and its refusals. AI-assisted (Claude).
qhukz13 commented 2026-11-26 01:19:54 +00:00

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

Merge state. The branch is 792 commits behind main and now conflicts with it in docs/design.md. #1477 also
conflicts with it, in two lines:

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

Whichever of the two lands second has to drop the other's opcodes from that line. While you are on that line,
v_ldexp_f64 is still listed as excluded, but main translates it.

Tests. I merged the branch into main (88479ff6) and took the PR's side of docs/design.md. These pass:
test_valu_f64_ops, test_valu_cvt_int_f64, test_valu_add_f64 and tests/test_semantic_translator_use.py.

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

Case Result
min(qNaN_a, qNaN_b) qNaN_a with its payload (S0)
max(sNaN, 1.0) and max(1.0, sNaN) 1.0
min(-0, +0) and min(+0, -0) -0 in the interpreter. The row says the driver decides this.
Subnormal product 2^-1000 × 2^-60 exact, 0x4000
v_cvt_i32_f64(-2^31 - 0.5) 0x80000000
v_cvt_u32_f64(-0.9) and v_cvt_u32_f64(NaN) 0
A literal source of v_fma_f64 the high word, with a zero low word
An SGPR-pair source handled
-|x| on min handled

One gap. A clamp of a NaN result still goes through the bare FClamp in clamp_mods_f64. GLSL.std.450 leaves
that result undefined. With DX10_CLAMP set, the game's MODE, the hardware gives +0. The f32 and f16 clamps select +0
for a NaN since 2026-11-24 ("Float min/max/med3 with NaN"), and that row lists the f64 clamp as still bare. That gap
was already on main through v_add_f64. This PR gives it new paths:

  • v_max_f64 v[4:5], qNaN, qNaN clamp returns the NaN in the interpreter;
  • v_mul_f64 inf, 0 clamp returns 0xfff8000000000000.

A NaN select before the FClamp in clamp_mods_f64 would cover every f64 op at once. A sentence in the new row
saying the f64 clamp of a NaN is left to the driver would also do. #1477's v_fract_f64 ... clamp of an infinity
hits the same line.

Doc nit. The new row still says v_fma_f64 is "one rounding" in the default mode. ecox982745's RTX 4090 readback
above, which the emit_fma64 docstring also records, shows NVIDIA rounding twice when all FMA operands are constants.
Saying that in the row, or pointing to --fma khr, would keep the row from overclaiming.

For scale: docs/isa_coverage.md puts the f64 transcendentals and v_div_* among the groups the 1.0.2.1 corpus does
not need. As far as I can tell, these ops are not on the game's path either, so none of the above blocks merging.

AI-assisted (Claude).

I checked `1b0442fc` on Linux (Python 3.14), CPU only. I did not use a GPU. **Merge state.** The branch is 792 commits behind main and now conflicts with it in `docs/design.md`. #1477 also conflicts with it, in two lines: - the `parse_line` f64 list in `tools/shader_ir.py`; - the `--list-ops` "Excluded" line in `tools/f64_diff.py`. Whichever of the two lands second has to drop the other's opcodes from that line. While you are on that line, `v_ldexp_f64` is still listed as excluded, but main translates it. **Tests.** I merged the branch into main (`88479ff6`) and took the PR's side of `docs/design.md`. These pass: `test_valu_f64_ops`, `test_valu_cvt_int_f64`, `test_valu_add_f64` and `tests/test_semantic_translator_use.py`. **Edge cases.** I translated 14 hand-written listings and ran them through `spirv_interp`. They give the words in the row: | Case | Result | |---|---| | `min(qNaN_a, qNaN_b)` | `qNaN_a` with its payload (S0) | | `max(sNaN, 1.0)` and `max(1.0, sNaN)` | 1.0 | | `min(-0, +0)` and `min(+0, -0)` | -0 in the interpreter. The row says the driver decides this. | | Subnormal product 2^-1000 × 2^-60 | exact, `0x4000` | | `v_cvt_i32_f64(-2^31 - 0.5)` | `0x80000000` | | `v_cvt_u32_f64(-0.9)` and `v_cvt_u32_f64(NaN)` | 0 | | A literal source of `v_fma_f64` | the high word, with a zero low word | | An SGPR-pair source | handled | | `-\|x\|` on min | handled | **One gap.** A `clamp` of a NaN result still goes through the bare `FClamp` in `clamp_mods_f64`. GLSL.std.450 leaves that result undefined. With DX10_CLAMP set, the game's MODE, the hardware gives +0. The f32 and f16 clamps select +0 for a NaN since 2026-11-24 ("Float min/max/med3 with NaN"), and that row lists the f64 clamp as still bare. That gap was already on main through `v_add_f64`. This PR gives it new paths: - `v_max_f64 v[4:5], qNaN, qNaN clamp` returns the NaN in the interpreter; - `v_mul_f64 inf, 0 clamp` returns `0xfff8000000000000`. A NaN select before the `FClamp` in `clamp_mods_f64` would cover every f64 op at once. A sentence in the new row saying the f64 clamp of a NaN is left to the driver would also do. #1477's `v_fract_f64 ... clamp` of an infinity hits the same line. **Doc nit.** The new row still says `v_fma_f64` is "one rounding" in the default mode. ecox982745's RTX 4090 readback above, which the `emit_fma64` docstring also records, shows NVIDIA rounding twice when all FMA operands are constants. Saying that in the row, or pointing to `--fma khr`, would keep the row from overclaiming. For scale: `docs/isa_coverage.md` puts the f64 transcendentals and `v_div_*` among the groups the 1.0.2.1 corpus does not need. As far as I can tell, these ops are not on the game's path either, so none of the above blocks merging. AI-assisted (Claude).
MoonEyes commented 2026-11-27 22:42:46 +00:00

Hi @vsking2000, thanks for this pull request.

CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post claiming: <ID> there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one (the ID SHADER-F64-VALU-OPS appears in the pull request, but there is no claiming: line for it).

The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time.

Could you post the claim in #1608 and add the ID to the pull request description? If you already claimed it in another form, a link to your comment is enough.

AI-assisted (Claude Code, Claude Opus 5.5).

Hi @vsking2000, thanks for this pull request. CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post `claiming: <ID>` there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one (the ID `SHADER-F64-VALU-OPS` appears in the pull request, but there is no `claiming:` line for it). The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time. Could you post the claim in #1608 and add the ID to the pull request description? If you already claimed it in another form, a link to your comment is enough. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 reviewed 2026-12-01 11:46:18 +00:00
aslan2142 left a comment
No description provided.
This PR cannot merge in its current state: - **Merge conflict** with `main` in `docs/design.md` (and overlaps `tools/shader_ir.py` / `tools/f64_diff.py` with `#1477`). - **No CI run** on current head `1b0442f`. - Please also link the coordination-issue claim in the PR description per `CONTRIBUTING.md`. Please rebase onto current `main` and obtain a green CI run. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 17:22:56 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.