indirect clamp: bound dispatch records by the device's maxComputeWorkGroupCount, not 65,535 (RT-INDIRECT-DISPATCH-GROUP-LIMIT) #2230
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2230
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2230"
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?
@Tyrannys on GitHub · 2026-11-26 08:50 UTC · original
Tyrannys:rt-indirect-dispatch-group-limit→main· +539 −305 · 6 files · 2 commits · merged 2026-11-26 21:43 UTCClaimed in the coordination issue as: RT-INDIRECT-DISPATCH-GROUP-LIMIT (#1608)
What and why
The ExecuteIndirect argument clamp (
runtime/src/indirect_clamp.comp, driven byvulkan_indirect_clamp.h) bounded every dispatch record at a fixed 65,535 groups per dimension, which is Vulkan's guaranteed minimum formaxComputeWorkGroupCount. Real devices report far more in x (this RTX 4070 SUPER: 2,147,483,647). So a one-dimensional indirect dispatch of more than 65,535 groups ran only its first 65,535 groups. The rest never wrote their output, which leaves stale blocks on screen.Now:
maxComputeWorkGroupCountper axis in its push constants (the block grows from 72 to 88 bytes: three limit words and a reserved word) and bounds dispatch records by those limits (indirect_clamp_dispatch_limit).LEONIDA_INDIRECT_GROUP_BUDGETare unchanged, so the TDR protection stays the same. Since x alone can now be above 65,535, the product check divides instead of multiplying.maxMeshWorkGroupCount), so they are left for another PR.Credit: the idea is from codec-d/cool_fox
docs/findings.md("Blocky patches: indirect dispatches cut at 65,535 groups"). I used the idea only and took no code.Not covered here (follow-up, if needed): a dispatch above the device's own limit. That means x > 65,535 on a device whose x limit is 65,535, or y/z > 65,535 anywhere. It is still cut at that limit. Running it whole would mean splitting it with a group-base offset that the translated shader adds to
WorkgroupId. The translator readsWorkgroupIdwith no base today, andvkCmdDispatchBasewould needVK_PIPELINE_CREATE_DISPATCH_BASE_BITon every compute pipeline, which would invalidate existing pipeline caches. DirectDispatch(not indirect) still passes its counts through unchanged. D3D12 already forbids counts above 65,535 there.Tested
indirect_clamp_testsends realvkCmdDispatchIndirectcalls through the clamped scratch. A marker shader (runtime/test/glsl/cs_group_marker.comp) does one atomic per workgroup, and the test reads the marks back. No game files.70000 x 1 x 1: onmain, 65,535 groups ran once and 4,465 never ran (the test fails, 3 CHECKs). With this change, all 70,000 groups run exactly once and none run past the end.65535 x 1 x 1and1 x 65535 x 1(exactly at the old limit): every group runs exactly once, both onmainand with this change.LEONIDA_VK_VALIDATION=1 indirect_clamp_test: passes, 0 validation errors.ctest -R "indirect|clamp": 25/25 passed. Full runtimectest(-j 2, while a title boot was running on the same GPU): 473/477 passed. Two were timeouts (d3d12_queue_wait_timeout,d3d12_queue_list_type) that pass when rerun alone. Two fail without involving the clamp:d3d12_set_descriptor_heapsdispatches with no PSO bound, which is fixed by the open #2153, andxbox_presentfailspresentwith VkResult -11 while the boot holds the display.tests/test_indirect_clamp_telemetry.py,tests/test_ctest_registration.py: pass.indirect_clamp_spv.hwas regenerated with the Vulkan SDK 1.4.341 glslangValidator (-V --target-env vulkan1.2 -Os --spirv-val), which emits different ids than the earlier header.GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
The ExecuteIndirect argument clamp (indirect_clamp.comp) cut every dispatch record at a fixed 65,535 groups per dimension, Vulkan's guaranteed minimum. Devices report far more in x (NVIDIA: 2^31 - 1), so a one-dimensional indirect dispatch of more than 65,535 groups ran only its first 65,535 groups; the rest never wrote their output. The clamp now takes the device's maxComputeWorkGroupCount per axis in its push constants (88 bytes, was 72) and bounds dispatch records by that. The 2^20 groups-per-dispatch cap, the list budget and LEONIDA_INDIRECT_GROUP_BUDGET are unchanged; the product check now divides instead of multiplying, since x alone may exceed 65,535. Mesh dispatches keep 65,535 in x. indirect_clamp_test runs real indirect dispatches through the clamped scratch with a marker shader (one atomic per group): 70,000 x 1 x 1 ran 65,535 groups and left 4,465 unrun on main, and runs all 70,000 exactly once now; 65,535 x 1 x 1 and 1 x 65,535 x 1 (at the old limit) run exactly once on both. A size past the device's own limit is skipped. Idea from codec-d/cool_fox docs/findings.md ("Blocky patches: indirect dispatches cut at 65,535 groups"); idea only, no code taken. Co-Authored-By: Claude Opus 5.5 <[email protected]>@real-rusher on GitHub · 2026-11-26 10:06 UTC · original
Verified on main
a73a57e1with Mesa llvmpipe (Mesa 25.2.8, LLVM 20.1.2, 256 bits, Ubuntu 24.04 x86-64, no GPU), GCC 13, Ninja. Merges cleanly.AI-assisted: yes (Claude Code)
@lixonik on GitHub · 2026-11-26 10:37 UTC · original · reviewed
Independent native Windows check on GeForce RTX 5070, NVIDIA 610.88:
indirect_clamp,indirect_clamp_safety, andd3d12_indirect_dispatch_countpassed. The GPU mark-and-readback cases ran without skips, including the 70,000-group X dispatch and the 65,535-group controls. The counted Vulkan dispatches also matched their expected results. Synthetic inputs only. AI-assisted.@kawaii-shakal on GitHub · 2026-11-26 13:03 UTC · original · approved these changes
Reviewed by Claude Code (AI-assisted) on my behalf. Looks right to me, approving.
x > max_groups || y > max_groups / x || z > max_groups / x / yis safe now that x can befar above 65,535. The old
x * ycould overflow 32 bits once x is no longer capped there. The newcost = x*y*z*64stays under 2^26.regenerated
indirect_clamp_spv.h, so the header and the.compagree.never filled.
Tested on Linux with Mesa lavapipe at
7a761696:indirect_clamp_test,indirect_clamp_safety_testandindirect_topology_and_stats_testpass. lavapipe reports 65,535 in x, so the 70,000 x 1 x 1 case is skipped there.It still needs a run on an NVIDIA or AMD device, whose x limit is far higher.
Non-blocking: on a device whose x limit is 65,535, a wider dispatch is still cut. A rate-limited log line when a
dispatch record asks past the device limit would make that case visible. The stats already count clamped records,
but they don't say why.
Generated by Claude Code
@aslan2142 on GitHub · 2026-11-26 21:43 UTC · original
Thanks for the fix.
mainhad moved past this branch, so I merged it in as a maintainer (a merge commit, no rebase). Your clamp change itself is untouched.main(fac8b4bb9) contains #2378, which changedindirect_clamp.compnext to your dispatch bound: a draw record of 2^23 vertices or more now runs empty and charges nothing.indirect_clamp.comp,vulkan_indirect_clamp.handindirect_clamp_test.cppmerged without conflicts and keep both changes.runtime/src/indirect_clamp_spv.h. It is regenerated from the merged.compwith the command in its header comment (glslangValidator 16.6.0,-V --target-env vulkan1.2 -Os --spirv-val;spirv-valpasses).maxComputeWorkGroupCount[0]= 4294967295), the 70000 × 1 × 1 case ran instead of being skipped.indirect_clamp_testpassed with the validation layer on, and the kernel log stayed clean. On llvmpipe it is skipped as before.vkCmdDispatchIndirectand a group counter ran all 67,440 groups on both RADV GPUs.cteston llvmpipe passed 114 of 114. The Windows suite under Wine on the iGPU: 488 tests, none changed againstmainfac8b4bb9.indirect clamp dispatch:line.AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)
@aslan2142 on GitHub · 2026-11-26 21:43 UTC · original
Merging.
maxComputeWorkGroupCountinstead of a fixed 65,535, so a wide dispatch is no longer cut on a device that can run it.595b1325d: a merge ofmainfac8b4bb9, described in the comment above. It regeneratesindirect_clamp_spv.hfrom the merged shader and changes nothing else of the PR.indirect_clamp_testwith the validation layer on llvmpipe, the integrated RDNA2 GPU and the RX 7900 XTX (RADV), with a clean kernel log. A 67,440 × 1 × 1 record runs all its groups on both RADV devices.ctest: 114/114. Windows suite under Wine: 488 tests, none changed againstmain.Thanks @Tyrannys, and the reviewers on this PR.
AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)