shader: lower group-shared ds_sub_u32 as two additions #2954
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2954"
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 alvaroolt on 2026-11-26T23:12:14Z.
Change
compute_store_aot_lds_shared_hardwarefails on an NVIDIA GeForce RTX 5080 (driver 32.0.16.2124).CreateComputePipelineStatereturnsE_OUTOFMEMORY(0x8007000e) for theshared_atomicsprogram, 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
InterlockedAddon groupshared memory whose operand issub i32 0, xfor a runtimex.tools/compute_store_aot.pyemittedds_sub_u32as 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 UAVInterlockedAdd, throughInterlockedExchange,XororMaxon groupshared memory, or into a plain groupshared store. It also builds with5u - x,0u - x * 3uor a constant addend.The change emits
ds_sub_u32as two additions on the same word,InterlockedAdd(lds[i], ~(v))and thenInterlockedAdd(lds[i], 1u). That ismem - vmodulo 2^32. The shared profile lowers only the non-returning form, and every DS step ends withGroupMemoryBarrierWithGroupSync(), so no lane reads the intermediate word. The other shared atomics and the UAVbuffer_atomic_sublowering are unchanged.Tests and docs:
shared_controls()now requires the two additions in the counter program and no0u -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
386deda1onmain6ee878d8. Windows 11 build 26300.9974. The D3D12 debug layer was unavailable (Graphics Tools not installed).6ee878d8)Create compute pipeline failed (HRESULT 0x8007000e)onshared_atomicsEach mutation mismatched at its expected word on all three adapters:
word=0 expected=12340001 actual=12340002;st64read spelled as plainread2:word=1 expected=2000003f actual=20000000;ds_min_u32fords_max_u32:word=11 expected=fdeb2507 actual=00000000;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 binarywith LLVM 15.0.7llvm-mc,llvm-objcopyandLLVM-C.dllexited 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_hardwarenow passes.ctest --preset release --no-tests=error -j 8: 2441 of 2444 passed.Failures, each also seen on
main6ee878d8on this machine, or passing when run alone:linear_buffer_backing_copy_hardware, both presets:gate2qsubcase.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
maindev run also had 53.Evidence and follow-up
Not shown:
ds_sub_rtn_u32form, which this profile does not lower. Splitting it into two additions would not give a single pre-op value.The production
gfx2hlslLDS atomics table has nods_sub_u32entry today, so it is not affected.Checklist
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 builtcmake --build --preset release --target offscreen_checkand ranctest --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.