Skip to content

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

Closed
Moon0755 wants to merge 1 commit into
fxceless:mainfrom
Moon0755:fix/salu-signed-overflow-scc
Closed

Moon0755 wants to merge 1 commit into
fxceless:mainfrom
Moon0755:fix/salu-signed-overflow-scc

Conversation

@Moon0755

Copy link
Copy Markdown

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

@HAL9000RELOADED

Copy link
Copy Markdown

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 (comment)

@Moon0755 Moon0755 closed this Nov 26, 2026
HAL9000RELOADED added a commit to HAL9000RELOADED/victory-fork that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants