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>
|
@ZSWolt thanks, this is a good approach (the radeonsi-style turn past the GDS range, per-chunk reset for split dispatches, graphics left unordered, and a bounded wait so nothing can hang). One problem in the timeout path needs fixing before it can land: A wave that gives up waiting still moves the turn. The wait loop leaves on Please:
The debt entry already says that in-order launch and progress are assumed and that Vulkan doesn't guarantee them, which is right; please add what happens on a timeout after the fix. We'll run it on an RTX 4090 when it's updated (the |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
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>
|
@oneandonlydean thanks, all five points are addressed in the new commit on top (no force-push).
A second bug the multi-wave test found. When the host subgroup is wider than the guest wave (wave32 code in a 64-lane subgroup on RADV), two guest waves shared one wait loop. The first could not leave the loop to release until the second stopped waiting, so the second always timed out (29 timeouts in that test). The wait, the add and the release now run inside the loop, done by one lane per guest wave, so guest waves in one host subgroup no longer wait on each other. Checks (RX 9060 XT, RADV):
A run on the RTX 4090 would be welcome. The delayed and multi-wave cases are the ones that depend on the host's subgroup layout. 🤖 Addressed by Claude Code |
CnRJay
left a comment
There was a problem hiding this comment.
The ordering fix is sound, and oneandonlydean's timeout points are addressed. One cost in recordDispatch is not covered yet and applies to every dispatch that binds the GDS, not just ordered ones.
The reset is gated on bindsGds, not on orderedAppend. bindsGds is true for any shader with a DescriptorRole::Gds binding, which includes plain append/consume and any other GDS user. Those shaders never read the turn dword, but they now get:
vkCmdPipelineBarrierALL_COMMANDS→TRANSFERvkCmdFillBufferof 4 bytesvkCmdPipelineBarrierTRANSFER→COMPUTE_SHADER
ALL_COMMANDS as the source stage drains everything recorded before it: preceding draws, other dispatches and copies. Each such dispatch also becomes a hard sync point, so it can't overlap the work before it. The same is added before each chunk of a split dispatch. A title that issues many small GDS dispatches per frame (particle and culling passes are the typical case) pays a GPU drain for each one.
Carry the orderedAppend requirement into the compiled program, or the binding info, and reset only for programs that contain DataOrderedCount or DataOrderedSwap in a compute stage. Shaders that don't order then get exactly what main gives them.
The first barrier is wider than it needs to be. The only prior writer of the turn dword is an earlier ordered dispatch. A COMPUTE_SHADER → TRANSFER barrier with SHADER_WRITE|SHADER_READ → TRANSFER_WRITE covers that. ALL_COMMANDS / TRANSFER_WRITE also orders graphics work against the fill, which nothing needs.
Alternative that avoids the fill and both barriers. Have the shader own the reset. The wave holding the last launch index already compare-exchanges the turn to 0. With a launch-epoch dword that the host bumps once per dispatch through push constants, the compare-exchange targets epoch * stride + launch and no dispatch ever needs a zeroed turn. A timed-out dispatch then can't poison the next one either, and the fill and barriers go away.
CPU-copy path (zeroGuestBytes returning nullopt). The memset runs at record time, while the GPU may still be executing a previously submitted dispatch that uses the same CPU-made GDS copy. Two dispatches recorded back to back into one command buffer also both zero the turn before either runs. Please confirm that case can't happen, or say what guarantees it can't.
Wait loop. Each waiting wave does up to 2^20 device-scope acquire loads with no backoff. If one wave never issues the done operation (a divergent path where a whole guest wave skips it), every later wave in that dispatch spends the full budget. The test counts the timeouts (2 here), but nothing records how long a timeout costs on hardware that doesn't schedule groups strictly in order. On a 4090, include the time of the skipped-group case in the numbers; it matters for Windows TDR.
Measurement. The title numbers are the corrupted-frame counts and the present counts (851–857 against about 790). Please add tools/trace_digest.py summaries of main and of this change from the same machine and scene, with the frame time and the gpu_busy_ms_per_present of the GoW fireplace scene. Presents going up while a drain is added before every GDS dispatch is surprising, and the digest will show which phase moved.
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>
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (5, not counted against this PR)Validation IDs already present on main (4 IDs in 397 tests)Skipped (40)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
@CnRJay thanks. All points are addressed in a new commit on top (no force-push). Reset only for ordering programs. The compiled program now carries Narrower barrier. The reset is now:
Epoch alternative. I kept the reset. An epoch needs a push word in every ordering program, bumped per dispatch, including dispatches replayed from recipes. A 32-bit turn of CPU-copy path. You're right, the record-time store was not safe to rely on, and it is removed. The reset is recorded only when the turn lives in an import or a GPU copy ( Wait loop cost. On an RX 9060 XT, 2^20 reads take about 130 ms. Your concern was right. I timed a dispatch where group 1 never takes its turn (a local timing build):
Before this commit, waves that launched after earlier ones had given up each waited a full budget again. Now the first wave that gives up marks the turn abandoned ( Measurement. A correction first: the earlier numbers in the description (851–857 presents against about 790, "on Plain
Where the time moved, per frame (
GPU busy per present drops by about 20 ms. My guess, not verified, is that the drop comes from the corrupted particle records: without the fix they are drawn as long streaks across the screen, which is far more raster work than correct particles. The traces dropped events after about 10 s on the busiest worker ( Checks on this commit:
TechLevelZero's NVIDIA run (RTX 2000 Ada) passed on the previous head, af3c0c1. 🤖 Addressed by Claude Code |
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (5, not counted against this PR)Validation IDs already present on main (5 IDs in 400 tests)Skipped (40)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
…d-append Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Windows data point to go with the RADV RX 9060 XT run: AMD Radeon RX 9070 XT (RDNA 4) on AMD's Windows driver 32.0.32015.7029, Windows 11 Pro 22631, MSYS2 UCRT64 GCC 16.1, Release, Tree:
I could not run the PR's test against AI-assisted: yes (Claude Code) |
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (4, not counted against this PR)Passed on retry (1, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)Validation IDs already present on main (3 IDs in 390 tests)Skipped (48)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
Windows GPU run of head Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, Radeon RX 6700 XT with AMD proprietary driver 26.10.1 (Vulkan 1.4.315), WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
AI-assisted: yes (Claude Code). |
|
NVIDIA on Windows, for head GPU: NVIDIA GeForce GTX 1650 (Turing,
Only this test target was built, not the full suite, and no title was run. AI-assisted. |
CnRJay
left a comment
There was a problem hiding this comment.
Thanks for the gate, the narrower barrier, the timing table and the correction of the present counts. One consequence of the CPU-copy change is not covered in your reply.
An abandoned mark is never cleared when the GDS binding is a CPU-made copy. The first wave that gives up stores 0xffffffff in the turn, and "the next ordering dispatch's reset clears the mark". For a CPU-made copy you no longer record a reset (FillTarget returns nothing), and you rely on the previous dispatch leaving 0. After a timeout it leaves 0xffffffff. The holder's compare-exchange cannot replace the mark, so every later ordering dispatch on that copy sees the mark at its first wait and runs unordered, with every wave counted as a timeout. That is main's behaviour, but it is permanent, and nothing in the log distinguishes it from a first timeout.
Please say which binding the GDS gets by default on the three platforms (import, GPU copy or CPU copy), since that decides how often this path is the one titles take. Then either:
- clear the mark from the CPU side when a CPU copy is bound and the timeout count has moved, before the next dispatch is recorded and with the previous submission retired; or
- refuse ordering programs on a CPU-made copy with a throw, so the gap is visible rather than a silent fallback.
A test that times out once and then runs a normal dispatch on a CPU-made binding would pin it. The existing "dispatch after a timeout" case runs on an import or GPU copy, where the reset covers it.
The frame-time table is what I asked for; gpu_busy_ms_per_present going from about 150 to about 129 ms with the change is a large move for a GDS-only fix, so it is worth a line saying which phase it comes from.
… 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>
|
@Lucke0051 @gabichuuuuu thanks for finding this and narrowing it down. @oneandonlydean you were right about where it is. Fixed in Cause. The shared, host-imported GDS is requested only on integrated GPUs (
Restoring only the constructor's import size didn't help, Lucke, because the file itself was still Fix. Test. The new Local results, RADV RX 9060 XT: build OK, 1564 of 1564 agc, shader, recompiler and GDS tests, I can't test ANV or Intel's Windows driver here. Lucke, if your rerun offer still stands, your six tests and the full @milescoviello thanks for the Linux and Windows NVIDIA runs on 🤖 Addressed by Claude Code |
|
Windows and NVIDIA Blackwell run of head
The new The 1 failure, No title was run. AI-assisted: yes. Claude Code ran the builds and tests and drafted this comment; the numbers are from the runs on this machine. |
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>
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — comments
The inspected code includes launch-order assumptions that the PR documents, but this review did not cover every changed file or run checks, so a formal approval is not justified.
What I ran
Head: 9d2d569f180e22993baeb08004d046c3e2dc1fe8. No commands or tests were run. I read the review description, commit list, manifest and diff, then inspected targeted source ranges.
Results
| Check | Result | Note |
|---|---|---|
| Source inspection | not run | Targeted review only |
| Tests and prechecks | not run | No execution environment available |
Findings
Blocking
None in the inspected code.
Non-blocking
None.
Not verified
I read Execution/include/Pm4.hpp, Execution/src/Pm4.cpp, targeted ranges of Execution/src/VulkanDevice.cpp, Graphics/include/GuestBufferMemory.hpp, Graphics/include/ShaderResources.hpp, targeted ranges of Graphics/src/GuestBufferMemory.cpp and Graphics/src/ShaderResources.cpp, tests/Pm4.cpp, tests/cmake/agc_driver_graphics_tests.cmake, tests/execution/GdsAppendConsume.cpp, shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvMemoryInstructions.cpp, shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp, and the review documents. Other changed files listed in the manifest were not read, including the remaining recompiler changes, GuardedMemoryLoads.cpp, the new CMake test registration, and docs/dev/debt/shader.md. Runtime behavior, test results, validation output, and performance claims were not independently verified.
To get this to a good state
Nothing is required. Optional: complete review of the unread changed files and run the relevant checks before a formal approval.
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.
|
NVIDIA Linux run with the Khronos validation layer of the current head Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor
The selection is the GDS and PM4 tests the PR adds or changes, Negative control: the PR build with so the new cases detect unordered service on this GPU too. The speed numbers from God of War Ragnarök were not measured here. No new AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the ordering path, metadata bounds, per-chunk reset, and added coverage are supported by the code inspected.
What I ran
Reviewed head 294347f4dc5e12f6ce0be825679b32e5180a02aa using the prepared diff and repo_read.py at the pinned head. No build or tests were run. Read the changed code and its relevant callers for the ordered SPIR-V emission, input declarations, GDS resource preparation and fill target, dispatch reset, and disk cache format; also read the added append/consume test code and GDS range helpers. The entire files at the head were not read.
Results
| Check | Result | Note |
|---|---|---|
| Diff and manifest review | passed | Changed paths and hunks inspected |
| Targeted code review | passed | Relevant paths and callers read |
| Build and tests | not run | Author-reported results not independently verified |
Findings
Blocking
None.
Non-blocking
None.
Not verified
Did not run a build, tests, validation layers, or console/game checks. Author-reported test and hardware results were not independently verified. Files listed as excluded in files.json were not read in full; relevant changed hunks in VulkanDevice.cpp, GuestBufferMemory.cpp, and ShaderResources.cpp were read through the pinned reader.
To get this to a good state
Nothing is required.
|
I ran the two requested Windows Intel tests on a physical Intel UHD Graphics
In all four PR runs, row 65537 in the second chunk returned 0, expected 66536 (65538 single-wave groups, split 65536 + 2). I reversed the order for the second pair. Each run started a fresh process, required Vulkan, disabled the shader cache and logged the selected Intel adapter and insertion of the Khronos 1.4.369 validation layer. There were no VUIDs, device losses or timeouts. The standard test reached this assertion without the earlier Windows mapping diagnostic. The forced-copy result matches the earlier Windows Intel observation on a different driver. The baseline predates both the split case and the copied test, so its pass covers only the original workload. I used the same clean integration base as the RTX 4090 comparison. AI-assisted testing. |
|
@ZSWolt the merge of main on this head is clean, but the Intel Windows result from @mihiii1337 on 294347f is still open: agc_driver_gds_append_consume and agc_driver_gds_append_consume_copied both fail 2/2 on an Intel UHD 8086:a78b with the GDS allocation fix already in, and pass on main. In the second chunk of the split dispatch (65536 + 2 groups) row 65537 returns 0 where 66536 is expected, with no VUID and no device loss, so it is not the short page. |
mihiii1337
left a comment
There was a problem hiding this comment.
I re-audited the still-open Intel A78B split-dispatch result on exact head 294347f4dc5e12f6ce0be825679b32e5180a02aa before repeating it on the updated driver. The fixture itself runs and reads one row beyond ChunkOutput when the device reports a Y workgroup limit of 65,536, so my earlier row 65537 returned 0 report cannot establish a reset/order defect. Details are inline.
I did not run a new build or hardware test after finding this; the fixture needs to be made in-bounds first.
AI-assisted: yes.
|
|
||
| std::string CheckChunkedRecovery(AgcDriver::VulkanDevice& device, AgcDriver::QueueState& queue) { | ||
| const auto limit = device.graphicsContext().limits.maxComputeWorkGroupCount[1]; | ||
| if (limit >= ChunkOutput.size() / OrderedGroupLanes) { |
There was a problem hiding this comment.
[P2] Cover limit + 2 rows before interpreting the Intel split result
ChunkOutput has (65535 + 2) rows, i.e. 65,537. On the A78B, maxComputeWorkGroupCount[1] is 65,536, so this guard is false and rows becomes 65,538. The descriptor at line 333 still exposes only 65,537 rows: the shader's row-65,537 store is out of bounds, and the check at line 354 then reads ChunkOutput[65537 * 32] one-past the array. The previously reported 0 instead of 66536 is exactly this first out-of-bounds row, in both the normal and copied registrations, so it cannot diagnose the reset between chunks. Please size bounded storage for all rows (or explicitly skip when rows exceeds capacity) and rerun the Intel case before treating that result as a driver/product failure.
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 #10193, feat(agc): test the depth bounds in the pixel program when the device lacks the depthBounds feature #11551, fix(agc): span table-reading wave64 programs by default on Intel drivers that share handles across fused threads #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: #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