fix(shader): lower 16-bit DPP compares and refuse 64-bit DPP compares #259

Merged
Sheffy007 merged 1 commit from upstream-pr/259 into main 2026-11-27 13:35:46 +00:00
Sheffy007 commented 2026-11-27 05:37:28 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T05:37:28Z.


What this changes

Refs #258

  • Lower full-mask 16-bit VOPC DPP compares (f16, i16, u16, v_cmp_class_f16, and v_cmpx_*_16) through Lower::half_src when Lower::dpp returns Ok((x, None)).
  • Explicitly refuse 64-bit compares with DPP ("a 64-bit compare with DPP", since src64 does not read self.src0).
  • Keep Ok((_, Some(_))) => Err("a compare with DPP row masks or bounds") refused, matching LLVM GCNDPPCombine.cpp's MaskAllLanes constraint (assert(MaskAllLanes || !isVOPC(DPPOp))).

How it was tested

  • native::addr_tests::compares_with_16bit_dpp_vcmpx_and_class_run_on_the_gpu (on Apple Silicon Metal GPU, with explicit constant expected arrays): tests v_cmp_gt_f16_dpp ([1, 0, 0, 1]), v_cmp_lt_i16_dpp with row_shr:1 bound_ctrl:1 ([0, 1]), v_cmp_class_f16_dpp ([0, 1, 1, 0]), and v_cmpx_eq_u16_dpp narrowing EXEC ([77, 77, CANARY, CANARY]).
  • emit::graphics::tests::pixel_compares_with_16bit_dpp_and_64bit_or_partial_mask_refusals.
  • Corpus comparison by output fingerprint (@Sandile-0511, 21,608 containers): 0 newly translated, 0 output changed, 0 newly refused.
  • cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask, both x86_64-pc-windows-gnullvm clippy targets, and cargo xtask policy.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5521791041 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/259). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T05:37:28Z. --- ## What this changes Refs #258 - Lower full-mask 16-bit VOPC DPP compares (`f16`, `i16`, `u16`, `v_cmp_class_f16`, and `v_cmpx_*_16`) through `Lower::half_src` when `Lower::dpp` returns `Ok((x, None))`. - Explicitly refuse 64-bit compares with DPP (`"a 64-bit compare with DPP"`, since `src64` does not read `self.src0`). - Keep `Ok((_, Some(_))) => Err("a compare with DPP row masks or bounds")` refused, matching LLVM `GCNDPPCombine.cpp`'s `MaskAllLanes` constraint (`assert(MaskAllLanes || !isVOPC(DPPOp))`). ## How it was tested - `native::addr_tests::compares_with_16bit_dpp_vcmpx_and_class_run_on_the_gpu` (on Apple Silicon Metal GPU, with explicit constant expected arrays): tests `v_cmp_gt_f16_dpp` (`[1, 0, 0, 1]`), `v_cmp_lt_i16_dpp` with `row_shr:1 bound_ctrl:1` (`[0, 1]`), `v_cmp_class_f16_dpp` (`[0, 1, 1, 0]`), and `v_cmpx_eq_u16_dpp` narrowing `EXEC` (`[77, 77, CANARY, CANARY]`). - `emit::graphics::tests::pixel_compares_with_16bit_dpp_and_64bit_or_partial_mask_refusals`. - Corpus comparison by output fingerprint (@Sandile-0511, 21,608 containers): `0 newly translated, 0 output changed, 0 newly refused`. - `cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask`, both `x86_64-pc-windows-gnullvm` clippy targets, and `cargo xtask policy`.
LakshanSivakumar commented 2026-11-27 06:48:33 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T06:48:33Z.


Thank you for this. It converts a refusal into an accept, so I need three things before it can merge.

  1. Evidence for the claim. Main refused these compares with the note that lanes DPP leaves out keep their old bit. This pull request says they write 0. Please quote the ISA text you rely on and say how it was confirmed on hardware or in LLVM's tests. If the old bit is kept, the guarded compares this now accepts are wrong accepts, and I would rather keep refusing them.
  2. A test the model cannot pass by construction. compares_with_16bit_dpp_and_row_bank_bounds_run_on_the_gpu computes its expected values from the same rule as the code. Please add one whose expected values come from somewhere else, and one each for v_cmpx with DPP, v_cmp_class_f16 with DPP, and the new 64-bit refusal.
  3. The full-corpus comparison by output fingerprint (gained, regressed, changed per stage), not only translated or refused counts. #250 has the same request.

