shader: lower direct LDS subtract with compare-exchange #3921

Manually merged
github merged 1 commit from github-bot/gh-3919 into gh-pr/3919/base 2026-12-03 11:40:34 +00:00 AGit
Owner

@⁠timbot103 on GitHub · 2026-12-03 10:34 UTC · original
timbot103:shader/native-scalar-lds-warp-hardware → main · +111 −23 · 5 files · 1 commits · merged 2026-12-03 11:35 UTC

Refs #1541. Related driver reproduction in #2954.

Change

Lower direct DXIL ds_sub_u32 and ds_sub_rtn_u32 through a groupshared compare-exchange retry. The returning form preserves the old value of the successful exchange, including when the destination aliases the input. Both forms retain modulo-32-bit arithmetic and the guest EXEC predicate.

Clean main d2e6a4ed failed native_scalar_lds_hardware with native compute PSO creation failed. A reduced LDS shader reproduced 0x8007000e when a groupshared atomic add consumed a negated operand. A standalone DXC cs_6_6 shader using InterlockedAdd(lds[tid], -tid, old) reproduced the same HRESULT. Ordinary LDS reads and writes, and atomic add with an unnegated or literal negative operand, created pipelines.

The source-built fixture checks 64 old values and 2 final values under contention across two groups, plus every guard. The existing signed-multiply control still differs in two result words.

Verification

Windows 11 26200.9974, NVIDIA GeForce RTX 5080 driver 32.0.16.2140 (621.40), Microsoft Basic Render Driver with app-local WARP 1.0.22.0.20261027.1, and DXC 1.9.2602.17 (21d28f727). The native replay does not enable the D3D12 debug layer.

After configuring with the project Python environment and placing app-local WARP beside each build's executables after building:

$env:XBOX2WINDOWS_ADAPTER = 'NVIDIA GeForce RTX 5080'
cmake --build out/build/dev -- -j 6
cmake --build out/build/release --target compile_dxil native_store_replay native_lds_gpu offscreen_check -- -j 6
ctest --preset dev --no-tests=error -j 1 -R '^native_(scalar_lds_|lds_(control_flow|hardware|warp|subword_.*)|compute_ds_append_)' -V
ctest --preset release --no-tests=error -j 1 -R '^native_(scalar_lds_|lds_(control_flow|hardware|warp|subword_.*)|compute_ds_append_)' -V
ctest --preset pr --no-tests=error -j 1 -R '^native_(compute_ds_append_controls|lds_subword_(read|store)_controls)$' -V
python -B tests/bidi_controls_check.py
python -B tests/docs_links_check.py
git diff --check origin/main...HEAD
  • Debug and Release each passed all 14 tests with zero failures or skips on the app-local WARP runs. Each run includes both WARP and RTX 5080.
  • The earlier Release run with in-box WARP had 10 passes and 4 capability skips. In-box WARP exposes no 32-lane waves on this host.
  • The PR preset passed all 3 selected controls with zero failures or skips. The full Debug build and document, bidirectional-control and diff checks passed.

🤖 Generated with Claude Code

**@⁠timbot103** on GitHub · 2026-12-03 10:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3919) `timbot103:shader/native-scalar-lds-warp-hardware` → `main` · +111 −23 · 5 files · 1 commits · merged 2026-12-03 11:35 UTC Refs #1541. Related driver reproduction in #2954. ## Change Lower direct DXIL `ds_sub_u32` and `ds_sub_rtn_u32` through a groupshared compare-exchange retry. The returning form preserves the old value of the successful exchange, including when the destination aliases the input. Both forms retain modulo-32-bit arithmetic and the guest EXEC predicate. Clean main `d2e6a4ed` failed `native_scalar_lds_hardware` with `native compute PSO creation failed`. A reduced LDS shader reproduced `0x8007000e` when a groupshared atomic add consumed a negated operand. A standalone DXC `cs_6_6` shader using `InterlockedAdd(lds[tid], -tid, old)` reproduced the same HRESULT. Ordinary LDS reads and writes, and atomic add with an unnegated or literal negative operand, created pipelines. The source-built fixture checks 64 old values and 2 final values under contention across two groups, plus every guard. The existing signed-multiply control still differs in two result words. ## Verification Windows 11 26200.9974, NVIDIA GeForce RTX 5080 driver 32.0.16.2140 (621.40), Microsoft Basic Render Driver with app-local WARP 1.0.22.0.20261027.1, and DXC 1.9.2602.17 (21d28f727). The native replay does not enable the D3D12 debug layer. After configuring with the project Python environment and placing app-local WARP beside each build's executables after building: ```powershell $env:XBOX2WINDOWS_ADAPTER = 'NVIDIA GeForce RTX 5080' cmake --build out/build/dev -- -j 6 cmake --build out/build/release --target compile_dxil native_store_replay native_lds_gpu offscreen_check -- -j 6 ctest --preset dev --no-tests=error -j 1 -R '^native_(scalar_lds_|lds_(control_flow|hardware|warp|subword_.*)|compute_ds_append_)' -V ctest --preset release --no-tests=error -j 1 -R '^native_(scalar_lds_|lds_(control_flow|hardware|warp|subword_.*)|compute_ds_append_)' -V ctest --preset pr --no-tests=error -j 1 -R '^native_(compute_ds_append_controls|lds_subword_(read|store)_controls)$' -V python -B tests/bidi_controls_check.py python -B tests/docs_links_check.py git diff --check origin/main...HEAD ``` - Debug and Release each passed all 14 tests with zero failures or skips on the app-local WARP runs. Each run includes both WARP and RTX 5080. - The earlier Release run with in-box WARP had 10 passes and 4 capability skips. In-box WARP exposes no 32-lane waves on this host. - The PR preset passed all 3 selected controls with zero failures or skips. The full Debug build and document, bidirectional-control and diff checks passed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Refs #1541. Avoid the groupshared atomic PSO failure reproduced on RTX 5080.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 10:35:24 +00:00
Author
Owner

