shader: lower group-shared ds_sub_u32 as two additions #2954

Manually merged
github merged 1 commit from github-bot/gh-2954 into gh-pr/2954/base 2026-11-27 03:39:34 +00:00 AGit
Owner

@⁠alvaroolt on GitHub · 2026-11-26 23:12 UTC · original
alvaroolt:shader/lds-sub-two-adds → main · +47 −8 · 3 files · 1 commits · merged 2026-11-27 03:35 UTC

Change

compute_store_aot_lds_shared_hardware fails on an NVIDIA GeForce RTX 5080 (driver 32.0.16.2124). CreateComputePipelineState returns E_OUTOFMEMORY (0x8007000e) for the shared_atomics program, and the test stops there. The other seven shared LDS programs pass on that adapter. WARP runs all eight, and an AMD Radeon iGPU builds the PSO of the reduced shader below.

A reduction to a 64-thread shader isolates the cause: an InterlockedAdd on groupshared memory whose operand is sub i32 0, x for a runtime x. tools/compute_store_aot.py emitted ds_sub_u32 as exactly that, InterlockedAdd(lds[i], (0u - v)). DXC folds every spelling of the negation I tried to the same instruction: ~x + 1u, x * 0xffffffffu, -(int)x, and -Od. The same shader builds a PSO when the negation goes through a UAV InterlockedAdd, through InterlockedExchange, Xor or Max on groupshared memory, or into a plain groupshared store. It also builds with 5u - x, 0u - x * 3u or a constant addend.

The change emits ds_sub_u32 as two additions on the same word, InterlockedAdd(lds[i], ~(v)) and then InterlockedAdd(lds[i], 1u). That is mem - v modulo 2^32. The shared profile lowers only the non-returning form, and every DS step ends with GroupMemoryBarrierWithGroupSync(), so no lane reads the intermediate word. The other shared atomics and the UAV buffer_atomic_sub lowering are unchanged.

Tests and docs:

  • shared_controls() now requires the two additions in the counter program and no 0u - there. It replaces the assertion on (0u - tid.x).
  • shared_draw() adds an HLSL mutation that drops the second addition. It must mismatch at word 1.
  • docs/experiments.md (Group-shared LDS on gfx1013) records the driver behavior, the workaround and the measurements below.

This change was AI-assisted (Claude Code); I reviewed the diff and the test results.

Verification

Commit 386deda1 on main 6ee878d8. Windows 11 build 26300.9974. The D3D12 debug layer was unavailable (Graphics Tools not installed).

ctest --preset dev --no-tests=error -R '^compute_store_aot_lds_shared_(warp|hardware)$' -V
$env:XBOX2WINDOWS_ADAPTER='Radeon'; ctest --preset dev --no-tests=error -R '^compute_store_aot_lds_shared_hardware$' -V
Adapter Before (6ee878d8) After
NVIDIA GeForce RTX 5080, driver 32.0.16.2124 failed: Create compute pipeline failed (HRESULT 0x8007000e) on shared_atomics passed
Microsoft Basic Render Driver (WARP) 10.0.26100.9818 passed passed
AMD Radeon(TM) Graphics, driver 32.0.11034.2 not run passed

Each mutation mismatched at its expected word on all three adapters:

  • next-but-one lane: word=0 expected=12340001 actual=12340002;
  • st64 read spelled as plain read2: word=1 expected=2000003f actual=20000000;
  • ds_min_u32 for ds_max_u32: word=11 expected=fdeb2507 actual=00000000;
  • new, second addition dropped: word=1 expected=fffff820 actual=fffff7e0 (64 short, one per lane).

Negative control for the translation check: with the previous tools/compute_store_aot.py, shared_controls() fails on the new two-addition assertion.

LLVM 15 round trip: tests/compute_store_check.py binary with LLVM 15.0.7 llvm-mc, llvm-objcopy and LLVM-C.dll exited 0.

Full suites on the change, RTX 5080 as the default hardware adapter:

  • ctest --preset dev --no-tests=error -j 8: 2442 of 2444 passed. compute_store_aot_lds_shared_hardware now passes.
  • ctest --preset release --no-tests=error -j 8: 2441 of 2444 passed.

