Skip to content

shader: lower gfx1013 image_atomic_add, umax and cmpswap - #2013

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
Jess-Doit:shader/gfx1013-image-atomics
Nov 24, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
Jess-Doit:shader/gfx1013-image-atomics

Conversation

@Jess-Doit

Copy link
Copy Markdown
Contributor

Refs #1545

Change

The gfx1013 compute profile refused every image atomic ("Invalid image UAV binding"). It now accepts image_atomic_add, image_atomic_umax and image_atomic_cmpswap on a 2D R32_UINT UAV 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, InterlockedMax and InterlockedCompareStore on RWTexture2D<uint>.

Still refused on gfx1013:

  • every other image atomic (sub, and, or, xor, umin, swap, inc, dec), with "gfx1013 image atomics require add, umax or cmpswap";
  • R32_SINT and R32_FLOAT formats and a nonzero UAV mip, with "Invalid image UAV binding";
  • glc and the other flags the gfx1030 lowering refuses, so none of these atomics returns a value;
  • array and 3D dimensions, a second atomic, and a store to the same image.

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.py reuses the gfx1030 cases (mimg_atomic_cases) and references (mimg_atomic_reference) with the gfx1013 profile:

  • Controls (no GPU): identical HLSL for add, contended add, umax and cmpswap; 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 --llvm it also checks the disassembly round trip and the container CLI output. CI runs it in the gfx1013 fixtures job.
  • --draw (WARP and hardware):
    • Cases: one add on unique texels, a contended add with two lanes per texel, and a umax and a cmpswap on unique texels.
    • Groups: each case runs with one and two groups.
    • Readback: all 336 words of a three-mip texture are compared, including untouched texels and mips.
    • Mutants: one per case and group count, each of which must mismatch at the first word its reference predicts. They are a subtracting add, InterlockedMin in place of umax, and cmpswap with the compare and replacement reversed.
    • Form coverage: the draws write FORM_COVERAGE_RECORD.

Verification

Tested 3ff6e9d4 from main 1ebfe511 on 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).

Preset Passed Failed Skipped
dev 14 0 0
release 15 0 0

The 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 gave mismatches=8 on the GTX 1060.

Also run locally:

  • compute_image_atomics_gfx1013_check.py with no arguments, and with --binary using LLVM 15.0.7 llvm-mc;
  • the five compile-mimg-atomic-* modes of compute_store_check.py;
  • docs_links_check.py, bidi_controls_check.py, run_checks_parallel_check.py, form_coverage_check.py and git diff --check.

The --llvm disassembly step needs libLLVM, which this machine does not have; CI's LLVM 15 job runs it.

. .\tools\dev.ps1
$env:VULKAN_SDK = 'C:\VulkanSDK\1.4.363.0'
foreach ($preset in 'dev', 'release') {
    cmake --preset $preset
    cmake --build --preset $preset --target offscreen_check -j 2
    ctest --preset $preset --no-tests=error -j 1 -R '^(compute_store_aot_(gfx1013_image_atomics|gfx1013_image_store|mimg_atomic_(integer|minmax|exchange|counter|float))_.*|docs_links)$' -V
}
python3 -B tests/compute_image_atomics_gfx1013_check.py --binary llvm-mc-15 llvm-objcopy-15 --llvm libLLVM-15.so.1

Limits

  • Atomics that return the old value (glc) are not covered on either target.
  • umin, swap and the others are lowered for gfx1030 but stay refused on gfx1013 until a gfx1013 draw covers them.
  • Overlap: shader: lower gfx1013 buffer_atomic_add, umax and cmpswap #1684 also changes the gfx1013 rules in tools/compute_store_aot.py, for buffer atomics. The two touch different lines; I'll rebase onto whichever lands first.

AI-assisted (Claude Code).

