gpu: read back tiny GPU-written images before signalling EOP labels (PPSA09809) #1753
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!1753
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1753/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?
@MrBigBritches on GitHub · 2026-10-20 06:33 UTC · original
MrBigBritches:lighting-readback-fix→main· +180 −11 · 7 files · 6 commits · closed without mergingGames read small render targets on the CPU after waiting for the GPU. UE4 does this to compute sky-light ambient: it renders the irradiance SH into a 9x1 RGBA16F target and reads it back with ReadSurfaceFloatData. Kyty never wrote tiled images back to guest memory, and it published EOP label writes at command-parse time, so the guest read zeros. In Octopath Traveler II this left everything in shade (characters especially) without ambient light.
Before

After

Partial Fix: #1617
@coderabbitai[bot] on GitHub · 2026-10-20 06:39 UTC · original · edited 2026-10-21 16:30 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
3bb73b4f-248a-4cc0-ab82-c25179ae7216📥 Commits
Reviewing files that changed from the base of the PR and between
6f8fe5cc24andf01c4cc584.📒 Files selected for processing: 3
src/graphics/guest_gpu/graphicsRun.cppsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
📝 Walkthrough
The texture cache enrolls qualifying small GPU-modified images for readback and reports queued and in-flight work. End-of-pipe label writes defer label publication and optional interrupts until readbacks complete. Interrupt-only completion and GDS synchronization also process queued readbacks and deferred operations.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
f01c4The change makes small GPU-written render targets reach guest memory before completion labels and interrupts are published. No concrete merge-blocking risk remains after review.
Pre-merge checks:
4 ·
1
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-20 06:39 UTC · original · edited 2026-10-20 06:49 UTC
On
src/graphics/guest_gpu/graphicsRun.cppline 1081 (outdated):🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Queue readbacks before the interrupt-only EOP path.
For selector
0x01on a non-async queue,WriteAtEndOfPipe()callsTriggerEopEventAtEndOfPipe()and returns at Lines 1065–1069. Neither changed readback check runs. If a guest waits for that interrupt before reading a tiny GPU-written image, the interrupt can arrive while its guest memory still contains stale data. Process pending readbacks before scheduling this interrupt.Also applies to: 1134-1134
✅ Addressed in commit
a4d3583@coderabbitai[bot] on GitHub · 2026-10-20 06:39 UTC · original · edited 2026-10-20 06:49 UTC
On
src/graphics/host_gpu/renderer/cache/textureCache.cppline 411 (outdated):🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5177
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 21049
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 16605
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 24336
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 24920
Re-enroll tiny images after every GPU write.
TrackImageDownload()runs for color render-target and storage bindings, but not afterFindDepthTarget(),MarkGpuWritten(), orClearImage()commits a GPU write. A supported depth target can have one layer, one level, and at most 64 texels.After
ProcessDownloadImages()clears the pending set, a later write through one of these paths is absent from the next EOP readback. The EOP label can then become visible while guest memory still contains stale data. Rebinds throughFindRenderTarget()re-enroll the image, butTrackImage()andCommitGpuWrite()do not.Call
TrackImageDownload()after eachCommitGpuWrite()in these paths. Also enroll an associated stencil image when that path commits the stencil image.✅ Addressed in commit
a4d3583@coderabbitai[bot] on GitHub · 2026-10-20 06:39 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
7f1a84d1-d736-4b4f-82d7-9e706573d408📥 Commits
Reviewing files that changed from the base of the PR and between
1a053f9e13andff1ac30272.📒 Files selected for processing: 4
src/graphics/guest_gpu/command_processor/commandProcessor.hsrc/graphics/guest_gpu/graphicsRun.cppsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.hIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@MrBigBritches on GitHub · 2026-10-20 06:49 UTC · original
Fixed in
a4d3583: interrupt-only and GDS EOP paths now land pending readbacks first, and tiny images are also enrolled after depth binds, MarkGpuWritten and clears (stencil associations skipped since they can’t be downloaded standalone).@coderabbitai[bot] on GitHub · 2026-10-20 06:54 UTC · original · edited 2026-10-20 07:09 UTC
On
src/graphics/guest_gpu/graphicsRun.cppline 1144 (outdated):🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Preserve readback ordering across consecutive EOP labels.
If one EOP queues a readback, a following EOP can find no newly enrolled images and write its label directly. The guest can observe the second label before the first readback reaches guest memory. This affects both
write64and thewrite32fallback. Defer a label while an earlier priority readback remains pending, even whenQueueReadbacksBeforeLabel()returns false. The scheduler executes queued priority operations asynchronously. (raw.githubusercontent.com)✅ Addressed in commit
e11d9a0@coderabbitai[bot] on GitHub · 2026-10-20 06:54 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
acada61f-8f42-4ff0-8b50-09f5143590e8📥 Commits
Reviewing files that changed from the base of the PR and between
ff1ac30272anda4d3583cf3.📒 Files selected for processing: 4
src/graphics/guest_gpu/command_processor/commandProcessor.hsrc/graphics/guest_gpu/graphicsRun.cppsrc/graphics/host_gpu/renderer/cache/textureCache.cppsrc/graphics/host_gpu/renderer/cache/textureCache.h🚧 Files skipped from review as they are similar to previous changes: 2
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@MrBigBritches on GitHub · 2026-10-20 07:09 UTC · original
Fixed in
e11d9a0: labels deferred behind readbacks are now tracked, and while any are outstanding later labels are deferred behind them as well. Priority operations run FIFO, so labels publish in submission order.@coderabbitai[bot] on GitHub · 2026-10-20 07:17 UTC · original · reviewed
ℹ️ Review info
⚙️ Run configuration
45746562-35e8-482e-862d-87e53be7d914📥 Commits
Reviewing files that changed from the base of the PR and between
a4d3583cf3ande11d9a00d1.📒 Files selected for processing: 2
src/graphics/guest_gpu/command_processor/commandProcessor.hsrc/graphics/guest_gpu/graphicsRun.cpp🚧 Files skipped from review as they are similar to previous changes: 2
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
@MrBigBritches on GitHub · 2026-10-20 07:24 UTC · original
Fixed in
6f8fe5c: the GDS EOP path now always drains priority operations after SynchronizeGpu(), so earlier readbacks and deferred labels land before the interrupt.@coderabbitai[bot] on GitHub · 2026-10-20 07:33 UTC · original · reviewed
ℹ️ Review info
⚙️ Run configuration
89dbc997-51cd-409d-851a-37979d470737📥 Commits
Reviewing files that changed from the base of the PR and between
e11d9a00d1and6f8fe5cc24.📒 Files selected for processing: 1
src/graphics/guest_gpu/graphicsRun.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
@MrBigBritches on GitHub · 2026-10-20 07:39 UTC · original
Fixed in
f01c4cc. Failed readbacks are retried, but entries that can never be downloaded are dropped so they don’t stay pending forever. For label ordering, I gate on a texture-cache count of in-flight readbacks rather than HasPendingPriorityOperations(), which would also defer labels behind every flip and EOP interrupt.@fozter on GitHub · 2026-10-21 12:20 UTC · original
Tested #1753 with NHL 27 (PPSA34063, 01.003.001) on Windows 11, NVIDIA GeForce RTX 3060 Ti (8 GB), driver 617.42. Base: main
4644c529plus local patches that are not on main (a few NHL-specific fixes from #1101 and #1745), so this is not a clean-main result.NHL 27 does use what this PR targets: in a session from boot to the end of the first period, the new enrollment picked up 64+ distinct tiny GPU-written images, most of them 1x1 with 8 bytes per texel (exposure/statistics-style targets), and more than 4,000 enrollments.
Two problems I hit:
The deferred label write can need a buffer readback. In the first run the emulator exited in the menus with:
PublishLabelAfterReadbackswrites the label withstd::memcpyinside a priority deferred operation. In NHL 27 the label sits in a page the buffer cache tracks (the GPU writes other bytes of that 4 KiB page), so the CPU write faults andBufferCache::ReadMemoryrefuses to run from a deferred operation. What worked for me: the deferred operation only hands the write to the GPU thread (GetGpu().SendCommand(...);ProcessPm4runs pending commands between packets, and the FIFO keeps the labels in order), and the interrupt is triggered from that same command after thememcpy, so the guest cannot wake up before the label is visible. The GDS path that callsDrainPriorityOperations()then needs aProcessCommands()before it writes its own label, so earlier deferred labels still land first. With that change the game plays through a full period, and the frame pacing is unchanged within noise.shader_recompiler_compute_testsfails (it needs a GPU, so CI does not run it):The test clears a small target and then requires
!TextureCacheTestAccess::PendingDownload(...)after binding it; the newEnrollTinyReadbackinClearImageputs it intom_download_images. Either the test's expectation or the enrollment point needs adjusting.audio_out2_port_tests(from #1745) passes.AI disclosure: the analysis and the fix above were done with an AI assistant (Claude); I ran the tests and the game.
@MrBigBritches on GitHub · 2026-10-21 15:30 UTC · original
Thanks for testing with another title. I’ll take a look
@MrBigBritches on GitHub · 2026-10-21 16:17 UTC · original
Thanks for testing on NHL 27 and for the detailed write-up. Both issues are fixed in
b8d609a9:The priority callback now only hands the label write to the GPU thread (FIFO between PM4 packets), and that same command triggers the interrupt after the memcpy. The GDS path runs ProcessCommands() after DrainPriorityOperations(), so earlier deferred labels land first. I also added GuestGpu::TrySendCommand so a callback that runs after the GPU thread stops accepting work drops its label instead of exiting. ShutdownGpu now drains priority callbacks before destroying the GuestGpu.
The stencil-binding test now expects the cleared tiny target to be enrolled by the clear, and checks that the render-target prefetch leaves that unchanged.
If you get a chance to rerun NHL 27 on this head, that would be great.
@Nmzik on GitHub · 2026-10-21 18:55 UTC · original
Credited
@fozter on GitHub · 2026-10-21 19:59 UTC · original
Retested NHL 27 on
b8d609a9(same setup as before: main4644c529plus local NHL patches and #1745):shader_recompiler_compute_testspasses again (101 checks, including RenderExecutorStencilBindingDiscovery), andaudio_out2_port_testspasses.Thanks for the quick fix.
Pull request closed