Failures, each also seen on main 6ee878d8 on this machine, or passing when run alone:

  • linear_buffer_backing_copy_hardware, both presets: gate2q subcase.
  • compute_store_aot_mac_f32_hardware, both presets: #2883, addressed by #2892.
  • linear_buffer_backing_copy_warp, release only: passed when rerun alone.

Capability skips (exit 77): 53 in each preset, counted separately from the passes and failures above. The main dev run also had 53.

Evidence and follow-up

Not shown:

  • whether other NVIDIA architectures or driver branches refuse the same pattern (the doc section's earlier RTX 3080 run, driver 32.0.15.9174, passed with the single negated add);
  • why the driver refuses it;
  • the returning ds_sub_rtn_u32 form, which this profile does not lower. Splitting it into two additions would not give a single pre-op value.

The production gfx2hlsl LDS atomics table has no ds_sub_u32 entry today, so it is not affected.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.
**@⁠alvaroolt** on GitHub · 2026-11-26 23:12 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2954) `alvaroolt:shader/lds-sub-two-adds` → `main` · +47 −8 · 3 files · 1 commits · merged 2026-11-27 03:35 UTC ## Change `compute_store_aot_lds_shared_hardware` fails on an NVIDIA GeForce RTX 5080 (driver 32.0.16.2124). `CreateComputePipelineState` returns `E_OUTOFMEMORY` (0x8007000e) for the `shared_atomics` program, and the test stops there. The other seven shared LDS programs pass on that adapter. WARP runs all eight, and an AMD Radeon iGPU builds the PSO of the reduced shader below. A reduction to a 64-thread shader isolates the cause: an `InterlockedAdd` on groupshared memory whose operand is `sub i32 0, x` for a runtime `x`. `tools/compute_store_aot.py` emitted `ds_sub_u32` as exactly that, `InterlockedAdd(lds[i], (0u - v))`. DXC folds every spelling of the negation I tried to the same instruction: `~x + 1u`, `x * 0xffffffffu`, `-(int)x`, and `-Od`. The same shader builds a PSO when the negation goes through a UAV `InterlockedAdd`, through `InterlockedExchange`, `Xor` or `Max` on groupshared memory, or into a plain groupshared store. It also builds with `5u - x`, `0u - x * 3u` or a constant addend. The change emits `ds_sub_u32` as two additions on the same word, `InterlockedAdd(lds[i], ~(v))` and then `InterlockedAdd(lds[i], 1u)`. That is `mem - v` modulo 2^32. The shared profile lowers only the non-returning form, and every DS step ends with `GroupMemoryBarrierWithGroupSync()`, so no lane reads the intermediate word. The other shared atomics and the UAV `buffer_atomic_sub` lowering are unchanged. Tests and docs: - `shared_controls()` now requires the two additions in the counter program and no `0u - ` there. It replaces the assertion on `(0u - tid.x)`. - `shared_draw()` adds an HLSL mutation that drops the second addition. It must mismatch at word 1. - `docs/experiments.md` (Group-shared LDS on gfx1013) records the driver behavior, the workaround and the measurements below. This change was AI-assisted (Claude Code); I reviewed the diff and the test results. ## Verification Commit 386deda1 on `main` 6ee878d8. Windows 11 build 26300.9974. The D3D12 debug layer was unavailable (Graphics Tools not installed). ```powershell ctest --preset dev --no-tests=error -R '^compute_store_aot_lds_shared_(warp|hardware)$' -V $env:XBOX2WINDOWS_ADAPTER='Radeon'; ctest --preset dev --no-tests=error -R '^compute_store_aot_lds_shared_hardware$' -V ``` | Adapter | Before (6ee878d8) | After | |---|---|---| | NVIDIA GeForce RTX 5080, driver 32.0.16.2124 | failed: `Create compute pipeline failed (HRESULT 0x8007000e)` on `shared_atomics` | passed | | Microsoft Basic Render Driver (WARP) 10.0.26100.9818 | passed | passed | | AMD Radeon(TM) Graphics, driver 32.0.11034.2 | not run | passed | Each mutation mismatched at its expected word on all three adapters: - next-but-one lane: `word=0 expected=12340001 actual=12340002`; - `st64` read spelled as plain `read2`: `word=1 expected=2000003f actual=20000000`; - `ds_min_u32` for `ds_max_u32`: `word=11 expected=fdeb2507 actual=00000000`; - new, second addition dropped: `word=1 expected=fffff820 actual=fffff7e0` (64 short, one per lane). Negative control for the translation check: with the previous `tools/compute_store_aot.py`, `shared_controls()` fails on the new two-addition assertion. LLVM 15 round trip: `tests/compute_store_check.py binary` with LLVM 15.0.7 `llvm-mc`, `llvm-objcopy` and `LLVM-C.dll` exited 0. Full suites on the change, RTX 5080 as the default hardware adapter: - `ctest --preset dev --no-tests=error -j 8`: 2442 of 2444 passed. `compute_store_aot_lds_shared_hardware` now passes. - `ctest --preset release --no-tests=error -j 8`: 2441 of 2444 passed. Failures, each also seen on `main` 6ee878d8 on this machine, or passing when run alone: - `linear_buffer_backing_copy_hardware`, both presets: `gate2q` subcase. - `compute_store_aot_mac_f32_hardware`, both presets: #2883, addressed by #2892. - `linear_buffer_backing_copy_warp`, release only: passed when rerun alone. Capability skips (exit 77): 53 in each preset, counted separately from the passes and failures above. The `main` dev run also had 53. ## Evidence and follow-up Not shown: - whether other NVIDIA architectures or driver branches refuse the same pattern (the doc section's earlier RTX 3080 run, driver 32.0.15.9174, passed with the single negated add); - why the driver refuses it; - the returning `ds_sub_rtn_u32` form, which this profile does not lower. Splitting it into two additions would not give a single pre-op value. The production `gfx2hlsl` LDS atomics table has no `ds_sub_u32` entry today, so it is not affected. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
On an NVIDIA GeForce RTX 5080 (driver 32.0.16.2124) the compute PSO of
the shared LDS counter program failed with E_OUTOFMEMORY, so
compute_store_aot_lds_shared_hardware failed. The cause is the single
InterlockedAdd(lds[i], (0u - v)) emitted for ds_sub_u32: the driver
refuses an InterlockedAdd on groupshared memory whose operand is
`sub i32 0, v`, and DXC folds every spelling of the negation to that
instruction. The same negation through a UAV atomic, other groupshared
atomics or a plain store compiles.

