Shaders: 64-bit integer compares on their dwords (AMD orders a shared-dword i64 compare wrong) #1598

Merged
alexdeliu merged 4 commits from upstream-pr/1599 into main 2026-11-25 21:51:05 +00:00
alexdeliu commented 2026-11-24 19:41:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T19:41:17Z.


v_cmp_{lt,le,gt,ge}_{i64,u64} are lowered to one icmp on an i64 built from the two dwords. AMD's D3D12 driver gets that wrong when the two operands share a dword.

Minimal case: v_cmp_lt_i64 s20, v[1:2], v[2:3] with v1 = v2 = 0, v3 = 1, i.e. 0 < 0x1_00000000.

Device Driver Result
AMD RX 9070 (RDNA4) 32.0.32029.2010 false
AMD Radeon Graphics, Ryzen 7700 iGPU (gfx1036, RDNA2) 32.0.21045.29003 false
WARP true (correct)

The wrong answers look as if the dwords were swapped. Disjoint register pairs give the right result, and so do eq and ne.

Change

  • The compare now runs on the dwords. The high dwords decide (signed for i64); when they are equal, the low dwords decide (unsigned). eq/ne compare both dwords.
  • It no longer needs INT64. src64_dwords reads operands as src64 does: register pairs, inline constants sign-extended, literals and null zero-extended.

Test

v_cmp_u64_and_i64_order_by_the_high_dword (GPU, hardware + WARP):

  • all twelve 64-bit compares;
  • 10 values, all pairs, picked so the high-dword and low-dword orders disagree;
  • both on disjoint registers (v[1:2], v[3:4]) and on shared ones (v[1:2], v[2:3]);
  • expected values computed in Rust.

Without the lowering change, the test fails on the RX 9070: hardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000). With it, it passes on both AMD GPUs and on WARP.

Checks

On Windows 11 with the RX 9070, both CI clippy runs are clean and cargo test --workspace --locked passes (343).

How it was found

A cross-device fuzzer ran every lowered VOP3 opcode as a one-thread compute shader on each adapter and on WARP, on the same special and random inputs, and compared the results. These compares were the only integer opcodes where the devices disagreed. The fuzzer is coming as a separate PR.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6589935778 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1599). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T19:41:17Z. --- `v_cmp_{lt,le,gt,ge}_{i64,u64}` are lowered to one `icmp` on an `i64` built from the two dwords. **AMD's D3D12 driver gets that wrong when the two operands share a dword.** Minimal case: `v_cmp_lt_i64 s20, v[1:2], v[2:3]` with v1 = v2 = 0, v3 = 1, i.e. `0 < 0x1_00000000`. | Device | Driver | Result | |---|---|---| | AMD RX 9070 (RDNA4) | 32.0.32029.2010 | **false** | | AMD Radeon Graphics, Ryzen 7700 iGPU (gfx1036, RDNA2) | 32.0.21045.29003 | **false** | | WARP | | true (correct) | The wrong answers look as if the dwords were swapped. Disjoint register pairs give the right result, and so do `eq` and `ne`. ## Change - The compare now runs on the dwords. The high dwords decide (signed for `i64`); when they are equal, the low dwords decide (unsigned). `eq`/`ne` compare both dwords. - It no longer needs `INT64`. `src64_dwords` reads operands as `src64` does: register pairs, inline constants sign-extended, literals and null zero-extended. ## Test `v_cmp_u64_and_i64_order_by_the_high_dword` (GPU, hardware + WARP): - all twelve 64-bit compares; - 10 values, all pairs, picked so the high-dword and low-dword orders disagree; - both on disjoint registers (`v[1:2]`, `v[3:4]`) and on shared ones (`v[1:2]`, `v[2:3]`); - expected values computed in Rust. Without the lowering change, the test fails on the RX 9070: `hardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000)`. With it, it passes on both AMD GPUs and on WARP. ## Checks On Windows 11 with the RX 9070, both CI clippy runs are clean and `cargo test --workspace --locked` passes (343). ## How it was found A cross-device fuzzer ran every lowered VOP3 opcode as a one-thread compute shader on each adapter and on WARP, on the same special and random inputs, and compared the results. These compares were the only integer opcodes where the devices disagreed. The fuzzer is coming as a separate PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
DrDarkDK commented 2026-11-24 21:03:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-24T20:26:56Z.


