indirect clamp: bound dispatch records by the device's maxComputeWorkGroupCount, not 65,535 (RT-INDIRECT-DISPATCH-GROUP-LIMIT) #2230
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2230
Loading…
Reference in a new issue
No description provided.
Delete branch "rt-indirect-dispatch-group-limit"
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?
Pull request successfully merged and closed
Claimed in the coordination issue as: RT-INDIRECT-DISPATCH-GROUP-LIMIT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7185983481)
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
Verified on main a73a57e1 with 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)
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
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)
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)