renderer: read unmapped guest memory as zeros in the SRT walk #1365

Closed
github-bot wants to merge 1 commit from gh-pr/1365/head into gh-pr/1365/base
Owner

@⁠LukaszRozmej on GitHub · 2026-10-10 11:25 UTC · original
LukaszRozmej:fix/shader-walk-unmapped-reads → main · +10 −0 · 1 files · 1 commits · closed without merging

Problem

Astro Bot (PPSA21564, v01.007.000) crashes right after its first shaders compile:

thread: (host thread)
rdx=0000000000000018 r8=0000000000000004 ...
Unhandled host exception: type=1 code=3221225477 ... access=1 address=0x0000000000000018

The faulting code is the CRT memcpy. Symbolizing the host return addresses against the PDB
puts the caller in IR::MaterializeResources → IR::SrtWalker::EvaluateRawRead.

PipelineCache builds the SrtRuntime with only read_specialization_memory, so
read_memory is null. Ordinary scalar reads in SrtWalker::EvaluateRawRead and
SrtReadCapture::ReadOrdinary then fall back to a raw memcpy of the guest address. The walk
evaluates loads the shader may never execute, and this game reaches one through a null SRT
pointer (base 0 + 0x18), which faults the host.

Fix

Give the walk a read_memory reader that goes through Memory::TryReadBacking and returns
zeros for unmapped guest addresses.

  • Mapped reads return the same bytes as the previous memcpy; no GPU buffer synchronization
    is added (unlike ReadShaderGuestMemory).
  • A zeroed descriptor is already handled as an empty resource by MaterializeResources.
  • CleanRuntime still overrides read_memory, so the clean walker is unchanged.

Testing

  • Windows, clang-cl 20.1.8, Release; builds cleanly on current main (307fdcf).
  • Astro Bot gets past this crash and keeps loading/streaming game data. That run used the same
    change on 7b9997b; on current main I've verified the build only.
**@⁠LukaszRozmej** on GitHub · 2026-10-10 11:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1365) `LukaszRozmej:fix/shader-walk-unmapped-reads` → `main` · +10 −0 · 1 files · 1 commits · closed without merging ## Problem Astro Bot (PPSA21564, v01.007.000) crashes right after its first shaders compile: ``` thread: (host thread) rdx=0000000000000018 r8=0000000000000004 ... Unhandled host exception: type=1 code=3221225477 ... access=1 address=0x0000000000000018 ``` The faulting code is the CRT `memcpy`. Symbolizing the host return addresses against the PDB puts the caller in `IR::MaterializeResources` → `IR::SrtWalker::EvaluateRawRead`. `PipelineCache` builds the `SrtRuntime` with only `read_specialization_memory`, so `read_memory` is null. Ordinary scalar reads in `SrtWalker::EvaluateRawRead` and `SrtReadCapture::ReadOrdinary` then fall back to a raw `memcpy` of the guest address. The walk evaluates loads the shader may never execute, and this game reaches one through a null SRT pointer (base 0 + 0x18), which faults the host. ## Fix Give the walk a `read_memory` reader that goes through `Memory::TryReadBacking` and returns zeros for unmapped guest addresses. - Mapped reads return the same bytes as the previous `memcpy`; no GPU buffer synchronization is added (unlike `ReadShaderGuestMemory`). - A zeroed descriptor is already handled as an empty resource by `MaterializeResources`. - `CleanRuntime` still overrides `read_memory`, so the clean walker is unchanged. ## Testing - Windows, clang-cl 20.1.8, Release; builds cleanly on current `main` (307fdcf). - Astro Bot gets past this crash and keeps loading/streaming game data. That run used the same change on 7b9997b; on current `main` I've verified the build only.
The pipeline cache never set SrtRuntime::read_memory, so ordinary scalar
reads in SrtWalker::EvaluateRawRead and SrtReadCapture::ReadOrdinary fell
back to a raw memcpy of the guest address. The walk evaluates loads the
shader may never execute, and Astro Bot (PPSA21564) reaches one through a
null SRT pointer: base 0 + 0x18 faults the host right after its first
shaders compile ("Unhandled host exception ... address=0x18").

