Repository navigation
indirect clamp: bound dispatch records by the device's maxComputeWorkGroupCount, not 65,535 (RT-INDIRECT-DISPATCH-GROUP-LIMIT) - #2230
Conversation
…GroupCount
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 <noreply@anthropic.com>
|
Verified on main a73a57e 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) |
lixonik
left a comment
There was a problem hiding this comment.
Independent native Windows check on GeForce RTX 5070, NVIDIA 610.88: indirect_clamp, indirect_clamp_safety, and d3d12_indirect_dispatch_count passed. 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
left a comment
There was a problem hiding this comment.
Reviewed by Claude Code (AI-assisted) on my behalf. Looks right to me, approving.
- The new overflow check
x > max_groups || y > max_groups / x || z > max_groups / x / yis safe now that x can be
far above 65,535. The oldx * ycould overflow 32 bits once x is no longer capped there. The new
cost = x*y*z*64stays under 2^26. - The push block is 6 addresses plus 10 words, 88 bytes, matching the shader. Test 6b only passes with the
regeneratedindirect_clamp_spv.h, so the header and the.compagree. - Mesh dispatches stay at 65,535 in x. That matches what is seen there: a mesh record past it is a slot the title
never filled.
Tested on Linux with Mesa lavapipe at 7a76169: indirect_clamp_test, indirect_clamp_safety_test and
indirect_topology_and_stats_test pass. 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
…dispatch limit and ProjectLeonida#2378's unfilled draw records main's ProjectLeonida#2378 (a draw record of 2^23 vertices or more runs empty and charges nothing) changed indirect_clamp.comp next to this branch's dispatch bound. The .comp, vulkan_indirect_clamp.h and indirect_clamp_test.cpp merged without conflicts and keep both changes. The only conflict was the generated indirect_clamp_spv.h: it is regenerated from the merged indirect_clamp.comp as its header comment says (glslangValidator 16.6.0, -V --target-env vulkan1.2 -Os --spirv-val; spirv-val passes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the fix.
AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2) |
|
Merging.
Thanks @Tyrannys, and the reviewers on this PR. AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2) |
…RECT-DISPATCH-COUNTERS) #2230 bounds a dispatch record by the device's maxComputeWorkGroupCount instead of 65 535. Nothing said how wide the title's dispatches are, nor when a device's own limit still cuts one (llvmpipe allows 65 535 in x; RADV 2^32 - 1), which its review asked for. The title's tile passes ask for 67 440 groups in x at 2560x1440 (found in the VIctory-Belobug-AMD fork of VIctory, crates/victory-gpu/src/indirect.rs; no code of it is used). - indirect_clamp.comp: stats words 12-15 count dispatch records that run wider than 65 535 groups in x, the widest x that runs, those cut at the device's limits (and still running), and all of them. - vulkan_indirect_clamp.h: the counters, read with the others (16 words a slot, words 8-15 zeroed before the pass), and a line every 10 s while dispatch records are clamped: `indirect clamp dispatch: N records, W wider than 65535 groups in x, widest x X, C cut at the device's limits (x x y x z)`. - indirect_clamp_spv.h regenerated from the .comp as its header says (glslangValidator 16.6.0). - docs/d3d12_vulkan.md section 4.7: the device's bound per dimension (it still said 65 535), the line, and the test. Tests: indirect_clamp_test's cases 6b and 6c check the counters (70 000 x 1 x 1: wider than 65 535 where the device runs it, cut at its limit and counted where not). tests/test_indirect_clamp_telemetry.py checks the new atomics. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claimed in the coordination issue as: RT-INDIRECT-DISPATCH-GROUP-LIMIT (#1608 (comment))
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 test: bind a PSO before direct heap dispatch #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