graphics: add opt-in compute dispatch buffer inspector for persistent-queue hangs #1084

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

@⁠overlordxrz-source on GitHub · 2026-10-05 22:14 UTC · original
overlordxrz-source:helper/nanite-dispatch-dump → main · +111 −0 · 1 files · 2 commits · closed without merging

Diagnostic tooling for #1072 (Wukong Nanite persistent-culling compute shaders never exit, every group runs to the loop cap).

The issue lists three unverified hypotheses: counters/slot markers never reset before each dispatch, glc atomic returns not reaching other lanes, or missing forward progress between workgroups. The suggested next step is capturing the state-buffer counters and slot-queue markers GPU-accurately around a dispatch. This implements exactly that recipe:

  • KYTY_DUMP_DISPATCH_BUFFERS=all or comma-separated hex shader hashes (e.g. KYTY_DUMP_DISPATCH_BUFFERS=539ebc039e965dfd); unset = off, zero behavior change.
  • For each matching DispatchDirect, logs the first 16 dwords of up to 8 bound buffers twice: a "before" snapshot (FlushAndWait drains prior work, then ReadMemory pulls the ranges to CPU visibility) and an "after" snapshot after recording the dispatch + FlushAndWait.
  • Capped at 16 snapshots total so logs stay manageable.

Comparing before/after across dispatches shows whether the 44-byte state-buffer counters and the -1 slot markers move or are stale, which separates a missed reset/reorder (hypothesis 1) from atomics-visibility / forward-progress problems (hypotheses 2-3).

Validation: x86_64 macOS no-Qt Release build of kyty_emulator succeeds; shader_cfg passes. GPU-harness tests are not runnable in this environment (no Vulkan loader — same pre-existing failure as clean main). Not yet exercised against the actual Wukong dispatch — needs someone with the game + Vulkan timestamps to run with the env var and post the before/after lines.

AI disclosure (per repo AI Use policy): AI tooling assisted with code exploration and patch drafting. Human reviewed the full diff, built kyty_emulator (x86_64) and ran shader_cfg before submitting, and remains responsible for correctness.

**@⁠overlordxrz-source** on GitHub · 2026-10-05 22:14 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1084) `overlordxrz-source:helper/nanite-dispatch-dump` → `main` · +111 −0 · 1 files · 2 commits · closed without merging Diagnostic tooling for #1072 (Wukong Nanite persistent-culling compute shaders never exit, every group runs to the loop cap). The issue lists three unverified hypotheses: counters/slot markers never reset before each dispatch, `glc` atomic returns not reaching other lanes, or missing forward progress between workgroups. The suggested next step is capturing the state-buffer counters and slot-queue markers GPU-accurately around a dispatch. This implements exactly that recipe: - `KYTY_DUMP_DISPATCH_BUFFERS=all` or comma-separated hex shader hashes (e.g. `KYTY_DUMP_DISPATCH_BUFFERS=539ebc039e965dfd`); unset = off, zero behavior change. - For each matching `DispatchDirect`, logs the first 16 dwords of up to 8 bound buffers twice: a "before" snapshot (FlushAndWait drains prior work, then ReadMemory pulls the ranges to CPU visibility) and an "after" snapshot after recording the dispatch + FlushAndWait. - Capped at 16 snapshots total so logs stay manageable. Comparing before/after across dispatches shows whether the 44-byte state-buffer counters and the -1 slot markers move or are stale, which separates a missed reset/reorder (hypothesis 1) from atomics-visibility / forward-progress problems (hypotheses 2-3). Validation: x86_64 macOS no-Qt Release build of `kyty_emulator` succeeds; `shader_cfg` passes. GPU-harness tests are not runnable in this environment (no Vulkan loader — same pre-existing failure as clean main). Not yet exercised against the actual Wukong dispatch — needs someone with the game + Vulkan timestamps to run with the env var and post the before/after lines. AI disclosure (per repo AI Use policy): AI tooling assisted with code exploration and patch drafting. Human reviewed the full diff, built `kyty_emulator` (x86_64) and ran `shader_cfg` before submitting, and remains responsible for correctness.
Wukong Nanite culling shaders spin to the loop cap (issue #1072) and the
open question is whether claim counters/slot markers move between
dispatches (missed reset/reorder) or are stale (atomics visibility /
forward progress). Log the first 16 dwords of every bound buffer around
matching compute dispatches, GPU-accurately (FlushAndWait + ReadMemory
before the 'before' snapshot and again after recording the dispatch).

Gated by KYTY_DUMP_DISPATCH_BUFFERS=all or comma-separated hex shader
hashes, capped at 16 snapshots. Off by default; no behavior change
otherwise.
- Snapshot 'before' right after FindBuffers, before RebindBuffers
  uploads/synchronizes this dispatch's bindings.
- Record ShaderAccessBarrier before the 'after' snapshot: the dump
  calls FlushAndWait, which submits the current command buffer, so a
  later barrier would land on the submitted buffer.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:42:29 +00:00
github-bot closed this pull request 2026-11-26 09:42:29 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-05 22:24 UTC · original · edited 2026-10-05 22:52 UTC

Review in Change Stack →

📝 Walkthrough

Walkthrough

Adds an opt-in inspector controlled by KYTY_DUMP_DISPATCH_BUFFERS. It selects all shaders or configured hexadecimal shader hashes. For matching direct dispatches, it logs up to 16 dwords from each of the first eight nonempty bound buffers before and after dispatch. Each dump waits for queued work and reads guest memory. Dump calls are capped at 16.

Suggested reviewers: nmzik

Priority: ⬇️ Low

Change: Feature

Merge Risk: 🔵 Low · up to ff970

Copying a logged hash into the opt-in setting produces no snapshots. The change remains mergeable with a bounded diagnostic usability issue; users can enter the hash without its prefix.

Security Architecture Review

Security architecture risk: 🔵 Low · up to ff970

The inspector is disabled by default and limits each diagnostic capture. Enabling it exposes buffer contents in logs and changes execution timing. Live GPU failure and recovery behavior remains unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated new exposure is dispatch-bound buffer prefixes entering diagnostic logs within an inspection-enabled emulator process. The selector cannot provide arbitrary addresses. Who can enable inspection or subsequently receive those logs is not established by the supplied runtime context.

Trust Boundaries and Controls

  • observed — The process environment controls whether existing guest-driven dispatches reach the new logging sink. Source inspection shows shader-hash selection and bounded capture, not a new guest command, authentication bypass, or independent resource-access interface.

Resilience and Maintainability Implications

  • inferred — The alleged missing after-phase readback and invalid barrier placement are not supported. Both phases invoke the same readback helper; the dispatch barrier precedes submission, and cache downloads add transfer and host-visibility barriers before waiting and publishing backing memory. This supports normal execution ordering but does not establish recovery after GPU non-completion or device loss.

Hardening Proposals

  • proposed — Treat inspection output as potentially sensitive: restrict access and remove unnecessary buffer contents and addresses before sharing diagnostic logs. This is precautionary guidance, not an observed unauthorized disclosure.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the opt-in compute dispatch buffer inspector and its diagnostic purpose.
Description check ✅ Passed The description explains the inspector, its configuration, snapshot behavior, and validation status. It directly relates to the changeset.
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.
  • Autopilot · 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-05 22:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1084#issuecomment-6004384318) · edited 2026-10-05 22:52 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1084?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough Adds an opt-in inspector controlled by `KYTY_DUMP_DISPATCH_BUFFERS`. It selects all shaders or configured hexadecimal shader hashes. For matching direct dispatches, it logs up to 16 dwords from each of the first eight nonempty bound buffers before and after dispatch. Each dump waits for queued work and reads guest memory. Dump calls are capped at 16. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"ff9701379f3badba73e80aeac2b2f0c377388ec3" --> **Change:** Feature <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _🔵 Low_ · up to `ff970` <!-- final_review_risk_coverage:{"sourceCommitId":"ff9701379f3badba73e80aeac2b2f0c377388ec3","coveredCommitId":"ff9701379f3badba73e80aeac2b2f0c377388ec3","kind":"reviewed"} --> Copying a logged hash into the opt-in setting produces no snapshots. The change remains mergeable with a bounded diagnostic usability issue; users can enter the hash without its prefix. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🔵 Low_ · up to `ff970` The inspector is disabled by default and limits each diagnostic capture. Enabling it exposes buffer contents in logs and changes execution timing. Live GPU failure and recovery behavior remains unverified. **Retained concerns** No architecture-level concerns identified. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — The demonstrated new exposure is dispatch-bound buffer prefixes entering diagnostic logs within an inspection-enabled emulator process. The selector cannot provide arbitrary addresses. Who can enable inspection or subsequently receive those logs is not established by the supplied runtime context. **Trust Boundaries and Controls** - _observed_ — The process environment controls whether existing guest-driven dispatches reach the new logging sink. Source inspection shows shader-hash selection and bounded capture, not a new guest command, authentication bypass, or independent resource-access interface. **Resilience and Maintainability Implications** - _inferred_ — The alleged missing after-phase readback and invalid barrier placement are not supported. Both phases invoke the same readback helper; the dispatch barrier precedes submission, and cache downloads add transfer and host-visibility barriers before waiting and publishing backing memory. This supports normal execution ordering but does not establish recovery after GPU non-completion or device loss. **Hardening Proposals** - _proposed_ — Treat inspection output as potentially sensitive: restrict access and remove unnecessary buffer contents and addresses before sharing diagnostic logs. This is precautionary guidance, not an observed unauthorized disclosure. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :----------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly summarizes the opt-in compute dispatch buffer inspector and its diagnostic purpose. | | Description check | ✅ Passed | The description explains the inspector, its configuration, snapshot behavior, and validation status. It directly relates to the changeset. | | 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. | </details> </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">Autopilot</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=1084)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [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) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -41,0 +136,4 @@
words[12], words[13], words[14], words[15]);
}
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-05 22:24 UTC · original · edited 2026-10-05 22:53 UTC

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '405,465p' src/graphics/host_gpu/renderer/renderCompute.cpp
rg -n 'RebindBuffers|void RebindBuffers|BufferSource|m_gpu_modified_ranges|ForEachUploadRange' src/graphics/host_gpu/renderer/renderCompute.cpp src/graphics/host_gpu/renderer/cache/bufferCache.cpp src/graphics/host_gpu/renderer/pipeline/descriptors.cpp

Repository: KytyPS5/KytyPS5

Length of output: 4346


Move the before dump before RebindBuffers.

FindBuffers has already populated bindings.buffer_sources at that point, so the dump retains its buffer list. RebindBuffers then marks writable ranges GPU-dirty. After dispatch, the after dump can download those ranges instead of reading stale guest memory.

Suggested fix
  RebindImages(bindings);
  BindSharedMemory(m_context, input_info, bindings);
- RebindBuffers(bindings);
  const bool dump_dispatch_buffers = DispatchBufferDumpWanted(program.shader_hash);
  if (dump_dispatch_buffers) {
    DumpDispatchBuffers(m_context, program.shader_hash, bindings, "before");
  }
+ RebindBuffers(bindings);

✅ Addressed in commit ff97013

**@⁠coderabbitai[bot]** on GitHub · 2026-10-05 22:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1084#discussion_r4189483964) · edited 2026-10-05 22:53 UTC _🎯 Functional Correctness_ | _🟡 Minor_ | _⚡ Quick win_ <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '405,465p' src/graphics/host_gpu/renderer/renderCompute.cpp rg -n 'RebindBuffers|void RebindBuffers|BufferSource|m_gpu_modified_ranges|ForEachUploadRange' src/graphics/host_gpu/renderer/renderCompute.cpp src/graphics/host_gpu/renderer/cache/bufferCache.cpp src/graphics/host_gpu/renderer/pipeline/descriptors.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 4346 --- </details> **Move the before dump before `RebindBuffers`.** `FindBuffers` has already populated `bindings.buffer_sources` at that point, so the dump retains its buffer list. `RebindBuffers` then marks writable ranges GPU-dirty. After dispatch, the after dump can download those ranges instead of reading stale guest memory. <details><summary>Suggested fix</summary> ```diff RebindImages(bindings); BindSharedMemory(m_context, input_info, bindings); - RebindBuffers(bindings); const bool dump_dispatch_buffers = DispatchBufferDumpWanted(program.shader_hash); if (dump_dispatch_buffers) { DumpDispatchBuffers(m_context, program.shader_hash, bindings, "before"); } + RebindBuffers(bindings); ``` </details> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:92a57a82c02f53edbc2e4c99 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit ff97013
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-05 22:24 UTC · original · edited 2026-10-05 22:55 UTC
On src/graphics/host_gpu/renderer/renderCompute.cpp line 539 (outdated):

@@ -431,6 +534,9 @@ void RenderExecutor::DispatchDirect(uint64_t submit_id, CommandBuffer& buffer,
 
 	vk_buffer.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline.pipeline);
 	vk_buffer.dispatch(thread_group_x, thread_group_y, thread_group_z);
+	if (dump_dispatch_buffers) {
+		DumpDispatchBuffers(m_context, program.shader_hash, bindings, "after");
+	}

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
rg -nP -C5 '\bHandle\s*\(\s*\)\s*(const)?\s*\{' --type=cpp src/graphics/host_gpu/renderer
rg -nP -C8 'void\s+CommandScheduler::(BeginNext|Submit)\b' src/graphics/host_gpu/renderer

Repository: KytyPS5/KytyPS5

Length of output: 1895


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- renderCompute relevant code ---'
nl -ba src/graphics/host_gpu/renderer/renderCompute.cpp | sed -n '430,565p'
printf '%s\n' '--- CommandBuffer declaration and implementation ---'
rg -n -F -- 'class CommandBuffer' src/graphics/host_gpu/renderer
nl -ba src/graphics/host_gpu/renderer/context.cpp | sed -n '1,100p'
printf '%s\n' '--- dump and flush definitions/usages ---'
rg -n -F -- 'DumpDispatchBuffers' src/graphics/host_gpu/renderer
rg -n -F -- 'FlushAndWait' src/graphics/host_gpu/renderer/commandScheduler.cpp src/graphics/host_gpu/renderer
printf '%s\n' '--- scheduler relevant code ---'
nl -ba src/graphics/host_gpu/renderer/commandScheduler.cpp | sed -n '145,205p'
nl -ba src/graphics/host_gpu/renderer/commandScheduler.cpp | sed -n '300,405p'
printf '%s\n' '--- diff against specified merge base ---'
git diff --unified=18 cdb64bfd4fb4d5312b2542a41a0070f25663166a 2b8acb40941abb8e9855e91036210ba6345bed19 -- src/graphics/host_gpu/renderer/renderCompute.cpp

Repository: KytyPS5/KytyPS5

Length of output: 30037


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- DispatchDirect declarations and callers ---'
rg -n -F -- 'DispatchDirect(' src/graphics/host_gpu/renderer
nl -ba src/graphics/host_gpu/renderer/render.h | sed -n '95,155p'
printf '%s\n' '--- ShaderAccessBarrier declaration and implementation ---'
rg -n -F -- 'ShaderAccessBarrier' src/graphics/host_gpu/renderer/pipeline
nl -ba src/graphics/host_gpu/renderer/pipeline/shaderResourceBarrier.cpp | sed -n '1,180p'
printf '%s\n' '--- scheduler command ownership ---'
nl -ba src/graphics/host_gpu/renderer/commandScheduler.h | sed -n '1,95p'
nl -ba src/graphics/host_gpu/renderer/commandScheduler.cpp | sed -n '70,145p'

Repository: KytyPS5/KytyPS5

Length of output: 17177


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- all repository DispatchDirect references ---'
rg -n -F -- 'DispatchDirect(' . || test "$?" -eq 1
printf '%s\n' '--- command-pool selection and reset ---'
nl -ba src/graphics/host_gpu/renderer/commandScheduler.cpp | sed -n '1,95p'
printf '%s\n' '--- scheduler Current call sites relevant to rendering ---'
rg -n -F -- '.Current()' src/graphics/host_gpu | head -80

Repository: KytyPS5/KytyPS5

Length of output: 9164


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- direct dispatch caller and CurrentBuffer definition ---'
nl -ba src/graphics/guest_gpu/graphicsRun.cpp | sed -n '940,992p'
rg -n -F -- 'CurrentBuffer()' src/graphics/guest_gpu

Repository: KytyPS5/KytyPS5

Length of output: 4303


Record the barrier before the after-dispatch snapshot.

When the after-dispatch snapshot is within DumpDispatchBuffers’ 16-call limit, it calls FlushAndWait(). vk_buffer holds the command-buffer handle captured before dispatch. The flush submits that command buffer and begins another one. ShaderAccessBarrier then tries to record a barrier on the submitted command buffer, and the new command buffer receives no barrier.

🐛 Suggested fix
 	vk_buffer.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline.pipeline);
 	vk_buffer.dispatch(thread_group_x, thread_group_y, thread_group_z);
+	// The removed host fence also ordered read-only dispatches before later writers.
+	ShaderAccessBarrier(vk_buffer, vk::PipelineStageFlagBits::eComputeShader);
 	if (dump_dispatch_buffers) {
 		DumpDispatchBuffers(m_context, program.shader_hash, bindings, "after");
 	}
-
-	// The removed host fence also ordered read-only dispatches before later writers.
-	ShaderAccessBarrier(vk_buffer, vk::PipelineStageFlagBits::eComputeShader);
 	ResetBindings();

✅ Addressed in commit ff97013

