renderer: tolerate stale descriptor-table slots #1119

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

@⁠NeySlim on GitHub · 2026-10-06 19:45 UTC · original
NeySlim:fix/stale-descriptor-slots → main · +92 −10 · 4 files · 3 commits · closed without merging

When an indirect image table is probed for its enumerated keys, slots past the table's live range hold stale or unrelated descriptors: the shader never selects them, but the host refused the table (indirect image table ... has incompatible candidates), failed to read their backing (BufferCache: failed to read mapped guest image backing) or aborted on the scalar-read overlap check.

This makes those slots harmless instead of fatal:

  • A probed candidate whose class, dimension, mip count, conversion or swizzle differs from the exemplar is bound as a null image (reported once per table).
  • A probed descriptor whose base address is unreadable, or that fails normalization, is bound as a null image.
  • An image larger than the staging ring is served from the buffer cache instead of being dropped (an unreadable backing is uploaded as zeros, as #937 also does).
  • The overlap between specialization reads and image writes is reported once instead of aborting.

These are tolerance changes for bring-up rather than fixes of the underlying planning; happy to narrow any of them. #852 extends the incompatible-candidate diagnostics and #937 carries the zero-fill of unreadable backings, so this overlaps them in those two spots. Seen with God of War Ragnarök (PPSA08332) on Linux, RTX 4090.

**@⁠NeySlim** on GitHub · 2026-10-06 19:45 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1119) `NeySlim:fix/stale-descriptor-slots` → `main` · +92 −10 · 4 files · 3 commits · closed without merging When an indirect image table is probed for its enumerated keys, slots past the table's live range hold stale or unrelated descriptors: the shader never selects them, but the host refused the table (`indirect image table ... has incompatible candidates`), failed to read their backing (`BufferCache: failed to read mapped guest image backing`) or aborted on the scalar-read overlap check. This makes those slots harmless instead of fatal: - A probed candidate whose class, dimension, mip count, conversion or swizzle differs from the exemplar is bound as a null image (reported once per table). - A probed descriptor whose base address is unreadable, or that fails normalization, is bound as a null image. - An image larger than the staging ring is served from the buffer cache instead of being dropped (an unreadable backing is uploaded as zeros, as #937 also does). - The overlap between specialization reads and image writes is reported once instead of aborting. These are tolerance changes for bring-up rather than fixes of the underlying planning; happy to narrow any of them. #852 extends the incompatible-candidate diagnostics and #937 carries the zero-fill of unreadable backings, so this overlaps them in those two spots. Seen with God of War Ragnarök (PPSA08332) on Linux, RTX 4090.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:43:53 +00:00
github-bot closed this pull request 2026-11-26 09:43:53 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 19:49 UTC · original · edited 2026-10-06 20:01 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: bd864c9e-207c-4b5b-9cff-d796b09544e2
📥 Commits

Reviewing files that changed from the base of the PR and between 028d8c9489 and e1fc0550f1.

📒 Files selected for processing (2)
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp

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


📝 Walkthrough

Walkthrough

Image buffer acquisition uses a temporary upload buffer when staging allocation fails. If sparse backing cannot be read, the upload range is zero-filled. Image initialization skips upload when no source is available. Descriptor binding logs scalar-read overlaps with bound image, attachment, or metadata writes and continues. Indirect image materialization replaces specified unreadable, unnormalizable, or incompatible candidates with null descriptors.

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to e1fc0