I tested #1599 (faccfbc) on native Windows using the unchanged fuzzer from #1614 (a01156e). I ran the eight ordered i64/u64 compare opcodes with 32 identical seeded inputs per opcode on both builds. The adapters were an RTX 4070 Ti (621.01), a Ryzen 9 7900X Radeon iGPU (32.0.11024.2), and WARP.

  • On ffe310e, 131 of 256 cases disagreed across adapters. In all 64 mismatch rows printed by the harness, the RTX 4070 Ti and WARP agreed and the Radeon iGPU differed.
  • With #1599, all three adapters agreed on all 256 cases. The PR’s expected-value regression test also passed without adapter skips.

This was a targeted synthetic comparison covering the eight ordered opcodes.

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143561613 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1599#issuecomment-7143561613). Originally posted by [DrDarkDK](https://github.com/DrDarkDK) on 2026-11-24T20:26:56Z. --- I tested #1599 (`faccfbc`) on native Windows using the unchanged fuzzer from #1614 (`a01156e`). I ran the eight ordered i64/u64 compare opcodes with 32 identical seeded inputs per opcode on both builds. The adapters were an RTX 4070 Ti (621.01), a Ryzen 9 7900X Radeon iGPU (32.0.11024.2), and WARP. - On `ffe310e`, 131 of 256 cases disagreed across adapters. In all 64 mismatch rows printed by the harness, the RTX 4070 Ti and WARP agreed and the Radeon iGPU differed. - With #1599, all three adapters agreed on all 256 cases. The PR’s expected-value regression test also passed without adapter skips. This was a targeted synthetic comparison covering the eight ordered opcodes. *AI-assisted with Codex.*
alexdeliu commented 2026-11-24 21:03:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T20:33:19Z.


@DrDarkDK thank you for the independent run. It adds an NVIDIA adapter (RTX 4070 Ti agreeing with WARP) and a third AMD device: your 7900X iGPU, after my RX 9070 and gfx1036. That pins the bug on AMD's D3D12 compiler rather than on the translation.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143724481 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1599#issuecomment-7143724481). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T20:33:19Z. --- @DrDarkDK thank you for the independent run. It adds an NVIDIA adapter (RTX 4070 Ti agreeing with WARP) and a third AMD device: your 7900X iGPU, after my RX 9070 and gfx1036. That pins the bug on AMD's D3D12 compiler rather than on the translation.
tumbubu commented 2026-11-24 22:02:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tumbubu on 2026-11-24T21:51:44Z.


First RDNA3 device: the bug reproduces on an RX 7900 XT, and faccfbc fixes it there.

On top of the RX 9070, gfx1036 and the 7900X iGPU, this adds a discrete RDNA3 card on a newer driver.

  • AMD Radeon RX 7900 XT, driver 32.0.31036.15, D3D12 waves 32..64
  • Windows 11 Pro 26300; dxil.dll from SDK 10.0.26100, so every module was validated
Run Result
This PR's v_cmp_u64_and_i64_order_by_the_high_dword, lowering left at ffe310e fails on the first case, the one in the commit message: hardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000)
faccfbc, cargo test -p victory-shader --locked -- --test-threads=1 121 passed, 0 failed, 1 ignored (main: 120). The new test passes on the 7900 XT and on WARP.
#1614's fuzzer on main all eight ordered v_cmp_{lt,le,gt,ge}_{i64,u64} differ from WARP, on 57 to 110 of 160 inputs; eq/ne agree