**@⁠coderabbitai[bot]** on GitHub · 2026-10-05 22:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1084#discussion_r4189483970) · edited 2026-10-05 22:55 UTC On `src/graphics/host_gpu/renderer/renderCompute.cpp` line 539 (outdated): ```diff @@ -431,6 +534,9 @@ void RenderExecutor::DispatchDirect(uint64_t submit_id, CommandBuffer& buffer, vk_buffer.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline.pipeline); vk_buffer.dispatch(thread_group_x, thread_group_y, thread_group_z); + if (dump_dispatch_buffers) { + DumpDispatchBuffers(m_context, program.shader_hash, bindings, "after"); + } ``` _🩺 Stability & Availability_ | _🟡 Minor_ | _⚡ Quick win_ <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash rg -nP -C5 '\bHandle\s*\(\s*\)\s*(const)?\s*\{' --type=cpp src/graphics/host_gpu/renderer rg -nP -C8 'void\s+CommandScheduler::(BeginNext|Submit)\b' src/graphics/host_gpu/renderer ``` Repository: KytyPS5/KytyPS5 Length of output: 1895 --- 🏁 Script executed: ```bash #!/bin/bash set -e printf '%s\n' '--- renderCompute relevant code ---' nl -ba src/graphics/host_gpu/renderer/renderCompute.cpp | sed -n '430,565p' printf '%s\n' '--- CommandBuffer declaration and implementation ---' rg -n -F -- 'class CommandBuffer' src/graphics/host_gpu/renderer nl -ba src/graphics/host_gpu/renderer/context.cpp | sed -n '1,100p' printf '%s\n' '--- dump and flush definitions/usages ---' rg -n -F -- 'DumpDispatchBuffers' src/graphics/host_gpu/renderer rg -n -F -- 'FlushAndWait' src/graphics/host_gpu/renderer/commandScheduler.cpp src/graphics/host_gpu/renderer printf '%s\n' '--- scheduler relevant code ---' nl -ba src/graphics/host_gpu/renderer/commandScheduler.cpp | sed -n '145,205p' nl -ba src/graphics/host_gpu/renderer/commandScheduler.cpp | sed -n '300,405p' printf '%s\n' '--- diff against specified merge base ---' git diff --unified=18 cdb64bfd4fb4d5312b2542a41a0070f25663166a 2b8acb40941abb8e9855e91036210ba6345bed19 -- src/graphics/host_gpu/renderer/renderCompute.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 30037 --- 🏁 Script executed: ```bash #!/bin/bash set -e printf '%s\n' '--- DispatchDirect declarations and callers ---' rg -n -F -- 'DispatchDirect(' src/graphics/host_gpu/renderer nl -ba src/graphics/host_gpu/renderer/render.h | sed -n '95,155p' printf '%s\n' '--- ShaderAccessBarrier declaration and implementation ---' rg -n -F -- 'ShaderAccessBarrier' src/graphics/host_gpu/renderer/pipeline nl -ba src/graphics/host_gpu/renderer/pipeline/shaderResourceBarrier.cpp | sed -n '1,180p' printf '%s\n' '--- scheduler command ownership ---' nl -ba src/graphics/host_gpu/renderer/commandScheduler.h | sed -n '1,95p' nl -ba src/graphics/host_gpu/renderer/commandScheduler.cpp | sed -n '70,145p' ``` Repository: KytyPS5/KytyPS5 Length of output: 17177 --- 🏁 Script executed: ```bash #!/bin/bash set -e printf '%s\n' '--- all repository DispatchDirect references ---' rg -n -F -- 'DispatchDirect(' . || test "$?" -eq 1 printf '%s\n' '--- command-pool selection and reset ---' nl -ba src/graphics/host_gpu/renderer/commandScheduler.cpp | sed -n '1,95p' printf '%s\n' '--- scheduler Current call sites relevant to rendering ---' rg -n -F -- '.Current()' src/graphics/host_gpu | head -80 ``` Repository: KytyPS5/KytyPS5 Length of output: 9164 --- 🏁 Script executed: ```bash #!/bin/bash set -e printf '%s\n' '--- direct dispatch caller and CurrentBuffer definition ---' nl -ba src/graphics/guest_gpu/graphicsRun.cpp | sed -n '940,992p' rg -n -F -- 'CurrentBuffer()' src/graphics/guest_gpu ``` Repository: KytyPS5/KytyPS5 Length of output: 4303 --- </details> **Record the barrier before the after-dispatch snapshot.** When the after-dispatch snapshot is within `DumpDispatchBuffers`’ 16-call limit, it calls `FlushAndWait()`. `vk_buffer` holds the command-buffer handle captured before dispatch. The flush submits that command buffer and begins another one. `ShaderAccessBarrier` then tries to record a barrier on the submitted command buffer, and the new command buffer receives no barrier. <details> <summary>🐛 Suggested fix</summary> ```diff vk_buffer.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline.pipeline); vk_buffer.dispatch(thread_group_x, thread_group_y, thread_group_z); + // The removed host fence also ordered read-only dispatches before later writers. + ShaderAccessBarrier(vk_buffer, vk::PipelineStageFlagBits::eComputeShader); if (dump_dispatch_buffers) { DumpDispatchBuffers(m_context, program.shader_hash, bindings, "after"); } - - // The removed host fence also ordered read-only dispatches before later writers. - ShaderAccessBarrier(vk_buffer, vk::PipelineStageFlagBits::eComputeShader); ResetBindings(); ``` </details> <!-- fingerprinting:phantom:medusa:pangolin --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:3c3c85b140a4146b9c7c5cc7 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit ff97013
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-05 22:24 UTC · original · reviewed

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 06fd4634-688a-45da-af5e-d21d312c727c
📥 Commits

Reviewing files that changed from the base of the PR and between cdb64bfd4f and 2b8acb4094.

📒 Files selected for processing (1)
  • src/graphics/host_gpu/renderer/renderCompute.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-05 22:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1084#pullrequestreview-5421362756) · **reviewed** **Actionable comments posted: 2** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `06fd4634-688a-45da-af5e-d21d312c727c` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between cdb64bfd4fb4d5312b2542a41a0070f25663166a and 2b8acb40941abb8e9855e91036210ba6345bed19. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/graphics/host_gpu/renderer/renderCompute.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=7b0fe293-b6c8-4fff-b8b1-da11c273498d attempt=a53b4985-dfbd-4424-a7ff-138f82246fa7 batch=1/1 -->
@ -41,0 +136,4 @@
words[12], words[13], words[14], words[15]);
}
}
Author
Owner

@⁠overlordxrz-source on GitHub · 2026-10-05 22:41 UTC · original

Good catch on the placement - taken with one nuance. I verified FindBuffers fully populates buffer_sources, so the snapshot now runs immediately after it, before RebindBuffers uploads/synchronizes this dispatch's bindings. (For the record, the staleness mechanism in the suggestion doesn't quite hold - ReadMemory downloads GPU-modified ranges rather than skipping them - but snapshotting before any of this dispatch's sync activity is strictly safer, so the move is right regardless.) Fixed in ff97013, build + shader_cfg green.

**@⁠overlordxrz-source** on GitHub · 2026-10-05 22:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1084#discussion_r4189617372) Good catch on the placement - taken with one nuance. I verified FindBuffers fully populates buffer_sources, so the snapshot now runs immediately after it, before RebindBuffers uploads/synchronizes this dispatch's bindings. (For the record, the staleness mechanism in the suggestion doesn't quite hold - ReadMemory downloads GPU-modified ranges rather than skipping them - but snapshotting before any of this dispatch's sync activity is strictly safer, so the move is right regardless.) Fixed in ff97013, build + shader_cfg green.
Author
Owner

@⁠overlordxrz-source on GitHub · 2026-10-05 22:42 UTC · original
On src/graphics/host_gpu/renderer/renderCompute.cpp line 539 (outdated):

@@ -431,6 +534,9 @@ void RenderExecutor::DispatchDirect(uint64_t submit_id, CommandBuffer& buffer,
 
 	vk_buffer.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline.pipeline);
 	vk_buffer.dispatch(thread_group_x, thread_group_y, thread_group_z);
+	if (dump_dispatch_buffers) {
+		DumpDispatchBuffers(m_context, program.shader_hash, bindings, "after");
+	}

Confirmed real - FlushAndWait calls Submit() + BeginNext(), and vk_buffer aliases the scheduler's current buffer, so the barrier would indeed have landed on the submitted buffer. Moved ShaderAccessBarrier ahead of the after-dispatch snapshot with a comment explaining why. Fixed in ff97013, build + shader_cfg green.

**@⁠overlordxrz-source** on GitHub · 2026-10-05 22:42 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1084#discussion_r4189617918) On `src/graphics/host_gpu/renderer/renderCompute.cpp` line 539 (outdated): ```diff @@ -431,6 +534,9 @@ void RenderExecutor::DispatchDirect(uint64_t submit_id, CommandBuffer& buffer, vk_buffer.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline.pipeline); vk_buffer.dispatch(thread_group_x, thread_group_y, thread_group_z); + if (dump_dispatch_buffers) { + DumpDispatchBuffers(m_context, program.shader_hash, bindings, "after"); + } ``` Confirmed real - FlushAndWait calls Submit() + BeginNext(), and vk_buffer aliases the scheduler's current buffer, so the barrier would indeed have landed on the submitted buffer. Moved ShaderAccessBarrier ahead of the after-dispatch snapshot with a comment explaining why. Fixed in ff97013, build + shader_cfg green.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-05 22:45 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 · Accept the hash format shown in the log. · renderCompute.cpp:77-78

src/graphics/host_gpu/renderer/renderCompute.cpp:77-78
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Accept the hash format shown in the log.

The log prints hashes as 0x..., but std::from_chars(..., 16) does not consume 0x. If a user copies a logged hash into KYTY_DUMP_DISPATCH_BUFFERS, the full-token check rejects it silently and the inspector records no snapshots. Strip an optional 0x prefix before parsing, or state clearly that the configuration requires hashes without the prefix.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8f1ab00d-e6a2-4f8d-8aed-17664170ec00
📥 Commits

Reviewing files that changed from the base of the PR and between 2b8acb4094 and ff9701379f.

📒 Files selected for processing (1)
  • src/graphics/host_gpu/renderer/renderCompute.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-05 22:45 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1084#pullrequestreview-5421559274) · **reviewed** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><strong>🟡 Minor</strong> · Accept the hash format shown in the log. · <code>renderCompute.cpp:77-78</code></summary><blockquote> > > `src/graphics/host_gpu/renderer/renderCompute.cpp:77-78` > **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** > > **Accept the hash format shown in the log.** > > The log prints hashes as `0x...`, but `std::from_chars(..., 16)` does not consume `0x`. If a user copies a logged hash into `KYTY_DUMP_DISPATCH_BUFFERS`, the full-token check rejects it silently and the inspector records no snapshots. Strip an optional `0x` prefix before parsing, or state clearly that the configuration requires hashes without the prefix. > > <!-- cr-comment:v1:6b9ecb2ab6ffcea9f92b3aab --> > > </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**: `8f1ab00d-e6a2-4f8d-8aed-17664170ec00` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 2b8acb40941abb8e9855e91036210ba6345bed19 and ff9701379f3badba73e80aeac2b2f0c377388ec3. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/graphics/host_gpu/renderer/renderCompute.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=e34631c9-a557-46b5-916f-46d00ade4452 attempt=282f28cc-1f6c-412c-b6a3-4c9f91f318b4 batch=1/1 -->
@ -41,0 +136,4 @@
words[12], words[13], words[14], words[15]);
}
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-05 22:54 UTC · original

@overlordxrz-source Thanks for the correction. ReadMemory downloads GPU-modified ranges; my staleness explanation was incorrect.

The supplied code places the before snapshot after FindBuffers and before RebindBuffers, as intended. Thanks for confirming the fix in ff97013 and the passing checks.


✏️ Learnings added
Learnt from: overlordxrz-source
Repo: KytyPS5/KytyPS5 PR: 1084
File: src/graphics/host_gpu/renderer/renderCompute.cpp:103-139
Timestamp: 2026-10-05T22:54:03.875Z
Learning: In KytyPS5's C++ renderer, src/graphics/host_gpu/renderer/cache/bufferCache.cpp's ReadMemory downloads GPU-modified ranges rather than skipping them. Do not infer stale guest-memory reads merely because RebindBuffers marks writable ranges GPU-dirty. In src/graphics/host_gpu/renderer/renderCompute.cpp, FindBuffers fully populates PreparedBindings::buffer_sources, so a before-dispatch snapshot can use that list before RebindBuffers uploads or synchronizes the dispatch's bindings.

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-05 22:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1084#discussion_r4189704928) `@overlordxrz-source` Thanks for the correction. `ReadMemory` downloads GPU-modified ranges; my staleness explanation was incorrect. The supplied code places the before snapshot after `FindBuffers` and before `RebindBuffers`, as intended. Thanks for confirming the fix in `ff97013` and the passing checks. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: overlordxrz-source Repo: KytyPS5/KytyPS5 PR: 1084 File: src/graphics/host_gpu/renderer/renderCompute.cpp:103-139 Timestamp: 2026-10-05T22:54:03.875Z Learning: In KytyPS5's C++ renderer, src/graphics/host_gpu/renderer/cache/bufferCache.cpp's ReadMemory downloads GPU-modified ranges rather than skipping them. Do not infer stale guest-memory reads merely because RebindBuffers marks writable ranges GPU-dirty. In src/graphics/host_gpu/renderer/renderCompute.cpp, FindBuffers fully populates PreparedBindings::buffer_sources, so a before-dispatch snapshot can use that list before RebindBuffers uploads or synchronizes the dispatch's bindings. ``` > 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=Move%20the%20buffer%20snapshot%20before%20%60RebindBuffers%60%20to%20capture%20dispatch%20inputs%20before%20sync%20activity.%20Verified%20with%20a%20build%20and%20shader_cfg%E2%80%94try%20%40coderabbitai%20for%20sharp%2C%20actionable%20reviews!%20%E2%9C%85&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1084%23discussion_r4189483964)? 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

