shader: serve DS_ORDERED_COUNT waves in dispatch order #1199
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1199
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1199"
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?
@NeySlim on GitHub · 2026-10-08 10:09 UTC · original
NeySlim:fix/ordered-append→main· +456 −33 · 13 files · 9 commits · openProblem
DS_ORDERED_COUNTis emulated as one unordered GDS atomic per wave. On hardware, the ordered-append unit serves the waves of a dispatch in dispatch order: each wave gets a term inTG_SIZE[16:6], waits until every earlier wave released, then does its GDS operation. Games build prefix sums on top of that.God of War Ragnarök (PPSA08332, 05.005) simulates all particle emitters in one compute dispatch that shares a single GDS counter. Each wave adds its live particles, and the last group of each emitter swaps the counter to zero to write its draw count. With unordered atomics, waves of a later, larger emitter add to the counter before the small emitter's final swap. Small emitters then get inflated counts (17634 indices for an emitter of at most 448 particles in one capture) and draw thousands of stale records from neighbouring chunks. The result is huge triangles radiating across the screen.
Change
TranslateProgram: every compute shader that usesDS_ORDERED_COUNTis served in order, whether or not it loadsTG_SIZE. When it does,TG_SIZE[16:6]carries the wave's position in dispatch order: flattened workgroup id times waves per group, plus the wave index, masked to 11 bits like the hardware term.DS_ORDERED_COUNTfirst waits until a release counter reaches the wave's full dispatch rank (OrderedAppendWait), does the GDS add or swap as before, and increments the release counter whenwave_releaseis set (OrderedAppendRelease). The rank is rebuilt fromWorkgroupId,NumWorkgroupsandLocalInvocationIndex, so waves 2048 apart do not share a slot; the game still sees the 11-bit term inTG_SIZE. The wait loop is bounded (2^22 polls), so a wave that never releases cannot hang the dispatch; past that bound the order for that wave is lost.dispatchBasesplit fromd4465faa7is removed: the in-shader order covers it, and the split serialized the GPU (6.9 to 18.5 fps in a God of War Ragnarök cutscene).NumWorkgroupsis accepted as a typed compute builtin byShaderInfoCollectionand declared as a shader input, so 2D and 3D dispatches get the right rank.Test
New
DsOrderedCountFollowsWaveLaunchOrder: 16 waves, where earlier waves spin longer beforeDS_ORDERED_COUNT(the iteration count is stored, so the delay is kept). Each wave must still read the counter value equal to its group index, and both the final count and the release counter must be 16. With the wait disabled, the waves are served in reverse order and the case fails. NewDsOrderedCountRanksPastElevenBits: 2049 one-wave groups where only wave 0 is delayed, so wave 2048 (same 11-bit term) must still be served last. NewDsOrderedCountFollowsWaveLaunchOrder2Druns the same check on 4x4 one-wave groups rankedy * 4 + x. All three also run under--ds-ordered-count-only.DsOrderedCountAddressAndExecWave32/64,DsOrderedCountPixelAddressWave32/64,DsAppendConsumeGdsRegionBoundsandComputeTgSizeSgprUsesWaveMetadatastill pass.Validation
Linux, AMD Radeon 8060S, Mesa RADV 26.2.3.
59183dbf: 605 of 615 cases pass; the 10 failures are the same as on main (602 of 612).Not tested: 3D dispatches using ordered append in a game (no case was seen; 2D is covered by the new test), and Windows/macOS (the change is platform-independent recompiler and renderer code).
AI use
I used Claude Code (AI agent) to capture and analyze the frames in RenderDoc, trace the particle counts back to the GDS prefix sum, write the change and the test, and run the tests above on my machine. I reviewed the diff and the results before opening this PR.
@coderabbitai[bot] on GitHub · 2026-10-08 10:14 UTC · original · edited 2026-10-20 14:31 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
e5a957b7-da15-4dff-9cd3-ae1d1c4fa176📥 Commits
Reviewing files that changed from the base of the PR and between 7495ea8619e6438dd41df1fc0cd2acd5d707c652 and ecb70d14279d69db85990b32d1310ddf30424f6a.
📒 Files selected for processing (2)
src/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpptests/ShaderRecompilerComputeTests.cpp🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.
📝 Walkthrough
Compute translation identifies programs that use
DS_ORDERED_COUNTand encodes dispatch and wave order. The shader recompiler emits GDS wait and release operations around the shared atomic. The renderer clears ordered-append counters before direct and indirect compute dispatches. New compute tests check launch order and ranks across 2,049 waves.Priority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
ecb70No confirmed issue blocks merging. The new 2D ordered-count test exercises the intended dispatch and rank order.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 10 files. (1 skipped: 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@ -1428,0 +1505,4 @@const auto expired = Binary(state, spv::OpUGreaterThanEqual, TypeBool(state), iteration,ConstantU32(state, 1u << 22u));const auto done = Binary(state, spv::OpLogicalOr, TypeBool(state), ready, expired);state.builder.AddFunction(spv::OpBranchConditional, done, merge, cont);@coderabbitai[bot] on GitHub · 2026-10-08 10:14 UTC · original · edited 2026-10-08 10:43 UTC
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Do not treat an expired wait as permission to execute the ordered atomic.
If an earlier wave takes longer than this polling bound to release,
expiredsends the later wave to the same exit asready. The later wave then performs its GDS atomic out of order. The bound prevents an indefinite wait, but it does not preserve the ordering promised by this path. Use a fallback that preserves ordering, or make the loss of ordering an explicit supported limitation. (docs.vulkan.org)✅ Confirmed as addressed by @NeySlim
@ -1183,0 +1203,4 @@builtin(IR::StageInputKind::WorkgroupId, 2)}));const auto term = entry_ir.BitwiseAnd(entry_ir.IAdd(entry_ir.IMul(group, u32(waves)), wave_id),u32(IR::OrderedAppendWaveIdMask));@coderabbitai[bot] on GitHub · 2026-10-08 10:14 UTC · original · edited 2026-10-08 10:43 UTC
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Preserve distinct terms for all waves in a dispatch.
With one wave per workgroup, workgroups 0 and 2,048 both receive term 0. If the later workgroup reaches
DS_ORDERED_COUNTwhile the release counter is 0,OrderedAppendWaitaccepts it before the earlier workgroup. The ordered GDS atomic can then execute out of order. Use a dispatch-wide term and compare the full release count, or define an explicit limit for ordered dispatches. Vulkan permits dispatches larger than this 11-bit range. (docs.vulkan.org)✅ Confirmed as addressed by @NeySlim
@coderabbitai[bot] on GitHub · 2026-10-08 10:14 UTC · original · reviewed
Actionable comments posted: 2
🧹 Nitpick comments (2)
ℹ️ Review info
⚙️ Run configuration
c6073b3d-0cce-4d9a-add6-a83f98a459bf📥 Commits
Reviewing files that changed from the base of the PR and between
5a8808086aand 8604a92028deb92df0ee96237e33646b7ae6c1f4.📒 Files selected for processing (12)
src/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/render.hsrc/graphics/host_gpu/renderer/renderCompute.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cppsrc/graphics/shader/recompiler/frontend/translate/Memory.cppsrc/graphics/shader/recompiler/frontend/translate/Translate.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.cppsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.incsrc/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@ -1428,0 +1505,4 @@const auto expired = Binary(state, spv::OpUGreaterThanEqual, TypeBool(state), iteration,ConstantU32(state, 1u << 22u));const auto done = Binary(state, spv::OpLogicalOr, TypeBool(state), ready, expired);state.builder.AddFunction(spv::OpBranchConditional, done, merge, cont);@NeySlim on GitHub · 2026-10-08 10:38 UTC · original
The bound is there to avoid a GPU hang when an earlier wave never releases, for example a wave that exits without reaching
DS_ORDERED_COUNT. Hardware handles that case and Kyty cannot tell it apart from a slow wave. I kept it and made it an explicit, documented limitation in e86d3da: past 2^22 polls, the wave proceeds and the order for that wave is lost, but the dispatch completes. With the full-rank comparison, the only way to reach it is a wave that never releases.@ -1183,0 +1203,4 @@builtin(IR::StageInputKind::WorkgroupId, 2)}));const auto term = entry_ir.BitwiseAnd(entry_ir.IAdd(entry_ir.IMul(group, u32(waves)), wave_id),u32(IR::OrderedAppendWaveIdMask));@NeySlim on GitHub · 2026-10-08 10:38 UTC · original
Agreed, fixed in e86d3da.
DS_ORDERED_COUNTno longer waits on the 11-bit term from M0. It rebuilds the wave's full dispatch rank fromWorkgroupId,NumWorkgroupsandLocalInvocationIndex(waves per group and wave size are recorded when the entry block writesTG_SIZE), andOrderedAppendWaitcompares it with the full 32-bit release counter. The game still gets the 11-bit term inTG_SIZE[16:6], as on hardware. New caseDsOrderedCountRanksPastElevenBits: 2049 one-wave groups where only wave 0 is delayed, so wave 2048 (same 11-bit term) must still be served last. It passes. To be transparent: on this GPU it also passes with the old 11-bit comparison, because the waves past 2048 are not resident until earlier ones retire, so it guards the behavior rather than reproducing the race here.@ -43229,1 +43476,4 @@AddCase(DsAppendConsumeGdsRegionBounds);AddCase(DsOrderedCountFollowsWaveLaunchOrder<false>);AddCase(DsOrderedCountFollowsWaveLaunchOrder<true>);AddCase(DsOrderedCountRanksPastElevenBits);@coderabbitai[bot] on GitHub · 2026-10-08 10:41 UTC · original · edited 2026-10-08 10:44 UTC
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Include the new order tests in the ordered-count test selector.
--ds-ordered-count-onlyruns four address tests directly. It does not useMakeCases(), so this registration does not makeDsOrderedCountRanksPastElevenBitsrun under that selector. The selector also omitsDsOrderedCountFollowsWaveLaunchOrder. Add both cases to the selector so the focused validation command checks the new ordering behavior.✅ Confirmed as addressed by @NeySlim
@coderabbitai[bot] on GitHub · 2026-10-08 10:41 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
0f0ced5d-545c-4ee0-b93b-678b6ecf7d4a📥 Commits
Reviewing files that changed from the base of the PR and between 8604a92028deb92df0ee96237e33646b7ae6c1f4 and e86d3da18246a0ec9a7ca89f45ed4bd0564fb222.
📒 Files selected for processing (5)
src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cppsrc/graphics/shader/recompiler/frontend/translate/Memory.cppsrc/graphics/shader/recompiler/frontend/translate/Translate.cppsrc/graphics/shader/recompiler/ir/ShaderIR.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
@ -1183,0 +1203,4 @@builtin(IR::StageInputKind::WorkgroupId, 2)}));const auto term = entry_ir.BitwiseAnd(entry_ir.IAdd(entry_ir.IMul(group, u32(waves)), wave_id),u32(IR::OrderedAppendWaveIdMask));@coderabbitai[bot] on GitHub · 2026-10-08 10:43 UTC · original
@NeySlim, thanks for the fix and the test limitation details. Using the full dispatch rank forOrderedAppendWaitaddresses the aliasing concern. Keeping the 11-bit term inTG_SIZE[16:6]preserves the hardware-visible encoding.DsOrderedCountRanksPastElevenBitschecks the expected ordering beyond 2,048 waves. As you explained, its pass on this GPU does not demonstrate that it detects the original race.✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@ -1428,0 +1505,4 @@const auto expired = Binary(state, spv::OpUGreaterThanEqual, TypeBool(state), iteration,ConstantU32(state, 1u << 22u));const auto done = Binary(state, spv::OpLogicalOr, TypeBool(state), ready, expired);state.builder.AddFunction(spv::OpBranchConditional, done, merge, cont);@coderabbitai[bot] on GitHub · 2026-10-08 10:43 UTC · original
@NeySlimThanks for the clarification. The comment inEmitOrderedAppendWaitnow makes the ordering loss explicit. This addresses the documented-limitation option in my finding.One distinction remains: full-rank comparison prevents 11-bit aliasing. It does not prevent a slow wave from exceeding
2^22polls. The bound remains a deliberate trade-off between ordering and avoiding an indefinite wait.✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@ -43229,1 +43476,4 @@AddCase(DsAppendConsumeGdsRegionBounds);AddCase(DsOrderedCountFollowsWaveLaunchOrder<false>);AddCase(DsOrderedCountFollowsWaveLaunchOrder<true>);AddCase(DsOrderedCountRanksPastElevenBits);@NeySlim on GitHub · 2026-10-08 10:44 UTC · original
Fixed in 94a1031:
--ds-ordered-count-onlynow also runsDsOrderedCountFollowsWaveLaunchOrderandDsOrderedCountRanksPastElevenBits, and all six cases pass.@ -43229,1 +43476,4 @@AddCase(DsAppendConsumeGdsRegionBounds);AddCase(DsOrderedCountFollowsWaveLaunchOrder<false>);AddCase(DsOrderedCountFollowsWaveLaunchOrder<true>);AddCase(DsOrderedCountRanksPastElevenBits);@coderabbitai[bot] on GitHub · 2026-10-08 10:44 UTC · original
@NeySlimThanks for the fix in94a1031and for confirming that all six cases pass. The selector now covers both new ordering tests.🧠 Learnings used
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@NeySlim on GitHub · 2026-10-09 19:22 UTC · original
Rebased on main (
59183dbf). The conflicts inShaderIR.handShaderInfoCollection.cppcame from the reworkedShaderInfoflags and the moved builtin validation; the change itself is unchanged. Also addressed the remaining nitpick from the first review: the two order cases now check the whole GDS readback, includingOrderedAppendReleaseCounter(7495ea86), so a release that counts twice fails. Full GPU suite, one case per process: 604/614, same 10 failures as main (602/612).@ -454,6 +455,7 @@ void Visit(Program& program, ShaderStageInputInfo input_info, InputUsage& inputsbreak;case StageInputKind::TessCoord:case StageInputKind::WorkgroupId:case StageInputKind::NumWorkgroups:@coderabbitai[bot] on GitHub · 2026-10-09 19:27 UTC · original · edited 2026-10-09 19:49 UTC
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Declare
NumWorkgroupswhen accepting the builtin.An ordered-append compute shader reads
NumWorkgroupsto calculate its wave rank.Visitnow accepts that read, butAddBuiltinInputhas noNumWorkgroupscase. The SPIR-V emitter therefore has no input binding for a GDS-only shader; its separate insertion applies only to LDS stored in a storage buffer. Add thegl_NumWorkGroupsinput inAddBuiltinInputso ordered-append shader compilation can resolve the read. (raw.githubusercontent.com)✅ Addressed in commit ecb70d1
@coderabbitai[bot] on GitHub · 2026-10-09 19:27 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
9a68b42f-7fa4-41f0-b940-bf22efbe1934📥 Commits
Reviewing files that changed from the base of the PR and between 94a1031d0c4b10bcee1d0885e471387214f4b6ac and 7495ea8619e6438dd41df1fc0cd2acd5d707c652.
📒 Files selected for processing (9)
src/graphics/host_gpu/renderer/render.hsrc/graphics/host_gpu/renderer/renderCompute.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cppsrc/graphics/shader/recompiler/frontend/translate/Translate.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.incsrc/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.
@ -454,6 +455,7 @@ void Visit(Program& program, ShaderStageInputInfo input_info, InputUsage& inputsbreak;case StageInputKind::TessCoord:case StageInputKind::WorkgroupId:case StageInputKind::NumWorkgroups:@NeySlim on GitHub · 2026-10-09 19:41 UTC · original
Confirmed and fixed in ecb70d14:
AddBuiltinInputnow declaresgl_NumWorkGroups. Without it the read fell back to 0, so the rank collapsed toWorkgroupId.x; 1D dispatches still came out right, which is why the existing cases passed. New caseDsOrderedCountFollowsWaveLaunchOrder2D(4x4 one-wave groups, rankedy * 4 + x) fails without the fix and passes with it; it also runs under--ds-ordered-count-only. Full GPU suite: 605/615, same 10 failures as main.@ -454,6 +455,7 @@ void Visit(Program& program, ShaderStageInputInfo input_info, InputUsage& inputsbreak;case StageInputKind::TessCoord:case StageInputKind::WorkgroupId:case StageInputKind::NumWorkgroups:@coderabbitai[bot] on GitHub · 2026-10-09 19:49 UTC · original
@NeySlimThanks for the fix and the explanation. The suppliedAddBuiltinInputcode now declaresgl_NumWorkGroupswith three components. The reportedDsOrderedCountFollowsWaveLaunchOrder2Dregression test covers the rank error that 1D dispatches did not expose.✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@NeySlim on GitHub · 2026-10-19 14:02 UTC · original
Rebased on
cd4eab9d. Withd4465faa7a single-wave ordered-append dispatch is now split into onedispatchBaseper group, soNumWorkgroupsis 1x1x1 inside each piece and the ranks this PR derived from it collapsed to x+y+z: on a 2x2x2 grid the waits ran into their bound instead of being served. The ranks now come from the group counts the host writes next to the release counter (filled for direct dispatches, copied from the arguments for indirect ones), so they are the same whether or not the dispatch is split. NewCheckOrderedAppendRanks(in--ordered-dispatch-only) goes through the real direct and indirect paths with TG_SIZE on, wave32 and wave64, and fails without the change.@NeySlim on GitHub · 2026-10-20 14:30 UTC · original
@shadowbeat070
d4465faa7splits every single-wave ordered-append dispatch into onedispatchBaseper group with a barrier in between. In God of War Ragnarök that is around 1300 groups per dispatch, a few dispatches per frame, and the GPU ends up busy most of the frame on those barriers. With my other open PRs applied, on a Radeon 8060S:This PR already serves
DS_ORDERED_COUNTin dispatch order inside the shader (each wave waits for its rank in a GDS release counter), so the split isn't needed for ordering. It only did that when the shader loads TG_SIZE though, and yourCheckOrderedDispatchdoesn't, so without the split that case failed here. The hardware orders ordered-append waves from the dispatch initiator bit, not from TG_SIZE, so:shader: serve ordered-append waves in order without TG_SIZE: every compute shader withDS_ORDERED_COUNTwaits for its rank; only the TG_SIZE term stays tied to TG_SIZE.gpu: drop the per-group ordered-append dispatch split: back to onedispatch, and the pipelines no longer needeDispatchBase.CheckOrderedDispatchpasses without the split (20 of 20 runs), and fails with the split removed but without the first commit. The other ordered-append cases still pass. Full GPU suite, one case per process: same failures as main.The wait is still bounded, so a wave that is never released can't hang the dispatch. If you had a game where the split fixed something the in-shader order doesn't cover, tell me which one and I'll check it.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.