gpu: read back submitted buffer data without a flush #1254

Open
github-bot wants to merge 1 commit from github-bot/gh-1254 into main AGit
Owner

@⁠NeySlim on GitHub · 2026-10-08 20:26 UTC · original
NeySlim:perf/detached-downloads → main · +542 −42 · 9 files · 1 commits · open

Problem

Every synchronous buffer readback (BufferCache::DownloadBufferMemory<false>) records its copy at the end of the current command buffer, submits it and waits until the GPU has drained everything. Guest CPU faults on GPU-written pages (reads and writes), scalar reads of the resource specialization, indirect dispatch arguments and color metadata all go through it.

In God of War Ragnarök (PPSA08332, 05.005) gameplay this happens about 6600 times every 5 seconds, mostly for guest reads and writes that fault one page at a time on buffers a shader wrote earlier. Each one splits the command buffer (about 9500 submissions every 5 seconds) and the GPU command thread is blocked about 1.6 s out of every 5 s, while most of these reads only need data written by work that was already submitted.

Change

  • CommandScheduler::SubmitDetached: records a small command buffer, submits it to the same queue with its own fence and waits for it. Its leading barrier covers every command submitted before it on the queue, and a queue-submission fence also covers earlier batches, so the copy runs behind all submitted work. The current command buffer stays open (rendering is not ended) and the tick timeline does not advance.
  • BufferCache tracks the guest ranges that unsubmitted work may still write: ranges bound for writing by ObtainBuffer, until the draw, dispatch, fill or copy using them is recorded (RecordPendingWrites) and then until the command buffer holding it is submitted; the copy into a new owner when buffers are joined; image data copied into a buffer by SynchronizeBufferFromImage. A recorded shader with address writes, which the cache does not track by range, counts for every range.
  • A synchronous readback uses the detached submission when none of its ranges has such a write, no address write is recorded in the current command buffer, and no priority operation is deferred at the current tick (guest-memory publications keep their order). Otherwise it flushes and waits as before.
  • A page-sized readback (fault, scalar read) also publishes the finished GPU-dirty pages within 256 KiB of the request in the same buffer. A page qualifies only when no unsubmitted or unrecorded write can still change it, so it reads back what a later read of its own would. Range readbacks (invalidation of a mapped range, color metadata) are unchanged.

Test

  • New buffer_cache_detached_download (--buffer-cache-detached-only, also in the default run): data written by a submitted fill is read back while the current command buffer stays open and keeps its tick, and a finished neighbouring page is published with it. A neighbour written by the open command buffer, a page bound for writing but not recorded yet, and a page outside the neighbourhood stay GPU-owned. Reads of data written by the open command buffer, of a joined owner, of image data copied into the owner by a texel read, after a priority operation deferred at the open tick, and after recorded address writes still flush.
  • New SchedulerDetachedSubmission (run by command_scheduler_timeline and the default run): a detached copy issued behind a submission that waits on an external timeline semaphore only returns after that submission ran, reads its write, and leaves the open command buffer and tick unchanged.
  • Each check fails when its guard is removed: join marking, image-copy marking, deferred-publication check, address-write check, pending ranges, unsubmitted ranges, neighbourhood, fence wait.

Validation

Linux, Ryzen AI Max+ 395, Radeon 8060S, Mesa RADV 26.2.3.

  • God of War Ragnarök (with the open fixes it needs to reach gameplay), alternating this change and the previous behaviour every 5 s in one session, so both see the same scenes; averages over 4 minutes of gameplay (sled after the intro):
Before After
GPU thread blocked in readbacks 1588 ms / 5 s 1163 ms / 5 s
Synchronous readbacks 6624 / 5 s 1144 / 5 s
Queue submissions 9521 / 5 s 3756 / 5 s
Frames presented 9.2 / s 10.8 / s
  • Two full runs from a new game, without and with the change, frame counter read from the window title: cutscene 10.6 to 12.1 fps, gameplay 8.0 to 9.2 fps. Screenshots of the same scenes show no rendering difference.
  • ctest: every test that passes on main passes, plus the new one (47 of 55; the other 8 fail on main too on this setup: shader_recompiler_compute, gpu_tiler, texture_cache_layered_image, texture_cache_image_views, texture_cache_storage_sampled, texture_cache_image_overlap, texture_cache_htile_clear, buffer_cache_ranges).
  • shader_recompiler_compute_tests, one case per process: same results as main (605 of 615 cases pass with the change, 603 of 613 on main; the same 10 fail on both on this RADV setup).