No actionable merge-blocking issue was found in the selected changes; merge after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 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 main change: tolerating stale slots in indirect descriptor tables.
Description check ✅ Passed The description directly explains the stale descriptor handling and related upload and overlap changes in the pull request.
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 19:49 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1119#issuecomment-6024197538) · edited 2026-10-06 20:01 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/1119?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**: `bd864c9e-207c-4b5b-9cff-d796b09544e2` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 028d8c9489026b1f4c80244e6815567222b575f3 and e1fc0550f1ddfa41fdfb0b3b917c2c760b8cfdf7. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (2)</summary> * src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp * src/graphics/host_gpu/renderer/cache/bufferCache.cpp </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough Image buffer acquisition uses a temporary upload buffer when staging allocation fails. If sparse backing cannot be read, the upload range is zero-filled. Image initialization skips upload when no source is available. Descriptor binding logs scalar-read overlaps with bound image, attachment, or metadata writes and continues. Indirect image materialization replaces specified unreadable, unnormalizable, or incompatible candidates with null descriptors. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"e1fc0550f1ddfa41fdfb0b3b917c2c760b8cfdf7" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `e1fc0` <!-- final_review_risk_coverage:{"sourceCommitId":"e1fc0550f1ddfa41fdfb0b3b917c2c760b8cfdf7","coveredCommitId":"e1fc0550f1ddfa41fdfb0b3b917c2c760b8cfdf7","kind":"reviewed"} --> No actionable merge-blocking issue was found in the selected changes; merge after normal checks. <!-- 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 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 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 main change: tolerating stale slots in indirect descriptor tables. | | Description check | ✅ Passed | The description directly explains the stale descriptor handling and related upload and overlap changes in the pull request. | | 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=1119)! 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 19:49 UTC · original · edited 2026-10-06 20:05 UTC
On src/graphics/host_gpu/renderer/cache/bufferCache.cpp line 501 (outdated):

@@ -495,8 +495,21 @@ std::pair<Buffer*, uint64_t> BufferCache::ObtainBufferForImage(uint64_t vaddr, u
 	}
 
 	auto [staging, stage_offset] = m_staging_buffer.Map(size, 16);