The gfx1013 profile refused every image atomic. It now accepts add, umax
and cmpswap on a 2D R32_UINT UAV at mip 0 and lowers them with the
existing gfx1030 image atomic lowering, which emits identical HLSL for
both targets. Every other image atomic is refused by name on gfx1013, as
are signed and float formats; glc and the other flags stay refused.

tests/compute_image_atomics_gfx1013_check.py reuses the gfx1030 cases
with the gfx1013 profile: controls pin identical HLSL and the gfx1013
refusals; --binary assembles the programs for gfx1013 with LLVM 15,
pins the atomic MIMG dwords and checks they equal the gfx1030 bytes;
--draw compares every texel of a three-mip texture on WARP and hardware
with one mutant per case that must mismatch. The gfx1030 control that
expected gfx1013 to refuse the binding now states the new rule.

Refs R0Y00#1545

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@R0Y00
R0Y00 merged commit 2ee7627 into R0Y00:main Nov 24, 2026
5 checks passed
@ChazY11

ChazY11 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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/main shows 2 253 lines for a 258-line change. The real shape:

.github/workflows/windows.yml                |   1 +
CMakeLists.txt                               |   5 +
README.md                                    |   1 +
docs/experiments.md                          |  34 ++++
tests/compute_image_atomics_gfx1013_check.py | 200 +++++++++++++++++
tests/compute_store_check.py                 |  11 +-
tools/compute_store_aot.py                   |   8 +-
out/pe-env/Scripts/python.exe -B tests/compute_image_atomics_gfx1013_check.py    # exit 0

Note for anyone else running this: tests/compute_store_check.py needs a mode argument (mode, *args = sys.argv[1:]), so invoking it bare raises
ValueError on main as well — a usage error, not a regression from this PR.

mutation in tools/compute_store_aot.py result
drop the image_format == "R32_UINT" restriction caught
allowed ops lose cmpswap caught
the UAV gate stops consulting gfx1013_image_atomic caught
the op restriction is removed entirely caught
cpu == "gfx1013" → cpu != "gfx1030" survived

The survivor is equivalent, not a gap

Line 300 refuses any other CPU before this code runs:

if cpu not in ("gfx1013", "gfx1030"):
    raise ...

so inside this function cpu != "gfx1030" and cpu == "gfx1013" are the same predicate. No fixture could distinguish them, and asking for one would be
asking 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}. That
triple 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, sub or umax only. 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 the
gfx1030 tail, say so — otherwise a future contributor adding smin will read "the forms its draws cover" as permission to extend the tuple, and the
fixture 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.md gained 34 lines describing what is now emitted. I did not compile or run any shader — no dxc, and this fixture is
translation-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

  • AI-assisted review.

Jess-Doit added a commit to Jess-Doit/Xbox2Windows that referenced this pull request Nov 24, 2026
Conflicts with R0Y00#2013 (gfx1013 image atomics): tools/compute_store_aot.py
keeps this branch's view-dimension checks and UAV type together with
main's gfx1013 image atomic flag and descriptor helper; the docs,
README, CMake and workflow lists keep both entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jess-Doit

Copy link
Copy Markdown
Contributor Author

Thanks @ChazY11. On your two points:

  • Identical output, not just the same path: controls() in tests/compute_image_atomics_gfx1013_check.py asserts that for add, contended add, umax and cmpswap the 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.
  • Widening the op tuple: it can't happen silently. The same controls loop over every other integer op the shared lowering knows (sub, and, or, xor, umin, swap, inc, dec) and require the "gfx1013 image atomics require add, umax or cmpswap" refusal, so adding sub or umin to the tuple fails the check until the test changes too. smin/smax are refused earlier by the format rule.
  • Why these three: they match compute: image_store / image_load_mip to typed UAVs, and buffer/image atomics #1545's list and shader: lower gfx1013 buffer_atomic_add, umax and cmpswap #1684's buffer atomics. Each new op on gfx1013 is meant to arrive with its own draw.

Agreed on the cpu != "gfx1030" survivor: the earlier target check makes it equivalent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants