Shaders: v_cvt_f32_f64 in 32-bit integer arithmetic #163

Open
github-bot wants to merge 1 commit from github-bot/gh-163 into main AGit
Owner

@⁠adonizm on GitHub · 2026-11-24 22:05 UTC · original
adonizm:shaders/v-cvt-f32-f64 → main · +121 −0 · 2 files · 1 commits · open

Programs that convert a double to a float (v_cvt_f32_f64) did not translate ("v_cvt_f32_f64 is not supported"), so their draws and dispatches were dropped. The emitter has no 64-bit float type, so the conversion is done on the double's two dwords with 32-bit integer operations:

  • round to nearest even (the MODE default), with a carry out of the mantissa moving into the exponent;
  • infinities stay infinities, NaNs become the quiet NaN, values too large for f32 become infinity;
  • results below f32's normal range (|x| < 2^-126) flush to signed zero. That is a shortcut, marked in the code;
  • an inline float constant as the 64-bit source is refused, because src64 reads those as 32-bit integers.

The change is one new case in valu_op (crates/victory-shader/src/emit/lower.rs) and one test.

Tested on an RTX 5070 Ti (driver 621.24), Ryzen 7 7800X3D, Windows 11, Series X profile

  • New GPU test cvt_f32_f64_rounds_to_nearest_even: 16 doubles (exact ties both ways, overflow to infinity, f32::MAX plus half an ulp, NaN, -0, the flush) compared bit for bit with Rust's own f64 as f32, on the hardware adapter and WARP. Passes on both.
  • On this branch (rebased onto 2119b0e): cargo test --workspace: 497 passed, 0 failed, 7 ignored. cargo clippy --workspace --all-targets: clean.
  • Offline, victory translate over the retail shader pack with this change: 0 programs fail on this instruction (an earlier sweep with upstream VIctory ffe310e listed 5).
  • In the game (on 4e17478 plus this change, VICTORY_RELAY=2): the prologue ran with no device loss and no crash, no v_cvt_f32_f64 warnings (an earlier run on 90228a7 logged 2 such shaders in the same stretch), 2.5 fps average / 5 fps peak in the world, the same as before.

Not tested

  • Other GPUs (AMD, older NVIDIA).
  • Whether the flushed subnormal results matter anywhere visible.
  • A long play session: the in-game check covers a few minutes of the prologue.

AI use: written with Claude Code (Claude Opus 5.5): the lowering, the test and this description. DeepSeek (deepseek-flash) was used only to summarize the existing test file's helpers; its notes were checked against the code. Tested on my machine with the commands above.

**@⁠adonizm** on GitHub · 2026-11-24 22:05 UTC · [original](https://github.com/fxceless/victory-fork/pull/163) `adonizm:shaders/v-cvt-f32-f64` → `main` · +121 −0 · 2 files · 1 commits · open Programs that convert a double to a float (`v_cvt_f32_f64`) did not translate ("v_cvt_f32_f64 is not supported"), so their draws and dispatches were dropped. The emitter has no 64-bit float type, so the conversion is done on the double's two dwords with 32-bit integer operations: - round to nearest even (the MODE default), with a carry out of the mantissa moving into the exponent; - infinities stay infinities, NaNs become the quiet NaN, values too large for f32 become infinity; - results below f32's normal range (|x| < 2^-126) flush to signed zero. That is a shortcut, marked in the code; - an inline float constant as the 64-bit source is refused, because `src64` reads those as 32-bit integers. The change is one new case in `valu_op` (`crates/victory-shader/src/emit/lower.rs`) and one test. **Tested on an RTX 5070 Ti (driver 621.24), Ryzen 7 7800X3D, Windows 11, Series X profile** - New GPU test `cvt_f32_f64_rounds_to_nearest_even`: 16 doubles (exact ties both ways, overflow to infinity, f32::MAX plus half an ulp, NaN, -0, the flush) compared bit for bit with Rust's own `f64 as f32`, on the hardware adapter and WARP. Passes on both. - On this branch (rebased onto `2119b0e`): `cargo test --workspace`: 497 passed, 0 failed, 7 ignored. `cargo clippy --workspace --all-targets`: clean. - Offline, `victory translate` over the retail shader pack with this change: 0 programs fail on this instruction (an earlier sweep with upstream VIctory `ffe310e` listed 5). - In the game (on `4e17478` plus this change, `VICTORY_RELAY=2`): the prologue ran with no device loss and no crash, no `v_cvt_f32_f64` warnings (an earlier run on `90228a7` logged 2 such shaders in the same stretch), 2.5 fps average / 5 fps peak in the world, the same as before. **Not tested** - Other GPUs (AMD, older NVIDIA). - Whether the flushed subnormal results matter anywhere visible. - A long play session: the in-game check covers a few minutes of the prologue. **AI use:** written with Claude Code (Claude Opus 5.5): the lowering, the test and this description. DeepSeek (deepseek-flash) was used only to summarize the existing test file's helpers; its notes were checked against the code. Tested on my machine with the commands above.
The emitter has no 64-bit floats, so programs converting a double to a
float did not translate and their draws were dropped. The conversion is
now done on the double's two dwords with integer operations: rounding to
nearest even, infinities kept, NaNs quieted, overflow to infinity.
Results below f32's normal range flush to signed zero (a shortcut,
noted in the code). Inline float constants as the 64-bit source are
refused, since src64 reads them as integers.

