Skip to content

Shaders: lower s_cmov_b32, s_cmov_b64 and s_cmovk_i32 - #91

Open
tedin7 wants to merge 1 commit into
Marvisak:mainfrom
tedin7:vic-scalar-cmov
Open

tedin7 wants to merge 1 commit into
Marvisak:mainfrom
tedin7:vic-scalar-cmov

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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 Shaders: set SCC from the carry of s_addc_u32 and s_subb_u32 #81 adds a similar lowers() test helper in the same tests module, so a trivial merge conflict there is possible.

@DaviTostes

Copy link
Copy Markdown

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

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

@lordon1a

Copy link
Copy Markdown
Contributor

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

Lyrnc commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants