gpu: hold game-thread BDA events until the command processor resumes #1933

Open
github-bot wants to merge 2 commits from github-bot/gh-1933 into main AGit
Owner

@⁠MrBigBritches on GitHub · 2026-10-27 04:47 UTC · original
MrBigBritches:bda-sync-defer → main · +230 −6 · 6 files · 2 commits · open

Before every BDA draw, BDA synchronization uploads the pages written since the previous one. A write fault on a game thread queued its page at once. So when a frame had many BDA draws, a page the game kept writing for later frames was uploaded, write-protected, and faulted on again at nearly every one.

Events from threads other than the GPU thread are now held back. They are promoted when the command processor starts or resumes a submission, or reads a guest value that a game thread may have written after the data it guards.

This is the second part of #1809, split out on its own. The first part, uploading BDA synchronization through one staging copy, is #1932. This PR is independent of it.

Changes

  • BufferCache::QueueBdaSync takes a deferred flag. Invalidations on any thread but the GPU thread (game threads, file I/O and so on) go to a separate set. GPU-thread writes still queue immediately, since later draws of the same submission can read them.
  • BufferCache::PromoteBdaSync moves the held-back set into the one TakeBdaSync returns. A flag set with each deferred event lets it return without taking the lock when nothing is held back. When the immediate set is empty, the held-back set is swapped in whole.
  • Where promotion happens:
    • GuestGpu::Process, at every submission slice.
    • CommandProcessor::PromoteGuestWrites(), after reading a guest value:
      • a passing WAIT_REG_MEM,
      • COND_EXEC,
      • BRANCH,
      • a REWIND that is already valid,
      • SET_PREDICATION on a memory value (op 3),
      • a MEM_SEMAPHORE wait that consumes a count.
    • #1809 only promoted on WAIT_REG_MEM. Without the others, a game that writes data and then sets a flag one of them reads could leave the BDA draws after it reading stale data.
  • Promotion runs after the value is read, behind an acquire fence. The game thread queues its data's event before it writes the flag, so promotion always catches it.

Measurements

Octopath Traveler II, the same route on three builds, all based on main 986721f5:

  • main.
  • This PR on its own.
  • This PR together with #1932, which uploads BDA synchronization through one staging copy.

The figures are per-second averages over matching stretches of each run. They come from a temporary log of the emulator's debug counters, which is not part of this PR.

Stretch Build BDA syncs/s FPS Write faults/s Faults per frame BDA queued MB/s Buffer upload MB/s Upload MB per frame
Burst of BDA draws (~35 per frame) main 2,127 53.9 175,645 3,259 801 684 12.7
this PR 2,402 59.0 120,574 2,044 584 469 7.9
this PR + #1932 2,366 59.1 125,426 2,122 597 487 8.2
Heavy scene (~2 per frame) main 100 50.2 84,059 1,675 443 327 6.5
this PR 100 50.0 90,110 1,802 451 349 7.0
this PR + #1932 110 55.2 94,719 1,716 478 367 6.6
60 fps stretch (~2 per frame) main 120 60.1 92,150 1,533 488 358 6.0
this PR 120 60.0 102,503 1,708 508 397 6.6
this PR + #1932 120 60.1 94,041 1,565 486 366 6.1
End of run, 60 fps (~2 per frame) main 120 59.9 96,997 1,619 492 376 6.3
this PR 120 59.9 98,972 1,652 492 384 6.4
this PR + #1932 120 59.8 100,722 1,684 508 390 6.5
  • Where frames have many BDA draws, this PR helps. Write faults and upload bytes per frame drop by about 35%. Frame rate rises from 54 to the 60 fps cap, with or without #1932.
  • With about 2 BDA draws per frame, it changes little. Each synchronization already takes everything queued since the last one.
    • On its own, this PR showed up to 11% more faults per frame in those stretches.
    • With #1932 as well, faults per frame are back within about 4% of main. That suggests the difference is run-to-run noise. Each build ran once, so variance hasn't been measured directly.
  • The two PRs add up. #1932 lifts the heavy scene from 50 to 55 fps by making each synchronization cheaper. Its faults and uploads per frame barely change, and the higher per-second figures there come from the extra frames. This PR fixes the burst. Together, they keep both gains.
  • The remaining ~100k faults/s is a cost of protection-based tracking for memory the CPU writes and the GPU reads every frame. Getting below it needs a different policy for pages that keep faulting, which is out of scope here.
  • In the logs, the game issues about 900 SET_PREDICATION op-3 packets per second. Each one now promotes, which costs one atomic load when nothing is held back.

