Shaders: v_cmp_lg is ordered on AMD hosts too (olt | ogt, not fcmp one) #706
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!706
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/706/head"
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?
@Lyrnc on GitHub · 2026-11-24 07:09 UTC · original
Lyrnc:fix/cmp-lg-ordered→main· +84 −20 · 3 files · 1 commits · merged 2026-11-24 08:24 UTCWhat
v_cmp_lg_f32/v_cmp_lg_f16("less or greater") are ordered not-equal compares. They are false when either operand is a NaN, on RDNA2 hardware as in the ISA.comparelowered them tofcmp one, which means the same thing in LLVM. The AMD D3D12 driver runsfcmp oneas unordered and returns true for a NaN. NVIDIA and WARP run it correctly. So on AMD hosts everyv_cmp_lgwith a NaN operand took the wrong side.lgnow lowers asfcmp olt | fcmp ogt, which gives the same answer on all three.pred::ONEis no longer emitted. It stays in the table with a note saying why.How it was found and measured
A differential check of the translator against RDNA2 hardware: the same raw VOP3 words run on a gfx1036 (RDNA2) iGPU through a HIP kernel, and through
build_valu_cson a D3D12 host, 240 inputs per opcode. Out of 70 VOPC compares,v_cmp_lg_f32andv_cmp_lg_f16were the only ones whose results differ on an AMD host: 40 and 33 of 240, all NaN rows. With the same DXIL on other hosts:mainv_cmp_lg_f32(0x7fc00000, 0x3f800000) = 1, want 0The AMD row needs #94's
VICTORY_ADAPTER=amdto put the test on the iGPU. I merged #94 locally for that run only; it is not part of this PR.olt,ogt,ord,une,ueqand the other float predicates matched the hardware on the AMD host in the same check, so onlyoneis affected.Test
v_cmp_lg_is_false_for_naninvalu_tests.rsbuildsv_cmp_lg_{f32,f16}_e64 s20, v1, v2+v_cndmask_b32_e64 v0, 0, 1, s20from hand-written words and runs it on the hardware device and WARP. It covers ordered pairs both ways, equal values,+0against-0,infagainstinfand-inf, NaN on either side and on both, a signalling NaN, and for f16, junk in the unread high halves. The expected values are the ISA's, and the same on the gfx1036 hardware.cargo test --workspace -j 4(Windows 11, RTX 5080 as the default adapter): 265 passed, 0 failed, 4 ignored (264 onmainplus the new test).cargo clippy -p victory-shader --all-targets: no warnings.rustfmt --edition 2024 --checkon the three files: clean.cargo xtask policy: 151 files ok.No game files were used.
AI use: Claude Code (Claude Opus 5.5) found this with the differential check, wrote the change and the test, and ran everything above. I reviewed the diff and the results.
🤖 Generated with Claude Code
v_cmp_lg_{f32,f16} ("less or greater") is ordered and not equal: false when either operand is a NaN, on RDNA2 hardware as in the ISA. It was lowered to `fcmp one`, which says the same, but the AMD D3D12 driver runs `fcmp one` as unordered and returns true for a NaN. NVIDIA and WARP get it right. It now lowers as `olt | ogt`, which all three run alike. New GPU test v_cmp_lg_is_false_for_nan covers both widths: NaN on either side, both NaN, a signalling NaN, +0 against -0, inf against inf and against -inf, and junk in the unread high halves for f16. Co-Authored-By: Claude Opus 5.5 <[email protected]>@slint6614-dev on GitHub · 2026-11-24 07:35 UTC · original
AMD hardware check, Windows 11, Adrenalin driver: RX 9070 (RDNA4) and the Ryzen 9600X iGPU (RDNA2, gfx1036), each picked as the D3D12 device for
cargo test -p victory-shader --release(local adapter-selection patch, not part of this PR).victory-shadersuite: 70 passed, 0 failed on both GPUs.lower.rs/bitcode.rsreverted to main and only the new test kept,v_cmp_lg_is_false_for_nanfails on both AMD GPUs (left: 1, right: 0). So main'sfcmp onelowering really returns true for NaN on AMD hardware, and this PR fixes it there.@sambagarandawertanda on GitHub · 2026-11-24 08:47 UTC · original
I ran
v_cmp_lg_is_false_for_nanon the original PR head51f1627with an RTX 3080 (driver 621.14) and WARP. All 20 input cases passed on each backend. This used Windows 11 and Rust 1.98.1 MSVC.On the merged commit
58fed370, the shader tests fail to compile withE0061inscalar_bit_tests_lower. The same call is already present on the merge's first parent,a51bdfa. The old helper usedrsrc2 = 0, so I restored that value at the call site.With this one-line test change, both
v_cmp_lg_is_false_for_nanandscalar_bit_tests_lowerpassed on58fed370. The former again exercised all 40 comparisons across both backends. Tests used synthetic inputs. AI assistance with Codex.