Read those loads through Memory::TryReadBacking instead and return zeros
for unmapped addresses. Mapped reads return the same bytes as before, and
a zeroed descriptor is already handled as an empty resource.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:54:31 +00:00
github-bot closed this pull request 2026-11-26 09:54:31 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-10 11:29 UTC · original

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: b3dfe153-9f72-4079-a91d-2d976f4a2a9b

📥 Commits

Reviewing files that changed from the base of the PR and between 307fdcf7ad and 0f5366f26f.


📒 Files selected for processing (1)
  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.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.



📝 Walkthrough

Walkthrough

ReadShaderScalarMemory was added to read shader data from guest backing memory. If the read fails, it fills the requested values with zero and returns true. ProgramCache::Get assigns this callback to SrtRuntime::read_memory. Specialization-memory reads continue to use ReadShaderGuestMemory.

Suggested reviewers: nmzik


Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 0f536

Unmapped scalar reads return zero while backed reads retain their data. No actionable merge risk remains in the reviewed change.

Pre-merge checks | Passed 4 | Failed 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 4 functions across 1 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 and concisely describes the main renderer change: treating unmapped guest memory as zero during the SRT walk.
Description check Passed The description directly explains the Astro Bot crash, the null read_memory cause, the zero-filling fix, and the reported testing.
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.

  • 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-10 11:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1365#issuecomment-6097032520) <!-- 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/1365?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `b3dfe153-9f72-4079-a91d-2d976f4a2a9b` <hr> </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 307fdcf7ad5d9d15b5966288fcc598ac9dbca188 and 0f5366f26f280ca81a3082051a53831e1c5b1308. <hr> </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing (1)</strong></summary> <dl> <dd> * `src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp` <hr> </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. <hr> </dd> </dl> </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> ## Walkthrough `ReadShaderScalarMemory` was added to read shader data from guest backing memory. If the read fails, it fills the requested values with zero and returns `true`. `ProgramCache::Get` assigns this callback to `SrtRuntime::read_memory`. Specialization-memory reads continue to use `ReadShaderGuestMemory`. **Suggested reviewers:** `nmzik` <hr> </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"0f5366f26f280ca81a3082051a53831e1c5b1308" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **⚪ Minimal** · up to `0f536` <!-- final_review_risk_coverage:{"sourceCommitId":"0f5366f26f280ca81a3082051a53831e1c5b1308","coveredCommitId":"0f5366f26f280ca81a3082051a53831e1c5b1308","kind":"reviewed"} --> Unmapped scalar reads return zero while backed reads retain their data. No actionable merge risk remains in the reviewed change. <!-- final_review_risk_end --> <!-- 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-v1.svg" width="14" height="17" align="middle" alt="Passed" title="Passed"></picture></sup> 4 | <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v1.svg" width="14" height="17" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | 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 4 functions across 1 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong>✅ Passed checks (4 passed)</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main renderer change: treating unmapped guest memory as zero during the SRT walk. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the Astro Bot crash, the null read_memory cause, the zero-filling fix, and the reported testing. | | 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> <hr> </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=1365)! 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) <hr> </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠overlordxrz-source on GitHub · 2026-10-11 00:57 UTC · original

Some extra Astro Bot evidence for this one, in case it helps review.

@⁠placintaalexandru attached the compute shader from this crash on #1268: PPSA21564 v01.007.000, official build 307fdcf, CachyOS, i7-9700K, RTX 2080S. It is CS 0x503d7f066a496c3c, 3596 dwords, the same hash and size @⁠carbonimax found on Windows with an RX 6900 XT. So the crash reproduces on both OSes and both GPU vendors.

The read at 0x18 is this sequence (bytes 0x1f58–0x1f84 of the dump):

s_andn1_saveexec_b64 s[40:41], vcc   ; lanes with v58 > 0 and v21 != 0 (and only if s35 >= s32)
s_cbranch_execz      ...
s_load_dwordx2       s[8:9], s[0:1], 0    ; pointer from user data s[0:1]; it is 0 here
s_load_dword         vcc_lo, s[8:9], 0x18 ; <- null + 0x18
s_bitcmp1_b32        vcc_lo, 18
s_cbranch_scc0       1
s_trap               1

About a hundred instructions further on, the same path runs image_bvh_intersect_ray. So it is the BVH traversal of the ray-traced path, and it is entered under a per-lane exec mask. The walker can't decide that branch, so it goes down both sides. This also explains why the community non-RT patch from #745 avoids the crash: @⁠mesientopremiumjeje-stack saw it on 307fdcf without the patch, but not with it.

About the zeros: this is a flat s_load through an SGPR base, not an s_buffer_load through a V#. The ISA rule that out-of-range scalar buffer reads return zero doesn't cover it, and on hardware a null base here would be a GPU page fault. So zero isn't emulated hardware behaviour. It's a safe value for a load the GPU only runs once that pointer is valid, which is how the comment in the patch puts it. With zeros, bit 18 of the header dword is clear, so the s_trap path is skipped. The loads that follow at +0x58 and +0x30 read zero too, so the walk ends with empty descriptors instead of a host fault.

I checked that the patch still applies cleanly on current main (947627d10).

AI-assisted: yes

**@⁠overlordxrz-source** on GitHub · 2026-10-11 00:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1365#issuecomment-6103971055) Some extra Astro Bot evidence for this one, in case it helps review. @⁠placintaalexandru attached the compute shader from this crash on #1268: PPSA21564 v01.007.000, official build `307fdcf`, CachyOS, i7-9700K, RTX 2080S. It is `CS 0x503d7f066a496c3c`, 3596 dwords, the same hash and size @⁠carbonimax found on Windows with an RX 6900 XT. So the crash reproduces on both OSes and both GPU vendors. The read at `0x18` is this sequence (bytes 0x1f58–0x1f84 of the dump): ``` s_andn1_saveexec_b64 s[40:41], vcc ; lanes with v58 > 0 and v21 != 0 (and only if s35 >= s32) s_cbranch_execz ... s_load_dwordx2 s[8:9], s[0:1], 0 ; pointer from user data s[0:1]; it is 0 here s_load_dword vcc_lo, s[8:9], 0x18 ; <- null + 0x18 s_bitcmp1_b32 vcc_lo, 18 s_cbranch_scc0 1 s_trap 1 ``` About a hundred instructions further on, the same path runs `image_bvh_intersect_ray`. So it is the BVH traversal of the ray-traced path, and it is entered under a per-lane exec mask. The walker can't decide that branch, so it goes down both sides. This also explains why the community non-RT patch from #745 avoids the crash: @⁠mesientopremiumjeje-stack saw it on `307fdcf` without the patch, but not with it. About the zeros: this is a flat `s_load` through an SGPR base, not an `s_buffer_load` through a V#. The ISA rule that out-of-range scalar buffer reads return zero doesn't cover it, and on hardware a null base here would be a GPU page fault. So zero isn't emulated hardware behaviour. It's a safe value for a load the GPU only runs once that pointer is valid, which is how the comment in the patch puts it. With zeros, bit 18 of the header dword is clear, so the `s_trap` path is skipped. The loads that follow at `+0x58` and `+0x30` read zero too, so the walk ends with empty descriptors instead of a host fault. I checked that the patch still applies cleanly on current main (`947627d10`). AI-assisted: yes
Author
Owner

@⁠Stepz97 on GitHub · 2026-10-12 16:06 UTC · original

Tested #1365 on Windows with Astro Bot (PPSA21564, 01.007.000).

Setup: Windows 10 (AtlasOS), i7-13700KF, RTX 4080 16 GB, NVIDIA 617.42. Flags: --amd-cpu --redzone.

Method: the same upstream commit with and without this PR.

  • Control, official release KytyPS5-2026-10-12-df5b9b9: crashes about 20 s after launch while building the pipeline for CS 0x503d7f066a496c3c, with Unhandled host exception ... address=0x0000000000000018 in runtimeLinker.cpp:711 (Shaders: VS 3 | PS 2 | CS 15), the crash from #1268.
  • df5b9b9 + this PR (cherry-picked, local clang-cl Release build): gets past that shader in both runs (2/2). The logo, title, save select, opening warp tunnel and asteroid field all render.

