[PR #2230] [MERGED] indirect clamp: bound dispatch records by the device's maxComputeWorkGroupCount, not 65,535 (RT-INDIRECT-DISPATCH-GROUP-LIMIT) #2235

Closed
opened 2026-11-26 21:20:30 +01:00 by 4ld0 · 0 comments
Owner

📋 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)

  • 7a76169 indirect clamp: bound dispatch records by the device's maxComputeWorkGroupCount
  • 595b132 Merge 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 by vulkan_indirect_clamp.h) bounded every dispatch record at a fixed 65,535 groups per dimension, which is Vulkan's guaranteed minimum for maxComputeWorkGroupCount. 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:

  • The clamp gets the device's maxComputeWorkGroupCount per 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).
  • The 2^20 groups-per-dispatch cap, the 2^27 list budget and LEONIDA_INDIRECT_GROUP_BUDGET are unchanged, so the TDR protection stays the same. Since x alone can now be above 65,535, the product check divides instead of multiplying.
  • Mesh dispatches keep 65,535 in x. Their limit is a separate one (maxMeshWorkGroupCount), so they are left for another PR.
  • No CPU readback of arguments. The pass is the same single tiny dispatch as before.

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 reads WorkgroupId with no base today, and vkCmdDispatchBase would need VK_PIPELINE_CREATE_DISPATCH_BASE_BIT on every compute pipeline, which would invalidate existing pipeline caches. Direct Dispatch (not indirect) still passes its counts through unchanged. D3D12 already forbids counts above 65,535 there.

Tested

  • New case 10 in indirect_clamp_test sends real vkCmdDispatchIndirect calls 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: on main, 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 1 and 1 x 65535 x 1 (exactly at the old limit): every group runs exactly once, both on main and with this change.
    • A size above the device's own limit is skipped, with a message.
  • Updated case 6b (the cut now follows the device's y limit) and added case 6c (70,000 in x comes back unclamped where the device allows it).
  • LEONIDA_VK_VALIDATION=1 indirect_clamp_test: passes, 0 validation errors.
  • ctest -R "indirect|clamp": 25/25 passed. Full runtime ctest (-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_heaps dispatches with no PSO bound, which is fixed by the open #2153, and xbox_present fails present with VkResult -11 while the boot holds the display.
  • tests/test_indirect_clamp_telemetry.py, tests/test_ctest_registration.py: pass.
  • indirect_clamp_spv.h was 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

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of 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.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2230 **Author:** [@Tyrannys](https://github.com/Tyrannys) **Created:** 11/26/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `rt-indirect-dispatch-group-limit` --- ### 📝 Commits (2) - [`7a76169`](https://github.com/ubiquitarianism/leonida/commit/7a761696dcef8cb2415c3000dfc3c4196675263b) indirect clamp: bound dispatch records by the device's maxComputeWorkGroupCount - [`595b132`](https://github.com/ubiquitarianism/leonida/commit/595b1325d922ed05782fc5fd7d0baa5459eadef6) Merge main (fac8b4bb9) into #2230: keep the device-bound dispatch limit and #2378's unfilled draw records ### 📊 Changes **6 files changed** (+539 additions, -305 deletions) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 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 by `vulkan_indirect_clamp.h`) bounded every dispatch record at a fixed 65,535 groups per dimension, which is Vulkan's guaranteed minimum for `maxComputeWorkGroupCount`. 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: - The clamp gets the device's `maxComputeWorkGroupCount` per 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`). - The 2^20 groups-per-dispatch cap, the 2^27 list budget and `LEONIDA_INDIRECT_GROUP_BUDGET` are unchanged, so the TDR protection stays the same. Since x alone can now be above 65,535, the product check divides instead of multiplying. - Mesh dispatches keep 65,535 in x. Their limit is a separate one (`maxMeshWorkGroupCount`), so they are left for another PR. - No CPU readback of arguments. The pass is the same single tiny dispatch as before. 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 reads `WorkgroupId` with no base today, and `vkCmdDispatchBase` would need `VK_PIPELINE_CREATE_DISPATCH_BASE_BIT` on every compute pipeline, which would invalidate existing pipeline caches. Direct `Dispatch` (not indirect) still passes its counts through unchanged. D3D12 already forbids counts above 65,535 there. ### Tested - New case 10 in `indirect_clamp_test` sends real `vkCmdDispatchIndirect` calls 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`: on `main`, 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 1` and `1 x 65535 x 1` (exactly at the old limit): every group runs exactly once, both on `main` and with this change. - A size above the device's own limit is skipped, with a message. - Updated case 6b (the cut now follows the device's y limit) and added case 6c (70,000 in x comes back unclamped where the device allows it). - `LEONIDA_VK_VALIDATION=1 indirect_clamp_test`: passes, 0 validation errors. - `ctest -R "indirect|clamp"`: 25/25 passed. Full runtime `ctest` (`-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_heaps` dispatches with no PSO bound, which is fixed by the open #2153, and `xbox_present` fails `present` with VkResult -11 while the boot holds the display. - `tests/test_indirect_clamp_telemetry.py`, `tests/test_ctest_registration.py`: pass. - `indirect_clamp_spv.h` was 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 changed title from [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) 2026-11-26 22:46:09 +01:00
4ld0 closed this issue 2026-11-26 22:46:09 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#2235
No description provided.