Shaders: lower s_cmov_b32, s_cmov_b64 and s_cmovk_i32 #91

Open
tedin7 wants to merge 1 commit from upstream-pr/91 into main
tedin7 commented 2026-11-24 00:22:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tedin7 on 2026-11-24T00:22:43Z.


What

  • Lowers the scalar conditional moves s_cmov_b32, s_cmov_b64 and s_cmovk_i32 as a select on SCC between the source and the destination's old value. They do not touch SCC.

Why

  • The IR already tracks them (reads SCC and the old destination, ir.rs), but the lowering had no case for them, so any shader using one failed to translate with Unsupported.

Tested

  • Linux x86_64 only. New unit test scalar_conditional_moves_lower builds synthetic compute programs (no game data) with each of the three instructions and lowers them. Before the change it fails with Unsupported { what: "s_cmov_b32" }; after, it passes.
  • cargo test -j4 -p victory-shader: 52 passed, 0 failed.
  • cargo clippy -j4 -p victory-shader --tests: no new warnings (one existing dead_code warning for a Windows-only test helper).
  • rustfmt --check on lower.rs: clean.
  • NOT run: Windows runtime, GPU, or a real console shader using these instructions. The test checks that lowering succeeds, not the emitted DXIL values.
  • Note: PR #81 adds a similar lowers() test helper in the same tests module, so a trivial merge conflict there is possible.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6571713172 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/91). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T00:22:43Z. --- What - Lowers the scalar conditional moves s_cmov_b32, s_cmov_b64 and s_cmovk_i32 as a select on SCC between the source and the destination's old value. They do not touch SCC. Why - The IR already tracks them (reads SCC and the old destination, ir.rs), but the lowering had no case for them, so any shader using one failed to translate with Unsupported. Tested - Linux x86_64 only. New unit test scalar_conditional_moves_lower builds synthetic compute programs (no game data) with each of the three instructions and lowers them. Before the change it fails with Unsupported { what: "s_cmov_b32" }; after, it passes. - cargo test -j4 -p victory-shader: 52 passed, 0 failed. - cargo clippy -j4 -p victory-shader --tests: no new warnings (one existing dead_code warning for a Windows-only test helper). - rustfmt --check on lower.rs: clean. - NOT run: Windows runtime, GPU, or a real console shader using these instructions. The test checks that lowering succeeds, not the emitted DXIL values. - Note: PR #81 adds a similar lowers() test helper in the same tests module, so a trivial merge conflict there is possible.
DaviTostes commented 2026-11-24 06:54:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:23:37Z.


Tested ed5f98f stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test --workspace: 156 passed, 0 failed, 3 ignored; merge with #39 clean.
  • The PR adds 4 #[test]s for the new s_cmov* lowerings, included in that run.
  • No game data used.

AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118021023 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/91#issuecomment-7118021023). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T00:23:37Z. --- Tested `ed5f98f` stacked on **#39** on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test --workspace`: **156 passed, 0 failed, 3 ignored**; merge with #39 clean. - The PR adds 4 `#[test]`s for the new `s_cmov*` lowerings, included in that run. - No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
lordon1a commented 2026-11-24 06:54:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T00:40:15Z.


Verified ed5f98ff6 on Windows 11 (x86_64-pc-windows-gnullvm, rustc 1.100.0, applied cleanly to main@35b054ec0): pass.

  • cargo xtask policy: 150 files ok
  • cargo test -p victory-shader: 58 passed, 0 failed (+1 new lowering test for s_cmov_b32/s_cmov_b64/s_cmovk_i32).

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118310256 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/91#issuecomment-7118310256). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T00:40:15Z. --- Verified `ed5f98ff6` on Windows 11 (`x86_64-pc-windows-gnullvm`, `rustc 1.100.0`, applied cleanly to `main@35b054ec0`): **pass**. - `cargo xtask policy`: 150 files ok - `cargo test -p victory-shader`: **58 passed, 0 failed** (+1 new lowering test for `s_cmov_b32`/`s_cmov_b64`/`s_cmovk_i32`). AI-assisted.
Lyrnc commented 2026-11-24 06:56:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-24T06:22:41Z.


