Shaders: preserve SCC on signed scalar add and subtract #1421
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!1421
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1421"
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?
@ghptc on GitHub · 2026-11-28 19:36 UTC · original
ghptc:fix/shader-scalar-condition-code→main· +106 −10 · 2 files · 1 commits · merged 2026-11-29 00:24 UTCAMD defines SCC for
S_ADD_I32,S_ADDK_I32, andS_SUB_I32as signed 32-bit overflow. The translator emits the arithmetic result but leaves SCC missing, so a laterS_CSELECT_B32can cause lowering to returnUnsupported.This ports the 32-bit sign-bit overflow calculation from ESAT586’s Marvisak/VIctory#1095. It uses the existing sign-extended SOPK immediate and retains the unsigned carry and borrow rules. AMD RDNA 2 ISA reference, sections 12.1 and 12.3
The regression uses LLVM MC gfx1030 assembly. It dispatches an unsigned carry control, then compares four signed arithmetic results and their packed SCC flags with Rust’s
overflowing_addandoverflowing_sub. An independent Python checker derives the same result from unbounded arithmetic and signed range checks.32ecacfae73fplus the identical test fixture returned[1, 0]forUINT_MAX + 1, then rejected the signed shader withUnsupported { offset: 132, what: "the carry of a scalar operation" }.6b4bb259aec8returned the same unsigned control and matched all 55 signed UAV words across 11 input pairs on an RTX 5070, driver 620.73.04, through Proton Experimental and VKD3D-Proton30b0eb9bc12dc9f. ForINT_MAX, 1the readback was[00000005, 80000000, 7ffffffe, 80000000, 7ffffffe]. ForINT_MIN, 1it was[0000000a, 80000001, 7fffffff, 80000001, 7fffffff].spirv-val --target-env vulkan1.3.Run the exact regression on an SM 6.6 D3D12 hardware adapter:
The fixture and resources are synthetic. Validation covers the NVIDIA hardware path through Proton.
Validation on current main
923e38cc8c92cd1c42090076382138538f2bb487as9790ba0c8e425b3a7d3ec64e9202f0a3244cc4e5. The measured original head6b4bb259aec85cdedf13554746d98764993785b0and its evidence were saved.99f0b329ddd019761a7a7f7f48ac4eda09468bfareproducedUnsupportedat byte offset 132 after the physical unsigned[1, 0]control. The new head again returned[1, 0]and all 55 signed words on the RTX 5070. The independent checker matched all 11 rows.6b4bb259aeto9790ba0c8e@upipibi on GitHub · 2026-11-28 21:29 UTC · original
Tested on Ampere: RTX 3070 (
10de:2484), driver 616.56, native Windows 11 Pro 10.0.26100, rustc 1.98.1. Debug test profile. The system WARP is the one that ships with Windows. llvm-mc 21.1.8 (AMDGPU), used only to check the test's instruction words.9790ba0c8, merged onto main77df871e5(--no-ff, clean, no conflicts). The PR's base is923e38cc8. Main's only commit after it is a README change, so the merge changes the same two files by the same amounts as the PR:lower.rs+22/-8,valu_tests.rs+84/-2. The head was still9790ba0c8when I finished.Ampere reproduces the refusal on main, and the PR fixes it. With the PR, the 3070 matches all 55 signed words (11 input pairs x 5 words) and the unsigned control. On main's code, the same test is refused with the description's error, at the same offset. No case gives a wrong value instead of a refusal.
The test
VICTORY_WARP=1, 3 runs: 1 passed, 0 failed, 0 ignored each (0.05 s).The test needs no
llvm-mcat run time. The gfx1030 words are hardcoded invalu_tests.rs, and nothing in the crate readsLLVM_MCor callsllvm-mc. So the test does not skip without it. I disassembled each word withllvm-mc -arch=amdgcn -mcpu=gfx1030 --disassemble, and all 18 match their comments. For example,0xB786FFFFiss_addk_i32 s6, 0xffff, the-1case.Unlike most
valu_tests, this test asks for one adapter only:devices = [("hardware", false)]. A default run therefore does not test WARP. WithVICTORY_WARP=1,Host::new(false)opens WARP, but the readback lines still sayhardware.There is a silent pass: if no SM 6.6 hardware device opens,
run_buffer_cases_onprintsno SM 6.6 hardware device; a hardware-only case not runand returns. The test then passes without dispatching. That line did not appear in any of my runs.Adapters seen
I added a temporary
eprintln!at the end ofHost::new. It resolvesdevice.GetAdapterLuid()throughEnumAdapterByLuidand printsGetDesc1andWaveLaneCountMin/Max. I removed it before the lib suites. The test opens two devices, one for the unsigned shader and one for the signed shader.10de:24840x0VICTORY_WARP=11414:008c0x2(software)Values (PR merged)
All 6 runs gave the same values, and every row matches the test's
expected. Unsigned control (s_add_u32,UINT_MAX + 1):[00000001, 00000000].Word 0 is the packed SCC (bit 0
s_add_i32, bit 1s_sub_i32, bit 2s_addk_i32 1, bit 3s_addk_i32 -1). Words 1 to 4 are the results.INT_MAX[00000005, 80000000, 7ffffffe, 80000000, 7ffffffe]INT_MAX[00000006, 7ffffffe, 80000000, 80000000, 7ffffffe]INT_MIN[0000000a, 80000001, 7fffffff, 80000001, 7fffffff]INT_MIN[00000009, 7fffffff, 80000001, 80000001, 7fffffff]INT_MAXINT_MAX[00000005, fffffffe, 00000000, 80000000, 7ffffffe]INT_MININT_MIN[00000009, 00000000, 00000000, 80000001, 7fffffff]INT_MIN[00000002, 80000000, 80000000, 00000001, ffffffff][00000000, 00000000, fffffffe, 00000000, fffffffe][00000000, 00000001, ffffffff, 00000001, ffffffff][00000000, 00000000, 00000002, 00000002, 00000000][00000000, 00000000, 00000000, 00000001, ffffffff]The
INT_MAX, 1andINT_MIN, 1rows are the same as the description's RTX 5070 readback.Negative control: main's
lower.rs, PR's testsgit checkout 77df871e5 -- crates/victory-shader/src/emit/lower.rs.git diff --stat 77df871e5 -- crates/:valu_tests.rs+86/-2 (the PR's test and helper) andhost.rs+13 (my temporary print). It builds.3 runs by default and 3 with
VICTORY_WARP=1: 0 passed, 1 failed, 0 ignored each. All 6 runs gave the same result:[00000001, 00000000]on the 3070 and on WARP.valu_tests.rs:172withlower: Unsupported { offset: 132, what: "the carry of a scalar operation" }.This is a refusal at lowering, the same in every run and on both adapters. No case returned a wrong value. The offset and text match the description's fixture-only baseline.
The offset 132 is not an SCC reader. On main,
s_add_i32/s_sub_i32/s_addk_i32store SCC asVal::Missing("the carry of a scalar operation")(lower.rs:7440), and the error appears where that value is used. By my count of the programbuild_valu_csmakes (a 7-word prologue, then the body), byte 132 is the finalbuffer_store_dwordofv0, which holds thes_cselect/s_orresult. This comes from reading the code, not from a measurement.cargo test -p victory-shader --lib --locked(default, once each)77df871e5: 349 passed, 0 failed, 8 ignored (317 s).77df871e5: 348 passed, 0 failed, 8 ignored (319 s).The PR adds no compiler warnings. The one warning in both builds, unused
colour, is main's (lower.rs:13896on main,:13910on the merge).CI
gh pr checks 1421:checkfails at Clippy, withunused variable: colour(lower.rs:13910) andmanual checked division(lower.rs:2213). Both lines are unchanged from main (lower.rs:13896and:2213), so this PR did not cause either failure. I did not run clippy.Overlap
CONFLICTING, headd25783b), and it changes the same two files.SCCands_add_i32. The search finds #479 and #388 as well, but neither diff changess_add_i32,s_sub_i32,s_addk_i32or this error.Not tested
VICTORY_WARP=1runs alone.s_addk_i32with immediates other than1and-1, and signed SCC read bys_cbranch_scc*rather thans_cselect_b32.s_sub_u32borrow (only thes_add_u32carry control is dispatched), ands_addc_u32/s_subb_u32.VICTORY_SHADER_OPT, clippy, the release build, and the rest of the workspace.AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
@nick0451 on GitHub · 2026-11-28 21:44 UTC · original
A smoke test in play: RTX 3090 24 GB (driver 610.88), i9-14900K, Windows 11. A release build of this PR merged onto main
923e38c, run in turn with main and three other PR builds. Series S, DLSS Performance, frame generation off. The same frozen save, outdoors on a balcony, standing still. Two rounds, each run 40 s to settle and 60 s measured, then a screenshot.ERRORline. The picture matches main. The shaders that do not translate are the same 10 as main (allno wave32 lowering), and none fails withUnsupportedin this scene on main either. So nothing here reaches theS_CSELECT_B32case; this is a no-harm check only.Tested with an AI assistant (Claude Code); results are from this PC.