shader: lower gfx1013 image_atomic_add, umax and cmpswap #2006
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2013"
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 Jess-Doit on 2026-11-24T23:07:03Z.
Refs #1545
Change
The gfx1013 compute profile refused every image atomic ("Invalid image UAV binding"). It now accepts
image_atomic_add,image_atomic_umaxandimage_atomic_cmpswapon a 2DR32_UINTUAV at mip 0, and lowers them with the gfx1030 image atomic lowering that is already on main. The emitted HLSL is byte-identical for the two targets:InterlockedAdd,InterlockedMaxandInterlockedCompareStoreonRWTexture2D<uint>.Still refused on gfx1013:
sub,and,or,xor,umin,swap,inc,dec), with "gfx1013 image atomics require add, umax or cmpswap";R32_SINTandR32_FLOATformats and a nonzero UAV mip, with "Invalid image UAV binding";glcand the other flags the gfx1030 lowering refuses, so none of these atomics returns a value;The gfx1030 control that expected gfx1013 to refuse every image atomic binding now states the rule above for each gfx1030 case, and checks that the accepted ones lower identically.
Tests
tests/compute_image_atomics_gfx1013_check.pyreuses the gfx1030 cases (mimg_atomic_cases) and references (mimg_atomic_reference) with the gfx1013 profile:umaxandcmpswap; pins for the operation, operand order and unsigned type; and every refusal above.--binary(LLVM 15): assembles the four programs for gfx1013, pins the two MIMG dwords of each atomic (opcode 17, 23 or 16, dmask, unorm, 2D), and checks that the bytes equal the gfx1030 bytes. With--llvmit also checks the disassembly round trip and the container CLI output. CI runs it in the gfx1013 fixtures job.--draw(WARP and hardware):umaxand acmpswapon unique texels.InterlockedMinin place ofumax, andcmpswapwith the compare and replacement reversed.FORM_COVERAGE_RECORD.Verification
Tested
3ff6e9d4from main1ebfe511on Windows 10 22H2 build 19045.6456, MSVC 19.44.35230, DXC from Vulkan SDK 1.4.363.0, with the D3D12 debug layer on (zero warnings and errors).devreleaseThe selection is the new test on both adapters, the gfx1013 image-store tests and the five gfx1030 image atomic suites on both adapters. In Release it adds
docs_links. Adapters: NVIDIA GeForce GTX 1060 6GB (hardware) and WARP. All 16 mutant draws, 4 cases × 2 group counts × 2 adapters, mismatched at the predicted word; for example, add with one group gavemismatches=8on the GTX 1060.Also run locally:
compute_image_atomics_gfx1013_check.pywith no arguments, and with--binaryusing LLVM 15.0.7llvm-mc;compile-mimg-atomic-*modes ofcompute_store_check.py;docs_links_check.py,bidi_controls_check.py,run_checks_parallel_check.py,form_coverage_check.pyandgit diff --check.The
--llvmdisassembly step needs libLLVM, which this machine does not have; CI's LLVM 15 job runs it.Limits
glc) are not covered on either target.umin,swapand the others are lowered for gfx1030 but stay refused on gfx1013 until a gfx1013 draw covers them.tools/compute_store_aot.py, for buffer atomics. The two touch different lines; I'll rebase onto whichever lands first.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:30:33Z.
Ran it, broke it five ways: four caught, one survivor proven equivalent by the function's own domain guard
Read on the merge base — your branch is 49 commits behind, so
git diff origin/mainshows 2 253 lines for a 258-line change. The real shape:Note for anyone else running this:
tests/compute_store_check.pyneeds a mode argument (mode, *args = sys.argv[1:]), so invoking it bare raisesValueErroronmainas well — a usage error, not a regression from this PR.tools/compute_store_aot.pyimage_format == "R32_UINT"restrictioncmpswapgfx1013_image_atomiccpu == "gfx1013"→cpu != "gfx1030"The survivor is equivalent, not a gap
Line 300 refuses any other CPU before this code runs:
so inside this function
cpu != "gfx1030"andcpu == "gfx1013"are the same predicate. No fixture could distinguish them, and asking for one would beasking for a test that cannot fail. Your expression is correct as written.
What the gating actually says, and the one thing I would add
Three conditions decide whether gfx1013 may use the shared atomic lowering: UAV output,
R32_UINT, and op ∈ {add, umax, cmpswap}. Thattriple is the whole claim of the PR, and all three are pinned by the mutations above — including the op list, which is the one most likely to be
silently widened later.
The omission I would fix: nothing states why those three ops and not, say,
suborumaxonly. The code comment says "the forms its draws cover",which is honest but not checkable. If the draws cover exactly those three because the third is
cmpswap's compare-and-swap semantics needing thegfx1030 tail, say so — otherwise a future contributor adding
sminwill read "the forms its draws cover" as permission to extend the tuple, and thefixture will not stop them because it only tests the three that exist.
A cheap version: assert in the check that the tuple is exactly
("add", "umax", "cmpswap"), so widening it requires touching the test.Coverage gap I did not close
docs/experiments.mdgained 34 lines describing what is now emitted. I did not compile or run any shader — nodxc, and this fixture istranslation-only. So the claim "the lowering is the gfx1030 one" is verified as the same code path being selected, not as identical output; if you
have a diff of the emitted HLSL against gfx1030 for the same three ops, that is the evidence a reviewer cannot produce locally.
Notes
Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-25T00:44:15Z.
Thanks @ChazY11. On your two points:
controls()intests/compute_image_atomics_gfx1013_check.pyasserts that for add, contended add,umaxandcmpswapthe gfx1013 HLSL equals the gfx1030 HLSL for the same lines (source == lowered(lines, binding | {"cpu": "gfx1030"})). The GPU draws then compile that HLSL with DXC and compare every texel on the GTX 1060 and WARP.sub,and,or,xor,umin,swap,inc,dec) and require the "gfx1013 image atomics require add, umax or cmpswap" refusal, so addingsuboruminto the tuple fails the check until the test changes too.smin/smaxare refused earlier by the format rule.Agreed on the
cpu != "gfx1030"survivor: the earlier target check makes it equivalent.