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

Open
github-bot wants to merge 1 commit from github-bot/gh-135 into main AGit
Owner

@⁠alexdeliu on GitHub · 2026-11-24 21:45 UTC · original
alexdeliu:fix/amd-i64-compare → main · +127 −14 · 2 files · 1 commits · open

Port of Marvisak/VIctory#1599, which is still open upstream, to this fork. It fixes a translation bug that only AMD hosts hit.

v_cmp_{lt,le,gt,ge}_{i64,u64} are lowered to one icmp on an i64 built from two dwords. AMD's D3D12 driver answers wrong when the two operands share a dword, as if the dwords were swapped. For example, v_cmp_lt_i64 s20, v[1:2], v[2:3] with v1 = v2 = 0, v3 = 1 asks whether 0 < 0x1_00000000. AMD says false, WARP and NVIDIA say true. It reproduced on:

  • an RX 9070 (RDNA4, driver 32.0.32029.2010);
  • a Ryzen 7700 iGPU (gfx1036, RDNA2, 32.0.21045.29003);
  • upstream, independently, on a Ryzen 9 7900X iGPU, where an RTX 4070 Ti agrees with WARP.

Change: the compare runs on the dwords. The high dwords decide (signed for i64); when they are equal, the low dwords decide (unsigned). It no longer needs INT64. The only conflict with this fork was that join64 and the new src64_dwords were added in the same place. Both are kept.

Test: v_cmp_u64_and_i64_order_by_the_high_dword, on the GPU (hardware and WARP):

  • all twelve 64-bit compares, over values whose high-dword and low-dword orders disagree;
  • on disjoint and on shared registers;
  • expected values computed in Rust.

Results on this fork's main (4e17478), RX 9070:

  • Without the change, the test fails on the hardware: hardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000). With it, it passes.
  • Both clippy runs are clean, and cargo test --workspace --locked passes 495.
  • The only failures, emit::rect::tests::{the_rectangle_stage_is_a_geometry_shader, rectangles_are_drawn_whole}, already fail on main with the Windows SDK's dxil.dll (1.7). #61 fixes them, and I checked that on the same card.

🤖 Generated with Claude Code

