graphics: split mesh draws that exceed the host workgroup limits #2361
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2361
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2361"
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?
@Nawid3333 on GitHub · 2026-11-17 21:19 UTC · original
Nawid3333:fix/mesh-slice-oversized-draws→main· +178 −59 · 6 files · 1 commits · openProblem
A direct mesh draw is one
vkCmdDrawMeshTasksEXT(groups, instances, 1). When the guest draw needs more workgroups than the host allows (maxMeshWorkGroupCount[0]/[1],maxMeshWorkGroupTotalCount), the emulator exits (renderDraw.cpp:1080 at2638b1b07):mesh draw exceeds host workgroup limits: 173400x1in Union City. That driver allows 65535 workgroups per dimension.1x68734.1x76426and1x65674in the Garden level, againstmaxMeshWorkGroupCount = 4194304, 65535, 65535.1x85246.#793 (by @prompterror) split these draws first. Since
943bc19f4("leave the start instance out of mesh and NGG instance ID VGPRs") it no longer moves the instance of later slices, as @ZrDaniel07 noted there, and it no longer merges. This PR takes the same approach (split on the host, keep every limit) and gives the shader the slice's start through two push dwords.Change
ForEachMeshSlice(new meshSlices.h) splits agroups x instancesgrid into slices that each keep all three limits and together cover every (group, instance) exactly once:groups <= min(maxX, maxTotal)), each slice takes all groups and as many instances asmaxYandmaxTotal / groupsallow.min(maxX, maxTotal).PushData::MeshBaseGroupDword(5) andMeshBaseInstanceDword(6) follow the five mesh draw dwords, so the mesh draw prefix grows from 5 to 7 dwords. The direct-draw prefix push writes them as 0 for every draw, and renderDraw.cpp:1210-1218 pushes the slice's start before each later slice.WorkgroupId.x/.yfor direct draws. The workgroup and instance the shader computes are the ones of the unsplit draw.indirect_draw, gpu_mesh_indirect.task). Its workgroup IDs come from the task payload, which stays 6 dwords.MeshTaskFirstInstanceDwordnames its existing dword 5.Tests
shader_cfg_tests:TestMeshSlices: exact slice lists for:173400x1and1x76426groups == min(maxX, maxTotal)Plus all three limits and exact coverage for
UINT32_MAX x 1and1 x UINT32_MAX.TestMeshInputAssemblyruns each case a second time as a split launch: the second slice's workgroup comes from the base dwords. On main's sources it fails withmesh index fetch address or active-lane predicate is wrong; with the change it passes.shader_cfg_testspasses on this head. The wholeshader_recompiler_compute_testssuite (keep-going, on the earlier base4da95bd8d) gives the same result with and without the change on an RX 9070 XT (Windows 11, clang-cl, with the harness change of #2038): 192 checks ok and the same 4 failed checks.Fork CI on this head (run 44171919256): Windows and Linux builds pass; the macOS job got no GitHub runner (capacity).
Costs
173400x1).ForEachMeshSlicetoo.In a game
@Crispy81 ran Beyond a Steel Sky (PPSA03979) with the fork build of this change on
4da95bd8d(run 44139846777, commit 0a830e6): the game gets past the point in Union City where main stops, and progresses further (#2338). That build has the same source change as this head, apart from the comment line in gpu_mesh_indirect.task.Written with Claude Code (AI): Claude Code wrote the change and the tests from the reports and #793, and ran them; Codex and Claude Opus reviewed the design and the change, and GLM found three missing test cases.
@coderabbitai[bot] on GitHub · 2026-11-17 21:26 UTC · original
No actionable comments were generated in the recent review.
Walkthrough
The renderer now divides non-task mesh draws into slices that fit within host grid limits. It sets base group and instance values for slices with nonzero offsets. Shader translation uses those offsets for non-indirect draws and workgroup IDs directly for indirect draws. Push-data indices define the mesh base values and task first-instance value. Tests cover slice limits, launch offsets, and shader input assembly.
Suggested reviewers:
nmzik,claxten10Change: Bug fix
Merge Risk:
Minimal · up to
a4a8fMesh draws that exceed the host's workgroup limits are now split into slices that keep their original group and instance IDs. No concrete merge-blocking risk was found. The indirect task path is unchanged, and the new slicing logic has dedicated tests.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the main change: direct mesh draws that exceed host workgroup limits are split into slices. The changeset adds ForEachMeshSlice, uses it in renderDraw.cpp, and adds shader push-data dwords for slice start offsets, which matches the title.
Full details: Description check
Explanation
The description is detailed and on-topic. It explains the problem (host workgroup limits in direct mesh draws), the split approach via ForEachMeshSlice, the new PushData mesh base dwords, the shader prolog changes, the unchanged indirect task path, and the tests added in shader_cfg_tests.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
4436890a-a7c3-44ed-a378-c6794f338b4cReviewing files that changed from the base of the PR and between
2638b1b076anda4a8fa5d30.src/graphics/host_gpu/renderer/meshSlices.hsrc/graphics/host_gpu/renderer/renderDraw.cppsrc/graphics/host_gpu/shaders/gpu_mesh_indirect.tasksrc/graphics/shader/recompiler/frontend/translate/Translate.cppsrc/graphics/shader/recompiler/ir/ShaderIR.htests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.