renderer: split oversized mesh draws into host-limit slices #793
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!793
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-793"
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?
@prompterror on GitHub · 2026-09-23 19:39 UTC · original
prompterror:mesh-draw-split-limits→main· +292 −26 · 7 files · 4 commits · openFixes #624
Problem
Mesh draws are replayed as a single
drawMeshTasksEXT(groups, instances, 1). Hosts limit each workgroup-count dimension as well as the total number of workgroups (VkPhysicalDeviceMeshShaderPropertiesEXT), and guest draws can exceed those limits. Astro's Playroom hitsmesh draw exceeds host workgroup limits: 1x68734on AMD (68,734 instances > 65535/65535/65535), which hard-crashes the emulator withEXIT.Fix
Split the oversized workgroup grid into slices that fit every reported host limit and replay the draw as one
drawMeshTasksEXTper slice. Each slice adjusts the mesh push constants so the mesh shader sees exactly what a single oversized dispatch would have provided:first_instancedword, sogl_WorkGroupID.ystill maps to the correct absolute instance.PushData::MeshDrawDwordCount6 → 7) and added togl_WorkGroupID.xin the mesh prolog. Since the primitive range, fan center / strip-winding parity and chunk math all derive fromprimitive_chunk = (base_group + gl_WorkGroupID.x) * primitives_per_group, these stay globally consistent across slices.Implementation
src/graphics/host_gpu/renderer/meshDispatch.h: newSplitMeshDispatchhelper that produces slices respecting the per-dimension and total-count limits.src/graphics/host_gpu/renderer/renderDraw.cpp: replaces the hardEXITwith the sliced loop; each slice pushes its own constants then dispatches.src/graphics/shader/recompiler/frontend/translate/Translate.cpp: mesh prolog adds the base-group dword to the primitive-chunk computation.src/graphics/shader/recompiler/ir/ShaderIR.h:MeshDrawDwordCount6 → 7.tests/MeshDispatchTests.cpp: unit test for the new helper covering the in-limits case, the reported1x68734case, group-dimension overflow, total-count capping, degenerate counts, and zero/tiny host limits.Verification
mesh_dispatch_testspasses.shader_cfg_teststarget builds cleanly (all TUs, no new warnings).Mesh draws are dispatched as drawMeshTasksEXT(groups, instances, 1), and drivers limit each dimension as well as the total workgroup count. Guest draws can exceed these (e.g. Astro's Playroom issues 1x68734, beyond the 65535 per-dimension limit), which previously crashed the emulator with 'mesh draw exceeds host workgroup limits'. Split the workgroup grid into slices that fit every host limit and replay the draw as one drawMeshTasksEXT per slice. Each slice adjusts the mesh push constants: - instance offset is folded into the draw's first instance, so gl_WorkGroupID.y still maps to the correct absolute instance; - the base group is passed in a new push-constant dword and added to gl_WorkGroupID.x in the mesh prolog, keeping the primitive range, fan centers, strip winding and index math globally consistent. Adds MeshDispatchSlice/SplitMeshDispatch with a unit test covering the per-dimension, total-count and degenerate cases.@coderabbitai[bot] on GitHub · 2026-09-23 19:48 UTC · original · edited 2026-09-24 15:38 UTC
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
📝 Walkthrough
Walkthrough
Mesh dispatches are divided into slices that fit the host’s axis and total workgroup limits. The renderer dispatches each slice with its group and instance offsets. Mesh shader translation adds the slice base group to
WorkgroupId(0), and the mesh draw push-data count increases from six to seven dwords. CTest builds and runs the mesh dispatch tests, including checks for non-dividing strides and trailing remainders.Merge Risk: 🔵 Low · up to
8b99dSlice offsets appear consistent across the draw path. Add a nonzero-base mesh test to protect that behavior; the remaining test gap is bounded and does not block merging.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
#624requires oversized mesh draws to avoid host workgroup-limit crashes.SplitMeshDispatchcreates slices within the X, Y, and total limits, including the1 x 68734case. `ExecutePreparedDr…#624. They implement mesh dispatch slicing, preserve mesh shader indexing, update the mesh push-constant layout, and add automated coverage. No unrelated change is esta…Full details: Docstring Coverage
Explanation
Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 19 functions across 5 files. (1 skipped: 1 too large.)
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-09-23 19:48 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
f46d5354-1495-45ba-8cd3-4affb1529178📥 Commits
Reviewing files that changed from the base of the PR and between
569ec04d1aandf5b5ecd97e.📒 Files selected for processing (6)
CMakeLists.txtsrc/graphics/host_gpu/renderer/meshDispatch.hsrc/graphics/host_gpu/renderer/renderDraw.cppsrc/graphics/shader/recompiler/frontend/translate/Translate.cppsrc/graphics/shader/recompiler/ir/ShaderIR.htests/MeshDispatchTests.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -414,0 +414,4 @@add_executable(mesh_dispatch_tests EXCLUDE_FROM_ALL"${KYTY_TESTS_DIR}/MeshDispatchTests.cpp")target_include_directories(mesh_dispatch_tests PRIVATE ${inc_headers})@coderabbitai[bot] on GitHub · 2026-09-23 19:48 UTC · original · edited 2026-09-24 13:00 UTC
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11624
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 10804
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5206
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5944
Add
mesh_dispatch_teststokyty_tests.mesh_dispatch_testsis excluded from the default build and is missing fromkyty_tests, although CTest registersmesh_dispatch. A build ofkyty_testscan therefore leave the executable absent, causing CTest to report the test as not run. The header include path is already correct because${inc_headers}contains${KYTY_SOURCE_DIR}.Suggested fix
Source: Learnings
✅ Addressed in commit
43c6481@coderabbitai[bot] on GitHub · 2026-09-24 13:06 UTC · original · reviewed
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
72361786-5e9b-4181-9d4d-b314ce2f2991📥 Commits
Reviewing files that changed from the base of the PR and between
f5b5ecd97eand43c64817f6.📒 Files selected for processing (1)
CMakeLists.txt🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@coderabbitai[bot] on GitHub · 2026-09-24 14:17 UTC · original · reviewed
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
db86f831-159a-45f0-9fcb-ac253412f69e📥 Commits
Reviewing files that changed from the base of the PR and between
43c64817f6andbe7a0078da.📒 Files selected for processing (2)
src/graphics/host_gpu/renderer/meshDispatch.htests/MeshDispatchTests.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@prompterror on GitHub · 2026-09-24 14:20 UTC · original
Real-hardware validation (RTX 3060 Ti)
Since this PR's whole point is to keep dispatch counts within host limits, I ran a throwaway Vulkan harness that replays the splitter's output against the real GPU. It
#includes the branch'smeshDispatch.hdirectly (same code path the emulator uses), splits each scenario with the actual device limits, issues every slice viadrawMeshTasksEXT, and a mesh shader atomic-increments one probe per(group, instance)cell using the slice's base offsets. A final value of exactly 1 per cell proves the driver accepted every slice with no gaps and no overlaps.Host: RTX 3060 Ti, NVIDIA 595.84 —
maxMeshWorkGroupCount = {4194304, 65535, 65535},maxMeshWorkGroupTotalCount = 4194304.Notes:
4,194,305 > 4,194,304) plus the total-limit cap on the first chunk, and S2 exercises the total-limit instance capping with the X dimension exactly at its limit./tmp), not part of this PR; happy to share the source on request.be7a007).@prompterror on GitHub · 2026-09-24 15:29 UTC · original
Addressed in
8b99d63:🟠 Major — "Advance counters by the consumed chunk" (
meshDispatch.h): both loops now advance by the count they actually emitted instead of the raw stride.group += group_count/instance += instance_countwhere the counts aremin(stride, remaining), so each step consumes>= 1and can never wrap auint32counter —groups/instances == UINT32_MAXwith an odd size now terminates (it lands exactly onUINT32_MAXand the loop condition fails) instead of wrapping forever.🟡 Minor — "Extend the mesh draw fixture to seven elements" (
shaderCfgTests.cpp):TestMeshInputAssembly'sdraw[]fixture now has the seventh element (0as the base group), removing the out-of-boundsdraw[6]read in the mesh translation path.Also added
TestNonDividingStridesConsumeExactRemainderstoMeshDispatchTests.cpp, pinning the exact-remainder semantics that termination relies on (the fullUINT32_MAXinput can't be enumerated in a unit test, but the consumed-count behavior it depends on is covered).Checks on this state (
8b99d63):mesh_dispatch_tests,shader_cfg_tests: passgit clang-format: clean@ -9960,2 +9960,2 @@const uint32_t draw[] = {test.count, test.base_vertex, 7, test.width,test.address_low, 0x12};const uint32_t draw[] = {test.count, test.base_vertex, 7, test.width, test.address_low, 0x12, 0};@coderabbitai[bot] on GitHub · 2026-09-24 15:38 UTC · original
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8484
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41595
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 16597
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8281
Add a nonzero slice base group to the mesh translation fixture.
draw[6]is always zero inTestMeshInputAssembly. The fixture therefore cannot detect a regression that ignores the slice base group. Add one case with a nonzero base group and assert the shifted vertex result.Suggested fix
@coderabbitai[bot] on GitHub · 2026-09-24 15:38 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
afc8b288-8986-4892-a936-e6b04c96dc31📥 Commits
Reviewing files that changed from the base of the PR and between
be7a0078daand8b99d6393c.📒 Files selected for processing (3)
src/graphics/host_gpu/renderer/meshDispatch.htests/MeshDispatchTests.cpptests/shaderCfgTests.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ZrDaniel07 on GitHub · 2026-10-24 01:49 UTC · original
The draw from #624 also aborts on an RTX 5090 (driver 617.42, Windows 11) in ASTRO BOT (PPSA21564 01.007.000), in the Garden level:
1x76426and1x65674in two runs, againstmaxMeshWorkGroupCount = 4194304, 65535, 65535andmaxMeshWorkGroupTotalCount = 4194304. One group, so only the instance count is over the limit.This PR no longer applies to current
main:CMakeLists.txt,renderDraw.cppandTranslate.cppconflict, and the mesh draw push constants have moved (UserClipPlaneDwordnow followsMeshDrawDwordCount).For this case, splitting only the instances was enough on current code, without a shader change: the mesh prolog already computes the instance as
draw(2) + WorkgroupId.y, so the draw is repeated in slices ofmin(maxMeshWorkGroupCount[1], maxMeshWorkGroupTotalCount / groups)instances, pushing dword 2 again (first_instance + done) before every slice after the first. With that local patch the level renders (the flamingos and foliage look right) and I got into gameplay. A group count overmaxMeshWorkGroupCount[0]still aborts; that part needs the base-group dword from this PR.Local patch (on top of
main@6aaa533+ #838 + other test fixes)One run with the patch so far, and the shader tests don't cover mesh draws.
AI use: Claude Code wrote the local patch and compared it with this PR with me; I ran the game and checked the outputs myself.
@ZrDaniel07 on GitHub · 2026-10-26 20:35 UTC · original
@prompterror heads-up:
mainf90a8b15changed two things this PR depends on.943bc19ftook the start instance out of the mesh instance ID VGPRs. Pushingfirst_instance + doneinto dword 2 no longer moves the instance, so later slices would repeat instances 0..N.560756f3only skips mesh shaders that exceed the host limits. ASTRO BOT's Garden still exits withmesh draw exceeds host workgroup limits: 1x65666.I reworked the slicing for the new base: a 6th mesh draw dword holds the slice's first instance (0 normally), and the shader adds it to
gl_WorkGroupID.y. With it the Garden loads and plays on an RTX 5090 (3 runs, no exit). The diff is in my #745 comment. Feel free to take it into this PR if it fits.AI use: Claude Code wrote the v2 patch with me; I ran the game.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.