Testing

  • Octopath Traveler II: frame time improved against main in the measured burst, and both logs are free of errors.
  • New tests in shader_recompiler_compute_tests:
Test What it checks
BdaSyncDeferredEvents Held-back events stay out of TakeBdaSync until promoted, and are promoted exactly once into both an empty and a non-empty set.
Pm4ControlReadsPromoteBdaSync WAIT_REG_MEM, COND_EXEC, BRANCH, REWIND, SET_PREDICATION and MEM_SEMAPHORE each promote a held-back event.
BdaSyncSubmissionPromotes Starting a submission on the GPU thread promotes a held-back event.
  • I checked that the tests can fail. Removing the promotion from COND_EXEC, REWIND or MEM_SEMAPHORE, or from submission start, each fails the matching test.
  • Changed test: BdaSyncUploads writes from the test thread, so its write is now held back. It now checks that the write is held back, then promotes it before its existing checks, which are unchanged.
  • ctest on Windows: 63 of 65 pass. The two failures also fail on main:
    • vdecsw doesn't build, because std::aligned_alloc isn't available in MSVC's C runtime.
    • kernel_file_system crashes with 0xc0000028.
  • Linux and macOS CI currently fail on main, and #1922 fixes them.

Conflicts

This PR and #1928 both change CommandProcessor::WaitRegMem. Whichever merges second needs a small rebase.