-	if (staging == nullptr || !Libs::LibKernel::Memory::TryReadSparseBacking(vaddr, staging, size)) {
-		EXIT("BufferCache: failed to read mapped guest image backing\n");
+	if (staging == nullptr) {
+		// Larger than the staging ring (streaming pools of several hundred MiB): serve the
+		// image from a cached buffer covering the range instead.
+		return ObtainBuffer(vaddr, size, false, false);

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Preserve sparse-read handling for oversized images.

If Map fails for an oversized image with unreadable, CPU-modified backing, ObtainBuffer can reach UploadCopies. That path reads the guest address with std::memcpy, so the new zero-fill fallback does not apply and the process can fault. Populate the cached buffer through a sparse-read-safe path, or zero-fill unreadable ranges before returning it.

✅ Addressed in commits 82514bf to e1fc055

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 19:49 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1119#discussion_r4199771881) · edited 2026-10-06 20:05 UTC On `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` line 501 (outdated): ```diff @@ -495,8 +495,21 @@ std::pair<Buffer*, uint64_t> BufferCache::ObtainBufferForImage(uint64_t vaddr, u } auto [staging, stage_offset] = m_staging_buffer.Map(size, 16); - if (staging == nullptr || !Libs::LibKernel::Memory::TryReadSparseBacking(vaddr, staging, size)) { - EXIT("BufferCache: failed to read mapped guest image backing\n"); + if (staging == nullptr) { + // Larger than the staging ring (streaming pools of several hundred MiB): serve the + // image from a cached buffer covering the range instead. + return ObtainBuffer(vaddr, size, false, false); ``` **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** **Preserve sparse-read handling for oversized images.** If `Map` fails for an oversized image with unreadable, CPU-modified backing, `ObtainBuffer` can reach `UploadCopies`. That path reads the guest address with `std::memcpy`, so the new zero-fill fallback does not apply and the process can fault. Populate the cached buffer through a sparse-read-safe path, or zero-fill unreadable ranges before returning it. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:97ea84e1d9c192944d8890a1 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commits 82514bf to e1fc055
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 19:49 UTC · original · edited 2026-10-06 20:06 UTC
On src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp line 446 (outdated):

@@ -433,7 +434,25 @@ bool MaterializeIndirectDescriptor(const ResourcePlan&                         p
 		} else if (!clean.EvaluateDescriptor(sources[entry], candidate)) {
 			return false;
 		}
-		if (!normalize(candidate)) return false;
+		// Probed slots past the table's live range may hold stale T#s whose memory is
+		// gone; the shader never selects them, so bind those as null images.
+		const auto stale_image = [&]() {
+			if (!sources.empty() || entry == 0u || dword_count != 8u ||
+			    NullImageDescriptor(candidate)) return false;
+			const uint64_t base =
+			    ((uint64_t {candidate.dwords[1] & 0xffu} << 32u) | candidate.dwords[0]) << 8u;
+			std::array<uint32_t, 4> probe {};
+			return base == 0u || runtime.read_specialization_memory == nullptr ||
+			       !runtime.read_specialization_memory(runtime.userdata, base & AddressMask, probe);

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

git diff --unified=12 fb7ff7ec03e8b7a940b7debdc9f54892a98ab4a 028d8c9489026b1f4c80244e6815567222b575f3 -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
printf '\\n--- capture / probe / overlap references ---\\n'
rg -n -F -- 'CaptureStrictRead' src/graphics/shader/recompiler
rg -n -F -- 'specialization_reads' src/graphics/shader/recompiler
rg -n -F -- 'shader_buffer' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp

Repository: yuzu-emu/yuzu

Length of output: 2955


🏁 Script executed:

git diff --unified=12 fb7ff7ec03e8b7a940b7debdc9f54892a98ab4a5 028d8c9489026b1f4c80244e6815567222b575f3 -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
printf '\\n--- capture / probe / overlap references ---\\n'
rg -n -F -- 'CaptureStrictRead' src/graphics/shader/recompiler
rg -n -F -- 'specialization_reads' src/graphics/shader/recompiler
rg -n -F -- 'shader_buffer' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp

Repository: KytyPS5/KytyPS5

Length of output: 6843


🏁 Script executed:

printf '%s\\n' '--- capture wrapper and setup ---'
sed -n '130,165p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
sed -n '1080,1135p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
printf '%s\\n' '--- all specialization read consumers ---'
rg -n -F -- 'specialization_reads' .
printf '%s\\n' '--- related buffer-overlap checks ---'
rg -n -i 'overlap|specialization.*read|read.*specialization' src/graphics

Repository: KytyPS5/KytyPS5

Length of output: 20968


🏁 Script executed:

printf '%s\\n' '--- scalar resource read overlap block ---'
sed -n '805,860p' src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
printf '%s\\n' '--- general resource read overlap block ---'
sed -n '985,1060p' src/graphics/host_gpu/renderer/pipeline/descriptors.cpp

Repository: KytyPS5/KytyPS5

Length of output: 6255


Keep the stale-image probe out of specialization_reads.

When capture is enabled and the strict reader is available, this probe reaches CaptureStrictRead, which records each successful 16-byte read. The descriptor checks call EXIT if a recorded range overlaps a written shader buffer. Read this probe through the original strict reader so the readability check does not become a specialization dependency.

🐛 Suggested fix
 			std::array<uint32_t, 4> probe {};
-			return base == 0u || runtime.read_specialization_memory == nullptr ||
-			       !runtime.read_specialization_memory(runtime.userdata, base & AddressMask, probe);
+			const auto capture = runtime.read_specialization_memory == CaptureStrictRead
+			                         ? static_cast<ReadCapture*>(runtime.userdata)
+			                         : nullptr;
+			const auto reader = capture != nullptr ? capture->source.read_specialization_memory
+			                                       : runtime.read_specialization_memory;
+			void* userdata = capture != nullptr ? capture->source.userdata : runtime.userdata;
+			return base == 0u || reader == nullptr ||
+			       !reader(userdata, base & AddressMask, probe);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

			const auto capture = runtime.read_specialization_memory == CaptureStrictRead
			                         ? static_cast<ReadCapture*>(runtime.userdata)
			                         : nullptr;
			const auto reader = capture != nullptr ? capture->source.read_specialization_memory
			                                       : runtime.read_specialization_memory;
			void* userdata = capture != nullptr ? capture->source.userdata : runtime.userdata;
			return base == 0u || reader == nullptr ||
			       !reader(userdata, base & AddressMask, probe);

✅ Addressed in commits 82514bf to e1fc055

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 19:49 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1119#discussion_r4199771888) · edited 2026-10-06 20:06 UTC On `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` line 446 (outdated): ```diff @@ -433,7 +434,25 @@ bool MaterializeIndirectDescriptor(const ResourcePlan& p } else if (!clean.EvaluateDescriptor(sources[entry], candidate)) { return false; } - if (!normalize(candidate)) return false; + // Probed slots past the table's live range may hold stale T#s whose memory is + // gone; the shader never selects them, so bind those as null images. + const auto stale_image = [&]() { + if (!sources.empty() || entry == 0u || dword_count != 8u || + NullImageDescriptor(candidate)) return false; + const uint64_t base = + ((uint64_t {candidate.dwords[1] & 0xffu} << 32u) | candidate.dwords[0]) << 8u; + std::array<uint32_t, 4> probe {}; + return base == 0u || runtime.read_specialization_memory == nullptr || + !runtime.read_specialization_memory(runtime.userdata, base & AddressMask, probe); ``` **🗄️ Data Integrity & Integration** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash git diff --unified=12 fb7ff7ec03e8b7a940b7debdc9f54892a98ab4a 028d8c9489026b1f4c80244e6815567222b575f3 -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp printf '\\n--- capture / probe / overlap references ---\\n' rg -n -F -- 'CaptureStrictRead' src/graphics/shader/recompiler rg -n -F -- 'specialization_reads' src/graphics/shader/recompiler rg -n -F -- 'shader_buffer' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp ``` Repository: yuzu-emu/yuzu Length of output: 2955 --- 🏁 Script executed: ```bash git diff --unified=12 fb7ff7ec03e8b7a940b7debdc9f54892a98ab4a5 028d8c9489026b1f4c80244e6815567222b575f3 -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp printf '\\n--- capture / probe / overlap references ---\\n' rg -n -F -- 'CaptureStrictRead' src/graphics/shader/recompiler rg -n -F -- 'specialization_reads' src/graphics/shader/recompiler rg -n -F -- 'shader_buffer' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 6843 --- 🏁 Script executed: ```bash printf '%s\\n' '--- capture wrapper and setup ---' sed -n '130,165p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp sed -n '1080,1135p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp printf '%s\\n' '--- all specialization read consumers ---' rg -n -F -- 'specialization_reads' . printf '%s\\n' '--- related buffer-overlap checks ---' rg -n -i 'overlap|specialization.*read|read.*specialization' src/graphics ``` Repository: KytyPS5/KytyPS5 Length of output: 20968 --- 🏁 Script executed: ```bash printf '%s\\n' '--- scalar resource read overlap block ---' sed -n '805,860p' src/graphics/host_gpu/renderer/pipeline/descriptors.cpp printf '%s\\n' '--- general resource read overlap block ---' sed -n '985,1060p' src/graphics/host_gpu/renderer/pipeline/descriptors.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 6255 --- </details> **Keep the stale-image probe out of `specialization_reads`.** When capture is enabled and the strict reader is available, this probe reaches `CaptureStrictRead`, which records each successful 16-byte read. The descriptor checks call `EXIT` if a recorded range overlaps a written shader buffer. Read this probe through the original strict reader so the readability check does not become a specialization dependency. <details> <summary>🐛 Suggested fix</summary> ```diff std::array<uint32_t, 4> probe {}; - return base == 0u || runtime.read_specialization_memory == nullptr || - !runtime.read_specialization_memory(runtime.userdata, base & AddressMask, probe); + const auto capture = runtime.read_specialization_memory == CaptureStrictRead + ? static_cast<ReadCapture*>(runtime.userdata) + : nullptr; + const auto reader = capture != nullptr ? capture->source.read_specialization_memory + : runtime.read_specialization_memory; + void* userdata = capture != nullptr ? capture->source.userdata : runtime.userdata; + return base == 0u || reader == nullptr || + !reader(userdata, base & AddressMask, probe); ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion const auto capture = runtime.read_specialization_memory == CaptureStrictRead ? static_cast<ReadCapture*>(runtime.userdata) : nullptr; const auto reader = capture != nullptr ? capture->source.read_specialization_memory : runtime.read_specialization_memory; void* userdata = capture != nullptr ? capture->source.userdata : runtime.userdata; return base == 0u || reader == nullptr || !reader(userdata, base & AddressMask, probe); ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:4d65906a98259764849107eb --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commits 82514bf to e1fc055
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 19:49 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: 044639d1-c66d-43af-b38d-46dd870f668c
📥 Commits

Reviewing files that changed from the base of the PR and between 199d0a9d92 and 028d8c9489.

📒 Files selected for processing (4)
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 19:49 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1119#pullrequestreview-5433799245) · **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**: `044639d1-c66d-43af-b38d-46dd870f668c` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 199d0a9d9225e560432301e39439296d57fa0e34 and 028d8c9489026b1f4c80244e6815567222b575f3. </details> <details> <summary>📒 Files selected for processing (4)</summary> * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=1fd50b36-ab82-4420-875a-9a1b7fa4a899 attempt=6149a0f0-0f21-4c89-9a41-722b853a438f batch=1/1 -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-06 19:57 UTC · original
On src/graphics/host_gpu/renderer/cache/bufferCache.cpp line 501 (outdated):

@@ -495,8 +495,21 @@ std::pair<Buffer*, uint64_t> BufferCache::ObtainBufferForImage(uint64_t vaddr, u
 	}
 
 	auto [staging, stage_offset] = m_staging_buffer.Map(size, 16);
-	if (staging == nullptr || !Libs::LibKernel::Memory::TryReadSparseBacking(vaddr, staging, size)) {
-		EXIT("BufferCache: failed to read mapped guest image backing\n");
+	if (staging == nullptr) {
+		// Larger than the staging ring (streaming pools of several hundred MiB): serve the
+		// image from a cached buffer covering the range instead.
+		return ObtainBuffer(vaddr, size, false, false);

Fixed in 82514bf: an image larger than the staging ring is now read with TryReadSparseBacking into a one-off upload buffer (zero-filled on failure) that is released after the submission, so the cached-buffer memcpy path is no longer reached.

**@⁠NeySlim** on GitHub · 2026-10-06 19:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1119#discussion_r4199845853) On `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` line 501 (outdated): ```diff @@ -495,8 +495,21 @@ std::pair<Buffer*, uint64_t> BufferCache::ObtainBufferForImage(uint64_t vaddr, u } auto [staging, stage_offset] = m_staging_buffer.Map(size, 16); - if (staging == nullptr || !Libs::LibKernel::Memory::TryReadSparseBacking(vaddr, staging, size)) { - EXIT("BufferCache: failed to read mapped guest image backing\n"); + if (staging == nullptr) { + // Larger than the staging ring (streaming pools of several hundred MiB): serve the + // image from a cached buffer covering the range instead. + return ObtainBuffer(vaddr, size, false, false); ``` Fixed in 82514bf: an image larger than the staging ring is now read with `TryReadSparseBacking` into a one-off upload buffer (zero-filled on failure) that is released after the submission, so the cached-buffer `memcpy` path is no longer reached.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-06 19:57 UTC · original
On src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp line 446 (outdated):

@@ -433,7 +434,25 @@ bool MaterializeIndirectDescriptor(const ResourcePlan&                         p
 		} else if (!clean.EvaluateDescriptor(sources[entry], candidate)) {
 			return false;
 		}
-		if (!normalize(candidate)) return false;
+		// Probed slots past the table's live range may hold stale T#s whose memory is
+		// gone; the shader never selects them, so bind those as null images.
+		const auto stale_image = [&]() {
+			if (!sources.empty() || entry == 0u || dword_count != 8u ||
+			    NullImageDescriptor(candidate)) return false;
+			const uint64_t base =
+			    ((uint64_t {candidate.dwords[1] & 0xffu} << 32u) | candidate.dwords[0]) << 8u;
+			std::array<uint32_t, 4> probe {};
+			return base == 0u || runtime.read_specialization_memory == nullptr ||
+			       !runtime.read_specialization_memory(runtime.userdata, base & AddressMask, probe);

Applied in e1fc055: the probe reads through the uncaptured reader when the strict capture is installed, so it no longer lands in specialization_reads.

**@⁠NeySlim** on GitHub · 2026-10-06 19:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1119#discussion_r4199846189) On `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` line 446 (outdated): ```diff @@ -433,7 +434,25 @@ bool MaterializeIndirectDescriptor(const ResourcePlan& p } else if (!clean.EvaluateDescriptor(sources[entry], candidate)) { return false; } - if (!normalize(candidate)) return false; + // Probed slots past the table's live range may hold stale T#s whose memory is + // gone; the shader never selects them, so bind those as null images. + const auto stale_image = [&]() { + if (!sources.empty() || entry == 0u || dword_count != 8u || + NullImageDescriptor(candidate)) return false; + const uint64_t base = + ((uint64_t {candidate.dwords[1] & 0xffu} << 32u) | candidate.dwords[0]) << 8u; + std::array<uint32_t, 4> probe {}; + return base == 0u || runtime.read_specialization_memory == nullptr || + !runtime.read_specialization_memory(runtime.userdata, base & AddressMask, probe); ``` Applied in e1fc055: the probe reads through the uncaptured reader when the strict capture is installed, so it no longer lands in `specialization_reads`.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 20:05 UTC · original
On src/graphics/host_gpu/renderer/cache/bufferCache.cpp line 501 (outdated):

@@ -495,8 +495,21 @@ std::pair<Buffer*, uint64_t> BufferCache::ObtainBufferForImage(uint64_t vaddr, u
 	}
 
 	auto [staging, stage_offset] = m_staging_buffer.Map(size, 16);
-	if (staging == nullptr || !Libs::LibKernel::Memory::TryReadSparseBacking(vaddr, staging, size)) {
-		EXIT("BufferCache: failed to read mapped guest image backing\n");
+	if (staging == nullptr) {
+		// Larger than the staging ring (streaming pools of several hundred MiB): serve the
+		// image from a cached buffer covering the range instead.
+		return ObtainBuffer(vaddr, size, false, false);

@NeySlim, thanks for the fix. The supplied code uses TryReadSparseBacking for the oversized-image fallback and zero-fills on failure. It defers release of the upload buffer until submission completes. This removes the flagged cached-buffer memcpy path from that fallback.


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-06 20:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1119#discussion_r4199921046) On `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` line 501 (outdated): ```diff @@ -495,8 +495,21 @@ std::pair<Buffer*, uint64_t> BufferCache::ObtainBufferForImage(uint64_t vaddr, u } auto [staging, stage_offset] = m_staging_buffer.Map(size, 16); - if (staging == nullptr || !Libs::LibKernel::Memory::TryReadSparseBacking(vaddr, staging, size)) { - EXIT("BufferCache: failed to read mapped guest image backing\n"); + if (staging == nullptr) { + // Larger than the staging ring (streaming pools of several hundred MiB): serve the + // image from a cached buffer covering the range instead. + return ObtainBuffer(vaddr, size, false, false); ``` `@NeySlim`, thanks for the fix. The supplied code uses `TryReadSparseBacking` for the oversized-image fallback and zero-fills on failure. It defers release of the upload buffer until submission completes. This removes the flagged cached-buffer `memcpy` path from that fallback. --- <!-- 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=%40coderabbitai%20caught%20a%20crash%20risk%20with%20oversized%20images%20on%20unreadable%20backing.%20Sparse-safe%20reads%20and%20zero-fill%20now%20prevent%20it%E2%80%94try%20%40coderabbitai%20for%20actionable%20code%20reviews!%20%F0%9F%9A%80&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1119%23discussion_r4199771881)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ 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-06 20:06 UTC · original
On src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp line 446 (outdated):

@@ -433,7 +434,25 @@ bool MaterializeIndirectDescriptor(const ResourcePlan&                         p
 		} else if (!clean.EvaluateDescriptor(sources[entry], candidate)) {
 			return false;
 		}
-		if (!normalize(candidate)) return false;
+		// Probed slots past the table's live range may hold stale T#s whose memory is
+		// gone; the shader never selects them, so bind those as null images.
+		const auto stale_image = [&]() {
+			if (!sources.empty() || entry == 0u || dword_count != 8u ||
+			    NullImageDescriptor(candidate)) return false;
+			const uint64_t base =
+			    ((uint64_t {candidate.dwords[1] & 0xffu} << 32u) | candidate.dwords[0]) << 8u;
+			std::array<uint32_t, 4> probe {};
+			return base == 0u || runtime.read_specialization_memory == nullptr ||
+			       !runtime.read_specialization_memory(runtime.userdata, base & AddressMask, probe);

@NeySlim, thanks for the fix. The supplied code calls the original strict reader with its original userdata, so the probe no longer enters specialization_reads.


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-06 20:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1119#discussion_r4199925339) On `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` line 446 (outdated): ```diff @@ -433,7 +434,25 @@ bool MaterializeIndirectDescriptor(const ResourcePlan& p } else if (!clean.EvaluateDescriptor(sources[entry], candidate)) { return false; } - if (!normalize(candidate)) return false; + // Probed slots past the table's live range may hold stale T#s whose memory is + // gone; the shader never selects them, so bind those as null images. + const auto stale_image = [&]() { + if (!sources.empty() || entry == 0u || dword_count != 8u || + NullImageDescriptor(candidate)) return false; + const uint64_t base = + ((uint64_t {candidate.dwords[1] & 0xffu} << 32u) | candidate.dwords[0]) << 8u; + std::array<uint32_t, 4> probe {}; + return base == 0u || runtime.read_specialization_memory == nullptr || + !runtime.read_specialization_memory(runtime.userdata, base & AddressMask, probe); ``` `@NeySlim`, thanks for the fix. The supplied code calls the original strict reader with its original `userdata`, so the probe no longer enters `specialization_reads`. --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=A%20stale-image%20readability%20probe%20was%20being%20recorded%20as%20a%20specialization%20dependency%2C%20risking%20false%20overlap%20failures%20with%20written%20shader%20buffers.%20%40coderabbitai%E2%80%99s%20fix%20keeps%20it%20out%20of%20%60specialization_reads%60%E2%80%94try%20CodeRabbit%20for%20actionable%20reviews.%20%F0%9F%9B%A0%EF%B8%8F&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1119%23discussion_r4199771888)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠Nmzik on GitHub · 2026-10-08 13:40 UTC · original

This is a hack!

**@⁠Nmzik** on GitHub · 2026-10-08 13:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1119#issuecomment-6061170290) This is a hack!
Author
Owner

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

Fair point, and closing it is the right call: it hid the errors instead of fixing them. I am tracking down why these tables get probed past their live range and why the candidates and backings disagree, and will only come back with fixes for those causes, each with a test.

**@⁠NeySlim** on GitHub · 2026-10-08 14:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1119#issuecomment-6061567707) Fair point, and closing it is the right call: it hid the errors instead of fixing them. I am tracking down why these tables get probed past their live range and why the candidates and backings disagree, and will only come back with fixes for those causes, each with a test.

Pull request closed

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