Skip to content

Shaders: restore 16-bit compares reading the low halves whatever op_sel says - #224

Merged
pablogonz12 merged 2 commits into
mainfrom
int/q5-cmp16
Nov 25, 2026
Merged

pablogonz12 merged 2 commits into
mainfrom
int/q5-cmp16

Conversation

@pablogonz12

@pablogonz12 pablogonz12 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

What

A regression, not a new idea: commit a8aa1d1cb (merged as Scarlight #16 / VIctory #926, BastienRodz) made v_cmp*_u16/i16/f16 read the low halves whatever VOP3 op_sel says, as RDNA2 does, with its test. Both the condition and the tests disappeared when the VALU integer operations moved to their own module (94d02c71b); half_src (crates/victory-shader/src/emit/lower.rs) honours op_sel for every 16-bit operation again, so a compare with a source op_sel set reads the wrong half and branches the wrong way.

This restores a8aa1d1cb and its follow-up f45973553 verbatim (git cherry-pick -x, author swarm kept): op_sel is ignored for v_cmp* other than v_cmp_class, the SDWA word select still applies. Route: fxceless/victory-fork PR #1036 reports the same class independently.

Gates

  • cargo xwin clippy --target x86_64-pc-windows-msvc --workspace --all-targets -- -D warnings: clean.
  • Restored tests under Wine on RADV: cmp16_ignores_op_sel_as_rdna2_does and cmp16_sdwa_preserves_word_selects — 2 passed; 0 failed.
  • Offline shaders-dump: 751/751 ok, DXIL identical to the base report of 23:28Z (0 of 751 changed). victory-run: 2912 rows, 2909 ok, 3 dxil-spirv timeouts (the same baseline), 0 of 2912 DXIL changed — no program in either dump sets op_sel on a 16-bit compare, so the fix changes the class, not a count.
  • cargo xtask policy: asset policy: 255 files ok; git grep -iE "gta ?(vi|6)|grand theft|rockstar" empty.

Off switch

None: this restores the behaviour Scarlight already shipped in #16; a switch could only turn the bug back on.

Not tested in a game run.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed incorrect results in 16-bit comparisons when selecting operand words. Floating-point, signed, and unsigned comparisons now handle low- and high-word selections correctly.
    • Preserved operand selection behavior for other 16-bit operations, including addition.

BastienRodz and others added 2 commits November 25, 2026 23:39
… 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 #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>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: 16-bit comparison operand selection

Layer / File(s) Summary
Comparison operand selection
crates/victory-shader/src/emit/lower.rs
half_src suppresses op_sel high-half selection for 16-bit comparisons other than v_cmp_class. Other operations retain the existing behavior.
VOP3 and SDWA comparison tests
crates/victory-shader/src/emit/valu_tests.rs
GPU-backed tests cover VOP3 comparison operand selection, including v_cmpx_lt_f16, and SDWA comparisons. A v_add_nc_u16 test checks that non-comparison operations still honor op_sel.

Suggested reviewers: fxceless, r4tedx

Change: Bug fix

Merge Risk: Minimal · up to b5283

This restores the earlier behavior where 16-bit compare instructions read the low halves regardless of op_sel, with tests covering the change. No merge-blocking risk was found.

Security architecture risk: Minimal · up to b5283

The fix changes which half of an operand an existing shader comparison reads. It does not add an interface, grant new access, or require a deployment change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 2
  • Waived: $0.50 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: af1fe98a-435e-40de-afc2-ffdb3bb34a60
Commits

Reviewing files that changed from the base of the PR and between 6319223 and b528388.

Files selected for processing: 2

  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/emit/valu_tests.rs

Limit details: You’ve used all 10 included reviews currently available.

@pablogonz12
pablogonz12 merged commit 3533680 into main Nov 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants