A Game About Digging A Hole: fix crash, GPU hang and grey image on AMD (Windows) #2302

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

@⁠Oskie5802 on GitHub · 2026-11-16 17:15 UTC · original
Oskie5802:digging-hole-amd-mesh → main · +518 −365 · 7 files · 4 commits · open

Game:

A Game About Digging A Hole (PPSA30552, 01.100.000)

Problem:

On an AMD Radeon RX 6600 (Windows 11, Adrenalin 26.10.1) the game never showed a correct image:

  1. The emulator crashed inside vkCreateGraphicsPipelines on the first mesh shader.
  2. With that fixed, the first indirect mesh draw hung the GPU (VK_ERROR_DEVICE_LOST).
  3. With that worked around, the image was grey and over-exposed.

On NVIDIA the game renders in colour (see #2249), so all three are specific to AMD's Windows driver.

Changes:

One commit per problem:

  • shader: the per-primitive Layer output is declared as a Block member, the way glslang
    declares gl_MeshPrimitivesEXT. A bare PerPrimitiveEXT Layer array crashes the driver.
  • graphics: on AMD/Windows, indirect mesh draw records go through the existing CPU path instead
    of a task shader. DrawIndirectMulti now reads the records back from the GPU first, because the
    game writes them there.
  • graphics: on AMD/Windows, layered mesh draws run once per 8 layers. The driver renders layer
    L into layer L mod 8, so the game's 32-layer colour-grading LUT had only 8 layers filled.

All three workarounds are limited to vendor 0x1002 on Windows.

Evidence

  • Before:
    image

  • After: Zrzut ekranu 2026-11-16 153625

  • Standalone repro of the Layer bug outside the emulator: layer i lands in slice i mod 8.

Testing

  • Played from boot through the menu into gameplay on RX 6600.
  • CI test list on Windows: 31/32 pass; resource_materialization fails on unmodified main too.
  • Not tested on NVIDIA, Intel, Linux or other AMD generations.

Known remaining issue

Black 128x128 px squares appear during the intro and cutscene on this card (motion blur). reported in #2303 .

Formatting

The clang-format hook reformatted the touched files, which is most of the line count.

AI use

The investigation and the code were done with Claude Fable 5.2. I reviewed the changes and
tested them on my own hardware as described, this description are writted by human - Me :) and corrected by AI

Fixes #2249

**@⁠Oskie5802** on GitHub · 2026-11-16 17:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302) `Oskie5802:digging-hole-amd-mesh` → `main` · +518 −365 · 7 files · 4 commits · open ### Game: A Game About Digging A Hole (PPSA30552, 01.100.000) ### Problem: On an AMD Radeon RX 6600 (Windows 11, Adrenalin 26.10.1) the game never showed a correct image: 1. The emulator crashed inside `vkCreateGraphicsPipelines` on the first mesh shader. 2. With that fixed, the first indirect mesh draw hung the GPU (`VK_ERROR_DEVICE_LOST`). 3. With that worked around, the image was grey and over-exposed. On NVIDIA the game renders in colour (see #2249), so all three are specific to AMD's Windows driver. ### Changes: One commit per problem: - **shader:** the per-primitive `Layer` output is declared as a `Block` member, the way glslang declares `gl_MeshPrimitivesEXT`. A bare `PerPrimitiveEXT` Layer array crashes the driver. - **graphics:** on AMD/Windows, indirect mesh draw records go through the existing CPU path instead of a task shader. `DrawIndirectMulti` now reads the records back from the GPU first, because the game writes them there. - **graphics:** on AMD/Windows, layered mesh draws run once per 8 layers. The driver renders layer `L` into layer `L mod 8`, so the game's 32-layer colour-grading LUT had only 8 layers filled. All three workarounds are limited to vendor `0x1002` on Windows. ### Evidence - Before: <img width="874" height="491" alt="image" src="https://github.com/user-attachments/assets/21dc6236-9b22-49ed-bdaa-1d12c518047c" /> - After: <img width="1310" height="777" alt="Zrzut ekranu 2026-11-16 153625" src="https://github.com/user-attachments/assets/7c85d82f-e53f-4e6d-9890-30d0d6ae412a" /> - Standalone repro of the Layer bug outside the emulator: layer `i` lands in slice `i mod 8`. ### Testing - Played from boot through the menu into gameplay on RX 6600. - CI test list on Windows: 31/32 pass; `resource_materialization` fails on unmodified `main` too. - Not tested on NVIDIA, Intel, Linux or other AMD generations. ### Known remaining issue Black 128x128 px squares appear during the intro and cutscene on this card (motion blur). reported in #2303 . ### Formatting The clang-format hook reformatted the touched files, which is most of the line count. ### AI use The investigation and the code were done with Claude Fable 5.2. I reviewed the changes and tested them on my own hardware as described, this description are writted by human - Me :) and corrected by AI Fixes #2249
AMD's Windows driver (Adrenalin 26.10.1, RX 6600) faults in
vkCreateGraphicsPipelines on a bare Layer output array decorated
PerPrimitiveEXT. A Game About Digging A Hole (PPSA30552) compiles such a mesh
shader before its first frame and the emulator crashed there. glslang declares
gl_MeshPrimitivesEXT the same way.
AMD's Windows driver (Adrenalin 26.10.1, RX 6600) hangs the GPU on the first
task+mesh draw before any task or mesh wave starts; A Game About Digging A
Hole (PPSA30552) lost the device on its first indirect mesh draw. On that
vendor the records take the existing CPU path instead of a task shader.

The game writes those records on the GPU, so DrawIndirectMulti brings them
back before reading them, as DispatchIndirect already does.
AMD's Windows driver (Adrenalin 26.10.1, RX 6600) renders a mesh shader's
per-primitive Layer L into layer L mod 8. A Game About Digging A Hole
(PPSA30552) builds its 32-layer colour-grading LUT with one such draw, so 24
layers stayed black and the image came out grey and over-exposed.

On that vendor a layered mesh draw runs once per chunk of 8 layers, on views
starting at the chunk. The mesh shader culls the other chunks' primitives and
writes the layer within the chunk; a pixel shader reading the layer adds the
chunk's base back.
The chunk dword is reserved for every mesh draw on AMD's Windows driver but
was only written for mesh shaders with a Layer output, so a later draw without
one could inherit the last chunk of an earlier layered draw and its pixel
shader would read a shifted layer.

The repeated chunks of a layered draw ran outside the occlusion query, so
samples in layers 8 and up were not counted. Each chunk now has its own query.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:18:21 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 17:27 UTC · original · edited 2026-11-17 13:41 UTC

Explain Change →

Walkthrough

The change adds chunked layered mesh rendering for eligible non-task mesh draws. It updates pipeline setup and SPIR-V generation to pass a layer-chunk index, filter mesh primitives, and adjust pixel-stage Layer inputs. It also changes Windows AMD indirect mesh draws to avoid the task-shader path. Separately, the CPU indirect-draw fallback reads its records through the buffer cache.

Suggested reviewers: nmzik, senaxx

Change: Bug fix

Merge Risk: Moderate · up to 7124a

The change fixes the crash, GPU hang and grey image on AMD Windows. Layered mesh draws that write buffers can double-apply those writes, and a pixel shader that reads Layer without user data or buffers can fail pipeline creation. Both are narrow, but they should be fixed or explicitly accepted before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the game, the three problems fixed (crash, GPU hang, grey image), and the AMD/Windows scope. The changeset adds AMD/Windows-specific workarounds for each of these: a Layer block-member…
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.
Description check Passed The description states a concrete problem (crash in vkCreateGraphicsPipelines, GPU hang, grey image on an AMD Radeon RX 6600 under Windows), lists three specific changes (Layer declared as a Block mem…
Full details: Title check

Explanation

The title names the game, the three problems fixed (crash, GPU hang, grey image), and the AMD/Windows scope. The changeset adds AMD/Windows-specific workarounds for each of these: a Layer block-member declaration fix in the mesh emitter, CPU-path routing for indirect mesh draws with a buffer read-back, and per-8-layer chunked mesh draws. The title is a single sentence and matches the main change. It is somewhat long at 81 characters, but it is clear and specific.

Full details: Description check

Explanation

The description states a concrete problem (crash in vkCreateGraphicsPipelines, GPU hang, grey image on an AMD Radeon RX 6600 under Windows), lists three specific changes (Layer declared as a Block member, CPU path for indirect mesh draws with readback, layered mesh draws run per 8 layers), and gives testing notes and a known remaining issue. These map directly onto the changeset in the shader, graphics, pipeline, and render files. The description is related to the changes and not off-topic, so the check passes.

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 17:27 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302#issuecomment-6923857393) · edited 2026-11-17 13:41 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/2302?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-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> The change adds chunked layered mesh rendering for eligible non-task mesh draws. It updates pipeline setup and SPIR-V generation to pass a layer-chunk index, filter mesh primitives, and adjust pixel-stage Layer inputs. It also changes Windows AMD indirect mesh draws to avoid the task-shader path. Separately, the CPU indirect-draw fallback reads its records through the buffer cache. **Suggested reviewers:** `nmzik`, `senaxx` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"7124af18706204d7c24cd976a1f686f85267c39e" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-normal-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Moderate</strong> · up to <code>7124a</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🟡 Moderate** · up to `7124a` --> <!-- final_review_risk_coverage:{"sourceCommitId":"7124af18706204d7c24cd976a1f686f85267c39e","coveredCommitId":"7124af18706204d7c24cd976a1f686f85267c39e","kind":"reviewed"} --> The change fixes the crash, GPU hang and grey image on AMD Windows. Layered mesh draws that write buffers can double-apply those writes, and a pixel shader that reads Layer without user data or buffers can fail pipeline creation. Both are narrow, but they should be fixed or explicitly accepted 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</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title names the game, the three problems fixed (crash, GPU hang, grey image), and the AMD/Windows scope. The changeset adds AMD/Windows-specific workarounds for each of these: a Layer block-member… | | 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. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description states a concrete problem (crash in vkCreateGraphicsPipelines, GPU hang, grey image on an AMD Radeon RX 6600 under Windows), lists three specific changes (Layer declared as a Block mem… | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title names the game, the three problems fixed (crash, GPU hang, grey image), and the AMD/Windows scope. The changeset adds AMD/Windows-specific workarounds for each of these: a Layer block-member declaration fix in the mesh emitter, CPU-path routing for indirect mesh draws with a buffer read-back, and per-8-layer chunked mesh draws. The title is a single sentence and matches the main change. It is somewhat long at 81 characters, but it is clear and specific. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description states a concrete problem (crash in vkCreateGraphicsPipelines, GPU hang, grey image on an AMD Radeon RX 6600 under Windows), lists three specific changes (Layer declared as a Block member, CPU path for indirect mesh draws with readback, layered mesh draws run per 8 layers), and gives testing notes and a known remaining issue. These map directly onto the changeset in the shader, graphics, pipeline, and render files. The description is related to the changes and not off-topic, so the check passes. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2302)! 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> <br> - [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> <!-- tips_end -->
@ -639,0 +638,4 @@
const uint64_t extent =
resource.OutOfBounds() == 2
? resource.Base48() - buffer.addr +
ShaderRecompiler::Format::GetFormatInfo(resource.Format()).byte_size
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 17:27 UTC · original · edited 2026-11-16 18:44 UTC

Minor · Functional Correctness · Quick win

Preserve the existing vertex-format fallbacks when sizing buffers.

For stride=0, NumRecords=16, OutOfBounds()==2, and raw format 113, GetFormatInfo(resource.Format()).byte_size is zero. With no address offset, this makes AcquireVertexBuffers bind a zero-length null buffer. However, InputFormat explicitly accepts format 113 through its R32G32B32A32Sfloat fallback. The previous size was 16 bytes. Derive the extent from the effective host format, including these fallbacks. (raw.githubusercontent.com)

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 17:27 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302#discussion_r4589129120) · edited 2026-11-16 18:44 UTC <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Functional Correctness** · **Quick win** **Preserve the existing vertex-format fallbacks when sizing buffers.** For `stride=0`, `NumRecords=16`, `OutOfBounds()==2`, and raw format `113`, `GetFormatInfo(resource.Format()).byte_size` is zero. With no address offset, this makes `AcquireVertexBuffers` bind a zero-length null buffer. However, `InputFormat` explicitly accepts format `113` through its `R32G32B32A32Sfloat` fallback. The previous size was 16 bytes. Derive the extent from the effective host format, including these fallbacks. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/0cbda940517908cbd16b4a518202ab9b621b2868/src/graphics/shader/shaderBindings.h)) <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:3ed186a4562c9d5b6b9c4b39 --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 17:27 UTC · original · edited 2026-11-16 18:43 UTC
On src/graphics/host_gpu/renderer/renderDraw.cpp line 1214 (outdated):

@@ -1205,6 +1209,20 @@ void RenderExecutor::ExecutePreparedDraw(CommandBuffer& buffer, const DrawCallIn
 		buffer.EndRendering();
 		ShaderWriteHazardBarrier(vk_buffer, shader_write_stages);
 	}
+	const auto layer_chunk_dword   = state.vertex_info[0].mesh.layer_chunk_dword;
+	uint32_t   layered_mesh_chunks = 0;
+	if (mesh_active && !mesh_task && layer_chunk_dword != UINT32_MAX) {

Major · Functional Correctness · Quick win

Initialize the chunk slot even when the mesh shader has no Layer output.

On Windows AMD, pipeline setup reserves this slot and enables the pixel-stage adjustment for every mesh draw. This block initializes the slot only when the mesh shader exports Layer.

After a 32-layer draw leaves chunk 3 in the slot, a mesh draw without that output can reuse the value. A pixel shader that reads Layer then receives 24 instead of 0. Initialize every reserved chunk slot to zero before the output check. Vulkan uses the first layer when the mesh interface has no Layer output. (docs.vulkan.org)

✅ Confirmed as addressed by @⁠Oskie5802

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 17:27 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302#discussion_r4589129129) · edited 2026-11-16 18:43 UTC On `src/graphics/host_gpu/renderer/renderDraw.cpp` line 1214 (outdated): ```diff @@ -1205,6 +1209,20 @@ void RenderExecutor::ExecutePreparedDraw(CommandBuffer& buffer, const DrawCallIn buffer.EndRendering(); ShaderWriteHazardBarrier(vk_buffer, shader_write_stages); } + const auto layer_chunk_dword = state.vertex_info[0].mesh.layer_chunk_dword; + uint32_t layered_mesh_chunks = 0; + if (mesh_active && !mesh_task && layer_chunk_dword != UINT32_MAX) { ``` <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Quick win** **Initialize the chunk slot even when the mesh shader has no Layer output.** On Windows AMD, pipeline setup reserves this slot and enables the pixel-stage adjustment for every mesh draw. This block initializes the slot only when the mesh shader exports `Layer`. After a 32-layer draw leaves chunk `3` in the slot, a mesh draw without that output can reuse the value. A pixel shader that reads `Layer` then receives `24` instead of `0`. Initialize every reserved chunk slot to zero before the output check. Vulkan uses the first layer when the mesh interface has no `Layer` output. ([docs.vulkan.org](https://docs.vulkan.org/refpages/latest/refpages/source/Layer.html)) <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:db6ffe41767094ae515df78f --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠Oskie5802 <!-- This is an auto-generated comment by CodeRabbit -->
@ -1225,0 +1271,4 @@
vk_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.pipeline);
// Each chunk counts its own samples; the dump adds the queries up.
const int32_t chunk_query = occlusion_queries.Begin(vk_buffer);
vk_buffer.drawMeshTasksEXT(mesh_groups, draw.instance_count, 1);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 17:27 UTC · original · edited 2026-11-16 18:43 UTC

Major · Data Integrity & Integration · Heavy lift

Preserve mesh shader side effects across chunk replays.

A 32-layer draw executes the complete guest mesh program four times. If that program increments a buffer counter once per workgroup, the counter increments four times. The chunk filter cannot prevent this: EmitMeshEntryPoint calls mesh_guest_func before it applies primitive culling. Preserve one execution of guest side effects, or use a separate path for side-effecting mesh programs. Adding barriers alone does not correct the duplicate writes. (raw.githubusercontent.com)


Major · Functional Correctness · Quick win

Count occlusion samples from every chunk.

The native occlusion query ends before this loop. If a 16-layer draw has visible geometry only in Layer 9, chunk zero contributes no samples. Chunk one renders that geometry outside any query, so the guest receives zero samples.

Begin and end a query inside each chunk's rendering scope. Let OcclusionQueries aggregate those results through its existing dump path. (raw.githubusercontent.com)

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 17:27 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302#discussion_r4589129141) · edited 2026-11-16 18:43 UTC <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Data Integrity & Integration** · **Heavy lift** **Preserve mesh shader side effects across chunk replays.** A 32-layer draw executes the complete guest mesh program four times. If that program increments a buffer counter once per workgroup, the counter increments four times. The chunk filter cannot prevent this: `EmitMeshEntryPoint` calls `mesh_guest_func` before it applies primitive culling. Preserve one execution of guest side effects, or use a separate path for side-effecting mesh programs. Adding barriers alone does not correct the duplicate writes. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/0cbda940517908cbd16b4a518202ab9b621b2868/src/graphics/shader/recompiler/backend/spirv/spirvEmitterMesh.cpp)) <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:10dc253cf94622344fbd9b0f --> --- **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major** · **Functional Correctness** · **Quick win** **Count occlusion samples from every chunk.** The native occlusion query ends before this loop. If a 16-layer draw has visible geometry only in Layer `9`, chunk zero contributes no samples. Chunk one renders that geometry outside any query, so the guest receives zero samples. Begin and end a query inside each chunk's rendering scope. Let `OcclusionQueries` aggregate those results through its existing dump path. ([raw.githubusercontent.com](https://raw.githubusercontent.com/KytyPS5/KytyPS5/0cbda940517908cbd16b4a518202ab9b621b2868/src/graphics/host_gpu/renderer/occlusionQueries.h)) <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:8cbf17a2d5c3a7ec6f92c7f9 --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 17:27 UTC · original · reviewed

Actionable comments posted: 4

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 41e2147c07 and 0cbda940517908cbd16b4a518202ab9b621b2868.

Files selected for processing: 7

  • src/graphics/guest_gpu/graphicsRun.cpp
  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
  • src/graphics/host_gpu/renderer/renderDraw.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterMesh.cpp
  • src/graphics/shader/shader.cpp
  • src/graphics/shader/shader.h

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 17:27 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302#pullrequestreview-5924399873) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 4** <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/41e2147c07bcc6d2206cb2b84e4646497896a18e/.coderabbit.yaml>) - **Commit**: [41e2147](<https://github.com/KytyPS5/KytyPS5/commit/41e2147c07bcc6d2206cb2b84e4646497896a18e>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `d2fe9d0a-1563-4531-9e2e-bccfdef62234` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 41e2147c07bcc6d2206cb2b84e4646497896a18e and 0cbda940517908cbd16b4a518202ab9b621b2868. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 7</summary> <dl> <dd> <br> * `src/graphics/guest_gpu/graphicsRun.cpp` * `src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp` * `src/graphics/host_gpu/renderer/renderDraw.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterMesh.cpp` * `src/graphics/shader/shader.cpp` * `src/graphics/shader/shader.h` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=b6f8b59d-26a3-49c9-8d9a-c56fd4888859 attempt=6d1bec47-d1ec-4506-81ce-e80a3fae9e0d batch=1/1 -->
Author
Owner

@⁠Oskie5802 on GitHub · 2026-11-16 18:43 UTC · original
On src/graphics/host_gpu/renderer/renderDraw.cpp line 1214 (outdated):

@@ -1205,6 +1209,20 @@ void RenderExecutor::ExecutePreparedDraw(CommandBuffer& buffer, const DrawCallIn
 		buffer.EndRendering();
 		ShaderWriteHazardBarrier(vk_buffer, shader_write_stages);
 	}
+	const auto layer_chunk_dword   = state.vertex_info[0].mesh.layer_chunk_dword;
+	uint32_t   layered_mesh_chunks = 0;
+	if (mesh_active && !mesh_task && layer_chunk_dword != UINT32_MAX) {

Fixed in 8e5e654a. The chunk is now reset to 0 for every draw that has the slot, not only for mesh shaders with a Layer output.

**@⁠Oskie5802** on GitHub · 2026-11-16 18:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302#discussion_r4589945028) On `src/graphics/host_gpu/renderer/renderDraw.cpp` line 1214 (outdated): ```diff @@ -1205,6 +1209,20 @@ void RenderExecutor::ExecutePreparedDraw(CommandBuffer& buffer, const DrawCallIn buffer.EndRendering(); ShaderWriteHazardBarrier(vk_buffer, shader_write_stages); } + const auto layer_chunk_dword = state.vertex_info[0].mesh.layer_chunk_dword; + uint32_t layered_mesh_chunks = 0; + if (mesh_active && !mesh_task && layer_chunk_dword != UINT32_MAX) { ``` Fixed in 8e5e654a. The chunk is now reset to 0 for every draw that has the slot, not only for mesh shaders with a Layer output.
@ -1225,0 +1271,4 @@
vk_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.pipeline);
// Each chunk counts its own samples; the dump adds the queries up.
const int32_t chunk_query = occlusion_queries.Begin(vk_buffer);
vk_buffer.drawMeshTasksEXT(mesh_groups, draw.instance_count, 1);
Author
Owner

@⁠Oskie5802 on GitHub · 2026-11-16 18:43 UTC · original

fixed in 8e5e654a, each chunk now runs inside its own query and the existing dump sums them.

Side effects: you're right that the guest mesh program runs once per chunk. I left it as is for now. The only layered mesh draw I've seen in this game is the colour grading LUT and that shader doesn't write to any buffer. Doing it properly would need a separate path for mesh programs with buffer writes, which felt too big for this PR. Happy to add a guard if the maintainers prefer.

**@⁠Oskie5802** on GitHub · 2026-11-16 18:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302#discussion_r4589950496) fixed in 8e5e654a, each chunk now runs inside its own query and the existing dump sums them. Side effects: you're right that the guest mesh program runs once per chunk. I left it as is for now. The only layered mesh draw I've seen in this game is the colour grading LUT and that shader doesn't write to any buffer. Doing it properly would need a separate path for mesh programs with buffer writes, which felt too big for this PR. Happy to add a guard if the maintainers prefer.
@ -639,0 +638,4 @@
const uint64_t extent =
resource.OutOfBounds() == 2
? resource.Base48() - buffer.addr +
ShaderRecompiler::Format::GetFormatInfo(resource.Format()).byte_size
Author
Owner

@⁠Oskie5802 on GitHub · 2026-11-16 18:43 UTC · original

I didn't change this code, it only shows up in the diff because the clang-format hook reformatted the whole file. Behaviour here is the same as on main.

**@⁠Oskie5802** on GitHub · 2026-11-16 18:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302#discussion_r4589954015) I didn't change this code, it only shows up in the diff because the clang-format hook reformatted the whole file. Behaviour here is the same as on main.
@ -639,0 +638,4 @@
const uint64_t extent =
resource.OutOfBounds() == 2
? resource.Base48() - buffer.addr +
ShaderRecompiler::Format::GetFormatInfo(resource.Format()).byte_size
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 18:44 UTC · original

@⁠Oskie5802 You’re right. The diff only reformats the expression; it does not change the buffer size calculation. My statement that the previous size was 16 bytes was incorrect.

I’m withdrawing the finding for this PR. Sorry for the confusion.

Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 18:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302#discussion_r4589959323) <!-- coderabbit-ai-generated:v1 --> @⁠Oskie5802 You’re right. The diff only reformats the expression; it does not change the buffer size calculation. My statement that the previous size was 16 bytes was incorrect. I’m withdrawing the finding for this PR. Sorry for the confusion. <!-- <review_comment_withdrawn> --> Review thread resolved. <sub><i>You are interacting with an AI system.</i></sub> <!-- This is an auto-generated reply by CodeRabbit -->
@ -1225,0 +1271,4 @@
vk_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.pipeline);
// Each chunk counts its own samples; the dump adds the queries up.
const int32_t chunk_query = occlusion_queries.Begin(vk_buffer);
vk_buffer.drawMeshTasksEXT(mesh_groups, draw.instance_count, 1);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 18:44 UTC · original

Analysis chain

Script executed:

#!/bin/bash
set -u

printf '%s\n' '--- Occlusion query files ---'
while IFS= read -r file; do
  printf '\n--- %s ---\n' "$file"
  ast-grep outline "$file" --items all 2>/dev/null || true
  rg -n -C 8 '(^|[^[:alnum:]_])(Begin|End|Dump|dump|sum|accumulate)([^[:alnum:]_]|$)' "$file" || true
done < <(fd -i -t f 'occlusionquer' src)

printf '\n%s\n' '--- Mesh shader execution and layer filtering ---'
file='src/graphics/shader/recompiler/backend/spirv/spirvEmitterMesh.cpp'
ast-grep outline "$file" --match 'EmitMeshEntryPoint' --view expanded 2>/dev/null || true
rg -n -C 8 'mesh_guest_func|layer_chunk_dword|CullPrimitive' "$file" || true

Length of output: 8743


@Oskie5802 Thanks for the fix and the context. Each chunk now has its own query, and OcclusionQueries::PublishDumps adds the results to the running counter.

I understand the decision to defer the mesh side-effects path. The reported colour-grading LUT has no buffer writes, but other mesh shaders can still repeat side effects. I won’t mark this thread as addressed while that concern remains.


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

Thank you for using CodeRabbit!

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 18:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302#discussion_r4589965118) <!-- coderabbit-ai-generated:v1 --> <details> <summary>Analysis chain</summary> <dl> <dd> <br> Script executed: ```shell #!/bin/bash set -u printf '%s\n' '--- Occlusion query files ---' while IFS= read -r file; do printf '\n--- %s ---\n' "$file" ast-grep outline "$file" --items all 2>/dev/null || true rg -n -C 8 '(^|[^[:alnum:]_])(Begin|End|Dump|dump|sum|accumulate)([^[:alnum:]_]|$)' "$file" || true done < <(fd -i -t f 'occlusionquer' src) printf '\n%s\n' '--- Mesh shader execution and layer filtering ---' file='src/graphics/shader/recompiler/backend/spirv/spirvEmitterMesh.cpp' ast-grep outline "$file" --match 'EmitMeshEntryPoint' --view expanded 2>/dev/null || true rg -n -C 8 'mesh_guest_func|layer_chunk_dword|CullPrimitive' "$file" || true ``` Length of output: 8743 --- </dd> </dl> </details> `@Oskie5802` Thanks for the fix and the context. Each chunk now has its own query, and `OcclusionQueries::PublishDumps` adds the results to the running counter. I understand the decision to defer the mesh side-effects path. The reported colour-grading LUT has no buffer writes, but other mesh shaders can still repeat side effects. I won’t mark this thread as addressed while that concern remains. --- <!-- 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=%40coderabbitai%20caught%20two%20mesh-rendering%20edge%20cases%3A%20query%20every%20chunk%20to%20aggregate%20occlusion%20samples%2C%20and%20prevent%20duplicate%20guest%20side%20effects%20across%20replays.%20Try%20CodeRabbit%20for%20sharper%20reviews%20%F0%9F%90%87&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F2302%23discussion_r4589129141)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> <sub><i>You are interacting with an AI system.</i></sub> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠virgil48YT on GitHub · 2026-11-16 18:48 UTC · original

This PR fixes Stray and gets it ingame for RDNA2 cards, before it was crashing with error code 0x4 with vkCreateGraphicsPipelines. Nice work!
image
image

**@⁠virgil48YT** on GitHub · 2026-11-16 18:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302#issuecomment-6925778061) This PR fixes Stray and gets it ingame for RDNA2 cards, before it was crashing with error code 0x4 with vkCreateGraphicsPipelines. Nice work! <img width="1258" height="737" alt="image" src="https://github.com/user-attachments/assets/2fc3abd4-572e-4817-8616-7ee98aaa0b7a" /> <img width="1271" height="745" alt="image" src="https://github.com/user-attachments/assets/088f947e-79d7-45a4-b845-c69b9e972c40" />
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-16 19:51 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 · The pixel-stage layer push load can use an undeclared… · spirvEmitterModule.cpp:240-270

src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp:240-270
Minor · Stability & Availability · Quick win

The pixel-stage layer push load can use an undeclared push-constant variable.

For a pixel shader with no user data registers and no buffers, ShaderDataDwords() is 0. StartFor then returns NoStart, so the push-constant block is not declared. The pixel Layer path still loads layer_chunk_dword through EmitPushDataLoad, which uses the undeclared variable id 0. The generated SPIR-V can then be invalid, and pipeline creation can fail.

The declaration guard in spirvEmitterModule.cpp should also declare the block when the pixel stage reads a layer chunk dword.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8e5e654a0b0e5991fccf406cc311d672834d4037 and 7124af1870.

Files selected for processing: 5

  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
  • src/graphics/host_gpu/renderer/renderDraw.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterMesh.cpp
  • src/graphics/shader/shader.cpp
  • src/graphics/shader/shader.h

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-16 19:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2302#pullrequestreview-5926490409) · **reviewed** <!-- coderabbit-ai-generated:v1 --> > [!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><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor</strong> · The pixel-stage layer push load can use an undeclared… · <code>spirvEmitterModule.cpp:240-270</code></summary><blockquote> > <dl> > <dd> > <br> > > `src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp:240-270` > **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Stability & Availability** · **Quick win** > > **The pixel-stage layer push load can use an undeclared push-constant variable.** > > For a pixel shader with no user data registers and no buffers, `ShaderDataDwords()` is 0. `StartFor` then returns `NoStart`, so the push-constant block is not declared. The pixel `Layer` path still loads `layer_chunk_dword` through `EmitPushDataLoad`, which uses the undeclared variable id 0. The generated SPIR-V can then be invalid, and pipeline creation can fail. > > The declaration guard in `spirvEmitterModule.cpp` should also declare the block when the pixel stage reads a layer chunk dword. > > <!-- cr-comment:v1:8c211b090df96b114d9aa313 --> > > </dd> > </dl> > </blockquote></details> <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/d45b0865d85ced3da80f43ef2a2ecbeca6296637/.coderabbit.yaml>) - **Commit**: [d45b086](<https://github.com/KytyPS5/KytyPS5/commit/d45b0865d85ced3da80f43ef2a2ecbeca6296637>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `daa72b5b-692c-475f-aeb3-f539447c7d3f` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 8e5e654a0b0e5991fccf406cc311d672834d4037 and 7124af18706204d7c24cd976a1f686f85267c39e. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 5</summary> <dl> <dd> <br> * `src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp` * `src/graphics/host_gpu/renderer/renderDraw.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterMesh.cpp` * `src/graphics/shader/shader.cpp` * `src/graphics/shader/shader.h` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=274a9376-a408-4b5b-b922-5f48243be345 attempt=57d65244-5647-4376-b37d-c0a6e732c698 batch=1/1 -->
This pull request has changes conflicting with the target branch.
  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
  • src/graphics/host_gpu/renderer/renderDraw.cpp
  • src/graphics/shader/shader.cpp
  • src/graphics/shader/shader.h
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/2302/head:github-bot/gh-2302'
git switch 'github-bot/gh-2302'

Merge

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