renderer: read unmapped guest memory as zeros in the SRT walk #1365
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1365
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1365/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 mergingProblem
Astro Bot (PPSA21564, v01.007.000) crashes right after its first shaders compile:
The faulting code is the CRT
memcpy. Symbolizing the host return addresses against the PDBputs the caller in
IR::MaterializeResources→IR::SrtWalker::EvaluateRawRead.PipelineCachebuilds theSrtRuntimewith onlyread_specialization_memory, soread_memoryis null. Ordinary scalar reads inSrtWalker::EvaluateRawReadandSrtReadCapture::ReadOrdinarythen fall back to a rawmemcpyof the guest address. The walkevaluates 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_memoryreader that goes throughMemory::TryReadBackingand returnszeros for unmapped guest addresses.
memcpy; no GPU buffer synchronizationis added (unlike
ReadShaderGuestMemory).MaterializeResources.CleanRuntimestill overridesread_memory, so the clean walker is unchanged.Testing
main(307fdcf).change on
7b9997b; on currentmainI'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.@coderabbitai[bot] on GitHub · 2026-10-10 11:29 UTC · original
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
b3dfe153-9f72-4079-a91d-2d976f4a2a9b📥 Commits
Reviewing files that changed from the base of the PR and between
307fdcf7adand0f5366f26f.📒 Files selected for processing (1)
src/graphics/host_gpu/renderer/pipeline/pipelineCache.cppIncluded 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
ReadShaderScalarMemorywas added to read shader data from guest backing memory. If the read fails, it fills the requested values with zero and returnstrue.ProgramCache::Getassigns this callback toSrtRuntime::read_memory. Specialization-memory reads continue to useReadShaderGuestMemory.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
0f536Unmapped scalar reads return zero while backed reads retain their data. No actionable merge risk remains in the reviewed change.
Pre-merge checks |
4 |
1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 helpto get the list of available commands.@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 isCS 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
0x18is this sequence (bytes 0x1f58–0x1f84 of the dump):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 on307fdcfwithout the patch, but not with it.About the zeros: this is a flat
s_loadthrough an SGPR base, not ans_buffer_loadthrough 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 thes_trappath is skipped. The loads that follow at+0x58and+0x30read 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
@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.
KytyPS5-2026-10-12-df5b9b9: crashes about 20 s after launch while building the pipeline forCS 0x503d7f066a496c3c, withUnhandled 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:
tbb_thead(address=0xffffffffffffffff) about 2.5 min in, during the asteroid scene.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 0x503d7f066a496c3cis clear-cut, though.Logs available if useful.


@NeySlim on GitHub · 2026-10-14 05:59 UTC · original
This costs a lot in God of War Ragnarök (PPSA08332). Setting
read_memoryturns off the compiled SRT walker:RefreshFlatBufferonly runssrt_codewhenread_memory == nullptr, so every draw's SRT refresh goes back to the interpreter, plus oneTryReadBackingcall per DWORD.Numbers from new-game runs (cutscene / sled / Freya fight, same timings, Linux, Radeon 8060S):
ReadShaderScalarMemoryalone is 7-13 ms per frame on the GPU thread. The Freya part is too noisy at that frame rate.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.
@Accelwolf01 on GitHub · 2026-10-14 21:43 UTC · original · approved these changes
@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 onto37df7f3(along with #1403) and it now gets to the title screen fine, ran for a few minutes with no crashbazzite linux, rtx 3080 ti, nvidia 615.71.09
(used claude to help track this down, tested it myself)
@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 inSrtWalker.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 inpipelineCache.cppsets onlyread_specialization_memory(:355) and leavesread_memorynull.ReadOrdinarymemcpy :42EvaluateRawReadmemcpy :747.read_memory, so :39 uses the callbackread_memory == nullptrreaderis non-nullCopySparseMemoryinstead ofTryReadBacking)address < 0x40000jb failedif the table is below 0x40000, then the interpreted walkbase < 0x40000Behaviour: none of the three refuses the read. All return zeros with
true, so a null table specializes as if it held zeros.SrtWalker.cppstay reachable for any runtime withoutread_memory.m_ranges.emplace_back(:44). ItsRefreshFlatBufferchange 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
CompileSrtWalkeremits code. Run the capture walk throughObservedRuntime(A1), thenRefreshFlatBufferwith the runtime exactly as the pipeline cache builds it (A2, then A3 whenread_memoryis null; the callback otherwise). Expect no fault, and every read of that table returnstrueand 0. A SrtWalker-only test withread_memory = nullptrpasses only #1528, so the real choice is whether the walker protects itself or a non-nullread_memorybecomes 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