**@⁠alexdeliu** on GitHub · 2026-11-24 21:45 UTC · [original](https://github.com/fxceless/victory-fork/pull/135) `alexdeliu:fix/amd-i64-compare` → `main` · +127 −14 · 2 files · 1 commits · open Port of Marvisak/VIctory#1599, which is still open upstream, to this fork. It fixes a translation bug that only AMD hosts hit. `v_cmp_{lt,le,gt,ge}_{i64,u64}` are lowered to one `icmp` on an `i64` built from two dwords. **AMD's D3D12 driver answers wrong when the two operands share a dword**, as if the dwords were swapped. For example, `v_cmp_lt_i64 s20, v[1:2], v[2:3]` with v1 = v2 = 0, v3 = 1 asks whether `0 < 0x1_00000000`. AMD says false, WARP and NVIDIA say true. It reproduced on: - an RX 9070 (RDNA4, driver 32.0.32029.2010); - a Ryzen 7700 iGPU (gfx1036, RDNA2, 32.0.21045.29003); - upstream, independently, on a Ryzen 9 7900X iGPU, where an RTX 4070 Ti agrees with WARP. **Change:** the compare runs on the dwords. The high dwords decide (signed for `i64`); when they are equal, the low dwords decide (unsigned). It no longer needs `INT64`. The only conflict with this fork was that `join64` and the new `src64_dwords` were added in the same place. Both are kept. **Test:** `v_cmp_u64_and_i64_order_by_the_high_dword`, on the GPU (hardware and WARP): - all twelve 64-bit compares, over values whose high-dword and low-dword orders disagree; - on disjoint and on shared registers; - expected values computed in Rust. **Results on this fork's `main` (`4e17478`), RX 9070:** - Without the change, the test fails on the hardware: `hardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000)`. With it, it passes. - Both clippy runs are clean, and `cargo test --workspace --locked` passes 495. - The only failures, `emit::rect::tests::{the_rectangle_stage_is_a_geometry_shader, rectangles_are_drawn_whole}`, already fail on `main` with the Windows SDK's `dxil.dll` (1.7). #61 fixes them, and I checked that on the same card. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
v_cmp_{lt,le,gt,ge}_{i64,u64} lowered to one i64 icmp give the wrong
answer on AMD's D3D12 driver when the operands share a dword: `v_cmp_lt_i64
s20, v[1:2], v[2:3]` with v1 = v2 = 0, v3 = 1 (0 < 0x1_00000000) is false
on an RX 9070 (32.0.32029.2010) and on a Ryzen 7700 iGPU, gfx1036
(32.0.21045.29003), as if the dwords were swapped; WARP gets it right.
Disjoint pairs are fine there, and so is equality.

The compare now runs on the dwords: the high ones decide (signed for
i64), equal ones leave it to the low ones (unsigned). It needs no INT64.
The GPU test runs all twelve compares over values whose dword orders
disagree, on disjoint and on shared registers; without the change it fails
on the AMD hardware.

Found by a cross-device fuzzer that compares single VALU instructions on
every adapter and WARP.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:46 +00:00
Author
Owner

@⁠bawhen on GitHub · 2026-11-24 22:17 UTC · original

Reproduced and fixed on a desktop RDNA3 card (RX 7700, driver 32.0.32029.2010), which adds a third AMD generation to the RX 9070 and gfx1036 results.

cargo test -p victory-shader --locked --lib v_cmp_u64_and_i64_order_by_the_high_dword -- --nocapture

build result
PR head 9b8ab0b passes on hardware and WARP (no skipped line, so the card ran it)
PR test, lower.rs from main fails on the hardware: hardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000), the same first failure as on the RX 9070

Setup: AMD Radeon RX 7700 (RDNA3, 16 GB), driver 32.0.32029.2010, Ryzen 7 8700F, 16 GB RAM, Windows 11 (build 26300), Rust 1.98.1 from rust-toolchain.toml. Baseline main at 4e17478: cargo test --workspace --locked gives 496 passed, 0 failed, 7 ignored. The "without the fix" run checks out main's version of the PR's non-test files and keeps the PR's new test. No game files used.

AI use: Claude Code (Claude Opus 5.5) ran the tests and drafted this comment; posted at my request.

**@⁠bawhen** on GitHub · 2026-11-24 22:17 UTC · [original](https://github.com/fxceless/victory-fork/pull/135#issuecomment-7146051092) Reproduced and fixed on a desktop RDNA3 card (RX 7700, driver 32.0.32029.2010), which adds a third AMD generation to the RX 9070 and gfx1036 results. `cargo test -p victory-shader --locked --lib v_cmp_u64_and_i64_order_by_the_high_dword -- --nocapture` | build | result | |---|---| | PR head `9b8ab0b` | passes on hardware and WARP (no `skipped` line, so the card ran it) | | PR test, `lower.rs` from `main` | fails on the hardware: `hardware: v_cmp_lt_i64(0x0000000000000000, 0x0000000100000000)`, the same first failure as on the RX 9070 | Setup: AMD Radeon RX 7700 (RDNA3, 16 GB), driver 32.0.32029.2010, Ryzen 7 8700F, 16 GB RAM, Windows 11 (build 26300), Rust 1.98.1 from `rust-toolchain.toml`. Baseline `main` at `4e17478`: `cargo test --workspace --locked` gives 496 passed, 0 failed, 7 ignored. The "without the fix" run checks out `main`'s version of the PR's non-test files and keeps the PR's new test. No game files used. *AI use: Claude Code (Claude Opus 5.5) ran the tests and drafted this comment; posted at my request.*
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/135/head:github-bot/gh-135'
git switch 'github-bot/gh-135'

Merge

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