fix: match RDNA2 rounded f32-to-i32 conversions in VIctory #321

Merged
mauroalvare merged 6 commits from upstream-pr/321 into main 2026-11-27 19:38:44 +00:00
mauroalvare commented 2026-11-26 02:50:36 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-26T02:50:36Z.


Change

Neptune lowered v_cvt_rpi_i32_f32 as a binary32 add of 0.5 followed by floor. On the RTX 5070 Ti, the float immediately below 0.5 returned 1 where the RDNA 2 result is 0. The same shader also returned 0 for a positive NaN, which should saturate to INT32_MAX in the rounded forms.

Use the in-tree HLSL recompiler's floor-and-fraction rule for RPI and apply the source modifiers at the bit level for the rounded conversions. RPI and FLR select the saturation endpoint from the resulting NaN sign. The fixtures also cover truncating conversions as a NaN-to-zero control.

The change is in the Rust DXIL emitter used by Neptune through tools/lancer_victory.ps1.

Verification

Base c4c93bdc413191a9dc909998d2d53080a3f0c880. Fix c6385d8cb05f59f774b32076818899e9f57456cc.

The synthetic shaders take f32 bits from root constants and store one converted dword to a UAV. The SDK DXIL validator accepted the shaders and the D3D12 pipelines ran on the RTX 5070 Ti (driver 621.40, 32-lane waves) and WARP (4-lane waves). The fix matched all 112 expected outputs per adapter. The cases include VOP1 and VOP3, halfway values, large odd integers, saturation limits, infinities, and quiet and signaling NaNs under the four VOP3 abs/neg combinations. The AnyXboxX interpreter independently agreed on the same 112 expected outputs.

From third_party/victory:

cargo test --locked --offline -j 2 -p victory-shader --lib rounded_f32_to_i32_ -- --nocapture --test-threads=1
Base with tests: 0 passed, 2 failed, 244 filtered out.
  RTX VOP1 RPI 0x3effffff: got 1, expected 0.
  RTX RPI 0x7fc00000: got 0, expected 2147483647.
Fix: 2 passed, 0 failed, 244 filtered out.

cargo test --locked --offline -p victory-shader -- --nocapture --test-threads=1
244 passed, 0 failed, 2 ignored.

cargo test --locked --offline -p victory-loader --test load_probe
2 passed, 0 failed.

cargo xtask policy
asset policy: 199 files ok

cargo check --locked --offline -j 2 -p victory
Passed, with two warnings emitted by victory-gpu.

The shader suite also reports four console-compiler comparisons that skip locally and two adapter-specific skips in existing wave-sum tests.

From the repository root, with ANYXBOXX_REQUIRE_RUNTIME=1, the SDK's DXC, and the C++/Rust/TomBox binaries already built in this worktree from the same base:

python -m pytest -rs
1665 passed, 0 skipped (87.76 s, Python 3.13.15).

python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools
All checks passed!

Oracle and test data

All shader words and inputs are constructed in the tests. AMD's ISA defines the conversion rules, and Lyrnc's published gfx1036 measurements establish the exact RPI threshold and NaN saturation. The original Rust change here also verifies VOP3 source sign modifiers in Neptune on Windows. AMD RDNA 2 ISA, §12.8 · gfx1036 measurements · In-tree HLSL reference

  • One reviewable behavior with synthetic regressions that fail on the base.
  • Verification commands, skips and results are recorded above.
  • README consistency checked by the full pytest suite.

