Shaders: 16-bit compares read the low halves whatever op_sel says, as RDNA2 does #926
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!926
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-926"
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?
@BastienRodz on GitHub · 2026-11-24 14:17 UTC · original
BastienRodz:shader/cmp16-ignores-op-sel→main· +120 −2 · 2 files · 3 commits · openWhat's wrong
On RDNA2 the VOP3
op_selbits are ignored by the 16-bit compares (v_cmp_*andv_cmpx_*onf16,u16,i16): both sources come from the low 16 bits. #833 measured it on gfx1036 (146 rows, every source kind, wave32 and wave64), withv_add_nc_u16as the control that does honour the bits.half_srchonoursop_selfor every 16-bit operation:So
v_cmp_lt_f16_e64 vcc, v0, v1 op_sel:[1,0]with v0 =0x4000_3C00and v1 =0x3C00_3E00compares high(v0) 2.0 < low(v1) 1.5 and gives false, where the hardware compares 1.0 < 1.5 and gives true.What the fix does
half_src, whichhalf_fsrcalso goes through, ignoresop_selwhen the instruction is av_cmp*other thanv_cmp_class*(whose behaviour was not measured, so it stays as it was). The SDWA select below it, which does pick the half on hardware, is unchanged, and so is every non-compare 16-bit operation.How it behaves after the fix
16-bit compares read the low halves whatever
op_selsays, as RDNA2 does. Nothing changes for Grand Theft Auto VI: #833 counted 166 VOP3 16-bit compares in its shaders, none withop_selset.Tests
cmp16_ignores_op_sel_as_rdna2_does(valu_tests.rs, run on the host GPU and WARP):v_cmp_lt_f16,v_cmp_lt_u16andv_cmp_lt_i16, each withop_sel0b01,0b10and0b11, on values where the high and low halves give opposite answers;v_cmpx_lt_f16_e64writing EXEC;v_add_nc_u16withop_sel:[1,0]still adds the high half.cmp16_sdwa_preserves_word_selects(by @MichaelSmithAI, BastienRodz/VIctory#5):v_cmp_lt_{f16,i16,u16}_sdwastill honour the SDWA word selects, low/low and either high word.On GitHub's
windows-latest, Rust 1.98.1, with the upstream CI's commands (clippy-D warningswith and without--all-features,cargo test --workspace --locked -- --test-threads=1):victory-shader121 passed, 0 failed (https://github.com/BastienRodz/VIctory/actions/runs/45389398916).e477c4b's parent): everything passes;victory-shader122 passed, 0 failed (https://github.com/BastienRodz/VIctory/actions/runs/45414030202).main: it fails at the first case,hardware: v_cmp_lt_f16 opsel=0b1 (0x40003c00, 0x3c003e00) = 0, want 1(https://github.com/BastienRodz/VIctory/actions/runs/45389413162).cargo xtask policy: ok. Synthetic programs only; no game data.Not tested:
v_cmp_class_*withop_sel(left as it was); a title that setsop_selon a 16-bit compare.AI-assisted: implemented with Gemini 4 Neon, reviewed and run with Claude Code.
Fixes #833.
🤖 Generated with Claude Code
@pickles976 on GitHub · 2026-11-24 14:22 UTC · original
Same divergence confirmed on the sibling runtime (ivall/xcl) — our VOPC emitter selects the compared half with
m.opselfor all 16-bit types (vopc'shalfclosure:m.opsel >> i & 1, f16/u16/i16 alike;v_cmp_classtoo, which you deliberately left alone). Console-exact is your measured behavior (Series = gfx103x), so ours is the wrong side; it is dormant for this title by your own corpus number — 166 16-bit VOPC compares, none withop_selset — which is exactly why we never tripped it. Filing it over here with your #833 measurement as the reference so nobody has to re-derive the quirk; thanks for thev_add_nc_u16control, that is what makes the 146-row result airtight.@MichaelSmithAI on GitHub · 2026-11-24 14:23 UTC · original
Independent RTX 4090 Wine/vkd3d-proton 3.2 result: the authored VOP3/EXEC test passed on a8aa1d1. A separate nine-case readback confirmed that SDWA compares still honor source-word selection for f16, i16 and u16 on both
ffe310eand a8aa1d1. Low/low compared true while choosing either high word compared false. The test-only follow-up adds that neighboring behavior to the regression suite. The class-compare run checks existing translator behavior only. RDNA2 class-compare op_sel remains unmeasured.@shortselow-byte on GitHub · 2026-11-24 14:27 UTC · original
Tested at head
a8aa1d1on an AMD host, to add a third backend to the NVIDIA + WARP run above: Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT (RDNA2, driver 32.0.21045.16010).cargo test --locked -p victory-shader cmp16_ignores_op_sel: passed on the AMD device and WARP (neither skipped).cargo test --locked -p victory-shader valu_tests: 14 passed, 0 failed.cargo clippy --workspace --all-targets --locked -- -D warnings, and with--all-features: clean.half_srcchange reverted, the new test fails on the AMD device as it should:hardware: v_cmp_lt_f16 opsel=0b1 (0x40003c00, 0x3c003e00) = 0, want 1.This checks our translation on AMD's driver, not the console's raw
op_selbehaviour, which rests on #833's measurement.Nit:
half_src's doc comment still says op_sel picks the high half; it could mention that 16-bit compares (other thanv_cmp_class) ignore it.@BastienRodz on GitHub · 2026-11-24 14:28 UTC · original
Thanks all. Pulled in @MichaelSmithAI's SDWA test (
f459735, windows-latest:victory-shader122 passed, https://github.com/BastienRodz/VIctory/actions/runs/45414030202) and fixed thehalf_srcdoc comment @shortselow-byte pointed out (e477c4b, comment only).@Zipettte on GitHub · 2026-11-24 15:41 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at e477c4b:
cargo test -p victory-shaderpasses, 122 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@BastienRodz on GitHub · 2026-11-24 21:50 UTC · original
Rebased onto
main70564ae; the only conflicts were test blocks added on both sides at the end of the file. Onwindows-latestthe run is red, but only onemit::synthetic_tests::gathers_at_a_level_match_the_hardwareandpermutes_read_the_lane_named_and_zero_from_lanes_left_out.mainalone fails those two the same way, in its own CI (https://github.com/Marvisak/VIctory/actions/runs/45492970391) and on our fork (https://github.com/BastienRodz/VIctory/actions/runs/45494314536): the runner's adapter is a software one. This PR's own tests pass there. A fix for those two tests is on its way as a separate PR.@BastienRodz on GitHub · 2026-11-24 21:59 UTC · original
The fix for those two
maintests is #1752 (windows-latestgreen with it).@BastienRodz on GitHub · 2026-11-25 00:56 UTC · original
Still red on the same two
victory-shadertests:main's own CI after42363abfails them too. The runner's Basic Render Driver doesn't set the software flag that commit checks. #1919 adds its vendor/device ids, andwindows-latestis green with it. This PR's crate passes.@Marvisak on GitHub · 2026-11-25 02:32 UTC · original · edited 2026-11-26 01:23 UTC
Automated triage for the maintainers.
Merge candidate (a recommendation to look, not an approval). The new push only rewords the doc comment on
half_src(crates/victory-shader/src/emit/lower.rs) to say that 16-bit compares other thanv_cmp_classignore op_sel; the code is unchanged from the earlier review.half_srcclears op_sel forv_cmp*/v_cmpx*except the class compares, while the SDWA word select below it still picks the half, which matches the gfx1036 measurement in #833 (withv_add_nc_u16as the control). The tests invalu_tests.rstake their expected values from that hardware behaviour and include the SDWA andv_add_nc_u16controls.The branch merges cleanly. CI:
checkpassing.Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-26 01:27 UTC · original
Code review and RTX 5090 + WARP + DXIL verification at head
d69cac127e53merged cleanly ontomain(63bcca43c6a0;emit/lower.rs=520,843B,3,445B under the 512 KiB cap):crates/victory-shader/src/emit/lower.rs:6806-6822):let compare = name.starts_with("v_cmp") && !name.contains("class"); let mut high = !compare && v.opsel >> k & 1 != 0;covers all 16-bitv_cmp_*andv_cmpx_*(f16/u16/i16) comparisons while explicitly exemptingv_cmp_class_f16, preservingv.opselfor 16-bit ALU/conversion ops, and keepingv.sdwaWORD_0/WORD_1selection intact afterwards.dxil.dll10.0.26100.0,VICTORY_D3D12_DEBUG=1, Rust 1.98.1):cargo xtask policy:191 files ok;cargo clippy(default +--all-features): 0 warningscmp16 emit::tests emit::lower::tests: 52/52 passed on both RTX 5090 and WARP (includingcmp16_ignores_op_sel_as_rdna2_doesandcmp16_sdwa_preserves_word_selects).LGTM.
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.