Shaders: compute signed overflow SCC for s_add_i32, s_addk_i32, and s_sub_i32 #1095
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1095"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-24T15:42:47Z.
What's wrong
In
crates/victory-shader/src/emit/lower.rs(salu, lines 2589–2609 and 2752–2754),s_add_i32,s_addk_i32, ands_sub_i32compute the 32-bit resultrbut returncarry = None, which falls through to:Meanwhile
ir.rs(writes_scc, line 951) already marks all three instructions as writingReg::Scc. Any shader that subsequently consumesSCC(for example vias_cselect_b32,s_cselect_b64, ors_cbranch_scc0/1) fails lowering withUnsupported { what: "the carry of a scalar operation" }.Fix
Per the AMD RDNA2 ISA,
S_ADD_I32,S_ADDK_I32, andS_SUB_I32setSCCto the 32-bit two's-complement signed overflow flag (distinct from unsigned carry/borrow ons_add_u32/s_sub_u32):s_add_i32/s_addk_i32:SCC = ((a ^ r) & (b ^ r)) <s 0(operands share a sign bit that the sum flips)s_sub_i32:SCC = ((a ^ b) & (a ^ r)) <s 0(operands have opposite sign bits and the difference flipsa's sign)Both compute signed overflow purely in 32-bit integer arithmetic without requiring
flags::INT64.d25783bonmain(ffe310e), 2 files,+132 / -5Verification (Real GPU + WARP + CI Gates)
Added synthetic end-to-end test
emit::valu_tests::signed_scalar_add_sub_scc_matches_rdna2covering 30 signed-overflow edge cases (INT_MAX + 1,INT_MIN + (-1),INT_MIN + INT_MIN,-1 + 1unsigned-carry/no-signed-overflow,0 - 1,0 - INT_MIN,INT_MIN - 1,INT_MAX - (-1),s_addk_i32with+1and-32768):mainffe310e):d25783b) on Windows 11, NVIDIA GeForce RTX 3060 Ti (driver32.0.16.1656), Rust1.98.1:cargo test -p victory-shader --lib signed_scalar_add_sub_scc_matches_rdna2: ok (DXIL validator + RTX 3060 Ti hardware + Microsoft WARP)cargo clippy --workspace --all-targets --locked -- -D warnings: pass (0 warnings)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass (0 warnings)cargo test --workspace --locked: pass (victory-shader: 121 passed, 0 failed, 1 ignored; all other workspace crates &xtaskpassed)cargo xtask policy:asset policy: 154 files okScope & Non-Overlap
#168coverss_min_*,s_max_*, ands_lshl1-4_add_u32(lines 2685–2700) and does not touchs_add_i32,s_addk_i32, ors_sub_i32(lines 2589–2609).Imported from Marvisak/VIctory. Originally posted by nullmarsh on 2026-11-24T16:14:05Z.
Ran on RDNA2 hardware through vkd3d-proton on a Steam Deck (not native Windows): AMD Van Gogh, RADV 26.1.99, SteamOS 3.8.28, Proton 11.0-3 (wine-11.0) with its vkd3d-proton 212991fc. Windows MSVC test binary (rustc 1.100.0) built from head
d25783bon mainffe310e.signed_scalar_add_sub_scc_matches_rdna2passes: SCC of s_add_i32, s_sub_i32 and s_addk_i32 (+1 and -32768) on all 30 cases.stub_pipeline_is_created, fails on main on this host too (likely vkd3d-proton accepting the zero DXIL digest the test expects refused; environment, not this PR).Not tested: native Windows AMD drivers; WARP (this setup has none, so the WARP leg ran on RADV too); whether the new test fails without the fix on this host.
AI-assisted (Claude Code, Claude Opus 5.5); no game data.
Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T16:29:36Z.
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
d25783b:cargo test -p victory-shaderpasses, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
upstream-sync referenced this pull request2026-11-24 19:03:41 +00:00
Imported from Marvisak/VIctory. Originally posted by Aniseto on 2026-11-24T18:46:33Z.
Ran the new test at
d25783b:Environment: Windows 11 Pro build 26200 x64, Intel Core i5-12400F, 64 GB RAM, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only) driver 32.0.16.2124, Rust 1.98.1 (pinned by
rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.emit::valu_tests::signed_scalar_add_sub_scc_matches_rdna2passes here (1.92 s, it builds and runs shader code on the host GPU). That is the case this PR is about: the console sets SCC from the signed overflow ofs_add_i32/s_addk_i32/s_sub_i32, and the test compares against the RDNA2 result.Because the check runs through the host GPU, this adds a Blackwell datapoint; the adapter is not otherwise a variable in the lowering itself.
Not tested: a title that depends on SCC after those scalar adds (no game data here), RDNA2/RDNA4 and Intel GPUs.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the test, wrote this report; no game data was used.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:35:08Z.
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-shader/src/emit/valu_tests.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.