compute: lower group-shared LDS and s_barrier on gfx1013 #1559
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1566"
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 archielcqp-a11y on 2026-11-24T14:14:11Z.
Refs #1541
Summary
compute_store_aothad only the gfx1030 private-LDS profile, so every gfx1013 DS instruction ands_barrierwas refused. With--cpu gfx1013 --lds-bytes N, LDS is nowgroupshared uint lds[N / 4], shared by the whole group. N must be a multiple of 4 and at most 32 KiB.Accepted:
ds_write_b32/ds_read_b32,_b64and_b128;ds_write2/ds_read2and theirst64forms, at b32 and b64;ds_add_u32,ds_sub_u32,ds_and_b32,ds_or_b32,ds_xor_b32,ds_min_u32andds_max_u32, asInterlocked*operations;s_barrier.An address comes from
v_lshlrev_b32on a local-ID VGPR (local << k) and the existing integer ALU subset.One guest wave per group:
--wave-size 64, the caller's statement that the program runs as wave64. That value is accepted only together with a gfx1013 shared LDS allocation; elsewhere it is still refused.--wave-size 32, are several guest waves and are refused.Ordering: every DS instruction is followed by
GroupMemoryBarrierWithGroupSync(). Within the one guest wave, DS operations therefore take effect in program order: a read sees all earlier writes, and a later write cannot overtake an earlier read. This holds even when the desktop runs the group as several host waves. With several guest waves, the same barriers would also order DS operations between waves befores_barrier, which the guest program does not guarantee. That case is left for a later change with its own native comparison.s_barrierlowers to the same barrier. Barriers need uniform control flow, so DS after a lane guard is refused.Input contract: the caller guarantees it, and it is not checked:
Outside the contract, each access is still guarded by
index < N / 4: a word past the allocation reads as zero and is not written, and the low two address bits are dropped. That rule keeps an access from reaching other words; it has not been compared with hardware.Not in this PR:
_rtnforms, whose results depend on the order in which lanes update one word;ds_permute/ds_bpermuteon gfx1013;Without
--lds-bytes, gfx1013 behaviour is unchanged.Fixture
compute_store_aot_lds_shared_{warp,hardware}runs eight 64-thread wave64 programs with a 1024-byte allocation, on one and two groups (one group for the four-word programs). Every UAV word is compared with a CPU reference:shared_exchangeds_write_b32,ds_read_b32,s_barriershared_pair_b32/shared_pair_st64_b32write2/read2,write2st64/read2st64(b32)shared_b64ds_write_b64,ds_read_b64shared_pair_b64/shared_pair_st64_b64write2_b64thenread2st64_b64, and the reverseshared_b128ds_write_b128,ds_read_b128shared_atomicsWith two groups, each group's counters cover only its own threads, so each group has its own LDS.
Negative controls: three assembly mutations must mismatch at the first word they change:
st64read spelled as a plainread2, at word 1;ds_min_u32in place ofds_max_u32, at word 11.Translation controls:
Interlocked*methods, and the< N / 4uguard on every LDS access;_rtn, b96, b8, signed min, offsets above 65535, equal pair offsets, local-ID data, register-range mismatches, DS after a lane guard, a missings_waitcnt, invalid allocations;s_barrier.Binary mode: the programs are assembled and disassembled with LLVM 15 for gfx1013, and the CLI, given the same options including
--wave-size 64, must emit the same HLSL.Results
Run on
b96960b(main) plus this branch atd28d85e, Windows 10 build 19045, debug layer enabled.tests/compute_store_check.py draw-lds-sharedcompute_store_check.pydraw modeOther checks:
tests/compute_store_check.py binarywith LLVM 15: pass.form_coverage_check,docs_links_check,bidi_controls_checkandshader_census_check: pass.No capability skips.
Coverage: of the gfx1013 forms, the test adds only
s_barrier, because the gfx1030 private-LDS fixtures already record the DS mnemonics.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T14:23:30Z.
Review: CHANGES_REQUESTED
The new branch accepts any valid group dimensions. A barrier after every DS instruction converts wave-local ordering into group-wide ordering, so a shader with multiple guest waves and a cross-wave atomic before s_barrier can observe an outcome the original scheduling did not guarantee. Scope this first slice to one guest wave with an explicit wave-width contract, or establish the multi-wave contract with an independent native comparison. Please also state the LDS input contract: in-bounds aligned accesses, each read and atomic word initialized, and no overlapping non-atomic writes within one instruction. Add a rejected multi-wave case for the narrow profile and retain the current two-workgroup isolation control. The HLSL barrier waits for the whole group: https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/groupmemorybarrierwithgroupsync
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T14:28:45Z.
Review: COMMENTED
Dual-platform peer review of PR #1566 (
f0c0a611f494098d2d69404027462e1e172b65f5).Code & Hygiene Audit
--cpu gfx1013 --lds-bytes Ngroup-shared LDS lowering (groupshared uint lds[N / 4]) ands_barrierintools/compute_store_aot.py. Merges cleanly againstorigin/main.4 <= lds_bytes <= 32768andlds_bytes % 4 == 0; without--lds-bytes,gfx1013continues to refuse DS instructions ands_barrier.ds_*access is bounds-checked (index < words) and followed byGroupMemoryBarrierWithGroupSync(), withs_barrierdeduplicated when immediately preceded by a DS barrier.ds_*ands_barrierare rejected under active lane guards (guard_span is not None or guard is not None), andds_sub_u32lowers toInterlockedAdd(lds[...], (0u - value)).ds_read2/ds_write2andst64forms scale offsets bycountandcount * 64words respectively, and reject out-of-range (> 255) or equal offsets (offset0 == offset1).shared_controls()andshared_draw()verify barrier counts,Interlocked*methods, 3 assembly mutations (first mismatched word), and 14 rejection cases.Verification
git diff --check origin/main..HEAD: passedpython3 tests/docs_links_check.py: passed (16 Markdown files, 344 links)python3 tests/bidi_controls_check.py: passed (1247 tracked files)python3 -B tests/compute_store_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so: passedpython3 -B tests/shader_census_check.py: passed (7 tests)f0c0a611f494098d2d69404027462e1e172b65f5:tests/form_coverage_check.pypassed (43.13s)--preset dev):cmake --build --preset dev --target offscreen_check -- -j 6succeeded;ctest --preset dev -R '^compute_store_aot_lds_shared_' --parallel 4 --no-tests=error --output-on-failure— 2/2 passed (compute_store_aot_lds_shared_warp,compute_store_aot_lds_shared_hardware; note: this VM only has WARP)/O2(--preset release):cmake --build --preset release --target offscreen_check -- -j 6succeeded;ctest --preset release -R '^compute_store_aot_lds_shared_' --parallel 4 --no-tests=error --output-on-failure— 2/2 passed (same 2 tests)Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-24T16:15:45Z.
Independent GPU validation
Measured
f0c0a611merged onto main (my mergef368f9e8, tree33257a6b, working tree clean). Nothing below is a code change.Environment
10.0.26100.0user-mode)AMD Radeon RX 9070 XT vendor=1002 device=7550, driver32.0.32029.2010Microsoft Basic Render Driver vendor=1414 device=008c, driver10.0.26100.9818dev(Debug),debug_layer=unavailableCommands
Observed
Two entries, three runs each: 6 passed, 0 failed, 0 skipped.
On the physical adapter the eight programs give 13 runs: five programs run at both group counts and three at the single-group count only, so eight runs report
groups=1and five reportgroups=2. Each reports:WARP reports the same 13 runs with
mismatches=0. So the cross-lane exchange, thewrite2/read2pairs in both the raw andst64forms, the qword and 128-bit programs and the atomic program all reproduce the CPU reference on this adapter, with no divergence between the two backends tested.Regression
^compute_store_aot_lds: 18 passed, 0 failed, 0 skipped.Limits
0x887a002d, SDK component missing), so the run says nothing about D3D12 API validation — only that the readbacks match.gfx1201(RDNA 4), not thegfx1013target. This run covers the translated HLSL executing on a different ISA from the one the source assembly belongs to; it says nothing about gfx1013 hardware itself.offset:65536form only appears as a lowering rejection. So it remains unmeasured against hardware after this run as well.AI-assisted; runs executed locally on the adapter above.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-24T16:22:26Z.
Correction to my run above, after reading the review of 14:23: it does not establish the multi-wave contract, and should not be read as doing so.
So the vertical slice the review describes is untouched by my measurement. When the narrow profile rejects the multi-wave case, the single-wave configuration is the native one on this adapter and I will re-run it there.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:35:05Z.
Review: COMMENTED
Audit at
head_sha:f0c0a611f494098d2d69404027462e1e172b65f5(this follows my earlier comment on the same head and adds the semantic audit and the mutation results it lacked).Verdict: 0 P1, 0 P2. One nit (P3).
Scope
CMakeLists.txt(oneadd_test, test only),docs/experiments.md,tests/compute_store_check.py,tools/compute_store_aot.py. Nosrc/, nogfx2hlsl, no.github/.git merge-treeagainst currentmain(68969ed8): no conflicts.cpu == "gfx1013" and lds_bytes != 0. The existing private-LDS path needsds_group = cpu == "gfx1030" and dims == (32, 1, 1), so no existing gfx1030 program changes, andlds_bytes == 0is untouched. The allocation must be a multiple of 4 between 4 and 32768 bytes.RDNA 2 semantics
word = (address + offset) >> 2. Single forms useoffset:in bytes (up to 65535);read2/write2useoffset0/offset1in elements of the access size (so wordsoffset * count),st64times 64; equal offsets and offsets above 255 are refused. I checked the element scaling againstllvm-mc-19 -mcpu=gfx1013:ds_write2_b32 ... offset0:1 offset1:3,ds_read2st64_b64 ... offset0:1 offset1:2,ds_write_b128 ... offset:16and the others all assemble to the encodings the lowering assumes.add/sub/and/or/xor/min/max_u32becomeInterlocked*onlds[](subas add of0u - value); each is order-independent within one instruction, so lane order does not matter. Returning forms (_rtn) are not matched and stay refused.GroupMemoryBarrierWithGroupSync(), which is stronger than the one-wave program order the guest relies on, ands_barrierbecomes the same barrier (merged when a DS barrier is already last). A lane guard before a DS instruction ors_barrieris refused, because the barrier needs uniform control flow.Findings
index < wordstoindex <= words: the Linux controls still pass, and the Windows fixtures cannot reach that word. The docs state the rule, so it would be good to have one fixture or control that reads and writes just past the end.Verified
Limits: Linux x86-64 only. No Windows/D3D12/DXC:
compute_store_aot_lds_shared_*(draw, WARP and hardware) was not run for this head.PYTHONPATH=tests:tools python3 -B -c "import compute_store_check as c; c.controls(); c.shared_controls()"-> OK.python3 -B tests/docs_links_check.py-> 16 files, 344 links OK.git diff --check HEAD^ HEADclean.ds_sub_u32without the negation (AssertionError); the barrier dropped after a DS step (AssertionError: shared_exchange);xor_b32mapped toOr(AssertionError: Xor). Also detected: the lane-guard refusal removed (Expected rejection: Shared LDS access under a lane guard).st64scale 64 -> 32 (guarded by the Windows fixturesshared_pair_st64_b32/_b64, which useoffset1:1, but not run here), and the out-of-range read bound above (not guarded anywhere).git checkout -- .;git status --shortclean.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by archielcqp-a11y on 2026-11-24T23:27:33Z.
@R0Y00 thanks. Addressed in
d28d85ea. I took the first option: this slice is now one guest wave per group, with an explicit wave width.One-wave profile:
--wave-size 64. That value is new, and it is accepted only together with a gfx1013 shared LDS allocation. Everywhere else it is still refused as "Unsupported wave size statement", so the existing readlane and mbcnt controls are unchanged.--wave-size 32, are several guest waves. They are refused with "Shared LDS requires a group of one guest wave".Within one guest wave, the per-instruction
GroupMemoryBarrierWithGroupSync()reproduces the guest's DS program order, even when the desktop runs the group as several host waves (WARP runs the fixture as two 32-wide waves). The multi-wave contract is left for a later change with its own native comparison.Input contract: now in the
shared_lds_stepdocstring and indocs/experiments.md. It is the caller's guarantee and is not checked:Outside the contract, the
index < N / 4guard still keeps an access from reaching other words. The docs no longer present that rule as defined behaviour.Controls:
@tedin7, on the out-of-range nit: in-bounds accesses are now part of the contract, so I didn't add a fixture past the end. A new control requires the
< N / 4uguard on every LDS access in every program. It catches<=in both the read and the write guard.Mutation check of the new controls:
<=<=Results: run on
b96960b(main) plus this branch, Windows 10 build 19045, debug layer enabled.tests/compute_store_check.py draw-lds-sharedcompute_store_check.pydraw modeOther checks:
compute_store_check.py binarywith LLVM 15, which passes--wave-size 64through the CLI: pass.form_coverage_check,docs_links_check,bidi_controls_checkandshader_census_check: pass.No capability skips.
@thepatrickworld, on wave64 hardware the 64-thread fixture is now the stated single-wave configuration, if you want to re-run it.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T00:51:51Z.
Independent measurement on AMD
Measured
d28d85eamerged ontomain(5a0b0aad), mergeacfdba45. Nothing below is a code change; the tree carries only the four files of this branch.Environment
10.0.26100.0user-mode)1002:7550, driver32.0.32029.201010.0.26100.9818; the debug layer is unavailable in this session, so the runs are without itResults
compute_store_aot_lds_shared_*Two consecutive runs, same outcome. Across the run the fixture prints 26 comparison lines and every one is
mismatches=0; none reports otherwise. That includes the two-workgroup isolation case, which printsgroups=2 compared_words=320 mismatches=0, and the single-group case at the same word count.The whole
^compute_store_aot_lds_family is 18/18 green here, so the private, packed, arithmetic, replacement and strided slices are unaffected on this adapter by the new profile.What this covers, and what it does not. It is the AMD half of the new one-wave profile: the 32-thread group without a statement, the 33-to-64 groups under
--wave-size 64, and the refusal cases the fixtures exercise. It says nothing about Maxwell, Turing or the RTX 3080 run in the description, since no NVIDIA adapter is available on this machine, and WARP is the reference this comparison is made against rather than an independent implementation of the guest ordering. The multi-wave contract stays untested by choice, as stated above.AI-assisted; runs executed on the machine above.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:44:07Z.
@archielcqp-a11y could you rebase this branch onto current
mainand force-push?GitHub reports head
d28d85eaas conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(b1a644ae):tools/compute_store_aot.pyCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T04:01:08Z.
Review: COMMENTED
@R0Y00's requested change (one guest wave plus an explicit wave-width contract, rejected multi-wave case, retained two-workgroup isolation control) was already implemented by the author in
d28d85ea. The PR was only blocked by a merge conflict withmain, so I mergedorigin/maininto the branch (plain merge, no rebase, no force) asbb96c631.What changed in the merge:
tools/compute_store_aot.py(argparse block near line 3439). Kept both sides: main's--buffer-float-domainand--gather-mips, and this PR's--wave-sizewith choices(32, 64).Commands executed locally:
git merge origin/main(one conflict, resolved as above);python3 -m py_compile tools/compute_store_aot.py;git diff --check origin/main..HEAD: cleanx2w_pipe.py win2025 1566 --patch <merge diff> --regex 'compute_store_aot.*_warp': 87/87 passed, includingcompute_store_aot_lds_shared_warp--regex compute_store_aotalso showedcompute_store_aot_mac_f32_hardwarefailing on the VM ("fused mad() instead of unfused multiply+add escaped detection"). That is a hardware-backend test of an unrelated fixture that this merge does not touch; the_warpsuites are green.@R0Y00 could you re-review? @archielcqp-a11y thanks, feel free to adjust.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T04:32:52Z.
Review: APPROVED
The current head retains the one-guest-wave contract and explicit width, refuses multi-wave groups, and keeps the two-workgroup isolation comparison. I ran compute_store_check.py controls plus shared_controls and draw-lds-shared on WARP and RTX 4060 Laptop with the Release offscreen harness. All reference outputs matched, and all three negative mutations produced their expected first mismatch on each backend. The merge tree preserves both CLI option groups. This resolves my prior wave-size review.