Shaders: lower v_cvt_f32_f64 and model v_add_f64 whole-wave sums #9

Open
github-bot wants to merge 3 commits from github-bot/gh-9 into main AGit
Owner

@⁠MartinIndra02 on GitHub · 2026-11-24 19:39 UTC · original
MartinIndra02:feat/fxceless-cvt-f32-f64 → main · +658 −1 · 5 files · 3 commits · open

Summary

Lowers v_cvt_f32_f64 and models v_add_f64 whole-wave sums (plus s_mov_b32 scalar copies inside whole-wave sections):

  1. v_cvt_f32_f64 (crates/victory-shader/src/emit/lower.rs)

    • Reads the binary64 operand (lo, hi) (VGPR pair, SGPR pair, inline f64 constants 240..=248, 0, or high-dword 32-bit literal) with abs/neg input modifiers.
    • Converts IEEE-754 binary64 to binary32 with round-to-nearest-even in 32-bit integer arithmetic (handling normals, ties-to-even, subnormals including carry-to-normal and exp64 == 873 halfway-to-min-subnormal, overflow to ±Inf, underflow to ±0, and sNaN→qNaN quieting) without requiring host DOUBLES support.
  2. 64-bit float whole-wave sum (v_add_f64) & s_mov_b32 copy (bitcode.rs, shader.rs, wave.rs, lower.rs)

    • Adds TypeDef::Double (TYPE_CODE_DOUBLE = 4) in bitcode.rs and flags::DOUBLES (ShaderFlags bit 5, SFI0 bit 0) in shader.rs.
    • Models v_add_f64 pairs in wave.rs as Sym::Red64F → Shape::ActiveF64(lo, hi, mask, high), and propagates s_mov_b32 copies inside whole-wave sections.
    • Lowers Shape::ActiveF64 via dx.op.makeDouble → dx.op.waveActiveOp.f64 → dx.op.splitDouble.f64, with exchange_halves + fadd when running Wave64-on-Wave32.

Verification

  • Hardware GPU + WARP tests (RTX 3080, SM 6.6):
    • v_cvt_f32_f64_matches_ieee754: 27 IEEE-754 edge cases + abs/neg modifiers pass bit-for-bit on both RTX 3080 and WARP.
    • whole_wave_f64_sum_and_cvt_f32_f64: end-to-end Wave32 v_add_f64 whole-wave reduction + s_mov_b32 + v_cvt_f32_f64 passes on RTX 3080.
    • Full cargo test -p victory-shader --lib: all tests pass.
    • cargo clippy --workspace -- -D warnings (default + --features diagnostics): 0 warnings.
    • cargo xtask policy: 167 files ok.
  • Offline shader corpus A/B (aggregate counts only, no game data):
    • emit: v_cvt_f32_f64: 5 → 0
    • emit: a whole-wave section step the simulation does not follow: 5 → 0 (0 remaining across all 26,084 programs)
    • Compute shaders emitted: 2,663 → 2,666 of 2,682 (+3 compute shaders emitted; the other 2 advance past v_add_f64/v_cvt_f32_f64 to a lane mask holding lanes elsewhere read as data).

AI-assisted contribution (Antigravity); all code, tests, and hardware verification run and reviewed locally. No game data.

**@⁠MartinIndra02** on GitHub · 2026-11-24 19:39 UTC · [original](https://github.com/fxceless/victory-fork/pull/9) `MartinIndra02:feat/fxceless-cvt-f32-f64` → `main` · +658 −1 · 5 files · 3 commits · open ## Summary Lowers `v_cvt_f32_f64` and models `v_add_f64` whole-wave sums (plus `s_mov_b32` scalar copies inside whole-wave sections): 1. **`v_cvt_f32_f64` (`crates/victory-shader/src/emit/lower.rs`)** - Reads the binary64 operand `(lo, hi)` (VGPR pair, SGPR pair, inline f64 constants `240..=248`, `0`, or high-dword 32-bit literal) with `abs`/`neg` input modifiers. - Converts IEEE-754 binary64 to binary32 with round-to-nearest-even in 32-bit integer arithmetic (handling normals, ties-to-even, subnormals including carry-to-normal and `exp64 == 873` halfway-to-min-subnormal, overflow to `±Inf`, underflow to `±0`, and `sNaN`→`qNaN` quieting) without requiring host `DOUBLES` support. 2. **64-bit float whole-wave sum (`v_add_f64`) & `s_mov_b32` copy (`bitcode.rs`, `shader.rs`, `wave.rs`, `lower.rs`)** - Adds `TypeDef::Double` (`TYPE_CODE_DOUBLE = 4`) in `bitcode.rs` and `flags::DOUBLES` (`ShaderFlags` bit 5, `SFI0` bit 0) in `shader.rs`. - Models `v_add_f64` pairs in `wave.rs` as `Sym::Red64F` → `Shape::ActiveF64(lo, hi, mask, high)`, and propagates `s_mov_b32` copies inside whole-wave sections. - Lowers `Shape::ActiveF64` via `dx.op.makeDouble` → `dx.op.waveActiveOp.f64` → `dx.op.splitDouble.f64`, with `exchange_halves` + `fadd` when running Wave64-on-Wave32. ## Verification - **Hardware GPU + WARP tests (RTX 3080, SM 6.6):** - `v_cvt_f32_f64_matches_ieee754`: 27 IEEE-754 edge cases + `abs`/`neg` modifiers pass bit-for-bit on both RTX 3080 and WARP. - `whole_wave_f64_sum_and_cvt_f32_f64`: end-to-end Wave32 `v_add_f64` whole-wave reduction + `s_mov_b32` + `v_cvt_f32_f64` passes on RTX 3080. - Full `cargo test -p victory-shader --lib`: all tests pass. - `cargo clippy --workspace -- -D warnings` (default + `--features diagnostics`): 0 warnings. - `cargo xtask policy`: 167 files ok. - **Offline shader corpus A/B (aggregate counts only, no game data):** - `emit: v_cvt_f32_f64`: **`5 → 0`** - `emit: a whole-wave section step the simulation does not follow`: **`5 → 0`** (0 remaining across all 26,084 programs) - Compute shaders emitted: **`2,663 → 2,666` of `2,682`** (`+3` compute shaders emitted; the other 2 advance past `v_add_f64`/`v_cvt_f32_f64` to `a lane mask holding lanes elsewhere read as data`). *AI-assisted contribution (Antigravity); all code, tests, and hardware verification run and reviewed locally. No game data.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:34:30 +00:00
Author
Owner

@⁠fxceless on GitHub · 2026-11-24 20:18 UTC · original

Thanks for this. The v_cvt_f32_f64 part looks fine, but on the test machine here (RTX 4070, with dxil.dll present so the tests validate) the PR's own test fails:

emit::valu_tests::whole_wave_f64_sum_and_cvt_f32_f64
DXIL validation failed: 'dx.op.makeDouble' is not a DXILOpFunction for DXILOpcode 'MakeDouble'
  at '%11 = call double @dx.op.makeDouble(i32 101, i32 %9, i32 %10)'

The validator wants the overloaded name (dx.op.makeDouble.f64); without dxil.dll the test skips validation, which is probably why it passed for you. Could you fix the declaration and re-run with the validator available? Happy to merge after that.

**@⁠fxceless** on GitHub · 2026-11-24 20:18 UTC · [original](https://github.com/fxceless/victory-fork/pull/9#issuecomment-7143346697) Thanks for this. The `v_cvt_f32_f64` part looks fine, but on the test machine here (RTX 4070, with `dxil.dll` present so the tests validate) the PR's own test fails: ``` emit::valu_tests::whole_wave_f64_sum_and_cvt_f32_f64 DXIL validation failed: 'dx.op.makeDouble' is not a DXILOpFunction for DXILOpcode 'MakeDouble' at '%11 = call double @dx.op.makeDouble(i32 101, i32 %9, i32 %10)' ``` The validator wants the overloaded name (`dx.op.makeDouble.f64`); without `dxil.dll` the test skips validation, which is probably why it passed for you. Could you fix the declaration and re-run with the validator available? Happy to merge after that.
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 20:26 UTC · original

Tested on an RTX 5070 (driver 621.40, Windows 11, SDK 10.0.26100 dxil.dll 1.9.2602), PR head b17b69f.

Same failure as on the 4070. Renaming the three calls to makeDouble.f64 clears the first error, but validation then stops on a second one:

error: Flags must match usage.
note: Flags declared=1074266144, actual=1074266116

The difference is 0x20 vs 0x04: flags::DOUBLES is 1 << 5, which is LowPrecisionPresent in DXIL's ShaderFlags; double precision is bit 2. With both changes:

-    pub const DOUBLES: u64 = 1 << 5;
+    pub const DOUBLES: u64 = 1 << 2;
-            .op(c, "makeDouble", Attr::ReadNone, f64t, 101, &[lo, hi]);
+            .op(c, "makeDouble.f64", Attr::ReadNone, f64t, 101, &[lo, hi]);

(and the same for the two calls in the wave64-on-wave32 branch), cargo test -p victory-shader --lib passes here, 200 passed, 2 ignored, including whole_wave_f64_sum_and_cvt_f32_f64 with the validator loaded and running on the card. The SFI0 bit 0x1 is already right.

**@⁠marquezinii** on GitHub · 2026-11-24 20:26 UTC · [original](https://github.com/fxceless/victory-fork/pull/9#issuecomment-7143545227) Tested on an RTX 5070 (driver 621.40, Windows 11, SDK 10.0.26100 `dxil.dll` 1.9.2602), PR head `b17b69f`. Same failure as on the 4070. Renaming the three calls to `makeDouble.f64` clears the first error, but validation then stops on a second one: ``` error: Flags must match usage. note: Flags declared=1074266144, actual=1074266116 ``` The difference is 0x20 vs 0x04: `flags::DOUBLES` is `1 << 5`, which is `LowPrecisionPresent` in DXIL's `ShaderFlags`; double precision is bit 2. With both changes: ```diff - pub const DOUBLES: u64 = 1 << 5; + pub const DOUBLES: u64 = 1 << 2; ``` ```diff - .op(c, "makeDouble", Attr::ReadNone, f64t, 101, &[lo, hi]); + .op(c, "makeDouble.f64", Attr::ReadNone, f64t, 101, &[lo, hi]); ``` (and the same for the two calls in the wave64-on-wave32 branch), `cargo test -p victory-shader --lib` passes here, 200 passed, 2 ignored, including `whole_wave_f64_sum_and_cvt_f32_f64` with the validator loaded and running on the card. The `SFI0` bit 0x1 is already right.
Author
Owner

@⁠MartinIndra02 on GitHub · 2026-11-24 20:47 UTC · original

Fixed both issues in the latest commit — thanks @⁠fxceless and @⁠marquezinii for catching this with \dxil.dll!

  • Renamed all three \makeDouble\ calls in \lower.rs\ to \makeDouble.f64.
  • Fixed \ lags::DOUBLES\ in \shader.rs\ from \1 << 5\ (\LowPrecisionPresent) to \1 << 2\ (\EnableDoublePrecision).

Re-verified \whole_wave_f64_sum_and_cvt_f32_f64, \ _cvt_f32_f64_matches_ieee754, \clippy -p victory-shader --all-targets -- -D warnings, and \cargo xtask policy\ locally on RTX 3080 (still without \dxil.dll\ installed on this machine).

**@⁠MartinIndra02** on GitHub · 2026-11-24 20:47 UTC · [original](https://github.com/fxceless/victory-fork/pull/9#issuecomment-7144060097) Fixed both issues in the latest commit — thanks @⁠fxceless and @⁠marquezinii for catching this with \dxil.dll\! - Renamed all three \makeDouble\ calls in \lower.rs\ to \makeDouble.f64\. - Fixed \ lags::DOUBLES\ in \shader.rs\ from \1 << 5\ (\LowPrecisionPresent\) to \1 << 2\ (\EnableDoublePrecision\). Re-verified \whole_wave_f64_sum_and_cvt_f32_f64\, \ _cvt_f32_f64_matches_ieee754\, \clippy -p victory-shader --all-targets -- -D warnings\, and \cargo xtask policy\ locally on RTX 3080 (still without \dxil.dll\ installed on this machine).
Author
Owner

@⁠adriaespii on GitHub · 2026-11-24 20:54 UTC · original

Independent test run on commit 61e5f79 (AMD RDNA4):

  • Hardware: AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (x86_64-pc-windows-msvc)
  • cargo clippy --workspace --all-targets -- -D warnings: 0 warnings
  • cargo test --workspace: 486 passed, 0 failed, 7 ignored (victory-shader: 200 passed, 0 failed, 2 ignored; victory-gpu: 110 passed, 0 failed, 1 ignored)
  • Not tested: retail shader pack / live game run (no game files on this machine)

AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.

**@⁠adriaespii** on GitHub · 2026-11-24 20:54 UTC · [original](https://github.com/fxceless/victory-fork/pull/9#issuecomment-7144219953) Independent test run on commit `61e5f79` (AMD RDNA4): - **Hardware:** AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (`x86_64-pc-windows-msvc`) - `cargo clippy --workspace --all-targets -- -D warnings`: 0 warnings - `cargo test --workspace`: 486 passed, 0 failed, 7 ignored (`victory-shader`: 200 passed, 0 failed, 2 ignored; `victory-gpu`: 110 passed, 0 failed, 1 ignored) - **Not tested:** retail shader pack / live game run (no game files on this machine) *AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.*
Author
Owner

@⁠KaliemSB on GitHub · 2026-11-24 21:43 UTC · original

Tested on the title's own shaders:

  • 3 of the 5 v_cvt_f32_f64 programs now translate and validate. The other 2 now stop at the next unsupported feature.
  • No regressions in the rest of the archive.
  • On a 32-lane NVIDIA card the 3 still don't run, because they come out as wave64.

Setup

  • CPU / RAM: Intel Core i5-12400F, 32 GB
  • GPU: NVIDIA GeForce RTX 4060 8 GB (32-lane waves), driver 621.24
  • OS: Windows 11 Pro 24H2 (build 26100)
  • Toolchain: rustc / cargo 1.98.1, cargo build --release -p victory
  • Validator / DXC: dxil.dll and dxc.exe 1.9.2609.5
  • Trees: base 4e17478 (fork main) against 4e17478 with this PR's head 61e5f79 merged (1ea962e). Nothing else merged.
  • Translation settings: VICTORY_HOST_WAVE=32 VICTORY_VIEW_LIMIT=999999, the same forms the runtime picks on this card

Whole archive (victory translate <dump> --list, 26,599 containers, 26,148 programs):

base with PR
compute DXIL emitted 2,718 of 2,734 2,721 of 2,734
v_cvt_f32_f64 5 0
programs that newly fail – 0

Per program (each extracted, --validate, then --pipelines, then dxc -dumpbin for the wave size):

program hash base with PR
water_shading:CS_TransmissionVolumetrics_Tiled 5dc3b25986622949 v_cvt_f32_f64 validated, WaveSize=64, pipeline refused (E_INVALIDARG)
water_shading:CS_TransmissionVolumetrics_Tiled_LocalLights 6f225b641c5b0708 v_cvt_f32_f64 validated, WaveSize=64, pipeline refused
water_shading:CS_TransmissionVolumetrics_VolumePortalsOnly a10179ab7eda0dc3 v_cvt_f32_f64 validated, WaveSize=64, pipeline refused
(compute) 926c46bab3b86bd6 v_cvt_f32_f64 a lane mask holding lanes elsewhere read as data
(compute) 6871d6e4b3ac9a10 v_cvt_f32_f64 a lane mask holding lanes elsewhere read as data
  • The conversion itself works: the three water programs pass the 1.9 validator.
  • They keep the console's 64-lane form even when translated for a 32-lane host, so this card's driver refuses the pipeline. On 64-lane hardware they should run.
  • On NVIDIA they would also need the wave64-on-32-lane form. That is the same thing that blocks 5 other compute pipelines I see refused in game, and it's outside this PR.

Tests, cargo test -p victory-shader on 4e17478 + this PR:

  • 210 passed, 2 failed. 4e17478 alone gives 208 passed, 2 failed.
  • The 2 failures are the existing rect::tests PSV-validation failures with the default Windows SDK 10.0.22621 dxil.dll (1.6.2112). They pass with dxil.dll 1.9.2609.5 or with #61.
  • This PR's new tests pass.

AI use: Claude Code (Claude Opus 5.5) built the trees, ran the translations and tests, and drafted this; the machine is mine. No game files or extracted shaders attached.

**@⁠KaliemSB** on GitHub · 2026-11-24 21:43 UTC · [original](https://github.com/fxceless/victory-fork/pull/9#issuecomment-7145310838) **Tested on the title's own shaders:** - 3 of the 5 `v_cvt_f32_f64` programs now translate and validate. The other 2 now stop at the next unsupported feature. - No regressions in the rest of the archive. - On a 32-lane NVIDIA card the 3 still don't run, because they come out as wave64. **Setup** - **CPU / RAM:** Intel Core i5-12400F, 32 GB - **GPU:** NVIDIA GeForce RTX 4060 8 GB (32-lane waves), driver 621.24 - **OS:** Windows 11 Pro 24H2 (build 26100) - **Toolchain:** rustc / cargo 1.98.1, `cargo build --release -p victory` - **Validator / DXC:** `dxil.dll` and `dxc.exe` 1.9.2609.5 - **Trees:** base `4e17478` (fork `main`) against `4e17478` with this PR's head `61e5f79` merged (`1ea962e`). Nothing else merged. - **Translation settings:** `VICTORY_HOST_WAVE=32 VICTORY_VIEW_LIMIT=999999`, the same forms the runtime picks on this card **Whole archive** (`victory translate <dump> --list`, 26,599 containers, 26,148 programs): | | base | with PR | |---|---|---| | compute DXIL emitted | 2,718 of 2,734 | **2,721** of 2,734 | | `v_cvt_f32_f64` | 5 | **0** | | programs that newly fail | – | **0** | **Per program** (each extracted, `--validate`, then `--pipelines`, then `dxc -dumpbin` for the wave size): | program | hash | base | with PR | |---|---|---|---| | `water_shading:CS_TransmissionVolumetrics_Tiled` | `5dc3b25986622949` | `v_cvt_f32_f64` | validated, `WaveSize=64`, pipeline refused (`E_INVALIDARG`) | | `water_shading:CS_TransmissionVolumetrics_Tiled_LocalLights` | `6f225b641c5b0708` | `v_cvt_f32_f64` | validated, `WaveSize=64`, pipeline refused | | `water_shading:CS_TransmissionVolumetrics_VolumePortalsOnly` | `a10179ab7eda0dc3` | `v_cvt_f32_f64` | validated, `WaveSize=64`, pipeline refused | | (compute) | `926c46bab3b86bd6` | `v_cvt_f32_f64` | `a lane mask holding lanes elsewhere read as data` | | (compute) | `6871d6e4b3ac9a10` | `v_cvt_f32_f64` | `a lane mask holding lanes elsewhere read as data` | - The conversion itself works: the three water programs pass the 1.9 validator. - They keep the console's 64-lane form even when translated for a 32-lane host, so this card's driver refuses the pipeline. On 64-lane hardware they should run. - On NVIDIA they would also need the wave64-on-32-lane form. That is the same thing that blocks 5 other compute pipelines I see refused in game, and it's outside this PR. **Tests**, `cargo test -p victory-shader` on `4e17478` + this PR: - 210 passed, 2 failed. `4e17478` alone gives 208 passed, 2 failed. - The 2 failures are the existing `rect::tests` PSV-validation failures with the default Windows SDK 10.0.22621 `dxil.dll` (1.6.2112). They pass with `dxil.dll` 1.9.2609.5 or with #61. - This PR's new tests pass. *AI use: Claude Code (Claude Opus 5.5) built the trees, ran the translations and tests, and drafted this; the machine is mine. No game files or extracted shaders attached.*
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 21:50 UTC · original

Re-ran 61e5f79 on the RTX 5070 (driver 621.40, Windows 11) with the SDK 10.0.26100 dxil.dll present, so the shader tests validate this time:

  • cargo test --workspace: 486 passed, 0 failed, 7 ignored.
  • whole_wave_f64_sum_and_cvt_f32_f64 and v_cvt_f32_f64_matches_ieee754 pass. DXIL validation succeeds, and both cases are compared on the card. On WARP the f64 test skips pipeline creation (E_INVALIDARG), which the test expects for the fixed wave size.
  • cargo clippy --workspace --all-targets -- -D warnings, default and --all-features: clean.
**@⁠marquezinii** on GitHub · 2026-11-24 21:50 UTC · [original](https://github.com/fxceless/victory-fork/pull/9#issuecomment-7145455061) Re-ran `61e5f79` on the RTX 5070 (driver 621.40, Windows 11) with the SDK 10.0.26100 `dxil.dll` present, so the shader tests validate this time: - `cargo test --workspace`: 486 passed, 0 failed, 7 ignored. - `whole_wave_f64_sum_and_cvt_f32_f64` and `v_cvt_f32_f64_matches_ieee754` pass. DXIL validation succeeds, and both cases are compared on the card. On WARP the f64 test skips pipeline creation (`E_INVALIDARG`), which the test expects for the fixed wave size. - `cargo clippy --workspace --all-targets -- -D warnings`, default and `--all-features`: clean.
Author
Owner

@⁠arminkhaleghirod on GitHub · 2026-11-24 22:23 UTC · original

Merged onto main 90228a7 and ran victory translate --validate over the full title (26,148 programs) on Windows 11 / RTX 4080.

  • v_cvt_f32_f64: 5 → 0
  • New: 2 × emit: a lane mask holding lanes elsewhere read as data
  • Net: 3 programs fewer failing.
**@⁠arminkhaleghirod** on GitHub · 2026-11-24 22:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/9#issuecomment-7146177786) Merged onto main 90228a7 and ran `victory translate --validate` over the full title (26,148 programs) on Windows 11 / RTX 4080. - `v_cvt_f32_f64`: 5 → 0 - **New:** 2 × `emit: a lane mask holding lanes elsewhere read as data` - Net: 3 programs fewer failing.
Author
Owner

@⁠rmstamate on GitHub · 2026-11-25 10:19 UTC · original

Ran 61e5f79 on the RTX 3070TI (driver 621.01, Windows 11) with the SDK 10.0.26100 dxil.dll present, so the shader tests validate this time:

cargo test & clippy passed clean on my side.

**@⁠rmstamate** on GitHub · 2026-11-25 10:19 UTC · [original](https://github.com/fxceless/victory-fork/pull/9#issuecomment-7159544873) Ran `61e5f79` on the RTX 3070TI (driver 621.01, Windows 11) with the `SDK 10.0.26100` `dxil.dll` present, so the shader tests validate this time: cargo test & clippy passed clean on my side.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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