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

Merged
mauroalvare merged 6 commits from upstream-pr/306 into main 2026-11-27 19:38:44 +00:00
mauroalvare commented 2026-11-26 01:57:18 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-26T01:57:18Z.


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

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5502569268 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/306). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-26T01:57:18Z. --- ## 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).*
mauroalvare commented 2026-11-26 18:41:30 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-26T18:41:30Z.


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.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7200745734 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/306#issuecomment-7200745734). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-26T18:41:30Z. --- 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).
LooperSalty commented 2026-11-27 16:24:27 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T16:24:27Z.


Thanks, the integer ties-to-even sequence reads correctly. Two Round_ne call sites are still left on the DXIL op: lower.rs:4540 (let whole = self.unary(26, x), the trig range reduction) and lower.rs:12289 (self.unary(26, lod), LOD rounding). On the NVIDIA drivers where op 26 folds half-way cases, these still round 0.5 differently from RDNA 2. Please route them through rndne_f32 too, or say in the commit why they are exempt (for example if a half-way input cannot reach them).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7223224420 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/306#issuecomment-7223224420). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T16:24:27Z. --- Thanks, the integer ties-to-even sequence reads correctly. Two `Round_ne` call sites are still left on the DXIL op: `lower.rs:4540` (`let whole = self.unary(26, x)`, the trig range reduction) and `lower.rs:12289` (`self.unary(26, lod)`, LOD rounding). On the NVIDIA drivers where op 26 folds half-way cases, these still round 0.5 differently from RDNA 2. Please route them through `rndne_f32` too, or say in the commit why they are exempt (for example if a half-way input cannot reach them).
mauroalvare commented 2026-11-27 17:20:35 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T17:20:35Z.


Addressed in dd63f35: routed the two remaining \dx.op.unary.f32(26, ...)\ sites (\ rig_turns\ and \image_gather4_l\ explicit LOD rounding) through
ndne_f32\ so zero \Round_ne\ DXIL op 26 calls remain, and bumped \TRANSLATOR_VERSION\ (\2 -> 3). Re-verified on RTX 5070 Ti + WARP + \dxil.dll\ (\cargo test --locked -p victory-shader -- --test-threads=1: 318 passed, 0 failed, 4 ignored; \cargo xtask policy: 286 files ok).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7224298779 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/306#issuecomment-7224298779). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-27T17:20:35Z. --- Addressed in dd63f35: routed the two remaining \dx.op.unary.f32(26, ...)\ sites (\ rig_turns\ and \image_gather4_l\ explicit LOD rounding) through \ ndne_f32\ so zero \Round_ne\ DXIL op 26 calls remain, and bumped \TRANSLATOR_VERSION\ (\2 -> 3\). Re-verified on RTX 5070 Ti + WARP + \dxil.dll\ (\cargo test --locked -p victory-shader -- --test-threads=1\: 318 passed, 0 failed, 4 ignored; \cargo xtask policy\: 286 files ok).
LooperSalty commented 2026-11-27 17:31:04 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T17:31:04Z.


Thanks, both remaining sites are covered now. One collision: this bumps TRANSLATOR_VERSION to 3, but #456 (open) also sets 3, and #485 now sets 4. If both #306 and #456 land at 3, a cache built with only one of them would be reused after the other merges, and serve stale DXIL. Each merged translation change needs its own value, so please take the next free one (5 today) or, if this lands right after another bump, rebase and bump again.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7224494761 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/306#issuecomment-7224494761). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T17:31:04Z. --- Thanks, both remaining sites are covered now. One collision: this bumps `TRANSLATOR_VERSION` to 3, but #456 (open) also sets 3, and #485 now sets 4. If both #306 and #456 land at 3, a cache built with only one of them would be reused after the other merges, and serve stale DXIL. Each merged translation change needs its own value, so please take the next free one (5 today) or, if this lands right after another bump, rebase and bump again.
mauroalvare commented 2026-11-27 17:57:27 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T17:57:27Z.


Updated TRANSLATOR_VERSION to 5 in 40554f0 (leaving 3 for #456 and 4 for #485; will re-bump if another version change merges ahead of this). Re-verified v_rndne_f32_ties_to_even_and_specials and cargo xtask policy (286 files ok).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7224966074 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/306#issuecomment-7224966074). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-27T17:57:27Z. --- Updated `TRANSLATOR_VERSION` to `5` in `40554f0` (leaving `3` for #456 and `4` for #485; will re-bump if another version change merges ahead of this). Re-verified `v_rndne_f32_ties_to_even_and_specials` and `cargo xtask policy` (286 files ok).
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
LooperSalty/AnyXboxX!306
No description provided.