Shaders: 64-bit integer compares on their dwords (backport of Marvisak/VIctory#1599, reproduced on an RX 7900 XT) #1506

Open
murillojndem wants to merge 1 commit from upstream-pr/1506 into main
murillojndem commented 2026-11-28 05:51:35 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by murillojndem on 2026-11-28T05:51:35Z.


v_cmp_{lt,le,gt,ge,eq,ne}_{i64,u64} (and the v_cmpx_ forms, which reach the same code) are lowered to one icmp on an i64 built from two dwords. AMD's D3D12 compiler gets the order wrong when the two operands share a dword: v_cmp_lt_i64 s20, v[1:2], v[2:3] with v1 = v2 = 0 and v3 = 1 asks whether 0 < 0x1_00000000, and the card answers false. WARP answers true.

This is a backport of Marvisak/VIctory#1599, merged upstream on 25 November as cc7ec2a (by alexdeliu). This fork's #135 is the same change by the same author; it conflicts since the tree moved to the VIctory-NVIDIA base. The compare now runs on the dwords: the high dwords decide (signed for i64), and equal high dwords leave it to the low dwords (unsigned). It no longer needs INT64. The added and removed lines are the same as in cc7ec2a; only the offsets differ (the helper sits before f64_pair here and before split64 upstream). The test is upstream's: all twelve compares over values whose dword orders disagree, on disjoint and on shared register pairs.

On other cards: upstream merged these lines for every host, and #135 cites an RTX 4070 Ti that agrees with WARP on this compare. The dword form gives the same answers wherever the i64 compare is right. It was not run on an NVIDIA card here; the RX 7900 XT and WARP are the two devices tested.

Tested on an AMD Radeon RX 7900 XT (RDNA 3, 20 GB, driver 32.0.32015.7029), Windows 11, Rust 1.98.1, on 6b3ce6c (current main) and first on 9e90746; the two commits between them do not touch lower.rs or valu_tests.rs. Synthetic shaders only; no game files.

  • Without the lowering change, v_cmp_u64_and_i64_order_by_the_high_dword fails on the card: hardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000), 0 where 1 is right. That is the first failure reported on an RX 9070, a gfx1036 iGPU and an RX 7700.
  • A census over the same values with the lowering of 9e90746 (a local probe, not in this PR) runs every case: on the card only the shared form v[1:2], v[2:3] is wrong, and only for the ordered compares. lt, le, gt and ge get 28 or 29 of 100 cases wrong for _i64 and 49 to 56 of 100 for _u64. eq, ne and the disjoint form v[1:2], v[3:4] have no mismatch. WARP has none.
  • With the lowering change, the test passes on the card and on WARP. rdna_forms_give_what_the_spelled_out_ones_give ran in the same binary without its "no RDNA card" line, so the hardware device was the Radeon.
  • On 9e90746, cargo test -p victory-shader --lib with VICTORY_WARP=1: 288 passed, 7 failed, 4 ignored. The same 7 fail there without the change (287 passed). Three are PSV0 mismatches with the dxil.dll of SDK 10.0.22621 (101.6.2112.13); #1337 reports the two rect ones with that validator, and barycentric_tests::first_half_values_render_on_hardware_and_warp gives the same error. The other four fail only under VICTORY_WARP=1, which puts WARP in the hardware device's place; on the card they pass.
  • victory-shader library on the card and WARP (--test-threads=1), on 6b3ce6c: with the test alone, 314 passed, 4 failed (the three PSV0 ones and this test), 4 ignored; with this PR, 315 passed, 3 failed (the three PSV0 ones), 4 ignored. On 9e90746 the same pair was 291/4/4 and 292/3/4.
  • Clippy in both CI configurations, with --keep-going: the same 15 errors with and without this change on 6b3ce6c, none in the changed files. (On main the CI job stops at its Clippy step, so its Tests step does not run.) cargo fmt --check -p victory-shader reports no new difference.
  • cargo xtask policy: 288 files ok. cargo test --workspace --locked --no-run builds. lower.rs has 636,765 bytes against the 655,360 limit.

