Shaders: 64-bit integer compares on their dwords (backport of Marvisak/VIctory#1599, reproduced on an RX 7900 XT) #1506
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1506"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 thev_cmpx_forms, which reach the same code) are lowered to oneicmpon 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_pairhere and beforesplit64upstream). 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(currentmain) and first on9e90746; the two commits between them do not touchlower.rsorvalu_tests.rs. Synthetic shaders only; no game files.v_cmp_u64_and_i64_order_by_the_high_dwordfails 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.9e90746(a local probe, not in this PR) runs every case: on the card only the shared formv[1:2], v[2:3]is wrong, and only for the ordered compares.lt,le,gtandgeget 28 or 29 of 100 cases wrong for_i64and 49 to 56 of 100 for_u64.eq,neand the disjoint formv[1:2], v[3:4]have no mismatch. WARP has none.rdna_forms_give_what_the_spelled_out_ones_giveran in the same binary without its "no RDNA card" line, so the hardware device was the Radeon.9e90746,cargo test -p victory-shader --libwithVICTORY_WARP=1: 288 passed, 7 failed, 4 ignored. The same 7 fail there without the change (287 passed). Three are PSV0 mismatches with thedxil.dllof SDK 10.0.22621 (101.6.2112.13); #1337 reports the tworectones with that validator, andbarycentric_tests::first_half_values_render_on_hardware_and_warpgives the same error. The other four fail only underVICTORY_WARP=1, which puts WARP in the hardware device's place; on the card they pass.victory-shaderlibrary on the card and WARP (--test-threads=1), on6b3ce6c: 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. On9e90746the same pair was 291/4/4 and 292/3/4.--keep-going: the same 15 errors with and without this change on6b3ce6c, none in the changed files. (Onmainthe CI job stops at its Clippy step, so its Tests step does not run.)cargo fmt --check -p victory-shaderreports no new difference.cargo xtask policy: 288 files ok.cargo test --workspace --locked --no-runbuilds.lower.rshas 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), ands_cmp_*_u64tests 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
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
de6370aonto main368967f8on 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'su64/i64, no mismatch. Literals are sign-extended for_i64and zero-extended for_u64.The check is not vacuous: with the low dwords of
lt_i64compared 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).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.