A GPU test compares 16 cases (ties, overflow, NaN, -0, the flush) with
the host's own conversion on hardware and WARP.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:37:19 +00:00
Author
Owner

@⁠Parakeet-Wheat on GitHub · 2026-11-24 23:36 UTC · original

Ran the whole pack on this PR alone, to see where the 5 v_cvt_f32_f64 programs end up.

  • Setup: Windows 11 26300, NVIDIA GeForce RTX 3070 (8 GB, driver 610.88), Ryzen 5 5600X, Rust 1.98.1 (x86_64-pc-windows-msvc), dxil.dll 1.8.2502, title 1.0.2.1; PR head 80cabd3 (on 2119b0e).
  • victory translate <exe> shaders.rpf --list --validate, program by program against 2119b0e: 0 gained, 0 lost (25,382 validated on both). The 5 compute programs refused with "v_cvt_f32_f64" on 2119b0e now get past it, and all 5 stop at "a whole-wave section step the simulation does not follow". So on its own this PR makes none of them translate. They also need the v_add_f64 whole-wave sum that #9 models.
  • cargo test -p victory-shader --locked: 211 passed, 0 failed, 2 ignored (210 on 2119b0e; the new cvt_f32_f64_rounds_to_nearest_even passes).

Offline translation and validation only; no shader contents or extracted data included. AI-assisted (Claude Code); run on my machine.

**@⁠Parakeet-Wheat** on GitHub · 2026-11-24 23:36 UTC · [original](https://github.com/fxceless/victory-fork/pull/163#issuecomment-7147592038) Ran the whole pack on this PR alone, to see where the 5 `v_cvt_f32_f64` programs end up. - **Setup:** Windows 11 26300, NVIDIA GeForce RTX 3070 (8 GB, driver `610.88`), Ryzen 5 5600X, Rust 1.98.1 (`x86_64-pc-windows-msvc`), `dxil.dll` 1.8.2502, title 1.0.2.1; PR head `80cabd3` (on `2119b0e`). - `victory translate <exe> shaders.rpf --list --validate`, program by program against `2119b0e`: **0 gained, 0 lost** (25,382 validated on both). The **5** compute programs refused with *"v_cvt_f32_f64"* on `2119b0e` now get past it, and all 5 stop at *"a whole-wave section step the simulation does not follow"*. So on its own this PR makes none of them translate. They also need the `v_add_f64` whole-wave sum that #9 models. - `cargo test -p victory-shader --locked`: **211 passed, 0 failed, 2 ignored** (210 on `2119b0e`; the new `cvt_f32_f64_rounds_to_nearest_even` passes). *Offline translation and validation only; no shader contents or extracted data included. AI-assisted (Claude Code); run on my machine.*
This pull request has changes conflicting with the target branch.
  • 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/163/head:github-bot/gh-163'
git switch 'github-bot/gh-163'

Merge

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