shader: read SRT words beside pending GPU writes without waiting #1828

Open
github-bot wants to merge 6 commits from github-bot/gh-1828 into main AGit
Owner

@⁠NeySlim on GitHub · 2026-10-22 11:54 UTC · original
NeySlim:perf/srt-pending-reads → main · +1773 −53 · 18 files · 6 commits · open

Stacked on #1456 (SRT read tables) and #1821 (unknown lists). The first three commits of this branch are those PRs; the three after them are this PR. Tested in God of War Ragnarök (PPSA08332, 05.005).

Problem

In the opening cutscene the GPU command thread, which is the limit in this game, waits 8.6-9.1 ms per frame for SRT reads of memory with pending GPU writes. Each wait submits the open command buffer and waits for the queue. Two cases wait for the same GPU work, and fixing only one moves the whole wait to the other:

  1. Walker reads beside GPU writes (7.2-8.2 ms per frame). A page with a pending GPU buffer write anywhere on it is read-protected. The CPU writes SRT tables right after the range a particle compute shader writes, in the same 4 KiB page, and the walker reads 128-192 bytes past that range, so every read faults and downloads the page.
    The same applies to the whole-plan walker of main: in a Demon's Souls scene measured on #1456, about 5% of its read faults were on pages protected for other bytes (the other 95% read GPU-written bytes, which still need the download).
  2. Block conditions on GPU-written words (the remaining 0.7-1.2 ms, 8.1-8.7 ms once case 1 is fixed). Two compute shaders (e33fa61895d03733, 2567fe9c6381d11e) branch on bit 2 of a word (s_buffer_load_dword at index * 0xa0 + 0x8c, s_bitcmp1_b32, s_cbranch_vccnz) that an earlier dispatch in the same command buffer writes. The shader reads the word itself on the GPU; the host only evaluates the condition to prune the descriptor sources of the branch not taken, and waits for the word to do so.

Change

  • shader: read SRT words beside GPU writes without a flush: guest loads of the SRT walker go through a guarded load, a small routine with a single guest load whose read fault the handler resumes at a failure exit (SetInstructionPointer) instead of downloading the page. The read tables of #1456 and interpreted ordinary reads use it; the whole-plan walker of main records the offsets of its own loads and shares the same exit. The walker then reads that DWORD with TryReadProtectedBacking: straight from the backing, or after a download (waiting as before) when its bytes are in the GPU-written ranges or a shader with address writes, which have no tracked range, is still in flight. The page stays protected.
  • shader: follow both edges of conditions on pending GPU writes: block conditions are evaluated with a reader that fails instead of waiting when the word has pending GPU writes (TryReadSettledBufferBacking). A condition that cannot be read follows both edges, which is what the walker already does for a condition it cannot evaluate: the host binds the sources of both branches and the shader picks its branch on the GPU. If that larger set does not materialize, MaterializeResources tries again with the waiting reader.
  • shader: keep SRT unknowns that read no pending word: a value that is unknown only because a read did not wait must not stay memoized, or a later waiting read would see it as unknown. A failure counter shared by the session tells which unknowns depend on such a read; only those are marked apart and reset after the condition, also when the condition itself is known. Other unknowns keep main's memo for the session.

Test

  • TestCompiledSrtLoadsFromProtectedPage: SRT tables on a page made unreadable, with a block plan, the same plan interpreted, and a tree plan. Values, captured reads and descriptors match an unprotected run, and no fault falls back to unprotecting the page. Fails when faults of guarded loads are not resumed, when the read table loads without the guard, or when a faulting read keeps its captured address.
  • CheckProtectedSrtRead (GPU, also --protected-srt-read-only): a word beside a pending GPU write is read without a download, a GPU-written word is downloaded, and address writes in flight make the read wait. Fails if the reader always downloads, or ignores address writes.
  • TestPendingConditionFollowsBothEdges: branch on a memory word, source in the branch or after the join, word pending or not, branch slot failing or not; checks the reader used, visited blocks, flat SRT, bound sources, captured reads and the retry. Fails if conditions wait.
  • TestNoWaitUnknownsKeepTheirMemo: an unknown that read no pending word keeps its memo, one that read a pending word is reset, also inside a known condition (a || b with a pending). Fails without the last commit.

