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

Merged
alvaroolt merged 1 commit from upstream-pr/2954 into main 2026-11-27 03:35:59 +00:00
alvaroolt commented 2026-11-26 23:12:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by alvaroolt on 2026-11-26T23:12:14Z.


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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5518402551 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2954). Originally posted by [alvaroolt](https://github.com/alvaroolt) on 2026-11-26T23:12:14Z. --- ## 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.
R0Y00 commented 2026-11-27 03:35:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T03:35:49Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6083110611 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2954#pullrequestreview-6083110611). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T03:35:49Z. **Review:** APPROVED --- 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.
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!2954
No description provided.