The translator has one more ordered 64-bit compare, the carry out of v_mad_u64_u32. It is wrong on the same card and fixed in #1507, which does not depend on this one. No other one was found: the rest of the 64-bit code is arithmetic (mul_hi, the BVH node address, shifts), and s_cmp_*_u64 tests equality only.

No in-game effect is claimed: without the title I cannot say which of its programs reach these compares.

Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:5537219784 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1506). Originally posted by [murillojndem](https://github.com/murillojndem) on 2026-11-28T05:51:35Z. --- `v_cmp_{lt,le,gt,ge,eq,ne}_{i64,u64}` (and the `v_cmpx_` forms, which reach the same code) are lowered to one `icmp` on an i64 built from two dwords. AMD's D3D12 compiler gets the order wrong when the two operands share a dword: `v_cmp_lt_i64 s20, v[1:2], v[2:3]` with v1 = v2 = 0 and v3 = 1 asks whether 0 < 0x1_00000000, and the card answers false. WARP answers true. This is a backport of Marvisak/VIctory#1599, merged upstream on 25 November as cc7ec2a (by alexdeliu). This fork's #135 is the same change by the same author; it conflicts since the tree moved to the VIctory-NVIDIA base. The compare now runs on the dwords: the high dwords decide (signed for i64), and equal high dwords leave it to the low dwords (unsigned). It no longer needs INT64. The added and removed lines are the same as in cc7ec2a; only the offsets differ (the helper sits before `f64_pair` here and before `split64` upstream). The test is upstream's: all twelve compares over values whose dword orders disagree, on disjoint and on shared register pairs. On other cards: upstream merged these lines for every host, and #135 cites an RTX 4070 Ti that agrees with WARP on this compare. The dword form gives the same answers wherever the i64 compare is right. It was not run on an NVIDIA card here; the RX 7900 XT and WARP are the two devices tested. Tested on an AMD Radeon RX 7900 XT (RDNA 3, 20 GB, driver 32.0.32015.7029), Windows 11, Rust 1.98.1, on 6b3ce6c (current `main`) and first on 9e90746; the two commits between them do not touch `lower.rs` or `valu_tests.rs`. Synthetic shaders only; no game files. - Without the lowering change, `v_cmp_u64_and_i64_order_by_the_high_dword` fails on the card: `hardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000)`, 0 where 1 is right. That is the first failure reported on an RX 9070, a gfx1036 iGPU and an RX 7700. - A census over the same values with the lowering of 9e90746 (a local probe, not in this PR) runs every case: on the card only the shared form `v[1:2], v[2:3]` is wrong, and only for the ordered compares. `lt`, `le`, `gt` and `ge` get 28 or 29 of 100 cases wrong for `_i64` and 49 to 56 of 100 for `_u64`. `eq`, `ne` and the disjoint form `v[1:2], v[3:4]` have no mismatch. WARP has none. - With the lowering change, the test passes on the card and on WARP. `rdna_forms_give_what_the_spelled_out_ones_give` ran in the same binary without its "no RDNA card" line, so the hardware device was the Radeon. - On 9e90746, `cargo test -p victory-shader --lib` with `VICTORY_WARP=1`: 288 passed, 7 failed, 4 ignored. The same 7 fail there without the change (287 passed). Three are PSV0 mismatches with the `dxil.dll` of SDK 10.0.22621 (101.6.2112.13); #1337 reports the two `rect` ones with that validator, and `barycentric_tests::first_half_values_render_on_hardware_and_warp` gives the same error. The other four fail only under `VICTORY_WARP=1`, which puts WARP in the hardware device's place; on the card they pass. - `victory-shader` library on the card and WARP (`--test-threads=1`), on 6b3ce6c: with the test alone, 314 passed, 4 failed (the three PSV0 ones and this test), 4 ignored; with this PR, 315 passed, 3 failed (the three PSV0 ones), 4 ignored. On 9e90746 the same pair was 291/4/4 and 292/3/4. - Clippy in both CI configurations, with `--keep-going`: the same 15 errors with and without this change on 6b3ce6c, none in the changed files. (On `main` the CI job stops at its Clippy step, so its Tests step does not run.) `cargo fmt --check -p victory-shader` reports no new difference. - `cargo xtask policy`: 288 files ok. `cargo test --workspace --locked --no-run` builds. `lower.rs` has 636,765 bytes against the 655,360 limit. The translator has one more ordered 64-bit compare, the carry out of `v_mad_u64_u32`. It is wrong on the same card and fixed in #1507, which does not depend on this one. No other one was found: the rest of the 64-bit code is arithmetic (`mul_hi`, the BVH node address, shifts), and `s_cmp_*_u64` tests equality only. No in-game effect is claimed: without the title I cannot say which of its programs reach these compares. Generated with [Claude Code](https://claude.com/claude-code)
Melow-code commented 2026-11-29 04:59:14 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Melow-code on 2026-11-29T04:59:14Z.

Review: COMMENTED


Checked that the dword form is exact, independently of any driver: no objection.

I merged de6370a onto main 368967f8 on Linux, added an evaluator of the emitted module (test code), lowered the twelve compares in 22 operand forms and evaluated each result: VGPR pairs apart, the same and sharing a register, SGPR pairs, inline integers (0, 1, 64, -1, -16) and a literal on either side. 2,000 random inputs per form, with zeros, ones, sign bits and equal high dwords mixed in: 528,000 compares against Rust's u64/i64, no mismatch. Literals are sign-extended for _i64 and zero-extended for _u64.

The check is not vacuous: with the low dwords of lt_i64 compared signed, it fails at once.

cargo test -p victory-formats -p victory-shader --lib: 42 and 208 passed (one of them mine), 0 failed. The merge is clean.

Not run: any card. The AMD compiler fault itself, and the PR's own device test, are not checked here. Also not run: v_cmpx, DPP and SDWA forms, inline floats, the Windows tests.

AI-assisted review (Claude Code).

<!-- greyfinch-sync:fxceless/victory-fork:review:6101501698 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1506#pullrequestreview-6101501698). Originally posted by [Melow-code](https://github.com/Melow-code) on 2026-11-29T04:59:14Z. **Review:** COMMENTED --- Checked that the dword form is exact, independently of any driver: no objection. I merged de6370a onto main 368967f8 on Linux, added an evaluator of the emitted module (test code), lowered the twelve compares in 22 operand forms and evaluated each result: VGPR pairs apart, the same and sharing a register, SGPR pairs, inline integers (0, 1, 64, -1, -16) and a literal on either side. 2,000 random inputs per form, with zeros, ones, sign bits and equal high dwords mixed in: 528,000 compares against Rust's `u64`/`i64`, no mismatch. Literals are sign-extended for `_i64` and zero-extended for `_u64`. The check is not vacuous: with the low dwords of `lt_i64` compared signed, it fails at once. `cargo test -p victory-formats -p victory-shader --lib`: 42 and 208 passed (one of them mine), 0 failed. The merge is clean. Not run: any card. The AMD compiler fault itself, and the PR's own device test, are not checked here. Also not run: `v_cmpx`, DPP and SDWA forms, inline floats, the Windows tests. AI-assisted review (Claude Code).
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/1506:upstream-pr/1506'
git switch 'upstream-pr/1506'

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/1506'
git switch 'upstream-pr/1506'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1506'
git switch 'upstream-pr/1506'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1506'
git switch 'main'
git merge --squash 'upstream-pr/1506'
git switch 'main'
git merge --ff-only 'upstream-pr/1506'
git switch 'main'
git merge 'upstream-pr/1506'
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
fxceless/victory-fork!1506
No description provided.