Repository navigation
Shaders: 16-bit compares read the low halves whatever op_sel says, as RDNA2 does - #926
BastienRodz wants to merge 3 commits into
Conversation
DenRakEiw
left a comment
There was a problem hiding this comment.
Tested head a8aa1d1 (fast-forward on main ffe310e) 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: ok
Clean, focused fix matching RDNA2 16-bit compare op_sel semantics. Approving.
AI-assisted (Gemini 4 Neon).
|
Same divergence confirmed on the sibling runtime (ivall/xcl) — our VOPC emitter selects the compared half with |
|
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 ffe310e and 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. |
|
Tested at head
This checks our translation on AMD's driver, not the console's raw Nit: |
|
Thanks all. Pulled in @MichaelSmithAI's SDWA test ( |
mercuryVM
left a comment
There was a problem hiding this comment.
Tested e477c4b on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 122 passed, including cmp16_ignores_op_sel_as_rdna2_does on the GPU backend, and cargo clippy -p victory-shader --all-targets is clean.
- Ignoring
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).
… halves whatever op_sel says, as RDNA2 does Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… RDNA2 does Upstream: Marvisak#926 by @BastienRodz Co-authored-by: BastienRdz <58186763+BastienRodz@users.noreply.github.com>
e477c4b to
3cdbc0c
Compare
|
Rebased onto |
|
The fix for those two |
…ever op_sel says, as RDNA2 does
3cdbc0c to
ae9158a
Compare
|
Still red on the same two |
ae9158a to
13b6019
Compare
|
Automated triage for the maintainers. Merge candidate (a recommendation to look, not an approval). The new push only rewords the doc comment on The branch merges cleanly. CI: Generated by Claude Code |
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, 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.
… RDNA2 does Previously `half_src` applied VOP3 `op_sel` bits to every 16-bit operation, causing 16-bit compares (`v_cmp_*` and `v_cmpx_*` on f16, u16, and i16) to read the high half when `op_sel` was set. As measured on gfx1036 (RDNA2) across 146 cases in Marvisak#833 (VGPR, SGPR, literal, inline-constant sources, wave32/wave64, and `v_cmpx_*_e64`), RDNA2 hardware ignores VOP3 `op_sel` on 16-bit compares and always compares the low halves, while non-compare 16-bit ops such as `v_add_nc_u16` still honour `op_sel`. Ignore VOP3 `op_sel` in `half_src` (which `half_fsrc` calls as well) for `v_cmp*` instructions except `v_cmp_class*` (not measured), while keeping SDWA word selects intact, and add an end-to-end VALU test covering f16/u16/i16 compares, `v_cmpx_lt_f16`, and `v_add_nc_u16` as a control. Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13b6019 to
d69cac1
Compare
|
Code review and RTX 5090 + WARP + DXIL verification at head
LGTM. |
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#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