Shaders: 16-bit compares read the low halves whatever op_sel says, as RDNA2 does #926
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-24T14:17:13Z.
What'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
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T14:21:21Z.
Review: APPROVED
Tested head
a8aa1d1(fast-forward onmainffe310e) on Windows 11 x64 (Rust 1.98.1 MSVC) with NVIDIA GeForce RTX 5090 (Blackwell) and WARP:cargo test -p victory-shader valu_tests: 14 passed, 0 failed (includingcmp16_ignores_op_sel_as_rdna2_doeson both RTX 5090 and WARP)cargo clippy -p victory-shader --all-targets: 0 warningscargo xtask policy: okClean, focused fix matching RDNA2 16-bit compare
op_selsemantics. Approving.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T14:32:02Z.
Review: APPROVED
Tested
e477c4bon Windows 11, RTX 5070, MSVC:cargo test -p victory-shader -- --test-threads=1122 passed, includingcmp16_ignores_op_sel_as_rdna2_doeson the GPU backend, andcargo clippy -p victory-shader --all-targetsis clean.op_selonly forv_cmp*(andv_cmpx*), notv_cmp_class, follows exactly what #833 measured, and thev_add_nc_u16control keeps honouring it. The test's cases are built so that reading either high half flips the result, so a regression back to honouringop_selfails it.v_cmp_classis left as before ("not measured"). Worth a follow-up row in #833's harness so the exception is measured rather than assumed.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-24T14:22:10Z.
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.Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T14:23:24Z.
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 bothffe310eanda8aa1d1. 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.Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-24T14:27:10Z.
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.Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-24T14:28:44Z.
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).Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T15:41:00Z.
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).
Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-24T21:50:07Z.
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.Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-24T21:59:19Z.
The fix for those two
maintests is #1752 (windows-latestgreen with it).Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T00:56:43Z.
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.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T02:32:43Z.
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
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:04:20Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed / 2 ignored. 16-bit compares read the low halves whatever op_sel says — hardware-accurate compare semantics; oldest PR in the backlog (opened early), still mergeable.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:27:07Z.
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.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T12:25:01Z.
I combined exact #926
d69cac1and #336455d58e0on main63bcca4. The integration branch ise002024. It preserves both PR heads and keeps both sets of tests. The conflict is resolved inhalf_opsel: ordinary 16-bit compares and the VOP3 encodings of the VOP1/VOP2 operations ignoreop_sel, with the existing SDWA selector still applied afterward.With the same fixtures on main, the compare test and the VOP1/VOP2 test fail. The full VALU group is 36 passed / 2 failed on main and 38 / 0 on the integration, on WARP 1.0.22 with DXIL validation. The SDWA word-select control passes on both, and the VOP3-only arithmetic controls pass on the integration. Strict all-features/all-targets shader Clippy and the asset policy passed.
The branch is available for retesting or for resolving the overlap when either PR lands. If folding the resolution into a commit, please retain Git attribution or use
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.AI-assisted with Codex. Synthetic WARP testing only.
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.