fix(rdna2): lift LDS ds_sub as a CAS loop so NVIDIA can build the pipeline #26

Manually merged
github merged 2 commits from gh-pr/26/head into gh-pr/26/base 2026-11-26 19:11:05 +00:00
Owner

@⁠marquezinii on GitHub · 2026-11-22 17:54 UTC · original
marquezinii:fix/lds-sub-cas-nvidia → main · +4 −1 · 1 files · 2 commits · merged 2026-11-22 18:50 UTC

What

On current main (85e2d3d), test_rdna2_corpus_bench and test_rdna2_gpu_accuracy fail on an RTX 5070 with [EXT-GPU-FAIL] D3D12 HW (mem_ds_atomics): and an empty diff. The empty diff means RunComputeDualUav returned false before readback. Instrumenting it showed CreateComputePipelineState failing with E_OUTOFMEMORY (0x8007000E). The debug layer adds no message.

Bisecting the generated HLSL brought it down to one construct: a groupshared InterlockedAdd whose operand is a runtime negation. The lifter emits exactly that for ds_sub_u32 / ds_sub_rtn_u32 (InterlockedAdd(_lds[_idx], (0u - v[n]), _prev)). Minimal reproducer (cs_6_0 to cs_6_6, root signature with two root UAVs):

RWByteAddressBuffer _uav0 : register(u0);
RWByteAddressBuffer _uav1 : register(u1);
groupshared uint _lds[64];
[numthreads(1, 1, 1)]
void main(uint3 dtid : SV_DispatchThreadID) {
    uint y = _uav0.Load(0);
    _lds[dtid.x] = 10u;
    uint p;
    InterlockedAdd(_lds[dtid.x], 0u - y, p);   // E_OUTOFMEMORY; with `y` it builds
    _uav1.Store(0, _lds[dtid.x]);
}

What I measured with that shader:

  • Fail: 0u - y, (~y) + 1u, y * 0xFFFFFFFFu, asuint(-asint(y)), (y ^ 0xFFFFFFFFu) + 1u. DXC folds all of these to atomicrmw add (sub 0, y).
  • Build: a constant (0u - 5u), the same negated add on a RWByteAddressBuffer (constant or dynamic address), and a compare-exchange loop on groupshared.

So it looks like a driver bug specific to LDS atomic add of a negated value. The buffer path (.InterlockedAdd(_addr, 0u - v[n])) is fine.

Change

ds_sub on LDS (op 0x33, is_lds) now uses the existing emit_cas_loop("_cur - v[n]"), the same loop the lifter already uses for ds_inc, ds_dec and signed ds_min/ds_max. The return value is the original value, as before. The buffer path and the typed-UAV (_rwtex_u32) path are unchanged. One file, four lines.

Tested

Windows 11 26H2 (26300), VS Build Tools 18 (MSVC 14.52), SDK 10.0.26100.0, dxc 1.9.2602.17, RTX 5070, driver 621.24:

  • main 85e2d3d: 60/62, with test_rdna2_corpus_bench and test_rdna2_gpu_accuracy failing on mem_ds_atomics (D3D12 HW).
  • this branch: full build with 0 warnings; ctest 62/62 passed, both tests included. mem_ds_atomics now runs and matches the CPU reference on D3D12 HW.

The GTX 1650 Ti and other drivers may well accept the old form. The CAS loop is correct everywhere, so this doesn't depend on that.