Remaining waits are reads of data written by the command buffer being recorded (draw-indirect arguments read on the CPU, color metadata, some descriptor tables); they still flush.

Not tested on Windows or macOS. The change uses core Vulkan objects (command pool, fence, queue submission) and the existing page tracking, with no platform-specific code.

AI use

I used Claude Code (AI agent) to measure where the GPU thread waits, write the change and the tests, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.

**@⁠NeySlim** on GitHub · 2026-10-08 20:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1254) `NeySlim:perf/detached-downloads` → `main` · +542 −42 · 9 files · 1 commits · open ## Problem Every synchronous buffer readback (`BufferCache::DownloadBufferMemory<false>`) records its copy at the end of the current command buffer, submits it and waits until the GPU has drained everything. Guest CPU faults on GPU-written pages (reads and writes), scalar reads of the resource specialization, indirect dispatch arguments and color metadata all go through it. In God of War Ragnarök (PPSA08332, 05.005) gameplay this happens about 6600 times every 5 seconds, mostly for guest reads and writes that fault one page at a time on buffers a shader wrote earlier. Each one splits the command buffer (about 9500 submissions every 5 seconds) and the GPU command thread is blocked about 1.6 s out of every 5 s, while most of these reads only need data written by work that was already submitted. ## Change - `CommandScheduler::SubmitDetached`: records a small command buffer, submits it to the same queue with its own fence and waits for it. Its leading barrier covers every command submitted before it on the queue, and a queue-submission fence also covers earlier batches, so the copy runs behind all submitted work. The current command buffer stays open (rendering is not ended) and the tick timeline does not advance. - `BufferCache` tracks the guest ranges that unsubmitted work may still write: ranges bound for writing by `ObtainBuffer`, until the draw, dispatch, fill or copy using them is recorded (`RecordPendingWrites`) and then until the command buffer holding it is submitted; the copy into a new owner when buffers are joined; image data copied into a buffer by `SynchronizeBufferFromImage`. A recorded shader with address writes, which the cache does not track by range, counts for every range. - A synchronous readback uses the detached submission when none of its ranges has such a write, no address write is recorded in the current command buffer, and no priority operation is deferred at the current tick (guest-memory publications keep their order). Otherwise it flushes and waits as before. - A page-sized readback (fault, scalar read) also publishes the finished GPU-dirty pages within 256 KiB of the request in the same buffer. A page qualifies only when no unsubmitted or unrecorded write can still change it, so it reads back what a later read of its own would. Range readbacks (invalidation of a mapped range, color metadata) are unchanged. ## Test - New `buffer_cache_detached_download` (`--buffer-cache-detached-only`, also in the default run): data written by a submitted fill is read back while the current command buffer stays open and keeps its tick, and a finished neighbouring page is published with it. A neighbour written by the open command buffer, a page bound for writing but not recorded yet, and a page outside the neighbourhood stay GPU-owned. Reads of data written by the open command buffer, of a joined owner, of image data copied into the owner by a texel read, after a priority operation deferred at the open tick, and after recorded address writes still flush. - New `SchedulerDetachedSubmission` (run by `command_scheduler_timeline` and the default run): a detached copy issued behind a submission that waits on an external timeline semaphore only returns after that submission ran, reads its write, and leaves the open command buffer and tick unchanged. - Each check fails when its guard is removed: join marking, image-copy marking, deferred-publication check, address-write check, pending ranges, unsubmitted ranges, neighbourhood, fence wait. ## Validation Linux, Ryzen AI Max+ 395, Radeon 8060S, Mesa RADV 26.2.3. - God of War Ragnarök (with the open fixes it needs to reach gameplay), alternating this change and the previous behaviour every 5 s in one session, so both see the same scenes; averages over 4 minutes of gameplay (sled after the intro): | | Before | After | |---|---|---| | GPU thread blocked in readbacks | 1588 ms / 5 s | 1163 ms / 5 s | | Synchronous readbacks | 6624 / 5 s | 1144 / 5 s | | Queue submissions | 9521 / 5 s | 3756 / 5 s | | Frames presented | 9.2 / s | 10.8 / s | - Two full runs from a new game, without and with the change, frame counter read from the window title: cutscene 10.6 to 12.1 fps, gameplay 8.0 to 9.2 fps. Screenshots of the same scenes show no rendering difference. - ctest: every test that passes on main passes, plus the new one (47 of 55; the other 8 fail on main too on this setup: `shader_recompiler_compute`, `gpu_tiler`, `texture_cache_layered_image`, `texture_cache_image_views`, `texture_cache_storage_sampled`, `texture_cache_image_overlap`, `texture_cache_htile_clear`, `buffer_cache_ranges`). - `shader_recompiler_compute_tests`, one case per process: same results as main (605 of 615 cases pass with the change, 603 of 613 on main; the same 10 fail on both on this RADV setup). Remaining waits are reads of data written by the command buffer being recorded (draw-indirect arguments read on the CPU, color metadata, some descriptor tables); they still flush. Not tested on Windows or macOS. The change uses core Vulkan objects (command pool, fence, queue submission) and the existing page tracking, with no platform-specific code. ## AI use I used Claude Code (AI agent) to measure where the GPU thread waits, write the change and the tests, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:50:12 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 20:29 UTC · original · edited 2026-10-17 14:09 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 31eaef72-32b9-4376-a810-102d4c8d06d9
📥 Commits

