shader: compute s_add_i32 overflow SCC from the result sign #998
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1005"
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 mumba17 on 2026-11-23T20:53:47Z.
Summary
pixel_aotlowers thes_add_i32SCC (signed overflow) as(~(a ^ b) & (a ^ r)) >> 31 != 0u. On an NVIDIA GeForce RTX 3090 the compiled shader returned SCC 0 for0x7fffffff + 5, sopixel_aot_blend_scalar_hardwarefails on that adapter while WARP passes.This PR switches to the equivalent form
((a ^ r) & (b ^ r)) >> 31 != 0u: overflow exactly when the result's sign differs from both operands. The HLSL isuintthroughout and DXC 1.7.2308 emits plainadd i32(nonsw/nuw) for the scalar fixture, so the old form is well defined; the difference is in the driver's compiled code, not in the DXIL.s_sub_i32keeps its form. Its overflowing case (set 0,0x80000000 - 0x20) passed on the same adapter.Observation (before)
mainataabbeddand again at3174eb3, serial run:Channel 0 carries SCC flag bits 0-9 shifted left by 13, so the single differing bit (
0x8000) is flag bit 2, which iss_add_i32 s62, s46, s45withSCALAR_WORDS[1](0x7fffffff + 5, expected SCC 1).After
Broader check on the branch:
ctest --preset dev --no-tests=error -j 4 -R '^(pixel_aot_.*_warp|pixel_aot_blend_scalar_hardware|pixel_aot_hardware|pixel_aot_controls.*|form_coverage.*)$'reports 55/55 passed.tests/form_coverage_check.py,tests/docs_links_check.pyandtests/bidi_controls_check.pypass.Equivalence: both formulas match the Python reference (
not -2**31 <= a + b < 2**31) on 144 edge pairs (0, 1, 2, 5,0x20,0x7ffffffe,0x7fffffff,0x80000000,0x80000001,0xfffffff0,0xfffffffe,0xffffffffsquared) and 2,000,000 random pairs.Negative control: the unmodified lowering is the failing run above; the existing
SCALAR_MUTATIONSand the second constant set still exercise both SCC arms.Changes
tools/pixel_aot.py:add_i32SCC expression.tests/pixel_aot_check.py: the scalar control that matches the emitted HLSL text.docs/experiments.md: one paragraph after the scalar ALU description.Environment
10de:2204), driver 32.0.16.1664, D3D12 debug layer enableddevpresetNot tested: other NVIDIA drivers or architectures, AMD and Intel hardware. A full
cteston this machine had no other deterministic failures; parallel-j 8runs timed out several_hardwaretests that pass serially (the timing issue tracked in #448).AI-assisted (Claude Code).
🤖 Generated with Claude Code