16-bit compares honour VOP3 op_sel, RDNA2 ignores it (no effect on GTA VI) #833
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#833
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@AwkGrep256 on GitHub · 2026-11-24 11:52 UTC · original
On RDNA2, the VOP3
op_selbits are ignored by the 16-bit compares (v_cmp_*andv_cmpx_*onf16,u16,i16). Both sources always come from the low 16 bits of the register. VIctory honours the bits and reads the high half instead.Example
Where
compare()incrates/victory-shader/src/emit/lower.rsreads both sources throughhalf_src/half_fsrc, andhalf_srcpicks the half fromop_sel:op_selis decoded for VOP3 compares ingfx10/fields.rs(v.opsel = (w0 >> 11 & 0xF) as u8).Possible fix
Ignore
op_selfor the compares inhalf_src, and keep the SDWA select below it, which does pick the half on hardware:Measurement
gfx1036 (RDNA2 iGPU), raw instruction words, wave32 and wave64. I covered VGPR, SGPR, 32-bit literal and inline constant sources, plus
v_cmpx_*_e64. All 146 rows matched the hardware ignoringop_sel. As a control,v_add_nc_u16with the same bits set does honour them, so the encoding is right.Impact
None for GTA VI right now.
shaders.rpfhas 1,368 16-bit compares, 166 of them VOP3 encoded, and none of them setop_sel. Filing it so it's known if another title runs into it.@BastienRodz on GitHub · 2026-11-24 11:53 UTC · original
I'll take this one: ignore
op_selfor the 16-bitv_cmp/v_cmpx(keeping the SDWA select), with a syntheticvalu_testscase built from your example (v_cmp_lt_f16_e64 ... op_sel:[1,0]) that fails onmainand passes with the fix. PR creation is limited to collaborators, so I'll link a fork branch with awindows-latestrun here.AI-assisted (Claude Code).
@BastienRodz on GitHub · 2026-11-24 12:03 UTC · original
A fix, on a branch of my fork since PR creation is limited to collaborators: https://github.com/BastienRodz/VIctory/commits/shader/cmp16-ignores-op-sel (
a8aa1d1, onmainffe310e, 2 files, +95/-1).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.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).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.
@AwkGrep256 on GitHub · 2026-11-24 12:05 UTC · original
Thanks for picking it up. I'm around if you want the hardware checked for anything else.
@Altorru on GitHub · 2026-11-24 12:27 UTC · original
Fixed in fork PR Altorru/VIctory#2, commit
0d918ce.half_src/half_fsrckeep their op_sel behaviour; newhalf_cmp_src/half_cmp_fsrcignore VOP3 op_sel but still honour an SDWA word select, and both 16-bit compare paths (f16 and u16/i16) use them.v_cmp_class_f16is unchanged, as its op_sel behaviour was not measured. The new test coversv_cmp_lt_f16andv_cmp_lt_u16withop_sel:[1,0]plus a clear control, with one case per form that is true only if op_sel is wrongly honoured. Windows CI passed: cargo test --workspace on https://github.com/Altorru/VIctory/actions/runs/45393331977, where the test ran on WARP. No game data. AI-assisted.@AwkGrep256 on GitHub · 2026-11-24 12:37 UTC · original
Thanks. BastienRodz said above he'd take this one too, so it might be worth comparing the two before either goes in as a PR.
@Marvisak on GitHub · 2026-11-25 03:49 UTC · original
Automated triage for the maintainers. Confirmed on
main.half_srcincrates/victory-shader/src/emit/lower.rstakes the high half whenever the VOP3op_selbit is set (v.opsel >> k & 1), for 16-bit compares too. The reporter's gfx1036 measurements show RDNA2 ignores it there. There is no effect on the current title (no 16-bit compare setsop_sel). Open PR #926 by BastienRodz carries the fix and test from this thread. Altorru's fork commit0d918cedoes the same; please compare it with #926 rather than open a second PR.Generated by Claude Code