Skip to content

shader: lower gfx1013 buffer_atomic_add, umax and cmpswap - #1684

Merged
tedin7 merged 2 commits into
R0Y00:mainfrom
Jess-Doit:shader/compute-buffer-atomics
Nov 25, 2026
Merged

tedin7 merged 2 commits into
R0Y00:mainfrom
Jess-Doit:shader/compute-buffer-atomics

Conversation

@Jess-Doit

@Jess-Doit Jess-Doit commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1545

Change

Extend the existing raw UAV atomic emitter to gfx1013 DWORD add, unsigned
max and compare-swap. The checked address forms are a fixed shared word
(off), a dispatch byte offset (offen) and a dispatch index with a
declared stride (idxen). Returning atomics publish the old DWORD to
the first data VGPR after vmcnt(0). A later plain DWORD store can record
it in a disjoint field. Compare-swap reads the replacement from VDATA
and compare from VDATA+1. The latter still holds the comparison word
after the wait. AMD RDNA 2 Shader ISA

The pure-Python controls also pin the emitted InterlockedCompareExchange argument order, the glc
old-value return and the record that stores it, and the non-returning form. Translation controls refuse a lane guard before or after the atomic, 64-bit forms, unmodeled opcodes, an atomic
to an SRV, a return consumed before its wait, overlapping record fields,
an address shift that wraps within a group, and consumption of the first
data VGPR after a non-returning atomic without an explicit rewrite.

Scope requested on #1545

  • Shared-address add: the test checks the final word and the old values. Each lane adds a distinct positive operand and nothing wraps, so sorting the (old value, operand) pairs gives the only order consistent with the trace. The check rebuilds each step from the initial word to the final word, which implies the multiset check. A control swaps two lanes' old values and must be rejected.
  • umax and compare-swap: each lane uses its own deterministic address, so every old value and final word has a single expected value. compare-swap has 16 matching and 16 non-matching lanes. No umax or compare-swap case shares an address.
  • Guard words: all 320 words are compared, including the sentinels around each record.
  • Missing wait: reading the returned value before s_waitcnt vmcnt(0), or after only an lgkmcnt wait, is refused.

Verification

The full draws below ran at 85271d0e. Later commits change only the test file and CMake, not the lowering, the fixture programs or the draw references:

  • the LLVM 15 machine words;
  • pure-Python pins of the emitted HLSL;
  • the form-coverage record.

They also merge main. At a823f6d4, compute_store_aot_gfx1013_buffer_atomics_{warp,hardware} passed again on both adapters.

The two commits after it, 5daf7adc and 43cd101a, only add controls to tests/compute_buffer_atomics_check.py. Every other 32-bit MUBUF atomic is refused, and so are the 64-bit add, umax and cmpswap forms with defined data. Removing the width check from the gfx1013 gate now fails the no-argument check.

Tested 85271d0e85a782066f1ce50ae93cf021f6a11c1c on base
df488f52338101bbcf049649bd737bb2d4dcb71b. Windows 10 22H2 build 19045.6456
and Windows SDK 10.0.26100.0 DXC, targeting cs_6_0 for the new cases.
The branch merges cleanly with #1649 at faa78cd4. It is merged with main at abb24b67 (0c1c7e2d).

Adapter Driver New fixture readbacks Shared add
GTX 1060 6 GB 32.0.15.6094 5 cases, 320 words each 32 valid return records
In-box WARP 10.0.19041.5794 5 cases, 320 words each 32 valid return records

The shared add reconstructed a valid serialization of the lane operands
from 9e3779b1 to 9e377bc1. The compare-swap case checked 16 hits and
16 misses, both data VGPR records, and all untouched words. The add-as-OR
mutation first differed at word 0 (9e3779b2 expected, 9e3779b1 read).
Writing the addend into the old-value record first differed at word 1
(9e3779b1 expected, 00000001 read). The debug layer reported zero
warnings and errors in the new Debug runs. The full Debug selection
recorded 85 passes, 6 capability skips and 0 failures. The existing raw
64-bit reduction, exchange and counter cases skipped on both adapters
because they require SM 6.6 and Int64ShaderOps. Release (/O2) gave the same result: 85 passes,
6 capability skips, 0 failures.

After the merge with main, a Debug rerun of compute_store_aot_(warp|hardware), the new
compute_store_aot_gfx1013_buffer_atomics_{warp,hardware} and the existing mubuf_{reduction,exchange,counter}
cases on both adapters had 10 passes and the same 6 capability skips.

. .\tools\dev.ps1
$env:VULKAN_SDK = 'C:\VulkanSDK\1.4.363.0'
$env:XBOX2WINDOWS_ADAPTER = '1060'
$env:X2W_D3D12_DEBUG = '1'
$venvPython = (Resolve-Path 'out/pe-env/Scripts/python.exe').Path
foreach ($preset in 'dev', 'release') {
    cmake --preset $preset "-DINTAKE_PYTHON:FILEPATH=$venvPython"
    cmake --build --preset $preset --target offscreen_check -j 2
    ctest --preset $preset --no-tests=error -j 1 -R '^(compute_store_aot_|docs_links$)' -V
}

The recorded words are LLVM 15's, as in CI. LLVM 15 and 19 leave the unused src2 field of the two
v_mul_lo_u32 words in the cmpswap case at 0, where LLVM 23 writes inline 0, so a local LLVM 23 run
differs in those two bytes only. The Ubuntu job also
checks the container CLI with LLVM 15.

python3 -B tests/compute_buffer_atomics_check.py
python3 -B tests/compute_buffer_atomics_check.py --binary llvm-mc-15 llvm-objcopy-15 --llvm libLLVM-15.so.1

AI-assisted (Codex, driven with Claude Code; Claude Code reviewed the change and ran the Release and post-merge checks).

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head 0c1c7e2df57582de7a04a471352dee0113b49721.

Linux limits. Linux x86_64, llvm-mc-19 / llvm-objcopy-19 (CI pins 15), Python 3.14. No Windows, no DXC, no GPU, so I could NOT run --draw (the ctest compute_store_aot_gfx1013_buffer_atomics_<adapter>). Old-value return, contended-add serialization and the HLSL semantics were not executed.

Scope. The title says DWORD buffer atomics, but the gfx1013 path accepts only add, umax and cmpswap (32-bit). sub, smin, umin, smax, and, or, xor, swap, inc, dec, csub and all _x2 forms are refused with gfx1013 buffer atomics require 32-bit add, umax or cmpswap. The README row and docs name add, umax and cmpswap, so this is consistent, but the title reads wider.

What I ran

  • python3 -B tests/compute_buffer_atomics_check.py (controls plus lowering of the 5 cases): passes.
  • --binary llvm-mc-19 llvm-objcopy-19 --llvm /usr/lib/llvm-19/lib/libLLVM-19.so: add_offen, umax_idxen, umax_no_glc, shared_add pass. cmpswap fails: the hard-coded words differ in 2 bytes of the filler src2 field of two v_mul_lo_u32-style VOP3 words (...0102 expected, ...0100 from llvm-19). The atomic words themselves (0060c4e0 00040680 etc.) match. So this is an assembler-version pin, harmless with the CI's llvm-15, but the check is brittle on other LLVM versions.
  • Mutations on tools/compute_store_aot.py, each followed by the no-argument check, restored with git checkout -- .:
    • cmpswap operand order swapped (f"{word}, {operands[1]}"): check STILL PASSED.
    • glc ignored (result = "ignoredAtomic", so the old value is not returned): check STILL PASSED.
    • guard refusal removed (s_and_saveexec_b32 after an atomic): check STILL PASSED.
    • overlap guard removed (Return record can overlap the fixed atomic address): FAILED, as intended.
    • extra op (or) let through the allow list: FAILED, as intended.

Findings

  • The three surviving mutations are semantic ones the Linux run cannot see: the cmpswap compare/replace order, the old-value return with glc, and the guard. They are guarded only by --draw on a Windows GPU. The ISA order itself (replacement in VDATA, compare in VDATA+1, HLSL compare first) is what the code does, and llvm-mc-19 accepts buffer_atomic_cmpswap v[4:5], v0, s[24:27], 0 idxen glc. A text-level assertion on the emitted InterlockedCompareExchange argument order and on atomicOld would make the Linux CI step meaningful.
  • Without glc the data register is popped from vector, so a consumer of it is refused (Store data is not a known word control). That is the safe choice.
  • Workflow wiring (windows.yml CHECKS entry with the explicit --binary llvm-mc-15 llvm-objcopy-15 --llvm libLLVM-15.so.1, the no-argument step, AGENTS.md) looks consistent with its neighbours; I did not run Actions.

Verdict: the accepted shapes assemble to the expected machine words, and the refusals are tight. The ordering and old-value semantics rest on Windows-only draws. Not approving.

AI-assisted; commands listed were executed locally.

@tedin7 tedin7 mentioned this pull request Nov 24, 2026
@Jess-Doit Jess-Doit changed the title shader: lower gfx1013 DWORD buffer atomics shader: lower gfx1013 buffer_atomic_add, umax and cmpswap Nov 24, 2026
@Jess-Doit

Copy link
Copy Markdown
Contributor Author

Thanks @tedin7. Both points are addressed in the latest commit:

  • LLVM pin: the cmpswap fixture recorded LLVM 23's encoding. LLVM 23 writes inline 0 into the unused src2 field of the two v_mul_lo_u32 words, where LLVM 15 and 19 leave it at 0, and that is what failed the gfx1013 CI job. The recorded words are now LLVM 15's, as in CI and in the bytes you saw from LLVM 19.

  • Surviving mutations: the pure-Python controls now pin:

    • the emitted InterlockedCompareExchange(addr, compare, replacement, atomicOld) order, with VDATA+1 as the compare and VDATA as the replacement;
    • the glc old value, and that the record stores atomicOld;
    • the non-glc form, which returns nothing;
    • lane-guard refusals before and after the atomic.

    Swapping the cmpswap operands, ignoring glc, and removing the guard-after refusal now each fail the no-argument check.

  • Title: narrowed to add, umax and cmpswap.

The Windows draws are unchanged from the description: Debug and Release on a GTX 1060 and WARP.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of head a34997b (comment only, not an approval). My earlier review was at 0c1c7e2.

Verdict: 0 P1 / 0 P2.

Earlier points

  • Fixed: the cmpswap fixture's two v_mul_lo_u32 words now end in ...0100; llvm-mc-19 --binary passes all 5 cases (llvm 15 not run).
  • Fixed: new assertions pin InterlockedCompareExchange(addr, compare, replacement, atomicOld), InterlockedAdd(..., atomicOld) plus the store, ignoredAtomic without atomicOld for the non-glc case, and two rejections for a lane guard before and after the atomic. I re-ran my earlier cmpswap-order and glc mutations and both now fail. The title now names add, umax and cmpswap.

Semantics: the replacement is in VDATA (v4) and the compare in VDATA+1 (v5), HLSL gets the compare first, matching the .s file. With glc the old value goes to the first data VGPR, gated by vmcnt(0) through loading[src]. llvm-mc-19 on gfx1013 and gfx1030 gives identical bytes (cmpswap opcode 49, add 50, umax 56). signed is true only for smin/smax, so umax is unsigned. off, idxen and offen go through linear_uav_address. The three opcodes are already in docs/coverage/gfx1013.tsv and rdna2.tsv. No assertion is weakened; the one loosened line only lets gfx1013 follow an atomic with a plain DWORD store, which is the record store.

Run

  • python3 -B tests/compute_buffer_atomics_check.py: controls passed. The same with --binary llvm-mc-19 llvm-objcopy-19 --llvm /usr/lib/llvm-19/lib/libLLVM-19.so: all 5 cases match (machine words, disassembly round trip, container CLI).
  • tests/compute_store_check.py binary ... (no gfx1030 regression), compute_entry_layout_check, run_checks_parallel_check, docs_links_check (17 files, 364 links), bidi_controls_check, git diff --check origin/main...HEAD: pass.
  • Mutations in tools/compute_store_aot.py (restored with git checkout --, green again), caught: cmpswap operands swapped; glc ignored; guard-before refusal removed; return VGPR readable before the wait; offen wrap bound << 40.
  • NOT caught on Linux: umax treated as signed; umax mapped to Min; per-thread address offset dropped (+ 0u; every atomic fixture uses offset 0, so it is untested even with --draw).

Non-blocking

  • Pin the umax HLSL the way the cmpswap and add text pins do (uint type and InterlockedMax in lowered["umax_idxen"], and lowered["umax_no_glc"] beyond ignoredAtomic);), so signedness and the Max/Min mapping do not rest only on a Windows draw.
  • Give one atomic fixture a nonzero offset:.
  • The new ctest has no FORM_COVERAGE_RECORD, unlike compute_store_aot_mubuf_reduction_*; the neighbouring gfx1013_image_store test omits it too, so optional.
  • The PR body's control list still says "Add shift that wraps within a group"; it matches the << 31 control.

Not run: --draw (ctest compute_store_aot_gfx1013_buffer_atomics_*), so the contended-add serialization, the hit/miss readbacks and the 85-pass claim are unconfirmed here.

Linux limits: no Windows, WARP or GPU here; LLVM 19 only (CI pins LLVM 15). Anything that needs them was not run.

AI-assisted; commands listed were executed locally.

@Jess-Doit

Copy link
Copy Markdown
Contributor Author

Thanks @tedin7. The non-blocking points are in a823f6d4:

  • umax pins: the controls now pin uint atomicOld; … InterlockedMax(tid.x * 8u + 0u, 0x80012345u, atomicOld) and the non-glc ignoredAtomic form. Treating umax as signed, or mapping it to Min, now fails the no-argument check.
  • Nonzero offset: a per-thread offen offset:4 atomic must emit (tid.x << 3u) + 4u, with the record moved to offset 0. That's a translation-level pin; the draw fixtures still use offset 0.
  • Form coverage: compute_store_aot_gfx1013_buffer_atomics_* now sets FORM_COVERAGE_RECORD, and the draw writes the accepted mnemonics. Both adapters passed again on the GTX 1060 and WARP with the record written.

This commit also merges main at a4d17cf5, with no conflicts.

@Jess-Doit

Copy link
Copy Markdown
Contributor Author

The Windows job failure at a823f6d4 is in startup_launch, which this PR doesn't touch. This PR only changes tests/compute_buffer_atomics_check.py and CMake since the last green run.

The failure is a timing edge in the timeout case: the process was killed by the 1 s timeout at the same moment the fast-fail check compared its run time against 1.0 s (killed after 1 s timeout in 1.00 s … fast-fail: exited with 0xdead0001 in 1.00 s (< 1.0 s)).

On the same merged tree, ctest --preset dev --no-tests=error -R '^startup_launch$' passed 3/3 locally (Windows 10 22H2). Could a maintainer rerun the failed job? I don't have rights to rerun it.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head c34d584dd163e8751974e82018945c73e2eb98d3. My earlier reviews were on 0c1c7e2d and a34997b9; since then the PR added a823f6d4 (umax and nonzero-offset pins, form-coverage record) and c34d584d (a comment), plus a main merge.

Verdict: no P1 and no P2. The lowering matches the RDNA 2 atomic semantics as I read them, and the new pins hold.

Linux limits. Linux x86_64, llvm-mc-19 and llvm-objcopy-19 (CI pins 15), Python 3. No Windows, no DXC, no GPU, and I did not run the pipeline's Windows helper. So I did not run --draw (compute_store_aot_gfx1013_buffer_atomics_<adapter>): the contended-add serialization, the returned old values and the compare-swap hit and miss counts are the author's GTX 1060 and WARP results, not reproduced by me. Those draws ran at 85271d0e; the PR text says later commits only changed the test file and CMake, and git diff 8cef962c HEAD agrees for the lowering except one added comment (tools/compute_store_aot.py:1586-1589).

Semantics I checked (tools/compute_store_aot.py)

  • cmpswap: the ISA takes the replacement in VDATA and the compare in VDATA+1 and returns the old value in VDATA when glc is set; the lowering emits compare first, then replacement (word = f"{operands[1]}, {word}"), the HLSL InterlockedCompareExchange order. With glc the first data VGPR is set from loading[src] and only readable after vmcnt(0); the compare register keeps its value.
  • Non-glc forms write ignoredAtomic and pop the first data VGPR, so a later read of it is refused instead of invented.
  • offen/idxen go through linear_uav_address (:254-266): the shift is bounded and dims[axis] << shift cannot pass 2^32, the field must fit the element, and every other group axis must be 1. A shared off atomic sets shared_atomic_offset, and a later record must be per-thread and start above it, so a record cannot land on the shared word for any lane.
  • gfx1013 refuses 64-bit forms, a guard before or after the atomic, an image binding, and a second atomic. Plain buffer_store_dword after the atomic is the only store allowed (buffer_store_dwordx2 and the others are still refused).

What I ran on this head (worktree at the exact SHA; git status clean after every mutation)

  • python3 -B tests/compute_buffer_atomics_check.py: passes.
  • ... --binary llvm-mc-19 llvm-objcopy-19 --llvm /usr/lib/llvm-19/lib/libLLVM-19.so: all five cases (add_offen, umax_idxen, umax_no_glc, shared_add, cmpswap) match llvm-mc.
  • python3 -B tests/compute_store_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so (the CI entry for the translator as a whole): exit 0, so the shared lowering still passes its existing cases.
  • git merge-tree --write-tree origin/main HEAD: clean; also clean against #1649. git diff --check origin/main...HEAD, docs_links_check.py (17 files, 366 links), bidi_controls_check.py: clean.
  • Mutations of tools/compute_store_aot.py, each restored:
Mutation controls
cmpswap compare/replacement order swapped fail
glc return dropped (always ignoredAtomic) fail
returned value not gated by vmcnt (loading[src] not set) fail
record allowed on the shared word (<= to <) fail
lane-guard-after-atomic check removed fail
gfx1013 also accepts 32-bit sub pass

Findings

  1. P3, test gap: the controls refuse inc, dec, csub and or (tests/compute_buffer_atomics_check.py:56) but not the other 32-bit forms the gfx1013 gate also refuses (sub, smin, umin, smax, and, xor, swap). Widening the accepted set by one opcode leaves the check green, although no draw covers that opcode. One loop over those names in the existing rejection block would pin it.
  2. P3, scope: the title now names add, umax and cmpswap, which matches the gate.
  3. Not verified by me: the Windows draw results above, and the CI jobs (the author notes a startup_launch timing failure unrelated to this PR).

AI-assisted; commands listed were executed locally.

@Jess-Doit

Copy link
Copy Markdown
Contributor Author

Thanks @tedin7. Finding 1 is fixed in 5daf7adc. The refusal loop now runs over every op in MUBUF_ATOMIC_METHODS except add, umax and cmpswap: sub, smin, umin, smax, and, or, xor, swap, inc, dec and csub. An assertion keeps that list from shrinking. With sub added to the gfx1013 gate, the no-argument check now fails. This changes only the test file, so the draws are unaffected.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of head 5daf7adc818198c6f4a3d18395889089cb76fc07. My previous review was at c34d584d. Comment only, not an approval.

Verdict: 0 P1 / 0 P2. The one open finding from my last review is closed.

Linux limits. Linux x86_64, llvm-mc-19 and llvm-objcopy-19 (CI pins 15), Python 3. No Windows, no DXC, no GPU. I did not run --draw (ctest compute_store_aot_gfx1013_buffer_atomics_<adapter>), so the contended-add serialization, the returned old values and the compare-swap hit and miss counts remain the author's GTX 1060 and WARP results. Not reproduced by me.

Previous finding

  • P3, "gfx1013 also accepts 32-bit sub stays green": fixed. git diff c34d584d HEAD is one commit touching only tests/compute_buffer_atomics_check.py (+4 / -1). The refusal loop now runs over sorted(set(aot.MUBUF_ATOMIC_METHODS) - {"add", "umax", "cmpswap"}), and an assertion keeps the eleven names sub, smin, umin, smax, and, or, xor, swap, inc, dec, csub inside that list, so the loop cannot silently shrink. Nothing under tools/ changed since the head I last reviewed, so the lowering review stands.

What I ran at this SHA (worktree at the exact head, git status clean after the mutations)

  • python3 -B tests/compute_buffer_atomics_check.py: "controls passed".
  • The same with --binary llvm-mc-19 llvm-objcopy-19 --llvm /usr/lib/llvm-19/lib/libLLVM-19.so: all five cases (add_offen, umax_idxen, umax_no_glc, shared_add, cmpswap) report "machine words match llvm-mc".
  • python3 -B tests/compute_store_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so: exit 0. The output ends with the two expected Unsupported MUBUF cache invalidation refusal lines.
  • tests/docs_links_check.py (17 files, 366 links), tests/bidi_controls_check.py (1299 files), git diff --check origin/main...HEAD: clean.
  • Mutations in tools/compute_store_aot.py, each followed by the no-argument check and git checkout -- .:
Mutation controls
gfx1013 gate also accepts sub (the previously surviving one) fail: "Expected rejection: require 32-bit add, umax or cmpswap"
gfx1013 gate also accepts _x2 forms fail, but with "Atomic reduction data is not a known word" (a different assertion, not a rejection pin for the 64-bit gate)
cmpswap compare/replacement order swapped fail
umax mapped to Min in MUBUF_ATOMIC_METHODS fail

Remaining notes (non-blocking)

  • P3: the _x2 mutation is killed only by a downstream "data is not a known word" assertion. A control that feeds an _x2 form and expects the "32-bit" rejection message would pin the wide half of the gate directly. Optional.
  • The CI startup_launch timing failure the author describes is not touched by this PR; I did not run Actions.

AI-assisted; commands listed were executed locally.

@Jess-Doit

Jess-Doit commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @tedin7. The _x2 note is fixed in 43cd101a. It only changes tests/compute_buffer_atomics_check.py.

  • Cause: the old add_x2 control left v5 undefined. With the width check removed, the data check still refused it ("Atomic reduction data is not a known word"), so the gate itself wasn't pinned.
  • Fix: the controls now feed buffer_atomic_add_x2 v[4:5], buffer_atomic_umax_x2 v[4:5] and buffer_atomic_cmpswap_x2 v[4:7] with v5 to v7 defined, and each expects the "require 32-bit add, umax or cmpswap" refusal. The old control is replaced; the new one covers the same add_x2 case.
  • Mutation: dropping wide or from the gfx1013 gate now fails the no-argument check with Expected rejection: require 32-bit add, umax or cmpswap. Restored, it passes again.

The lowering and the draws are unchanged.

Status: ready to merge from our side. Every finding from tedin7's four reviews, the P3s included, is addressed in the code or answered here. CI is green at 43cd101a, and the branch merges cleanly with main and with #1649. If you'd like anything else changed or tested, I'll do it.

@Jess-Doit

Copy link
Copy Markdown
Contributor Author

Merged main at 889cd3f4 in 5de96be9 to resolve a conflict with main:

  • Conflict: main added startup_ngg_slice_check.py to the Python check lists in .github/workflows/windows.yml and AGENTS.md, at the spot where this PR adds compute_buffer_atomics_check.py.
  • Resolution: both entries are kept. No code changed.

After the merge, the atomics controls, run_checks_parallel_check.py, docs_links_check.py and the new startup_ngg_slice_check.py pass locally.

Status: ready to merge from our side. CI is green at 5de96be9, and every review finding is addressed or answered above.

@Jess-Doit

Copy link
Copy Markdown
Contributor Author

Merged main at 05092b6e in 26604aa8 to resolve a conflict with #1683 (descriptor-format stores):

  • Where: the indexed raw-store branch of tools/compute_store_aot.py. This PR routes that branch through linear_uav_address, while main changed the field size from 4 * count to span.
  • Resolution: the helper now receives span, so descriptor stores reserve the same bytes as on main.
  • Check: main's descriptor-store program lowers to HLSL byte-identical to main's own output.

Reruns after the merge:

  • the atomics controls and LLVM 15 --binary check;
  • Debug compute_store_aot_* draws on the GTX 1060 and WARP. The six _x2 atomic draws are capability skips (77) on these adapters, as before.
  • compute_store_aot_descriptor_store_format_* can't run here as registered: this machine's clang has no AMDGPU target. I ran its controls and draws with the assembler round trip skipped, and both adapters had 0 mismatches and no debug-layer messages.

Status: ready to merge from our side. CI is green at 26604aa8, and every review finding is addressed or answered above.

@Jess-Doit

Copy link
Copy Markdown
Contributor Author

Merged main at e16fec3c in fa86d4c5. The only conflict was in the Python check lists in AGENTS.md and .github/workflows/windows.yml. Main added compute_alu_bcnt64_check.py where this PR adds compute_buffer_atomics_check.py, and both are kept. The translator merged without conflicts. The atomics controls and the LLVM 15 --binary check pass after the merge.

Status: ready to merge from our side. CI is green at fa86d4c5, the branch merges cleanly with main, and every review finding is addressed or answered above.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head fa86d4c59eb585d6a14b36a8a7ff9689a24db870 (Linux only; no Windows run by me, CI shows Windows build/test and fixture jobs passing on this head).

Checked: title is neutral, PR is not a draft, CI jobs "Build and test on Windows", "Assemble and translate gfx1013 fixtures" and "Run platform-independent Python checks on Linux" pass (the O2 and chart jobs were skipped).

Commands executed locally (worktree of the PR head):

  • python3 -B tests/compute_buffer_atomics_check.py -> gfx1013 atomic translation and serialization controls passed
  • python3 tests/docs_links_check.py -> self-test passed, 18 Markdown files, 399 links
  • python3 tests/bidi_controls_check.py -> no bidirectional controls in 1440 files
  • git diff --check origin/main...HEAD -> clean
  • Mutation 1: in tools/compute_store_aot.py swapped the cmpswap HLSL operand order (compare/replacement). The new check fails. Killed.
  • Mutation 2: in the plain DWORD store guard, changed cpu == "gfx1030" or not line.startswith(...) so gfx1030 no longer refuses a store after an atomic. The new check still passes. Survived (see P2).
  • All mutations reverted with git checkout -- ..

Semantics read against the RDNA 2 MUBUF atomic description: replacement in VDATA, compare in VDATA+1, old value returned in the first VDATA dword with glc, and HLSL InterlockedCompareExchange taking compare first. The lowering matches. The gfx1013 refusals (guarded programs, _x2, other ops, mixed idxen+offen, overlap with the fixed shared word) look sound, and the shared-add serialization oracle with a scramble control is a good test.

Findings:

  • P1: none.
  • P2 tools/compute_store_aot.py (store branch, if atomic_update and (cpu == "gfx1030" or not line.startswith("buffer_store_dword "))): the gfx1030 half of this condition is not guarded by the new suite. A change that lets gfx1030 write a UAV after its atomic passes compute_buffer_atomics_check.py. Please add one negative control for gfx1030 atomic followed by buffer_store_dword (or point to an existing test that covers it).
  • nit tools/compute_store_aot.py atomic branch: for non-glc gfx1013 atomics the data register is silently dropped from vector. That is documented in docs/experiments.md, and the umax_no_glc fixture exercises it. A one-line control that a later read of that register is refused would pin it down.

AI-assisted; commands listed were executed locally.

@Jess-Doit

Copy link
Copy Markdown
Contributor Author

Merged current main (681d01f5) at 4bf7f7ac to clear the conflict. tools/compute_store_aot.py keeps both linear_uav_address() and main's descriptor_load_hlsl(), and the workflow keeps both LLVM 15 entries. Re-run on Windows 10 19045 with the debug layer on (0 D3D12 warnings or errors): the buffer-atomics cases pass on GTX 1060 + WARP. The neighbouring mubuf_reduction_x2 cases skip (77, they need SM 6.6 Int64). The descriptor-store cases need the LLVM 15 assembler and pass with it. The descriptor-load hardware case hit the 120 s CTest limit on this GTX 1060 but passes directly in 115 s, and its HLSL is byte-identical to main. compute_store_check.py binary (LLVM 15), docs links, bidi and git diff --check also pass. The texture-case flag bits are unchanged.

Status: ready to merge from our side.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of head 4bf7f7ac66a0a1c0bb7eeb9b4bd16361a8597d19. This head is a merge of upstream main (681d01f) into the branch. I read the PR's own diff against main (9 files, +399/-22).

Verdict: no P1, no P2.

Commands run locally (Linux worktree at this head):

  • git diff --check origin/main...HEAD: clean.
  • python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 407 links.
  • python3 tests/bidi_controls_check.py: 1484 files, no bidirectional controls.
  • python3 tests/compute_buffer_atomics_check.py: "gfx1013 atomic translation and serialization controls passed".
  • gh pr checks 1684: Linux Python checks, gfx1013 fixture assembly and Windows build/test all pass. The /O2 job and chart publishing are skipped.

Mutations (each reverted with git checkout -- .):

  1. tools/compute_store_aot.py: changed the guard offset <= shared_atomic_offset to offset < shared_atomic_offset. The suite fails with Expected rejection: Return record can overlap the fixed atomic address. Killed.
  2. Swapped the cmpswap operand order in the emitted HLSL, {operands[1]}, {word} to {word}, {operands[1]}. The suite fails on the emitted HLSL. Killed.

Findings:

  • P1: none.
  • P2: none.
  • nit: the fixed-address atomic guard (Return record can overlap the fixed atomic address) relies on dword alignment, so a store at offset > shared_atomic_offset is at least 4 bytes past it. That holds, because the atomic and dword offsets are both multiples of 4. A one-line comment saying so would make it easier to maintain.
  • Checked and fine: gfx1013 is limited to unguarded raw-buffer programs. s_and_saveexec_b32 after an atomic is refused. Only 32-bit add, umax and cmpswap are accepted. The cmpswap order matches the ISA (replacement in VDATA, compare in VDATA+1). Without GLC the source register is invalidated rather than given a made-up old value. The per-thread address helper linear_uav_address requires every group axis to be separated.
  • Not run: python3 $P win2025. The merge only brought in unrelated upstream changes, and the Windows CI job covering the D3D12 readback check is green on this head.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@Jess-Doit could you rebase this branch onto current main and force-push?

GitHub reports head 4bf7f7ac as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (4aaea119):

  • tools/compute_store_aot.py

Commands run locally:

git fetch origin main pull/1684/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1684 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

@Jess-Doit
Jess-Doit force-pushed the shader/compute-buffer-atomics branch from 4bf7f7a to 809b422 Compare November 25, 2026 17:08
@Jess-Doit

Copy link
Copy Markdown
Contributor Author

@tedin7 thanks. Rebased onto current main (7092683a) as one commit and force-pushed: head is now 809b422a.

The conflict was in tools/compute_store_aot.py. main added the heap store view branch, and this PR adds the linear address used by the atomics.

  • Both are kept.
  • The linear address is computed only when no heap store view is declared, so the heap path behaves exactly as on main.

Tests on Windows 10 build 19045, dev preset, GTX 1060 6GB (driver 32.0.15.6094) and in-box WARP 10.0.19041.

  • compute_store_aot_(gfx1013_buffer_atomics|mubuf_reduction|gfx1013_image_uav_load)_ and startup_compute_buffer_atomics: 11 of 11, including 2 capability skips for the _x2 reduction variants.
  • Pure-Python: compute_buffer_atomics_check, compute_heap_store_check, compute_heap_view_check, compute_load_format_check, form_coverage_check and compute_desc_numeric_check controls pass.

A note on scope: #2331 and #2382 lowered buffer atomics in tools/startup/gfx2hlsl.py, the startup translator. This PR covers the separate offline compute translator, tools/compute_store_aot.py, so the two don't overlap.

Ready to merge from our side.

@Jess-Doit
Jess-Doit force-pushed the shader/compute-buffer-atomics branch from 809b422 to 3cff259 Compare November 25, 2026 20:40
@Jess-Doit

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (5123cc6d) as one commit and force-pushed: head is now 3cff259e.

The conflict was in tools/compute_store_aot.py, with #2511's finite-normal fmin/fmax buffer atomics, which landed in the same atomic block.

  • shader: lower finite-normal raw buffer floating-point min and max atomics #2511 still reads m[1]..m[7]. This PR moved that regex to named groups, so its checks now use op, wide and glc.
  • The fmin/fmax domain check now sits in the non-gfx1013 branch next to the csub and glc checks. gfx1013 keeps its own allowlist (32-bit add, umax, cmpswap), so a float atomic there still gets the gfx1013 refusal. That is what this PR's control expects.
  • buffer_float_update = False and shared_atomic_offset = None are both kept.

Tests, run on Windows 10 19045 with GTX 1060 + WARP:

  • ctest -R atomic: 21 passed and 1 capability skip (bvh_atomics_warp), 0 failed.
  • compute_buffer_atomics_check.py, startup_compute_buffer_atomics_check.py and rdna2_tools_check.py pass.

Ready to merge from our side.

Lowers 32-bit MUBUF buffer_atomic_add, umax and cmpswap in the gfx1013
compute translator to InterlockedAdd, InterlockedMax and
InterlockedCompareExchange on the raw UAV, one atomic per program, and
refuses every other 32-bit MUBUF atomic. The LLVM 15 words are recorded
for the fixtures, and the width gate is pinned with defined 64-bit data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Jess-Doit
Jess-Doit force-pushed the shader/compute-buffer-atomics branch from 3cff259 to 373f7a7 Compare November 25, 2026 21:18
@Jess-Doit

Copy link
Copy Markdown
Contributor Author

Fixed the failed Assemble and translate gfx1013 fixtures job: head is now 373f7a7a.

Cause: #2511's mubuf_float_controls runs a buffer_atomic_fmin/fmax program with cpu="gfx1013" and expects Unsupported atomic reduction target or binding. On this branch the gfx1013 op allowlist refused it first, with a message that lacked that prefix. That control only runs in the LLVM 15 --binary mode, which I couldn't run locally.

Fix: the gfx1013 allowlist refusal now starts with Unsupported atomic reduction target or binding:. That matches the other gfx1013 refusal in this block, and the PR's own control still matches require 32-bit add, umax or cmpswap. Nothing else changed.

Checks:

  • All 52 zero-argument *_controls functions in tests/compute_store_check.py pass, mubuf_float_controls included.
  • compute_buffer_atomics_check.py and startup_compute_buffer_atomics_check.py pass.

Ready for more review.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of head 27e8b22 (main merged into the PR) against current main. No blocking issues found.

What I checked:

  • tools/compute_store_aot.py: the gfx1013 raw UAV path now accepts 32-bit buffer_atomic_add, umax and cmpswap with off, offen and idxen addressing. 64-bit forms and other opcodes are refused with a clear error. The cmpswap data range uses VDATA and VDATA+1.
  • Overlap: #2331 (merged) lowers buffer atomics in tools/startup/gfx2hlsl.py. This PR works in a different tool (compute_store_aot.py), and #2511's float min/max atomic block is kept intact (the op allowlist still reaches its expected error text).
  • Tests: tests/compute_buffer_atomics_check.py pins machine words against the assembler, the emitted HLSL argument order, and the translation refusals. The --draw mode is a real D3D12 readback of the raw UAV, registered as compute_store_aot_gfx1013_buffer_atomics_<adapter> in CTest. The workflow and AGENTS.md check lists are extended in both places.
  • Care item .github/workflows/windows.yml: the only change is one extra Python check entry (LLVM 15 binaries) next to its siblings. The PR's own CI run on this head exercises it.
  • This PR does not claim to advance game startup.

Commands run (Linux, clean worktree at this head). This machine has LLVM 19 only, so I ran the check with llvm-mc-19/llvm-objcopy-19 instead of LLVM 15:

  • python3 -B tests/compute_buffer_atomics_check.py --binary llvm-mc-19 llvm-objcopy-19 --llvm libLLVM.so.1: all cases OK
  • python3 tests/docs_links_check.py: OK
  • python3 tests/bidi_controls_check.py: OK
  • git diff --check origin/main...HEAD: clean
  • Mutation 1: drop umax from the gfx1013 allowlist: the check fails.
  • Mutation 2: map cmpswap to InterlockedExchange: the check fails.

Not covered here: the D3D12 draw readback and the LLVM 15 run (Win2025 and CI follow separately).

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Win2025 WARP receipt for head 27e8b22 after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 27e8b22a6c5ff46eb80426991d2fc28b2a652512:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 6.20s (configure 2.09s)
    • Test (ctest --preset dev -R 'gfx1013_buffer_atomics|compute_store_aot_mubuf_reduction' --parallel 4 --no-tests=error --output-on-failure): 6/6 passed (11.42s: compute_store_aot_mubuf_reduction_x2_hardware 4.58s, compute_store_aot_mubuf_reduction_hardware 4.75s, compute_store_aot_mubuf_reduction_warp 5.27s, compute_store_aot_mubuf_reduction_x2_warp 5.83s, compute_store_aot_gfx1013_buffer_atomics_hardware 6.27s, compute_store_aot_gfx1013_buffer_atomics_warp 6.48s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 25.05s (configure 2.58s)
    • Test (ctest --preset release -R 'gfx1013_buffer_atomics|compute_store_aot_mubuf_reduction' --parallel 4 --no-tests=error --output-on-failure): 6/6 passed (10.05s: compute_store_aot_mubuf_reduction_x2_hardware 8.07s, compute_store_aot_mubuf_reduction_warp 8.07s, compute_store_aot_mubuf_reduction_x2_warp 8.12s, compute_store_aot_mubuf_reduction_hardware 8.14s, compute_store_aot_gfx1013_buffer_atomics_hardware 1.43s, compute_store_aot_gfx1013_buffer_atomics_warp 1.42s)
  • Windows Python checks: tests/compute_buffer_atomics_check.py ok (0.6s), tests/compute_entry_layout_check.py ok (0.2s)
  • sccache: 168/224 hits; wall 56.0s

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit 8f045ae into R0Y00:main Nov 25, 2026
5 checks passed
@ChazY11

ChazY11 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Post-merge audit of 8f045aee: seven mutations of the DWORD buffer atomics, all caught

Reading this as a coverage statement about main, not a review request.

python -B tests/startup_compute_buffer_atomics_check.py
    buffer_atomic controls (11 ops, scalar byte offset, glc/non-glc, alignment, modifiers,
    descriptors, refusals) passed

Eleven ops with the scalar-offset, glc/non-glc, alignment, modifier and descriptor dimensions crossed is the right shape
for a table-driven lowering: the table is where a wrong entry hides, so the fixture walks the table.

mutation caught
buffer_atomic_smin loses signed (Min, True → Min, False) caught
buffer_atomic_sub stops negating (is_sub True → False) caught
cmpswap with glc: compare/replace swapped (words[1], words[0] → words[0], words[1]) caught
cmpswap without glc: same swap in InterlockedCompareStore caught
cmpswap data VGPR count 2 → 1 caught
InterlockedExchange loses its output operand caught
the compute-stage restriction removed (if self.kind != 'cs': raise) caught

The two cmpswap swaps matter most: RDNA 2 puts the replacement in vdata[0] and the compare in vdata[1],
while HLSL takes compare first. Getting that backwards compiles and runs, and silently stores the wrong value — the
fixture catches both the glc and the non-glc form, which are different HLSL intrinsics.

The InterlockedExchange one is a nice second-order guard: the comment says HLSL's form always requires an output
operand, so dropping ao is a compile error rather than a logic error — but the fixture still catches it, meaning it
compares the emitted call text rather than only whether translation succeeded.

A correction about my own run, since it changes what the numbers mean

My first pass used tests/compute_buffer_atomics_check.py and reported five survivors. That is a different,
pre-existing
fixture, registered with --draw <dxc> against the desktop device — it exited 0 on the no-argument run
for its own reasons and never touched the paths I mutated. The file this PR adds is
tests/startup_compute_buffer_atomics_check.py. Re-run against it, all seven are caught as shown above.

Two near-identical filenames in one directory is the trap; I should have matched the name from the PR's own file list
rather than from a Select-String for buffer_atomic. Recording it here because a "survived" list from the wrong
fixture reads exactly like a coverage gap.

AI-assisted; pure Python, Windows 11 build 26300, no DXC or GPU for the rows above.

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