Shaders: lower nearest-even binary64 rounding #2645

Open
andrewpozdnakov7-jpg wants to merge 2 commits from upstream-pr/2647 into main
andrewpozdnakov7-jpg commented 2026-11-25 17:30:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T17:30:35Z.


Problem

The shader decoder recognizes V_RNDNE_F64, but lowering rejects it in both VOP1 and VOP3. The instruction rounds a binary64 value to a whole number, with halfway values rounded to even. AMD RDNA 2 ISA reference, VOP1 instructions

Change

Round the binary64 bit pattern using its two 32-bit words, including the carry across the words and the signed-zero result for small magnitudes. Apply the source sign modifiers before rounding. The generated DXIL does not require optional double-precision or Int64 shader features.

Verification

  • The same two synthetic shader tests fail with Unsupported v_rndne_f64 on main 13f91ca and pass after the patch. The VOP1 fixture compares both result words for 28 values through VGPR and SGPR pairs. It covers ties, values adjacent to halfway, signed zero, subnormals, the 31/32/33-bit fractional boundary, and infinities. The VOP3 fixture checks a negated literal and the DXIL feature flags.
  • 32 project VALU tests and a temporary runtime identity test passed on app-local WARP SM 6.6 with the DXIL validator. Strict victory-shader Clippy and the staged policy also passed.

Coordination claim

AI-assisted (Codex 2). Please retain the Git author on cherry-pick or rebase. If folding this change into another commit, please retain Co-authored-by: andrewpozdnakov7-jpg [email protected].

<!-- greyfinch-sync:Marvisak/VIctory:issue:5496058472 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2647). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T17:30:35Z. --- ## Problem The shader decoder recognizes V_RNDNE_F64, but lowering rejects it in both VOP1 and VOP3. The instruction rounds a binary64 value to a whole number, with halfway values rounded to even. [AMD RDNA 2 ISA reference, VOP1 instructions](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture) ## Change Round the binary64 bit pattern using its two 32-bit words, including the carry across the words and the signed-zero result for small magnitudes. Apply the source sign modifiers before rounding. The generated DXIL does not require optional double-precision or Int64 shader features. ## Verification - The same two synthetic shader tests fail with Unsupported v_rndne_f64 on main 13f91ca and pass after the patch. The VOP1 fixture compares both result words for 28 values through VGPR and SGPR pairs. It covers ties, values adjacent to halfway, signed zero, subnormals, the 31/32/33-bit fractional boundary, and infinities. The VOP3 fixture checks a negated literal and the DXIL feature flags. - 32 project VALU tests and a temporary runtime identity test passed on app-local WARP SM 6.6 with the DXIL validator. Strict victory-shader Clippy and the staged policy also passed. [Coordination claim](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7169478115) AI-assisted (Codex 2). Please retain the Git author on cherry-pick or rebase. If folding this change into another commit, please retain Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.
kotekompotek commented 2026-11-25 18:02:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T17:53:32Z.


Reviewed: lowering v_rndne_f64 without requiring host doubles is the right direction (GTX hosts lack f64). Source operand handling covers register pairs, inline constants (incl. the sign-extended const range 193–208), and literal high words. CI green.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170144249 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2647#issuecomment-7170144249). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T17:53:32Z. --- Reviewed: lowering `v_rndne_f64` without requiring host doubles is the right direction (GTX hosts lack f64). Source operand handling covers register pairs, inline constants (incl. the sign-extended const range 193–208), and literal high words. CI green.
oni-swr commented 2026-11-25 18:02:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T17:58:13Z.


Independent verification of head 7636aedbe624fcae2c7bb0c970798dba70708186 merged onto origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca.

  • Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1 (48a229cea 2026-09-01), -j 4, WARP only (VICTORY_WARP=1, VICTORY_D3D12_WARP=1; d3d10warp 10.0.26100.9818), DXC/DXIL 1.8.2502.11 (Windows SDK 10.0.26100.0 x64 dxil.dll on PATH). No physical GPU device was created by the test runs. The new tests run on WARP (run_cases uses Host::new, which honours VICTORY_WARP=1 for both of its loop labels).
  • Diff: lower.rs (v_rndne_f64 lowering without host doubles/i64) plus 2 tests in valu_tests.rs. Merges cleanly.
  • clippy (-p victory-shader --all-targets): no warnings.
  • cargo test --locked --no-fail-fast -p victory-shader: 269 passed, 3 failed, 3 ignored (origin/main: 267/3/3). The 3 failures are the same pre-existing WARP baseline ones (a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out: "no pipeline for a wave of 32"); the 2 new tests pass.
  • Negative control: with the new tests kept and the "v_rndne_f64" dispatch line removed, both v_rndne_f64_rounds_ties_to_even_across_both_words and v_rndne_f64_rounds_a_negated_vop3_literal fail.
  • Found: no bugs. Coverage is the listed values plus the SFI0 check that no doubles/int64 features are required; it is not an exhaustive sweep.

Independent verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or shader names were used. Each PR head was merged (no conflicts) onto origin/main and run with --locked; clippy used --all-targets.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170255116 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2647#issuecomment-7170255116). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T17:58:13Z. --- **Independent verification** of head `7636aedbe624fcae2c7bb0c970798dba70708186` merged onto `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca`. - Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1 (48a229cea 2026-09-01), `-j 4`, WARP only (`VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`; d3d10warp 10.0.26100.9818), DXC/DXIL 1.8.2502.11 (Windows SDK 10.0.26100.0 x64 dxil.dll on PATH). No physical GPU device was created by the test runs. The new tests run on WARP (`run_cases` uses `Host::new`, which honours `VICTORY_WARP=1` for both of its loop labels). - Diff: `lower.rs` (`v_rndne_f64` lowering without host doubles/i64) plus 2 tests in `valu_tests.rs`. Merges cleanly. - clippy (`-p victory-shader --all-targets`): no warnings. - `cargo test --locked --no-fail-fast -p victory-shader`: **269 passed, 3 failed, 3 ignored** (`origin/main`: 267/3/3). The 3 failures are the same pre-existing WARP baseline ones (`a_mask_joined_with_data_at_a_uniform_loop_is_its_number`, `gathers_at_a_level_match_the_hardware`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`: "no pipeline for a wave of 32"); the 2 new tests pass. - **Negative control:** with the new tests kept and the `"v_rndne_f64"` dispatch line removed, both `v_rndne_f64_rounds_ties_to_even_across_both_words` and `v_rndne_f64_rounds_a_negated_vop3_literal` **fail**. - Found: no bugs. Coverage is the listed values plus the SFI0 check that no doubles/int64 features are required; it is not an exhaustive sweep. Independent verification by Claude Code (Claude Sonnet 5.5), an AI. No game files, dumps or shader names were used. Each PR head was merged (no conflicts) onto `origin/main` and run with `--locked`; clippy used `--all-targets`.
fuzeofficlal commented 2026-11-25 19:06:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T18:16:41Z.


Tested 7636aedb merged cleanly onto main (13f91ca) on Windows 11 with NVIDIA GeForce RTX 5090 (32.0.16.1656), D3D12 WARP, and Windows SDK dxil.dll:

  • RTX 5090 + WARP (cargo test -p victory-shader --lib v_rndne_f64): 2 passed, 0 failed (v_rndne_f64_rounds_ties_to_even_across_both_words and v_rndne_f64_rounds_a_negated_vop3_literal pass on both adapters with dxil.dll validation and no doubles/int64 SFI0 feature bits set)
  • WARP (VICTORY_WARP=1 cargo test -p victory-shader --lib emit::valu_tests): 32 passed, 0 failed
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean (0 warnings)

