Skip to content

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

Merged
Marvisak merged 4 commits into
Marvisak:mainfrom
alexdeliu:fix/amd-i64-compare
Nov 25, 2026
Merged

Marvisak merged 4 commits into
Marvisak:mainfrom
alexdeliu:fix/amd-i64-compare

Conversation

@alexdeliu

Copy link
Copy Markdown
Contributor

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

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 <noreply@anthropic.com>
@DrDarkDK

Copy link
Copy Markdown

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.

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

AI-assisted with Codex.

@alexdeliu

Copy link
Copy Markdown
Contributor Author

@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

tumbubu commented Nov 24, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor Author

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

PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
…n their dwords; AMD orders a shared-dword i64 compare wrong)
PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
Code tree of fxceless/victory-fork 4e17478 (all rendering work by its author and
the VIctory contributors) with, on top:
- AMD fixes: skip of 39f0e9aeb156a61c, 32-lane programs per half wave and NaN/Inf
  filter, configurable texture upload queue, VIctory Marvisak#1599
- upstream VIctory Marvisak#334 (buffer-state tracking) and Marvisak#1271 (globally coherent glc UAVs)
- fork PRs Marvisak#95, Marvisak#71, Marvisak#32, Marvisak#86; VIctory Marvisak#1696, Marvisak#1338, Marvisak#1291, Marvisak#1732
- DirectStorage page lists read at the title's submit (analysis by JappertjeV, klbf-lab#3)
- offline pipeline pre-build that saves as it goes and skips driver-crashing pipelines
- Series S plane composition, VICTORY_FFX_SIMPLE, scripted keys in release builds
- docs/klbf/skip-amd.txt: AMD skip list used for our runs

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, 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).

alexdeliu and others added 2 commits November 25, 2026 06:49
…split too

main's src64 now sign-extends the 32-bit literal of an _i64 operand
(signed_64_bit_operands_sign_extend_their_literal). The dword compare
read the literal's high dword as zero, so v_cmp_lt_i64 v[1:2], -100
compared against 0x00000000_FFFFFF9C. It now takes the same high dword
src64 would.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexdeliu

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor Author

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

PastiiJay added a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
…n their dwords; AMD orders a shared-dword i64 compare wrong)
@Marvisak
Marvisak merged commit cc7ec2a into Marvisak:main Nov 25, 2026
1 check passed
Airamek added a commit to Airamek/VIctory that referenced this pull request Nov 26, 2026
Upstream model everywhere, our additive diagnostics kept. 15 files
conflicted, all resolved file-by-file:

- README: our fuzz_tests/ship-profile/VICTORY_DIFF_ONLY/VICTORY_NAME_SHADERS
  notes beside upstream's status/blake3-paths/translate-jobs wording.
- descriptor/host.rs: upstream Marvisak#2462 (no typed UAV in a format the host
  cannot store to) lands untouched through the merge; keeps its
  device-removal fix, no behavior change on capable hosts.
- descriptor.rs: our monotonic heap-id guard + upstream Marvisak#2234
  (released view heap takes its page table with it).
- pipeline/library.rs: upstream Marvisak#2179 (lock-free loads via Shared) +
  our best-effort periodic save (try_lock on state).
- capture.rs: our Marvisak#2607 signed-32 decode + test beside upstream's
  r32_integer_to_rgba.
- draw.rs: our buffer_state tracking + root-signature test beside
  upstream's marked page-range refresh (Marvisak#2172) + sampler-heap test.
- pipeline/host.rs: upstream vertex/depth-bounds/integer-blend model
  (stream_pipeline, host_blend, depth_with_bounds) + our padding-zeroing
  clean_* and Stream zeroing; both test batches kept.
- pipeline/make.rs: keep lost/screen fields + upstream skipped_shader.
- pipeline.rs: keep bytes()/pipelines_waiting() beside for_test.
- host.rs: multi-plane present (Marvisak#1997, Compositor) + our previous-frame
  wait, presented/probed frame tracking, keep-textures, drain-before-save;
  both test modules (submissions + present_plane_tests).
- queue.rs: upstream blinks (Option<bool>) supersedes ours.
- shadow.rs: upstream update_tracked/update + merge_writeback (Marvisak#2054) +
  our stale/submission_done/Part snapshots/buffer_states; update_free and
  update_busy retired as subsumed (no callers left).
- xmem.rs: upstream shared system_commit() supersedes our inline version.
- emit/host.rs: our fence-event wait() + upstream SharedDevice/Marvisak#244
  (shared/serialized WARP device).
- emit/lower.rs: upstream i64 dword ordering (Marvisak#1599) + our f/t lane path
  and RDNA2 opcode names; tests moved verbatim to lower_tests.rs via
  #[path] (lower.rs exceeded the 512 KiB asset-policy limit after the
  merge; module path unchanged, content byte-identical).
- emit/valu_tests.rs: our s_load_dwordx4_at + upstream sopk helper.
- gfx10/opcodes.rs: upstream pub(crate) + our RDNA2 names.
- fuzz_tests.rs: Host::from_device() for upstream's new warp field.

Test adaptations (same execution-model class as the 13f91ca merge):
8 upstream tests written for synchronous execute() drain explicitly on
our async-completion queue (marked-UAV/placed-view/rebind tests);
Host::from_device() port; words() accessor for privatized field.

Gates: cargo test --workspace --locked green, clippy --workspace
--all-targets --all-features -D warnings clean, xtask policy 197 ok.
LeanWasTaken pushed a commit to LeanWasTaken/VIctory-bc250 that referenced this pull request Nov 26, 2026
…-dword i64 compare wrong) (Marvisak#1599)

* Shaders: 64-bit integer compares on their dwords

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.

Ported without upstream's follow-up that sign-extends an _i64 literal
in the dword split: this tree's src64 zero-extends every 32-bit literal
(it lacks upstream's src64 change), so src64_dwords reads literals the
same way src64 does here.

(cherry picked from commit cc7ec2a)
Gandalem added a commit to Gandalem/VIctory that referenced this pull request Nov 26, 2026
Apply complete, uniquely matching upstream hunks in dependency order, preserving fork-specific raw structured buffer lowering and configurable descriptor capacity. Defer incompatible shader ABI and cross-module changes until GPU reconciliation.

704d25e Shaders: v_mul_legacy_f32 treats denormal operands as zero (Marvisak#682)
cc7ec2a Shaders: 64-bit integer compares on their dwords (AMD orders a shared-dword i64 compare wrong) (Marvisak#1599)
77fd819 Shaders: cube-map face coordinates read denormals as zeros (Marvisak#1766)
084d4ff Shaders: round full-width unsigned integer conversions once (Marvisak#2186)
f3578e3 Shaders: decode f16 inline float constants in whole-wave v_add_f16 simulation (Marvisak#2493)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants