Shaders: lower f64 operations, conversions, and wave sums #54

Open
IAmTheSween wants to merge 1 commit from upstream-pr/54 into main
IAmTheSween commented 2026-11-25 07:06:26 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by IAmTheSween on 2026-11-25T06:27:04Z.


Adds native f64 (IEEE-754 binary64) bitcode encoding, VALU instruction lowering, and 64-bit wave-sum reduction tracking.

What is in it

  • crates/victory-shader/src/emit/bitcode.rs: adds TypeDef::Double, Const::Double(u64), Cast::{FpTrunc, FpExt}, and Module::{double, f64} (no change to bitcode emitted for shaders that do not use double).
  • crates/victory-shader/src/emit/shader.rs: adds shader flags flags::DOUBLE (1 << 2, SFI0 0x1 / D3D_SHADER_REQUIRES_DOUBLES) and flags::DOUBLE_EXT (1 << 6, SFI0 0x20 / D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS, set on int <-> f64 conversions). Verified against dxc.exe -dumpbin (10.0.26100.0).
  • crates/victory-shader/src/emit/lower.rs: adds inline_f64 (128..=208 integers and 240..=248 IEEE-754 doubles), high-dword placement for 32-bit Operand::Literal, make_double (dx.op.makeDouble.f64), split_double (dx.op.splitDouble.f64), f64_src (abs/neg), write_f64 (omod/clamp), wide_sum (dx.op.waveActiveOp.f64 + cross-half exchange), and lowerings for v_add_f64, v_mul_f64, v_cvt_f32_f64, v_cvt_f64_f32, v_cvt_i32_f64, v_cvt_u32_f64, v_cvt_f64_i32, v_cvt_f64_u32.
  • crates/victory-shader/src/emit/wave.rs: adds Sym::Wide, Shape::WideAdd, combine_wide, v_add_f64 pair simulation, and scalar s_mov_b32/s_mov_b64 uni propagation so whole-wave v_add_f64 + cross-lane reductions fold into WideAdd.
  • crates/victory-shader/src/emit/valu_tests.rs: adds GPU execution + dxil.dll validator tests f64_arith_and_conversions_validate_and_match_ieee and f64_wave_reduction_executes_on_gpu.

Why / Relation to #38 and #52

Compute shaders in the water_shading:CS_TransmissionVolumetrics* family cited in #38 (5dc3b25986622949, 6f225b641c5b0708, 926c46bab3b86bd6) accumulate f64 values across the wave with v_add_f64 and cross-lane moves before converting down with v_cvt_f32_f64. While #52 covers v_cvt_f32_f64 on its own, full f64 ops plus wave::Shape::WideAdd recognition are required for those compute shaders to get past the emit stage.

Checked against the five water_shading compute shaders (VICTORY_HOST_WAVE=32):

  • 3 shaders (5dc3b25986622949, 6f225b641c5b0708, a10179ab7eda0dc3) now translate to DXIL and pass dxil.dll validation (10.0.26100.0). On RTX 5070 hardware, their pipeline creation still hits the pre-existing WaveSize(64) fallback on LDS-flag regions addressed separately in #36.
  • 2 shaders (6871d6e4b3ac9a10, 926c46bab3b86bd6) get past all f64 instructions and stop later at an unrelated wave-64 lane-mask error (a lane mask holding lanes elsewhere read as data).

Tested

  • Hardware: NVIDIA GeForce RTX 5070, Windows 11 x64, Windows SDK dxil.dll 10.0.26100.0 (WARP and GPU both exercised).
  • cargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings).
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings).
  • cargo test -p victory-shader --locked: 212 passed, 0 failed, 2 ignored (includes both new f64 GPU tests).
  • cargo test --workspace --locked -- --test-threads=1: all workspace test suites passed with 0 failures (victory 1, victory_core 11, victory_formats 24 / 4 ignored, victory_game 2, victory_gpu 110 / 1 ignored, victory_hle 95 + no_dll_planting 1, victory_loader 24 + load_probe 2 + title_dlls 1, victory_pe 7, victory_pipeline 4, victory_shader 212 / 2 ignored, xtask 4 (repository_passes_policy)). Single-threaded execution was used for the full workspace run due to pre-existing WARP device contention when victory_gpu GPU tests run concurrently (valu_tests.rs:198).

AI use

Written with Antigravity.

