renderer: split oversized mesh draws into host-limit slices #793

Open
github-bot wants to merge 4 commits from github-bot/gh-793 into main AGit
Owner

@⁠prompterror on GitHub · 2026-09-23 19:39 UTC · original
prompterror:mesh-draw-split-limits → main · +292 −26 · 7 files · 4 commits · open

Fixes #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 hits mesh draw exceeds host workgroup limits: 1x68734 on AMD (68,734 instances > 65535/65535/65535), which hard-crashes the emulator with EXIT.

Fix

Split the oversized workgroup grid into slices that fit every reported host limit and replay the draw as one drawMeshTasksEXT per slice. Each slice adjusts the mesh push constants so the mesh shader sees exactly what a single oversized dispatch would have provided:

  • The slice's instance offset is folded into the draw's first_instance dword, so gl_WorkGroupID.y still maps to the correct absolute instance.
  • The slice's base group is carried in a new push-constant dword (PushData::MeshDrawDwordCount 6 → 7) and added to gl_WorkGroupID.x in the mesh prolog. Since the primitive range, fan center / strip-winding parity and chunk math all derive from primitive_chunk = (base_group + gl_WorkGroupID.x) * primitives_per_group, these stay globally consistent across slices.

Implementation

  • src/graphics/host_gpu/renderer/meshDispatch.h: new SplitMeshDispatch helper that produces slices respecting the per-dimension and total-count limits.
  • src/graphics/host_gpu/renderer/renderDraw.cpp: replaces the hard EXIT with 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: MeshDrawDwordCount 6 → 7.
  • tests/MeshDispatchTests.cpp: unit test for the new helper covering the in-limits case, the reported 1x68734 case, group-dimension overflow, total-count capping, degenerate counts, and zero/tiny host limits.

Verification

  • New unit test mesh_dispatch_tests passes.
  • Full shader_cfg_tests target builds cleanly (all TUs, no new warnings).
  • Mesh pipeline push-constant block is the full 32-dword array, so reading dword 6 is in bounds; the pipeline layout's 128-byte range is unchanged.
  • Cannot run Astro's Playroom on this machine, so GPU verification of rendered output is left to the reporter / CI.
**@⁠prompterror** on GitHub · 2026-09-23 19:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/793) `prompterror:mesh-draw-split-limits` → `main` · +292 −26 · 7 files · 4 commits · open Fixes #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 hits `mesh draw exceeds host workgroup limits: 1x68734` on AMD (68,734 instances > 65535/65535/65535), which hard-crashes the emulator with `EXIT`. ## Fix Split the oversized workgroup grid into slices that fit every reported host limit and replay the draw as one `drawMeshTasksEXT` per slice. Each slice adjusts the mesh push constants so the mesh shader sees exactly what a single oversized dispatch would have provided: - The slice's instance offset is folded into the draw's `first_instance` dword, so `gl_WorkGroupID.y` still maps to the correct absolute instance. - The slice's base group is carried in a new push-constant dword (`PushData::MeshDrawDwordCount` 6 → 7) and added to `gl_WorkGroupID.x` in the mesh prolog. Since the primitive range, fan center / strip-winding parity and chunk math all derive from `primitive_chunk = (base_group + gl_WorkGroupID.x) * primitives_per_group`, these stay globally consistent across slices. ## Implementation - `src/graphics/host_gpu/renderer/meshDispatch.h`: new `SplitMeshDispatch` helper that produces slices respecting the per-dimension and total-count limits. - `src/graphics/host_gpu/renderer/renderDraw.cpp`: replaces the hard `EXIT` with 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`: `MeshDrawDwordCount` 6 → 7. - `tests/MeshDispatchTests.cpp`: unit test for the new helper covering the in-limits case, the reported `1x68734` case, group-dimension overflow, total-count capping, degenerate counts, and zero/tiny host limits. ## Verification - New unit test `mesh_dispatch_tests` passes. - Full `shader_cfg_tests` target builds cleanly (all TUs, no new warnings). - Mesh pipeline push-constant block is the full 32-dword array, so reading dword 6 is in bounds; the pipeline layout's 128-byte range is unchanged. - Cannot run Astro's Playroom on this machine, so GPU verification of rendered output is left to the reporter / CI.
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.
The splitter test was previously only built when its target was requested
directly, so a build of kyty_tests left it absent and CTest reported the
mesh_dispatch test as not run.
A host can report maxMeshWorkGroupCount[0] above maxMeshWorkGroupTotalCount,
in which case a single group slice could exceed the total product limit on
its own (the instance-dimension cap cannot go below one). Cap each group
chunk by the total limit as well.

Adds a regression test for the (4, 1, 4, 1, 3) case flagged in review plus
a mixed-dimension case; both previously produced slices whose product
exceeded the total limit.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:32:30 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-23 19:48 UTC · original · edited 2026-09-24 15:38 UTC

Review in Change Stack →

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 8b99d

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

