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

Closed
Moon0755 wants to merge 1 commit from upstream-pr/1036 into main
Moon0755 commented 2026-11-25 16:59:03 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Moon0755 on 2026-11-25T16:59:03Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6609485897 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1036). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-25T16:59:03Z. --- 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](https://github.com/Moon0755/victory-fork/actions/runs/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 commented 2026-11-25 18:05:10 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by avt0m4t48 on 2026-11-25T17:11:05Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7169130882 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1036#issuecomment-7169130882). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-25T17:11:05Z. --- 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 commented 2026-11-25 18:05:11 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Moon0755 on 2026-11-25T17:14:07Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:comment:7169204691 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1036#issuecomment-7169204691). Originally posted by [Moon0755](https://github.com/Moon0755) on 2026-11-25T17:14:07Z. --- 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 commented 2026-11-25 18:05:15 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T18:00:59Z.


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: https://github.com/fxceless/victory-fork/pull/1030#issuecomment-7170315986

<!-- greyfinch-sync:fxceless/victory-fork:comment:7170319298 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1036#issuecomment-7170319298). Originally posted by [HAL9000RELOADED](https://github.com/HAL9000RELOADED) on 2026-11-25T18:00:59Z. --- 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: https://github.com/fxceless/victory-fork/pull/1030#issuecomment-7170315986
upstream-sync closed this pull request 2026-11-26 12:07:13 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!1034
No description provided.