Repository navigation
Conversation
The hardware hands out an ordered-append counter in wavefront launch order. Compute waves now wait for a turn dword kept past the 64 KiB GDS to reach their launch index (flattened workgroup ID times waves per workgroup plus the wave index), perform the add or swap, and pass the turn on when the wave-done bit is set; the last wave of a dispatch resets it. The wait is bounded so a wave that never issues a done operation cannot hang the device. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A wave now passes the turn on with a compare-exchange from its launch index, so a wave that gave up waiting adds unordered and leaves the turn alone. The driver zeroes the turn in the buffer each dispatch binds, before the dispatch and each chunk of a split one, instead of relying on the last wave. Waves that give up are counted in a dword after the turn. The wait, the add and the release now run inside the loop, one lane per guest wave, so guest waves sharing a host subgroup no longer wait on each other until the timeout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The compiled program now records whether it orders GDS appends, and the driver resets the turn only for those, behind a compute-to-transfer barrier instead of draining all prior work. A GDS copy the CPU made is no longer zeroed at record time. The first wave that gives up waiting marks the turn abandoned, so the rest of the dispatch runs unordered at once instead of each later wave waiting a full budget. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d-append Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d-append The shared GDS mapping from boykopovar#13159 takes GdsBindingBytes, as its import check does, so the ordered-append turn and timeout count past the 64 KiB GDS stay mapped; disk cache format 52 follows main's 51. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ordinary GDS accesses are bounded by the guest GDS again: the binding holds RuntimeAbi::GdsMetadataDwords more, which only the ordering helper reaches. A CPU-made copy that holds the turn is created fillable, so the turn is reset on the GPU before each dispatch and chunk whatever backs the GDS; an image mirror holding it throws. The debt entry keeps its encoding sources, with the ordering model as its own entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d-append orderedAppend sits beside the artifact's other flags, so main's encoder size assertions stay as they are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d case Vulkan does not guarantee that workgroups start in WorkgroupId order. On AMD's Windows driver row 0 of a 1 x 65535 dispatch started after most of the dispatch, so its wait could only end unordered. The split case now reports that as a skip with the values it saw; a row 0 that is served early but not first still fails. The ordering debt entry names the assumption and says that chunks are ordered by the barrier between them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…first row When row 0 is served late, only the row 0 value and the unordered count depend on when waves start. The skipped row, the second chunk's launch order after its reset and the final counter are checked as on any driver, and the skip is named in the test's success line. The debt entry words the AMD Windows report as an observation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bumps ShaderDiskCache FormatVersion to 53. Main landed boykopovar#10000 with format 52, which this branch also used for its own cache format change; both sides set the same line, so the merge kept 52 silently, and caches written by main would load under this format.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main moved the shader disk cache to format 56; this branch's ordered-append field moves it to 57. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main moved the shader disk cache to format 60; this branch's ordered-append field moves it to 61. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main moved the shader disk cache to format 68; this branch's ordered-append field moves it to 69. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… 64 KiB units The ordered-append metadata made the GDS binding 0x10008 bytes, and the shared memory file and its host import used that size. The import's last page then ran past the end of the file, which loses the device on Mesa ANV and fails the shared-memory alias check on Windows. The allocation and the import now cover GdsBindingBytes rounded up to 64 KiB; shaders still bind GdsBindingBytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main reached shader disk cache format 69, the number this branch had, so the ordered-append field moves to 70. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve conflicts: keep both SpirvEmitter fields (orderedAppend, anySubgroupSize), keep main's atomicLockTable setup with the PR's GdsAllocationBytes host import, and move the shader cache FormatVersion to 92 above main's 90.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Background. On AMD GCN/RDNA GPUs, GDS (global data share) is a small on-chip memory shared by all waves of a dispatch.
ds_ordered_countis a GDS instruction that adds to, or swaps, a counter in GDS and returns the old value. Unlike an ordinary atomic, the hardware serves the waves in wavefront launch order: the first-launched wave gets the first value, the next wave the next, and so on. Shaders use it to give each wave a contiguous, ordered slice of an output buffer (stream compaction, particle lists, culling output). Because the order is guaranteed, the result is deterministic and the slices never overlap.The bug.
ds_ordered_count(ordered append on GDS) ran as a plain device atomic, so the waves of a dispatch added in whatever order the host ran them. The hardware hands the counter out in wavefront launch order. radeonsi'ssi_compute_prim_discard.c(mesa-20.3.0) describes it as "an atomic counter that is incremented in the wavefront launch order", withORDER_MODE 0launching in order. A title that turns the returned values into output offsets therefore got overlapping or shifted ranges, intermittently.In compute shaders the ordered add and swap now run in launch order:
RuntimeAbi::GdsMetadataDwords), the turn and a timeout count (Pm4::GdsBindingBytes). Ordinary GDS accesses stay bounded at 64 KiB; only the ordering code reaches the two dwords. The wait, the add and the release run inside one loop, so guest waves that share a host subgroup (wave32 code in a 64-lane subgroup) do not wait on each other.offset1bit 1 (wave done) is set, compare-exchanges the turn from its own index to the next (0 after the dispatch's last wave). Only the wave that holds the turn moves it.orderedAppend, disk cache format 70). For those programs only, the driver zeroes the turn in the buffer the dispatch binds, before the dispatch and before each chunk of a split one. It uses aCOMPUTE_SHADER→TRANSFERbarrier, a 4-bytevkCmdFillBuffer, thenTRANSFER→COMPUTE_SHADER. A GDS copy the CPU made is created fillable, so it is reset the same way. Each chunk counts its own waves.main), marks the turn abandoned so the rest of the dispatch runs unordered at once, and adds 1 to the timeout count, which the test checks. With one wave that never takes its turn, a 65536-group dispatch takes about 350 ms; without the mark it lost the device after 2 s.The wait relies on waves being launched in workgroup order and on earlier waves running while later ones spin. AMD hardware does this, but Vulkan does not guarantee it. This is recorded in
docs/dev/debt/shader.md, which now describes the new behaviour in place of "not modeled".Tested
Ubuntu 26.04.1 (Linux 7.0.0-38), GCC 15.2.0, Release, RX 9060 XT (RADV GFX1200, Mesa 26.0.8-1ubuntu0.3). Based on
main6d56eb8 (merged into the branch on Oct 30).agc_driver_gds_append_consume, each checking every lane's value, the counter and a timeout count of 0:ds_ordered_count: group 0 gets the start value, groups 2–3 time out and get the remaining values, and exactly 2 timeouts are counted.mainbb04a4f (with only this test file added) it fails: "64 single-wave groups, dispatch 1, ds_ordered_count: group 0 lane 0 returned 1025, expected 1000 (the counter in launch order)".ds_ordered_count), inagc_driver_gds_append_consumeand_copied. The RX 9060 XT on RADV reportsmaxComputeWorkGroupCount[1] = 65535, so the case takes the split path here: 2 chunks, row 0 gets the start value, 65533 waves of the first chunk run unordered, and the second chunk and the dispatch after it are ordered. It passes 3 of 3 in both registrations, with 0VUID-messages.WorkgroupIdorder. For a row 0 served that late, the case skips only the row 0 value and the unordered count, and names the skip in its success line; the skipped row, the second chunk's order after its reset and the final counter are still checked. A row 0 served early but not first still fails. The debt entry names the assumption.ctest -R '^agc_|^shader_|recompiler' -j4on this branch: 1130 of 1132 pass. The 2 failures,agc_idle_publish_waitandagc_driver_native_multisample_depth, also fail onmainon this machine (the second because a host import getsvkAllocateMemory-13 here).ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest -V -R gds_appendon the same machine and GPU, onmainbb04a4f and on this branch.VUID-messages.mainthe test fails only on the new case, as intended.mainstops at startup in this title (sceHttp2SetResolveRetry not implemented), so this ran on my local integration build (mainplus local branches) with and without this PR.0x1038fb8200) intermittently produced overlapping particle records, drawn as long streaks. That was 1–9 corrupted frames per 8-minute run; with the change, 0 in 3 runs (Oct 23, first version of this PR).tools/trace_digest.py,APS5_TRACE_SECONDS=200:60, order without, with, with, without:gpu_busy_ms_per_present148.5 / 128.9 / 128.6 / 151.9. This metric spans each batch from its first to its last command, idle gaps included, so it is not shader time. I have not attributed the change to a phase.main. That was wrong: those were runs of the integration build against a baseline from another day.python3 tools/check_conventions.py --base origin/main: all conventions checks passed.tools/pr_overlap.py --branch fix/recompiler-ordered-append: no open PR changesds_ordered_count. The overlaps are on shared files only:Graphics/src/ShaderResources.cpp,SpirvMemoryInstructions.cpp,SpirvEmitterHelpers.cpp,Execution/src/Pm4.cppanddocs/dev/debt/shader.md(e.g. feat(agc): serve lane-keyed, pointer and runtime image-table columns boykopovar/AnyPS5#10193, feat(agc): test the depth bounds in the pixel program when the device lacks the depthBounds feature boykopovar/AnyPS5#11551, fix(agc): span table-reading wave64 programs by default on Intel drivers that share handles across fused threads boykopovar/AnyPS5#10846).Progress
PPSA08329 on this machine (RX 9060 XT, RADV), on
mainwith this change and other local, unrelated fixes; this PR depends on none of them. Bring-up thread: boykopovar#12128.0x1038fb8200writes throughds_ordered_countslots, and serving those slots in launch order removed every streak.gpu_busy_ms_per_present: 148.5 / 151.9 without, 128.9 / 128.6 with.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code