Shaders: lower nearest-even binary64 rounding #2647

Open
github-bot wants to merge 2 commits from github-bot/gh-2647 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 17:30 UTC · original
andrewpozdnakov7-jpg:codex2/rndne-f64 → main · +192 −0 · 3 files · 2 commits · open

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].

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 17:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2647) `andrewpozdnakov7-jpg:codex2/rndne-f64` → `main` · +192 −0 · 3 files · 2 commits · open ## 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://git.gtahub.st/github/Marvisak--VIctory/issues/1633) 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]>.
Round both words of V_RNDNE_F64 with 32-bit DXIL operations. The same VOP1 and VOP3 shaders fail to lower on main and read back the expected values on WARP after the patch.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:11:09 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:53 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2647#issuecomment-7170144249) 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.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 17:58 UTC · original

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.

**@⁠oni-swr** on GitHub · 2026-11-25 17:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2647#issuecomment-7170255116) **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`.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 18:16 UTC · original

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 18:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2647#issuecomment-7170688236) 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.
Author
Owner

@⁠Mericas77 on GitHub · 2026-11-25 18:27 UTC · original

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.

**@⁠Mericas77** on GitHub · 2026-11-25 18:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2647#issuecomment-7170944332) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:17 UTC · original · edited 2026-11-26 03:25 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 22:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2647#issuecomment-7176184180) · edited 2026-11-26 03:25 UTC <!-- 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)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2647'
git switch 'github-bot/gh-2647'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2647'
git switch 'github-bot/gh-2647'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2647'
git switch 'main'
git merge --squash 'github-bot/gh-2647'
git switch 'main'
git merge --ff-only 'github-bot/gh-2647'
git switch 'main'
git merge 'github-bot/gh-2647'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2647
No description provided.