Without their source changes the tests of the first two commits do not compile.

Validation

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

  • ctest: same failures as main. shader_recompiler_compute_tests one case per process: same results as main plus the new case (784 of 848 pass, main 783 of 847).
  • clang-format of the changed lines: clean.
  • God of War Ragnarök, on top of my other open PRs (main alone does not get in game), with an earlier version of these commits: walker fault waits 7.2-8.2 -> 0 ms per frame, condition waits -> 0, cutscene 19.2-19.3 -> 20.2-20.3 fps (paired +0.9). The first change alone gains nothing, the wait moves to the conditions. No errors, same rendering in the cutscene and the Freya fight.
  • The last commit, measured on the same stack with #1821, against a version that reset every unknown of a condition evaluated without waiting (about 275 k evaluations again per frame): cutscene 19.7 -> 20.5 fps, sled 17.3 -> 18.1, GPU command thread -1.9 / -2.8 ms per frame. A paired check in game (old and new protocol on the same materialization) found no difference in 45 M materializations.

Not tested on Windows. SetInstructionPointer sets CONTEXT::Rip there (__ss.__rip on macOS), and the CPU tests only use HostException and VirtualMemory. If #1254 lands first, NoteAddressWrites can go: its RecordPendingWrites already records the tick of address writes.

AI use

I used Claude Code (AI agent) to profile the GPU thread, write the changes and the tests, and run the tests and game runs above on my machine. I reviewed the code and the results.

