shader: no raw guest dereference in the SRT walker and the read capture #1102

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

@⁠wuboo on GitHub · 2026-10-06 07:34 UTC · original
wuboo:fix/srt-checked-reads → main · +139 −27 · 4 files · 5 commits · closed without merging

shader: no raw guest dereference in the SRT walker and the read capture

Problem

In the production configuration the pipeline cache builds SrtRuntime with only
read_specialization_memory = ReadShaderGuestMemory (a bounds-checked reader); read_memory is null.
Two places treated "no ordinary reader" as "the address can be dereferenced directly":

  • SrtWalker::EvaluateRawRead did memcpy from the guest address when neither reader was set.
  • CaptureOrdinaryRead (the read capture used while refreshing a plan with captured specialization reads)
    did memcpy from the guest address when read_memory was null. With the production runtime this path is
    always taken.

A scalar table the guest never set up (null or stale base, e.g. a DispatchIndirect shader whose
wave-dependent path is not executed) therefore faults the host in memmove instead of failing the refresh.
Seen with Astro Bot on macOS: host access violation at null+0x18 in CaptureOrdinaryRead.

Changes (3 commits)

  1. SrtWalker::EvaluateRawRead falls back to the checked specialization reader when no ordinary reader is
    set. RefreshFlatBuffer tolerates failed reads in blocks that were entered only because their branch
    condition could not be evaluated (the path is chosen per wave and may not run on the guest). Blocks
    reached through evaluated conditions must still resolve.
  2. No raw guest dereference is left: CaptureOrdinaryRead uses read_memory if set, otherwise the checked
    reader, otherwise the read fails; EvaluateRawRead likewise (vector reads and reads without any reader fail).
  3. Tests.

No behaviour change when an ordinary reader is supplied.

Tests

  • resource_materialization: mapped SRT reads go through the checked reader (read counter > 0); a null table
    is rejected by the checked reader; a read with no reader at all fails instead of faulting.
  • resource_tracking: the guarded scalar descriptor test runs with only the checked reader.
  • Both tests fail without the source changes (resource_materialization aborts, resource_tracking segfaults)
    and pass with them.
  • Full ctest on macOS (50 tests): identical to a fresh origin/main (cdb64bfd) build: 34 pass, 16 skipped
    (no Vulkan loader in the test environment), 0 failures.

Caveats

  • A refresh that used to fault now returns false, so callers that treat a failed MaterializeResources as
    fatal (EXIT_IF in ProgramCache::Get) report a materialization failure instead of a host fault.
  • Only the CPU tests were run for this branch; the GPU-dependent tests were skipped.
**@⁠wuboo** on GitHub · 2026-10-06 07:34 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1102) `wuboo:fix/srt-checked-reads` → `main` · +139 −27 · 4 files · 5 commits · closed without merging # shader: no raw guest dereference in the SRT walker and the read capture ## Problem In the production configuration the pipeline cache builds `SrtRuntime` with only `read_specialization_memory = ReadShaderGuestMemory` (a bounds-checked reader); `read_memory` is null. Two places treated "no ordinary reader" as "the address can be dereferenced directly": - `SrtWalker::EvaluateRawRead` did `memcpy` from the guest address when neither reader was set. - `CaptureOrdinaryRead` (the read capture used while refreshing a plan with captured specialization reads) did `memcpy` from the guest address when `read_memory` was null. With the production runtime this path is always taken. A scalar table the guest never set up (null or stale base, e.g. a DispatchIndirect shader whose wave-dependent path is not executed) therefore faults the host in `memmove` instead of failing the refresh. Seen with Astro Bot on macOS: host access violation at null+0x18 in `CaptureOrdinaryRead`. ## Changes (3 commits) 1. `SrtWalker::EvaluateRawRead` falls back to the checked specialization reader when no ordinary reader is set. `RefreshFlatBuffer` tolerates failed reads in blocks that were entered only because their branch condition could not be evaluated (the path is chosen per wave and may not run on the guest). Blocks reached through evaluated conditions must still resolve. 2. No raw guest dereference is left: `CaptureOrdinaryRead` uses `read_memory` if set, otherwise the checked reader, otherwise the read fails; `EvaluateRawRead` likewise (vector reads and reads without any reader fail). 3. Tests. No behaviour change when an ordinary reader is supplied. ## Tests - `resource_materialization`: mapped SRT reads go through the checked reader (read counter > 0); a null table is rejected by the checked reader; a read with no reader at all fails instead of faulting. - `resource_tracking`: the guarded scalar descriptor test runs with only the checked reader. - Both tests fail without the source changes (`resource_materialization` aborts, `resource_tracking` segfaults) and pass with them. - Full `ctest` on macOS (50 tests): identical to a fresh `origin/main` (cdb64bfd) build: 34 pass, 16 skipped (no Vulkan loader in the test environment), 0 failures. ## Caveats - A refresh that used to fault now returns false, so callers that treat a failed `MaterializeResources` as fatal (`EXIT_IF` in `ProgramCache::Get`) report a materialization failure instead of a host fault. - Only the CPU tests were run for this branch; the GPU-dependent tests were skipped.
Without an ordinary reader the walker dereferenced guest addresses directly, so a table
the guest never set (null base, e.g. a DispatchIndirect shader whose wave-dependent path
is not taken) faulted the host in memmove. Use the checked specialization reader when
present, and let reads fail without failing the refresh in blocks entered only because
their branch condition could not be evaluated. Reachable blocks still must resolve.
The read capture fell back to memcpy from the guest address when no ordinary reader
was set, and the walker did the same when no reader of either kind was set. Both now
use the checked specialization reader and fail the read otherwise, so a table the
guest never set can no longer fault the host. The guarded scalar descriptor test also
runs with only the checked reader.
A block that is certain to run and has one successor leaves nothing for the wave to
choose, so the successor must stay certain. It was marked speculative, which let a
failed SRT read there be ignored and the refresh report success with a zero slot.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:43:01 +00:00
github-bot closed this pull request 2026-11-26 09:43:01 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 07:43 UTC · original · edited 2026-10-06 08:14 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f567e6b5-43f8-4d71-a4ae-83a723a60fba
📥 Commits

Reviewing files that changed from the base of the PR and between 7e40b02c8f and eda7620666.

📒 Files selected for processing (2)
  • src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
  • tests/ResourceTrackingTests.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
  • tests/ResourceTrackingTests.cpp

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


📝 Walkthrough

Walkthrough

Resource materialization and raw SRT reads no longer dereference guest addresses when a checked reader is unavailable or fails. They use the specialization-memory reader when the ordinary reader is unavailable. Flat-buffer traversal tracks definite and speculative paths, and read failures abort refresh only on definite paths. Tests cover checked readers, failed reads, cache rematerialization, and traversal certainty.

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to eda76

The reviewed changes have no identified issue requiring a fix before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the change: preventing raw guest-memory dereferences in the SRT walker and read capture.
Description check ✅ Passed The description explains the guest-memory read problem, the changes to reader fallback and speculative control flow, and the tests performed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

❤️ Share

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 07:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1102#issuecomment-6011737856) · edited 2026-10-06 08:14 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1102?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `f567e6b5-43f8-4d71-a4ae-83a723a60fba` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 7e40b02c8f26599f77660a31b2749c2e55d1c937 and eda7620666c4d1dfb9f5cb84cc1621f0e478db9d. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp` * `tests/ResourceTrackingTests.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (2)</summary> * src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp * tests/ResourceTrackingTests.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> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough Resource materialization and raw SRT reads no longer dereference guest addresses when a checked reader is unavailable or fails. They use the specialization-memory reader when the ordinary reader is unavailable. Flat-buffer traversal tracks definite and speculative paths, and read failures abort refresh only on definite paths. Tests cover checked readers, failed reads, cache rematerialization, and traversal certainty. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"eda7620666c4d1dfb9f5cb84cc1621f0e478db9d" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `eda76` <!-- final_review_risk_coverage:{"sourceCommitId":"eda7620666c4d1dfb9f5cb84cc1621f0e478db9d","coveredCommitId":"eda7620666c4d1dfb9f5cb84cc1621f0e478db9d","kind":"reviewed"} --> The reviewed changes have no identified issue requiring a fix before merge. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 4 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly identifies the change: preventing raw guest-memory dereferences in the SRT walker and read capture. | | Description check | ✅ Passed | The description explains the guest-memory read problem, the changes to reader fallback and speculative control flow, and the tests performed. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1102)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 07:43 UTC · original · edited 2026-10-06 08:04 UTC
On src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp line 990 (outdated):

