renderer: decide color metadata clears on the GPU #1283

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

@⁠NeySlim on GitHub · 2026-10-09 07:25 UTC · original
NeySlim:perf/gpu-meta-clear → main · +621 −14 · 13 files · 6 commits · closed without merging

Problem

When a color target or a view of it is bound, MaterializeColorClear decides on the CPU whether each metadata slice holds a fast-clear key (CMASK key 0, DCC keys 0x20, 0x00, 0x40, 0x80, 0xc0). When a compute shader wrote the metadata, which is how games fast-clear, ReadMemory first downloads it and the command thread waits until the GPU has finished the work recorded so far.

God of War Ragnarök (PPSA08332, 05.005) rewrites the metadata of several targets by compute every frame. The command thread blocks on these readbacks about 4 times per frame: 3.4 ms per frame in the opening cutscene and 4.8 ms per frame in the first gameplay section (scheduler traces, perf record -e sched:sched_switch, blocked time attributed by stack).

Change

  • When the metadata range is GPU-written and VK_EXT_conditional_rendering is available, the decision runs on the GPU. A compute pass (gpu_meta_clear_check.comp, one workgroup per slice) checks that all bytes of a slice equal one of the keys the target decodes and writes one predicate per key. When a key matches, it also writes the expanded keys (0xff) in place, as the CPU path does in guest memory.
  • The clears are recorded with vkCmdClearAttachments under conditional rendering, one per slice and per decodable key, with the color the CPU path would use. Same decision, same point in the command stream.
  • Conditional rendering applies to vkCmdClearAttachments but not to transfer clears, so the GPU path needs an image created with color attachment usage and a view format with the color attachment feature. Otherwise the CPU path is used, as before.
  • A skipped clear keeps the image contents, so the image is initialized from guest memory first when it is dirty, then committed as GPU-written.
  • BufferCache can watch a range: a GPU write, an upload, an invalidation, a CPU write or a shader address write marks it changed. When a target is bound again with unchanged metadata and the same decode inputs, the last decision is reused: the bytes are either expanded or not a clear for these inputs, so the CPU path would not clear either. A shader address write has no known range, so every draw or dispatch with address writes (has_address_writes) marks all watched ranges changed: in frames with many such shaders, as in God of War Ragnarök, the decision cache rarely hits and the gain comes from removing the readbacks. Each watch keeps its own change state, so watching a range that overlaps another does not hide a change already recorded for the other. Unmapping memory drops its watches and decisions.
  • A target that decodes none of the keys returns before reading the metadata, since no slice can be cleared.
  • Unchanged CPU path: without the extension, for video-out bindings (they clear without expanding the keys), for volume or MSAA targets, and for images or view formats that cannot be color attachments.

Test

RenderExecutorColorMetadataClear runs with conditional rendering enabled in the test harness. After the native compute fill of the metadata, binding the target must not read the metadata back (the range stays GPU-written). All existing cases of the test now go through the GPU path and still pass: clear value, expanded keys after a later readback, rebinding unchanged metadata keeps rendered texels, CPU re-clear, partial and repeated fills, texture views. With the GPU path disabled the new check fails (binding a target read its GPU-written metadata back to the CPU).

The test also removes the color attachment usage from the cached image (standing in for a host format that cannot be rendered to; on RADV every color format the emulator maps supports it, so no real format reaches this case here) and checks that the next fill is decided through a readback and still clears; without the capability check it fails. After unmapping, no watched range or cached decision may remain; it fails without the purge. Two overlapping watches: after a GPU write to the overlap and a new watch of the second range, the first must still report the change; it fails when a new watch clears the changes of the ranges it overlaps. The harness only queries the conditional rendering features when the device exposes the extension.

