fix(victory-shader): implement ties-to-even rounding in integer DXIL for NVIDIA #306

Open
github-bot wants to merge 4 commits from github-bot/gh-306 into main AGit
Owner

@⁠mauroalvare on GitHub · 2026-11-26 01:57 UTC · original
mauroalvare:fix/victory-rndne-nvidia → main · +149 −1 · 3 files · 4 commits · open

Change

In VIctory's RDNA2-to-DXIL translator (third_party/victory/crates/victory-shader/src/emit/lower.rs), v_rndne_f32, v_rndne_f16, and v_cvt_pk_u8_f32 lowered round-to-nearest-even to DXIL dx.op.unary.f32(26) (Round_ne).

On NVIDIA driver 621.xx (measured on RTX 5070 Ti 621.40; previously observed in PrototypeScarlett in #227 / PR #260), the driver constant-folds Round_ne(2.5) after a barrier to 3.0 (0x40400000, round half away from zero) instead of 2.0 (0x40000000, ties to even), and replaces NaN payloads with 0x7FFFFFFF (while WARP leaves signalling NaNs unquieted).

Fix:

  • Add Lower::rndne_f32, computing branchless IEEE-754 ties-to-even rounding in 32-bit integer bit arithmetic (matching RDNA 2 for ties-to-even, signed zeros ±0.0, subnormals, integers >= 2^23, infinities, qNaN payload preservation, and sNaN quieting).
  • Route v_rndne_f32, v_rndne_f16, and v_cvt_pk_u8_f32 through Lower::rndne_f32.

Linked issue: Refs #227

Verification

Base SHA: c4c93bdc413191a9dc909998d2d53080a3f0c880 (LooperSalty/AnyXboxX:main)
Hardware: Windows 11, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver 621.40), WARP, dxil.dll 10.0.26100.0, Rust 1.98.1 (MSVC).

Before the fix (failing on base c4c93bd on RTX 5070 Ti):

cargo test --locked -p victory-shader v_rndne_f32_ties_to_even -- --test-threads=1 --nocapture
-> FAILED: hardware: literal v_rndne_f32(0x40200000) = 0x40400000, want 0x40000000

After the fix (from third_party/victory):

cargo test --locked -p victory-shader v_rndne_f32_ties_to_even -- --test-threads=1 --nocapture
-> test result: ok. 1 passed; 0 failed; 0 ignored (validated by dxil.dll; executed on RTX 5070 Ti and WARP)
cargo test --locked -p victory-shader -- --test-threads=1
-> test result: ok. 243 passed; 0 failed; 2 ignored
cargo xtask policy
-> asset policy: 200 files ok

Oracle and test data

The new regression test v_rndne_f32_ties_to_even_and_specials in third_party/victory/crates/victory-shader/src/emit/valu_tests.rs synthesizes minimal GFX10 compute shaders for:

  • dynamic v_rndne_f32 across ties-to-even (±0.5, ±1.5, ±2.5, ±3.5, 4.5, 8388607.5), signed zeros, subnormals, infinities, quiet NaNs (0x7FC00000, 0x7FC00001, 0xFFC00000), and signalling NaNs (0x7F800001, 0xFF800001);
  • literal 2.5, -2.5, 0.5, -0.5 into v_rndne_f32 across s_barrier;
  • literal 2.5 across s_barrier into v_rndne_f16 (0x4100 -> 0x4000) and v_cvt_pk_u8_f32 (2.5 -> 2).

All shaders are validated with dxil.dll and executed bit-for-bit on both RTX 5070 Ti and WARP against IEEE-754 / AMD RDNA 2 ISA semantics. No game, console, or SDK files were used.