**@⁠marquezinii** on GitHub · 2026-11-22 17:54 UTC · [original](https://github.com/californiaAlmonds/OpenScarlett/pull/26) `marquezinii:fix/lds-sub-cas-nvidia` → `main` · +4 −1 · 1 files · 2 commits · merged 2026-11-22 18:50 UTC ## What On current main (85e2d3d), `test_rdna2_corpus_bench` and `test_rdna2_gpu_accuracy` fail on an RTX 5070 with `[EXT-GPU-FAIL] D3D12 HW (mem_ds_atomics):` and an empty diff. The empty diff means `RunComputeDualUav` returned false before readback. Instrumenting it showed `CreateComputePipelineState` failing with **`E_OUTOFMEMORY` (0x8007000E)**. The debug layer adds no message. Bisecting the generated HLSL brought it down to one construct: a **groupshared** `InterlockedAdd` whose operand is a runtime negation. The lifter emits exactly that for `ds_sub_u32` / `ds_sub_rtn_u32` (`InterlockedAdd(_lds[_idx], (0u - v[n]), _prev)`). Minimal reproducer (cs_6_0 to cs_6_6, root signature with two root UAVs): ```hlsl RWByteAddressBuffer _uav0 : register(u0); RWByteAddressBuffer _uav1 : register(u1); groupshared uint _lds[64]; [numthreads(1, 1, 1)] void main(uint3 dtid : SV_DispatchThreadID) { uint y = _uav0.Load(0); _lds[dtid.x] = 10u; uint p; InterlockedAdd(_lds[dtid.x], 0u - y, p); // E_OUTOFMEMORY; with `y` it builds _uav1.Store(0, _lds[dtid.x]); } ``` What I measured with that shader: - **Fail:** `0u - y`, `(~y) + 1u`, `y * 0xFFFFFFFFu`, `asuint(-asint(y))`, `(y ^ 0xFFFFFFFFu) + 1u`. DXC folds all of these to `atomicrmw add (sub 0, y)`. - **Build:** a constant (`0u - 5u`), the same negated add on a `RWByteAddressBuffer` (constant or dynamic address), and a compare-exchange loop on groupshared. So it looks like a driver bug specific to LDS atomic add of a negated value. The buffer path (`.InterlockedAdd(_addr, 0u - v[n])`) is fine. ## Change `ds_sub` on LDS (op 0x33, `is_lds`) now uses the existing `emit_cas_loop("_cur - v[n]")`, the same loop the lifter already uses for `ds_inc`, `ds_dec` and signed `ds_min`/`ds_max`. The return value is the original value, as before. The buffer path and the typed-UAV (`_rwtex_u32`) path are unchanged. One file, four lines. ## Tested Windows 11 26H2 (26300), VS Build Tools 18 (MSVC 14.52), SDK 10.0.26100.0, dxc 1.9.2602.17, RTX 5070, driver 621.24: - main 85e2d3d: 60/62, with `test_rdna2_corpus_bench` and `test_rdna2_gpu_accuracy` failing on `mem_ds_atomics` (D3D12 HW). - this branch: full build with 0 warnings; `ctest` **62/62 passed**, both tests included. `mem_ds_atomics` now runs and matches the CPU reference on D3D12 HW. The GTX 1650 Ti and other drivers may well accept the old form. The CAS loop is correct everywhere, so this doesn't depend on that.
The lifter emitted ds_sub_u32 / ds_sub_rtn_u32 on LDS as InterlockedAdd of
(0u - v[n]). On an RTX 5070 (driver 621.24) CreateComputePipelineState
returns E_OUTOFMEMORY for any compute shader with a groupshared atomic add
whose operand is a runtime negation; DXC folds every spelling of -x
(0u - x, ~x + 1u, x * 0xFFFFFFFF, asuint(-asint(x))) to sub 0, x. The same
pattern on a UAV is accepted. This made the mem_ds_atomics kernel fail on
D3D12 HW, failing test_rdna2_corpus_bench and test_rdna2_gpu_accuracy.

ds_sub on LDS now goes through the same compare-exchange loop the lifter
already uses for ds_inc, ds_dec and the signed min/max. The buffer and
typed-UAV paths are unchanged.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:11:02 +00:00
github manually merged commit ecd80fdd76 into gh-pr/26/base 2026-11-26 19:11:05 +00:00
Author
Owner

@⁠californiaAlmonds on GitHub · 2026-11-22 18:50 UTC · original · approved these changes

Clean, minimal CAS-loop fix for NVIDIA RTX 5070 LDS ds_sub E_OUTOFMEMORY, and 4/4 CI jobs are green. Thanks @⁠marquezinii!

**@⁠californiaAlmonds** on GitHub · 2026-11-22 18:50 UTC · [original](https://github.com/californiaAlmonds/OpenScarlett/pull/26#pullrequestreview-6013833835) · **approved these changes** Clean, minimal CAS-loop fix for NVIDIA RTX 5070 LDS ds_sub E_OUTOFMEMORY, and 4/4 CI jobs are green. Thanks @⁠marquezinii!
This discussion has been locked. Commenting is limited to contributors.
No description provided.