mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:10:53 +01:00
[PR #2230] [MERGED] indirect clamp: bound dispatch records by the device's maxComputeWorkGroupCount, not 65,535 (RT-INDIRECT-DISPATCH-GROUP-LIMIT) #2235
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2235
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2230
Author: @Tyrannys
Created: 11/26/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142
Base:
main← Head:rt-indirect-dispatch-group-limit📝 Commits (2)
7a76169indirect clamp: bound dispatch records by the device's maxComputeWorkGroupCount595b132Merge main (fac8b4bb9) into #2230: keep the device-bound dispatch limit and #2378's unfilled draw records📊 Changes
6 files changed (+539 additions, -305 deletions)
View changed files
📝
runtime/src/indirect_clamp.comp(+19 -9)📝
runtime/src/indirect_clamp_spv.h(+311 -285)📝
runtime/src/vulkan_indirect_clamp.h(+26 -6)➕
runtime/test/cs_group_marker_spv.h(+43 -0)➕
runtime/test/glsl/cs_group_marker.comp(+16 -0)📝
runtime/test/indirect_clamp_test.cpp(+124 -5)📄 Description
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
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
[PR #2230] indirect clamp: bound dispatch records by the device's maxComputeWorkGroupCount, not 65,535 (RT-INDIRECT-DISPATCH-GROUP-LIMIT)to [PR #2230] [MERGED] indirect clamp: bound dispatch records by the device's maxComputeWorkGroupCount, not 65,535 (RT-INDIRECT-DISPATCH-GROUP-LIMIT)