Repository navigation
shader: lower typed 2D image atomics in direct Compute DXIL - #3162
Conversation
|
LGTM! The typed 2D image atomic lowering is well-implemented: Key features:
Test coverage:
Implementation notes:
This enables games using 2D texture atomics for compute shaders, which is common in modern rendering pipelines. |
pigalot
left a comment
There was a problem hiding this comment.
I tried to review ed946ef8 over current main 673a9f2c. The trial merge conflicts in src/gfx1013_compute_native.h and src/direct_compute_cache.cpp. Since this PR's base 88cddb09, #3140 (673a9f2c) has appended ComputeViewKind::heap_sampler to the same enum and raised the cached-binding bound in decode() to it. This PR appends uint_texture_uav at 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 in decode() must name whichever one ends up last, or a cached binding of the other kind is rejected as invalid cached binding. #3140 also added a sampler_heap root check in that loop, so a uint_texture_uav binding needs to take the ordinary root_parameter < 16 branch. A cache round trip of a uint_texture_uav shader 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.
|
Fixed |
pigalot
left a comment
There was a problem hiding this comment.
Retested e99e1dfd integrated over main 6d690968 (tree 33882c84). The merge is clean and git diff --cached --check is clean. The conflict from my comment on ed946ef8 is resolved as suggested. uint_texture_uav follows heap_sampler, the decode() bound names uint_texture_uav, and a uint_texture_uav binding takes the ordinary root_parameter branch of #3140's check.
What I traced.
- Encoding. The opcodes match RDNA 2 MIMG:
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. - Operand order. AMD's cmpswap data is
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]. - Predication and barriers. The atomic sits behind
br i1 active(). Image atomics now count inwrites_uavs, sos_waitcnt_vscnt null, 0ands_barrieremit the UAV barrier. - Runtime. The
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_dump in dev and release, then ran the PR's own selection:
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(native_(image_atomic_.+|gather_lod_.+)|compute_store_aot_mimg_atomic_(integer|minmax|exchange)_(warp|hardware)|startup_compute_dispatch_(native|texture|two_mips)_(warp|hardware))$'The _hardware tests 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_warp and startup_compute_dispatch_native_warp. All three are WARP wave32 capability skips (77), as in the description. native_image_atomic_hardware matched 336 texture words in each of the seven cases. native_image_atomic_runtime_hardware matched 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 dev and run against native_image_atomic_{controls,hardware,runtime_hardware}:
| Mutant | Result |
|---|---|
the four source files back to main |
killed: all three refuse at "direct image opcode or descriptor modifiers" |
UMAX 7 → signed IMAX 5 |
killed (umax {}: 16 of 336 words differ) |
| cmpswap compare and new value swapped | killed (cmpswap {}: 16 words differ) |
ignore EXEC (br i1 true) |
killed (sparse add, and the runtime case at word 197) |
drop the runtime R32_UINT check |
killed (native_image_atomic_runtime_hardware) |
image atomics not counted in writes_uavs |
survives |
Restored and rebuilt afterwards; git diff --quiet is clean.
Non-blocking. The UAV barrier is untested. Every fixture program already ends in s_waitcnt_vscnt null, 0 (0xBBFD0000), so one more assert in controls() pins it. It passes on this head and kills the surviving mutant:
assert '@dx.op.barrier(i32 80, i32 2)' in dump, dumpVerdict: approve on e99e1dfd. This supersedes my conflict comment on ed946ef8.
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 Windows passes on e99e1dfd (the pr preset doesn't include these tests).
This reply was AI-assisted.
* compute: lower more typed 2D image atomics in direct compute The direct compute typed 2D image atomic path of #3162 (cmpswap, add, umax) now also lowers image_atomic_swap, _umin, _and, _or and _xor to DXIL AtomicBinOp Exchange, UMin, And, Or and Xor on the same RWTexture2D<uint> binding, with the same operand checks, EXEC guard and GLC return of the old value. image_atomic_smin and _smax stay refused, because signed min/max is not verified on this R32_UINT binding; sub, inc, dec and the float atomics stay refused too. New test native_image_atomic_binops (controls, WARP, hardware) reuses the #3162 fixture: each new op compiles to atomicBinOp with its code, the operand refusals still apply, and the refused ops keep "direct image opcode or descriptor modifiers". The readback covers distinct and contended texels, GLC on and off, and a sparse EXEC. AI-assisted. * docs: list the new typed 2D image atomics native-image-atomics now lists swap, umin, and, or and xor with their AtomicBinOp codes, keeps signed min/max outside the verified scope, and links the binary-operation fixture. AI-assisted.
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.