Emit ds_sub_u32 as InterlockedAdd(~v) followed by InterlockedAdd(1u)
on the same word, which is mem - v modulo 2^32. The update returns no
value and the step ends with a barrier, so no lane reads the
intermediate word. The translation controls require the two additions
and no negation in the counter program, and a new HLSL mutation that
drops the second addition must mismatch at word 1.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:30:32 +00:00
github-bot changed target branch from main to gh-pr/2954/base 2026-11-27 03:39:29 +00:00
github manually merged commit 386deda168 into gh-pr/2954/base 2026-11-27 03:39:31 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 03:35 UTC · original · approved these changes

Reviewed 386deda168054a2db9558c3a18089e67f926ddf1. The LDS profile emits a group barrier after each step and only accepts the non-returning atomic here, so the two additions have the original final value modulo 2^32. On Windows 11 26200.9974 I built cmake --build --preset release --target offscreen_check and ran ctest --preset release --no-tests=error --output-on-failure -R '^compute_store_aot_lds_shared'. Both source-built tests passed, including the missing-add mutation, on WARP (10.0.26100.9818) and RTX 4060 Laptop (32.0.16.1656), with the D3D12 debug layer enabled. The RTX 5080 failure and recovery are the author's measurements. Required Windows CI passed.

**@⁠R0Y00** on GitHub · 2026-11-27 03:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2954#pullrequestreview-6083110611) · **approved these changes** Reviewed `386deda168054a2db9558c3a18089e67f926ddf1`. The LDS profile emits a group barrier after each step and only accepts the non-returning atomic here, so the two additions have the original final value modulo 2^32. On Windows 11 26200.9974 I built `cmake --build --preset release --target offscreen_check` and ran `ctest --preset release --no-tests=error --output-on-failure -R '^compute_store_aot_lds_shared'`. Both source-built tests passed, including the missing-add mutation, on WARP (10.0.26100.9818) and RTX 4060 Laptop (32.0.16.1656), with the D3D12 debug layer enabled. The RTX 5080 failure and recovery are the author's measurements. Required Windows CI passed.
This discussion has been locked. Commenting is limited to contributors.
No description provided.