Reviewing files that changed from the base of the PR and between 23ba5b448053f1e42990e1ffb18d311b084cbd66 and d6ff37635a.

📒 Files selected for processing: 8
  • CMakeLists.txt
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/commandScheduler.cpp
  • src/graphics/host_gpu/renderer/renderCompute.cpp
  • src/graphics/host_gpu/renderer/renderDraw.cpp
  • tests/ShaderRecompilerComputeTests.cpp

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

📝 Walkthrough

The scheduler adds detached Vulkan command submission that waits for its fence without advancing the active command-buffer tick. BufferCache tracks pending and unsubmitted writes, uses that tracking to choose between detached and current-command-buffer readback, and can include eligible nearby dirty pages in small synchronous downloads. New tests cover scheduler ordering, readback behavior, and a dedicated CTest selector.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Feature

Merge Risk: ⚪ Minimal · up to d6ff3

The change lets small GPU buffer readbacks complete without flushing the open command buffer whenever no unsubmitted or pending writes could affect the requested data. Otherwise it falls back to the existing flush path. No concrete defect was found in the write tracking, neighbour-page publication, or detached submission, and the change appears ready to merge after normal checks.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive 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 29 functions across 7 files. (2 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description directly explains the synchronous buffer readback problem, detached submission design, pending-write tracking, tests, and validation results.
Title check Passed The title clearly summarizes the main change: reading back submitted GPU buffer data without flushing the current command buffer.
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.
Full details: Docstring Coverage

Explanation

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 29 functions across 7 files. (2 skipped: 1 unsupported, 1 too large.)

Resolution

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

  • 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-08 20:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1254#issuecomment-6068474669) · edited 2026-10-17 14:09 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/1254?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `31eaef72-32b9-4376-a810-102d4c8d06d9` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 23ba5b448053f1e42990e1ffb18d311b084cbd66 and d6ff37635aa5b1e5804a49589c68b3ca0de3b6f1. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 8</strong></summary> <dl> <dd> * `CMakeLists.txt` * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/commandScheduler.cpp` * `src/graphics/host_gpu/renderer/renderCompute.cpp` * `src/graphics/host_gpu/renderer/renderDraw.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The scheduler adds detached Vulkan command submission that waits for its fence without advancing the active command-buffer tick. BufferCache tracks pending and unsubmitted writes, uses that tracking to choose between detached and current-command-buffer readback, and can include eligible nearby dirty pages in small synchronous downloads. New tests cover scheduler ordering, readback behavior, and a dedicated CTest selector. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"d6ff37635aa5b1e5804a49589c68b3ca0de3b6f1" --> **Change:** Feature <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>d6ff3</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `d6ff3` --> <!-- final_review_risk_coverage:{"sourceCommitId":"d6ff37635aa5b1e5804a49589c68b3ca0de3b6f1","coveredCommitId":"d6ff37635aa5b1e5804a49589c68b3ca0de3b6f1","kind":"reviewed"} --> The change lets small GPU buffer readbacks complete without flushing the open command buffer whenever no unsubmitted or pending writes could affect the requested data. Otherwise it falls back to the existing flush path. No concrete defect was found in the write tracking, neighbour-page publication, or detached submission, and the change appears ready to merge after normal checks. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 7 files. (2 skipped: 1… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------ | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the synchronous buffer readback problem, detached submission design, pending-write tracking, tests, and validation results. | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly summarizes the main change: reading back submitted GPU buffer data without flushing the current command buffer. | | 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. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** 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 29 functions across 7 files. (2 skipped: 1 unsupported, 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">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=1254)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

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

Rebased on main after 5559cfcb: SynchronizeBufferFromImage now uses the new DownloadImage(..., levels), and the image copy is still marked as an unsubmitted write. BufferCacheDetachedDownload gained a check for that case (a texel read copies a newer image into the owner, then a readback of that range must flush), which fails without the marking. ctest and the GPU suite (one case per process) fail the same tests as main (47/55 vs 46/54, 605/615 vs 603/613). The in-game numbers were not measured again.

**@⁠NeySlim** on GitHub · 2026-10-10 02:21 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1254#issuecomment-6092669121) Rebased on main after 5559cfcb: `SynchronizeBufferFromImage` now uses the new `DownloadImage(..., levels)`, and the image copy is still marked as an unsubmitted write. `BufferCacheDetachedDownload` gained a check for that case (a texel read copies a newer image into the owner, then a readback of that range must flush), which fails without the marking. ctest and the GPU suite (one case per process) fail the same tests as main (47/55 vs 46/54, 605/615 vs 603/613). The in-game numbers were not measured again.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-18 23:51 UTC · original

Test result: Demon's Souls (PPSA01341) on Windows with an AMD Radeon RX 6700 XT and a Ryzen 7 5700X, tested by volan3 in #821.

Builds: main 099de8de + #1152 + #1630, then the same plus this PR, tested as commit b0f8d02c (same patch-id as this PR's head d6ff3763). Performance panel numbers (not a controlled A/B: the tester was asked to use the same place, but that is not confirmed):

  • without this PR: "CPU waiting on GPU" about 220 ms/s, about 1300 waits/s
  • with this PR: 113 ms/s, 193 waits/s; 4.5 FPS; 7465 draws and 3087 dispatches per frame and the emulator at 85% of 16 threads, so the CPU side looks like the limit

With this PR the third launch reached gameplay. The second launch stopped before gameplay with shader resource specialization failed: indirect image table at pc 0x000000fc has incompatible candidates and the fatal MaterializeResources check. The same message (at pc 0x0000114c) stops Marvel's Wolverine on main (#1453), so I don't think it comes from this PR, but I can't rule out a timing effect yet.

I also checked four places where the detached path could miss a write, against the code of that build:

  1. Draws: RecordPendingWrites runs after the draw is recorded (drawMeshTasksEXT / EmitDrawPrimitives) and tags the pending ranges with the current tick, so the shader writes get the tick of the command buffer that holds the draw, also when a stream-buffer wrap submits during binding preparation.
  2. Writers outside the hooked paths: ObtainBuffer is the only place that adds to m_gpu_modified_ranges, and it adds the same range to m_pending_writes; while a range is pending, CanDownloadDetached refuses it and the download takes the old flush path.
  3. SynchronizeBufferFromImage returns early unless the image starts inside the buffer and copies to buffer.Offset(image.info.data.address) (address minus the buffer's CPU address), so the marked range (image.info.data.address, copy_size) is the copy destination.
  4. Deadlock: the submit wait arrays are filled only by SubmitInfo::AddWait, whose only caller is the swapchain's image-acquired semaphore (swapchain.cpp:877), and EndDetached submits without waits. So no batch ahead of the detached fence waits on a master tick or a guest-signalled value.
**@⁠Nawid3333** on GitHub · 2026-10-18 23:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1254#issuecomment-6256705436) Test result: Demon's Souls (PPSA01341) on Windows with an AMD Radeon RX 6700 XT and a Ryzen 7 5700X, tested by volan3 in #821. Builds: main 099de8de + #1152 + #1630, then the same plus this PR, tested as commit b0f8d02c (same patch-id as this PR's head d6ff3763). Performance panel numbers (not a controlled A/B: the tester was asked to use the same place, but that is not confirmed): - without this PR: "CPU waiting on GPU" about 220 ms/s, about 1300 waits/s - with this PR: 113 ms/s, 193 waits/s; 4.5 FPS; 7465 draws and 3087 dispatches per frame and the emulator at 85% of 16 threads, so the CPU side looks like the limit With this PR the third launch reached gameplay. The second launch stopped before gameplay with `shader resource specialization failed: indirect image table at pc 0x000000fc has incompatible candidates` and the fatal `MaterializeResources` check. The same message (at pc 0x0000114c) stops Marvel's Wolverine on main (#1453), so I don't think it comes from this PR, but I can't rule out a timing effect yet. I also checked four places where the detached path could miss a write, against the code of that build: 1. Draws: `RecordPendingWrites` runs after the draw is recorded (`drawMeshTasksEXT` / `EmitDrawPrimitives`) and tags the pending ranges with the current tick, so the shader writes get the tick of the command buffer that holds the draw, also when a stream-buffer wrap submits during binding preparation. 2. Writers outside the hooked paths: `ObtainBuffer` is the only place that adds to `m_gpu_modified_ranges`, and it adds the same range to `m_pending_writes`; while a range is pending, `CanDownloadDetached` refuses it and the download takes the old flush path. 3. `SynchronizeBufferFromImage` returns early unless the image starts inside the buffer and copies to `buffer.Offset(image.info.data.address)` (address minus the buffer's CPU address), so the marked range `(image.info.data.address, copy_size)` is the copy destination. 4. Deadlock: the submit wait arrays are filled only by `SubmitInfo::AddWait`, whose only caller is the swapchain's image-acquired semaphore (`swapchain.cpp:877`), and `EndDetached` submits without waits. So no batch ahead of the detached fence waits on a master tick or a guest-signalled value.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-20 20:19 UTC · original

A/B in Demon's Souls (PPSA01341) on Windows 11, RX 9070 XT, Ryzen 7600X: main 0cad4672 + #1630 (to get past #1660) with lab counters, with and without this PR (d6ff3763 cherry-picked cleanly). Same scripted input, the character creation menus at 9-11 min, medians of 2-second samples, two runs each, alternating:

without with this PR
CPU waiting on the GPU 687 / 652 ms/s 274 / 218 ms/s
waits 351 / 367 per s 128 / 134 per s
frame rate 5 / 6 fps 7 / 8 fps

No hang or device loss in the four 11-minute runs.

What it does not change in this scene: a buffer readback still takes about 2 ms (2.0-2.2 ms without, 2.2-2.5 ms with), and so does a CPU read fault on a GPU-written page (2.2-2.5 ms in both builds). Most of the whole-plan SRT walker's time is spent in those faults (see #1456).

**@⁠Nawid3333** on GitHub · 2026-10-20 20:19 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1254#issuecomment-6300603288) A/B in Demon's Souls (PPSA01341) on Windows 11, RX 9070 XT, Ryzen 7600X: main 0cad4672 + #1630 (to get past #1660) with lab counters, with and without this PR (d6ff3763 cherry-picked cleanly). Same scripted input, the character creation menus at 9-11 min, medians of 2-second samples, two runs each, alternating: | | without | with this PR | |---|---|---| | CPU waiting on the GPU | 687 / 652 ms/s | 274 / 218 ms/s | | waits | 351 / 367 per s | 128 / 134 per s | | frame rate | 5 / 6 fps | 7 / 8 fps | No hang or device loss in the four 11-minute runs. What it does not change in this scene: a buffer readback still takes about 2 ms (2.0-2.2 ms without, 2.2-2.5 ms with), and so does a CPU read fault on a GPU-written page (2.2-2.5 ms in both builds). Most of the whole-plan SRT walker's time is spent in those faults (see #1456).
Author
Owner

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

Good to see it on Windows and DeS too. So the next cost there is the ~2 ms per readback itself, and #1456's whole-plan walk just inherits it. I'll look at where those 2 ms go.

**@⁠NeySlim** on GitHub · 2026-10-20 20:55 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1254#issuecomment-6301279303) Good to see it on Windows and DeS too. So the next cost there is the ~2 ms per readback itself, and #1456's whole-plan walk just inherits it. I'll look at where those 2 ms go.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-21 07:24 UTC · original

Looked into the 2 ms on my side (GoW, RADV). The copy itself is ~6 µs and the fence wakeup ~20 µs; the rest is waiting for the GPU work already submitted ahead of it, since the writer is usually still in flight. So #1254 removes the flushes but can't shorten that. In GoW most of those waits came from tessellated indirect draws that #1288 still kept on the CPU path; moving them to the GPU path removes them (about +5% in the cutscene). If you can, it'd help to know whether in DeS the writer is usually the last submitted batch or older work, that decides whether a separate copy queue would pay off.

**@⁠NeySlim** on GitHub · 2026-10-21 07:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1254#issuecomment-6310481902) Looked into the 2 ms on my side (GoW, RADV). The copy itself is ~6 µs and the fence wakeup ~20 µs; the rest is waiting for the GPU work already submitted ahead of it, since the writer is usually still in flight. So #1254 removes the flushes but can't shorten that. In GoW most of those waits came from tessellated indirect draws that #1288 still kept on the CPU path; moving them to the GPU path removes them (about +5% in the cutscene). If you can, it'd help to know whether in DeS the writer is usually the last submitted batch or older work, that decides whether a separate copy queue would pay off.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-21 16:39 UTC · original

@⁠NeySlim Measured in the same Demon's Souls scene (main 0cad4672 + #1630 + this PR, lab counters): for each buffer I recorded the tick when it was last bound as written, and at every BufferCache::ReadMemory compared it with CurrentTick() and IsFree():

writer of the read-back buffer (share of readbacks) character creation menus, 9-11 min (14,170 readbacks) whole 11-min run (64,366)
already finished on the GPU 56.5% 64.6%
still in the open, unsubmitted command buffer 42.2% 26.0%
the last submitted batch 0.0% (4 readbacks) 0.8%
older work still in flight 1.3% 8.6%

So in DeS the writer is almost never the last submitted batch; most readbacks read data whose writer has already finished. Those still take about 1.5-2 ms each, but that time is measured on the calling thread around SendCommandSync, so it includes handing the readback to the busy GPU thread, and I can't split it into GPU wait and hand-over yet. If that split would help you decide on the copy queue, I can add it.

**@⁠Nawid3333** on GitHub · 2026-10-21 16:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1254#issuecomment-6321259623) @⁠NeySlim Measured in the same Demon's Souls scene (main 0cad4672 + #1630 + this PR, lab counters): for each buffer I recorded the tick when it was last bound as written, and at every `BufferCache::ReadMemory` compared it with `CurrentTick()` and `IsFree()`: | writer of the read-back buffer (share of readbacks) | character creation menus, 9-11 min (14,170 readbacks) | whole 11-min run (64,366) | |---|---|---| | already finished on the GPU | 56.5% | 64.6% | | still in the open, unsubmitted command buffer | 42.2% | 26.0% | | the last submitted batch | 0.0% (4 readbacks) | 0.8% | | older work still in flight | 1.3% | 8.6% | So in DeS the writer is almost never the last submitted batch; most readbacks read data whose writer has already finished. Those still take about 1.5-2 ms each, but that time is measured on the calling thread around `SendCommandSync`, so it includes handing the readback to the busy GPU thread, and I can't split it into GPU wait and hand-over yet. If that split would help you decide on the copy queue, I can add it.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-22 07:11 UTC · original

That's the case where a separate copy path pays off: when the writer has finished, a copy on its own queue waits ~80 µs here instead of the whole submitted work. In GoW I tried it and also served those readbacks straight from the guest thread: guest waits halved, but the GPU thread lost more than it saved, because GoW's readbacks mostly hit the last batch. DeS looks like the opposite, so yes, the split (time until the GPU thread picks the readback up vs. the readback itself) would show whether the hand-over or the GPU wait dominates.

**@⁠NeySlim** on GitHub · 2026-10-22 07:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1254#issuecomment-6334987284) That's the case where a separate copy path pays off: when the writer has finished, a copy on its own queue waits ~80 µs here instead of the whole submitted work. In GoW I tried it and also served those readbacks straight from the guest thread: guest waits halved, but the GPU thread lost more than it saved, because GoW's readbacks mostly hit the last batch. DeS looks like the opposite, so yes, the split (time until the GPU thread picks the readback up vs. the readback itself) would show whether the hand-over or the GPU wait dominates.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-31 12:29 UTC · original · edited 2026-10-31 12:31 UTC

Demon's Souls (PPSA01341) on Windows 11, RX 9070 XT, Ryzen 5 7600X: main 4919fdb6 against main + this PR (d6ff3763 cherry-picked; one line adapted to main's rename: stage->runtime->module->info.has_address_writes in renderDraw.cpp). Both builds also carry a lab input-script player that presses the same buttons in every run. Runs from boot without save data.

With Tracy on main, a flush before a guest write to a GPU-modified buffer page took 24 ms (1,866 flushes in one capture), a read fault on such a page 15-22 ms. In one of 9 main runs the boot got stuck in these flushes (2,863 in one capture, 21 ms each); none of the 9 runs with this PR got stuck there.

To your question from 10-22, measured with a log around BufferCache::ReadMemory (hand-over = until the GPU thread starts the readback, readback = the rest, including the GPU wait). Calls that downloaded, among the first 20,000 ReadMemory calls of two runs per build, median / mean in ms, ranges over the two runs:

main: hand-over main: readback this PR: hand-over this PR: readback
guest read faults 0.01 / 1.3-2.5 5.4-12.0 / 11.4-13.3 0.01 / 2.1-2.7 0.5-0.7 / 7.9-8.7
guest write faults (flush) 0.01 / 2.8-5.9 15.6-15.9 / 15.0-15.4 0.06-0.09 / 5.7-10.3 0.6-1.2 / 8.8-9.3
reads on the GPU thread itself - 2.1-16.1 / 12.0-15.6 - 0.6-0.7 / 7.8-8.9

On main the GPU wait dominates. With this PR the median readback drops to about 1 ms or less, but a tail stays (readback p90 28-32 ms in every row, both builds), and for write faults the hand-over is now about as long as the readback (means 5.7-10.3 vs 8.8-9.3 ms, hand-over p90 ~25 ms): the GPU thread is busy, partly with its own readbacks (about 11,700 of the first 20,000 calls in each run). Your neighbour download shows too: on main 3,300 of 15,526 and 3,756 of 19,999 logged read faults hit the page right after the previous fault's page, with this PR none of 19,999.

What the readbacks bring back: the same log compares each downloaded range with the guest bytes it replaces. On main, 43% and 64% of the readbacks (35,500 and 51,000 per run) changed no byte, and of 112 MB and 125 MB downloaded, 10.7 MB and 8.2 MB differed. With this PR 43% and 44% changed no byte, of 1.08 GB and 1.14 GB downloaded (it also takes the neighbouring ranges) 136 MB and 71 MB differed. For example, a page holding 16-byte ranges marked as written is read back 1,535 times, 1,466 of them unchanged; on another page the game reads at +0xed8, next to written ranges that end at +0xed0, and 687 of 710 readbacks are unchanged. Kyty's own GPU thread reading guest memory on such pages takes 41-45% of the read-fault time on main and 63% with this PR, the rest is the game's job worker threads. So in DeS most of these waits are for bytes the GPU did not change: ObtainBuffer(..., written) marks the whole bound range of a written storage buffer as GPU-modified.

Correction to my 10-20 table: its "CPU waiting on the GPU" rows came from a counter in MasterSemaphore::Wait. This PR's readback waits in EndDetached (waitForFences), which that counter does not see, so those rows understate the PR side. The readback time and frame rate rows are not affected.

**@⁠Nawid3333** on GitHub · 2026-10-31 12:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1254#issuecomment-6543373051) · edited 2026-10-31 12:31 UTC Demon's Souls (PPSA01341) on Windows 11, RX 9070 XT, Ryzen 5 7600X: main 4919fdb6 against main + this PR (d6ff3763 cherry-picked; one line adapted to main's rename: `stage->runtime->module->info.has_address_writes` in renderDraw.cpp). Both builds also carry a lab input-script player that presses the same buttons in every run. Runs from boot without save data. With Tracy on main, a flush before a guest write to a GPU-modified buffer page took 24 ms (1,866 flushes in one capture), a read fault on such a page 15-22 ms. In one of 9 main runs the boot got stuck in these flushes (2,863 in one capture, 21 ms each); none of the 9 runs with this PR got stuck there. To your question from 10-22, measured with a log around `BufferCache::ReadMemory` (hand-over = until the GPU thread starts the readback, readback = the rest, including the GPU wait). Calls that downloaded, among the first 20,000 `ReadMemory` calls of two runs per build, median / mean in ms, ranges over the two runs: | | main: hand-over | main: readback | this PR: hand-over | this PR: readback | |---|---|---|---|---| | guest read faults | 0.01 / 1.3-2.5 | 5.4-12.0 / 11.4-13.3 | 0.01 / 2.1-2.7 | 0.5-0.7 / 7.9-8.7 | | guest write faults (flush) | 0.01 / 2.8-5.9 | 15.6-15.9 / 15.0-15.4 | 0.06-0.09 / 5.7-10.3 | 0.6-1.2 / 8.8-9.3 | | reads on the GPU thread itself | - | 2.1-16.1 / 12.0-15.6 | - | 0.6-0.7 / 7.8-8.9 | On main the GPU wait dominates. With this PR the median readback drops to about 1 ms or less, but a tail stays (readback p90 28-32 ms in every row, both builds), and for write faults the hand-over is now about as long as the readback (means 5.7-10.3 vs 8.8-9.3 ms, hand-over p90 ~25 ms): the GPU thread is busy, partly with its own readbacks (about 11,700 of the first 20,000 calls in each run). Your neighbour download shows too: on main 3,300 of 15,526 and 3,756 of 19,999 logged read faults hit the page right after the previous fault's page, with this PR none of 19,999. What the readbacks bring back: the same log compares each downloaded range with the guest bytes it replaces. On main, 43% and 64% of the readbacks (35,500 and 51,000 per run) changed no byte, and of 112 MB and 125 MB downloaded, 10.7 MB and 8.2 MB differed. With this PR 43% and 44% changed no byte, of 1.08 GB and 1.14 GB downloaded (it also takes the neighbouring ranges) 136 MB and 71 MB differed. For example, a page holding 16-byte ranges marked as written is read back 1,535 times, 1,466 of them unchanged; on another page the game reads at +0xed8, next to written ranges that end at +0xed0, and 687 of 710 readbacks are unchanged. Kyty's own GPU thread reading guest memory on such pages takes 41-45% of the read-fault time on main and 63% with this PR, the rest is the game's job worker threads. So in DeS most of these waits are for bytes the GPU did not change: `ObtainBuffer(..., written)` marks the whole bound range of a written storage buffer as GPU-modified. Correction to my 10-20 table: its "CPU waiting on the GPU" rows came from a counter in `MasterSemaphore::Wait`. This PR's readback waits in `EndDetached` (`waitForFences`), which that counter does not see, so those rows understate the PR side. The readback time and frame rate rows are not affected.
This pull request has changes conflicting with the target branch.
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/renderDraw.cpp
  • tests/ShaderRecompilerComputeTests.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1254/head:github-bot/gh-1254'
git switch 'github-bot/gh-1254'

Merge

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