**@⁠MrBigBritches** on GitHub · 2026-10-27 04:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1933) `MrBigBritches:bda-sync-defer` → `main` · +230 −6 · 6 files · 2 commits · open Before every BDA draw, BDA synchronization uploads the pages written since the previous one. A write fault on a game thread queued its page at once. So when a frame had many BDA draws, a page the game kept writing for later frames was uploaded, write-protected, and faulted on again at nearly every one. Events from threads other than the GPU thread are now held back. They are promoted when the command processor starts or resumes a submission, or reads a guest value that a game thread may have written after the data it guards. This is the second part of #1809, split out on its own. The first part, uploading BDA synchronization through one staging copy, is #1932. This PR is independent of it. ## Changes - `BufferCache::QueueBdaSync` takes a `deferred` flag. Invalidations on any thread but the GPU thread (game threads, file I/O and so on) go to a separate set. GPU-thread writes still queue immediately, since later draws of the same submission can read them. - `BufferCache::PromoteBdaSync` moves the held-back set into the one `TakeBdaSync` returns. A flag set with each deferred event lets it return without taking the lock when nothing is held back. When the immediate set is empty, the held-back set is swapped in whole. - **Where promotion happens:** - `GuestGpu::Process`, at every submission slice. - `CommandProcessor::PromoteGuestWrites()`, after reading a guest value: - a passing `WAIT_REG_MEM`, - `COND_EXEC`, - `BRANCH`, - a `REWIND` that is already valid, - `SET_PREDICATION` on a memory value (op 3), - a `MEM_SEMAPHORE` wait that consumes a count. - #1809 only promoted on `WAIT_REG_MEM`. Without the others, a game that writes data and then sets a flag one of them reads could leave the BDA draws after it reading stale data. - Promotion runs after the value is read, behind an acquire fence. The game thread queues its data's event before it writes the flag, so promotion always catches it. ## Measurements Octopath Traveler II, the same route on three builds, all based on `main` 986721f5: - `main`. - This PR on its own. - This PR together with #1932, which uploads BDA synchronization through one staging copy. The figures are per-second averages over matching stretches of each run. They come from a temporary log of the emulator's debug counters, which is not part of this PR. | Stretch | Build | BDA syncs/s | FPS | Write faults/s | Faults per frame | BDA queued MB/s | Buffer upload MB/s | Upload MB per frame | |---|---|---|---|---|---|---|---|---| | **Burst of BDA draws** (~35 per frame) | `main` | 2,127 | 53.9 | 175,645 | 3,259 | 801 | 684 | 12.7 | | | this PR | 2,402 | 59.0 | 120,574 | 2,044 | 584 | 469 | 7.9 | | | this PR + #1932 | 2,366 | 59.1 | 125,426 | 2,122 | 597 | 487 | 8.2 | | **Heavy scene** (~2 per frame) | `main` | 100 | 50.2 | 84,059 | 1,675 | 443 | 327 | 6.5 | | | this PR | 100 | 50.0 | 90,110 | 1,802 | 451 | 349 | 7.0 | | | this PR + #1932 | 110 | 55.2 | 94,719 | 1,716 | 478 | 367 | 6.6 | | **60 fps stretch** (~2 per frame) | `main` | 120 | 60.1 | 92,150 | 1,533 | 488 | 358 | 6.0 | | | this PR | 120 | 60.0 | 102,503 | 1,708 | 508 | 397 | 6.6 | | | this PR + #1932 | 120 | 60.1 | 94,041 | 1,565 | 486 | 366 | 6.1 | | **End of run, 60 fps** (~2 per frame) | `main` | 120 | 59.9 | 96,997 | 1,619 | 492 | 376 | 6.3 | | | this PR | 120 | 59.9 | 98,972 | 1,652 | 492 | 384 | 6.4 | | | this PR + #1932 | 120 | 59.8 | 100,722 | 1,684 | 508 | 390 | 6.5 | - **Where frames have many BDA draws, this PR helps.** Write faults and upload bytes per frame drop by about 35%. Frame rate rises from 54 to the 60 fps cap, with or without #1932. - **With about 2 BDA draws per frame, it changes little.** Each synchronization already takes everything queued since the last one. - On its own, this PR showed up to 11% more faults per frame in those stretches. - With #1932 as well, faults per frame are back within about 4% of `main`. That suggests the difference is run-to-run noise. Each build ran once, so variance hasn't been measured directly. - **The two PRs add up.** #1932 lifts the heavy scene from 50 to 55 fps by making each synchronization cheaper. Its faults and uploads per frame barely change, and the higher per-second figures there come from the extra frames. This PR fixes the burst. Together, they keep both gains. - The remaining ~100k faults/s is a cost of protection-based tracking for memory the CPU writes and the GPU reads every frame. Getting below it needs a different policy for pages that keep faulting, which is out of scope here. - In the logs, the game issues about 900 `SET_PREDICATION` op-3 packets per second. Each one now promotes, which costs one atomic load when nothing is held back. ## Testing - **Octopath Traveler II:** frame time improved against `main` in the measured burst, and both logs are free of errors. - **New tests** in `shader_recompiler_compute_tests`: | Test | What it checks | |---|---| | `BdaSyncDeferredEvents` | Held-back events stay out of `TakeBdaSync` until promoted, and are promoted exactly once into both an empty and a non-empty set. | | `Pm4ControlReadsPromoteBdaSync` | `WAIT_REG_MEM`, `COND_EXEC`, `BRANCH`, `REWIND`, `SET_PREDICATION` and `MEM_SEMAPHORE` each promote a held-back event. | | `BdaSyncSubmissionPromotes` | Starting a submission on the GPU thread promotes a held-back event. | - I checked that the tests can fail. Removing the promotion from `COND_EXEC`, `REWIND` or `MEM_SEMAPHORE`, or from submission start, each fails the matching test. - **Changed test:** `BdaSyncUploads` writes from the test thread, so its write is now held back. It now checks that the write is held back, then promotes it before its existing checks, which are unchanged. - **ctest on Windows:** 63 of 65 pass. The two failures also fail on `main`: - `vdecsw` doesn't build, because `std::aligned_alloc` isn't available in MSVC's C runtime. - `kernel_file_system` crashes with `0xc0000028`. - **Linux and macOS CI** currently fail on `main`, and #1922 fixes them. ## Conflicts This PR and #1928 both change `CommandProcessor::WaitRegMem`. Whichever merges second needs a small rebase.
Every shader that uses BDA synchronizes the pages queued since the
previous one. A write fault on a game thread queued its page at once,
so pages the game keeps writing for later frames were uploaded again
at nearly every BDA draw.