Walked through the bit-level ties-to-even paths (±0.0, subnormals, |x| < 1.0, n == 32, n == 33..=52 including n = 52, n == 1..=31 cross-word carry, |x| >= 2^52, ±inf, NaN) — all look clean.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170688236 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2647#issuecomment-7170688236). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T18:16:41Z. --- Tested `7636aedb` merged cleanly onto `main` (`13f91ca`) on Windows 11 with **NVIDIA GeForce RTX 5090** (`32.0.16.1656`), **D3D12 WARP**, and Windows SDK `dxil.dll`: - RTX 5090 + WARP (`cargo test -p victory-shader --lib v_rndne_f64`): **2 passed, 0 failed** (`v_rndne_f64_rounds_ties_to_even_across_both_words` and `v_rndne_f64_rounds_a_negated_vop3_literal` pass on both adapters with `dxil.dll` validation and no `doubles`/`int64` `SFI0` feature bits set) - WARP (`VICTORY_WARP=1 cargo test -p victory-shader --lib emit::valu_tests`): **32 passed, 0 failed** - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean (0 warnings) Walked through the bit-level ties-to-even paths (`±0.0`, subnormals, `|x| < 1.0`, `n == 32`, `n == 33..=52` including `n = 52`, `n == 1..=31` cross-word carry, `|x| >= 2^52`, `±inf`, `NaN`) — all look clean.
Mericas77 commented 2026-11-25 19:06:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Mericas77 on 2026-11-25T18:27:57Z.


