gpu: draw GPU-written indirect arguments without a readback #1288

Closed
github-bot wants to merge 9 commits from gh-pr/1288/head into gh-pr/1288/base
Owner

@⁠NeySlim on GitHub · 2026-10-09 07:40 UTC · original
NeySlim:perf/gpu-indirect-draw → main · +1347 −74 · 15 files · 9 commits · closed without merging

Problem

DRAW_INDIRECT, DRAW_INDEX_INDIRECT and their _MULTI forms read their arguments and draw count on the CPU in CommandProcessor::DrawIndirectMulti. When a compute shader wrote them, as GPU-driven culling does, the read faults and the command thread waits for the GPU to finish everything recorded so far.

In God of War Ragnarök (PPSA08332, 05.005) about 3% of the indirect draws (about 28 per second) have GPU-written arguments. All of them are single indexed draws of a regular vertex shader, with no user SGPR destination for the offsets. The command thread blocks on them 3.0 ms per frame in the opening cutscene and 1.7 ms per frame in the first gameplay section (scheduler traces, blocked time attributed by stack).

Change

  • When the arguments or the count are GPU-written, CommandProcessor::DrawIndirectOnGpu passes the packet to RenderExecutor::DrawIndirect instead of reading it. Arguments that are not GPU-written stay on the CPU path, which reads them without a readback.
  • A compute pass (gpu_indirect_draw_prepare.comp) reads the guest arguments and writes host draw commands with the parameters the CPU path emits: index count, first index, and a zero base vertex and first instance for native vertex fetches (kept for rewritten fetches, which consume them through Vulkan). The draw count is the guest count bounded by the packet maximum. The draws are recorded with vkCmdDrawIndexedIndirectCount / vkCmdDrawIndirectCount.
  • The arguments and the count can be at any dword address: their descriptors start at an offset aligned to minStorageBufferOffsetAlignment and the pass adds the remainder.
  • Indices past INDEX_BUFFER_SIZE read as zero, on both paths, as on the hardware: the index fetcher returns 0 past the max size and the draw keeps its count (RADV and PAL rely on this; Vulkan gives the same result for a sized index buffer binding with robustBufferAccess2). The GPU path binds the index buffer from INDEX_BASE with a size of INDEX_BUFFER_SIZE indices (vkCmdBindIndexBuffer2KHR) and lets Vulkan apply the start index inside it. The CPU path used to clamp the count to INDEX_BUFFER_SIZE without the start index; it now draws the full count with the same sized binding, or with a host copy when VK_KHR_maintenance5 or robustBufferAccess2 is missing (and for 8-bit indices, as before). The copy reads only the indices inside INDEX_BUFFER_SIZE; the zeros after them are written straight into the stream buffer. A copy holds at most a quarter of the stream buffer: a longer zero tail is drawn by further draws over the zeros of the same copy, split on whole primitives for lists, one instance at a time so that each instance runs completely before the next. Mesh pipelines (NGG emulation), which fetch indices in the shader, keep the full count and get the readable limit in their draw constants: the index load is inactive, and reads 0, past it. The GPU path is only used for indexed draws when both are available.
  • NUM_INSTANCES stays in GPU memory: the last executed draw sets it, and a draw whose GPU count is 0 leaves it unchanged (starting from the CPU value when the CPU knows it). It is read back only when a later direct draw uses it; a NUM_INSTANCES packet or a CPU-path indirect draw replaces it.
  • Draws of a primitive type the CPU path does not draw (patches without tessellation, line loops, adjacency, quad strips) take the GPU path too, but only record the prepare pass, which latches NUM_INSTANCES on the GPU, and no draw. On the CPU path these draws read their arguments (and wait for the GPU when a shader wrote them) only to latch NUM_INSTANCES and skip the draw.
  • Tessellated patch draws (LS, HS and TES) take the GPU path too: Vulkan draws the patches from the prepared commands like any other draw, the arguments count control points.
  • The CPU path is kept, unchanged, for: offset destinations in user SGPRs (latched on the CPU), mesh pipelines, 8-bit indices, a custom primitive restart index, quad and rectangle lists, the color modes handled on the CPU (metadata eliminate, resolve, depth copy), and depth or stencil clears (DB_RENDER_CONTROL), whose clear would otherwise apply even when the GPU count is 0.
  • Uses drawIndirectCount, multiDrawIndirect, drawIndirectFirstInstance and VK_KHR_maintenance5 when the device has them.

Limitations

  • When a zero tail is split on the host-copy path, strips, fans and the primitive ID restart at each draw. Only primitives made of index 0 alone are regrouped; they are degenerate except for points.
  • A host copy whose indices inside INDEX_BUFFER_SIZE alone exceed a quarter of the stream buffer still stops with an error, as 8-bit indices did before.
  • INDEX_BUFFER_SIZE 0 (never set) still leaves the indices unbounded on the CPU path, as before; the GPU path is not used then.
  • Indices inside INDEX_BUFFER_SIZE but past mapped memory read as zero on the GPU path.
  • A draw whose GPU count is 0 still binds its render targets; this does not change their content.

Test

New GpuIndirectDraw checks in the rasterization test, through RenderExecutor::DrawIndirect with GPU-written arguments, with the storage offset alignment raised to 64 bytes and arguments and counts at unaligned addresses:

  • an indexed draw, a non-indexed draw, and an indexed multi-draw with a GPU-written count (1 and 2 of 2 draws); the arguments are not read back;
  • the base vertex and first instance in the arguments (7 and 5) are not applied to a native vertex fetch, as on the CPU path: the full-screen triangle must still cover the target;
  • an indexed draw starting at index 1 of an INDEX_BUFFER_SIZE of 3, followed in memory by a stale index: it must draw indices 1, 2, 0;
  • NUM_INSTANCES comes from the last counted draw; a draw with a GPU count of 0 keeps the previous draw's value, or the CPU value it starts from;
  • a depth clear draw stays on the CPU path;
  • a patch draw (tessellation disabled) and a line loop draw with GPU-written arguments take the GPU path without a readback, leave the target unchanged and latch NUM_INSTANCES;
  • a tessellated patch draw (LS, HS and TES), indexed and not, with GPU-written arguments takes the GPU path without a readback and covers the target with the patch output written by the HS;
  • the prepared commands, read back, keep the base vertex and first instance for a rewritten fetch and drop them for a native one.

DrawIndex with the CPU-path limit draws indices past INDEX_BUFFER_SIZE as zero through the sized binding, the host copy, and 8-bit indices; also with a count of 0x1200000 and an INDEX_BUFFER_SIZE of 2 on the host copy (32-bit and 8-bit), more than the stream buffer holds (exits without the split). A host check runs the split draws of 3 instances over a copy and requires the indices of the draw in order for each instance in turn, read from the copy only, with list primitives kept whole. TestMeshInputAssembly (shader_cfg_tests) checks that the mesh prolog reads index 0 at and past the limit and loads the index below it. The test device enables VK_KHR_maintenance5 and robustBufferAccess2 when available, as the emulator does.

The checks fail when the GPU path is disabled or when the matching change is reverted. The alignment check cannot fail on RADV, whose alignment is 4 bytes; it fails when the pass ignores the offset remainder.

Validation

Linux, AMD Radeon 8060S (RDNA 3.5), Mesa RADV 26.2.3.

  • shader_recompiler_compute_tests, one case per process, after the review changes: same results as a clean main build (600 of 610 pass; the 10 others fail on main too on this setup). shader_cfg_tests, resource_tracking_tests and resource_materialization_tests pass.
  • God of War Ragnarök, new game through the opening cutscene and the sled section, with the color metadata change from #1283 (measured on the first version of this PR, before the review changes):
    • indirect-argument waits go from 3.0 to 0.5 ms per frame in the cutscene and from 1.7 to 0.1 ms in gameplay;
    • alternating the new and the old paths every 5 s in the same session (same scenes): command thread blocked 20.2 ms per frame before, 14.6 ms after; frame rate +0.4 fps median (about 5%);
    • screenshots of the same scenes show no rendering difference.
  • Draws the CPU path skips: the game runs without tessellation and issues about 20 indirect patch draws per second in the opening cutscene, with arguments written by a particle compute shader. Each made the command thread wait 6 to 7 ms for a draw it then skipped. With the skip path: command thread blocked 5.9-6.6 -> 0.7-1.2 ms per frame in the cutscene, 20.3 -> 21.7 fps (three new-game runs each, with my other open PRs the game needs). Sled and Freya fight within noise. GPU suite, one case per process: 613/623, same 10 failures as main.

Not tested on Windows. The features used are core Vulkan 1.2, plus VK_KHR_maintenance5 (core in 1.4) and robustBufferAccess2 for indexed draws; without them the CPU path is used.

AI use

I used Claude Code (AI agent) to find which indirect draws block the command thread, write the change and the test, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.

**@⁠NeySlim** on GitHub · 2026-10-09 07:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288) `NeySlim:perf/gpu-indirect-draw` → `main` · +1347 −74 · 15 files · 9 commits · closed without merging ## Problem `DRAW_INDIRECT`, `DRAW_INDEX_INDIRECT` and their `_MULTI` forms read their arguments and draw count on the CPU in `CommandProcessor::DrawIndirectMulti`. When a compute shader wrote them, as GPU-driven culling does, the read faults and the command thread waits for the GPU to finish everything recorded so far. In God of War Ragnarök (PPSA08332, 05.005) about 3% of the indirect draws (about 28 per second) have GPU-written arguments. All of them are single indexed draws of a regular vertex shader, with no user SGPR destination for the offsets. The command thread blocks on them 3.0 ms per frame in the opening cutscene and 1.7 ms per frame in the first gameplay section (scheduler traces, blocked time attributed by stack). ## Change - When the arguments or the count are GPU-written, `CommandProcessor::DrawIndirectOnGpu` passes the packet to `RenderExecutor::DrawIndirect` instead of reading it. Arguments that are not GPU-written stay on the CPU path, which reads them without a readback. - A compute pass (`gpu_indirect_draw_prepare.comp`) reads the guest arguments and writes host draw commands with the parameters the CPU path emits: index count, first index, and a zero base vertex and first instance for native vertex fetches (kept for rewritten fetches, which consume them through Vulkan). The draw count is the guest count bounded by the packet maximum. The draws are recorded with `vkCmdDrawIndexedIndirectCount` / `vkCmdDrawIndirectCount`. - The arguments and the count can be at any dword address: their descriptors start at an offset aligned to `minStorageBufferOffsetAlignment` and the pass adds the remainder. - Indices past `INDEX_BUFFER_SIZE` read as zero, on both paths, as on the hardware: the index fetcher returns 0 past the max size and the draw keeps its count (RADV and PAL rely on this; Vulkan gives the same result for a sized index buffer binding with `robustBufferAccess2`). The GPU path binds the index buffer from `INDEX_BASE` with a size of `INDEX_BUFFER_SIZE` indices (`vkCmdBindIndexBuffer2KHR`) and lets Vulkan apply the start index inside it. The CPU path used to clamp the count to `INDEX_BUFFER_SIZE` without the start index; it now draws the full count with the same sized binding, or with a host copy when `VK_KHR_maintenance5` or `robustBufferAccess2` is missing (and for 8-bit indices, as before). The copy reads only the indices inside `INDEX_BUFFER_SIZE`; the zeros after them are written straight into the stream buffer. A copy holds at most a quarter of the stream buffer: a longer zero tail is drawn by further draws over the zeros of the same copy, split on whole primitives for lists, one instance at a time so that each instance runs completely before the next. Mesh pipelines (NGG emulation), which fetch indices in the shader, keep the full count and get the readable limit in their draw constants: the index load is inactive, and reads 0, past it. The GPU path is only used for indexed draws when both are available. - `NUM_INSTANCES` stays in GPU memory: the last executed draw sets it, and a draw whose GPU count is 0 leaves it unchanged (starting from the CPU value when the CPU knows it). It is read back only when a later direct draw uses it; a `NUM_INSTANCES` packet or a CPU-path indirect draw replaces it. - Draws of a primitive type the CPU path does not draw (patches without tessellation, line loops, adjacency, quad strips) take the GPU path too, but only record the prepare pass, which latches `NUM_INSTANCES` on the GPU, and no draw. On the CPU path these draws read their arguments (and wait for the GPU when a shader wrote them) only to latch `NUM_INSTANCES` and skip the draw. - Tessellated patch draws (LS, HS and TES) take the GPU path too: Vulkan draws the patches from the prepared commands like any other draw, the arguments count control points. - The CPU path is kept, unchanged, for: offset destinations in user SGPRs (latched on the CPU), mesh pipelines, 8-bit indices, a custom primitive restart index, quad and rectangle lists, the color modes handled on the CPU (metadata eliminate, resolve, depth copy), and depth or stencil clears (`DB_RENDER_CONTROL`), whose clear would otherwise apply even when the GPU count is 0. - Uses `drawIndirectCount`, `multiDrawIndirect`, `drawIndirectFirstInstance` and `VK_KHR_maintenance5` when the device has them. ## Limitations - When a zero tail is split on the host-copy path, strips, fans and the primitive ID restart at each draw. Only primitives made of index 0 alone are regrouped; they are degenerate except for points. - A host copy whose indices inside `INDEX_BUFFER_SIZE` alone exceed a quarter of the stream buffer still stops with an error, as 8-bit indices did before. - `INDEX_BUFFER_SIZE` 0 (never set) still leaves the indices unbounded on the CPU path, as before; the GPU path is not used then. - Indices inside `INDEX_BUFFER_SIZE` but past mapped memory read as zero on the GPU path. - A draw whose GPU count is 0 still binds its render targets; this does not change their content. ## Test New `GpuIndirectDraw` checks in the rasterization test, through `RenderExecutor::DrawIndirect` with GPU-written arguments, with the storage offset alignment raised to 64 bytes and arguments and counts at unaligned addresses: - an indexed draw, a non-indexed draw, and an indexed multi-draw with a GPU-written count (1 and 2 of 2 draws); the arguments are not read back; - the base vertex and first instance in the arguments (7 and 5) are not applied to a native vertex fetch, as on the CPU path: the full-screen triangle must still cover the target; - an indexed draw starting at index 1 of an `INDEX_BUFFER_SIZE` of 3, followed in memory by a stale index: it must draw indices 1, 2, 0; - `NUM_INSTANCES` comes from the last counted draw; a draw with a GPU count of 0 keeps the previous draw's value, or the CPU value it starts from; - a depth clear draw stays on the CPU path; - a patch draw (tessellation disabled) and a line loop draw with GPU-written arguments take the GPU path without a readback, leave the target unchanged and latch `NUM_INSTANCES`; - a tessellated patch draw (LS, HS and TES), indexed and not, with GPU-written arguments takes the GPU path without a readback and covers the target with the patch output written by the HS; - the prepared commands, read back, keep the base vertex and first instance for a rewritten fetch and drop them for a native one. `DrawIndex` with the CPU-path limit draws indices past `INDEX_BUFFER_SIZE` as zero through the sized binding, the host copy, and 8-bit indices; also with a count of 0x1200000 and an `INDEX_BUFFER_SIZE` of 2 on the host copy (32-bit and 8-bit), more than the stream buffer holds (exits without the split). A host check runs the split draws of 3 instances over a copy and requires the indices of the draw in order for each instance in turn, read from the copy only, with list primitives kept whole. `TestMeshInputAssembly` (`shader_cfg_tests`) checks that the mesh prolog reads index 0 at and past the limit and loads the index below it. The test device enables `VK_KHR_maintenance5` and `robustBufferAccess2` when available, as the emulator does. The checks fail when the GPU path is disabled or when the matching change is reverted. The alignment check cannot fail on RADV, whose alignment is 4 bytes; it fails when the pass ignores the offset remainder. ## Validation Linux, AMD Radeon 8060S (RDNA 3.5), Mesa RADV 26.2.3. - `shader_recompiler_compute_tests`, one case per process, after the review changes: same results as a clean main build (600 of 610 pass; the 10 others fail on main too on this setup). `shader_cfg_tests`, `resource_tracking_tests` and `resource_materialization_tests` pass. - God of War Ragnarök, new game through the opening cutscene and the sled section, with the color metadata change from #1283 (measured on the first version of this PR, before the review changes): - indirect-argument waits go from 3.0 to 0.5 ms per frame in the cutscene and from 1.7 to 0.1 ms in gameplay; - alternating the new and the old paths every 5 s in the same session (same scenes): command thread blocked 20.2 ms per frame before, 14.6 ms after; frame rate +0.4 fps median (about 5%); - screenshots of the same scenes show no rendering difference. - Draws the CPU path skips: the game runs without tessellation and issues about 20 indirect patch draws per second in the opening cutscene, with arguments written by a particle compute shader. Each made the command thread wait 6 to 7 ms for a draw it then skipped. With the skip path: command thread blocked 5.9-6.6 -> 0.7-1.2 ms per frame in the cutscene, 20.3 -> 21.7 fps (three new-game runs each, with my other open PRs the game needs). Sled and Freya fight within noise. GPU suite, one case per process: 613/623, same 10 failures as main. Not tested on Windows. The features used are core Vulkan 1.2, plus `VK_KHR_maintenance5` (core in 1.4) and `robustBufferAccess2` for indexed draws; without them the CPU path is used. ## AI use I used Claude Code (AI agent) to find which indirect draws block the command thread, write the change and the test, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:51:37 +00:00
github-bot closed this pull request 2026-11-26 09:51:37 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 07:40 UTC · original · edited 2026-10-21 16:29 UTC

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

  • Last reviewed commit: 83058637c98e64f74099be95f9d6475e2039cc69
  • Latest commit, not reviewed: d7cbd49846

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 67e32692-e78f-4487-8711-9cef1a99390c
📥 Commits

Reviewing files that changed from the base of the PR and between e9a0880b7fa401fb300075d9b1e2a431145771de and 83058637c98e64f74099be95f9d6475e2039cc69.

📒 Files selected for processing (5)
  • CMakeLists.txt
  • src/graphics/guest_gpu/graphicsRun.cpp
  • src/graphics/host_gpu/renderer/render.h
  • src/graphics/presentation/window/vulkanWindow.cpp
  • tests/ShaderRecompilerComputeTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.

📝 Walkthrough

The changes add GPU-side preparation and submission for eligible indirect draws, with CPU fallback for unsupported requests. They track indirect-draw instance counts and add bounded index reads for indexed draws. Vulkan capability checks control indirect-count drawing and sized index-buffer bindings. The changes also add compute-shader build integration and tests for GPU and CPU draw paths.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 83058

The reviewed draw paths have no identified issue that needs resolution before merge.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 12.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 50 functions across 11 files. (2 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely summarizes the main change: supporting GPU-written indirect arguments without a CPU readback.
Description check Passed The description directly explains the problem, implementation, limitations, tests, and validation for GPU-written indirect draws. It is fully related to the changeset.
Full details: Docstring Coverage

Explanation

Docstring coverage is 12.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 50 functions across 11 files. (2 skipped: 1 unsupported, 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 07:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#issuecomment-6076643797) · edited 2026-10-21 16:29 UTC <!-- coderabbit-ai-generated:v1 --> <!-- 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/1288?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- This is an auto-generated comment: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > - Last reviewed commit: 83058637c98e64f74099be95f9d6475e2039cc69 > - Latest commit, not reviewed: d7cbd498469f937c3804a28e2311252521d5aba1 > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> ▶️ Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `67e32692-e78f-4487-8711-9cef1a99390c` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between e9a0880b7fa401fb300075d9b1e2a431145771de and 83058637c98e64f74099be95f9d6475e2039cc69. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing (5)</strong></summary> <dl> <dd> * `CMakeLists.txt` * `src/graphics/guest_gpu/graphicsRun.cpp` * `src/graphics/host_gpu/renderer/render.h` * `src/graphics/presentation/window/vulkanWindow.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The changes add GPU-side preparation and submission for eligible indirect draws, with CPU fallback for unsupported requests. They track indirect-draw instance counts and add bounded index reads for indexed draws. Vulkan capability checks control indirect-count drawing and sized index-buffer bindings. The changes also add compute-shader build integration and tests for GPU and CPU draw paths. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"83058637c98e64f74099be95f9d6475e2039cc69" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>83058</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `83058` --> <!-- final_review_risk_coverage:{"sourceCommitId":"83058637c98e64f74099be95f9d6475e2039cc69","coveredCommitId":"83058637c98e64f74099be95f9d6475e2039cc69","kind":"reviewed"} --> The reviewed draw paths have no identified issue that needs resolution before merge. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | Docstring coverage is 12.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 50 functions across 11 files. (2 skipped:… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely summarizes the main change: supporting GPU-written indirect arguments without a CPU readback. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the problem, implementation, limitations, tests, and validation for GPU-written indirect draws. It is fully related to the changeset. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 12.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 50 functions across 11 files. (2 skipped: 1 unsupported, 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1288)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-09 15:08 UTC · original

Rebased on main and bounded the host index copy of the CPU path (no VK_KHR_maintenance5/robustBufferAccess2, or 8-bit indices):

  • Only the indices inside INDEX_BUFFER_SIZE are read and copied; the zero tail is written straight into the stream buffer, so no count-sized vector is built.
  • A copy holds at most a quarter of the stream buffer. A longer zero tail is drawn by further draws over the zeros of the same copy, split on whole primitives for lists; strips and fans only regroup primitives made of index 0 alone. The description lists what this changes (primitive ID and instance order of those primitives).
  • Tests: the CPU-path case now also draws 0x1200000 indices with an INDEX_BUFFER_SIZE of 2 on the forced host copy (32-bit and 8-bit); before, the 32-bit one exited on the stream buffer. A host check runs the split draws over a copy and requires every index of the draw in order, read from the copy only. Both fail when the split or its chunk draws are removed.

GPU suite one case per process: same 10 failures as a clean main build (610 cases). resource_* pass.

**@⁠NeySlim** on GitHub · 2026-10-09 15:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#issuecomment-6083631898) Rebased on main and bounded the host index copy of the CPU path (no `VK_KHR_maintenance5`/`robustBufferAccess2`, or 8-bit indices): - Only the indices inside `INDEX_BUFFER_SIZE` are read and copied; the zero tail is written straight into the stream buffer, so no count-sized vector is built. - A copy holds at most a quarter of the stream buffer. A longer zero tail is drawn by further draws over the zeros of the same copy, split on whole primitives for lists; strips and fans only regroup primitives made of index 0 alone. The description lists what this changes (primitive ID and instance order of those primitives). - Tests: the CPU-path case now also draws 0x1200000 indices with an `INDEX_BUFFER_SIZE` of 2 on the forced host copy (32-bit and 8-bit); before, the 32-bit one exited on the stream buffer. A host check runs the split draws over a copy and requires every index of the draw in order, read from the copy only. Both fail when the split or its chunk draws are removed. GPU suite one case per process: same 10 failures as a clean main build (610 cases). resource_* pass.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:17 UTC · original · edited 2026-10-09 15:40 UTC
On src/graphics/host_gpu/renderer/renderDraw.cpp line 1091 (outdated):

@@ -1009,20 +1071,26 @@ static void EmitDrawPrimitives(const HW::UserConfig& ucfg, vk::CommandBuffer vk_
 		case Prospero::PrimitiveType::kRectListLegacy:
 		case Prospero::PrimitiveType::kPatch:
 			if (draw.IsIndexed()) {
-				vk_buffer.drawIndexed(draw.index_count, draw.instance_count, 0, emit.vertex_offset,
-				                      emit.first_instance);
+				emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) {
+					vk_buffer.drawIndexed(count, draw.instance_count, first, emit.vertex_offset,
+					                      emit.first_instance);
+				});
 			} else {
 				vk_buffer.draw(draw.index_count, draw.instance_count, emit.first_vertex,
 				               emit.first_instance);
 			}
 			break;
 		case Prospero::PrimitiveType::kQuadListLegacy:
 			EXIT_NOT_IMPLEMENTED((draw.index_count & 0x3u) != 0);
-			for (uint32_t i = 0; i < draw.index_count; i += 4) {
-				if (draw.IsIndexed()) {
-					vk_buffer.drawIndexed(4, draw.instance_count, i, emit.vertex_offset,
-					                      emit.first_instance);
-				} else {
+			if (draw.IsIndexed()) {
+				emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) {
+					for (uint32_t i = 0; i < count; i += 4) {
+						vk_buffer.drawIndexed(4, draw.instance_count, first + i, emit.vertex_offset,
+						                      emit.first_instance);
+					}
+				});

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -eu
printf '%s\n' '--- renderDraw emission ---'
nl -ba src/graphics/host_gpu/renderer/renderDraw.cpp | sed -n '1035,1100p'
printf '%s\n' '--- instance-sensitive shader support ---'
nl -ba src/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpp | sed -n '140,165p'
rg -n -F --glob '*.{cpp,h,hpp}' -- 'gl_InstanceIndex' src/graphics | sed -n '1,80p'
printf '%s\n' '--- reachable blending or shared-target writes ---'
rg -n -i --glob '*.{cpp,h,hpp}' -- 'blend|imageStore|atomic|storage image|subpass' src/graphics/host_gpu src/graphics/shader | sed -n '1,120p'

Repository: KytyPS5/KytyPS5

Length of output: 16804


Preserve instance-major ordering for split indexed draws.

When draw.instance_count > 1, the current callback submits every zero-tail segment with the full instance count. This makes execution segment-major instead of instance-major. Overlapping primitives can therefore produce different results with blending or shared-target shader writes.

Emit one instance per segment in an outer instance loop. Keep primitive-ID preservation as a separate correction.

Suggested fix
-				emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) {
-					vk_buffer.drawIndexed(count, draw.instance_count, first, emit.vertex_offset,
-					                      emit.first_instance);
-				});
+				for (uint32_t instance = 0; instance < draw.instance_count; ++instance) {
+					emit.zero_tail.ForEachDraw(draw.index_count,
+					                           [&](uint32_t first, uint32_t count) {
+						                           vk_buffer.drawIndexed(
+							                           count, 1, first, emit.vertex_offset,
+							                           emit.first_instance + instance);
+					                           });
+				}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

			if (draw.IsIndexed()) {
				for (uint32_t instance = 0; instance < draw.instance_count; ++instance) {
					emit.zero_tail.ForEachDraw(draw.index_count,
					                           [&](uint32_t first, uint32_t count) {
						                           vk_buffer.drawIndexed(
							                           count, 1, first, emit.vertex_offset,
							                           emit.first_instance + instance);
					                           });
				}
			} else {
				vk_buffer.draw(draw.index_count, draw.instance_count, emit.first_vertex,
				               emit.first_instance);
			}
			break;
		case Prospero::PrimitiveType::kQuadListLegacy:
			EXIT_NOT_IMPLEMENTED((draw.index_count & 0x3u) != 0);
			if (draw.IsIndexed()) {
				emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) {
					for (uint32_t i = 0; i < count; i += 4) {
						vk_buffer.drawIndexed(4, draw.instance_count, first + i, emit.vertex_offset,
						                      emit.first_instance);
					}
				});

✅ Confirmed as addressed by @⁠NeySlim

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:17 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#discussion_r4231662888) · edited 2026-10-09 15:40 UTC On `src/graphics/host_gpu/renderer/renderDraw.cpp` line 1091 (outdated): ```diff @@ -1009,20 +1071,26 @@ static void EmitDrawPrimitives(const HW::UserConfig& ucfg, vk::CommandBuffer vk_ case Prospero::PrimitiveType::kRectListLegacy: case Prospero::PrimitiveType::kPatch: if (draw.IsIndexed()) { - vk_buffer.drawIndexed(draw.index_count, draw.instance_count, 0, emit.vertex_offset, - emit.first_instance); + emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) { + vk_buffer.drawIndexed(count, draw.instance_count, first, emit.vertex_offset, + emit.first_instance); + }); } else { vk_buffer.draw(draw.index_count, draw.instance_count, emit.first_vertex, emit.first_instance); } break; case Prospero::PrimitiveType::kQuadListLegacy: EXIT_NOT_IMPLEMENTED((draw.index_count & 0x3u) != 0); - for (uint32_t i = 0; i < draw.index_count; i += 4) { - if (draw.IsIndexed()) { - vk_buffer.drawIndexed(4, draw.instance_count, i, emit.vertex_offset, - emit.first_instance); - } else { + if (draw.IsIndexed()) { + emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) { + for (uint32_t i = 0; i < count; i += 4) { + vk_buffer.drawIndexed(4, draw.instance_count, first + i, emit.vertex_offset, + emit.first_instance); + } + }); ``` **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash set -eu printf '%s\n' '--- renderDraw emission ---' nl -ba src/graphics/host_gpu/renderer/renderDraw.cpp | sed -n '1035,1100p' printf '%s\n' '--- instance-sensitive shader support ---' nl -ba src/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpp | sed -n '140,165p' rg -n -F --glob '*.{cpp,h,hpp}' -- 'gl_InstanceIndex' src/graphics | sed -n '1,80p' printf '%s\n' '--- reachable blending or shared-target writes ---' rg -n -i --glob '*.{cpp,h,hpp}' -- 'blend|imageStore|atomic|storage image|subpass' src/graphics/host_gpu src/graphics/shader | sed -n '1,120p' ``` Repository: KytyPS5/KytyPS5 Length of output: 16804 --- </details> **Preserve instance-major ordering for split indexed draws.** When `draw.instance_count > 1`, the current callback submits every zero-tail segment with the full instance count. This makes execution segment-major instead of instance-major. Overlapping primitives can therefore produce different results with blending or shared-target shader writes. Emit one instance per segment in an outer instance loop. Keep primitive-ID preservation as a separate correction. <details> <summary>Suggested fix</summary> ```diff - emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) { - vk_buffer.drawIndexed(count, draw.instance_count, first, emit.vertex_offset, - emit.first_instance); - }); + for (uint32_t instance = 0; instance < draw.instance_count; ++instance) { + emit.zero_tail.ForEachDraw(draw.index_count, + [&](uint32_t first, uint32_t count) { + vk_buffer.drawIndexed( + count, 1, first, emit.vertex_offset, + emit.first_instance + instance); + }); + } ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion if (draw.IsIndexed()) { for (uint32_t instance = 0; instance < draw.instance_count; ++instance) { emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) { vk_buffer.drawIndexed( count, 1, first, emit.vertex_offset, emit.first_instance + instance); }); } } else { vk_buffer.draw(draw.index_count, draw.instance_count, emit.first_vertex, emit.first_instance); } break; case Prospero::PrimitiveType::kQuadListLegacy: EXIT_NOT_IMPLEMENTED((draw.index_count & 0x3u) != 0); if (draw.IsIndexed()) { emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) { for (uint32_t i = 0; i < count; i += 4) { vk_buffer.drawIndexed(4, draw.instance_count, first + i, emit.vertex_offset, emit.first_instance); } }); ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:bb158407dd24e73f6c3f6245 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠NeySlim <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

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

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)

🟡 Minor · Preserve zero-tail primitives for mesh indexed draws. · renderDraw.cpp:1118-1119

src/graphics/host_gpu/renderer/renderDraw.cpp:1118-1119
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve zero-tail primitives for mesh indexed draws.

When draw.index_count exceeds index_source.limit, use the full draw count for mesh workgroup sizing and push-constant dword 0. Pass the readable element limit separately. When input_vertex >= limit, use index value 0 instead of loading guest memory.

The current clamp can omit complete primitives formed from the zero tail. This violates the INDEX_BUFFER_SIZE contract, which requires later indices to read as zero without reducing the draw count.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e7745353-f0ea-495f-a750-b48ba0526705
📥 Commits

Reviewing files that changed from the base of the PR and between afbb50a37b710d5469042db7bb49808115774206 and eb2347e40762aef80192bb498aa034921eeaa933.

📒 Files selected for processing (3)
  • src/graphics/host_gpu/renderer/render.h
  • src/graphics/host_gpu/renderer/renderDraw.cpp
  • tests/ShaderRecompilerComputeTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:17 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#pullrequestreview-5471966911) · **reviewed** **Actionable comments posted: 1** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><strong>🟡 Minor</strong> · Preserve zero-tail primitives for mesh indexed draws. · <code>renderDraw.cpp:1118-1119</code></summary><blockquote> > > `src/graphics/host_gpu/renderer/renderDraw.cpp:1118-1119` > **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** > > **Preserve zero-tail primitives for mesh indexed draws.** > > When `draw.index_count` exceeds `index_source.limit`, use the full draw count for mesh workgroup sizing and push-constant dword 0. Pass the readable element limit separately. When `input_vertex >= limit`, use index value `0` instead of loading guest memory. > > The current clamp can omit complete primitives formed from the zero tail. This violates the `INDEX_BUFFER_SIZE` contract, which requires later indices to read as zero without reducing the draw count. > > <!-- cr-comment:v1:0011b8cc4337cdd42d18858e --> > > </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**: `e7745353-f0ea-495f-a750-b48ba0526705` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between afbb50a37b710d5469042db7bb49808115774206 and eb2347e40762aef80192bb498aa034921eeaa933. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/graphics/host_gpu/renderer/render.h` * `src/graphics/host_gpu/renderer/renderDraw.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=388b20a6-3095-4784-8484-51e0334acdfb attempt=68196661-1e59-4ff4-a220-faeb286b8164 batch=1/1 -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-09 15:35 UTC · original
On src/graphics/host_gpu/renderer/renderDraw.cpp line 1091 (outdated):

@@ -1009,20 +1071,26 @@ static void EmitDrawPrimitives(const HW::UserConfig& ucfg, vk::CommandBuffer vk_
 		case Prospero::PrimitiveType::kRectListLegacy:
 		case Prospero::PrimitiveType::kPatch:
 			if (draw.IsIndexed()) {
-				vk_buffer.drawIndexed(draw.index_count, draw.instance_count, 0, emit.vertex_offset,
-				                      emit.first_instance);
+				emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) {
+					vk_buffer.drawIndexed(count, draw.instance_count, first, emit.vertex_offset,
+					                      emit.first_instance);
+				});
 			} else {
 				vk_buffer.draw(draw.index_count, draw.instance_count, emit.first_vertex,
 				               emit.first_instance);
 			}
 			break;
 		case Prospero::PrimitiveType::kQuadListLegacy:
 			EXIT_NOT_IMPLEMENTED((draw.index_count & 0x3u) != 0);
-			for (uint32_t i = 0; i < draw.index_count; i += 4) {
-				if (draw.IsIndexed()) {
-					vk_buffer.drawIndexed(4, draw.instance_count, i, emit.vertex_offset,
-					                      emit.first_instance);
-				} else {
+			if (draw.IsIndexed()) {
+				emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) {
+					for (uint32_t i = 0; i < count; i += 4) {
+						vk_buffer.drawIndexed(4, draw.instance_count, first + i, emit.vertex_offset,
+						                      emit.first_instance);
+					}
+				});

Fixed in 38a0df57. When the zero tail is split, ZeroTailDraws::ForEachDraw now loops over the instances outside the segments: each segment is drawn with one instance and first_instance + i, so each instance runs all its indices before the next one, as a single instanced draw does. gl_InstanceIndex includes the base instance, so its values do not change. Unsplit draws still use one draw with all instances; only the split path (a host copy longer than a quarter of the stream buffer) pays for the extra draws. Quad lists on the split path follow the same order.

The ZeroTailDraws host check now uses 3 instances and requires the (instance, index) sequence of one instanced draw; it fails with the previous segment-major order.

Drawing the zero tail as one non-indexed draw would not be exact: its vertex IDs count up from the first vertex instead of all being index 0 plus the base vertex. So the split over the zeros of the copy stays. Primitive IDs still restart at each split draw, as listed in the PR limitations.

**@⁠NeySlim** on GitHub · 2026-10-09 15:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#discussion_r4231830518) On `src/graphics/host_gpu/renderer/renderDraw.cpp` line 1091 (outdated): ```diff @@ -1009,20 +1071,26 @@ static void EmitDrawPrimitives(const HW::UserConfig& ucfg, vk::CommandBuffer vk_ case Prospero::PrimitiveType::kRectListLegacy: case Prospero::PrimitiveType::kPatch: if (draw.IsIndexed()) { - vk_buffer.drawIndexed(draw.index_count, draw.instance_count, 0, emit.vertex_offset, - emit.first_instance); + emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) { + vk_buffer.drawIndexed(count, draw.instance_count, first, emit.vertex_offset, + emit.first_instance); + }); } else { vk_buffer.draw(draw.index_count, draw.instance_count, emit.first_vertex, emit.first_instance); } break; case Prospero::PrimitiveType::kQuadListLegacy: EXIT_NOT_IMPLEMENTED((draw.index_count & 0x3u) != 0); - for (uint32_t i = 0; i < draw.index_count; i += 4) { - if (draw.IsIndexed()) { - vk_buffer.drawIndexed(4, draw.instance_count, i, emit.vertex_offset, - emit.first_instance); - } else { + if (draw.IsIndexed()) { + emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) { + for (uint32_t i = 0; i < count; i += 4) { + vk_buffer.drawIndexed(4, draw.instance_count, first + i, emit.vertex_offset, + emit.first_instance); + } + }); ``` Fixed in 38a0df57. When the zero tail is split, `ZeroTailDraws::ForEachDraw` now loops over the instances outside the segments: each segment is drawn with one instance and `first_instance + i`, so each instance runs all its indices before the next one, as a single instanced draw does. `gl_InstanceIndex` includes the base instance, so its values do not change. Unsplit draws still use one draw with all instances; only the split path (a host copy longer than a quarter of the stream buffer) pays for the extra draws. Quad lists on the split path follow the same order. The `ZeroTailDraws` host check now uses 3 instances and requires the (instance, index) sequence of one instanced draw; it fails with the previous segment-major order. Drawing the zero tail as one non-indexed draw would not be exact: its vertex IDs count up from the first vertex instead of all being index 0 plus the base vertex. So the split over the zeros of the copy stays. Primitive IDs still restart at each split draw, as listed in the PR limitations.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-09 15:35 UTC · original

Mesh indexed draws past INDEX_BUFFER_SIZE (CodeRabbit comment outside the diff, renderDraw.cpp 1118-1119): fixed in c7037bfe. A mesh draw keeps the full index count for its workgroup count and push constant dword 0. The readable index limit goes in a new dword 6 (UINT32_MAX for non-indexed draws), and the mesh prolog makes the index load inactive, which reads 0, when the input vertex is at or past it.

TestMeshInputAssembly in shader_cfg_tests checks a list lane at the limit (index 0), the same lane with the limit one higher (loaded), and a fan center with a limit of 0. It fails when the prolog ignores the limit.

**@⁠NeySlim** on GitHub · 2026-10-09 15:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#issuecomment-6084090901) Mesh indexed draws past `INDEX_BUFFER_SIZE` (CodeRabbit comment outside the diff, `renderDraw.cpp` 1118-1119): fixed in c7037bfe. A mesh draw keeps the full index count for its workgroup count and push constant dword 0. The readable index limit goes in a new dword 6 (`UINT32_MAX` for non-indexed draws), and the mesh prolog makes the index load inactive, which reads 0, when the input vertex is at or past it. `TestMeshInputAssembly` in `shader_cfg_tests` checks a list lane at the limit (index 0), the same lane with the limit one higher (loaded), and a fan center with a limit of 0. It fails when the prolog ignores the limit.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:40 UTC · original
On src/graphics/host_gpu/renderer/renderDraw.cpp line 1091 (outdated):

@@ -1009,20 +1071,26 @@ static void EmitDrawPrimitives(const HW::UserConfig& ucfg, vk::CommandBuffer vk_
 		case Prospero::PrimitiveType::kRectListLegacy:
 		case Prospero::PrimitiveType::kPatch:
 			if (draw.IsIndexed()) {
-				vk_buffer.drawIndexed(draw.index_count, draw.instance_count, 0, emit.vertex_offset,
-				                      emit.first_instance);
+				emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) {
+					vk_buffer.drawIndexed(count, draw.instance_count, first, emit.vertex_offset,
+					                      emit.first_instance);
+				});
 			} else {
 				vk_buffer.draw(draw.index_count, draw.instance_count, emit.first_vertex,
 				               emit.first_instance);
 			}
 			break;
 		case Prospero::PrimitiveType::kQuadListLegacy:
 			EXIT_NOT_IMPLEMENTED((draw.index_count & 0x3u) != 0);
-			for (uint32_t i = 0; i < draw.index_count; i += 4) {
-				if (draw.IsIndexed()) {
-					vk_buffer.drawIndexed(4, draw.instance_count, i, emit.vertex_offset,
-					                      emit.first_instance);
-				} else {
+			if (draw.IsIndexed()) {
+				emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) {
+					for (uint32_t i = 0; i < count; i += 4) {
+						vk_buffer.drawIndexed(4, draw.instance_count, first + i, emit.vertex_offset,
+						                      emit.first_instance);
+					}
+				});
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
ast-grep outline src/graphics/host_gpu/renderer/render.h --match 'ZeroTailDraws' --view expanded
rg -n -C 35 'void ForEachDraw|struct ZeroTailDraws' src/graphics/host_gpu/renderer/render.h
rg -n -C 20 'ForEachDraw\(|PlanZeroTailDraws\(' tests/ShaderRecompilerComputeTests.cpp
rg -n -C 8 'emit\.zero_tail\.ForEachDraw' src/graphics/host_gpu/renderer/renderDraw.cpp

Length of output: 10565


@NeySlim, verified by code inspection. ZeroTailDraws::ForEachDraw now processes all segments for one instance before the next. Both indexed emission paths, including quad lists, apply emit.first_instance + instance. Unsplit draws retain one draw with all instances.

The host check uses three instances and checks the complete (instance, index) sequence. I did not run the tests.

Thanks for clarifying why a non-indexed zero-tail draw is not equivalent. Primitive-ID resets remain a separate limitation.


✏️ Learnings added
Learnt from: NeySlim
Repo: KytyPS5/KytyPS5 PR: 1288
File: src/graphics/host_gpu/renderer/renderDraw.cpp:0-0
Timestamp: 2026-10-09T15:40:18.792Z
Learning: In src/graphics/host_gpu/renderer/renderDraw.cpp, indexed zero-tail draws must preserve index-zero vertex IDs plus the base vertex. Replacing the zero tail with a non-indexed draw is not equivalent because non-indexed vertex IDs increase. Split indexed draws can still reset primitive IDs at each draw; instance-major ordering does not preserve primitive IDs.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#discussion_r4231875551) On `src/graphics/host_gpu/renderer/renderDraw.cpp` line 1091 (outdated): ```diff @@ -1009,20 +1071,26 @@ static void EmitDrawPrimitives(const HW::UserConfig& ucfg, vk::CommandBuffer vk_ case Prospero::PrimitiveType::kRectListLegacy: case Prospero::PrimitiveType::kPatch: if (draw.IsIndexed()) { - vk_buffer.drawIndexed(draw.index_count, draw.instance_count, 0, emit.vertex_offset, - emit.first_instance); + emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) { + vk_buffer.drawIndexed(count, draw.instance_count, first, emit.vertex_offset, + emit.first_instance); + }); } else { vk_buffer.draw(draw.index_count, draw.instance_count, emit.first_vertex, emit.first_instance); } break; case Prospero::PrimitiveType::kQuadListLegacy: EXIT_NOT_IMPLEMENTED((draw.index_count & 0x3u) != 0); - for (uint32_t i = 0; i < draw.index_count; i += 4) { - if (draw.IsIndexed()) { - vk_buffer.drawIndexed(4, draw.instance_count, i, emit.vertex_offset, - emit.first_instance); - } else { + if (draw.IsIndexed()) { + emit.zero_tail.ForEachDraw(draw.index_count, [&](uint32_t first, uint32_t count) { + for (uint32_t i = 0; i < count; i += 4) { + vk_buffer.drawIndexed(4, draw.instance_count, first + i, emit.vertex_offset, + emit.first_instance); + } + }); ``` <details> <summary>🧩 Analysis chain</summary> 🏁 Script executed: ```shell #!/bin/bash set -euo pipefail ast-grep outline src/graphics/host_gpu/renderer/render.h --match 'ZeroTailDraws' --view expanded rg -n -C 35 'void ForEachDraw|struct ZeroTailDraws' src/graphics/host_gpu/renderer/render.h rg -n -C 20 'ForEachDraw\(|PlanZeroTailDraws\(' tests/ShaderRecompilerComputeTests.cpp rg -n -C 8 'emit\.zero_tail\.ForEachDraw' src/graphics/host_gpu/renderer/renderDraw.cpp ``` Length of output: 10565 --- </details> `@NeySlim`, verified by code inspection. `ZeroTailDraws::ForEachDraw` now processes all segments for one instance before the next. Both indexed emission paths, including quad lists, apply `emit.first_instance + instance`. Unsplit draws retain one draw with all instances. The host check uses three instances and checks the complete `(instance, index)` sequence. I did not run the tests. Thanks for clarifying why a non-indexed zero-tail draw is not equivalent. Primitive-ID resets remain a separate limitation. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: NeySlim Repo: KytyPS5/KytyPS5 PR: 1288 File: src/graphics/host_gpu/renderer/renderDraw.cpp:0-0 Timestamp: 2026-10-09T15:40:18.792Z Learning: In src/graphics/host_gpu/renderer/renderDraw.cpp, indexed zero-tail draws must preserve index-zero vertex IDs plus the base vertex. Replacing the zero tail with a non-indexed draw is not equivalent because non-indexed vertex IDs increase. Split indexed draws can still reset primitive IDs at each draw; instance-major ordering does not preserve primitive IDs. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Split%20indexed%20draws%20now%20preserve%20instance-major%20ordering%20by%20completing%20each%20instance%20before%20the%20next%2C%20matching%20instanced-draw%20behavior%20and%20keeping%20%60gl_InstanceIndex%60%20unchanged.%20The%20fix%20also%20covers%20quad%20lists%20and%20adds%20a%20regression%20test.%20Try%20%40coderabbitai%20for%20sharp%2C%20actionable%20code%20reviews.%20%F0%9F%90%87&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1288%23discussion_r4231662888)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-11 08:35 UTC · original

Rebased on main after the depth to color copy (1029511b). Conflicts in graphicContext.h and renderDraw.cpp: both sides kept.

CopyDepthToColor checks the draw counts on the CPU, so indirect draws with COPY_DEPTH_TO_COLOR now stay on the CPU path (new check in the GpuIndirectDraw test; without the gate it hits the EXIT_NOT_IMPLEMENTED in CopyDepthToColor).

Linux, Radeon 8060S (RADV): GPU suite one case per process and ctest match a clean main build.

**@⁠NeySlim** on GitHub · 2026-10-11 08:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#issuecomment-6107184227) Rebased on main after the depth to color copy (1029511b). Conflicts in graphicContext.h and renderDraw.cpp: both sides kept. `CopyDepthToColor` checks the draw counts on the CPU, so indirect draws with `COPY_DEPTH_TO_COLOR` now stay on the CPU path (new check in the GpuIndirectDraw test; without the gate it hits the `EXIT_NOT_IMPLEMENTED` in `CopyDepthToColor`). Linux, Radeon 8060S (RADV): GPU suite one case per process and ctest match a clean main build.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-13 20:53 UTC · original

Added 90df3b50: draws the CPU path does not draw (patches with tessellation off, line loops, adjacency, quad strips) now only latch NUM_INSTANCES on the GPU, without reading the arguments back. In God of War that was a 6 ms per frame wait in the opening cutscene, 20.3 -> 21.7 fps. Description updated.

**@⁠NeySlim** on GitHub · 2026-10-13 20:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#issuecomment-6154975141) Added 90df3b50: draws the CPU path does not draw (patches with tessellation off, line loops, adjacency, quad strips) now only latch `NUM_INSTANCES` on the GPU, without reading the arguments back. In God of War that was a 6 ms per frame wait in the opening cutscene, 20.3 -> 21.7 fps. Description updated.
Author
Owner

@⁠fozter on GitHub · 2026-10-19 01:30 UTC · original · edited 2026-10-19 07:23 UTC

Tested #1288 with NHL 27 (PPSA34063, 01.003.001) on Windows 11, NVIDIA GeForce RTX 3060 Ti (8 GB), driver 617.42.

Base: main 099de8de plus local patches that are not on main (among them #1271, #1032 with --tessellation, #1211, #1679, and a few NHL-specific fixes from #1101), so this is not a clean-main result.

Tests: shader_cfg_tests and shader_recompiler_compute_tests (including the new GpuIndirectDraw checks) pass on this NVIDIA setup.

In game: with the GPU path active, black triangle fans appear on the ice during gameplay. They all start at center ice (the world origin) and stretch towards players, referees and the benches, as if some vertices of each triangle land at (0, 0, 0). They come and go from frame to frame (screenshots attached). One close-up of a player also showed a glowing, blown-out beard (screenshot attached).

Bisect: I added a local switch that returns false at the top of CommandProcessor::DrawIndirectOnGpu, which keeps every indirect draw on the CPU path but leaves the rest of the PR (including the INDEX_BUFFER_SIZE handling on the CPU path) in place. With the switch set, the fans are gone; without it, they are back. So it is the GPU path itself, not the index-size change.

Counts (counters at the exits of DrawIndirectOnGpu, about 3 minutes from boot into gameplay):

GPU path: 2924 draws
CPU path:
user-SGPR offsets: 0
arguments not GPU-written: 3512
RenderExecutor::DrawIndirect declined: 1756 (tessellation is enabled)
So none of NHL 27's indirect draws name user-SGPR destinations for the offsets, and about 2900 take the GPU path. I have not identified which pipelines the broken ones are yet. If it would help, I can capture a frame with RenderDoc and look at the base vertex / first instance the prepare pass writes for those draws, compared with the CPU path.

Written with AI assistance (Claude Code); the runs and observations are from my machine.
run30_black_wedges_13
run30_black_wedges_16

Edit: forgot to add the screenshot of the festive glowing beard i mentioned
run27_beard_glow

**@⁠fozter** on GitHub · 2026-10-19 01:30 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#issuecomment-6257738890) · edited 2026-10-19 07:23 UTC Tested #1288 with NHL 27 (PPSA34063, 01.003.001) on Windows 11, NVIDIA GeForce RTX 3060 Ti (8 GB), driver 617.42. Base: main 099de8de plus local patches that are not on main (among them #1271, #1032 with --tessellation, #1211, #1679, and a few NHL-specific fixes from #1101), so this is not a clean-main result. Tests: shader_cfg_tests and shader_recompiler_compute_tests (including the new GpuIndirectDraw checks) pass on this NVIDIA setup. In game: with the GPU path active, black triangle fans appear on the ice during gameplay. They all start at center ice (the world origin) and stretch towards players, referees and the benches, as if some vertices of each triangle land at (0, 0, 0). They come and go from frame to frame (screenshots attached). One close-up of a player also showed a glowing, blown-out beard (screenshot attached). Bisect: I added a local switch that returns false at the top of CommandProcessor::DrawIndirectOnGpu, which keeps every indirect draw on the CPU path but leaves the rest of the PR (including the INDEX_BUFFER_SIZE handling on the CPU path) in place. With the switch set, the fans are gone; without it, they are back. So it is the GPU path itself, not the index-size change. Counts (counters at the exits of DrawIndirectOnGpu, about 3 minutes from boot into gameplay): GPU path: 2924 draws CPU path: user-SGPR offsets: 0 arguments not GPU-written: 3512 RenderExecutor::DrawIndirect declined: 1756 (tessellation is enabled) So none of NHL 27's indirect draws name user-SGPR destinations for the offsets, and about 2900 take the GPU path. I have not identified which pipelines the broken ones are yet. If it would help, I can capture a frame with RenderDoc and look at the base vertex / first instance the prepare pass writes for those draws, compared with the CPU path. Written with AI assistance (Claude Code); the runs and observations are from my machine. <img width="1291" height="763" alt="run30_black_wedges_13" src="https://github.com/user-attachments/assets/25aca620-5281-4d9b-bdad-e89cb2b28c1a" /> <img width="1291" height="757" alt="run30_black_wedges_16" src="https://github.com/user-attachments/assets/e02abe78-aad7-406a-8e28-1963d17ec69e" /> Edit: forgot to add the screenshot of the festive glowing beard i mentioned <img width="1280" height="750" alt="run27_beard_glow" src="https://github.com/user-attachments/assets/0f74a2d1-0ec0-4354-9847-5682fc378586" />
Author
Owner

@⁠NeySlim on GitHub · 2026-10-19 02:59 UTC · original

I couldn't reproduce this here: for the same arguments the GPU path records the same draw parameters as the CPU path (a local test comparing both paths on a counted multi-draw with a 32-byte stride, 16-bit indices, a start index, base vertex and first instance gives identical images). What it does change is that the whole packet becomes one vkCmdDrawIndexedIndirectCount, the index buffer is bound over the full INDEX_BUFFER_SIZE instead of the drawn range, and the CPU no longer waits for the GPU at these draws. Could you check whether the broken draws have a count above 1, whether the fans go away if you call GetScheduler().FlushAndWait() at the top of DrawIndirectOnGpu (draws still on the GPU path), and whether the log has any clamped buffer range lines during gameplay? A RenderDoc capture of one bad draw (the prepared commands and the index buffer binding size) would also help.

**@⁠NeySlim** on GitHub · 2026-10-19 02:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#issuecomment-6258688498) I couldn't reproduce this here: for the same arguments the GPU path records the same draw parameters as the CPU path (a local test comparing both paths on a counted multi-draw with a 32-byte stride, 16-bit indices, a start index, base vertex and first instance gives identical images). What it does change is that the whole packet becomes one `vkCmdDrawIndexedIndirectCount`, the index buffer is bound over the full INDEX_BUFFER_SIZE instead of the drawn range, and the CPU no longer waits for the GPU at these draws. Could you check whether the broken draws have a count above 1, whether the fans go away if you call `GetScheduler().FlushAndWait()` at the top of `DrawIndirectOnGpu` (draws still on the GPU path), and whether the log has any `clamped buffer range` lines during gameplay? A RenderDoc capture of one bad draw (the prepared commands and the index buffer binding size) would also help.
Author
Owner

@⁠fozter on GitHub · 2026-10-19 07:38 UTC · original

Thanks for looking into it. Answers from 4 more runs with the GPU path on (same setup otherwise):

  1. Count: none above 1. A counter over every packet that took the GPU path (from about 1,400 to over 4,000 per run) found only a fixed count of 1, none with a count address, none with a count above 1. The packets I sampled (1 in every 1,024, 10 in total) were all non-indexed with a 16-byte stride. So the case here is a single draw, not the counted indexed multi-draw your comparison test covers.
  2. FlushAndWait: I couldn't get a clean comparison. In the 4 runs without the flush, the fans didn't show up at all: one run went about 4 minutes past the puck drop, the other 3 were shorter. In the 1st run the fans were already visible at the opening faceoff, and an earlier run with the PR played a whole period without fans (only the glowing beard). So the fans are intermittent, which fits a timing or ordering difference better than different draw parameters. Since they don't show up every run, one clean run with the flush would not prove much, but I can repeat it a few times.
  3. Clamped buffer range: none in these 4 runs (I also sent that log line to stderr, since my launcher doesn't keep the normal log). The 1st run, the one with the fans, didn't keep that log, so I can't tell for that one.

I will try a RenderDoc capture of a bad frame (the prepared commands and the index buffer binding size) once it reproduces again.

**@⁠fozter** on GitHub · 2026-10-19 07:38 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#issuecomment-6262181708) Thanks for looking into it. Answers from 4 more runs with the GPU path on (same setup otherwise): 1. **Count:** none above 1. A counter over every packet that took the GPU path (from about 1,400 to over 4,000 per run) found only a fixed count of 1, none with a count address, none with a count above 1. The packets I sampled (1 in every 1,024, 10 in total) were all non-indexed with a 16-byte stride. So the case here is a single draw, not the counted indexed multi-draw your comparison test covers. 2. **FlushAndWait:** I couldn't get a clean comparison. In the 4 runs without the flush, the fans didn't show up at all: one run went about 4 minutes past the puck drop, the other 3 were shorter. In the 1st run the fans were already visible at the opening faceoff, and an earlier run with the PR played a whole period without fans (only the glowing beard). So the fans are intermittent, which fits a timing or ordering difference better than different draw parameters. Since they don't show up every run, one clean run with the flush would not prove much, but I can repeat it a few times. 3. **Clamped buffer range:** none in these 4 runs (I also sent that log line to stderr, since my launcher doesn't keep the normal log). The 1st run, the one with the fans, didn't keep that log, so I can't tell for that one. I will try a RenderDoc capture of a bad frame (the prepared commands and the index buffer binding size) once it reproduces again.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-19 11:44 UTC · original

Thanks, that narrows it down a lot. I went through the ordering for exactly that case (non-indexed, count 1, stride 16, arguments written by a compute dispatch) and added a local test that rewrites the arguments with a dispatch before each of several draws with no CPU wait in between: every draw reads its own arguments here, and the prepare pass sits between full memory barriers on the same queue, so I still can't see where it would read stale ones. If you catch it in RenderDoc, the useful part is the Kyty.IndirectDrawCommands buffer at the offset of the bad vkCmdDrawIndirectCount (draw count, vertex count, instance count, first vertex, first instance), compared with the 16 guest argument bytes in the game buffer the prepare dispatch just before it reads, plus the vertex buffers bound for that draw and their sizes. If the vertex count there looks sane, the zeros probably come from the vertex data rather than the arguments.

**@⁠NeySlim** on GitHub · 2026-10-19 11:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#issuecomment-6266424916) Thanks, that narrows it down a lot. I went through the ordering for exactly that case (non-indexed, count 1, stride 16, arguments written by a compute dispatch) and added a local test that rewrites the arguments with a dispatch before each of several draws with no CPU wait in between: every draw reads its own arguments here, and the prepare pass sits between full memory barriers on the same queue, so I still can't see where it would read stale ones. If you catch it in RenderDoc, the useful part is the `Kyty.IndirectDrawCommands` buffer at the offset of the bad `vkCmdDrawIndirectCount` (draw count, vertex count, instance count, first vertex, first instance), compared with the 16 guest argument bytes in the game buffer the prepare dispatch just before it reads, plus the vertex buffers bound for that draw and their sizes. If the vertex count there looks sane, the zeros probably come from the vertex data rather than the arguments.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-21 16:19 UTC · original

Rebased on main and added d7cbd4984: tessellated patch draws (LS, HS, TES) with GPU-written arguments now take the GPU path too, instead of staying on the CPU path.

With --tessellation, these were the only indirect draws still read back in the GoW opening cutscene: about 18 per second, each blocking the command thread for about 7 ms (it waits for all submitted GPU work). With the change there are none left there and the cutscene goes from about 18.5 to 19.6-19.8 fps here (Radeon 8060S, RADV 26.2.5, with my other open PRs). Sled section unchanged, rendering identical.

New GpuIndirectDraw check: an indexed and a non-indexed tessellated patch draw with GPU-written arguments, drawn without a readback, with the HS patch output reaching the target. It fails on the old code (the draw falls back to the CPU path) and when the GPU path records no draw. The old check that tessellated patches stay on the CPU path is gone.

**@⁠NeySlim** on GitHub · 2026-10-21 16:19 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#issuecomment-6320841021) Rebased on main and added d7cbd4984: tessellated patch draws (LS, HS, TES) with GPU-written arguments now take the GPU path too, instead of staying on the CPU path. With `--tessellation`, these were the only indirect draws still read back in the GoW opening cutscene: about 18 per second, each blocking the command thread for about 7 ms (it waits for all submitted GPU work). With the change there are none left there and the cutscene goes from about 18.5 to 19.6-19.8 fps here (Radeon 8060S, RADV 26.2.5, with my other open PRs). Sled section unchanged, rendering identical. New `GpuIndirectDraw` check: an indexed and a non-indexed tessellated patch draw with GPU-written arguments, drawn without a readback, with the HS patch output reaching the target. It fails on the old code (the draw falls back to the CPU path) and when the GPU path records no draw. The old check that tessellated patches stay on the CPU path is gone.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-23 17:12 UTC · original

Closing this one. c513a4a13, 949de19bb and 86fed10b8 cover what it was for: in GoW every indirect draw now takes the GPU path on main, with no readback left, and a rebased port of this branch measured the same or slightly slower.

Two things from here still differ on main. Indices past INDEX_BUFFER_SIZE are read from memory instead of returning 0, and offsets without an SGPR destination still apply vertexOffset/firstInstance, which the hardware ignores. I'll send the index range as its own small PR.

**@⁠NeySlim** on GitHub · 2026-10-23 17:12 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1288#issuecomment-6370505952) Closing this one. c513a4a13, 949de19bb and 86fed10b8 cover what it was for: in GoW every indirect draw now takes the GPU path on main, with no readback left, and a rebased port of this branch measured the same or slightly slower. Two things from here still differ on main. Indices past INDEX_BUFFER_SIZE are read from memory instead of returning 0, and offsets without an SGPR destination still apply vertexOffset/firstInstance, which the hardware ignores. I'll send the index range as its own small PR.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.