Validation

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

  • shader_recompiler_compute_tests, one case per process: same results as main (595 of 604 pass; the 9 others fail on main too on this setup). resource_tracking_tests and resource_materialization_tests pass.
  • God of War Ragnarök, new game through the opening cutscene and the sled section, with the indirect-draw change from #1288:
    • no metadata readback left in the scheduler traces (3.4 and 4.8 ms per frame before);
    • alternating the new and the old paths every 5 s in the same session (same scenes, about 75 periods each): command thread blocked 20.2 ms per frame before, 14.6 ms after; frame rate +0.4 fps median (about 5%, 45 of 62 cycles faster);
    • screenshots of the same scenes show no rendering difference (the black blocks in the characters' eyes are already there on main).

Not tested on Windows. VK_EXT_conditional_rendering is available on current AMD, NVIDIA and Intel drivers; without it the existing path is used.

AI use

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

**@⁠NeySlim** on GitHub · 2026-10-09 07:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1283) `NeySlim:perf/gpu-meta-clear` → `main` · +621 −14 · 13 files · 6 commits · closed without merging ## Problem When a color target or a view of it is bound, `MaterializeColorClear` decides on the CPU whether each metadata slice holds a fast-clear key (CMASK key 0, DCC keys 0x20, 0x00, 0x40, 0x80, 0xc0). When a compute shader wrote the metadata, which is how games fast-clear, `ReadMemory` first downloads it and the command thread waits until the GPU has finished the work recorded so far. God of War Ragnarök (PPSA08332, 05.005) rewrites the metadata of several targets by compute every frame. The command thread blocks on these readbacks about 4 times per frame: 3.4 ms per frame in the opening cutscene and 4.8 ms per frame in the first gameplay section (scheduler traces, `perf record -e sched:sched_switch`, blocked time attributed by stack). ## Change - When the metadata range is GPU-written and `VK_EXT_conditional_rendering` is available, the decision runs on the GPU. A compute pass (`gpu_meta_clear_check.comp`, one workgroup per slice) checks that all bytes of a slice equal one of the keys the target decodes and writes one predicate per key. When a key matches, it also writes the expanded keys (0xff) in place, as the CPU path does in guest memory. - The clears are recorded with `vkCmdClearAttachments` under conditional rendering, one per slice and per decodable key, with the color the CPU path would use. Same decision, same point in the command stream. - Conditional rendering applies to `vkCmdClearAttachments` but not to transfer clears, so the GPU path needs an image created with color attachment usage and a view format with the color attachment feature. Otherwise the CPU path is used, as before. - A skipped clear keeps the image contents, so the image is initialized from guest memory first when it is dirty, then committed as GPU-written. - `BufferCache` can watch a range: a GPU write, an upload, an invalidation, a CPU write or a shader address write marks it changed. When a target is bound again with unchanged metadata and the same decode inputs, the last decision is reused: the bytes are either expanded or not a clear for these inputs, so the CPU path would not clear either. A shader address write has no known range, so every draw or dispatch with address writes (`has_address_writes`) marks all watched ranges changed: in frames with many such shaders, as in God of War Ragnarök, the decision cache rarely hits and the gain comes from removing the readbacks. Each watch keeps its own change state, so watching a range that overlaps another does not hide a change already recorded for the other. Unmapping memory drops its watches and decisions. - A target that decodes none of the keys returns before reading the metadata, since no slice can be cleared. - Unchanged CPU path: without the extension, for video-out bindings (they clear without expanding the keys), for volume or MSAA targets, and for images or view formats that cannot be color attachments. ## Test `RenderExecutorColorMetadataClear` runs with conditional rendering enabled in the test harness. After the native compute fill of the metadata, binding the target must not read the metadata back (the range stays GPU-written). All existing cases of the test now go through the GPU path and still pass: clear value, expanded keys after a later readback, rebinding unchanged metadata keeps rendered texels, CPU re-clear, partial and repeated fills, texture views. With the GPU path disabled the new check fails (`binding a target read its GPU-written metadata back to the CPU`). The test also removes the color attachment usage from the cached image (standing in for a host format that cannot be rendered to; on RADV every color format the emulator maps supports it, so no real format reaches this case here) and checks that the next fill is decided through a readback and still clears; without the capability check it fails. After unmapping, no watched range or cached decision may remain; it fails without the purge. Two overlapping watches: after a GPU write to the overlap and a new watch of the second range, the first must still report the change; it fails when a new watch clears the changes of the ranges it overlaps. The harness only queries the conditional rendering features when the device exposes the extension. ## Validation Linux, AMD Radeon 8060S (RDNA 3.5), Mesa RADV 26.2.3. - `shader_recompiler_compute_tests`, one case per process: same results as main (595 of 604 pass; the 9 others fail on main too on this setup). `resource_tracking_tests` and `resource_materialization_tests` pass. - God of War Ragnarök, new game through the opening cutscene and the sled section, with the indirect-draw change from #1288: - no metadata readback left in the scheduler traces (3.4 and 4.8 ms per frame before); - alternating the new and the old paths every 5 s in the same session (same scenes, about 75 periods each): command thread blocked 20.2 ms per frame before, 14.6 ms after; frame rate +0.4 fps median (about 5%, 45 of 62 cycles faster); - screenshots of the same scenes show no rendering difference (the black blocks in the characters' eyes are already there on main). Not tested on Windows. `VK_EXT_conditional_rendering` is available on current AMD, NVIDIA and Intel drivers; without it the existing path is used. ## AI use I used Claude Code (AI agent) to measure where the GPU command thread waits, write the change and the test, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:51:21 +00:00
github-bot closed this pull request 2026-11-26 09:51:21 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 07:32 UTC · original · edited 2026-10-21 23:04 UTC

Review in Change Stack →

Note

Reviews paused

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

  • Last reviewed commit: b34f3f7ba5b2848c38d74a30e5f9fd50856e4d5d
  • Latest commit, not reviewed: 6b465518cd

Use the following commands to manage reviews:

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

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1faa17c0-1f11-4b74-93da-a11b77dc1e44
📥 Commits