Queue BDA events from invalidations on threads other than the GPU
thread (game threads, file I/O and so on) separately. Promote them when
the command processor starts or resumes a submission, or reads a guest
value a game thread may have written after the data it guards. That
covers a passing WAIT_REG_MEM, COND_EXEC, BRANCH, a REWIND that is
already valid, SET_PREDICATION on a memory value, and a MEM_SEMAPHORE
wait that consumes a count. Promotion runs after the value is read,
behind an acquire fence, so it catches every event queued before the
write the command processor saw. GPU-thread writes still queue
immediately, since later draws of the same submission can read them.

Promotion runs at every submission slice and at each of those packets,
and usually finds nothing deferred. A flag set with each deferred event
lets it return without taking the lock. When the immediate set is empty,
the deferred set is swapped in whole.

New tests: Pm4ControlReadsPromoteBdaSync runs each of those packets and
checks it promotes a held-back event, and BdaSyncSubmissionPromotes
checks that starting a submission on the GPU thread does. The existing
CheckBdaSyncUploads writes from the test thread, which is now held back,
so it checks that and promotes the write before its existing checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
BdaSyncSubmissionPromotes polled a volatile marker that the GPU thread
writes, then checked TakeBdaSync. The marker shows the submission ran,
but it gives no ordering under the C++ memory model. Waiting for the GPU
thread to go idle orders its promotion before the check through the GPU
queue mutex. The bounded poll stays as the timeout, so the wait is only
reached once the marker has been seen.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:09:24 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-27 04:56 UTC · original · edited 2026-10-27 05:20 UTC

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between f84350b413 and d6d22a51a0.

Files selected for processing: 1
  • tests/ShaderRecompilerComputeTests.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.

Walkthrough

BufferCache stores off-GPU-thread BDA invalidation ranges separately until promotion. CommandProcessor and GuestGpu promote these ranges at submission and guest control-read points. Tests cover deferred ranges, promotion behavior, and the relevant PM4 packets.

Suggested reviewers: nmzik

Priority: Normal

Change: Bug fix

Merge Risk: Low · up to d6d22

The submission-promotion test has undefined cross-thread behavior, but production promotion ordering appears correct.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly describes the main change: holding game-thread BDA events until the command processor resumes.
Description check Passed The description explains the deferred BDA event changes, promotion points, performance measurements, tests, and known CI failures. It is directly related 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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 13 functions across 5 files. (1 skipped: 1 too large.)

Resolution

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

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-27 04:56 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1933#issuecomment-6434113944) · edited 2026-10-27 05:20 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/1933?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><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <!-- review_info_content --> <details> <summary><strong><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</strong></summary> <dl> <dd> - **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/db12f0c5fb1617b7ce5eaffba0d6be8d9b042bc1/.coderabbit.yaml>) - **Commit**: [db12f0c](<https://github.com/KytyPS5/KytyPS5/commit/db12f0c5fb1617b7ce5eaffba0d6be8d9b042bc1>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `bdd5948a-b00c-46ce-9e86-a55fab9396aa` </dd> </dl> </details> <details> <summary><strong><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</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between f84350b41366d6d842f949ddc897d270820fbce8 and d6d22a51a00a579f0a799a1ef7ac1cc2b95faaa2. </dd> </dl> </details> <details> <summary><strong><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: 1</strong></summary> <dl> <dd> * `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; 6 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> BufferCache stores off-GPU-thread BDA invalidation ranges separately until promotion. CommandProcessor and GuestGpu promote these ranges at submission and guest control-read points. Tests cover deferred ranges, promotion behavior, and the relevant PM4 packets. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <strong>Priority: <picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/priority-normal-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Normal</strong> <!-- change_assessment_commit:"d6d22a51a00a579f0a799a1ef7ac1cc2b95faaa2" --> **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-low-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Low</strong> · up to <code>d6d22</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🔵 Low** · up to `d6d22` --> <!-- final_review_risk_coverage:{"sourceCommitId":"d6d22a51a00a579f0a799a1ef7ac1cc2b95faaa2","coveredCommitId":"d6d22a51a00a579f0a799a1ef7ac1cc2b95faaa2","kind":"reviewed"} --> The submission-promotion test has undefined cross-thread behavior, but production promotion ordering appears correct. <!-- 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 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… | 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 | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly describes the main change: holding game-thread BDA events until the command processor resumes. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description explains the deferred BDA event changes, promotion points, performance measurements, tests, and known CI failures. It is directly related to the changeset. | | 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 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 13 functions across 5 files. (1 skipped: 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1933)! 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 -->
@ -5766,0 +5819,4 @@
"a held-back BDA event was visible before the submission");
// The submission only writes a marker, so the test can tell it has started.
volatile uint32_t done = 0;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-27 04:56 UTC · original · edited 2026-10-27 05:12 UTC

