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

Merged
timbot103 merged 1 commit from upstream-pr/3919 into main 2026-12-03 11:35:07 +00:00
timbot103 commented 2026-12-03 10:34:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-03T10:34:17Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5624724067 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3919). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-03T10:34:17Z. --- 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)
JohnConnorNPC commented 2026-12-03 11:27:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-12-03T11:27:28Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7376727046 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3919#issuecomment-7376727046). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-12-03T11:27:28Z. --- 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.
R0Y00 commented 2026-12-03 11:35:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T11:35:01Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6168938168 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3919#pullrequestreview-6168938168). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T11:35:01Z. **Review:** APPROVED --- 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.
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!3919
No description provided.