Also: #182 and #15 are closed, please refer to #258. This pull request, #261 and #262 all append to the same place in docs/native-host.md, so the second and third will need a rebase after the first merges.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7211866215 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/259#issuecomment-7211866215). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T06:48:33Z. --- Thank you for this. It converts a refusal into an accept, so I need three things before it can merge. 1. Evidence for the claim. Main refused these compares with the note that lanes DPP leaves out keep their old bit. This pull request says they write 0. Please quote the ISA text you rely on and say how it was confirmed on hardware or in LLVM's tests. If the old bit is kept, the guarded compares this now accepts are wrong accepts, and I would rather keep refusing them. 2. A test the model cannot pass by construction. `compares_with_16bit_dpp_and_row_bank_bounds_run_on_the_gpu` computes its expected values from the same rule as the code. Please add one whose expected values come from somewhere else, and one each for `v_cmpx` with DPP, `v_cmp_class_f16` with DPP, and the new 64-bit refusal. 3. The full-corpus comparison by output fingerprint (gained, regressed, changed per stage), not only translated or refused counts. #250 has the same request. Also: #182 and #15 are closed, please refer to #258. This pull request, #261 and #262 all append to the same place in `docs/native-host.md`, so the second and third will need a rebase after the first merges.
LakshanSivakumar commented 2026-11-27 08:07:58 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T08:07:58Z.


Sandile-0511's corpus run (his comment in #258) finds no shader whose outcome or output changes with this pull request. So there is no measured harm, and also no measured use: none of the title's shaders in that corpus needs it.

My three points stand, and the first matters most: please quote the ISA text that says a DPP compare writes 0 in the lanes it leaves out, and say how it was confirmed. If it is not, those shaders stay refused. Without a shader that needs it, I would also like to hear why it should merge now. The branch is also behind main.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7213185369 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/259#issuecomment-7213185369). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T08:07:58Z. --- Sandile-0511's corpus run (his comment in #258) finds no shader whose outcome or output changes with this pull request. So there is no measured harm, and also no measured use: none of the title's shaders in that corpus needs it. My three points stand, and the first matters most: please quote the ISA text that says a DPP compare writes 0 in the lanes it leaves out, and say how it was confirmed. If it is not, those shaders stay refused. Without a shader that needs it, I would also like to hear why it should merge now. The branch is also behind main.
Sheffy007 commented 2026-11-27 08:39:06 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T08:39:06Z.


Addressed all three points and rebased onto main (2a3b03d):

  1. Kept Ok((_, Some(_))) (row_mask/bank_mask/unguarded bound_ctrl:0) refused: Checking LLVM lib/Target/AMDGPU/GCNDPPCombine.cpp confirms LLVM itself enforces assert((MaskAllLanes || !(TII->isVOPC(DPPOp) || ...)) && "VOPC cannot form DPP unless mask is full") alongside BoundCtrlZero || ExecMaskSame because VOPC DPP lacks an old operand and partial masks do not clear unmasked sdst bits. Reverted enable masking so Ok((_, Some(_))) continues to return Err("a compare with DPP row masks or bounds"), keeping only full-mask 16-bit VOPC DPP (Ok((x, None))) and the new 64-bit DPP refusal (src64 ignores self.src0).
  2. Independent expected-value Metal GPU tests & refusals: Replaced the formula-based check with native::addr_tests::compares_with_16bit_dpp_vcmpx_and_class_run_on_the_gpu testing explicit input tables against fixed constant arrays for v_cmp_gt_f16_dpp ([1, 0, 0, 1]), v_cmp_lt_i16_dpp with row_shr:1 bound_ctrl:1 ([0, 1]), v_cmp_class_f16_dpp ([0, 1, 1, 0]), and v_cmpx_eq_u16_dpp narrowing EXEC ([77, 77, CANARY, CANARY]), plus negative assertions in emit::graphics::tests::pixel_compares_with_16bit_dpp_and_64bit_or_partial_mask_refusals for "a 64-bit compare with DPP" and "a compare with DPP row masks or bounds".
  3. Corpus comparison & issue references: Updated references to #258. Per @Sandile-0511's 21,608-shader output-fingerprint sweep (#258), 0 existing shaders in that corpus change output or regress.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7213767075 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/259#issuecomment-7213767075). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T08:39:06Z. --- Addressed all three points and rebased onto `main` (`2a3b03d`): 1. **Kept `Ok((_, Some(_)))` (`row_mask`/`bank_mask`/unguarded `bound_ctrl:0`) refused:** Checking LLVM `lib/Target/AMDGPU/GCNDPPCombine.cpp` confirms LLVM itself enforces `assert((MaskAllLanes || !(TII->isVOPC(DPPOp) || ...)) && "VOPC cannot form DPP unless mask is full")` alongside `BoundCtrlZero || ExecMaskSame` because VOPC DPP lacks an `old` operand and partial masks do not clear unmasked `sdst` bits. Reverted `enable` masking so `Ok((_, Some(_)))` continues to return `Err("a compare with DPP row masks or bounds")`, keeping only full-mask 16-bit VOPC DPP (`Ok((x, None))`) and the new 64-bit DPP refusal (`src64` ignores `self.src0`). 2. **Independent expected-value Metal GPU tests & refusals:** Replaced the formula-based check with `native::addr_tests::compares_with_16bit_dpp_vcmpx_and_class_run_on_the_gpu` testing explicit input tables against fixed constant arrays for `v_cmp_gt_f16_dpp` (`[1, 0, 0, 1]`), `v_cmp_lt_i16_dpp` with `row_shr:1 bound_ctrl:1` (`[0, 1]`), `v_cmp_class_f16_dpp` (`[0, 1, 1, 0]`), and `v_cmpx_eq_u16_dpp` narrowing `EXEC` (`[77, 77, CANARY, CANARY]`), plus negative assertions in `emit::graphics::tests::pixel_compares_with_16bit_dpp_and_64bit_or_partial_mask_refusals` for `"a 64-bit compare with DPP"` and `"a compare with DPP row masks or bounds"`. 3. **Corpus comparison & issue references:** Updated references to `#258`. Per @Sandile-0511's 21,608-shader output-fingerprint sweep (#258), 0 existing shaders in that corpus change output or regress.
LakshanSivakumar commented 2026-11-27 08:53:16 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T08:53:16Z.


My own corpus run (33,625 containers, compared by output fingerprint, this branch merged onto main 2a3b03d1):

No shader gained, lost or changed.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7214036253 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/259#issuecomment-7214036253). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T08:53:16Z. --- My own corpus run (33,625 containers, compared by output fingerprint, this branch merged onto main 2a3b03d1): No shader gained, lost or changed.
LakshanSivakumar commented 2026-11-27 10:32:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T10:32:14Z.


Thank you. Keeping the partial masks and the unguarded bound_ctrl:0 compares refused is the right narrowing, and the tests with fixed expected values answer my second point.

What is left: you quote LLVM's combiner, not the ISA text, and nothing was confirmed on hardware. And my corpus run shows no shader gained, lost or changed, so nothing in the corpus needs this change. I do not see a reason to merge it now. Please say which shader or which game screen needs 16-bit DPP compares. If there is none, I will keep it open until one shows up. The branch is also behind main.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216002312 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/259#issuecomment-7216002312). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T10:32:14Z. --- Thank you. Keeping the partial masks and the unguarded `bound_ctrl:0` compares refused is the right narrowing, and the tests with fixed expected values answer my second point. What is left: you quote LLVM's combiner, not the ISA text, and nothing was confirmed on hardware. And my corpus run shows no shader gained, lost or changed, so nothing in the corpus needs this change. I do not see a reason to merge it now. Please say which shader or which game screen needs 16-bit DPP compares. If there is none, I will keep it open until one shows up. The branch is also behind main.
Sheffy007 commented 2026-11-27 11:53:54 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T11:53:54Z.


Rebased onto current main (e2f211a8).

I do not have a game shader or screen that needs 16-bit DPP compares today: the 9 "a compare with DPP is not supported" refusals from the earlier boot log that prompted this branch turned out to be 32-bit VOPC DPP compares, which 37f9cb54 subsequently covered on main. Your 33,625-container corpus run confirms nothing in the current corpus hits 16-bit or 64-bit VOPC DPP compares yet, so parking this open until a shader hits it (or closing it until needed) makes complete sense.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217602126 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/259#issuecomment-7217602126). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T11:53:54Z. --- Rebased onto current `main` (`e2f211a8`). I do not have a game shader or screen that needs 16-bit DPP compares today: the 9 `"a compare with DPP is not supported"` refusals from the earlier boot log that prompted this branch turned out to be 32-bit VOPC DPP compares, which `37f9cb54` subsequently covered on `main`. Your 33,625-container corpus run confirms nothing in the current corpus hits 16-bit or 64-bit VOPC DPP compares yet, so parking this open until a shader hits it (or closing it until needed) makes complete sense.
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
LakshanSivakumar/Native-Victory-macOS!259
No description provided.