Tested on NVIDIA: RTX 4070 (the only adapter), driver 621.01, Windows 11, rustc 1.98.1. Head 7636aed against main 13f91ca.

  • v_rndne_f64_rounds_ties_to_even_across_both_words and v_rndne_f64_rounds_a_negated_vop3_literal: 2/2 pass, through run_cases, so on the NVIDIA hardware adapter as well as WARP (no skipped line).
  • cargo test -p victory-shader --lib --locked (with --skip heap_direct_texture_reads_mark_their_heap_index, which crashes the process on main here, #2571): main 266 passed / 3 failed / 3 ignored, this PR 268 / 3 / 3. The 3 failures are the known NVIDIA ones on main (a_heap_buffer_read_by_element_takes_the_views_stride, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, gathers_at_a_level_match_the_hardware) and are the same.

So the lowering gives the same bits on NVIDIA hardware, no regression. No game data; the title was not run.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170944332 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2647#issuecomment-7170944332). Originally posted by [Mericas77](https://github.com/Mericas77) on 2026-11-25T18:27:57Z. --- Tested on NVIDIA: RTX 4070 (the only adapter), driver 621.01, Windows 11, rustc 1.98.1. Head `7636aed` against `main` `13f91ca`. - `v_rndne_f64_rounds_ties_to_even_across_both_words` and `v_rndne_f64_rounds_a_negated_vop3_literal`: **2/2 pass**, through `run_cases`, so on the NVIDIA hardware adapter as well as WARP (no `skipped` line). - `cargo test -p victory-shader --lib --locked` (with `--skip heap_direct_texture_reads_mark_their_heap_index`, which crashes the process on `main` here, #2571): `main` 266 passed / 3 failed / 3 ignored, this PR 268 / 3 / 3. The 3 failures are the known NVIDIA ones on `main` (`a_heap_buffer_read_by_element_takes_the_views_stride`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `gathers_at_a_level_match_the_hardware`) and are the same. So the lowering gives the same bits on NVIDIA hardware, no regression. No game data; the title was not run. AI-assisted.
Marvisak commented 2026-11-25 23:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:17:47Z.


Automated triage for the maintainers.

Verdict: merge candidate (unchanged). The new head c49835a merges main and moves round_ne_f64 from emit/lower.rs into crates/victory-shader/src/emit/lower/rndne.rs. I compared it with the reviewed 7636aed. The function body is the same apart from rustfmt line breaks and pub(super), the v_rndne_f64 dispatch line in lower.rs is unchanged, and the valu_tests.rs additions are identical. My earlier review of the rounding arithmetic still applies.

The branch contains a merge commit from main, so a squash merge would keep the history tidy.

CI: passing (check). Merges cleanly.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176184180 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2647#issuecomment-7176184180). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:17:47Z. --- <!-- victory-triage v1 head=c49835aebf1919435a1f02de69ac8a4178d7483c verdict=merge-candidate at=2026-11-26T03:25:03Z --> Automated triage for the maintainers. **Verdict: merge candidate** (unchanged). The new head `c49835a` merges `main` and moves `round_ne_f64` from `emit/lower.rs` into `crates/victory-shader/src/emit/lower/rndne.rs`. I compared it with the reviewed `7636aed`. The function body is the same apart from `rustfmt` line breaks and `pub(super)`, the `v_rndne_f64` dispatch line in `lower.rs` is unchanged, and the `valu_tests.rs` additions are identical. My earlier review of the rounding arithmetic still applies. The branch contains a merge commit from `main`, so a squash merge would keep the history tidy. CI: passing (`check`). Merges cleanly. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 04:47:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T04:47:27Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, dxil.dll validator active):

  • cargo test -p victory-shader --lib emit::valu_tests::v_rndne_f64: 2 passed, 0 failed (v_rndne_f64_rounds_ties_to_even_across_both_words and v_rndne_f64_rounds_a_negated_vop3_literal pass on both RTX 5090 hardware and WARP).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6068684989 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2647#pullrequestreview-6068684989). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T04:47:27Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, `dxil.dll` validator active): - `cargo test -p victory-shader --lib emit::valu_tests::v_rndne_f64`: **2 passed, 0 failed** (`v_rndne_f64_rounds_ties_to_even_across_both_words` and `v_rndne_f64_rounds_a_negated_vop3_literal` pass on both RTX 5090 hardware and WARP). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 192 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-27 02:26:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T02:26:35Z.

Review: APPROVED


Reviewed c49835aebf1919435a1f02de69ac8a4178d7483c.

LGTM — Lower::round_ne_f64 accurately lowers v_rndne_f64 using pure 32-bit integer DXIL ops (no DOUBLE/INT64 SFI0 feature bits), handling ties-to-even with implicit units bit at exp = 0, cross-word sticky/parity carries across exp = 19/20/21, subnormals, ±0.0, ±Inf, and abs/neg modifiers before rounding.

Verified locally on RTX 5090 + WARP:

  • cargo xtask policy (192 files ok), cargo clippy -p victory-shader --all-targets / --all-features (-D warnings), and rustfmt --edition 2024 --check on rndne.rs pass cleanly (zero new rustfmt diffs in lower.rs; lower.rs is 520,635 bytes).
  • Both new v_rndne_f64_* tests pass under VICTORY_WARP=0 and VICTORY_WARP=1 with SFI0 & 0x8001 == 0, and emit::lower::tests passes (33 passed).

Non-blocking notes:

  • rustfmt --edition 2024 --check flags one line-wrapping diff on the new assert_eq! at crates/victory-shader/src/emit/valu_tests.rs:622.
  • NaN payloads pass through unchanged and clamp/omod modifiers return an unsupported error.
<!-- greyfinch-sync:Marvisak/VIctory:review:6082685565 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2647#pullrequestreview-6082685565). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T02:26:35Z. **Review:** APPROVED --- Reviewed `c49835aebf1919435a1f02de69ac8a4178d7483c`. **LGTM** — `Lower::round_ne_f64` accurately lowers `v_rndne_f64` using pure 32-bit integer DXIL ops (no `DOUBLE`/`INT64` `SFI0` feature bits), handling ties-to-even with implicit units bit at `exp = 0`, cross-word sticky/parity carries across `exp = 19/20/21`, subnormals, `±0.0`, `±Inf`, and `abs`/`neg` modifiers before rounding. Verified locally on RTX 5090 + WARP: - `cargo xtask policy` (`192 files ok`), `cargo clippy -p victory-shader --all-targets` / `--all-features` (`-D warnings`), and `rustfmt --edition 2024 --check` on `rndne.rs` pass cleanly (zero new `rustfmt` diffs in `lower.rs`; `lower.rs` is 520,635 bytes). - Both new `v_rndne_f64_*` tests pass under `VICTORY_WARP=0` and `VICTORY_WARP=1` with `SFI0 & 0x8001 == 0`, and `emit::lower::tests` passes (33 passed). Non-blocking notes: - `rustfmt --edition 2024 --check` flags one line-wrapping diff on the new `assert_eq!` at `crates/victory-shader/src/emit/valu_tests.rs:622`. - NaN payloads pass through unchanged and `clamp`/`omod` modifiers return an unsupported error.
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/2647:upstream-pr/2647'
git switch 'upstream-pr/2647'

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/2647'
git switch 'upstream-pr/2647'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2647'
git switch 'upstream-pr/2647'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2647'
git switch 'main'
git merge --squash 'upstream-pr/2647'
git switch 'main'
git merge --ff-only 'upstream-pr/2647'
git switch 'main'
git merge 'upstream-pr/2647'
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
Marvisak/VIctory!2645
No description provided.