So it is the same bug on RDNA2, RDNA3 and RDNA4. AI-assisted (Claude Code); every run was on this machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145486231 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1599#issuecomment-7145486231). Originally posted by [tumbubu](https://github.com/tumbubu) on 2026-11-24T21:51:44Z. --- **First RDNA3 device: the bug reproduces on an RX 7900 XT, and `faccfbc` fixes it there.** On top of the RX 9070, gfx1036 and the 7900X iGPU, this adds a discrete RDNA3 card on a newer driver. - AMD Radeon RX 7900 XT, driver 32.0.31036.15, D3D12 waves 32..64 - Windows 11 Pro 26300; `dxil.dll` from SDK 10.0.26100, so every module was validated | Run | Result | |---|---| | This PR's `v_cmp_u64_and_i64_order_by_the_high_dword`, lowering left at `ffe310e` | **fails** on the first case, the one in the commit message: `hardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000)` | | `faccfbc`, `cargo test -p victory-shader --locked -- --test-threads=1` | 121 passed, 0 failed, 1 ignored (`main`: 120). The new test passes on the 7900 XT and on WARP. | | #1614's fuzzer on `main` | all eight ordered `v_cmp_{lt,le,gt,ge}_{i64,u64}` differ from WARP, on 57 to 110 of 160 inputs; `eq`/`ne` agree | So it is the same bug on RDNA2, RDNA3 and RDNA4. AI-assisted (Claude Code); every run was on this machine.
alexdeliu commented 2026-11-24 22:02:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T21:56:38Z.


@tumbubu thank you, that's the RDNA3 data point that was missing. With your RX 7900 XT, the bug now reproduces on RDNA2 (gfx1036), RDNA3 (7900 XT) and RDNA4 (RX 9070), plus a 7900X iGPU. NVIDIA and WARP agree with the reference, and this PR fixes it on all of them.

It also still applies on the new main (70564ae): I merged it in (1f6b392). There the test still fails on the RX 9070 without the change and passes with it. Clippy ×2 is clean, and the workspace passes apart from the two PSV0 tests that fail on main itself with the SDK's 1.7 validator (see #1744).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145594833 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1599#issuecomment-7145594833). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T21:56:38Z. --- @tumbubu thank you, that's the RDNA3 data point that was missing. With your RX 7900 XT, the bug now reproduces on RDNA2 (gfx1036), RDNA3 (7900 XT) and RDNA4 (RX 9070), plus a 7900X iGPU. NVIDIA and WARP agree with the reference, and this PR fixes it on all of them. It also still applies on the new `main` (`70564ae`): I merged it in (`1f6b392`). There the test still fails on the RX 9070 without the change and passes with it. Clippy ×2 is clean, and the workspace passes apart from the two PSV0 tests that fail on `main` itself with the SDK's 1.7 validator (see #1744).
catminou4 commented 2026-11-25 04:05:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:39:20Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. 64-bit integer compares lowered on their dwords, AMD shared-exponent ordering — compares without INT64; relates to the 64-bit atomics cluster (#1899/#1953).

<!-- greyfinch-sync:Marvisak/VIctory:review:6051512766 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1599#pullrequestreview-6051512766). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T03:39:20Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 144 passed / 0 failed / 2 ignored. 64-bit integer compares lowered on their dwords, AMD shared-exponent ordering — compares without INT64; relates to the 64-bit atomics cluster (#1899/#1953).
Marvisak commented 2026-11-25 04:06:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:31:14Z.


Automated triage for the maintainers.

Merge candidate. This lowers the v_cmp_*_{i64,u64} compares on the two dwords, which avoids AMD's misordering of a 64-bit icmp. The high dwords decide (signed for i64); when they are equal, the low dwords decide, unsigned. eq/ne compare both dwords. Update after the new head (e60eb70): src64_dwords now sign-extends an _i64 instruction's 32-bit literal into the high dword, exactly as src64 on main does. Register pairs, sign-extended inline constants, zero-extended other literals and null are also read the same way. The predicates are right for all eight ordered cases, and the test computes its expected values in Rust. The failure is reproduced on several AMD generations in this thread, and WARP agrees with the fix. It merges cleanly with main, and CI passes.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151990698 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1599#issuecomment-7151990698). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T03:31:14Z. --- <!-- victory-triage v1 head=e60eb70943ff37d05ba38eee5d2cb960041adf8f verdict=merge-candidate at=2026-11-25T07:20:09Z --> Automated triage for the maintainers. **Merge candidate.** This lowers the `v_cmp_*_{i64,u64}` compares on the two dwords, which avoids AMD's misordering of a 64-bit `icmp`. The high dwords decide (signed for i64); when they are equal, the low dwords decide, unsigned. `eq`/`ne` compare both dwords. Update after the new head (`e60eb70`): `src64_dwords` now sign-extends an `_i64` instruction's 32-bit literal into the high dword, exactly as `src64` on `main` does. Register pairs, sign-extended inline constants, zero-extended other literals and null are also read the same way. The predicates are right for all eight ordered cases, and the test computes its expected values in Rust. The failure is reproduced on several AMD generations in this thread, and WARP agrees with the fix. It merges cleanly with `main`, and CI passes. --- _Generated by [Claude Code](https://claude.ai/code)_
alexdeliu commented 2026-11-25 05:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-25T05:00:36Z.


Merged main (940d32f) in. Its new signed_64_bit_operands_sign_extend_their_literal caught a real gap in this PR: the dword split read an _i64 literal's high dword as zero, where src64 now sign-extends it. e60eb70 makes src64_dwords take the same high dword as src64. On the RX 9070 + gfx1036 machine: both CI clippy runs are clean, and cargo test --workspace --locked passes, including that test and this PR's shared-dword compare test. The only failures are the 2 PSV0 tests main itself fails with the SDK's dxil.dll 1.7.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7153364338 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1599#issuecomment-7153364338). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-25T05:00:36Z. --- Merged `main` (`940d32f`) in. Its new `signed_64_bit_operands_sign_extend_their_literal` caught a real gap in this PR: the dword split read an `_i64` literal's high dword as zero, where `src64` now sign-extends it. `e60eb70` makes `src64_dwords` take the same high dword as `src64`. On the RX 9070 + gfx1036 machine: both CI clippy runs are clean, and `cargo test --workspace --locked` passes, including that test and this PR's shared-dword compare test. The only failures are the 2 PSV0 tests `main` itself fails with the SDK's `dxil.dll` 1.7.
alexdeliu commented 2026-11-25 07:03:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-25T06:31:36Z.


A standalone repro of the bug this PR fixes, outside VIctory: https://github.com/alexdeliu/rdna2-conformance runs VIctory's own DXIL for v_cmp_{lt,gt}_{i64,u64} and v_cmp_eq_i64 on v[1:2] vs v[2:3] (lowered as on main without this fix) on every D3D12 adapter (cargo run --release, no game files).

  • RX 9070 and gfx1036: every ordered compare fails (12-21 of 32 cases); the equality passes.
  • WARP: passes all five.
  • The same compares written in HLSL and compiled by DXC pass on all three, so the driver bug depends on this lowering's DXIL shape. That's why the dword split here is the fix rather than a workaround for one driver version.

Anyone with an NVIDIA/Intel/RDNA3 card can add a column. Reports go in the repo's results/.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154880929 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1599#issuecomment-7154880929). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-25T06:31:36Z. --- A standalone repro of the bug this PR fixes, outside VIctory: https://github.com/alexdeliu/rdna2-conformance runs VIctory's own DXIL for `v_cmp_{lt,gt}_{i64,u64}` and `v_cmp_eq_i64` on `v[1:2]` vs `v[2:3]` (lowered as on `main` without this fix) on every D3D12 adapter (`cargo run --release`, no game files). - **RX 9070 and gfx1036:** every ordered compare fails (12-21 of 32 cases); the equality passes. - **WARP:** passes all five. - **The same compares written in HLSL and compiled by DXC** pass on all three, so the driver bug depends on this lowering's DXIL shape. That's why the dword split here is the fix rather than a workaround for one driver version. Anyone with an NVIDIA/Intel/RDNA3 card can add a column. Reports go in the repo's `results/`.
upstream-sync closed this pull request 2026-11-25 22:03:04 +00:00
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
Marvisak/VIctory!1598
No description provided.