Shaders: v_cvt_f32_f64 in 32-bit integer arithmetic #163

Closed
adonizm wants to merge 1 commit from upstream-pr/163 into main
adonizm commented 2026-11-24 22:05:46 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by adonizm on 2026-11-24T22:05:46Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:issue:5481113998 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/163). Originally posted by [adonizm](https://github.com/adonizm) on 2026-11-24T22:05:46Z. --- 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.
Parakeet-Wheat commented 2026-11-25 00:10:08 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Parakeet-Wheat on 2026-11-24T23:36:24Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7147592038 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/163#issuecomment-7147592038). Originally posted by [Parakeet-Wheat](https://github.com/Parakeet-Wheat) on 2026-11-24T23:36:24Z. --- 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.*

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!163
No description provided.