Checklist

  • The PR covers a single reviewable behaviour.
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success.
  • README: unchanged (not applicable).
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none (synthetic tests only).
  • Code taken from another project: none (independent DXIL implementation inspired by the NVIDIA Round_ne driver bug identified in #227 / PR #260).

AI assistance: investigated, implemented, tested on RTX 5070 Ti and WARP, and drafted with Antigravity (Gemini).

**@⁠mauroalvare** on GitHub · 2026-11-26 01:57 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/306) `mauroalvare:fix/victory-rndne-nvidia` → `main` · +149 −1 · 3 files · 4 commits · open ## Change In VIctory's RDNA2-to-DXIL translator (`third_party/victory/crates/victory-shader/src/emit/lower.rs`), `v_rndne_f32`, `v_rndne_f16`, and `v_cvt_pk_u8_f32` lowered round-to-nearest-even to DXIL `dx.op.unary.f32(26)` (`Round_ne`). On NVIDIA driver 621.xx (measured on RTX 5070 Ti `621.40`; previously observed in `PrototypeScarlett` in #227 / PR #260), the driver constant-folds `Round_ne(2.5)` after a barrier to `3.0` (`0x40400000`, round half away from zero) instead of `2.0` (`0x40000000`, ties to even), and replaces NaN payloads with `0x7FFFFFFF` (while WARP leaves signalling NaNs unquieted). Fix: - Add `Lower::rndne_f32`, computing branchless IEEE-754 ties-to-even rounding in 32-bit integer bit arithmetic (matching RDNA 2 for ties-to-even, signed zeros `±0.0`, subnormals, integers `>= 2^23`, infinities, qNaN payload preservation, and sNaN quieting). - Route `v_rndne_f32`, `v_rndne_f16`, and `v_cvt_pk_u8_f32` through `Lower::rndne_f32`. Linked issue: Refs #227 ## Verification Base SHA: `c4c93bdc413191a9dc909998d2d53080a3f0c880` (`LooperSalty/AnyXboxX:main`) Hardware: Windows 11, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver `621.40`), WARP, `dxil.dll` `10.0.26100.0`, Rust `1.98.1` (MSVC). Before the fix (failing on base `c4c93bd` on RTX 5070 Ti): ``` cargo test --locked -p victory-shader v_rndne_f32_ties_to_even -- --test-threads=1 --nocapture -> FAILED: hardware: literal v_rndne_f32(0x40200000) = 0x40400000, want 0x40000000 ``` After the fix (from `third_party/victory`): ``` cargo test --locked -p victory-shader v_rndne_f32_ties_to_even -- --test-threads=1 --nocapture -> test result: ok. 1 passed; 0 failed; 0 ignored (validated by dxil.dll; executed on RTX 5070 Ti and WARP) cargo test --locked -p victory-shader -- --test-threads=1 -> test result: ok. 243 passed; 0 failed; 2 ignored cargo xtask policy -> asset policy: 200 files ok ``` ## Oracle and test data The new regression test `v_rndne_f32_ties_to_even_and_specials` in `third_party/victory/crates/victory-shader/src/emit/valu_tests.rs` synthesizes minimal GFX10 compute shaders for: - dynamic `v_rndne_f32` across ties-to-even (`±0.5`, `±1.5`, `±2.5`, `±3.5`, `4.5`, `8388607.5`), signed zeros, subnormals, infinities, quiet NaNs (`0x7FC00000`, `0x7FC00001`, `0xFFC00000`), and signalling NaNs (`0x7F800001`, `0xFF800001`); - literal `2.5`, `-2.5`, `0.5`, `-0.5` into `v_rndne_f32` across `s_barrier`; - literal `2.5` across `s_barrier` into `v_rndne_f16` (`0x4100 -> 0x4000`) and `v_cvt_pk_u8_f32` (`2.5 -> 2`). All shaders are validated with `dxil.dll` and executed bit-for-bit on both RTX 5070 Ti and WARP against IEEE-754 / AMD RDNA 2 ISA semantics. No game, console, or SDK files were used. ## Checklist - [x] The PR covers a single reviewable behaviour. - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. - [x] README: unchanged (not applicable). - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none (synthetic tests only). - [x] Code taken from another project: none (independent DXIL implementation inspired by the NVIDIA `Round_ne` driver bug identified in #227 / PR #260). *AI assistance: investigated, implemented, tested on RTX 5070 Ti and WARP, and drafted with Antigravity (Gemini).*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:42:33 +00:00
github-bot force-pushed github-bot/gh-306 from 2827d7bc4e to e3dfa39f62 2026-11-26 18:40:47 +00:00 Compare
Author
Owner

@⁠mauroalvare on GitHub · 2026-11-26 18:41 UTC · original

The branch was rebased while I was testing. I kept the new commit and pushed a follow-up that moves the rounding helper into its own module, keeping lower.rs under the 512 KiB asset-policy limit. The new arithmetic tests from main and the rounding regression are both present.

The regression reproduced the NVIDIA NaN-payload mismatch on the base and passed on the fix. The full shader suite reported 258 passed and two ignored. GitHub now reports the PR as mergeable.

GitHub Actions for this revision.

**@⁠mauroalvare** on GitHub · 2026-11-26 18:41 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/306#issuecomment-7200745734) The branch was rebased while I was testing. I kept the new commit and pushed a follow-up that moves the rounding helper into its own module, keeping `lower.rs` under the 512 KiB asset-policy limit. The new arithmetic tests from main and the rounding regression are both present. The regression reproduced the NVIDIA NaN-payload mismatch on the base and passed on the fix. The full shader suite reported 258 passed and two ignored. GitHub now reports the PR as mergeable. [GitHub Actions for this revision](https://github.com/LooperSalty/AnyXboxX/actions/runs/45877810557).
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/306/head:github-bot/gh-306'
git switch 'github-bot/gh-306'

Merge

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