gpu: read sparse backing when uploading buffer copies #1144
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!1144
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1144/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?
@NeySlim on GitHub · 2026-10-07 14:45 UTC · original
NeySlim:fix/prt-sparse-upload→main· +105 −3 · 2 files · 2 commits · closed without mergingProblem
God of War Ragnarök (PPSA08332, 05.005) stops a few minutes into boot with:
The game calls
sceKernelSetPrtAperturewithaddr = 0x1000000000, len = 0x7600000000.KernelSetPrtApertureregisters the whole aperture as GPU memory (MapGpuRange), but only some of its pages are resident.PrepareBdathen synchronizes every buffer in the mapped ranges. When a buffer covers a non-resident page,UploadCopiesrunsmemcpyon a reserved, inaccessible host page from insideForEachUploadRange. The read fault goes throughHandleFaulttoBufferCache::ReadMemory, which re-enters the tracker:The faulting address was in a
---phost mapping (reserved, nothing mapped), about 0.8 MiB before the first resident page of the buffer.#227 (Stray) reports the same assertion. I have not checked whether it has the same cause.
Change
UploadCopiesreads guest bytes throughTryReadBackingfirst, thenTryReadSparseBacking. Non-resident pages read as zero, as in the existing image upload path inBufferCache. The plainmemcpyremains as a fallback for mappings without a backing alias, such as private flexible memory.The copies cover CPU-dirty ranges only, so the backing store holds the current bytes for them.
Test
New
BufferCachePrtHoleUploadinShaderRecompilerComputeTests. It reserves 4 MiB at0x1000000000, registers it as PRT aperture 0 and maps 64 KiB of direct memory at+0x10000. It then obtains a 128 KiB read-only buffer at the start of the aperture and checks:It runs in the full suite next to
BufferCacheDirtyGarbageCollection(Windows block), and on its own with--buffer-cache-prt-only.Validation
Linux, AMD Radeon 8060S (RDNA 3.5), Mesa RADV 26.2.3.
--buffer-cache-prt-only: passes. Without the change, the test crashes on the read fault (SIGSEGV in this harness, which has no guest fault handler).shader_recompiler_compute_testsin its own process, with and without the change: identical results. On this setup, 12 cases fail on main either way (10 unrelated, plus the 2BranchVccnz*cases fixed by #1143).Not tested on Windows.
TryReadBacking,TryReadSparseBackingand the mapping table they read are shared by both platforms, and a read of a reserved page faults through the same handler there. The test only uses the emulated kernel calls and Vulkan transfers.AI use
I used Claude Code (AI agent) to investigate the crash, write the change and the test, and run the tests above on my machine. I reviewed the diff and the results before opening this PR.
@coderabbitai[bot] on GitHub · 2026-10-07 14:49 UTC · original · edited 2026-10-07 16:14 UTC
📝 Walkthrough
Walkthrough
UploadCopiesnow reads through backing storage, then sparse backing, before falling back to a direct host-memory copy. The same read path serves staging-buffer and temporary-buffer uploads. A new PRT aperture test checks that reads from non-resident pages return zero and that a resident page retains its initialized value. The test has a dedicated command-line selector and runs in the default test sequence.Suggested reviewers:
nmzikPriority: ⬆️ High
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
a7468An unowned PRT aperture can still crash buffer synchronization; reject such apertures before mapping.
🚥 Pre-merge checks | ✅ 4 | ❓ 1
❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
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 1 functions across 1 files. (1 skipped: 1 too large.)
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.@coderabbitai[bot] on GitHub · 2026-10-07 14:49 UTC · original · reviewed
🧹 Nitpick comments (1)
ℹ️ Review info
⚙️ Run configuration
2e60c8bb-c9ec-4882-9634-d3b17309c366📥 Commits
Reviewing files that changed from the base of the PR and between
d2413fc2eband3e63b9ae7e.📒 Files selected for processing (2)
src/graphics/host_gpu/renderer/cache/bufferCache.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
@NeySlim on GitHub · 2026-10-07 15:59 UTC · original
Done in
a746839. The check now runs with the other platform-independent checks, outside the rasterization and Windows block. It passes on Linux in the full sequence.@coderabbitai[bot] on GitHub · 2026-10-07 16:13 UTC · original · reviewed
ℹ️ Review info
⚙️ Run configuration
97b6a3ee-e269-4da5-879e-909292b30de2📥 Commits
Reviewing files that changed from the base of the PR and between
3e63b9ae7eanda746839a2c.📒 Files selected for processing (1)
tests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@NeySlim on GitHub · 2026-10-07 22:00 UTC · original
The aperture window
[0x0f00000000, 0xfc00000000)sits inside the guest-owned address space here: for God of War Ragnarök'ssceKernelSetPrtAperture(0x1000000000, 0x7600000000),g_guest_address_space->Owns()returns true. I don't have a hardware or SDK reference saying the call must fail on an unreserved range, so I'd rather not add a new EINVAL path toKernelSetPrtAperturein this PR. It is outside this change and could reject calls that work on hardware.@NeySlim on GitHub · 2026-10-14 06:17 UTC · original
Covered by
40692dfbon main, the PRT hole upload test passes there without this change. Closing.Pull request closed