After that point both runs hit the level-loading problems from #745, which look unrelated to this PR:

  • Run 1: guest fault in thread tbb_thead (address=0xffffffffffffffff) about 2.5 min in, during the asteroid scene.
  • Run 2: stuck in the warp tunnel for over 3 min at about 34 fps; the log has about 12k Equeue wait timedout: Gpu::GpuDevice::EopEq.

Caveat: this PC currently shows RAM instability (a bit-flipped page-cache copy of a header and one MEMORY_MANAGEMENT bugcheck today), so I'd treat the post-tunnel failures as weak evidence. The control-vs-PR difference at CS 0x503d7f066a496c3c is clear-cut, though.

Logs available if useful.
IMG_0143
IMG_0142

**@⁠Stepz97** on GitHub · 2026-10-12 16:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1365#issuecomment-6127985050) Tested #1365 on Windows with Astro Bot (PPSA21564, 01.007.000). **Setup:** Windows 10 (AtlasOS), i7-13700KF, RTX 4080 16 GB, NVIDIA 617.42. Flags: `--amd-cpu --redzone`. **Method:** the same upstream commit with and without this PR. - **Control**, official release `KytyPS5-2026-10-12-df5b9b9`: crashes about 20 s after launch while building the pipeline for `CS 0x503d7f066a496c3c`, with `Unhandled host exception ... address=0x0000000000000018 in runtimeLinker.cpp:711` (`Shaders: VS 3 | PS 2 | CS 15`), the crash from #1268. - **`df5b9b9` + this PR** (cherry-picked, local clang-cl Release build): gets past that shader in both runs (2/2). The logo, title, save select, opening warp tunnel and asteroid field all render. After that point both runs hit the level-loading problems from #745, which look unrelated to this PR: - **Run 1:** guest fault in thread `tbb_thead` (`address=0xffffffffffffffff`) about 2.5 min in, during the asteroid scene. - **Run 2:** stuck in the warp tunnel for over 3 min at about 34 fps; the log has about 12k `Equeue wait timedout: Gpu::GpuDevice::EopEq`. **Caveat:** this PC currently shows RAM instability (a bit-flipped page-cache copy of a header and one MEMORY_MANAGEMENT bugcheck today), so I'd treat the post-tunnel failures as weak evidence. The control-vs-PR difference at `CS 0x503d7f066a496c3c` is clear-cut, though. Logs available if useful. <img width="1296" height="759" alt="IMG_0143" src="https://github.com/user-attachments/assets/440a4580-78c5-4bf5-a5b2-2525f05e7eea" /> <img width="1296" height="759" alt="IMG_0142" src="https://github.com/user-attachments/assets/d1c08606-efb8-42c4-81d0-8dd28dc397a6" />
Author
Owner

@⁠NeySlim on GitHub · 2026-10-14 05:59 UTC · original

This costs a lot in God of War Ragnarök (PPSA08332). Setting read_memory turns off the compiled SRT walker: RefreshFlatBuffer only runs srt_code when read_memory == nullptr, so every draw's SRT refresh goes back to the interpreter, plus one TryReadBacking call per DWORD.

Numbers from new-game runs (cutscene / sled / Freya fight, same timings, Linux, Radeon 8060S):

  • main + the fixes GoW needs to boot, 3 runs each: 9.9 / 7.6 fps without, 9.2 / 7.1 fps with this PR (cutscene / sled, about -7%). ReadShaderScalarMemory alone is 7-13 ms per frame on the GPU thread. The Freya part is too noisy at that frame rate.
  • with compiled SRT reads (#1456 and follow-ups), 3-4 runs each: 22.8 / 20.7 / 24.6 fps without, 17.4 / 14.5 / 19.5 fps with. Resource materialization goes from 15-16 to 30-36 ms per frame, 13-16 ms of it in ReadShaderScalarMemory.

The Astro Bot crash is real, but it only needs the unmapped case to read as zero. Could the null/unmapped base be handled without dropping the compiled path, e.g. by checking the base pointer once per table, or by having the compiled code fall back to the reader only when a load faults? I have a local change that resumes compiled SRT loads at a failure exit when they fault (for reads beside GPU writes); the same mechanism could turn an unmapped load into zeros. Happy to put it up if that direction works for you.

**@⁠NeySlim** on GitHub · 2026-10-14 05:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1365#issuecomment-6161979010) This costs a lot in God of War Ragnarök (PPSA08332). Setting `read_memory` turns off the compiled SRT walker: `RefreshFlatBuffer` only runs `srt_code` when `read_memory == nullptr`, so every draw's SRT refresh goes back to the interpreter, plus one `TryReadBacking` call per DWORD. Numbers from new-game runs (cutscene / sled / Freya fight, same timings, Linux, Radeon 8060S): - main + the fixes GoW needs to boot, 3 runs each: 9.9 / 7.6 fps without, 9.2 / 7.1 fps with this PR (cutscene / sled, about -7%). `ReadShaderScalarMemory` alone is 7-13 ms per frame on the GPU thread. The Freya part is too noisy at that frame rate. - with compiled SRT reads (#1456 and follow-ups), 3-4 runs each: 22.8 / 20.7 / 24.6 fps without, 17.4 / 14.5 / 19.5 fps with. Resource materialization goes from 15-16 to 30-36 ms per frame, 13-16 ms of it in `ReadShaderScalarMemory`. The Astro Bot crash is real, but it only needs the unmapped case to read as zero. Could the null/unmapped base be handled without dropping the compiled path, e.g. by checking the base pointer once per table, or by having the compiled code fall back to the reader only when a load faults? I have a local change that resumes compiled SRT loads at a failure exit when they fault (for reads beside GPU writes); the same mechanism could turn an unmapped load into zeros. Happy to put it up if that direction works for you.
Author
Owner

@⁠Accelwolf01 on GitHub · 2026-10-14 21:43 UTC · original · approved these changes

**@⁠Accelwolf01** on GitHub · 2026-10-14 21:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1365#pullrequestreview-5525077075) · **approved these changes**
Author
Owner

@⁠ReverendOzmund on GitHub · 2026-10-18 07:42 UTC · original

confirming this fixes a host crash on linux too. halo campaign evolved (PPSA28038, my dump) segfaults on current main (37df7f3) right after the first shaders compile, null read in ReadShaderGuestMemory -> TryReadBufferBacking during MaterializeResources. merged this onto 37df7f3 (along with #1403) and it now gets to the title screen fine, ran for a few minutes with no crash

bazzite linux, rtx 3080 ti, nvidia 615.71.09

(used claude to help track this down, tested it myself)

**@⁠ReverendOzmund** on GitHub · 2026-10-18 07:42 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1365#issuecomment-6247258458) confirming this fixes a host crash on linux too. halo campaign evolved (PPSA28038, my dump) segfaults on current main (37df7f3) right after the first shaders compile, null read in ReadShaderGuestMemory -> TryReadBufferBacking during MaterializeResources. merged this onto 37df7f3 (along with #1403) and it now gets to the title screen fine, ran for a few minutes with no crash bazzite linux, rtx 3080 ti, nvidia 615.71.09 (used claude to help track this down, tested it myself)
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-19 15:43 UTC · original

@⁠LukaszRozmej @⁠MIKL99999 @⁠theantipopau, and maintainers: I have no PR here. I compared the three diffs against current main (0cad4672) for the three host reads through a NULL SRT table pointer in SrtWalker.cpp. These are the sites in the crash logs of Astro Bot (A1, e.g. #1268), Star Wars Galactic Racer #1481 (A2) and UFC 6 #1055 (A3, matched by the code bytes around the faulting pc). On main, all three are reachable, because the runtime built in pipelineCache.cpp sets only read_specialization_memory (:355) and leaves read_memory null.

A1 ReadOrdinary memcpy :42 A2 compiled-walker load :476 A3 EvaluateRawRead memcpy :747
#1365 avoided: the runtime gets .read_memory, so :39 uses the callback avoided: :1171 runs the walker only if read_memory == nullptr avoided: :740 reader is non-null
#1549 same as #1365 (the callback uses CopySparseMemory instead of TryReadBacking) same same
#1528 fixed: zero if address < 0x40000 fixed: jb failed if the table is below 0x40000, then the interpreted walk fixed: zero if base < 0x40000

Behaviour: none of the three refuses the read. All return zeros with true, so a null table specializes as if it held zeros.

  • #1365 and #1549 zero any scalar read whose probe fails. #1549's comment says the two probes differ on private mappings, so the two PRs can specialize differently. The memcpys in SrtWalker.cpp stay reachable for any runtime without read_memory.
  • #1528 zeroes only below 0x40000, so a bad non-null pointer still reaches the loads. Its zero paths skip m_ranges.emplace_back (:44). Its RefreshFlatBuffer change makes every walker failure fall back to the interpreted walk, including the user-data-count check at :451, which returns false on main.

One test for all three: a plan whose SRT table pointer in user data is 0, with scalar reads at offset 0 and at a non-zero offset, built so CompileSrtWalker emits code. Run the capture walk through ObservedRuntime (A1), then RefreshFlatBuffer with the runtime exactly as the pipeline cache builds it (A2, then A3 when read_memory is null; the callback otherwise). Expect no fault, and every read of that table returns true and 0. A SrtWalker-only test with read_memory = nullptr passes only #1528, so the real choice is whether the walker protects itself or a non-null read_memory becomes the contract.

I'd suggest converging on one PR. All three are on older bases than main and need a rebase anyway.

Written with Claude Code (AI): it compared the diffs; I checked the matrix against the code.

**@⁠Nawid3333** on GitHub · 2026-10-19 15:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1365#issuecomment-6271188084) @⁠LukaszRozmej @⁠MIKL99999 @⁠theantipopau, and maintainers: I have no PR here. I compared the three diffs against current main (0cad4672) for the three host reads through a NULL SRT table pointer in `SrtWalker.cpp`. These are the sites in the crash logs of Astro Bot (A1, e.g. #1268), Star Wars Galactic Racer #1481 (A2) and UFC 6 #1055 (A3, matched by the code bytes around the faulting pc). On main, all three are reachable, because the runtime built in `pipelineCache.cpp` sets only `read_specialization_memory` (:355) and leaves `read_memory` null. | | A1 `ReadOrdinary` memcpy :42 | A2 compiled-walker load :476 | A3 `EvaluateRawRead` memcpy :747 | |---|---|---|---| | #1365 | avoided: the runtime gets `.read_memory`, so :39 uses the callback | avoided: :1171 runs the walker only if `read_memory == nullptr` | avoided: :740 `reader` is non-null | | #1549 | same as #1365 (the callback uses `CopySparseMemory` instead of `TryReadBacking`) | same | same | | #1528 | fixed: zero if `address < 0x40000` | fixed: `jb failed` if the table is below 0x40000, then the interpreted walk | fixed: zero if `base < 0x40000` | **Behaviour:** none of the three refuses the read. All return zeros with `true`, so a null table specializes as if it held zeros. - #1365 and #1549 zero any scalar read whose probe fails. #1549's comment says the two probes differ on private mappings, so the two PRs can specialize differently. The memcpys in `SrtWalker.cpp` stay reachable for any runtime without `read_memory`. - #1528 zeroes only below 0x40000, so a bad non-null pointer still reaches the loads. Its zero paths skip `m_ranges.emplace_back` (:44). Its `RefreshFlatBuffer` change makes every walker failure fall back to the interpreted walk, including the user-data-count check at :451, which returns false on main. **One test for all three:** a plan whose SRT table pointer in user data is 0, with scalar reads at offset 0 and at a non-zero offset, built so `CompileSrtWalker` emits code. Run the capture walk through `ObservedRuntime` (A1), then `RefreshFlatBuffer` with the runtime exactly as the pipeline cache builds it (A2, then A3 when `read_memory` is null; the callback otherwise). Expect no fault, and every read of that table returns `true` and 0. A SrtWalker-only test with `read_memory = nullptr` passes only #1528, so the real choice is whether the walker protects itself or a non-null `read_memory` becomes the contract. I'd suggest converging on one PR. All three are on older bases than main and need a rebase anyway. Written with Claude Code (AI): it compared the diffs; I checked the matrix against the code.

Pull request closed

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