16-bit compares honour VOP3 op_sel, RDNA2 ignores it (no effect on GTA VI) #833

Open
opened 2026-11-26 04:14:02 +00:00 by github-bot · 6 comments
Owner

@⁠AwkGrep256 on GitHub · 2026-11-24 11:52 UTC · original

On RDNA2, the VOP3 op_sel bits are ignored by the 16-bit compares (v_cmp_* and v_cmpx_* on f16, 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

v0 = 0x4000_3C00    high half 2.0, low half 1.0 (f16)
v1 = 0x3C00_3E00    high half 1.0, low half 1.5

v_cmp_lt_f16_e64 vcc, v0, v1 op_sel:[1,0]
compares result
RDNA2 hardware low(v0) 1.0 < low(v1) 1.5 true
VIctory high(v0) 2.0 < low(v1) 1.5 false

Where

compare() in crates/victory-shader/src/emit/lower.rs reads both sources through half_src / half_fsrc, and half_src picks the half from op_sel:

let mut high = v.opsel >> k & 1 != 0;

op_sel is decoded for VOP3 compares in gfx10/fields.rs (v.opsel = (w0 >> 11 & 0xF) as u8).

Possible fix

Ignore op_sel for the compares in half_src, and keep the SDWA select below it, which does pick the half on hardware:

// RDNA2 ignores VOP3 op_sel on 16-bit compares (v_cmp_class not measured).
let name = inst.name();
let compare = name.starts_with("v_cmp") && !name.contains("class");
let mut high = !compare && v.opsel >> k & 1 != 0;

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 ignoring op_sel. As a control, v_add_nc_u16 with the same bits set does honour them, so the encoding is right.

Impact

None for GTA VI right now. shaders.rpf has 1,368 16-bit compares, 166 of them VOP3 encoded, and none of them set op_sel. Filing it so it's known if another title runs into it.

**@⁠AwkGrep256** on GitHub · 2026-11-24 11:52 UTC · [original](https://github.com/Marvisak/VIctory/issues/833) On RDNA2, the VOP3 `op_sel` bits are ignored by the 16-bit compares (`v_cmp_*` and `v_cmpx_*` on `f16`, `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 ``` v0 = 0x4000_3C00 high half 2.0, low half 1.0 (f16) v1 = 0x3C00_3E00 high half 1.0, low half 1.5 v_cmp_lt_f16_e64 vcc, v0, v1 op_sel:[1,0] ``` | | compares | result | |---|---|---| | RDNA2 hardware | low(v0) 1.0 < low(v1) 1.5 | true | | VIctory | high(v0) 2.0 < low(v1) 1.5 | false | ### Where `compare()` in `crates/victory-shader/src/emit/lower.rs` reads both sources through `half_src` / `half_fsrc`, and `half_src` picks the half from `op_sel`: ```rust let mut high = v.opsel >> k & 1 != 0; ``` `op_sel` is decoded for VOP3 compares in `gfx10/fields.rs` (`v.opsel = (w0 >> 11 & 0xF) as u8`). ### Possible fix Ignore `op_sel` for the compares in `half_src`, and keep the SDWA select below it, which does pick the half on hardware: ```rust // RDNA2 ignores VOP3 op_sel on 16-bit compares (v_cmp_class not measured). let name = inst.name(); let compare = name.starts_with("v_cmp") && !name.contains("class"); let mut high = !compare && v.opsel >> k & 1 != 0; ``` ### 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 ignoring `op_sel`. As a control, `v_add_nc_u16` with the same bits set does honour them, so the encoding is right. ### Impact None for GTA VI right now. `shaders.rpf` has 1,368 16-bit compares, 166 of them VOP3 encoded, and none of them set `op_sel`. Filing it so it's known if another title runs into it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:02 +00:00
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-24 11:53 UTC · original

I'll take this one: ignore op_sel for the 16-bit v_cmp/v_cmpx (keeping the SDWA select), with a synthetic valu_tests case built from your example (v_cmp_lt_f16_e64 ... op_sel:[1,0]) that fails on main and passes with the fix. PR creation is limited to collaborators, so I'll link a fork branch with a windows-latest run here.

AI-assisted (Claude Code).

**@⁠BastienRodz** on GitHub · 2026-11-24 11:53 UTC · [original](https://github.com/Marvisak/VIctory/issues/833#issuecomment-7130692412) I'll take this one: ignore `op_sel` for the 16-bit `v_cmp`/`v_cmpx` (keeping the SDWA select), with a synthetic `valu_tests` case built from your example (`v_cmp_lt_f16_e64 ... op_sel:[1,0]`) that fails on `main` and passes with the fix. PR creation is limited to collaborators, so I'll link a fork branch with a `windows-latest` run here. AI-assisted (Claude Code).
Author
Owner

@⁠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, on main ffe310e, 2 files, +95/-1).

What's wrong

On RDNA2 the VOP3 op_sel bits are ignored by the 16-bit compares (v_cmp_* and v_cmpx_* on f16, u16, i16): both sources come from the low 16 bits. #833 measured it on gfx1036 (146 rows, every source kind, wave32 and wave64), with v_add_nc_u16 as the control that does honour the bits. half_src honours op_sel for every 16-bit operation:

let mut high = v.opsel >> k & 1 != 0;

So v_cmp_lt_f16_e64 vcc, v0, v1 op_sel:[1,0] with v0 = 0x4000_3C00 and v1 = 0x3C00_3E00 compares 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, which half_fsrc also goes through, ignores op_sel when the instruction is a v_cmp* other than v_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_sel says, as RDNA2 does. Nothing changes for Grand Theft Auto VI: #833 counted 166 VOP3 16-bit compares in its shaders, none with op_sel set.

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_u16 and v_cmp_lt_i16, each with op_sel 0b01, 0b10 and 0b11, on values where the high and low halves give opposite answers;
  • v_cmpx_lt_f16_e64 writing EXEC;
  • a control: v_add_nc_u16 with op_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 warnings with and without --all-features, cargo test --workspace --locked -- --test-threads=1):

cargo xtask policy: ok. Synthetic programs only; no game data.

Not tested: v_cmp_class_* with op_sel (left as it was); a title that sets op_sel on a 16-bit compare.

AI-assisted: implemented with Gemini 4 Neon, reviewed and run with Claude Code.

**@⁠BastienRodz** on GitHub · 2026-11-24 12:03 UTC · [original](https://github.com/Marvisak/VIctory/issues/833#issuecomment-7130905579) 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`, on `main` `ffe310e`, 2 files, +95/-1). ## What's wrong On RDNA2 the VOP3 `op_sel` bits are ignored by the 16-bit compares (`v_cmp_*` and `v_cmpx_*` on `f16`, `u16`, `i16`): both sources come from the low 16 bits. #833 measured it on gfx1036 (146 rows, every source kind, wave32 and wave64), with `v_add_nc_u16` as the control that does honour the bits. `half_src` honours `op_sel` for every 16-bit operation: ```rust let mut high = v.opsel >> k & 1 != 0; ``` So `v_cmp_lt_f16_e64 vcc, v0, v1 op_sel:[1,0]` with v0 = `0x4000_3C00` and v1 = `0x3C00_3E00` compares 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`, which `half_fsrc` also goes through, ignores `op_sel` when the instruction is a `v_cmp*` other than `v_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_sel` says, as RDNA2 does. Nothing changes for Grand Theft Auto VI: #833 counted 166 VOP3 16-bit compares in its shaders, none with `op_sel` set. ## 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_u16` and `v_cmp_lt_i16`, each with `op_sel` `0b01`, `0b10` and `0b11`, on values where the high and low halves give opposite answers; - `v_cmpx_lt_f16_e64` writing EXEC; - a control: `v_add_nc_u16` with `op_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 warnings` with and without `--all-features`, `cargo test --workspace --locked -- --test-threads=1`): - **This change:** everything passes; `victory-shader` 121 passed, 0 failed (https://github.com/BastienRodz/VIctory/actions/runs/45389398916). - **The new test alone on `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_*` with `op_sel` (left as it was); a title that sets `op_sel` on a 16-bit compare. AI-assisted: implemented with Gemini 4 Neon, reviewed and run with Claude Code.
Author
Owner

@⁠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.

**@⁠AwkGrep256** on GitHub · 2026-11-24 12:05 UTC · [original](https://github.com/Marvisak/VIctory/issues/833#issuecomment-7130953036) Thanks for picking it up. I'm around if you want the hardware checked for anything else.
Author
Owner

@⁠Altorru on GitHub · 2026-11-24 12:27 UTC · original

Fixed in fork PR Altorru/VIctory#2, commit 0d918ce. half_src/half_fsrc keep their op_sel behaviour; new half_cmp_src/half_cmp_fsrc ignore 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_f16 is unchanged, as its op_sel behaviour was not measured. The new test covers v_cmp_lt_f16 and v_cmp_lt_u16 with op_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.

**@⁠Altorru** on GitHub · 2026-11-24 12:27 UTC · [original](https://github.com/Marvisak/VIctory/issues/833#issuecomment-7131470041) Fixed in fork PR Altorru/VIctory#2, commit 0d918ce. `half_src`/`half_fsrc` keep their op_sel behaviour; new `half_cmp_src`/`half_cmp_fsrc` ignore 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_f16` is unchanged, as its op_sel behaviour was not measured. The new test covers `v_cmp_lt_f16` and `v_cmp_lt_u16` with `op_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.
Author
Owner

@⁠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.

**@⁠AwkGrep256** on GitHub · 2026-11-24 12:37 UTC · [original](https://github.com/Marvisak/VIctory/issues/833#issuecomment-7131687475) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:49 UTC · original

Automated triage for the maintainers. Confirmed on main. half_src in crates/victory-shader/src/emit/lower.rs takes the high half whenever the VOP3 op_sel bit 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 sets op_sel). Open PR #926 by BastienRodz carries the fix and test from this thread. Altorru's fork commit 0d918ce does the same; please compare it with #926 rather than open a second PR.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:49 UTC · [original](https://github.com/Marvisak/VIctory/issues/833#issuecomment-7152271060) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-24T12:37:02Z at=2026-11-25T03:49:13Z --> Automated triage for the maintainers. Confirmed on `main`. `half_src` in `crates/victory-shader/src/emit/lower.rs` takes the high half whenever the VOP3 `op_sel` bit 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 sets `op_sel`). Open PR #926 by BastienRodz carries the fix and test from this thread. Altorru's fork commit `0d918ce` does the same; please compare it with #926 rather than open a second PR. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#833
No description provided.