@⁠coderabbitai[bot] on GitHub · 2026-10-05 22:55 UTC · original
On src/graphics/host_gpu/renderer/renderCompute.cpp line 539 (outdated):

@@ -431,6 +534,9 @@ void RenderExecutor::DispatchDirect(uint64_t submit_id, CommandBuffer& buffer,
 
 	vk_buffer.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline.pipeline);
 	vk_buffer.dispatch(thread_group_x, thread_group_y, thread_group_z);
+	if (dump_dispatch_buffers) {
+		DumpDispatchBuffers(m_context, program.shader_hash, bindings, "after");
+	}

@overlordxrz-source Thanks for confirming the fix and explaining the command-buffer transition. The supplied code records ShaderAccessBarrier before the after-dispatch snapshot, which addresses this finding.


✏️ Learnings added
Learnt from: overlordxrz-source
Repo: KytyPS5/KytyPS5 PR: 1084
File: src/graphics/host_gpu/renderer/renderCompute.cpp:0-0
Timestamp: 2026-10-05T22:55:49.245Z
Learning: In KytyPS5's graphics renderer, CommandScheduler::FlushAndWait calls Submit() and BeginNext(). A Vulkan command-buffer handle captured before the flush refers to the submitted buffer. In src/graphics/host_gpu/renderer/renderCompute.cpp, RenderExecutor::DispatchDirect must record ShaderAccessBarrier before the after-dispatch DumpDispatchBuffers call because that snapshot can call FlushAndWait.

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-05 22:55 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1084#discussion_r4189716403) On `src/graphics/host_gpu/renderer/renderCompute.cpp` line 539 (outdated): ```diff @@ -431,6 +534,9 @@ void RenderExecutor::DispatchDirect(uint64_t submit_id, CommandBuffer& buffer, vk_buffer.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline.pipeline); vk_buffer.dispatch(thread_group_x, thread_group_y, thread_group_z); + if (dump_dispatch_buffers) { + DumpDispatchBuffers(m_context, program.shader_hash, bindings, "after"); + } ``` `@overlordxrz-source` Thanks for confirming the fix and explaining the command-buffer transition. The supplied code records `ShaderAccessBarrier` before the after-dispatch snapshot, which addresses this finding. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: overlordxrz-source Repo: KytyPS5/KytyPS5 PR: 1084 File: src/graphics/host_gpu/renderer/renderCompute.cpp:0-0 Timestamp: 2026-10-05T22:55:49.245Z Learning: In KytyPS5's graphics renderer, CommandScheduler::FlushAndWait calls Submit() and BeginNext(). A Vulkan command-buffer handle captured before the flush refers to the submitted buffer. In src/graphics/host_gpu/renderer/renderCompute.cpp, RenderExecutor::DispatchDirect must record ShaderAccessBarrier before the after-dispatch DumpDispatchBuffers call because that snapshot can call FlushAndWait. ``` > 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=A%20snapshot%20can%20flush%20and%20rotate%20command%20buffers%E2%80%94record%20the%20compute%20barrier%20first%2C%20or%20it%20lands%20on%20a%20submitted%20buffer.%20%40coderabbitai%20caught%20a%20real%20stability%20bug%3B%20try%20it%20for%20sharper%20reviews!%20%F0%9F%A9%BA%E2%9A%A1&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1084%23discussion_r4189483970)? 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

@⁠overlordxrz-source on GitHub · 2026-10-06 00:40 UTC · original

Maintainers: the two build workflow runs for this PR are sitting at action_required (awaiting approval), so there's no CI signal yet. When convenient, please approve a run — in the meantime, local validation (x86_64 macOS no-Qt Release build + shader_cfg) is documented in the description above. Happy to fix anything CI flags.

**@⁠overlordxrz-source** on GitHub · 2026-10-06 00:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1084#issuecomment-6006692958) Maintainers: the two build workflow runs for this PR are sitting at `action_required` (awaiting approval), so there's no CI signal yet. When convenient, please approve a run — in the meantime, local validation (x86_64 macOS no-Qt Release build + `shader_cfg`) is documented in the description above. Happy to fix anything CI flags.

Pull request closed

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