AI assistance from OpenAI Codex for investigation, implementation and validation.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5503099953 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/321). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-26T02:50:36Z. --- ## Change Neptune lowered `v_cvt_rpi_i32_f32` as a binary32 add of 0.5 followed by floor. On the RTX 5070 Ti, the float immediately below 0.5 returned 1 where the RDNA 2 result is 0. The same shader also returned 0 for a positive NaN, which should saturate to `INT32_MAX` in the rounded forms. Use the in-tree HLSL recompiler's floor-and-fraction rule for RPI and apply the source modifiers at the bit level for the rounded conversions. RPI and FLR select the saturation endpoint from the resulting NaN sign. The fixtures also cover truncating conversions as a NaN-to-zero control. The change is in the Rust DXIL emitter used by Neptune through `tools/lancer_victory.ps1`. ## Verification Base `c4c93bdc413191a9dc909998d2d53080a3f0c880`. Fix `c6385d8cb05f59f774b32076818899e9f57456cc`. The synthetic shaders take f32 bits from root constants and store one converted dword to a UAV. The SDK DXIL validator accepted the shaders and the D3D12 pipelines ran on the RTX 5070 Ti (driver 621.40, 32-lane waves) and WARP (4-lane waves). The fix matched all 112 expected outputs per adapter. The cases include VOP1 and VOP3, halfway values, large odd integers, saturation limits, infinities, and quiet and signaling NaNs under the four VOP3 abs/neg combinations. The AnyXboxX interpreter independently agreed on the same 112 expected outputs. From `third_party/victory`: ```text cargo test --locked --offline -j 2 -p victory-shader --lib rounded_f32_to_i32_ -- --nocapture --test-threads=1 Base with tests: 0 passed, 2 failed, 244 filtered out. RTX VOP1 RPI 0x3effffff: got 1, expected 0. RTX RPI 0x7fc00000: got 0, expected 2147483647. Fix: 2 passed, 0 failed, 244 filtered out. cargo test --locked --offline -p victory-shader -- --nocapture --test-threads=1 244 passed, 0 failed, 2 ignored. cargo test --locked --offline -p victory-loader --test load_probe 2 passed, 0 failed. cargo xtask policy asset policy: 199 files ok cargo check --locked --offline -j 2 -p victory Passed, with two warnings emitted by victory-gpu. ``` The shader suite also reports four console-compiler comparisons that skip locally and two adapter-specific skips in existing wave-sum tests. From the repository root, with `ANYXBOXX_REQUIRE_RUNTIME=1`, the SDK's DXC, and the C++/Rust/TomBox binaries already built in this worktree from the same base: ```text python -m pytest -rs 1665 passed, 0 skipped (87.76 s, Python 3.13.15). python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools All checks passed! ``` ## Oracle and test data All shader words and inputs are constructed in the tests. AMD's ISA defines the conversion rules, and Lyrnc's published gfx1036 measurements establish the exact RPI threshold and NaN saturation. The original Rust change here also verifies VOP3 source sign modifiers in Neptune on Windows. [AMD RDNA 2 ISA, §12.8](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content) · [gfx1036 measurements](https://github.com/Marvisak/VIctory/pull/605#issuecomment-7123302580) · [In-tree HLSL reference](https://github.com/LooperSalty/AnyXboxX/blob/c4c93bdc413191a9dc909998d2d53080a3f0c880/PrototypeScarlett/emu/rdna2_hlsl_helpers.py#L37-L44) - [x] One reviewable behavior with synthetic regressions that fail on the base. - [x] Verification commands, skips and results are recorded above. - [x] README consistency checked by the full pytest suite. AI assistance from OpenAI Codex for investigation, implementation and validation.
LooperSalty commented 2026-11-27 13:03:10 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T13:03:10Z.


Rebase on current main (fa6b209e) is needed: recent merges into main now conflict with this PR. Please rebase and push so the PR can be reviewed again.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7218997688 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/321#issuecomment-7218997688). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T13:03:10Z. --- Rebase on current main (fa6b209e) is needed: recent merges into main now conflict with this PR. Please rebase and push so the PR can be reviewed again.
mauroalvare commented 2026-11-27 17:02:05 +00:00 (Migrated from github.com)

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


Updated this PR to a4453083. I retained the binary64 comparison tests from #313 alongside this PR's two rounded-conversion regressions. Both conversion tests passed locally.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7223950422 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/321#issuecomment-7223950422). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-27T17:02:05Z. --- Updated this PR to `a4453083`. I retained the binary64 comparison tests from #313 alongside this PR's two rounded-conversion regressions. Both conversion tests passed locally.
LooperSalty commented 2026-11-27 17:31:06 +00:00 (Migrated from github.com)

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


This changes the DXIL of the rounded f32-to-i32 conversions for shaders that translated before, so TRANSLATOR_VERSION (victory-shader/src/lib.rs) needs a bump, as its doc comment asks; otherwise caches from earlier builds keep serving the old rounding. Please take the next free value (#456 uses 3, #485 4, #306 asks for 5) and re-bump if another one lands first.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7224495569 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/321#issuecomment-7224495569). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T17:31:06Z. --- This changes the DXIL of the rounded f32-to-i32 conversions for shaders that translated before, so `TRANSLATOR_VERSION` (`victory-shader/src/lib.rs`) needs a bump, as its doc comment asks; otherwise caches from earlier builds keep serving the old rounding. Please take the next free value (#456 uses 3, #485 4, #306 asks for 5) and re-bump if another one lands first.
mauroalvare commented 2026-11-27 17:57:30 +00:00 (Migrated from github.com)

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


Bumped TRANSLATOR_VERSION to 6 in c2c2cc0 (leaving 3 for #456, 4 for #485, 5 for #306; will re-bump if another translation bump lands first). Re-verified both rounded_f32_to_i32_* tests and cargo xtask policy (286 files ok).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7224966877 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/321#issuecomment-7224966877). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-27T17:57:30Z. --- Bumped `TRANSLATOR_VERSION` to `6` in `c2c2cc0` (leaving `3` for #456, `4` for #485, `5` for #306; will re-bump if another translation bump lands first). Re-verified both `rounded_f32_to_i32_*` tests 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!321
No description provided.