@⁠JohnConnorNPC on GitHub · 2026-12-03 11:27 UTC · original

Reviewed e89741bfb42d. Verdict: no MUST or SHOULD, two NITs. The lowering reads correctly (sub and sub_rtn only, aliasing safe, EXEC kept).

  1. NIT (contended fixture): buffer_store_dword v11 reads the ds_sub_rtn_u32 result before s_waitcnt lgkmcnt(0). As guest code that store could see stale data; the translator ignores the wait, so the test passes. Swapping the two lines makes the program well-formed.
  2. NIT (docs/experiments/native-lds-subtract.md): it records the base failure but no result for the change (adapter, driver, commit, pass counts are only in this description).

Outside this change, from reading only: lower_lds in src/gfx1013_compute_ir.cpp still emits InterlockedAdd of 0u - v for ds_sub, the form this change and #2954 avoid.

Review by reading; the Windows and D3D12 tests were not run.

AI-assisted review.

**@⁠JohnConnorNPC** on GitHub · 2026-12-03 11:27 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3919#issuecomment-7376727046) Reviewed `e89741bfb42d`. **Verdict: no MUST or SHOULD, two NITs.** The lowering reads correctly (sub and sub_rtn only, aliasing safe, EXEC kept). 1. **NIT** (contended fixture): `buffer_store_dword v11` reads the `ds_sub_rtn_u32` result before `s_waitcnt lgkmcnt(0)`. As guest code that store could see stale data; the translator ignores the wait, so the test passes. Swapping the two lines makes the program well-formed. 2. **NIT** (`docs/experiments/native-lds-subtract.md`): it records the base failure but no result for the change (adapter, driver, commit, pass counts are only in this description). Outside this change, from reading only: `lower_lds` in `src/gfx1013_compute_ir.cpp` still emits `InterlockedAdd` of `0u - v` for ds_sub, the form this change and #2954 avoid. Review by reading; the Windows and D3D12 tests were not run. AI-assisted review.
github-bot changed target branch from main to gh-pr/3919/base 2026-12-03 11:40:32 +00:00
github manually merged commit e89741bfb4 into gh-pr/3919/base 2026-12-03 11:40:34 +00:00
Author
Owner

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

Approved e89741bf. The CAS loop retries against the observed word, returns the value from the successful exchange, and captures the input before a possibly aliased destination is written. Independent MSVC Debug with SDK DXC, Windows 11 build 26300: ctest --preset dev -j 1 --no-tests=error -V -R '^native_scalar_lds_(warp|hardware)$'. RTX 4060 Laptop 32.0.16.1656 matched 64 returned values under contention, both final words, and every guard. The existing signed-multiply mutation still differs twice. Inbox WARP returned capability skip 77. The native replay does not enable the D3D12 debug layer.

**@⁠R0Y00** on GitHub · 2026-12-03 11:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3919#pullrequestreview-6168938168) · **approved these changes** Approved e89741bf. The CAS loop retries against the observed word, returns the value from the successful exchange, and captures the input before a possibly aliased destination is written. Independent MSVC Debug with SDK DXC, Windows 11 build 26300: ctest --preset dev -j 1 --no-tests=error -V -R '^native_scalar_lds_(warp|hardware)$'. RTX 4060 Laptop 32.0.16.1656 matched 64 returned values under contention, both final words, and every guard. The existing signed-multiply mutation still differs twice. Inbox WARP returned capability skip 77. The native replay does not enable the D3D12 debug layer.
This discussion has been locked. Commenting is limited to contributors.
No description provided.