Minor · Stability & Availability · Quick win

Supported by static analysis

Script executed:

sed -n '5811,5842p' tests/ShaderRecompilerComputeTests.cpp
sed -n '725,785p' src/graphics/host_gpu/renderer/cache/bufferCache.cpp
rg -n 'TakeBdaSync|PromoteBdaSync|WaitForIdle' src/graphics/host_gpu/renderer/cache/bufferCache.cpp src/graphics/guest_gpu/graphicsRun.cpp tests/ShaderRecompilerComputeTests.cpp | head -100

Repository: KytyPS5/KytyPS5

Length of output: 7954


Script executed:

set -o pipefail
printf '%s\n' '--- graphicsRun.cpp relevant blocks ---'
nl -ba src/graphics/guest_gpu/graphicsRun.cpp | sed -n '235,275p;305,340p;400,450p;510,535p'
printf '%s\n' '--- declarations and contract references ---'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'volatile uint32_t' -e 'guest-memory' -e 'guest memory' -e 'WriteData' -e 'TakeBdaSync' -e 'PromoteBdaSync' src tests | head -160

Repository: KytyPS5/KytyPS5

Length of output: 17074


Script executed:

set -o pipefail
printf '%s\n' '--- command processor contract ---'
nl -ba src/graphics/guest_gpu/command_processor/commandProcessor.h | sed -n '75,112p'
printf '%s\n' '--- control-read implementations ---'
nl -ba src/graphics/guest_gpu/command_processor/pm4Handlers.cpp | sed -n '1365,1395p;1588,1620p'
printf '%s\n' '--- existing volatile completion usage ---'
nl -ba tests/ShaderRecompilerComputeTests.cpp | sed -n '10195,10245p'
printf '%s\n' '--- surrounding submission processing ---'
nl -ba src/graphics/guest_gpu/graphicsRun.cpp | sed -n '446,522p'

Repository: KytyPS5/KytyPS5

Length of output: 11591


Script executed:

set -o pipefail
printf '%s\n' '--- GuestGpu declarations and Submit API ---'
rg -n -F --glob '*.{h,hpp,cpp}' -e 'class GuestGpu' -e 'WaitForIdle' -e 'Submit(' src/graphics tests | head -100
printf '%s\n' '--- condition wait declarations and implementations ---'
rg -n -F --glob '*.{h,hpp,cpp}' -e 'class Condition' -e 'WaitFor(' -e 'Wait(' src/common src | head -140

Repository: KytyPS5/KytyPS5

Length of output: 11381


Use a bounded idle wait before reading the marker.

volatile does not synchronize the WriteData store with the test-thread read. Add a timeout-capable GuestGpu::WaitForIdle() overload and call it before reading done. If the deadline expires, fail without reading done; otherwise read the marker after the GPU thread has become idle.

Do not add an unbounded WaitForIdle() after the existing poll. TakeBdaSync() already synchronizes the BDA queue with PromoteBdaSync().

