shader: lower direct LDS subtract with compare-exchange #3919
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3919"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_u32andds_sub_rtn_u32through 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
d2e6a4edfailednative_scalar_lds_hardwarewithnative compute PSO creation failed. A reduced LDS shader reproduced0x8007000ewhen a groupshared atomic add consumed a negated operand. A standalone DXCcs_6_6shader usingInterlockedAdd(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:
🤖 Generated with Claude Code
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).buffer_store_dword v11reads theds_sub_rtn_u32result befores_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.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_ldsinsrc/gfx1013_compute_ir.cppstill emitsInterlockedAddof0u - vfor ds_sub, the form this change and #2954 avoid.Review by reading; the Windows and D3D12 tests were not run.
AI-assisted review.
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.