**@⁠NeySlim** on GitHub · 2026-10-22 11:54 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1828) `NeySlim:perf/srt-pending-reads` → `main` · +1773 −53 · 18 files · 6 commits · open Stacked on #1456 (SRT read tables) and #1821 (unknown lists). The first three commits of this branch are those PRs; the three after them are this PR. Tested in God of War Ragnarök (PPSA08332, 05.005). ## Problem In the opening cutscene the GPU command thread, which is the limit in this game, waits 8.6-9.1 ms per frame for SRT reads of memory with pending GPU writes. Each wait submits the open command buffer and waits for the queue. Two cases wait for the same GPU work, and fixing only one moves the whole wait to the other: 1. Walker reads beside GPU writes (7.2-8.2 ms per frame). A page with a pending GPU buffer write anywhere on it is read-protected. The CPU writes SRT tables right after the range a particle compute shader writes, in the same 4 KiB page, and the walker reads 128-192 bytes past that range, so every read faults and downloads the page. The same applies to the whole-plan walker of main: in a Demon's Souls scene measured on #1456, about 5% of its read faults were on pages protected for other bytes (the other 95% read GPU-written bytes, which still need the download). 2. Block conditions on GPU-written words (the remaining 0.7-1.2 ms, 8.1-8.7 ms once case 1 is fixed). Two compute shaders (`e33fa61895d03733`, `2567fe9c6381d11e`) branch on bit 2 of a word (`s_buffer_load_dword` at `index * 0xa0 + 0x8c`, `s_bitcmp1_b32`, `s_cbranch_vccnz`) that an earlier dispatch in the same command buffer writes. The shader reads the word itself on the GPU; the host only evaluates the condition to prune the descriptor sources of the branch not taken, and waits for the word to do so. ## Change - `shader: read SRT words beside GPU writes without a flush`: guest loads of the SRT walker go through a guarded load, a small routine with a single guest load whose read fault the handler resumes at a failure exit (`SetInstructionPointer`) instead of downloading the page. The read tables of #1456 and interpreted ordinary reads use it; the whole-plan walker of main records the offsets of its own loads and shares the same exit. The walker then reads that DWORD with `TryReadProtectedBacking`: straight from the backing, or after a download (waiting as before) when its bytes are in the GPU-written ranges or a shader with address writes, which have no tracked range, is still in flight. The page stays protected. - `shader: follow both edges of conditions on pending GPU writes`: block conditions are evaluated with a reader that fails instead of waiting when the word has pending GPU writes (`TryReadSettledBufferBacking`). A condition that cannot be read follows both edges, which is what the walker already does for a condition it cannot evaluate: the host binds the sources of both branches and the shader picks its branch on the GPU. If that larger set does not materialize, `MaterializeResources` tries again with the waiting reader. - `shader: keep SRT unknowns that read no pending word`: a value that is unknown only because a read did not wait must not stay memoized, or a later waiting read would see it as unknown. A failure counter shared by the session tells which unknowns depend on such a read; only those are marked apart and reset after the condition, also when the condition itself is known. Other unknowns keep main's memo for the session. ## Test - `TestCompiledSrtLoadsFromProtectedPage`: SRT tables on a page made unreadable, with a block plan, the same plan interpreted, and a tree plan. Values, captured reads and descriptors match an unprotected run, and no fault falls back to unprotecting the page. Fails when faults of guarded loads are not resumed, when the read table loads without the guard, or when a faulting read keeps its captured address. - `CheckProtectedSrtRead` (GPU, also `--protected-srt-read-only`): a word beside a pending GPU write is read without a download, a GPU-written word is downloaded, and address writes in flight make the read wait. Fails if the reader always downloads, or ignores address writes. - `TestPendingConditionFollowsBothEdges`: branch on a memory word, source in the branch or after the join, word pending or not, branch slot failing or not; checks the reader used, visited blocks, flat SRT, bound sources, captured reads and the retry. Fails if conditions wait. - `TestNoWaitUnknownsKeepTheirMemo`: an unknown that read no pending word keeps its memo, one that read a pending word is reset, also inside a known condition (`a || b` with `a` pending). Fails without the last commit. Without their source changes the tests of the first two commits do not compile. ## Validation Linux, Radeon 8060S (RDNA 3.5), Mesa RADV 26.2.5. - ctest: same failures as main. `shader_recompiler_compute_tests` one case per process: same results as main plus the new case (784 of 848 pass, main 783 of 847). - clang-format of the changed lines: clean. - God of War Ragnarök, on top of my other open PRs (main alone does not get in game), with an earlier version of these commits: walker fault waits 7.2-8.2 -> 0 ms per frame, condition waits -> 0, cutscene 19.2-19.3 -> 20.2-20.3 fps (paired +0.9). The first change alone gains nothing, the wait moves to the conditions. No errors, same rendering in the cutscene and the Freya fight. - The last commit, measured on the same stack with #1821, against a version that reset every unknown of a condition evaluated without waiting (about 275 k evaluations again per frame): cutscene 19.7 -> 20.5 fps, sled 17.3 -> 18.1, GPU command thread -1.9 / -2.8 ms per frame. A paired check in game (old and new protocol on the same materialization) found no difference in 45 M materializations. Not tested on Windows. `SetInstructionPointer` sets `CONTEXT::Rip` there (`__ss.__rip` on macOS), and the CPU tests only use `HostException` and `VirtualMemory`. If #1254 lands first, `NoteAddressWrites` can go: its `RecordPendingWrites` already records the tick of address writes. ## AI use I used Claude Code (AI agent) to profile the GPU thread, write the changes and the tests, and run the tests and game runs above on my machine. I reviewed the code and the results.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:06:42 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-22 12:02 UTC · original · edited 2026-10-23 17:40 UTC

Review in Change Stack →

📝 Walkthrough

The SRT walker now compiles eligible scalar and descriptor reads and supports non-waiting condition evaluation. GPU backing readers account for dirty ranges and in-flight shader address writes. Protected-load faults can resume at a generated failure exit. New tests cover compiled reads, conditional traversal, protected pages, and pending GPU writes.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Refactor

Merge Risk: 🟡 Moderate · up to 8e191

