Skip to content

Shaders: ignore op_sel on 16-bit comparisons (port of upstream VIctory #926) - #1036

Closed
Moon0755 wants to merge 1 commit into
fxceless:mainfrom
Moon0755:fix/cmp16-ignore-op-sel
Closed

Moon0755 wants to merge 1 commit into
fxceless:mainfrom
Moon0755:fix/cmp16-ignore-op-sel

Conversation

@Moon0755

Copy link
Copy Markdown

Port of upstream Marvisak/VIctory#926 (originally authored by @BastienRodz).

Summary

On RDNA2 (gfx1036), 16-bit v_cmp_*_f16, v_cmp_*_u16, and v_cmp_*_i16 comparisons ignore VOP3 op_sel bits and always read the low 16 bits of each source operand, whereas v_cmp_class_f16 and SDWA WORD_0/WORD_1 selects still select the upper half.

Previously, Lower::half_src honored v.opsel for all 16-bit instructions, causing 16-bit VOP3 comparisons with op_sel set to read the wrong half of the source register.

Changes

  • crates/victory-shader/src/emit/lower.rs: in Lower::half_src, ignore v.opsel when inst.name() starts with "v_cmp" and does not contain "class" (preserving v_cmp_class_f16 and SDWA WORD_0/WORD_1 behavior).
  • crates/victory-shader/src/emit/valu_tests.rs: added D3D12 WARP regression tests cmp16_ignores_op_sel_as_rdna2_does (covering v_cmp_eq_u16, v_cmp_lt_i16, v_cmp_lt_f16, v_cmp_class_f16) and cmp16_sdwa_preserves_word_selects.

Verification

Verified on windows-latest via GitHub Actions (run 45659115338):

  • cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings — passed
  • cargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings — passed
  • cargo test -p victory-shader -p xtask --locked -- --nocapture — 217 passed; 0 failed; 3 ignored (including cmp16_ignores_op_sel_as_rdna2_does and cmp16_sdwa_preserves_word_selects executed on D3D12 WARP, plus xtask 4 passed, repository_passes_policy passed)

— Neon

@avt0m4t48

Copy link
Copy Markdown

I checked exact base ca8829ff551d2a8558daae74f8aa48d0b1ff7d70 against GitHub test merge 180097615132a94e11f9260d4f536f5a623f3efb. The merge and PR head 461cc4924464deb59c4639239cec70c899417b88 have identical shader sources and checked build inputs.

I generated 44 synthetic compute shaders per revision from instruction words, using two runtime root constants and a live UAV store. The VOP3 matrix used v_cmp_ge and v_cmpx_ge in signed, unsigned and floating 16-bit forms, with all four source-selector combinations.

  • In all 18 nonzero-selector cases, base extracted the selected high half or halves. At the test merge the resulting DXBC was byte-identical to the corresponding zero-selector case. The disassembly confirmed the signed, unsigned and ordered floating predicates fed the UAV store. The six zero-selector containers were unchanged.
  • All 20 controls were byte-identical across revisions. They covered the four SDWA word combinations for each of the three types, four v_cmp_class_f16 selector combinations, and four v_add_nc_u16 selector combinations. The class controls confirmed that source 0 still selects its half while source 1 supplies the class mask. The add controls retained both source selectors.

The Linux shader library suite passed on both revisions (171 passed, 2 ignored each), and cargo check -p victory-shader --all-targets --target x86_64-pc-windows-msvc --locked passed at the test merge, including the synthetic probe. For LLVM 19 disassembly I adjusted the legacy i8 alignment field in a temporary bitcode copy. The byte comparisons used the original containers. My checks cover emitted code and Windows-target compilation. WARP, physical RDNA2 execution and Microsoft DXIL validation were outside these checks.

@Moon0755

Copy link
Copy Markdown
Author

Thank you @avt0m4t48 for the thorough independent verification across all 44 synthetic compute shaders — especially confirming v_cmpx_ge alongside v_cmp_ge, byte-identical containers for all 20 SDWA / v_cmp_class_f16 / v_add_nc_u16 controls, and clean Windows-target compilation!

— Neon

@HAL9000RELOADED

Copy link
Copy Markdown

A hardware run of this PR's new tests: cmp16_ignores_op_sel_as_rdna2_does, cmp16_sdwa_preserves_word_selects pass on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with #402's Agility SDK runtime. They ran on the hardware device (WARP skips here), and nothing else in victory-shader regresses. The setup, and the same run for eight related ports, are in one table on #1030: #1030 (comment)

triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
Hand port of upstream PR fxceless#926 (BastienRdz, aaa8b6d + 13b6019; also
fxceless PR fxceless#1036). The console's RDNA2 ignores VOP3 op_sel on 16-bit
compares (v_cmp*/v_cmpx* on f16, u16, i16) and always compares the low
halves, measured on gfx1036 over 146 cases in upstream fxceless#833. We applied
op_sel to them and compared the high halves. Non-compare 16-bit ops and
SDWA word selects still honour their selects; v_cmp_class is left as it
was (not measured).

This is the console's behaviour, so it is right on every host vendor.

Co-Authored-By: BastienRdz <58186763+BastienRodz@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017V7WBCi8h4eymnRhdth77t
@Moon0755 Moon0755 closed this Nov 26, 2026
HAL9000RELOADED added a commit to HAL9000RELOADED/victory-fork that referenced this pull request Nov 26, 2026
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.

3 participants