shader: lower 32-bit compute raw MUBUF buffer atomics in gfx2hlsl #2323
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2331"
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 Vladimir-Human on 2026-11-25T12:37:28Z.
Refs #1545
Summary
Lower 11 gfx1013 compute 32-bit raw
offenMUBUF buffer atomics (buffer_atomic_swap,cmpswap,add,sub,smin,umin,smax,umax,and,or,xor) intools/startup/gfx2hlsl.py(Stage.buffer_atomic,MUBUF_ATOMIC_OPS, sharedStage.raw_table_uav_store).Stage.raw_table_uav_storedelegates descriptor validation toStage.store_descriptor(..., stride0_ok=True)and consolidatesbuffer_store_dword*/buffer_atomic_*operand,offen-only, modifier, alignedsoffset, and aligned immediateoffsetchecks (& 0xfffffffcuaddress rounding).SIInstrInfo/ D3D12 HLSLRWByteAddressBuffer:buffer_atomic_cmpswapflips RDNA 2(vdata[0]=replacement, vdata[1]=compare)into HLSLInterlockedCompareStore/InterlockedCompareExchange(a, cmp, rep[, ao]), writing pre-atomic return underglconly tovdata[0](vdata[1]preserved).buffer_atomic_swaplowers viaInterlockedExchange(a, val, ao)(assigningvdata[0] = aoonly whenglcis set).buffer_atomic_sublowers viaInterlockedAdd(a, (0u - val)[, ao]);smin/smaxuse signedasintoverloads (InterlockedMin/InterlockedMaxwithasuint(ai)writeback onglc).EXECwraps the atomic call andglcwriteback inif (exec & 1).offen,idxen, extra modifiers (slc/dlc), unaligned immediate/scalar offsets, badvdata/vaddr/soffset, non-stride0 modified/misaligned/aliased descriptors, andinc/dec/float/64-bit atomics.CMakeLists.txt,.github/workflows/windows.yml,README.md, anddocs/experiments.md.Verification (
2f6c92bb, Windows Build26300.9974(26H2), DXCcs_6_0 -Gis -WX, D3D12debug_layer=enabled)Commands:
. .\tools\dev.ps1; cmake --preset release; cmake --build --preset release --target offscreen_checkpython -B tests/startup_compute_buffer_atomics_check.py(11 ops xglcon/off, alignment, modifiers, descriptor & out-of-scope refusals)ctest --preset release --no-tests=error -j 1 -R "^startup_(compute_buffer_atomics|gfx2hlsl_compute)(_mbcnt|_swapped-axes|_dropped-store|_b-offset|_c-unpredicated)?(_controls|_warp|_hardware)?$" -V(16/16 passed, 0 failed, 0 skipped)ctest --preset release --no-tests=error -R "^startup_(gfx2hlsl|compute_buffer_atomics|compute_gather|compute_image_store|compute_readfirstlane|compute_request_offline|compute_translate|image_|translator|tools_lint|capture|uniform_lane|smem_address|inline_sampler|sampler_heap|flat_param|ngg_slice)" -E "_(warp|hardware)$"(83/83 passed, 0 failed, 0 skipped)offscreen_check --compute-store-caseruns onREDUCE_BYTES(32 contended threads,groups=2x1x1) andEXCHANGE_BYTES(8 lanes,EXECmask,glc,cmpswap,vdata == vaddr,groups=1x1x1) + 6 mutated GPU negative controls:Microsoft Basic Render Driver,vendor=1414 device=008c, driver10.0.26100.9818,debug_layer=enabled): both positive casescompared_words=320 mismatches=0 debug_errors=0 debug_warnings=0; all 6 negative controls rejected withdebug_errors=0 debug_warnings=0(dropped_atomic:word=0 expected=4c5ec7b5 actual=c5c5c5c5,wrong_sub_sign:word=1 expected=3f2cc3d5 actual=4c5ec7b5,unsigned_smin:word=2 expected=a434c802 actual=2434c800,swapped_cmpswap:word=72 expected=55667788 actual=c5c5c5c5,dropped_glc_return:word=8 expected=c5c5c5c5 actual=00000010,dropped_exec_guard:word=6 expected=c5c5c5c5 actual=c5c5c5db).NVIDIA GeForce RTX 4070 SUPER,vendor=10de device=2783, driver32.0.16.2114,debug_layer=enabled): both positive casescompared_words=320 mismatches=0 debug_errors=0 debug_warnings=0; all 6 negative controls rejected withdebug_errors=0 debug_warnings=0at the exact same first-mismatch words.startup_tools_lint_check.py,docs_links_check.py,bidi_controls_check.py,form_coverage_check.py,shader_census_check.py,startup_translator_check.py) all passed.Not Tested Locally
llvm-mc-15assembly check (python -B tests/startup_compute_buffer_atomics_check.py --llvm-mc llvm-mc-15) was not run locally on Windows (covered by Ubuntu CI in.github/workflows/windows.yml; fixture bytes cross-checked withtools/disasm_rdna2.py).idxen,slc/dlc, andinc/dec/float/64-bit atomics.AI-assisted implementation and verification.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:45:42Z.
Review: COMMENTED
Review of head
2f6c92bb1a99ef802022d4675c067d308bb7387f.Result: no P1, no P2. Looks correct.
Checked:
buffer_atomic_cmpswapswaps the operand order correctly (RDNA 2 vdata[0]=replacement, vdata[1]=compare -> HLSL compare first). Return goes to vdata[0] only underglc.subviaInterlockedAdd(a, 0u - v),smin/smaxviaasintwithasuintwriteback: correct.swapalways uses the output form (HLSL needs it), writeback only underglc.glcwriteback.offen,idxen,slc/dlc, unaligned offsets, bad descriptors.buffer_store_dword*intoraw_table_uav_storekeeps the same checks and address rounding.Commands run locally on the PR head:
python3 tests/startup_compute_buffer_atomics_check.py-> "buffer_atomic controls (11 ops, glc/non-glc, alignment, modifiers, descriptors, refusals) passed", "Self-test passed."python3 tests/docs_links_check.py-> Checked 18 Markdown files and 452 links.python3 tests/bidi_controls_check.py-> no bidirectional controls.git diff --check origin/main...HEAD-> clean.InterlockedCompareExchangeemit -> the check failed with AssertionError (killed). Reverted.Not run: the D3D12 WARP readback part (needs Windows). I relied on the green
Build and test on WindowsCI job. Win2025 was not queued.Nits (non-blocking):
buffer_atomicre-createsused_atomicdefensively for stage objects built without__init__; a class-level default already exists, so theisinstanceguard is only needed for unit probes.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:52:39Z.
@Vladimir-Human could you rebase this branch onto current
mainand force-push?GitHub reports head
2f6c92bbas conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(4aaea119):.github/workflows/windows.ymlCMakeLists.txtREADME.mddocs/experiments.mdCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T12:54:57Z.
I ran
2f6c92bbon Intel UHD Graphics 770 (8086:a780, driver 32.0.101.5973), Windows 11 24H2 build 26100.9711, DXC 1.9.2609.5. Both the 32-thread reduction and the masked exchange matched all 320 words. The six mutants reported their predicted first mismatches at words 0, 1, 2, 72, 8 and 6 respectively. The dropped GLC return changed six words and the dropped EXEC guard changed two. The local D3D12 debug layer was unavailable.The fixture's assembly check also passed locally for the combined programs and all 11 operations with GLC on and off. I used LLVM 15.0.7's gfx1013 integrated assembler (
clang -cc1as -triple amdgcn-amd-amdhsa -target-cpu gfx1013 -filetype asm -show-encoding) as the--llvm-mcencoding provider.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:03:23Z.
Review: COMMENTED
Review of head
b5708a53f2a31929e511b21d7d839310c9d28bf9(PR #2331, 32-bit compute raw MUBUF atomics in gfx2hlsl).Verdict: no P1, no P2 findings. Comment only, no approval.
Semantics checked against the RDNA 2 MUBUF atomic definitions
cmpswap: replacement isvdata[0], compare isvdata[1]. The lowering emitsInterlockedCompareExchange(a, vdata[1], vdata[0], ao), orInterlockedCompareStore(a, vdata[1], vdata[0])without glc. Operand order matches HLSL (compare first). The pre-atomic value goes only tovdata[0](set_v(data[1])is the range start).swap: HLSL requires the output operand, soaois always declared and used. It is written back only under glc.sub:InterlockedAdd(a, 0u - val).smin/smax: signed overloads with anint aioutput, written back throughasuint(ai).if (exec & 1), andset_valready guards the writeback, so inactive lanes keep their VGPR (gfx2hlsl.py:1111,:2754).offen,idxen,slc/dlc, unaligned offset, bad descriptor. Theraw_table_uav_storerefactor keeps the store path identical (same& 0xfffffffcurounding and same checks).ao/aicome fromused_atomic, emitted only when needed.Commands executed locally in the worktree at this head
python3 tests/startup_compute_buffer_atomics_check.py->buffer_atomic controls (11 ops, glc/non-glc, alignment, modifiers, descriptors, refusals) passedpython3 tests/docs_links_check.py->Checked 19 Markdown files and 454 links.python3 tests/bidi_controls_check.py->no bidirectional controlsgit diff --check origin/main...HEAD-> cleangit checkout -- .); all were killed by the check (AssertionError):InterlockedCompareStore0u -negation forbuffer_atomic_subset_v)CI at review time: Linux Python checks pass, Windows build and test pass. "Assemble and translate gfx1013 fixtures" was still pending.
Not run: Win2025 WARP. The PR adds a
--dispatchreadback test (startup_compute_buffer_atomics_<adapter>), and I did not exercise it locally. It needs a Windows WARP pass before merge.Nits (non-blocking)
gfx2hlsl.pybuffer_atomic: theisinstance(getattr(self, 'used_atomic', None), set)fallback is needed only for stages built without__init__. A short comment would say so.MUBUF_ATOMIC_OPSthat wave-wide lowering would have to revisit it.AI-assisted; commands listed were executed locally.