Check name Status Explanation Resolution
Docstring Coverage ❓ Inconclusive 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: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: splitting oversized mesh draws into host-limit-compatible slices.
Description check ✅ Passed The description is directly related to the changeset and explains the problem, implementation, affected files, tests, and verification status.
Linked Issues check ✅ Passed Issue #624 requires oversized mesh draws to avoid host workgroup-limit crashes. SplitMeshDispatch creates slices within the X, Y, and total limits, including the 1 x 68734 case. `ExecutePreparedDr…
Out of Scope Changes check ✅ Passed The changed files support issue #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 help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-23 19:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/793#issuecomment-5801807648) · edited 2026-09-24 15:38 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/793"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## 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. </details> <!-- walkthrough_end --> <!-- final_review_risk_start --> **Merge Risk:** _🔵 Low_ · up to `8b99d` <!-- final_review_risk_coverage:{"sourceCommitId":"8b99d6393c18475e56c92e9d712f68b84a2baafc","coveredCommitId":"8b99d6393c18475e56c92e9d712f68b84a2baafc","kind":"reviewed"} --> Slice 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. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 inconclusive) | Check name | Status | Explanation | Resolution | | :----------------: | :------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ❓ Inconclusive | 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: … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly and concisely describes the main change: splitting oversized mesh draws into host-limit-compatible slices. | | Description check | ✅ Passed | The description is directly related to the changeset and explains the problem, implementation, affected files, tests, and verification status. | | Linked Issues check | ✅ Passed | Issue `#624` requires oversized mesh draws to avoid host workgroup-limit crashes. `SplitMeshDispatch` creates slices within the X, Y, and total limits, including the `1 x 68734` case. `ExecutePreparedDr… | | Out of Scope Changes check | ✅ Passed | The changed files support issue `#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… | </details> <details> <summary>Full details: Docstring Coverage</summary> **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.) </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- <sub>Comment `@⁠coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠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 569ec04d1a and f5b5ecd97e.

📒 Files selected for processing (6)
  • CMakeLists.txt
  • src/graphics/host_gpu/renderer/meshDispatch.h
  • src/graphics/host_gpu/renderer/renderDraw.cpp
  • src/graphics/shader/recompiler/frontend/translate/Translate.cpp
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • tests/MeshDispatchTests.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-23 19:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/793#pullrequestreview-5295990312) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `f46d5354-1495-45ba-8cd3-4affb1529178` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 569ec04d1a77127c601eed522ad5bba187173f9d and f5b5ecd97e652c0b2ce2f1f0e15cd3ab70b57d2a. </details> <details> <summary>📒 Files selected for processing (6)</summary> * `CMakeLists.txt` * `src/graphics/host_gpu/renderer/meshDispatch.h` * `src/graphics/host_gpu/renderer/renderDraw.cpp` * `src/graphics/shader/recompiler/frontend/translate/Translate.cpp` * `src/graphics/shader/recompiler/ir/ShaderIR.h` * `tests/MeshDispatchTests.cpp` </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 9 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -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})
Author
Owner

@⁠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:

#!/bin/bash
rg -n -C3 'inc_headers' CMakeLists.txt | head -60
rg -n -C2 'EXCLUDE_FROM_ALL|add_test|add_dependencies|BUILD_TESTING' CMakeLists.txt

Repository: KytyPS5/KytyPS5

Length of output: 11624


🏁 Script executed:

#!/bin/bash
printf '%s\n' '--- CMake test aggregate and nearby test registration ---'
sed -n '500,655p' CMakeLists.txt
printf '%s\n' '--- exact target references ---'
rg -n -C4 'kyty_tests|mesh_dispatch_tests|mesh_dispatch' CMakeLists.txt
printf '%s\n' '--- changed files and relevant source include ---'
rg -n -C3 '`#include`[[:space:]]*[<"]graphics/host_gpu/renderer/meshDispatch\.h[">]' tests src CMakeLists.txt 2>/dev/null

Repository: KytyPS5/KytyPS5

Length of output: 10804


🏁 Script executed:

#!/bin/bash
sed -n '450,545p' CMakeLists.txt
printf '%s\n' '--- exact kyty_tests references in repository CMake files ---'
rg -n -C3 'kyty_tests' -g 'CMakeLists.txt' -g '*.cmake' .

Repository: KytyPS5/KytyPS5

Length of output: 5206


🏁 Script executed:

printf '%s\n' '--- aggregate section ---'; sed -n '450,545p' CMakeLists.txt; printf '%s\n' '--- aggregate references ---'; rg -n -C2 'kyty_tests|mesh_dispatch_tests|mesh_dispatch' . -g 'CMakeLists.txt' -g '*.cmake' -g '*.cpp' -g '*.h'

Repository: KytyPS5/KytyPS5

Length of output: 5944


Add mesh_dispatch_tests to kyty_tests.

mesh_dispatch_tests is excluded from the default build and is missing from kyty_tests, although CTest registers mesh_dispatch. A build of kyty_tests can 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
 	add_custom_target(kyty_tests DEPENDS
 		ime_dialog_tests
 		shader_cfg_tests
 		scalar_provenance_tests
 		image_page_table_tests
 		memory_tracker_tests
 		page_manager_tests
 		bit_array_tests
+		mesh_dispatch_tests
 		shader_vertex_metadata_tests

Source: Learnings

✅ Addressed in commit 43c6481

**@⁠coderabbitai[bot]** on GitHub · 2026-09-23 19:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/793#discussion_r4086629215) · edited 2026-09-24 13:00 UTC _🩺 Stability & Availability_ | _🟡 Minor_ | _⚡ Quick win_ <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash rg -n -C3 'inc_headers' CMakeLists.txt | head -60 rg -n -C2 'EXCLUDE_FROM_ALL|add_test|add_dependencies|BUILD_TESTING' CMakeLists.txt ``` Repository: KytyPS5/KytyPS5 Length of output: 11624 --- 🏁 Script executed: ```bash #!/bin/bash printf '%s\n' '--- CMake test aggregate and nearby test registration ---' sed -n '500,655p' CMakeLists.txt printf '%s\n' '--- exact target references ---' rg -n -C4 'kyty_tests|mesh_dispatch_tests|mesh_dispatch' CMakeLists.txt printf '%s\n' '--- changed files and relevant source include ---' rg -n -C3 '`#include`[[:space:]]*[<"]graphics/host_gpu/renderer/meshDispatch\.h[">]' tests src CMakeLists.txt 2>/dev/null ``` Repository: KytyPS5/KytyPS5 Length of output: 10804 --- 🏁 Script executed: ```bash #!/bin/bash sed -n '450,545p' CMakeLists.txt printf '%s\n' '--- exact kyty_tests references in repository CMake files ---' rg -n -C3 'kyty_tests' -g 'CMakeLists.txt' -g '*.cmake' . ``` Repository: KytyPS5/KytyPS5 Length of output: 5206 --- 🏁 Script executed: ```bash printf '%s\n' '--- aggregate section ---'; sed -n '450,545p' CMakeLists.txt; printf '%s\n' '--- aggregate references ---'; rg -n -C2 'kyty_tests|mesh_dispatch_tests|mesh_dispatch' . -g 'CMakeLists.txt' -g '*.cmake' -g '*.cpp' -g '*.h' ``` Repository: KytyPS5/KytyPS5 Length of output: 5944 --- </details> **Add `mesh_dispatch_tests` to `kyty_tests`.** `mesh_dispatch_tests` is excluded from the default build and is missing from `kyty_tests`, although CTest registers `mesh_dispatch`. A build of `kyty_tests` can 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}`. <details> <summary>Suggested fix</summary> ```diff add_custom_target(kyty_tests DEPENDS ime_dialog_tests shader_cfg_tests scalar_provenance_tests image_page_table_tests memory_tracker_tests page_manager_tests bit_array_tests + mesh_dispatch_tests shader_vertex_metadata_tests ``` </details> <!-- coderabbit-global-learning v1 gid=b2ef6c45a49333c3 scope=framework --> <!-- fingerprinting:phantom:medusa:pangolin --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:fcb9036c0715d43e44d12f2c --> _Source: Learnings_ <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 43c6481
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-24 13:06 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Clamp the group stride to the total workgroup limit. · meshDispatch.h:43-61

src/graphics/host_gpu/renderer/meshDispatch.h:43-61
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Clamp the group stride to the total workgroup limit.

When maxMeshWorkGroupCount[0] exceeds maxMeshWorkGroupTotalCount, SplitMeshDispatch can produce a 4 x 1 slice for (4, 1, 4, 1, 3). The max(1u, total_limit / group_count) fallback forces one instance even though the product remains above the total limit. renderDraw.cpp submits that slice through drawMeshTasksEXT, which violates Vulkan's product limit. Clamp the group stride before generating slices.

Suggested fix
-	const uint32_t group_stride    = std::max(1u, max_groups);
-	const uint32_t instance_stride = std::max(1u, max_instances);
 	const uint32_t total_limit     = std::max(1u, max_total);
+	const uint32_t group_stride    = std::min(std::max(1u, max_groups), total_limit);
+	const uint32_t instance_stride = std::max(1u, max_instances);

ℹ️ 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 f5b5ecd97e and 43c64817f6.

📒 Files selected for processing (1)
  • CMakeLists.txt
🚧 Files skipped from review as they are similar to previous changes (1)
  • CMakeLists.txt

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 13:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/793#pullrequestreview-5304818556) · **reviewed** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><em>🟡 Minor</em> · Clamp the group stride to the total workgroup limit. · <code>meshDispatch.h:43-61</code></summary><blockquote> > > `src/graphics/host_gpu/renderer/meshDispatch.h:43-61` > _🎯 Functional Correctness_ | _🟡 Minor_ | _⚡ Quick win_ > > **Clamp the group stride to the total workgroup limit.** > > When `maxMeshWorkGroupCount[0]` exceeds `maxMeshWorkGroupTotalCount`, `SplitMeshDispatch` can produce a `4 x 1` slice for `(4, 1, 4, 1, 3)`. The `max(1u, total_limit / group_count)` fallback forces one instance even though the product remains above the total limit. `renderDraw.cpp` submits that slice through `drawMeshTasksEXT`, which violates Vulkan's product limit. Clamp the group stride before generating slices. > > <details> > <summary>Suggested fix</summary> > > ```diff > - const uint32_t group_stride = std::max(1u, max_groups); > - const uint32_t instance_stride = std::max(1u, max_instances); > const uint32_t total_limit = std::max(1u, max_total); > + const uint32_t group_stride = std::min(std::max(1u, max_groups), total_limit); > + const uint32_t instance_stride = std::max(1u, max_instances); > ``` > > </details> > > <!-- cr-comment:v1:532a1f893d0f3cdc2235ac44 --> > > </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `72361786-5e9b-4181-9d4d-b314ce2f2991` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between f5b5ecd97e652c0b2ce2f1f0e15cd3ab70b57d2a and 43c64817f6cac787447ba30adbeba0a7726f07f1. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `CMakeLists.txt` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary> * CMakeLists.txt </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 9 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-24 14:17 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (2)

🟠 Major · Advance counters by the consumed chunk. · meshDispatch.h:50-63

src/graphics/host_gpu/renderer/meshDispatch.h:50-63
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Advance counters by the consumed chunk.

When groups == UINT32_MAX, the outer counter wraps if the effective group_stride does not divide UINT32_MAX. The same condition applies to instance_chunk when instances == UINT32_MAX. Host limits pass directly into these effective chunks, so a value such as 2 is possible. Because UINT32_MAX is odd, a chunk of 2 wraps and never reaches the terminating value. SplitMeshDispatch can then keep appending slices.

Use the actual consumed count for each iteration.

🐛 Suggested fix
-	for (uint32_t group = 0u; group < groups; group += group_stride) {
+	for (uint32_t group = 0u; group < groups;) {
		const uint32_t group_count = std::min(group_stride, groups - group);
		// The total-limit cap is shared with the instance dimension. When the
		// remaining instance range already fits under that cap together with
		// this group chunk, keep it in one chunk.
		uint32_t instance_chunk = instance_stride;
		if (static_cast<uint64_t>(group_count) * instances > total_limit) {
			instance_chunk = std::max(1u, total_limit / group_count);
			instance_chunk = std::min(instance_chunk, instance_stride);
		}
-		for (uint32_t instance = 0u; instance < instances; instance += instance_chunk) {
+		for (uint32_t instance = 0u; instance < instances;) {
+			const uint32_t instance_count = std::min(instance_chunk, instances - instance);
			slices.push_back(
-			    {group, group_count, instance, std::min(instance_chunk, instances - instance)});
+			    {group, group_count, instance, instance_count});
+			instance += instance_count;
		}
+		group += group_count;
	}
🟡 Minor · Extend the mesh draw fixture to seven elements. · Translate.cpp:1080-1086

src/graphics/shader/recompiler/frontend/translate/Translate.cpp:1080-1086
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Extend the mesh draw fixture to seven elements.

TestMeshInputAssembly reaches the mesh translation path and substitutes every MeshDrawParameter with draw[inst.Arg(0).U32()]. The new draw(6) access indexes past the six-element fixture, causing undefined behavior and possible test failure.

Suggested fix
-    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};

ℹ️ 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 43c64817f6 and be7a0078da.

📒 Files selected for processing (2)
  • src/graphics/host_gpu/renderer/meshDispatch.h
  • tests/MeshDispatchTests.cpp

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](https://github.com/KytyPS5/KytyPS5/pull/793#pullrequestreview-5305677531) · **reviewed** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (2)** > > <details> > <summary><em>🟠 Major</em> · Advance counters by the consumed chunk. · <code>meshDispatch.h:50-63</code></summary><blockquote> > > `src/graphics/host_gpu/renderer/meshDispatch.h:50-63` > _🩺 Stability & Availability_ | _🟠 Major_ | _⚡ Quick win_ > > **Advance counters by the consumed chunk.** > > When `groups == UINT32_MAX`, the outer counter wraps if the effective `group_stride` does not divide `UINT32_MAX`. The same condition applies to `instance_chunk` when `instances == UINT32_MAX`. Host limits pass directly into these effective chunks, so a value such as `2` is possible. Because `UINT32_MAX` is odd, a chunk of `2` wraps and never reaches the terminating value. `SplitMeshDispatch` can then keep appending slices. > > Use the actual consumed count for each iteration. > > <details> > <summary>🐛 Suggested fix</summary> > > ```diff > - for (uint32_t group = 0u; group < groups; group += group_stride) { > + for (uint32_t group = 0u; group < groups;) { > const uint32_t group_count = std::min(group_stride, groups - group); > // The total-limit cap is shared with the instance dimension. When the > // remaining instance range already fits under that cap together with > // this group chunk, keep it in one chunk. > uint32_t instance_chunk = instance_stride; > if (static_cast<uint64_t>(group_count) * instances > total_limit) { > instance_chunk = std::max(1u, total_limit / group_count); > instance_chunk = std::min(instance_chunk, instance_stride); > } > - for (uint32_t instance = 0u; instance < instances; instance += instance_chunk) { > + for (uint32_t instance = 0u; instance < instances;) { > + const uint32_t instance_count = std::min(instance_chunk, instances - instance); > slices.push_back( > - {group, group_count, instance, std::min(instance_chunk, instances - instance)}); > + {group, group_count, instance, instance_count}); > + instance += instance_count; > } > + group += group_count; > } > ``` > > </details> > > <!-- cr-comment:v1:6d8226c9905cbd11d26c3c95 --> > > </blockquote></details> > <details> > <summary><em>🟡 Minor</em> · Extend the mesh draw fixture to seven elements. · <code>Translate.cpp:1080-1086</code></summary><blockquote> > > `src/graphics/shader/recompiler/frontend/translate/Translate.cpp:1080-1086` > _🩺 Stability & Availability_ | _🟡 Minor_ | _⚡ Quick win_ > > **Extend the mesh draw fixture to seven elements.** > > `TestMeshInputAssembly` reaches the mesh translation path and substitutes every `MeshDrawParameter` with `draw[inst.Arg(0).U32()]`. The new `draw(6)` access indexes past the six-element fixture, causing undefined behavior and possible test failure. > > <details> > <summary>Suggested fix</summary> > > ```diff > - 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}; > ``` > > </details> > > <!-- cr-comment:v1:ebab6fb2b1d44aac192b25ef --> > > </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `db86f831-159a-45f0-9fcb-ac253412f69e` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 43c64817f6cac787447ba30adbeba0a7726f07f1 and be7a0078da6bd7cb92aef10b56739cd188fb96ef. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/graphics/host_gpu/renderer/meshDispatch.h` * `tests/MeshDispatchTests.cpp` </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 9 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Author
Owner

@⁠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's meshDispatch.h directly (same code path the emulator uses), splits each scenario with the actual device limits, issues every slice via drawMeshTasksEXT, 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.

Scenario Guest draw Slices Cells Verified
S0 sanity 100 × 50 1 5,000 ✅
S1 (#624 shape) 1 × 68,734 2 68,734 ✅
S2 at X-limit, product > total 4,194,304 × 5 5 20,971,520 ✅
S3 past X-limit 4,194,305 × 2 3 8,388,610 ✅

Notes:

  • S1 mirrors issue #624's trigger: this host's Y-limit is 65,535, so the raw 68,734-instance draw would be invalid — the splitter turns it into two valid draws (65,535 + 3,199) that cover the grid exactly once.
  • S3 exercises the X-dimension slice (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.
  • Harness is throwaway (out-of-repo, in /tmp), not part of this PR; happy to share the source on request.
  • All checks green under the latest branch state (be7a007).
**@⁠prompterror** on GitHub · 2026-09-24 14:20 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/793#issuecomment-5815917050) ## 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 `#include`s the branch's `meshDispatch.h` directly (same code path the emulator uses), splits each scenario with the **actual** device limits, issues every slice via `drawMeshTasksEXT`, 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`. | Scenario | Guest draw | Slices | Cells | Verified | |---|---|---|---|---| | S0 sanity | 100 × 50 | 1 | 5,000 | ✅ | | S1 (#624 shape) | 1 × 68,734 | 2 | 68,734 | ✅ | | S2 at X-limit, product > total | 4,194,304 × 5 | 5 | 20,971,520 | ✅ | | S3 past X-limit | 4,194,305 × 2 | 3 | 8,388,610 | ✅ | Notes: - **S1 mirrors issue #624's trigger**: this host's Y-limit is 65,535, so the raw 68,734-instance draw would be invalid — the splitter turns it into two valid draws (65,535 + 3,199) that cover the grid exactly once. - **S3 exercises the X-dimension slice** (`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. - Harness is throwaway (out-of-repo, in `/tmp`), not part of this PR; happy to share the source on request. - All checks green under the latest branch state (`be7a007`).
Author
Owner

@⁠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_count where the counts are min(stride, remaining), so each step consumes >= 1 and can never wrap a uint32 counter — groups/instances == UINT32_MAX with an odd size now terminates (it lands exactly on UINT32_MAX and the loop condition fails) instead of wrapping forever.

🟡 Minor — "Extend the mesh draw fixture to seven elements" (shaderCfgTests.cpp): TestMeshInputAssembly's draw[] fixture now has the seventh element (0 as the base group), removing the out-of-bounds draw[6] read in the mesh translation path.

Also added TestNonDividingStridesConsumeExactRemainders to MeshDispatchTests.cpp, pinning the exact-remainder semantics that termination relies on (the full UINT32_MAX input 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: pass
  • Full build: clean; git clang-format: clean
  • Re-ran the real-hardware harness from the previous comment against the updated header: identical slicing output, still all-green (every slice dispatched at the actual RTX 3060 Ti limits, grid covered exactly once)
**@⁠prompterror** on GitHub · 2026-09-24 15:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/793#issuecomment-5817113040) 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_count` where the counts are `min(stride, remaining)`, so each step consumes `>= 1` and can never wrap a `uint32` counter — `groups`/`instances == UINT32_MAX` with an odd size now terminates (it lands exactly on `UINT32_MAX` and the loop condition fails) instead of wrapping forever. **🟡 Minor — "Extend the mesh draw fixture to seven elements"** (`shaderCfgTests.cpp`): `TestMeshInputAssembly`'s `draw[]` fixture now has the seventh element (`0` as the base group), removing the out-of-bounds `draw[6]` read in the mesh translation path. Also added `TestNonDividingStridesConsumeExactRemainders` to `MeshDispatchTests.cpp`, pinning the exact-remainder semantics that termination relies on (the full `UINT32_MAX` input 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`: pass - Full build: clean; `git clang-format`: clean - Re-ran the real-hardware harness from the previous comment against the updated header: identical slicing output, still all-green (every slice dispatched at the actual RTX 3060 Ti limits, grid covered exactly once)
@ -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};
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-24 15:38 UTC · original

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '9900,10025p' tests/shaderCfgTests.cpp
rg -n 'draw\(6\)|MeshDrawDwordCount|base.group|base_group|SplitMeshDispatch' tests src/graphics/shader/recompiler/frontend/translate/Translate.cpp

Repository: KytyPS5/KytyPS5

Length of output: 8484


🏁 Script executed:

set -eu
printf '%s\n' '--- PR diff for target file and translation ---'
git diff --unified=30 569ec04d1a77127c601eed522ad5bba187173f9d 8b99d6393c18475e56c92e9d712f68b84a2baafc -- tests/shaderCfgTests.cpp src/graphics/shader/recompiler/frontend/translate/Translate.cpp tests/MeshDispatchTests.cpp
printf '%s\n' '--- fixture declarations and cases ---'
sed -n '9760,9975p' tests/shaderCfgTests.cpp
printf '%s\n' '--- translation implementation ---'
sed -n '1040,1105p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp
printf '%s\n' '--- mesh dispatch tests and implementation references ---'
sed -n '1,180p' tests/MeshDispatchTests.cpp
rg -n -C 4 'SplitMeshDispatch|WorkgroupId|MeshDrawParameter|draw\(6\)' src tests --glob '!tests/shaderCfgTests.cpp'

Repository: KytyPS5/KytyPS5

Length of output: 41595


🏁 Script executed:

set -eu
printf '%s\n' '--- TestMeshInputAssembly definition and assertions ---'
rg -n -B 8 -A 155 'void TestMeshInputAssembly' tests/shaderCfgTests.cpp
printf '%s\n' '--- all test references to mesh draw parameters and base-group fields ---'
rg -n -S 'MeshDrawParameter|draw\[6\]|MeshDrawDwordCount|base_group|base.group|group_offset|MeshDispatchSlice' --glob '*.{cpp,h,hpp,cc,cxx}' .
printf '%s\n' '--- draw parameter packing at the production caller ---'
sed -n '1010,1080p' src/graphics/host_gpu/renderer/renderDraw.cpp
printf '%s\n' '--- test registration for the relevant tests ---'
rg -n -S 'TestMeshInputAssembly|MeshDispatchTests|shaderCfgTests' CMakeLists.txt cmake tests src --glob 'CMakeLists.txt' --glob '*.cmake' --glob '*.cpp'

Repository: KytyPS5/KytyPS5

Length of output: 16597


🏁 Script executed:

set -eu
printf '%s\n' '--- mesh slice push-data construction ---'
sed -n '1128,1162p' src/graphics/host_gpu/renderer/renderDraw.cpp
printf '%s\n' '--- mesh translation downstream arithmetic ---'
sed -n '1080,1162p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp
printf '%s\n' '--- mesh draw push-data contract ---'
sed -n '276,300p' src/graphics/shader/recompiler/ir/ShaderIR.h
printf '%s\n' '--- focused diff metadata ---'
git diff --stat 569ec04d1a77127c601eed522ad5bba187173f9d 8b99d6393c18475e56c92e9d712f68b84a2baafc

Repository: KytyPS5/KytyPS5

Length of output: 8281


Add a nonzero slice base group to the mesh translation fixture.

draw[6] is always zero in TestMeshInputAssembly. 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
     uint32_t wave_info, first, second, third, byte_offset, vertex_id;
     bool fetch;
     uint32_t wave_size = 64;
+    uint32_t base_group = 0;
...
-       0x40000101, 0, 0, 0, 0, 11, false},
+       0x40000101, 0, 0, 0, 0, 12, false, 64, 1},
...
-        test.count, test.base_vertex, 7, test.width, test.address_low, 0x12, 0};
+        test.count, test.base_vertex, 7, test.width, test.address_low, 0x12,
+        test.base_group};
**@⁠coderabbitai[bot]** on GitHub · 2026-09-24 15:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/793#discussion_r4095461859) _🎯 Functional Correctness_ | _🟡 Minor_ | _⚡ Quick win_ <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '9900,10025p' tests/shaderCfgTests.cpp rg -n 'draw\(6\)|MeshDrawDwordCount|base.group|base_group|SplitMeshDispatch' tests src/graphics/shader/recompiler/frontend/translate/Translate.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 8484 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- PR diff for target file and translation ---' git diff --unified=30 569ec04d1a77127c601eed522ad5bba187173f9d 8b99d6393c18475e56c92e9d712f68b84a2baafc -- tests/shaderCfgTests.cpp src/graphics/shader/recompiler/frontend/translate/Translate.cpp tests/MeshDispatchTests.cpp printf '%s\n' '--- fixture declarations and cases ---' sed -n '9760,9975p' tests/shaderCfgTests.cpp printf '%s\n' '--- translation implementation ---' sed -n '1040,1105p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp printf '%s\n' '--- mesh dispatch tests and implementation references ---' sed -n '1,180p' tests/MeshDispatchTests.cpp rg -n -C 4 'SplitMeshDispatch|WorkgroupId|MeshDrawParameter|draw\(6\)' src tests --glob '!tests/shaderCfgTests.cpp' ``` Repository: KytyPS5/KytyPS5 Length of output: 41595 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- TestMeshInputAssembly definition and assertions ---' rg -n -B 8 -A 155 'void TestMeshInputAssembly' tests/shaderCfgTests.cpp printf '%s\n' '--- all test references to mesh draw parameters and base-group fields ---' rg -n -S 'MeshDrawParameter|draw\[6\]|MeshDrawDwordCount|base_group|base.group|group_offset|MeshDispatchSlice' --glob '*.{cpp,h,hpp,cc,cxx}' . printf '%s\n' '--- draw parameter packing at the production caller ---' sed -n '1010,1080p' src/graphics/host_gpu/renderer/renderDraw.cpp printf '%s\n' '--- test registration for the relevant tests ---' rg -n -S 'TestMeshInputAssembly|MeshDispatchTests|shaderCfgTests' CMakeLists.txt cmake tests src --glob 'CMakeLists.txt' --glob '*.cmake' --glob '*.cpp' ``` Repository: KytyPS5/KytyPS5 Length of output: 16597 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- mesh slice push-data construction ---' sed -n '1128,1162p' src/graphics/host_gpu/renderer/renderDraw.cpp printf '%s\n' '--- mesh translation downstream arithmetic ---' sed -n '1080,1162p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp printf '%s\n' '--- mesh draw push-data contract ---' sed -n '276,300p' src/graphics/shader/recompiler/ir/ShaderIR.h printf '%s\n' '--- focused diff metadata ---' git diff --stat 569ec04d1a77127c601eed522ad5bba187173f9d 8b99d6393c18475e56c92e9d712f68b84a2baafc ``` Repository: KytyPS5/KytyPS5 Length of output: 8281 --- </details> **Add a nonzero slice base group to the mesh translation fixture.** `draw[6]` is always zero in `TestMeshInputAssembly`. 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. <details> <summary>Suggested fix</summary> ```diff uint32_t wave_info, first, second, third, byte_offset, vertex_id; bool fetch; uint32_t wave_size = 64; + uint32_t base_group = 0; ... - 0x40000101, 0, 0, 0, 0, 11, false}, + 0x40000101, 0, 0, 0, 0, 12, false, 64, 1}, ... - test.count, test.base_vertex, 7, test.width, test.address_low, 0x12, 0}; + test.count, test.base_vertex, 7, test.width, test.address_low, 0x12, + test.base_group}; ``` </details> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:39a8fc8db081969cac012806 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠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 be7a0078da and 8b99d6393c.