**@⁠coderabbitai[bot]** on GitHub · 2026-10-27 04:56 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1933#discussion_r4385218527) · edited 2026-10-27 05:12 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** · **Stability & Availability** · **Quick win** <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/review-details.svg" width="16" height="16" align="absmiddle" alt=""></picture> Supported by static analysis</summary> <dl> <dd> Script executed: ```bash sed -n '5811,5842p' tests/ShaderRecompilerComputeTests.cpp sed -n '725,785p' src/graphics/host_gpu/renderer/cache/bufferCache.cpp rg -n 'TakeBdaSync|PromoteBdaSync|WaitForIdle' src/graphics/host_gpu/renderer/cache/bufferCache.cpp src/graphics/guest_gpu/graphicsRun.cpp tests/ShaderRecompilerComputeTests.cpp | head -100 ``` Repository: KytyPS5/KytyPS5 Length of output: 7954 --- Script executed: ```bash set -o pipefail printf '%s\n' '--- graphicsRun.cpp relevant blocks ---' nl -ba src/graphics/guest_gpu/graphicsRun.cpp | sed -n '235,275p;305,340p;400,450p;510,535p' printf '%s\n' '--- declarations and contract references ---' rg -n -F --glob '*.{cpp,h,hpp}' -e 'volatile uint32_t' -e 'guest-memory' -e 'guest memory' -e 'WriteData' -e 'TakeBdaSync' -e 'PromoteBdaSync' src tests | head -160 ``` Repository: KytyPS5/KytyPS5 Length of output: 17074 --- Script executed: ```bash set -o pipefail printf '%s\n' '--- command processor contract ---' nl -ba src/graphics/guest_gpu/command_processor/commandProcessor.h | sed -n '75,112p' printf '%s\n' '--- control-read implementations ---' nl -ba src/graphics/guest_gpu/command_processor/pm4Handlers.cpp | sed -n '1365,1395p;1588,1620p' printf '%s\n' '--- existing volatile completion usage ---' nl -ba tests/ShaderRecompilerComputeTests.cpp | sed -n '10195,10245p' printf '%s\n' '--- surrounding submission processing ---' nl -ba src/graphics/guest_gpu/graphicsRun.cpp | sed -n '446,522p' ``` Repository: KytyPS5/KytyPS5 Length of output: 11591 --- Script executed: ```bash set -o pipefail printf '%s\n' '--- GuestGpu declarations and Submit API ---' rg -n -F --glob '*.{h,hpp,cpp}' -e 'class GuestGpu' -e 'WaitForIdle' -e 'Submit(' src/graphics tests | head -100 printf '%s\n' '--- condition wait declarations and implementations ---' rg -n -F --glob '*.{h,hpp,cpp}' -e 'class Condition' -e 'WaitFor(' -e 'Wait(' src/common src | head -140 ``` Repository: KytyPS5/KytyPS5 Length of output: 11381 --- </dd> </dl> </details> **Use a bounded idle wait before reading the marker.** `volatile` does not synchronize the `WriteData` store with the test-thread read. Add a timeout-capable `GuestGpu::WaitForIdle()` overload and call it before reading `done`. If the deadline expires, fail without reading `done`; otherwise read the marker after the GPU thread has become idle. Do not add an unbounded `WaitForIdle()` after the existing poll. `TakeBdaSync()` already synchronizes the BDA queue with `PromoteBdaSync()`. <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:fff33fba9e3fffc042e64cf7 --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-27 04:56 UTC · original · reviewed

Actionable comments posted: 1


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between db12f0c5fb and f84350b413.

Files selected for processing: 6
  • src/graphics/guest_gpu/command_processor/commandProcessor.h
  • src/graphics/guest_gpu/command_processor/pm4Handlers.cpp
  • src/graphics/guest_gpu/graphicsRun.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • 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.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-27 04:56 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1933#pullrequestreview-5662387637) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** --- <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <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> - **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/db12f0c5fb1617b7ce5eaffba0d6be8d9b042bc1/.coderabbit.yaml>) - **Commit**: [db12f0c](<https://github.com/KytyPS5/KytyPS5/commit/db12f0c5fb1617b7ce5eaffba0d6be8d9b042bc1>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `af32b6cb-b779-42db-82de-311444584b6d` </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> Reviewing files that changed from the base of the PR and between db12f0c5fb1617b7ce5eaffba0d6be8d9b042bc1 and f84350b41366d6d842f949ddc897d270820fbce8. </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: 6</summary> <dl> <dd> * `src/graphics/guest_gpu/command_processor/commandProcessor.h` * `src/graphics/guest_gpu/command_processor/pm4Handlers.cpp` * `src/graphics/guest_gpu/graphicsRun.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `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> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=8d9a8531-3cdb-4f3c-b22d-6933a68c9d3a attempt=e1e44d67-30f5-469e-ac8e-d1bea5c61e9e batch=1/1 -->
@ -5766,0 +5819,4 @@
"a held-back BDA event was visible before the submission");
// The submission only writes a marker, so the test can tell it has started.
volatile uint32_t done = 0;
Author
Owner

@⁠MrBigBritches on GitHub · 2026-10-27 05:05 UTC · original

The race is formally real but harmless on x86-64. Fixed by calling the existing WaitForIdle() after the bounded poll. It's only reached once the marker is seen, and it synchronizes through the GPU queue mutex, so no timeout API is added. Note the TakeBdaSync/PromoteBdaSync mutex gives exclusion, not ordering.

**@⁠MrBigBritches** on GitHub · 2026-10-27 05:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1933#discussion_r4385265349) The race is formally real but harmless on x86-64. Fixed by calling the existing WaitForIdle() after the bounded poll. It's only reached once the marker is seen, and it synchronizes through the GPU queue mutex, so no timeout API is added. Note the TakeBdaSync/PromoteBdaSync mutex gives exclusion, not ordering.
@ -5766,0 +5819,4 @@
"a held-back BDA event was visible before the submission");
// The submission only writes a marker, so the test can tell it has started.
volatile uint32_t done = 0;
Author
Owner

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
ast-grep outline tests/ShaderRecompilerComputeTests.cpp --match CheckBdaSyncSubmissionPromotes
sed -n '5800,5860p' tests/ShaderRecompilerComputeTests.cpp
rg -n -C8 'GuestGpu::WaitForIdle|GuestGpu::Run|GuestGpu::Submit|m_submit_done|m_queue_mutex' src/graphics/guest_gpu/graphicsRun.cpp

Length of output: 9544


@MrBigBritches I verified that WaitForIdle() now runs after the marker check and before TakeBdaSync(). The GPU queue mutex orders completed submission processing before that assertion.

You are right about my earlier BDA mutex claim: mutual exclusion alone does not ensure that promotion runs before TakeBdaSync().

The added wait does not remove the formal race in the earlier volatile poll. It fixes the ordering of the promotion assertion. I understand that you accept the remaining polling race for x86-64, and I will not press for a timeout API. The original race finding remains technically unresolved.


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-10-27 05:13 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1933#discussion_r4385308124) <!-- coderabbit-ai-generated:v1 --> <details> <summary>🧩 Analysis chain</summary> <dl> <dd> 🏁 Script executed: ```shell #!/bin/bash ast-grep outline tests/ShaderRecompilerComputeTests.cpp --match CheckBdaSyncSubmissionPromotes sed -n '5800,5860p' tests/ShaderRecompilerComputeTests.cpp rg -n -C8 'GuestGpu::WaitForIdle|GuestGpu::Run|GuestGpu::Submit|m_submit_done|m_queue_mutex' src/graphics/guest_gpu/graphicsRun.cpp ``` Length of output: 9544 --- </dd> </dl> </details> `@MrBigBritches` I verified that `WaitForIdle()` now runs after the marker check and before `TakeBdaSync()`. The GPU queue mutex orders completed submission processing before that assertion. You are right about my earlier BDA mutex claim: mutual exclusion alone does not ensure that promotion runs before `TakeBdaSync()`. The added wait does not remove the formal race in the earlier `volatile` poll. It fixes the ordering of the promotion assertion. I understand that you accept the remaining polling race for x86-64, and I will not press for a timeout API. The original race finding remains technically unresolved. --- <!-- 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%20formal%20race%20can%20hide%20even%20when%20code%20appears%20harmless.%20%40coderabbitai%20spots%20the%20missing%20synchronization%20and%20explains%20the%20tradeoffs%E2%80%94try%20it%20for%20sharper%20code%20reviews.%20%F0%9F%94%8D%F0%9F%9B%A0%EF%B8%8F&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1933%23discussion_r4385218527)? 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 -->
This pull request has changes conflicting with the target branch.
  • src/graphics/guest_gpu/command_processor/pm4Handlers.cpp
  • src/graphics/guest_gpu/graphicsRun.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • 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/1933/head:github-bot/gh-1933'
git switch 'github-bot/gh-1933'

Merge

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