<!-- greyfinch-sync:Zettrox/ztrx:issue:6598626598 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/54). Originally posted by [IAmTheSween](https://github.com/IAmTheSween) on 2026-11-25T06:27:04Z. --- Adds native `f64` (IEEE-754 binary64) bitcode encoding, VALU instruction lowering, and 64-bit wave-sum reduction tracking. ### What is in it - **`crates/victory-shader/src/emit/bitcode.rs`**: adds `TypeDef::Double`, `Const::Double(u64)`, `Cast::{FpTrunc, FpExt}`, and `Module::{double, f64}` (no change to bitcode emitted for shaders that do not use `double`). - **`crates/victory-shader/src/emit/shader.rs`**: adds shader flags `flags::DOUBLE` (`1 << 2`, `SFI0` `0x1` / `D3D_SHADER_REQUIRES_DOUBLES`) and `flags::DOUBLE_EXT` (`1 << 6`, `SFI0` `0x20` / `D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS`, set on int <-> f64 conversions). Verified against `dxc.exe -dumpbin` (`10.0.26100.0`). - **`crates/victory-shader/src/emit/lower.rs`**: adds `inline_f64` (`128..=208` integers and `240..=248` IEEE-754 doubles), high-dword placement for 32-bit `Operand::Literal`, `make_double` (`dx.op.makeDouble.f64`), `split_double` (`dx.op.splitDouble.f64`), `f64_src` (`abs`/`neg`), `write_f64` (`omod`/`clamp`), `wide_sum` (`dx.op.waveActiveOp.f64` + cross-half exchange), and lowerings for `v_add_f64`, `v_mul_f64`, `v_cvt_f32_f64`, `v_cvt_f64_f32`, `v_cvt_i32_f64`, `v_cvt_u32_f64`, `v_cvt_f64_i32`, `v_cvt_f64_u32`. - **`crates/victory-shader/src/emit/wave.rs`**: adds `Sym::Wide`, `Shape::WideAdd`, `combine_wide`, `v_add_f64` pair simulation, and scalar `s_mov_b32`/`s_mov_b64` `uni` propagation so whole-wave `v_add_f64` + cross-lane reductions fold into `WideAdd`. - **`crates/victory-shader/src/emit/valu_tests.rs`**: adds GPU execution + `dxil.dll` validator tests `f64_arith_and_conversions_validate_and_match_ieee` and `f64_wave_reduction_executes_on_gpu`. ### Why / Relation to #38 and #52 Compute shaders in the `water_shading:CS_TransmissionVolumetrics*` family cited in #38 (`5dc3b25986622949`, `6f225b641c5b0708`, `926c46bab3b86bd6`) accumulate `f64` values across the wave with `v_add_f64` and cross-lane moves before converting down with `v_cvt_f32_f64`. While #52 covers `v_cvt_f32_f64` on its own, full `f64` ops plus `wave::Shape::WideAdd` recognition are required for those compute shaders to get past the `emit` stage. Checked against the five `water_shading` compute shaders (`VICTORY_HOST_WAVE=32`): - 3 shaders (`5dc3b25986622949`, `6f225b641c5b0708`, `a10179ab7eda0dc3`) now translate to DXIL and pass `dxil.dll` validation (`10.0.26100.0`). On RTX 5070 hardware, their pipeline creation still hits the pre-existing `WaveSize(64)` fallback on LDS-flag regions addressed separately in #36. - 2 shaders (`6871d6e4b3ac9a10`, `926c46bab3b86bd6`) get past all `f64` instructions and stop later at an unrelated wave-64 lane-mask error (`a lane mask holding lanes elsewhere read as data`). ### Tested - Hardware: NVIDIA GeForce RTX 5070, Windows 11 x64, Windows SDK `dxil.dll` `10.0.26100.0` (WARP and GPU both exercised). - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed (0 warnings). - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed (0 warnings). - `cargo test -p victory-shader --locked`: 212 passed, 0 failed, 2 ignored (includes both new `f64` GPU tests). - `cargo test --workspace --locked -- --test-threads=1`: all workspace test suites passed with 0 failures (`victory` 1, `victory_core` 11, `victory_formats` 24 / 4 ignored, `victory_game` 2, `victory_gpu` 110 / 1 ignored, `victory_hle` 95 + `no_dll_planting` 1, `victory_loader` 24 + `load_probe` 2 + `title_dlls` 1, `victory_pe` 7, `victory_pipeline` 4, `victory_shader` 212 / 2 ignored, `xtask` 4 (`repository_passes_policy`)). Single-threaded execution was used for the full workspace run due to pre-existing WARP device contention when `victory_gpu` GPU tests run concurrently (`valu_tests.rs:198`). ### AI use Written with Antigravity.
futurepro62 commented 2026-11-25 16:13:07 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by futurepro62 on 2026-11-25T15:15:01Z.


Full-suite run on Windows, since this PR has no test report yet. Tested exact head 0bd72da (on its base 90b529f).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (rust-toolchain.toml), DXC + dxil.dll 1.9.2602.17, debug.
  • cargo test --workspace --locked: 498 passed, 0 failed, 7 ignored (main 90b529f on this machine: 492 passed, 0 failed, 7 ignored).
  • cargo clippy --workspace --all-targets --locked -- -D warnings (the CI lint step): passed.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings (the CI lint step): passed.
  • The new tests ran and passed: f64_arith_and_conversions_validate_and_match_ieee, f64_wave_reduction_executes_on_gpu.

Not tested

  • AMD (ztrx targets NVIDIA), a release build, the game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Zettrox/ztrx:comment:7166541301 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/54#issuecomment-7166541301). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-25T15:15:01Z. --- Full-suite run on Windows, since this PR has no test report yet. Tested exact head `0bd72da` (on its base `90b529f`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (`rust-toolchain.toml`), DXC + dxil.dll 1.9.2602.17, debug. - `cargo test --workspace --locked`: **498 passed, 0 failed, 7 ignored** (main `90b529f` on this machine: 492 passed, 0 failed, 7 ignored). - `cargo clippy --workspace --all-targets --locked -- -D warnings` (the CI lint step): passed. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` (the CI lint step): passed. - The new tests ran and passed: `f64_arith_and_conversions_validate_and_match_ieee`, `f64_wave_reduction_executes_on_gpu`. **Not tested** - AMD (ztrx targets NVIDIA), a release build, the game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/54:upstream-pr/54'
git switch 'upstream-pr/54'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/54'
git switch 'upstream-pr/54'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/54'
git switch 'upstream-pr/54'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/54'
git switch 'main'
git merge --squash 'upstream-pr/54'
git switch 'main'
git merge --ff-only 'upstream-pr/54'
git switch 'main'
git merge 'upstream-pr/54'
git push origin 'main'
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
Zettrox/ztrx!54
No description provided.