shader: lower typed 2D image atomics in direct Compute DXIL #3162
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3162"
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 RonLogic on 2026-11-27T19:17:55Z.
Change
Fixes #3156. Refs #2935, #1545 and #3074. The direct Compute compiler now lowers 32-bit
image_atomic_add,image_atomic_umaxandimage_atomic_cmpswapon a fixed 2DR32_UINTUAV. Synthetic containers previously stopped at the three image instructions at+0x28or+0x30on88cddb09.DXIL uses a typed 2D handle and the ordinary EXEC predicate. GLC returns the previous word to the data register, and the compare-and-swap operands retain AMD's replacement/compare ordering. The operations count as UAV writes for wait/barrier translation. Published manifests carry the unsigned one-channel format, and the stand-in refuses a mismatched UAV before recording a dispatch.
The patch composes cleanly with the current heads of #3049 and #3154. In-process binding of this format can follow their changes to the native slot layout. The typed path here is the published DXIL/manifest route.
Verification
Tested
ed946ef86369bec2a066673228507a9265576b0bon88cddb0919fd4044ff45211c0919c3aefda73c35. Windows 1126300.10075, MSVC with Visual Studio 2026 18.12.1, SDK 10.0.26100 and DXC 1.9.2602.17. RTX 407032.0.16.2124, WARP10.0.26100.10068.R16G16B16A16_FLOATcontrol was refused and all 1,024 output halfwords stayed at their sentinels. The D3D12 debug layer reported no errors in the positive runtime case.Evidence and follow-up
The experiment note records source-built fixture generation, public reference provenance, reproduction and limits. The shadPS4 report is a behavioral reference. The code and fixtures were developed independently.
I used Codex to prepare the change and ran verification locally.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T21:00:58Z.
LGTM! The typed 2D image atomic lowering is well-implemented:
Key features:
image_atomic_add,image_atomic_umax, andimage_atomic_cmpswapon R32_UINT UAVsRWTexture2D<uint>with integer coordinatesTest coverage:
Implementation notes:
startup_stream_consumer.cppchanges correctly handle the R32_UINT format for atomic operationsThis enables games using 2D texture atomics for compute shaders, which is common in modern rendering pipelines.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T21:37:30Z.
Review: COMMENTED
I tried to review
ed946ef8over currentmain673a9f2c. The trial merge conflicts insrc/gfx1013_compute_native.handsrc/direct_compute_cache.cpp. Since this PR's base88cddb09, #3140 (673a9f2c) has appendedComputeViewKind::heap_samplerto the same enum and raised the cached-binding bound indecode()to it. This PR appendsuint_texture_uavat the same place and raises the bound to that. The other six files merge cleanly (git merge-tree --write-tree origin/main review/3162).When you rebase, both enumerators have to stay. The
in.count(...)bound indecode()must name whichever one ends up last, or a cached binding of the other kind is rejected asinvalid cached binding. #3140 also added asampler_heaproot check in that loop, so auint_texture_uavbinding needs to take the ordinaryroot_parameter < 16branch. A cache round trip of auint_texture_uavshader on the rebased branch would show both points. I haven't run that.I'll review it once it is updated with
main.This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-27T22:05:50Z.
Fixed
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T22:20:02Z.
Review: APPROVED
Retested
e99e1dfdintegrated overmain6d690968(tree33882c84). The merge is clean andgit diff --cached --checkis clean. The conflict from my comment oned946ef8is resolved as suggested.uint_texture_uavfollowsheap_sampler, thedecode()bound namesuint_texture_uav, and auint_texture_uavbinding takes the ordinaryroot_parameterbranch of #3140's check.What I traced.
image_atomic_cmpswap16,image_atomic_add17,image_atomic_umax23. GLC is word 0 bit 13. The refusal mask0x3c0c6covers NSA, DLC, R128, TFE and LWE. Word 10xffe00000covers SSAMP, A16 and D16. dmask must be 1, or 3 for cmpswap.vdata[0]= new value,vdata[1]= compare. The lowering passesread(257 + dst)as DXIL'scompareValueandread(256 + dst)asnewValue, which matches.AtomicBinOpcodes 0 (IADD) and 7 (UMAX) are right. With GLC, the pre-operation value goes back tovdata[0].br i1 active(). Image atomics now count inwrites_uavs, sos_waitcnt_vscnt null, 0ands_barrieremit the UAV barrier.tex2d uint ... channels 1manifest line parses into a 2D slot flaggedatomic_uint_texture. That slot accepts onlyR32_UINT, and the float-format check now skips it.What I ran. I built
compile_dxil offscreen_check startup_stream_consumer d3d12_xs_shim native_store_replay native_compute_ir_dumpindevandrelease, then ran the PR's own selection:The
_hardwaretests ran at-j 1. In Debug and in Release/O2, each run had 18 passes, 0 failures and 3 skips:native_gather_lod_cs_warp,native_image_atomic_warpandstartup_compute_dispatch_native_warp. All three are WARP wave32 capability skips (77), as in the description.native_image_atomic_hardwarematched 336 texture words in each of the seven cases.native_image_atomic_runtime_hardwarematched all 256 words and left the float UAV unchanged. The debug layer was enabled with no errors.Negative control and mutants. Each mutant was rebuilt in
devand run againstnative_image_atomic_{controls,hardware,runtime_hardware}:main7→ signed IMAX5umax {}: 16 of 336 words differ)cmpswap {}: 16 words differ)br i1 true)R32_UINTchecknative_image_atomic_runtime_hardware)writes_uavsRestored and rebuilt afterwards;
git diff --quietis clean.Non-blocking. The UAV barrier is untested. Every fixture program already ends in
s_waitcnt_vscnt null, 0(0xBBFD0000), so one more assert incontrols()pins it. It passes on this head and kills the surviving mutant:Verdict: approve on
e99e1dfd. This supersedes my conflict comment oned946ef8.Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.26100, DXC 1.9.2602.17; Python 3.12.10; wave32; D3D12 debug layer enabled in the hardware tests.
CI:
Build and test on Windowspasses one99e1dfd(theprpreset doesn't include these tests).This reply was AI-assisted.