Shaders: compute signed overflow SCC for s_add_i32, s_addk_i32, and s_sub_i32 #1095
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1095
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@ESAT586 on GitHub · 2026-11-24 15:42 UTC · original
ESAT586:shader/signed-salu-scc-overflow→main· +132 −5 · 2 files · 1 commits · openWhat'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).AI-generated & verified with Gemini 4 Neon (not written by a human engineer). s_add_i32, s_addk_i32, and s_sub_i32 previously left SCC as Val::Missing("the carry of a scalar operation"), causing any shader that reads SCC after these instructions (e.g. via s_cselect_b32 or s_cbranch_scc*) to fail lowering. Compute 32-bit two's-complement signed overflow directly in i32 (no i64 capability required), matching the AMD RDNA2 ISA: - s_add_i32 / s_addk_i32: ((a ^ r) & (b ^ r)) <s 0 - s_sub_i32: ((a ^ b) & (a ^ r)) <s 0 Verified with synthetic GPU + WARP + dxil.dll tests in valu_tests.rs on NVIDIA GeForce RTX 3060 Ti (Windows 11, Rust 1.98.1). No game data used. Co-Authored-By: Gemini 4 Neon <[email protected]>@ghost on GitHub · 2026-11-24 16:14 UTC · original
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.
@Zipettte on GitHub · 2026-11-24 16:29 UTC · original
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).
@Aniseto on GitHub · 2026-11-24 18:46 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 00:35 UTC · original
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
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.