shader: compute s_add_i32 overflow SCC from the result sign #998

Merged
mumba17 merged 1 commit from upstream-pr/1005 into main 2026-11-23 21:10:46 +00:00
mumba17 commented 2026-11-23 20:53:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-23T20:53:47Z.


Summary

pixel_aot lowers the s_add_i32 SCC (signed overflow) as (~(a ^ b) & (a ^ r)) >> 31 != 0u. On an NVIDIA GeForce RTX 3090 the compiled shader returned SCC 0 for 0x7fffffff + 5, so pixel_aot_blend_scalar_hardware fails 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 is uint throughout and DXC 1.7.2308 emits plain add i32 (no nsw/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_i32 keeps its form. Its overflowing case (set 0, 0x80000000 - 0x20) passed on the same adapter.

Observation (before)

main at aabbedd and again at 3174eb3, serial run:

pixel_aot_blend_scalar_hardware ... ***Failed
AssertionError: Expected ['pass', 'pass'], got ['pass', 'mismatch']
case=1 status=mismatch
pixel_mismatch x=0 y=0
channel=0 expected=1.25586 actual=1.25195 expected_bits=3fa0c000 actual_bits=3fa04000
debug_errors=0 debug_warnings=0
pixel_aot_blend_scalar_warp ... Passed

Channel 0 carries SCC flag bits 0-9 shifted left by 13, so the single differing bit (0x8000) is flag bit 2, which is s_add_i32 s62, s46, s45 with SCALAR_WORDS[1] (0x7fffffff + 5, expected SCC 1).

After

ctest --preset dev --no-tests=error -R '^pixel_aot_blend_scalar_(hardware|warp)$' -V
pixel_aot_blend_scalar_hardware ... Passed
pixel_aot_blend_scalar_warp ....... Passed

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.py and tests/bidi_controls_check.py pass.

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, 0xffffffff squared) and 2,000,000 random pairs.

Negative control: the unmodified lowering is the failing run above; the existing SCALAR_MUTATIONS and the second constant set still exercise both SCC arms.

Changes

  • tools/pixel_aot.py: add_i32 SCC 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

  • NVIDIA GeForce RTX 3090 (10de:2204), driver 32.0.16.1664, D3D12 debug layer enabled
  • Windows 11 Pro build 26300
  • MSVC 19.44.35207 (VS 2022 Build Tools), Windows SDK 10.0.26100, DXC 1.7.2308.16, Python 3.13.1, dev preset

Not tested: other NVIDIA drivers or architectures, AMD and Intel hardware. A full ctest on this machine had no other deterministic failures; parallel -j 8 runs timed out several _hardware tests that pass serially (the timing issue tracked in #448).

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6568619640 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1005). Originally posted by [mumba17](https://github.com/mumba17) on 2026-11-23T20:53:47Z. --- ## Summary `pixel_aot` lowers the `s_add_i32` SCC (signed overflow) as `(~(a ^ b) & (a ^ r)) >> 31 != 0u`. On an NVIDIA GeForce RTX 3090 the compiled shader returned SCC 0 for `0x7fffffff + 5`, so `pixel_aot_blend_scalar_hardware` fails 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 is `uint` throughout and DXC 1.7.2308 emits plain `add i32` (no `nsw`/`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_i32` keeps its form. Its overflowing case (set 0, `0x80000000 - 0x20`) passed on the same adapter. ## Observation (before) `main` at `aabbedd` and again at `3174eb3`, serial run: ``` pixel_aot_blend_scalar_hardware ... ***Failed AssertionError: Expected ['pass', 'pass'], got ['pass', 'mismatch'] case=1 status=mismatch pixel_mismatch x=0 y=0 channel=0 expected=1.25586 actual=1.25195 expected_bits=3fa0c000 actual_bits=3fa04000 debug_errors=0 debug_warnings=0 pixel_aot_blend_scalar_warp ... Passed ``` Channel 0 carries SCC flag bits 0-9 shifted left by 13, so the single differing bit (`0x8000`) is flag bit 2, which is `s_add_i32 s62, s46, s45` with `SCALAR_WORDS[1]` (`0x7fffffff + 5`, expected SCC 1). ## After ``` ctest --preset dev --no-tests=error -R '^pixel_aot_blend_scalar_(hardware|warp)$' -V pixel_aot_blend_scalar_hardware ... Passed pixel_aot_blend_scalar_warp ....... Passed ``` 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.py` and `tests/bidi_controls_check.py` pass. 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`, `0xffffffff` squared) and 2,000,000 random pairs. Negative control: the unmodified lowering is the failing run above; the existing `SCALAR_MUTATIONS` and the second constant set still exercise both SCC arms. ## Changes - `tools/pixel_aot.py`: `add_i32` SCC 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 - NVIDIA GeForce RTX 3090 (`10de:2204`), driver 32.0.16.1664, D3D12 debug layer enabled - Windows 11 Pro build 26300 - MSVC 19.44.35207 (VS 2022 Build Tools), Windows SDK 10.0.26100, DXC 1.7.2308.16, Python 3.13.1, `dev` preset Not tested: other NVIDIA drivers or architectures, AMD and Intel hardware. A full `ctest` on this machine had no other deterministic failures; parallel `-j 8` runs timed out several `_hardware` tests that pass serially (the timing issue tracked in #448). AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:45:48 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!998
No description provided.