Reviewing files that changed from the base of the PR and between 71afd45b990eebbd39c604cd2b6baead99201789 and b34f3f7ba5b2848c38d74a30e5f9fd50856e4d5d.

📒 Files selected for processing: 9
  • CMakeLists.txt
  • src/graphics/host_gpu/graphicContext.h
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.h
  • src/graphics/host_gpu/renderer/renderCompute.cpp
  • src/graphics/host_gpu/renderer/renderDraw.cpp
  • src/graphics/presentation/window/vulkanWindow.cpp
  • tests/ShaderRecompilerComputeTests.cpp

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

📝 Walkthrough

The change adds Vulkan conditional-rendering support and a compute shader that checks metadata slices against supported clear codes. BufferCache tracks watched memory ranges and shader address writes. TextureCache uses the resulting predicates to conditionally clear eligible image slices and retains the metadata readback path when GPU materialization is unavailable. Tests cover conditional-rendering support, metadata clearing, watched-range changes, and unmapping.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Refactor

Merge Risk: ⚪ Minimal · up to b34f3

The overlapping-watch fix preserves pending metadata changes, and no remaining issue is established that should block merging 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 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 10 files. (2 skipped:… 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 and concisely describes the main change: moving color metadata clear decisions to the GPU.
Description check Passed The description directly explains the problem, GPU-based metadata clear decision path, fallback behavior, tests, and validation results for 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 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 10 files. (2 skipped: 1 unsupported, 1 too large.)

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

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

❤️ Share

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 07:32 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1283#issuecomment-6076529635) · edited 2026-10-21 23:04 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/1283?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- This is an auto-generated comment: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > - Last reviewed commit: b34f3f7ba5b2848c38d74a30e5f9fd50856e4d5d > - Latest commit, not reviewed: 6b465518cdb9732a9af78a1a46ef75ad84ac70e6 > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> ▶️ Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `1faa17c0-1f11-4b74-93da-a11b77dc1e44` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 71afd45b990eebbd39c604cd2b6baead99201789 and b34f3f7ba5b2848c38d74a30e5f9fd50856e4d5d. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 9</strong></summary> <dl> <dd> * `CMakeLists.txt` * `src/graphics/host_gpu/graphicContext.h` * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.h` * `src/graphics/host_gpu/renderer/renderCompute.cpp` * `src/graphics/host_gpu/renderer/renderDraw.cpp` * `src/graphics/presentation/window/vulkanWindow.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The change adds Vulkan conditional-rendering support and a compute shader that checks metadata slices against supported clear codes. `BufferCache` tracks watched memory ranges and shader address writes. `TextureCache` uses the resulting predicates to conditionally clear eligible image slices and retains the metadata readback path when GPU materialization is unavailable. Tests cover conditional-rendering support, metadata clearing, watched-range changes, and unmapping. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"b34f3f7ba5b2848c38d74a30e5f9fd50856e4d5d" --> **Change:** Refactor <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>b34f3</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `b34f3` --> <!-- final_review_risk_coverage:{"sourceCommitId":"b34f3f7ba5b2848c38d74a30e5f9fd50856e4d5d","coveredCommitId":"b34f3f7ba5b2848c38d74a30e5f9fd50856e4d5d","kind":"reviewed"} --> The overlapping-watch fix preserves pending metadata changes, and no remaining issue is established that should block merging 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 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 10 files. (2 skipped:… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: moving color metadata clear decisions to the GPU. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the problem, GPU-based metadata clear decision path, fallback behavior, tests, and validation results for 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 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 28 functions across 10 files. (2 skipped: 1 unsupported, 1 too large.) </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=1283)! 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 -->
@ -1116,0 +1170,4 @@
if (const auto found = m_meta_clear_decisions.find(address);
found != m_meta_clear_decisions.end() && found->second == decision &&
m_buffer_cache.IsWatchedRangeUnchanged(address, decision.size)) {
return true;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 07:32 UTC · original · edited 2026-10-09 07:46 UTC

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1225,1278p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '1380,1470p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
rg -n 'MaterializeColorClear\(|m_meta_clear_decisions|Invalidate.*Image|DeleteImage' src/graphics/host_gpu/renderer/cache/textureCache.cpp

Repository: KytyPS5/KytyPS5

Length of output: 6024


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- declarations and references ---'
rg -n -F -- 'MaterializeColorClear' src/graphics/host_gpu/renderer/cache
rg -n -F -- 'm_meta_clear_decisions' src/graphics/host_gpu/renderer/cache
rg -n -F -- 'FindImage(' src/graphics/host_gpu/renderer/cache/textureCache.cpp
rg -n -F -- 'InsertImage(' src/graphics/host_gpu/renderer/cache/textureCache.cpp
rg -n -F -- 'FreeImage(' src/graphics/host_gpu/renderer/cache/textureCache.cpp
rg -n -F -- 'ResolveOverlap' src/graphics/host_gpu/renderer/cache/textureCache.cpp
printf '%s\n' '--- materialization and image lifetime ---'
sed -n '250,345p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '1080,1278p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '1278,1395p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '1395,1485p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
printf '%s\n' '--- declarations/types ---'
rg -n -F -- 'MetaClearDecision' src/graphics/host_gpu/renderer/cache
rg -n -F -- 'struct ImageInfo' src/graphics/host_gpu/renderer/cache
rg -n -F -- 'SameBacking' src/graphics/host_gpu/renderer/cache

Repository: KytyPS5/KytyPS5

Length of output: 22547


🏁 Script executed:

rg -n -F -- 'm_meta_clear_decisions' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '250,345p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '1080,1280p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
rg -n -F -- 'FindImage(' src/graphics/host_gpu/renderer/cache/textureCache.cpp
rg -n -F -- 'InsertImage(' src/graphics/host_gpu/renderer/cache/textureCache.cpp
rg -n -F -- 'FreeImage(' src/graphics/host_gpu/renderer/cache/textureCache.cpp
rg -n -F -- 'ResolveOverlap' src/graphics/host_gpu/renderer/cache/textureCache.cpp

Repository: KytyPS5/KytyPS5

Length of output: 13111


🏁 Script executed:

sed -n '250,345p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '1080,1280p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
rg -n -F -- 'm_meta_clear_decisions' src/graphics/host_gpu/renderer/cache/textureCache.cpp

Repository: KytyPS5/KytyPS5

Length of output: 12262


🏁 Script executed:

set -o pipefail
sed -n '150,255p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '735,835p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '1388,1452p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
rg -n -F -- 'struct MetaClearDecision' src/graphics/host_gpu/renderer/cache/textureCache.h
sed -n '88,115p' src/graphics/host_gpu/renderer/cache/textureCache.h

Repository: KytyPS5/KytyPS5

Length of output: 11244


🏁 Script executed:

sed -n '150,255p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '735,835p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '1388,1452p' src/graphics/host_gpu/renderer/cache/textureCache.cpp
sed -n '88,115p' src/graphics/host_gpu/renderer/cache/textureCache.h

Repository: KytyPS5/KytyPS5

Length of output: 11213


Include the native image and layer in the GPU clear decision cache.

m_meta_clear_decisions is keyed only by the metadata address and decision parameters. FindImage can free a cached native image and create a replacement for the same guest data. FreeImage does not remove the decision. A later cache hit can therefore return before ClearImageSlicesIf runs for the replacement image. The replacement can render stale or uninitialized contents.

Store the native image and first layer in the cached decision, and remove decisions when their image is deleted.

Suggested fix
 struct MetaClearDecision {
+	ImageId                                        image {};
+	uint32_t                                       first_layer = 0;
 	uint64_t                                      size   = 0;
 	vk::Format                                    format = vk::Format::eUndefined;
 	uint32_t                                      level  = 0;
 void TextureCache::DeleteImage(ImageId id) {
 	auto* image = m_slot_images.try_get(id);
 	if (image == nullptr || !image->registered) {
 		return;
 	}
+	for (auto it = m_meta_clear_decisions.begin(); it != m_meta_clear_decisions.end();) {
+		it = it->second.image == id ? m_meta_clear_decisions.erase(it) : std::next(it);
+	}
 	MetaClearDecision decision {.size       = slice_size * count,
+	                            .image      = id,
+	                            .first_layer = image_first,
 	                            .format     = view.format,
**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 07:32 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1283#discussion_r4227757761) · edited 2026-10-09 07:46 UTC **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '1225,1278p' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '1380,1470p' src/graphics/host_gpu/renderer/cache/textureCache.cpp rg -n 'MaterializeColorClear\(|m_meta_clear_decisions|Invalidate.*Image|DeleteImage' src/graphics/host_gpu/renderer/cache/textureCache.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 6024 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- declarations and references ---' rg -n -F -- 'MaterializeColorClear' src/graphics/host_gpu/renderer/cache rg -n -F -- 'm_meta_clear_decisions' src/graphics/host_gpu/renderer/cache rg -n -F -- 'FindImage(' src/graphics/host_gpu/renderer/cache/textureCache.cpp rg -n -F -- 'InsertImage(' src/graphics/host_gpu/renderer/cache/textureCache.cpp rg -n -F -- 'FreeImage(' src/graphics/host_gpu/renderer/cache/textureCache.cpp rg -n -F -- 'ResolveOverlap' src/graphics/host_gpu/renderer/cache/textureCache.cpp printf '%s\n' '--- materialization and image lifetime ---' sed -n '250,345p' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '1080,1278p' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '1278,1395p' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '1395,1485p' src/graphics/host_gpu/renderer/cache/textureCache.cpp printf '%s\n' '--- declarations/types ---' rg -n -F -- 'MetaClearDecision' src/graphics/host_gpu/renderer/cache rg -n -F -- 'struct ImageInfo' src/graphics/host_gpu/renderer/cache rg -n -F -- 'SameBacking' src/graphics/host_gpu/renderer/cache ``` Repository: KytyPS5/KytyPS5 Length of output: 22547 --- 🏁 Script executed: ```bash rg -n -F -- 'm_meta_clear_decisions' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '250,345p' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '1080,1280p' src/graphics/host_gpu/renderer/cache/textureCache.cpp rg -n -F -- 'FindImage(' src/graphics/host_gpu/renderer/cache/textureCache.cpp rg -n -F -- 'InsertImage(' src/graphics/host_gpu/renderer/cache/textureCache.cpp rg -n -F -- 'FreeImage(' src/graphics/host_gpu/renderer/cache/textureCache.cpp rg -n -F -- 'ResolveOverlap' src/graphics/host_gpu/renderer/cache/textureCache.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 13111 --- 🏁 Script executed: ```bash sed -n '250,345p' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '1080,1280p' src/graphics/host_gpu/renderer/cache/textureCache.cpp rg -n -F -- 'm_meta_clear_decisions' src/graphics/host_gpu/renderer/cache/textureCache.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 12262 --- 🏁 Script executed: ```bash set -o pipefail sed -n '150,255p' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '735,835p' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '1388,1452p' src/graphics/host_gpu/renderer/cache/textureCache.cpp rg -n -F -- 'struct MetaClearDecision' src/graphics/host_gpu/renderer/cache/textureCache.h sed -n '88,115p' src/graphics/host_gpu/renderer/cache/textureCache.h ``` Repository: KytyPS5/KytyPS5 Length of output: 11244 --- 🏁 Script executed: ```bash sed -n '150,255p' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '735,835p' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '1388,1452p' src/graphics/host_gpu/renderer/cache/textureCache.cpp sed -n '88,115p' src/graphics/host_gpu/renderer/cache/textureCache.h ``` Repository: KytyPS5/KytyPS5 Length of output: 11213 --- </details> **Include the native image and layer in the GPU clear decision cache.** `m_meta_clear_decisions` is keyed only by the metadata address and decision parameters. `FindImage` can free a cached native image and create a replacement for the same guest data. `FreeImage` does not remove the decision. A later cache hit can therefore return before `ClearImageSlicesIf` runs for the replacement image. The replacement can render stale or uninitialized contents. Store the native image and first layer in the cached decision, and remove decisions when their image is deleted. <details> <summary>Suggested fix</summary> ```diff struct MetaClearDecision { + ImageId image {}; + uint32_t first_layer = 0; uint64_t size = 0; vk::Format format = vk::Format::eUndefined; uint32_t level = 0; ``` ```diff void TextureCache::DeleteImage(ImageId id) { auto* image = m_slot_images.try_get(id); if (image == nullptr || !image->registered) { return; } + for (auto it = m_meta_clear_decisions.begin(); it != m_meta_clear_decisions.end();) { + it = it->second.image == id ? m_meta_clear_decisions.erase(it) : std::next(it); + } ``` ```diff MetaClearDecision decision {.size = slice_size * count, + .image = id, + .first_layer = image_first, .format = view.format, ``` </details> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:20a6205da743a072d9c693f3 --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bfb73cd8-6b64-4b62-8ea2-f73cea015e08
📥 Commits

Reviewing files that changed from the base of the PR and between 7b9997baea and 9c6c388f1437d6961f7ba50a755839a63f32425b.

📒 Files selected for processing (13)
  • CMakeLists.txt
  • src/graphics/host_gpu/graphicContext.h
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/cache/metaClearCheck.cpp
  • src/graphics/host_gpu/renderer/cache/metaClearCheck.h
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.h
  • src/graphics/host_gpu/renderer/renderCompute.cpp
  • src/graphics/host_gpu/renderer/renderDraw.cpp
  • src/graphics/host_gpu/shaders/gpu_meta_clear_check.comp
  • src/graphics/presentation/window/vulkanWindow.cpp
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 07:32 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1283#pullrequestreview-5467157033) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `bfb73cd8-6b64-4b62-8ea2-f73cea015e08` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 7b9997baea0d385e9e8fc2bd3abeb02110bc4148 and 9c6c388f1437d6961f7ba50a755839a63f32425b. </details> <details> <summary>📒 Files selected for processing (13)</summary> * `CMakeLists.txt` * `src/graphics/host_gpu/graphicContext.h` * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `src/graphics/host_gpu/renderer/cache/metaClearCheck.cpp` * `src/graphics/host_gpu/renderer/cache/metaClearCheck.h` * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.h` * `src/graphics/host_gpu/renderer/renderCompute.cpp` * `src/graphics/host_gpu/renderer/renderDraw.cpp` * `src/graphics/host_gpu/shaders/gpu_meta_clear_check.comp` * `src/graphics/presentation/window/vulkanWindow.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=9ecd4625-6ff5-46c8-bb38-33f593e8ac98 attempt=67e0d62a-5267-4c11-8daa-c4a7f4c999d2 batch=1/1 -->
@ -1116,0 +1170,4 @@
if (const auto found = m_meta_clear_decisions.find(address);
found != m_meta_clear_decisions.end() && found->second == decision &&
m_buffer_cache.IsWatchedRangeUnchanged(address, decision.size)) {
return true;
Author
Owner

@⁠NeySlim on GitHub · 2026-10-09 07:46 UTC · original

No change needed. The decision cache only skips a redundant check: both deciding paths expand every matched slice to 0xff (the compute check with its expand flag, the CPU path with WriteBacking), so a second run over unchanged bytes decodes no code and clears nothing, whatever native image is bound. The cache is dropped as soon as the bytes change (IsWatchedRangeUnchanged), which is the only case where a new decision can differ. Keying it by image would re-record a compute pass that clears nothing; the contents of a replacement image created from guest data are a separate property of FreeImage, unchanged by this PR and the same as the CPU path on main.

**@⁠NeySlim** on GitHub · 2026-10-09 07:46 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1283#discussion_r4227861640) No change needed. The decision cache only skips a redundant check: both deciding paths expand every matched slice to 0xff (the compute check with its expand flag, the CPU path with WriteBacking), so a second run over unchanged bytes decodes no code and clears nothing, whatever native image is bound. The cache is dropped as soon as the bytes change (IsWatchedRangeUnchanged), which is the only case where a new decision can differ. Keying it by image would re-record a compute pass that clears nothing; the contents of a replacement image created from guest data are a separate property of FreeImage, unchanged by this PR and the same as the CPU path on main.
@ -1116,0 +1170,4 @@
if (const auto found = m_meta_clear_decisions.find(address);
found != m_meta_clear_decisions.end() && found->second == decision &&
m_buffer_cache.IsWatchedRangeUnchanged(address, decision.size)) {
return true;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 07:47 UTC · original

@NeySlim, you’re right. Thanks for the clarification.

Both paths expand matched metadata slices to 0xff. With unchanged bytes and decode parameters, another check would clear nothing, regardless of the native image. Adding the image and first layer to the cache would not fix replacement image contents.

I withdraw this finding. No change is needed for this comment.


✏️ Learnings added
Learnt from: NeySlim
Repo: KytyPS5/KytyPS5 PR: 1283
File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:1255-1259
Timestamp: 2026-10-09T07:47:00.427Z
Learning: In src/graphics/host_gpu/renderer/cache/textureCache.cpp, TextureCache::MaterializeColorClearOnGpu caches completed metadata processing, not clear operations to replay for each native image. The GPU checker expands matched slices to 0xff, and TextureCache::MaterializeColorClear does the same through WriteBacking on the CPU path. With unchanged metadata bytes and decode parameters, rechecking produces no clears. Native image identity and destination first layer are therefore not required in this decision cache to replay clears after image replacement.

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.

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 07:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1283#discussion_r4227865629) `@NeySlim`, you’re right. Thanks for the clarification. Both paths expand matched metadata slices to `0xff`. With unchanged bytes and decode parameters, another check would clear nothing, regardless of the native image. Adding the image and first layer to the cache would not fix replacement image contents. I withdraw this finding. No change is needed for this comment. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: NeySlim Repo: KytyPS5/KytyPS5 PR: 1283 File: src/graphics/host_gpu/renderer/cache/textureCache.cpp:1255-1259 Timestamp: 2026-10-09T07:47:00.427Z Learning: In src/graphics/host_gpu/renderer/cache/textureCache.cpp, TextureCache::MaterializeColorClearOnGpu caches completed metadata processing, not clear operations to replay for each native image. The GPU checker expands matched slices to 0xff, and TextureCache::MaterializeColorClear does the same through WriteBacking on the CPU path. With unchanged metadata bytes and decode parameters, rechecking produces no clears. Native image identity and destination first layer are therefore not required in this decision cache to replay clears after image replacement. ``` > 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> ✅ 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-09 09:43 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)

🟠 Major · Do not clear another watch’s pending change. · bufferCache.cpp:270

src/graphics/host_gpu/renderer/cache/bufferCache.cpp:270
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Do not clear another watch’s pending change.

If two metadata ranges overlap, WatchRange for the second range clears m_watch_changed in the overlap. A write already recorded for the first range can then disappear. IsWatchedRangeUnchanged can return true for its stale decision, so TextureCache::MaterializeColorClearOnGpu skips a needed metadata check. Track changes per watch, or retain change generations until each decision has observed them. Based on learnings, cached results must account for every input that can change their validity.

Source: Learnings


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6908937e-2dcc-4207-8da4-e41ad8cc8142
📥 Commits

Reviewing files that changed from the base of the PR and between 9c6c388f1437d6961f7ba50a755839a63f32425b and e08765630b23d3585eea568a28f83dfe67324203.

📒 Files selected for processing (4)
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • 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.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 09:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1283#pullrequestreview-5468419094) · **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>🟠 Major</strong> · Do not clear another watch’s pending change. · <code>bufferCache.cpp:270</code></summary><blockquote> > > `src/graphics/host_gpu/renderer/cache/bufferCache.cpp:270` > **🗄️ Data Integrity & Integration** | **🟠 Major** | **🏗️ Heavy lift** > > **Do not clear another watch’s pending change.** > > If two metadata ranges overlap, `WatchRange` for the second range clears `m_watch_changed` in the overlap. A write already recorded for the first range can then disappear. `IsWatchedRangeUnchanged` can return true for its stale decision, so `TextureCache::MaterializeColorClearOnGpu` skips a needed metadata check. Track changes per watch, or retain change generations until each decision has observed them. Based on learnings, cached results must account for every input that can change their validity. > > <!-- cr-comment:v1:0793877a75a3694a31a033fd --> > > _Source: Learnings_ > > </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**: `6908937e-2dcc-4207-8da4-e41ad8cc8142` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 9c6c388f1437d6961f7ba50a755839a63f32425b and e08765630b23d3585eea568a28f83dfe67324203. </details> <details> <summary>📒 Files selected for processing (4)</summary> * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `tests/ShaderRecompilerComputeTests.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=e6a3649f-6070-4014-a3d2-8977567eba3b attempt=60783cfb-5979-4707-a0d3-be202ad90ac0 batch=1/1 -->
Author
Owner

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

@⁠coderabbitai Re the outside-diff comment on bufferCache.cpp (overlapping watches): confirmed, a new WatchRange cleared the shared change set in the overlap and could hide a write recorded for another watch. Fixed in 0a9a1d37: each watch now keeps its own changed flag (address writes are tracked by a counter each watch compares with), and watching a range only resets that watch. RenderExecutorColorMetadataClear checks two overlapping watches; it fails when a new watch clears the changes of the ranges it overlaps.

**@⁠NeySlim** on GitHub · 2026-10-09 10:01 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1283#issuecomment-6078688990) @⁠coderabbitai Re the outside-diff comment on `bufferCache.cpp` (overlapping watches): confirmed, a new `WatchRange` cleared the shared change set in the overlap and could hide a write recorded for another watch. Fixed in 0a9a1d37: each watch now keeps its own changed flag (address writes are tracked by a counter each watch compares with), and watching a range only resets that watch. `RenderExecutorColorMetadataClear` checks two overlapping watches; it fails when a new watch clears the changes of the ranges it overlaps.
Author
Owner

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

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
fd '^bufferCache\.cpp$|^bufferCache\.h$|^ShaderRecompilerComputeTests\.cpp$'
ast-grep outline src/graphics/host_gpu/renderer/cache/bufferCache.cpp --match 'WatchRange|UnwatchRange|IsRangeUnchanged|NotifyChange|NotifyAddressWrites' --view expanded
rg -n -C 12 'BufferCache::(WatchRange|UnwatchRange|IsRangeUnchanged|NotifyChange|NotifyAddressWrites)\s*\(' src/graphics/host_gpu/renderer/cache/bufferCache.cpp
rg -n -C 8 'address_write|changed|WatchRange|IsRangeUnchanged' src/graphics/host_gpu/renderer/cache/bufferCache.h
rg -n -C 16 'WatchRange\s*\(|IsRangeUnchanged\s*\(' tests/ShaderRecompilerComputeTests.cpp

Length of output: 8204


@NeySlim Thanks for the fix and explanation. I verified that WatchRange resets only the watch at the specified address. Each watch keeps its own changed flag and compares its address-write counter with the global counter.

The regression test checks that creating an overlapping watch leaves the first watch changed and the new watch unchanged. This addresses the reported issue. I inspected the code but did not run the test.


✏️ Learnings added
Learnt from: NeySlim
URL: https://github.com/KytyPS5/KytyPS5/pull/1283

Timestamp: 2026-10-09T10:05:32.632Z
Learning: In src/graphics/host_gpu/renderer/cache/bufferCache.cpp, BufferCache range watches must retain independent change state. Creating an overlapping watch must not clear a change recorded for an existing watch. WatchRange resets only the watch at its starting address; each watch stores its own changed flag and a snapshot of the global address-write counter. RenderExecutorColorMetadataClear in tests/ShaderRecompilerComputeTests.cpp covers creating an overlapping watch after a write and checks that the existing watch remains changed.

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!

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 10:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1283#issuecomment-6078753174) <!-- This is an auto-generated reply by CodeRabbit --> > [!TIP] > For best results, initiate chat on the files or code changes. <details> <summary>🧩 Analysis chain</summary> 🏁 Script executed: ```shell #!/bin/bash set -euo pipefail fd '^bufferCache\.cpp$|^bufferCache\.h$|^ShaderRecompilerComputeTests\.cpp$' ast-grep outline src/graphics/host_gpu/renderer/cache/bufferCache.cpp --match 'WatchRange|UnwatchRange|IsRangeUnchanged|NotifyChange|NotifyAddressWrites' --view expanded rg -n -C 12 'BufferCache::(WatchRange|UnwatchRange|IsRangeUnchanged|NotifyChange|NotifyAddressWrites)\s*\(' src/graphics/host_gpu/renderer/cache/bufferCache.cpp rg -n -C 8 'address_write|changed|WatchRange|IsRangeUnchanged' src/graphics/host_gpu/renderer/cache/bufferCache.h rg -n -C 16 'WatchRange\s*\(|IsRangeUnchanged\s*\(' tests/ShaderRecompilerComputeTests.cpp ``` Length of output: 8204 --- </details> `@NeySlim` Thanks for the fix and explanation. I verified that `WatchRange` resets only the watch at the specified address. Each watch keeps its own `changed` flag and compares its address-write counter with the global counter. The regression test checks that creating an overlapping watch leaves the first watch changed and the new watch unchanged. This addresses the reported issue. I inspected the code but did not run the test. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: NeySlim URL: https://github.com/KytyPS5/KytyPS5/pull/1283 Timestamp: 2026-10-09T10:05:32.632Z Learning: In src/graphics/host_gpu/renderer/cache/bufferCache.cpp, BufferCache range watches must retain independent change state. Creating an overlapping watch must not clear a change recorded for an existing watch. WatchRange resets only the watch at its starting address; each watch stores its own changed flag and a snapshot of the global address-write counter. RenderExecutorColorMetadataClear in tests/ShaderRecompilerComputeTests.cpp covers creating an overlapping watch after a write and checks that the existing watch remains changed. ``` > 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=Overlapping%20watches%20could%20hide%20writes%20when%20a%20new%20range%20reset%20shared%20change%20state.%20Per-watch%20counters%20and%20a%20regression%20test%20fix%20it%E2%80%94try%20%40coderabbitai%20%F0%9F%90%87&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1283)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> _You are interacting with an AI system._
Author
Owner

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

Rebased on main after the depth to color copy (1029511b). Conflicts in graphicContext.h and vulkanWindow.cpp: both sides kept (VK_KHR_maintenance8 and VK_EXT_conditional_rendering are both requested and chained into the device create info).

Linux, Radeon 8060S (RADV): GPU suite one case per process and ctest match a clean main build; RenderExecutorColorMetadataClear still fails when the GPU decision is disabled.

**@⁠NeySlim** on GitHub · 2026-10-11 08:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1283#issuecomment-6107214809) Rebased on main after the depth to color copy (1029511b). Conflicts in graphicContext.h and vulkanWindow.cpp: both sides kept (`VK_KHR_maintenance8` and `VK_EXT_conditional_rendering` are both requested and chained into the device create info). Linux, Radeon 8060S (RADV): GPU suite one case per process and ctest match a clean main build; RenderExecutorColorMetadataClear still fails when the GPU decision is disabled.
Author
Owner

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

Re-measured on main e5f0ee7fc in God of War Ragnarök (new game, no tessellation, #1165 on both sides since main alone stops on a short file read): the proven fills from #1628 never cover the game's color metadata, so main still reads it back 5 times per frame and the command thread blocks 16.5 ms per frame on these readbacks in the opening cutscene and 15.3 ms in the sled section, while this PR leaves no readback. The frame rate gain stays small over 5 runs per side: 8.60 to 8.64 fps in the cutscene (noise) and 7.31 to 7.45 fps in the sled section (+2%), because the command thread waits elsewhere instead (35 ms per frame off CPU on both sides). The "repeated Goat fill stays CPU-owned" test from main is now "repeated Goat fill avoids readback": with this PR the Goat decision is taken on the GPU when conditional rendering is available, so the metadata stays GPU-written and is never read back.

**@⁠NeySlim** on GitHub · 2026-10-19 14:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1283#issuecomment-6269063604) Re-measured on main e5f0ee7fc in God of War Ragnarök (new game, no tessellation, #1165 on both sides since main alone stops on a short file read): the proven fills from #1628 never cover the game's color metadata, so main still reads it back 5 times per frame and the command thread blocks 16.5 ms per frame on these readbacks in the opening cutscene and 15.3 ms in the sled section, while this PR leaves no readback. The frame rate gain stays small over 5 runs per side: 8.60 to 8.64 fps in the cutscene (noise) and 7.31 to 7.45 fps in the sled section (+2%), because the command thread waits elsewhere instead (35 ms per frame off CPU on both sides). The "repeated Goat fill stays CPU-owned" test from main is now "repeated Goat fill avoids readback": with this PR the Goat decision is taken on the GPU when conditional rendering is available, so the metadata stays GPU-written and is never read back.
Author
Owner

@⁠Nmzik on GitHub · 2026-10-22 14:16 UTC · original

b54057942d

**@⁠Nmzik** on GitHub · 2026-10-22 14:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1283#issuecomment-6342970330) b54057942d6bb65e93969c78e79b5de0e9aa4514

Pull request closed

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