@@ -955,28 +959,35 @@ bool SrtWalker::RefreshFlatBuffer(std::vector<uint32_t>& flat) {
 	for (const auto& block: m_program.control_flow) {
 		for (const auto source: block.sources) active.at(source) = 0u;
 	}
+	// Blocks entered only because their branch condition could not be evaluated may not run on
+	// the guest at all (the path is chosen per wave), so their reads may legitimately fail.
+	constexpr uint32_t Speculative = 0x80000000u;
 	auto& visited = m_program.visited_blocks;
 	auto& pending = m_program.pending_blocks;
 	visited.assign(m_program.control_flow.size(), 0u);
 	pending.clear();
 	pending.push_back(0u);
 	while (!pending.empty()) {
-		const auto index = pending.back();
+		const auto entry       = pending.back();
+		const auto index       = entry & ~Speculative;
+		const bool speculative = (entry & Speculative) != 0u;
 		pending.pop_back();
-		if (visited.at(index)) continue;
-		visited[index] = 1u;
+		const uint8_t level = speculative ? 1u : 2u;
+		if (visited.at(index) >= level) continue;
+		visited[index] = level;
 		const auto& block = m_program.control_flow[index];
 		for (const auto source: block.sources) active[source] = 1u;
 		for (const auto slot: block.srt_reads) {
-			if (!refresh(slot)) return false;
+			if (!refresh(slot) && !speculative) return false;
 		}
 		uint32_t condition = 0;
 		auto& predicate = m_clean_evaluator != nullptr ? *m_clean_evaluator : *this;
 		if (!block.condition.IsEmpty() && m_runtime.read_specialization_memory != nullptr &&
 		    predicate.Evaluate(block.condition, condition)) {
-			pending.push_back(block.successors[condition != 0u ? 0u : 1u]);
+			pending.push_back(block.successors[condition != 0u ? 0u : 1u] |
+			                  (speculative ? Speculative : 0u));
 		} else {
-			pending.insert(pending.end(), block.successors.begin(), block.successors.end());
+			for (const auto successor: block.successors) pending.push_back(successor | Speculative);

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep single-successor edges definite.

If a definite block has one successor, this line marks that mandatory successor speculative. A failed SRT read in the successor is then ignored, and RefreshFlatBuffer can return success with a zero flattened slot. Propagate the current certainty when there is only one successor. Mark successors speculative only when selection is unresolved.


🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '940,1000p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
rg -n 'read_specialization_memory' src | head -50

Repository: KytyPS5/KytyPS5

Length of output: 4865


🏁 Script executed:

printf '%s\n' '--- evaluator and condition types ---'
sed -n '1,90p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
sed -n '470,550p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
sed -n '900,1000p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
printf '%s\n' '--- declarations and direct RefreshFlatBuffer callers ---'
rg -n -F 'RefreshFlatBuffer' src/graphics/shader/recompiler
rg -n -F 'SrtRuntime' src/graphics/shader/recompiler/ir/passes
sed -n '1,90p' src/graphics/shader/recompiler/ir/passes/SrtWalker.h
printf '%s\n' '--- runtime setup and materialization reachability ---'
sed -n '270,325p' src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
sed -n '1010,1070p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
printf '%s\n' '--- base version of affected traversal ---'
git show cdb64bfd4fb4d5312b2542a41a0070f25663166a:src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '910,1000p'
printf '%s\n' '--- base evaluator implementation ---'
git show cdb64bfd4fb4d5312b2542a41a0070f25663166a:src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '470,545p'

Repository: KytyPS5/KytyPS5

Length of output: 25282


🏁 Script executed:

printf '%s\n' '--- relevant plan flags and assignments ---'
rg -n 'requires_specialization_memory|capture_specialization_reads|control_flow' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp src/graphics/shader/recompiler/ir/ShaderIR.h
printf '%s\n' '--- condition evaluation ---'
rg -n 'GetUserData|bool SrtWalker::Arg|bool SrtWalker::Evaluate\\(' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
sed -n '340,405p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
sed -n '560,625p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
printf '%s\n' '--- complete MaterializeResources entry and callers ---'
rg -n 'MaterializeResources\\(' src
sed -n '1035,1095p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
printf '%s\n' '--- control-flow construction ---'
rg -n 'ResourceControlFlow|ControlFlowBlock|\\.condition\\s*=|condition =' src/graphics/shader/recompiler/ir/passes src/graphics/shader/recompiler/ir

Repository: KytyPS5/KytyPS5

Length of output: 12239


🏁 Script executed:

printf '%s\n' '--- in-repository materialization callers ---'
rg -n -F 'MaterializeResources(' src
printf '%s\n' '--- plan construction flags and control flow ---'
sed -n '900,1032p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
sed -n '640,730p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
printf '%s\n' '--- materialization reader capture callbacks ---'
sed -n '130,180p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
printf '%s\n' '--- user-data evaluator ---'
rg -n -F 'case ValueOpcode::GetUserData' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
sed -n '385,435p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
printf '%s\n' '--- public declaration ---'
sed -n '35,55p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.h

Repository: KytyPS5/KytyPS5

Length of output: 14958


🏁 Script executed:

printf '%s\n' '--- GetUserData evaluator ---'
sed -n '540,575p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
printf '%s\n' '--- renderer runtime and both calls ---'
sed -n '295,320p' src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
sed -n '355,385p' src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp

Repository: KytyPS5/KytyPS5

Length of output: 4721


🏁 Script executed:

printf '%s\n' '--- runtime validator declaration and relevant opcode handling ---'
rg -n -F 'class RuntimeValidator' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
rg -n -F 'GetUserData' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
rg -n -F 'RuntimeValueType::Integer' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp

Repository: KytyPS5/KytyPS5

Length of output: 685


🏁 Script executed:

sed -n '140,275p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp

Repository: KytyPS5/KytyPS5

Length of output: 5094


🏁 Script executed:

printf '%s\n' '--- remaining runtime validator rules ---'
sed -n '255,345p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
printf '%s\n' '--- predicate operator handling in evaluator ---'
rg -n -F 'case ValueOpcode::LogicalAnd' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
rg -n -F 'case ValueOpcode::ICompare' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp

Repository: KytyPS5/KytyPS5

Length of output: 3823


Evaluate predicates that do not need specialization memory.

MaterializeResources accepts a runtime with read_memory but no specialization reader when the plan does not otherwise require specialization memory. The current renderer call sites supply ReadShaderGuestMemory. For a reader-only runtime, RefreshFlatBuffer skips a resolvable user-data predicate and marks both successors speculative. A failed ordinary read on the selected successor can then be ignored, leaving its flattened slot at zero while refresh succeeds. Evaluate the predicate through the clean evaluator; it can resolve user-data-only conditions and rejects memory reads when no checked reader is available.

🐛 Suggested fix
-		if (!block.condition.IsEmpty() && m_runtime.read_specialization_memory != nullptr &&
+		if (!block.condition.IsEmpty() &&
		    predicate.Evaluate(block.condition, condition)) {

✅ Addressed in commits 0e4a876 to eda7620

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 07:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1102#discussion_r4192767097) · edited 2026-10-06 08:04 UTC On `src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp` line 990 (outdated): ```diff @@ -955,28 +959,35 @@ bool SrtWalker::RefreshFlatBuffer(std::vector<uint32_t>& flat) { for (const auto& block: m_program.control_flow) { for (const auto source: block.sources) active.at(source) = 0u; } + // Blocks entered only because their branch condition could not be evaluated may not run on + // the guest at all (the path is chosen per wave), so their reads may legitimately fail. + constexpr uint32_t Speculative = 0x80000000u; auto& visited = m_program.visited_blocks; auto& pending = m_program.pending_blocks; visited.assign(m_program.control_flow.size(), 0u); pending.clear(); pending.push_back(0u); while (!pending.empty()) { - const auto index = pending.back(); + const auto entry = pending.back(); + const auto index = entry & ~Speculative; + const bool speculative = (entry & Speculative) != 0u; pending.pop_back(); - if (visited.at(index)) continue; - visited[index] = 1u; + const uint8_t level = speculative ? 1u : 2u; + if (visited.at(index) >= level) continue; + visited[index] = level; const auto& block = m_program.control_flow[index]; for (const auto source: block.sources) active[source] = 1u; for (const auto slot: block.srt_reads) { - if (!refresh(slot)) return false; + if (!refresh(slot) && !speculative) return false; } uint32_t condition = 0; auto& predicate = m_clean_evaluator != nullptr ? *m_clean_evaluator : *this; if (!block.condition.IsEmpty() && m_runtime.read_specialization_memory != nullptr && predicate.Evaluate(block.condition, condition)) { - pending.push_back(block.successors[condition != 0u ? 0u : 1u]); + pending.push_back(block.successors[condition != 0u ? 0u : 1u] | + (speculative ? Speculative : 0u)); } else { - pending.insert(pending.end(), block.successors.begin(), block.successors.end()); + for (const auto successor: block.successors) pending.push_back(successor | Speculative); ``` **🎯 Functional Correctness** | **🟠 Major** | **⚡ Quick win** **Keep single-successor edges definite.** If a definite block has one successor, this line marks that mandatory successor speculative. A failed SRT read in the successor is then ignored, and `RefreshFlatBuffer` can return success with a zero flattened slot. Propagate the current certainty when there is only one successor. Mark successors speculative only when selection is unresolved. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:e99caf95c7ffcfc0dcbb6d26 --> --- **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '940,1000p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp rg -n 'read_specialization_memory' src | head -50 ``` Repository: KytyPS5/KytyPS5 Length of output: 4865 --- 🏁 Script executed: ```bash printf '%s\n' '--- evaluator and condition types ---' sed -n '1,90p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp sed -n '470,550p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp sed -n '900,1000p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp printf '%s\n' '--- declarations and direct RefreshFlatBuffer callers ---' rg -n -F 'RefreshFlatBuffer' src/graphics/shader/recompiler rg -n -F 'SrtRuntime' src/graphics/shader/recompiler/ir/passes sed -n '1,90p' src/graphics/shader/recompiler/ir/passes/SrtWalker.h printf '%s\n' '--- runtime setup and materialization reachability ---' sed -n '270,325p' src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp sed -n '1010,1070p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp printf '%s\n' '--- base version of affected traversal ---' git show cdb64bfd4fb4d5312b2542a41a0070f25663166a:src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '910,1000p' printf '%s\n' '--- base evaluator implementation ---' git show cdb64bfd4fb4d5312b2542a41a0070f25663166a:src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp | sed -n '470,545p' ``` Repository: KytyPS5/KytyPS5 Length of output: 25282 --- 🏁 Script executed: ```bash printf '%s\n' '--- relevant plan flags and assignments ---' rg -n 'requires_specialization_memory|capture_specialization_reads|control_flow' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp src/graphics/shader/recompiler/ir/ShaderIR.h printf '%s\n' '--- condition evaluation ---' rg -n 'GetUserData|bool SrtWalker::Arg|bool SrtWalker::Evaluate\\(' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp sed -n '340,405p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp sed -n '560,625p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp printf '%s\n' '--- complete MaterializeResources entry and callers ---' rg -n 'MaterializeResources\\(' src sed -n '1035,1095p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp printf '%s\n' '--- control-flow construction ---' rg -n 'ResourceControlFlow|ControlFlowBlock|\\.condition\\s*=|condition =' src/graphics/shader/recompiler/ir/passes src/graphics/shader/recompiler/ir ``` Repository: KytyPS5/KytyPS5 Length of output: 12239 --- 🏁 Script executed: ```bash printf '%s\n' '--- in-repository materialization callers ---' rg -n -F 'MaterializeResources(' src printf '%s\n' '--- plan construction flags and control flow ---' sed -n '900,1032p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp sed -n '640,730p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp printf '%s\n' '--- materialization reader capture callbacks ---' sed -n '130,180p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp printf '%s\n' '--- user-data evaluator ---' rg -n -F 'case ValueOpcode::GetUserData' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp sed -n '385,435p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp printf '%s\n' '--- public declaration ---' sed -n '35,55p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.h ``` Repository: KytyPS5/KytyPS5 Length of output: 14958 --- 🏁 Script executed: ```bash printf '%s\n' '--- GetUserData evaluator ---' sed -n '540,575p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp printf '%s\n' '--- renderer runtime and both calls ---' sed -n '295,320p' src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp sed -n '355,385p' src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 4721 --- 🏁 Script executed: ```bash printf '%s\n' '--- runtime validator declaration and relevant opcode handling ---' rg -n -F 'class RuntimeValidator' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp rg -n -F 'GetUserData' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp rg -n -F 'RuntimeValueType::Integer' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 685 --- 🏁 Script executed: ```bash sed -n '140,275p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 5094 --- 🏁 Script executed: ```bash printf '%s\n' '--- remaining runtime validator rules ---' sed -n '255,345p' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp printf '%s\n' '--- predicate operator handling in evaluator ---' rg -n -F 'case ValueOpcode::LogicalAnd' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp rg -n -F 'case ValueOpcode::ICompare' src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 3823 --- </details> **Evaluate predicates that do not need specialization memory.** `MaterializeResources` accepts a runtime with `read_memory` but no specialization reader when the plan does not otherwise require specialization memory. The current renderer call sites supply `ReadShaderGuestMemory`. For a reader-only runtime, `RefreshFlatBuffer` skips a resolvable user-data predicate and marks both successors speculative. A failed ordinary read on the selected successor can then be ignored, leaving its flattened slot at zero while refresh succeeds. Evaluate the predicate through the clean evaluator; it can resolve user-data-only conditions and rejects memory reads when no checked reader is available. <details> <summary>🐛 Suggested fix</summary> ```diff - if (!block.condition.IsEmpty() && m_runtime.read_specialization_memory != nullptr && + if (!block.condition.IsEmpty() && predicate.Evaluate(block.condition, condition)) { ``` </details> <!-- fingerprinting:phantom:medusa:pangolin --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:66c30b2a7ff418277aa24563 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commits 0e4a876 to eda7620
Author
Owner

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1e67a0b0-f49e-4358-8019-3642e40a77fe
📥 Commits

Reviewing files that changed from the base of the PR and between cdb64bfd4f and 7e40b02c8f.

📒 Files selected for processing (4)
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp
  • tests/ResourceMaterializationTests.cpp
  • tests/ResourceTrackingTests.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-06 07:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1102#pullrequestreview-5425287502) · **reviewed** **Actionable comments posted: 2** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `1e67a0b0-f49e-4358-8019-3642e40a77fe` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between cdb64bfd4fb4d5312b2542a41a0070f25663166a and 7e40b02c8f26599f77660a31b2749c2e55d1c937. </details> <details> <summary>📒 Files selected for processing (4)</summary> * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp` * `tests/ResourceMaterializationTests.cpp` * `tests/ResourceTrackingTests.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=71c2b41f-c5c0-4497-96c8-4c9d4907993e attempt=fc8c6fe9-eae2-48f4-bb90-700a03ddae40 batch=1/1 -->
Author
Owner

@⁠wuboo on GitHub · 2026-10-06 08:04 UTC · original

Single-successor edges (Major): Fixed in 0e4a876a — a block that is certain to run now passes that certainty to its only successor, so a failed SRT read there fails the refresh. Speculative is kept only for undecided branches (two or more successors). Regression test in eda76206 (fails on the previous code).

"Evaluate predicates that do not need specialization memory" (Minor): I'd rather leave this out of this PR. Predicates are evaluated only when specialization memory is available, exactly as before the PR, and changing that alters which blocks count as certain for existing shaders. It is a behavior change independent of the checked-read work, so it fits better in a separate PR with its own test.

**@⁠wuboo** on GitHub · 2026-10-06 08:04 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1102#issuecomment-6012055568) **Single-successor edges (Major):** Fixed in 0e4a876a — a block that is certain to run now passes that certainty to its only successor, so a failed SRT read there fails the refresh. Speculative is kept only for undecided branches (two or more successors). Regression test in eda76206 (fails on the previous code). **"Evaluate predicates that do not need specialization memory" (Minor):** I'd rather leave this out of this PR. Predicates are evaluated only when specialization memory is available, exactly as before the PR, and changing that alters which blocks count as certain for existing shaders. It is a behavior change independent of the checked-read work, so it fits better in a separate PR with its own test.

Pull request closed

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