📒 Files selected for processing (3)
  • src/graphics/host_gpu/renderer/meshDispatch.h
  • tests/MeshDispatchTests.cpp
  • tests/shaderCfgTests.cpp

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 15:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/793#pullrequestreview-5306648814) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `afc8b288-8986-4892-a936-e6b04c96dc31` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between be7a0078da6bd7cb92aef10b56739cd188fb96ef and 8b99d6393c18475e56c92e9d712f68b84a2baafc. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/graphics/host_gpu/renderer/meshDispatch.h` * `tests/MeshDispatchTests.cpp` * `tests/shaderCfgTests.cpp` </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 9 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Author
Owner

@⁠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: 1x76426 and 1x65674 in two runs, against maxMeshWorkGroupCount = 4194304, 65535, 65535 and maxMeshWorkGroupTotalCount = 4194304. One group, so only the instance count is over the limit.

This PR no longer applies to current main: CMakeLists.txt, renderDraw.cpp and Translate.cpp conflict, and the mesh draw push constants have moved (UserClipPlaneDword now follows MeshDrawDwordCount).

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 of min(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 over maxMeshWorkGroupCount[0] still aborts; that part needs the base-group dword from this PR.

Local patch (on top of main @ 6aaa533 + #838 + other test fixes)
@@ -1134,7 +1134,8 @@ void RenderExecutor::ExecutePreparedDraw(uint64_t submit_id, CommandBuffer& buff
 	const auto vertex_stages =
 	    std::span {state.vertex_info.data(), state.programs.VertexStageCount()};
 	const bool mesh_active = state.vertex_info[0].stage.program->stage == ShaderType::Mesh;
-	uint32_t   mesh_groups = 0;
+	uint32_t   mesh_groups         = 0;
+	uint32_t   mesh_instance_slice = 0;
 	if (mesh_active) {
 		const auto& mesh = state.vertex_info[0].mesh;
 		EXIT_NOT_IMPLEMENTED(mesh.fast_launch && (draw.IsIndexed() || primitive_restart_enable));
@@ -1154,10 +1155,11 @@ void RenderExecutor::ExecutePreparedDraw(uint64_t submit_id, CommandBuffer& buff
 		}
 		mesh_groups        = (primitives - 1u) / mesh.primitives_per_group + 1u;
 		const auto& limits = m_context.GetGraphics().mesh_shader_properties;
-		if (mesh_groups > limits.maxMeshWorkGroupCount[0] ||
-		    draw.instance_count > limits.maxMeshWorkGroupCount[1] ||
-		    static_cast<uint64_t>(mesh_groups) * draw.instance_count >
-		        limits.maxMeshWorkGroupTotalCount) {
+		// Instances beyond the host limits are drawn in slices below; the mesh shader adds the
+		// pushed first instance to gl_WorkGroupID.y, so each slice only moves that dword.
+		mesh_instance_slice =
+		    std::min(limits.maxMeshWorkGroupCount[1], limits.maxMeshWorkGroupTotalCount / mesh_groups);
+		if (mesh_groups > limits.maxMeshWorkGroupCount[0] || mesh_instance_slice == 0) {
 			EXIT("mesh draw exceeds host workgroup limits: %ux%u\n", mesh_groups,
 			     draw.instance_count);
 		}
@@ -1287,7 +1289,17 @@ void RenderExecutor::ExecutePreparedDraw(uint64_t submit_id, CommandBuffer& buff
 	auto&         occlusion_queries = m_context.GetOcclusionQueries();
 	const int32_t occlusion_query   = occlusion_queries.Begin(vk_buffer);
 	if (mesh_active) {
-		vk_buffer.drawMeshTasksEXT(mesh_groups, draw.instance_count, 1);
+		for (uint32_t done = 0; done < draw.instance_count;) {
+			if (done != 0) {
+				// Draw dword 2 is the first instance.
+				const uint32_t first_instance = emit.first_instance + done;
+				vk_buffer.pushConstants(pipeline.pipeline_layout, draw_stages, 2 * sizeof(uint32_t),
+				                        sizeof(first_instance), &first_instance);
+			}
+			const auto count = std::min(mesh_instance_slice, draw.instance_count - done);
+			vk_buffer.drawMeshTasksEXT(mesh_groups, count, 1);
+			done += count;
+		}
 	} else if (args_buffer.first == nullptr) {
 		EmitDrawPrimitives(ucfg, vk_buffer, draw, emit);
 	} else if (draw.IsIndexed()) {

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-24 01:49 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/793#issuecomment-6378382605) 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: `1x76426` and `1x65674` in two runs, against `maxMeshWorkGroupCount = 4194304, 65535, 65535` and `maxMeshWorkGroupTotalCount = 4194304`. One group, so only the instance count is over the limit. This PR no longer applies to current `main`: `CMakeLists.txt`, `renderDraw.cpp` and `Translate.cpp` conflict, and the mesh draw push constants have moved (`UserClipPlaneDword` now follows `MeshDrawDwordCount`). 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 of `min(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 over `maxMeshWorkGroupCount[0]` still aborts; that part needs the base-group dword from this PR. <details> <summary>Local patch (on top of <code>main</code> @ 6aaa533 + #838 + other test fixes)</summary> ```diff @@ -1134,7 +1134,8 @@ void RenderExecutor::ExecutePreparedDraw(uint64_t submit_id, CommandBuffer& buff const auto vertex_stages = std::span {state.vertex_info.data(), state.programs.VertexStageCount()}; const bool mesh_active = state.vertex_info[0].stage.program->stage == ShaderType::Mesh; - uint32_t mesh_groups = 0; + uint32_t mesh_groups = 0; + uint32_t mesh_instance_slice = 0; if (mesh_active) { const auto& mesh = state.vertex_info[0].mesh; EXIT_NOT_IMPLEMENTED(mesh.fast_launch && (draw.IsIndexed() || primitive_restart_enable)); @@ -1154,10 +1155,11 @@ void RenderExecutor::ExecutePreparedDraw(uint64_t submit_id, CommandBuffer& buff } mesh_groups = (primitives - 1u) / mesh.primitives_per_group + 1u; const auto& limits = m_context.GetGraphics().mesh_shader_properties; - if (mesh_groups > limits.maxMeshWorkGroupCount[0] || - draw.instance_count > limits.maxMeshWorkGroupCount[1] || - static_cast<uint64_t>(mesh_groups) * draw.instance_count > - limits.maxMeshWorkGroupTotalCount) { + // Instances beyond the host limits are drawn in slices below; the mesh shader adds the + // pushed first instance to gl_WorkGroupID.y, so each slice only moves that dword. + mesh_instance_slice = + std::min(limits.maxMeshWorkGroupCount[1], limits.maxMeshWorkGroupTotalCount / mesh_groups); + if (mesh_groups > limits.maxMeshWorkGroupCount[0] || mesh_instance_slice == 0) { EXIT("mesh draw exceeds host workgroup limits: %ux%u\n", mesh_groups, draw.instance_count); } @@ -1287,7 +1289,17 @@ void RenderExecutor::ExecutePreparedDraw(uint64_t submit_id, CommandBuffer& buff auto& occlusion_queries = m_context.GetOcclusionQueries(); const int32_t occlusion_query = occlusion_queries.Begin(vk_buffer); if (mesh_active) { - vk_buffer.drawMeshTasksEXT(mesh_groups, draw.instance_count, 1); + for (uint32_t done = 0; done < draw.instance_count;) { + if (done != 0) { + // Draw dword 2 is the first instance. + const uint32_t first_instance = emit.first_instance + done; + vk_buffer.pushConstants(pipeline.pipeline_layout, draw_stages, 2 * sizeof(uint32_t), + sizeof(first_instance), &first_instance); + } + const auto count = std::min(mesh_instance_slice, draw.instance_count - done); + vk_buffer.drawMeshTasksEXT(mesh_groups, count, 1); + done += count; + } } else if (args_buffer.first == nullptr) { EmitDrawPrimitives(ucfg, vk_buffer, draw, emit); } else if (draw.IsIndexed()) { ``` </details> 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.
Author
Owner

@⁠ZrDaniel07 on GitHub · 2026-10-26 20:35 UTC · original

@⁠prompterror heads-up: main f90a8b15 changed two things this PR depends on.

  • 943bc19f took the start instance out of the mesh instance ID VGPRs. Pushing first_instance + done into dword 2 no longer moves the instance, so later slices would repeat instances 0..N.
  • 560756f3 only skips mesh shaders that exceed the host limits. ASTRO BOT's Garden still exits with mesh 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.

**@⁠ZrDaniel07** on GitHub · 2026-10-26 20:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/793#issuecomment-6426709650) @⁠prompterror heads-up: `main` `f90a8b15` changed two things this PR depends on. - `943bc19f` took the start instance out of the mesh instance ID VGPRs. Pushing `first_instance + done` into dword 2 no longer moves the instance, so later slices would repeat instances 0..N. - `560756f3` only skips mesh *shaders* that exceed the host limits. ASTRO BOT's Garden still exits with `mesh 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](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/745). 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.
This pull request has changes conflicting with the target branch.
  • CMakeLists.txt
  • src/graphics/host_gpu/renderer/renderDraw.cpp
  • src/graphics/shader/recompiler/frontend/translate/Translate.cpp
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • tests/shaderCfgTests.cpp
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.
git fetch -u origin '+refs/pull/793/head:github-bot/gh-793'
git switch 'github-bot/gh-793'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-793'
git switch 'github-bot/gh-793'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-793'
git switch 'github-bot/gh-793'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-793'
git switch 'main'
git merge --squash 'github-bot/gh-793'
git switch 'main'
git merge --ff-only 'github-bot/gh-793'
git switch 'main'
git merge 'github-bot/gh-793'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.