Protected SRT reads can observe stale backing, and a pending branch can abort binding setup. Resolve these paths before merging unless their impact is explicitly accepted.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 17.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 86 functions across 16 files. (2 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description clearly explains the SRT read optimization, protected backing reads, pending-condition handling, unknown memoization, tests, and validation results.
Title check Passed The title clearly and concisely describes the main change: reading SRT words adjacent to pending GPU writes without waiting.
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 17.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 86 functions across 16 files. (2 skipped: 1 unsupported, 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-22 12:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1828#issuecomment-6340253357) · edited 2026-10-23 17:40 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/1828?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 --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The SRT walker now compiles eligible scalar and descriptor reads and supports non-waiting condition evaluation. GPU backing readers account for dirty ranges and in-flight shader address writes. Protected-load faults can resume at a generated failure exit. New tests cover compiled reads, conditional traversal, protected pages, and pending GPU writes. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"8e19144b970ee680e0c028cce9a6ace4112b94d7" --> **Change:** Refactor <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>🟡 Moderate</strong> · up to <code>8e191</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🟡 Moderate** · up to `8e191` --> <!-- final_review_risk_coverage:{"sourceCommitId":"8e19144b970ee680e0c028cce9a6ace4112b94d7","coveredCommitId":"8e19144b970ee680e0c028cce9a6ace4112b94d7","kind":"reviewed"} --> Protected SRT reads can observe stale backing, and a pending branch can abort binding setup. Resolve these paths before merging unless their impact is explicitly accepted. <!-- 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 17.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 86 functions across 16 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 | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description clearly explains the SRT read optimization, protected backing reads, pending-condition handling, unknown memoization, tests, and validation results. | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: reading SRT words adjacent to pending GPU writes without waiting. | | 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 17.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 86 functions across 16 files. (2 skipped: 1 unsupported, 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">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=1828)! 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 -->
@ -874,0 +879,4 @@
auto& buffers = GetGpuResources().GetBufferCache();
// Shader address writes are not tracked by range: they may change any byte.
if (buffers.HasGpuDirtyBytes(vaddr, size) || buffers.HasAddressWritesInFlight()) {
buffers.ReadMemory(vaddr, size);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-22 12:02 UTC · original · edited 2026-10-23 17:42 UTC

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Wait for shader address writes before reading protected backing.

If an address write is in flight but the requested bytes have no dirty range, ReadMemory finds no download copies and returns before its scheduler wait. TryReadProtectedBacking then reads backing that the pending write can change. Wait for the address-write tick and ensure affected buffer bytes reach backing before returning them. A wait alone does not supply the missing readback.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-22 12:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1828#discussion_r4348058727) · edited 2026-10-23 17:42 UTC <!-- coderabbit-ai-generated:v1 --> **🗄️ Data Integrity & Integration** | **🟠 Major** | **🏗️ Heavy lift** **Wait for shader address writes before reading protected backing.** If an address write is in flight but the requested bytes have no dirty range, `ReadMemory` finds no download copies and returns before its scheduler wait. `TryReadProtectedBacking` then reads backing that the pending write can change. Wait for the address-write tick and ensure affected buffer bytes reach backing before returning them. A wait alone does not supply the missing readback. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:9f8f796c8a0cae1b30a33a72 --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-22 12:02 UTC · original · edited 2026-10-23 17:43 UTC
On src/kernel/memory.cpp line 890 (outdated):

@@ -871,6 +871,28 @@ bool TryReadBufferBacking(uint64_t vaddr, void* data, uint64_t size) {
 	return TryReadBacking(vaddr, data, size);
 }
 
+bool TryReadProtectedBacking(uint64_t vaddr, void* data, uint64_t size) {
+	if (g_gpu_resources == nullptr || !IsGpuAddressRange(vaddr, size) ||
+	    !Graphics::GuestGpu::IsGpuThread()) {
+		return false;
+	}
+	auto& buffers = GetGpuResources().GetBufferCache();
+	// Shader address writes are not tracked by range: they may change any byte.
+	if (buffers.HasGpuDirtyBytes(vaddr, size) || buffers.HasAddressWritesInFlight()) {
+		buffers.ReadMemory(vaddr, size);
+	}
+	return TryReadBacking(vaddr, data, size);
+}
+
+bool TryReadSettledBufferBacking(uint64_t vaddr, void* data, uint64_t size) {
+	if (g_gpu_resources != nullptr && IsGpuAddressRange(vaddr, size) &&
+	    (!Graphics::GuestGpu::IsGpuThread() ||
+	     GetGpuResources().GetBufferCache().HasGpuDirtyBytes(vaddr, size))) {

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reject non-waiting reads while address writes are in flight.

If a shader address write targets a mapped SRT value, it leaves no dirty range. This check then accepts the backing read while that write is pending, so a condition can use the old value instead of taking the non-waiting fallback. Include HasAddressWritesInFlight() in the rejection check.

✅ Confirmed as addressed by @⁠NeySlim

**@⁠coderabbitai[bot]** on GitHub · 2026-10-22 12:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1828#discussion_r4348058741) · edited 2026-10-23 17:43 UTC On `src/kernel/memory.cpp` line 890 (outdated): ```diff @@ -871,6 +871,28 @@ bool TryReadBufferBacking(uint64_t vaddr, void* data, uint64_t size) { return TryReadBacking(vaddr, data, size); } +bool TryReadProtectedBacking(uint64_t vaddr, void* data, uint64_t size) { + if (g_gpu_resources == nullptr || !IsGpuAddressRange(vaddr, size) || + !Graphics::GuestGpu::IsGpuThread()) { + return false; + } + auto& buffers = GetGpuResources().GetBufferCache(); + // Shader address writes are not tracked by range: they may change any byte. + if (buffers.HasGpuDirtyBytes(vaddr, size) || buffers.HasAddressWritesInFlight()) { + buffers.ReadMemory(vaddr, size); + } + return TryReadBacking(vaddr, data, size); +} + +bool TryReadSettledBufferBacking(uint64_t vaddr, void* data, uint64_t size) { + if (g_gpu_resources != nullptr && IsGpuAddressRange(vaddr, size) && + (!Graphics::GuestGpu::IsGpuThread() || + GetGpuResources().GetBufferCache().HasGpuDirtyBytes(vaddr, size))) { ``` <!-- coderabbit-ai-generated:v1 --> **🎯 Functional Correctness** | **🟠 Major** | **⚡ Quick win** **Reject non-waiting reads while address writes are in flight.** If a shader address write targets a mapped SRT value, it leaves no dirty range. This check then accepts the backing read while that write is pending, so a condition can use the old value instead of taking the non-waiting fallback. Include `HasAddressWritesInFlight()` in the rejection check. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:82873e6c00636be2734a05e5 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Confirmed as addressed by @⁠NeySlim <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between c5016d9455 and 32fb5cf9dd0dfaa3b644dea15ca5329de1610939.

📒 Files selected for processing: 18
  • CMakeLists.txt
  • src/common/hostException.cpp
  • src/common/hostException.h
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
  • src/graphics/host_gpu/renderer/renderContext.cpp
  • src/graphics/host_gpu/renderer/renderContext.h
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
  • src/graphics/shader/recompiler/ir/passes/SrtWalker.h
  • src/kernel/memory.cpp
  • src/kernel/memory.h
  • src/loader/runtimeLinker.cpp
  • tests/ResourceMaterializationTests.cpp
  • tests/ShaderRecompilerComputeTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-22 12:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1828#pullrequestreview-5613815889) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 2** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **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/c5016d9455fe52bdd090cef7d80beb15fad6a3a5/.coderabbit.yaml>) - **Commit**: [c5016d9](<https://github.com/KytyPS5/KytyPS5/commit/c5016d9455fe52bdd090cef7d80beb15fad6a3a5>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `fdcfd2af-1f0c-4a9b-a882-167032c06cb9` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between c5016d9455fe52bdd090cef7d80beb15fad6a3a5 and 32fb5cf9dd0dfaa3b644dea15ca5329de1610939. </details> <details> <summary>📒 Files selected for processing: 18</summary> * `CMakeLists.txt` * `src/common/hostException.cpp` * `src/common/hostException.h` * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp` * `src/graphics/host_gpu/renderer/renderContext.cpp` * `src/graphics/host_gpu/renderer/renderContext.h` * `src/graphics/shader/recompiler/ir/ShaderIR.h` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp` * `src/graphics/shader/recompiler/ir/passes/SrtWalker.h` * `src/kernel/memory.cpp` * `src/kernel/memory.h` * `src/loader/runtimeLinker.cpp` * `tests/ResourceMaterializationTests.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </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. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=c78f8df3-1d1e-4057-bb3d-0056ba68b146 attempt=d312d464-b585-4709-8cec-84f38f7354ac batch=1/1 -->
@ -874,0 +879,4 @@
auto& buffers = GetGpuResources().GetBufferCache();
// Shader address writes are not tracked by range: they may change any byte.
if (buffers.HasGpuDirtyBytes(vaddr, size) || buffers.HasAddressWritesInFlight()) {
buffers.ReadMemory(vaddr, size);
Author
Owner

@⁠NeySlim on GitHub · 2026-10-23 17:34 UTC · original

This matches the regular fault path: a read fault on a protected page calls the same ReadMemory and then reads backing. Address writes are not downloaded anywhere today since they leave no dirty range, so waiting here would not bring their bytes back either. Making them visible to the CPU is a separate change from this PR.

**@⁠NeySlim** on GitHub · 2026-10-23 17:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1828#discussion_r4362453090) This matches the regular fault path: a read fault on a protected page calls the same `ReadMemory` and then reads backing. Address writes are not downloaded anywhere today since they leave no dirty range, so waiting here would not bring their bytes back either. Making them visible to the CPU is a separate change from this PR.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-23 17:34 UTC · original
On src/kernel/memory.cpp line 890 (outdated):

@@ -871,6 +871,28 @@ bool TryReadBufferBacking(uint64_t vaddr, void* data, uint64_t size) {
 	return TryReadBacking(vaddr, data, size);
 }
 
+bool TryReadProtectedBacking(uint64_t vaddr, void* data, uint64_t size) {
+	if (g_gpu_resources == nullptr || !IsGpuAddressRange(vaddr, size) ||
+	    !Graphics::GuestGpu::IsGpuThread()) {
+		return false;
+	}
+	auto& buffers = GetGpuResources().GetBufferCache();
+	// Shader address writes are not tracked by range: they may change any byte.
+	if (buffers.HasGpuDirtyBytes(vaddr, size) || buffers.HasAddressWritesInFlight()) {
+		buffers.ReadMemory(vaddr, size);
+	}
+	return TryReadBacking(vaddr, data, size);
+}
+
+bool TryReadSettledBufferBacking(uint64_t vaddr, void* data, uint64_t size) {
+	if (g_gpu_resources != nullptr && IsGpuAddressRange(vaddr, size) &&
+	    (!Graphics::GuestGpu::IsGpuThread() ||
+	     GetGpuResources().GetBufferCache().HasGpuDirtyBytes(vaddr, size))) {

Right, fixed: the settled reader now fails while address writes are in flight, so the condition falls back to the waiting read. Added checks for it in ProtectedSrtRead.

**@⁠NeySlim** on GitHub · 2026-10-23 17:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1828#discussion_r4362453375) On `src/kernel/memory.cpp` line 890 (outdated): ```diff @@ -871,6 +871,28 @@ bool TryReadBufferBacking(uint64_t vaddr, void* data, uint64_t size) { return TryReadBacking(vaddr, data, size); } +bool TryReadProtectedBacking(uint64_t vaddr, void* data, uint64_t size) { + if (g_gpu_resources == nullptr || !IsGpuAddressRange(vaddr, size) || + !Graphics::GuestGpu::IsGpuThread()) { + return false; + } + auto& buffers = GetGpuResources().GetBufferCache(); + // Shader address writes are not tracked by range: they may change any byte. + if (buffers.HasGpuDirtyBytes(vaddr, size) || buffers.HasAddressWritesInFlight()) { + buffers.ReadMemory(vaddr, size); + } + return TryReadBacking(vaddr, data, size); +} + +bool TryReadSettledBufferBacking(uint64_t vaddr, void* data, uint64_t size) { + if (g_gpu_resources != nullptr && IsGpuAddressRange(vaddr, size) && + (!Graphics::GuestGpu::IsGpuThread() || + GetGpuResources().GetBufferCache().HasGpuDirtyBytes(vaddr, size))) { ``` Right, fixed: the settled reader now fails while address writes are in flight, so the condition falls back to the waiting read. Added checks for it in `ProtectedSrtRead`.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-23 17:40 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 79c90a0eb85315f774f0132234380a02a794ae5d and 8e19144b97.

📒 Files selected for processing: 11
  • CMakeLists.txt
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
  • src/graphics/host_gpu/renderer/renderContext.cpp
  • src/graphics/host_gpu/renderer/renderContext.h
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • src/graphics/shader/recompiler/ir/passes/SrtWalker.h
  • src/kernel/memory.cpp
  • tests/ResourceMaterializationTests.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-23 17:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1828#pullrequestreview-5632201207) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **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/9dcff95e809ec43ba66f56648164070f4b16348f/.coderabbit.yaml>) - **Commit**: [9dcff95](<https://github.com/KytyPS5/KytyPS5/commit/9dcff95e809ec43ba66f56648164070f4b16348f>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `3f589e58-8c89-4799-a707-b91cd52f030f` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 79c90a0eb85315f774f0132234380a02a794ae5d and 8e19144b970ee680e0c028cce9a6ace4112b94d7. </details> <details> <summary>📒 Files selected for processing: 11</summary> * `CMakeLists.txt` * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp` * `src/graphics/host_gpu/renderer/renderContext.cpp` * `src/graphics/host_gpu/renderer/renderContext.h` * `src/graphics/shader/recompiler/ir/ShaderIR.h` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `src/graphics/shader/recompiler/ir/passes/SrtWalker.h` * `src/kernel/memory.cpp` * `tests/ResourceMaterializationTests.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=a1e8a4a4-3777-4d12-a01a-68ea72002b4d attempt=15c65f07-026e-46fa-8d90-85d1fe28524d batch=1/1 -->
@ -1569,2 +1571,4 @@
bool MaterializeResources(const ResourcePlan& program, const SrtRuntime& runtime,
ResourceSnapshot& snapshot, ResourceSpecialization& specialization) {
if (MaterializeOnce(program, runtime, snapshot, specialization)) return true;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-23 17:40 UTC · original

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Retry when speculative bindings fail the read/write overlap check.

If a pending condition follows both edges, one edge can capture a scalar read while the other binds a buffer write to the same range. MaterializeOnce can succeed, so this return skips the waiting retry. RenderExecutor::CommitBindings then calls EXIT on the overlap at src/graphics/host_gpu/renderer/pipeline/descriptors.cpp Lines 941-977, even when the actual branch uses only one edge. Check the speculative resource set before accepting it, and retry with the waiting reader when the extra edge causes this conflict.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-23 17:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1828#discussion_r4362501648) <!-- coderabbit-ai-generated:v1 --> **🩺 Stability & Availability** | **🟠 Major** | **🏗️ Heavy lift** **Retry when speculative bindings fail the read/write overlap check.** If a pending condition follows both edges, one edge can capture a scalar read while the other binds a buffer write to the same range. `MaterializeOnce` can succeed, so this return skips the waiting retry. `RenderExecutor::CommitBindings` then calls `EXIT` on the overlap at `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` Lines 941-977, even when the actual branch uses only one edge. Check the speculative resource set before accepting it, and retry with the waiting reader when the extra edge causes this conflict. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:d1ccae0f645a682b1b737813 --> <!-- This is an auto-generated comment by CodeRabbit -->
@ -874,0 +879,4 @@
auto& buffers = GetGpuResources().GetBufferCache();
// Shader address writes are not tracked by range: they may change any byte.
if (buffers.HasGpuDirtyBytes(vaddr, size) || buffers.HasAddressWritesInFlight()) {
buffers.ReadMemory(vaddr, size);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-23 17:42 UTC · original

@⁠NeySlim You're right. This path preserves the regular fault path’s behavior. My finding incorrectly treated the existing lack of address-write readback as a defect introduced by this PR. A wait alone would not make those bytes available in backing memory.

I withdraw this finding. CPU visibility for shader address writes belongs in a separate change. Would you like me to open a follow-up issue?

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-23 17:42 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1828#discussion_r4362521873) <!-- coderabbit-ai-generated:v1 --> @⁠NeySlim You're right. This path preserves the regular fault path’s behavior. My finding incorrectly treated the existing lack of address-write readback as a defect introduced by this PR. A wait alone would not make those bytes available in backing memory. I withdraw this finding. CPU visibility for shader address writes belongs in a separate change. Would you like me to open a follow-up issue? <!-- <review_comment_withdrawn> --> ✅ Review thread resolved. <sub><i>You are interacting with an AI system.</i></sub> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-23 17:43 UTC · original
On src/kernel/memory.cpp line 890 (outdated):

@@ -871,6 +871,28 @@ bool TryReadBufferBacking(uint64_t vaddr, void* data, uint64_t size) {
 	return TryReadBacking(vaddr, data, size);
 }
 
+bool TryReadProtectedBacking(uint64_t vaddr, void* data, uint64_t size) {
+	if (g_gpu_resources == nullptr || !IsGpuAddressRange(vaddr, size) ||
+	    !Graphics::GuestGpu::IsGpuThread()) {
+		return false;
+	}
+	auto& buffers = GetGpuResources().GetBufferCache();
+	// Shader address writes are not tracked by range: they may change any byte.
+	if (buffers.HasGpuDirtyBytes(vaddr, size) || buffers.HasAddressWritesInFlight()) {
+		buffers.ReadMemory(vaddr, size);
+	}
+	return TryReadBacking(vaddr, data, size);
+}
+
+bool TryReadSettledBufferBacking(uint64_t vaddr, void* data, uint64_t size) {
+	if (g_gpu_resources != nullptr && IsGpuAddressRange(vaddr, size) &&
+	    (!Graphics::GuestGpu::IsGpuThread() ||
+	     GetGpuResources().GetBufferCache().HasGpuDirtyBytes(vaddr, size))) {

@⁠NeySlim The updated TryReadSettledBufferBacking rejects reads when HasAddressWritesInFlight() is true. This addresses the stale backing-read concern. Thanks for adding the regression checks.


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

Thank you for using CodeRabbit!

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-23 17:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1828#discussion_r4362528420) On `src/kernel/memory.cpp` line 890 (outdated): ```diff @@ -871,6 +871,28 @@ bool TryReadBufferBacking(uint64_t vaddr, void* data, uint64_t size) { return TryReadBacking(vaddr, data, size); } +bool TryReadProtectedBacking(uint64_t vaddr, void* data, uint64_t size) { + if (g_gpu_resources == nullptr || !IsGpuAddressRange(vaddr, size) || + !Graphics::GuestGpu::IsGpuThread()) { + return false; + } + auto& buffers = GetGpuResources().GetBufferCache(); + // Shader address writes are not tracked by range: they may change any byte. + if (buffers.HasGpuDirtyBytes(vaddr, size) || buffers.HasAddressWritesInFlight()) { + buffers.ReadMemory(vaddr, size); + } + return TryReadBacking(vaddr, data, size); +} + +bool TryReadSettledBufferBacking(uint64_t vaddr, void* data, uint64_t size) { + if (g_gpu_resources != nullptr && IsGpuAddressRange(vaddr, size) && + (!Graphics::GuestGpu::IsGpuThread() || + GetGpuResources().GetBufferCache().HasGpuDirtyBytes(vaddr, size))) { ``` <!-- coderabbit-ai-generated:v1 --> @⁠NeySlim The updated `TryReadSettledBufferBacking` rejects reads when `HasAddressWritesInFlight()` is true. This addresses the stale backing-read concern. Thanks for adding the regression checks. --- <!-- 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=Reject%20non-waiting%20SRT%20reads%20while%20address%20writes%20are%20in%20flight%20to%20avoid%20stale%20values.%20%40coderabbitai%20caught%20the%20race%3B%20try%20it%20for%20sharper%20code%20reviews%20%F0%9F%94%8D%E2%9A%A1&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1828%23discussion_r4348058741)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. <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/common/hostException.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
  • src/graphics/shader/recompiler/ir/passes/SrtWalker.h
  • src/kernel/memory.cpp
  • src/kernel/memory.h
  • src/loader/runtimeLinker.cpp
  • tests/ResourceMaterializationTests.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/1828/head:github-bot/gh-1828'
git switch 'github-bot/gh-1828'

Merge

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