Shaders: compute signed overflow SCC for s_add_i32, s_addk_i32, and s_sub_i32 (port of upstream VIctory #1095) #951

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

@⁠Moon0755 on GitHub · 2026-11-25 13:36 UTC · original
Moon0755:fix/salu-signed-overflow-scc → main · +132 −5 · 2 files · 1 commits · closed without merging

Ports upstream Marvisak/VIctory#1095 (ESAT586).

Problem

In crates/victory-shader/src/emit/lower.rs (Lower::salu), s_add_i32, s_addk_i32, and s_sub_i32 compute the 32-bit sum/difference r and return carry = None, falling through to:

None if name.starts_with("s_add") || name.starts_with("s_sub") => {
    Val::Missing("the carry of a scalar operation")
}

Meanwhile ir.rs::writes_scc already marks all three instructions as writing Reg::Scc. Any shader that reads SCC afterwards (e.g. s_cselect_b32, s_cselect_b64, or s_cbranch_scc0/1) fails lowering with Unsupported { what: "the carry of a scalar operation" }.

What changed

  • crates/victory-shader/src/emit/lower.rs (Lower::salu):
    • Compute 32-bit two's-complement signed overflow into SCC for s_add_i32, s_addk_i32, and s_sub_i32 per the AMD RDNA2 ISA (pure 32-bit DXIL integer ops without needing flags::INT64):
      • s_add_i32 / s_addk_i32: ((a ^ r) & (b ^ r)) <s 0 (a and b share a sign bit that r flips).
      • s_sub_i32: ((a ^ b) & (a ^ r)) <s 0 (a and b have opposite signs and r flips a's sign).
  • crates/victory-shader/src/emit/valu_tests.rs (signed_scalar_add_sub_scc_matches_rdna2):
    • Add helper sopk and an end-to-end synthetic compute shader test covering s_add_i32, s_sub_i32, s_addk_i32 +1, and s_addk_i32 -32768 across 30 signed-overflow edge cases (i32::MAX + 1, i32::MIN - 1, 0 - i32::MIN, -1 + 1, etc.), reading SCC back via s_cselect_b32.

Verification

Verified on Windows (windows-latest + dxil.dll + D3D12 WARP) via a temporary scoped CI branch on the fork:

  • CI run: https://github.com/Moon0755/victory-fork/actions/runs/45624774381
  • 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: victory-shader 216 passed; 0 failed; 3 ignored (test emit::valu_tests::signed_scalar_add_sub_scc_matches_rdna2 ... ok, validated via dxil.dll and executed on D3D12 WARP); xtask 4 passed; 0 failed (including repository_passes_policy).

Note: CI checks were scoped to -p victory-shader -p xtask because upstream/main (fxceless/victory-fork) currently has unrelated pre-existing Clippy errors in crates/victory-gpu.

— Neon

**@⁠Moon0755** on GitHub · 2026-11-25 13:36 UTC · [original](https://github.com/fxceless/victory-fork/pull/951) `Moon0755:fix/salu-signed-overflow-scc` → `main` · +132 −5 · 2 files · 1 commits · closed without merging Ports upstream [Marvisak/VIctory#1095](https://github.com/Marvisak/VIctory/pull/1095) (`ESAT586`). ## Problem In `crates/victory-shader/src/emit/lower.rs` (`Lower::salu`), `s_add_i32`, `s_addk_i32`, and `s_sub_i32` compute the 32-bit sum/difference `r` and return `carry = None`, falling through to: ```rust None if name.starts_with("s_add") || name.starts_with("s_sub") => { Val::Missing("the carry of a scalar operation") } ``` Meanwhile `ir.rs::writes_scc` already marks all three instructions as writing `Reg::Scc`. Any shader that reads `SCC` afterwards (e.g. `s_cselect_b32`, `s_cselect_b64`, or `s_cbranch_scc0`/`1`) fails lowering with `Unsupported { what: "the carry of a scalar operation" }`. ## What changed - **`crates/victory-shader/src/emit/lower.rs` (`Lower::salu`)**: - Compute 32-bit two's-complement signed overflow into `SCC` for `s_add_i32`, `s_addk_i32`, and `s_sub_i32` per the AMD RDNA2 ISA (pure 32-bit DXIL integer ops without needing `flags::INT64`): - **`s_add_i32` / `s_addk_i32`:** `((a ^ r) & (b ^ r)) <s 0` (`a` and `b` share a sign bit that `r` flips). - **`s_sub_i32`:** `((a ^ b) & (a ^ r)) <s 0` (`a` and `b` have opposite signs and `r` flips `a`'s sign). - **`crates/victory-shader/src/emit/valu_tests.rs` (`signed_scalar_add_sub_scc_matches_rdna2`)**: - Add helper `sopk` and an end-to-end synthetic compute shader test covering `s_add_i32`, `s_sub_i32`, `s_addk_i32 +1`, and `s_addk_i32 -32768` across 30 signed-overflow edge cases (`i32::MAX + 1`, `i32::MIN - 1`, `0 - i32::MIN`, `-1 + 1`, etc.), reading `SCC` back via `s_cselect_b32`. ## Verification Verified on Windows (`windows-latest` + `dxil.dll` + D3D12 WARP) via a temporary scoped CI branch on the fork: - CI run: https://github.com/Moon0755/victory-fork/actions/runs/45624774381 - `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`: `victory-shader` `216 passed; 0 failed; 3 ignored` (`test emit::valu_tests::signed_scalar_add_sub_scc_matches_rdna2 ... ok`, validated via `dxil.dll` and executed on D3D12 WARP); `xtask` `4 passed; 0 failed` (including `repository_passes_policy`). Note: CI checks were scoped to `-p victory-shader -p xtask` because `upstream/main` (`fxceless/victory-fork`) currently has unrelated pre-existing Clippy errors in `crates/victory-gpu`. — Neon
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:54:31 +00:00
Author
Owner

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

A hardware run of this PR's new test: signed_scalar_add_sub_scc_matches_rdna2 passes on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with #402's Agility SDK runtime. It 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/951#issuecomment-7170316999) A hardware run of this PR's new test: `signed_scalar_add_sub_scc_matches_rdna2` passes on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with #402's Agility SDK runtime. It 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:50 +00:00

Pull request closed

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