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

Closed
github-bot wants to merge 1 commit from github-bot/gh-1036 into main AGit
Owner

@⁠Moon0755 on GitHub · 2026-11-25 16:59 UTC · original
Moon0755:fix/cmp16-ignore-op-sel → main · +120 −2 · 2 files · 1 commits · closed without merging

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

**@⁠Moon0755** on GitHub · 2026-11-25 16:59 UTC · [original](https://github.com/fxceless/victory-fork/pull/1036) `Moon0755:fix/cmp16-ignore-op-sel` → `main` · +120 −2 · 2 files · 1 commits · closed without merging 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:56:25 +00:00
Author
Owner

@⁠avt0m4t48 on GitHub · 2026-11-25 17:11 UTC · original

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.

**@⁠avt0m4t48** on GitHub · 2026-11-25 17:11 UTC · [original](https://github.com/fxceless/victory-fork/pull/1036#issuecomment-7169130882) 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.
Author
Owner

@⁠Moon0755 on GitHub · 2026-11-25 17:14 UTC · original

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

**@⁠Moon0755** on GitHub · 2026-11-25 17:14 UTC · [original](https://github.com/fxceless/victory-fork/pull/1036#issuecomment-7169204691) 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
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 18:00 UTC · original

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

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 18:00 UTC · [original](https://github.com/fxceless/victory-fork/pull/1036#issuecomment-7170319298) 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://git.gtahub.st/github/fxceless--victory-fork/pulls/1030
github-bot closed this pull request 2026-11-26 11:35:53 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.