shader: lower compute v_add_nc_i32 and v_sub_nc_i32 #1950
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1957"
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 R0Y00/Xbox2Windows. Originally posted by henriazz10 on 2026-11-24T22:07:13Z.
Change
Refs #721. This is the
v_add_nc_i32/v_sub_nc_i32slice claimed in https://github.com/R0Y00/Xbox2Windows/issues/721#issuecomment-7143412663. It touches onlytools/compute_store_aot.py,tests/compute_store_check.py,CMakeLists.txt, anddocs/experiments.md.v_add_nc_i32 vD, S0, S1andv_sub_nc_i32 vD, S0, S1(VOP3, RDNA2 ISAD.i = S0.i + S1.iandD.i = S0.i - S1.i) lower on known words (ALU_SOURCE: VGPR, known SGPR, integer inline constant, or 32-bit literal) to({0} + {1})and({0} - {1})inuintarithmetic so 32-bit two's-complement wrap-around without carry-out is exact.s30,v40,s12);clamponv_add_nc_i32andv_sub_nc_i32, andomod(mul:2);-v3,|v3|,neg(v3));vDabovev255(v256);v_add_nc_i32_e32,v_add_nc_i32_e64,v_sub_nc_i32_e32,v_sub_nc_i32_e64).Verification
Commit
4fe59c25, rebased onto999875ad. The draws,controls()and the LLVM 15 round trip were re-run on4fe59c25. Windows 11 build 26300, DXC 10.0.26100.0, Python 3.12.10, debug layer enabled.offscreen_checkwas built from an earliermain; this PR does not change it.groups=1 compared_words=320 mismatches=0,debug_errors=0 debug_warnings=0groups=1 compared_words=320 mismatches=0,debug_errors=0 debug_warnings=0docs_links_check.py: exit 0 (Checked 18 Markdown files and 376 links.).bidi_controls_check.py: exit 0 (Checked 1330 tracked source, script and build/CI files: no bidirectional controls.).git diff --check HEAD~1: exit 0.The LLVM 15 round trip in Docker:
vadd_nc_i32_binary()decodes the assembled fixture back to the samev_add_nc_i32andv_sub_nc_i32lines and requires the same translation (binary_exit=0).Negative control. With
tools/compute_store_aot.pyfromorigin/main,vadd_nc_i32_controls()fails withValueError: Unsupported compute instruction: v_add_nc_i32 v4, v3, 0x7ffffff0.Evidence
The fixture
VADD_NC_I32is source-built in LLVM 15 spelling. It runs one group of 64 threads and exercisesv_add_nc_i32andv_sub_nc_i32across VGPR, SGPR (s4 = 0x80000005,s5 = 0x80000001), negative inline constant (-16), and 32-bit literal (0x7ffffff0), crossing0x7fffffff <-> 0x80000000with unique words per thread and comparing all 320 words against an independent Python reference.vadd_nc_i32_controls()checks the exact HLSLoutputData.Storeexpression and all rejection cases listed above.add as sub: word 0;sub as add: word 0;signed clamp instead of wrap: word 0;sentinel past group: word 64.Compute readback differs:add replaced by sub(+ 0x7ffffff0u)->- 0x7ffffff0u));sub replaced by add(0x80000001u - tid.x->0x80000001u + tid.x);literal off by one(0x7ffffff0u->0x7ffffff1u).Checklist
docs/experiments.md).AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T22:16:03Z.
Review: COMMENTED
Review of head
4fe59c2571Scope:
tools/compute_store_aot.pylowersv_add_nc_i32/v_sub_nc_i32(VOP3, known words) to({0} + {1})/({0} - {1})in uint arithmetic.clamp,omod, source modifiers,_e32/_e64spellings and unknown sources are refused. CMakeLists.txt only registers the newcompute_store_aot_vadd_nc_i32_{warp,hardware}tests. The docs match the code. No copied vendor material seen.Commands run locally (all PASS):
git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflictspython3 -B tests/compute_store_check.py controls: controls pass (the new rejection cases and exact HLSL line)python3 tests/docs_links_check.py: passpython3 tests/bidi_controls_check.py: passgit diff --check origin/main...HEAD: cleanwin2025 1957), Debug (--preset dev) and Release /O2 (--preset release): pass, includingcompute_store_aot_vadd_nc_i32_warpMutations in the code under test (each killed by
controls, then reverted):v_add_nc_i32lowered with-instead of+: killed (exact HLSL assert)v_sub_nc_i32lowered with+instead of-: killed (exact HLSL assert)v_sub_nc_i32dropped from the VOP3 regex: killed (lowering refused)P1: 0. P2: 0.
AI-assisted; commands listed were executed locally.