shader: SCC after s_min/s_max is the comparison, after s_lshlN_add_u32 the carry (stacked on #62) #88
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/uiliannn--VItoriaBr!88
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-88"
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?
@lcg007xd-c on GitHub · 2026-11-25 22:19 UTC · original
lcg007xd-c:shader-salu-scc→main· +1137 −3 · 4 files · 6 commits · openWhat is broken
The scalar lowering (
sopinemit/lower.rs) sets SCC toresult != 0for every SCC-writing operation it does not name. AMD's RDNA2 ISA gives two families a different SCC:s_min_i32/s_min_u32/s_max_i32/s_max_u32(SOP2 6–9):SCC = (S0 < S1)for min,SCC = (S0 > S1)for max.s_lshl1_add_u32…s_lshl4_add_u32(SOP2 46–49):SCC = ((S0 << N) + S1) >= 2^32, "unsigned overflow". That is the carry out of the add, likes_add_u32's. Mesa's ACO confirms the reading: it fusess_add_u32(a, s_lshl_b32(b, n))intos_lshlN_add_u32even whens_add_u32's carry is used (aco_optimizer.cpp), buts_add_i32only when its SCC is unused.So
s_min_u32 s12, 5, 3followed bys_cselect_b32ors_cbranch_scc1took the wrong side.Found with the CPU harness (#62): I ran
op s12, s0, s1; s_cselect_b32 s13, 1, 0; v_mov_b32 v0, s13for each op on main.s_min_i32 case 0 [5, 3]: got 1, want 0.s_lshl1_add_u32gave SCC = 1 for1 << 1 + 1, where nothing overflows.The change (
emit/lower.rs, insop)s_min/s_max: the comparison that already picks the result is now also SCC.s_lshlN_add_u32: SCC is the carry of the 32-bit add,r < (a << N). Bits shifted out of the 32-bit shift do not count, which matches ACO's fusion.Tests
emit::cpu_tests::scalar_min_max_set_scc_to_the_comparisonandscalar_shift_adds_set_scc_to_the_carry(Linux, through #62's harness):u32::MAXvs 1 signed and unsigned, equal);s_lshl1/s_lshl4_add_u32, including a shifted-out bit with no carry and a real carry.Both fail without the fix (
s_min_i32 case 0 [5, 3]: got 0x00000001, want 0x00000000,s_lshl1_add_u32 case 0 [1, 1]: got 0x00000001, want 0x00000000) and pass with it.valu_tests::scalar_min_max_and_shift_add_set_scc_like_rdna2(Windows/GPU): the same program shape and checks on the GPU.Run here (Linux, Rust 1.98.1, LLVM 23):
cargo test -p victory-shader --lib --locked: 200 passed, 0 failed, 2 ignored.CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run here: the GPU case, since I have no Windows machine.
🤖 Generated with Claude Code
The scalar lowering set SCC to "result != 0" for every operation it did not name. AMD's RDNA2 ISA gives s_min_*/s_max_* SCC = (S0 < S1) and (S0 > S1), and s_lshl1..4_add_u32 the carry out of the add ("unsigned overflow", as s_add_u32's; Mesa's ACO fuses s_lshl_b32 + s_add_u32 into them even where the carry is read). So s_min_u32 s0, 5, 3 followed by s_cselect took the wrong side. Found with the CPU harness: s_min/s_max gave the wrong SCC in 16 of 24 cases, s_lshl1_add_u32 gave 1 for 1 << 1 + 1. Both now pass, and a GPU case in valu_tests checks the same on Windows. Co-Authored-By: Claude Opus 5.5 <[email protected]>@lmouz823-lang on GitHub · 2026-11-27 15:14 UTC · original
I can take the Windows/NVIDIA validation of this PR at exact head
3be32b40c29e22d188386b1af8f44c90cdb1ce6c. I will runscalar_min_max_and_shift_add_set_scc_like_rdna2on an RTX 4060 Laptop with strict device checks and the SDK DXIL validator, verify actual hardware and WARP execution, and check the SCC boundary coverage. In particular, the current shift-add inputs appear to exercise only lshl1 with carry=0; I plan a small synthetic test addition for shifts 1–4, addition carry=1, and shifted-out bits without addition carry. I'll report exact results and any test-only diff here.AI-assisted with Codex.
@lmouz823-lang on GitHub · 2026-11-27 15:25 UTC · original
Windows validation on exact head
3be32b40c29e22d188386b1af8f44c90cdb1ce6c: the existingscalar_min_max_and_shift_add_set_scc_like_rdna2test passes on both RTX 4060 Laptop and WARP, withVICTORY_STRICT_TESTS=1, exactly one selected test and no GPU-test skips.The five shift-add inputs all produce carry 0, so I added a test-only follow-up covering shifts 1–4 with 40 fixed result/SCC vectors. It checks carry 1, shifted-out bits without addition carry, and values just below/at/above the carry boundary. Each vector is tested with incoming SCC 0 and 1; result and SCC are read separately: 160 dispatches per backend, 320 total. The new test passes on both backends. Expected values are fixed tables checked against AMD RDNA2 ISA, §12.1.
Negative control: temporarily forcing shift-add SCC to 0 still lets the original test pass, but the new test fails on hardware at
(0x7fffffff, 2), got SCC 0 / expected 1. After restoring the implementation, both tests pass again. The patch also corrects the CPU test's comment about(0x80000000 << 1) + 0xffffffff, whose carry is 0.Environment: Windows 11 Pro 26200, i9-14900HX, NVIDIA 610.88, Rust 1.98.1 MSVC, release. Explicit Windows SDK
dxil.dll1.8.2502.11 was verified to createIDxcValidator; all generated modules passed validation/hash checks. Temporary diagnostics and the mutation were removed. Strict skip-policy test andgit diff --checkalso pass.Command for each exact filter:
Not tested: native AMD/console execution, game/FPS, the Linux CPU harness, full workspace suite, or a merge onto current main.
AI assistance: Codex implemented the test, ran the checks and drafted this report.
Test-only patch against the PR head
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.