RDNA2 hardware check of the three conditional moves: all match.

Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. 130 cases: SCC set from bit 0 of a test value (s_bitcmp1_b32), with random and edge sources.

  • s_cmov_b32 / s_cmov_b64: the source when SCC = 1, the destination's old value (both dwords for _b64) when SCC = 0: 130/130.
  • s_cmovk_i32: the 16-bit constant sign-extended (0xbeef → 0xffffbeef) when SCC = 1, else the old value: 130/130.
  • SCC is unchanged after them: 130/130.

So the select on SCC is right. The k form sign-extends its simm16, so it is worth checking that the lowering uses the sign-extended constant and not a zero-extended one.

AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123870236 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/91#issuecomment-7123870236). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T06:22:41Z. --- RDNA2 hardware check of the three conditional moves: **all match.** **Setup.** AMD Radeon iGPU of a Ryzen 7 9800X3D, **gfx1036 (RDNA2)**, AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. 130 cases: SCC set from bit 0 of a test value (`s_bitcmp1_b32`), with random and edge sources. - `s_cmov_b32` / `s_cmov_b64`: the source when SCC = 1, the destination's old value (both dwords for `_b64`) when SCC = 0: 130/130. - `s_cmovk_i32`: the 16-bit constant **sign-extended** (`0xbeef` → `0xffffbeef`) when SCC = 1, else the old value: 130/130. - SCC is unchanged after them: 130/130. So the select on SCC is right. The `k` form sign-extends its `simm16`, so it is worth checking that the lowering uses the sign-extended constant and not a zero-extended one. AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
ricarmandoagent commented 2026-11-24 13:02:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ricarmandoagent on 2026-11-24T13:01:24Z.


Two things before this can land.

  1. It is dirty against main today, and the rebase is not mechanical: main now has its own fn lowers(words: &[u32], rsrc2: u32) in this test module (line 6959). This branch adds a second fn lowers(words: &[u32]); both names cannot coexist after a rebase. Reuse the existing helper.

  2. scalar_conditional_moves_lower only asserts that lowering returns Ok (lowers(&words).unwrap()). An inverted select (select(c, cond, old, a)), a swapped half, or a stale destination read all still pass. Since the change is about the value kept when SCC is clear, please assert on the lowered program, or add a fixture that does.

AI-assisted review.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7132239914 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/91#issuecomment-7132239914). Originally posted by [ricarmandoagent](https://github.com/ricarmandoagent) on 2026-11-24T13:01:24Z. --- Two things before this can land. 1. It is `dirty` against main today, and the rebase is not mechanical: `main` now has its own `fn lowers(words: &[u32], rsrc2: u32)` in this test module (line 6959). This branch adds a second `fn lowers(words: &[u32])`; both names cannot coexist after a rebase. Reuse the existing helper. 2. `scalar_conditional_moves_lower` only asserts that lowering returns `Ok` (`lowers(&words).unwrap()`). An inverted select (`select(c, cond, old, a)`), a swapped half, or a stale destination read all still pass. Since the change is about the value kept when SCC is clear, please assert on the lowered program, or add a fixture that does. AI-assisted review.
Marvisak commented 2026-11-25 01:07:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:16:33Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148338496 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/91#issuecomment-7148338496). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:16:33Z. --- <!-- victory-triage v1 head=ed5f98ff67e3c09cde81b36c28bff216cc16a079 verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-shader/src/emit/lower.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/91:upstream-pr/91'
git switch 'upstream-pr/91'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/91'
git switch 'upstream-pr/91'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/91'
git switch 'upstream-pr/91'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/91'
git switch 'main'
git merge --squash 'upstream-pr/91'
git switch 'main'
git merge --ff-only 'upstream-pr/91'
git switch 'main'
git merge 'upstream-pr/91'
git push origin 'main'
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
Marvisak/VIctory!91
No description provided.