shader: read SRT words beside pending GPU writes without waiting #1828
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!1828
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1828"
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-22 11:54 UTC · original
NeySlim:perf/srt-pending-reads→main· +1773 −53 · 18 files · 6 commits · openStacked on #1456 (SRT read tables) and #1821 (unknown lists). The first three commits of this branch are those PRs; the three after them are this PR. Tested in God of War Ragnarök (PPSA08332, 05.005).
Problem
In the opening cutscene the GPU command thread, which is the limit in this game, waits 8.6-9.1 ms per frame for SRT reads of memory with pending GPU writes. Each wait submits the open command buffer and waits for the queue. Two cases wait for the same GPU work, and fixing only one moves the whole wait to the other:
The same applies to the whole-plan walker of main: in a Demon's Souls scene measured on #1456, about 5% of its read faults were on pages protected for other bytes (the other 95% read GPU-written bytes, which still need the download).
e33fa61895d03733,2567fe9c6381d11e) branch on bit 2 of a word (s_buffer_load_dwordatindex * 0xa0 + 0x8c,s_bitcmp1_b32,s_cbranch_vccnz) that an earlier dispatch in the same command buffer writes. The shader reads the word itself on the GPU; the host only evaluates the condition to prune the descriptor sources of the branch not taken, and waits for the word to do so.Change
shader: read SRT words beside GPU writes without a flush: guest loads of the SRT walker go through a guarded load, a small routine with a single guest load whose read fault the handler resumes at a failure exit (SetInstructionPointer) instead of downloading the page. The read tables of #1456 and interpreted ordinary reads use it; the whole-plan walker of main records the offsets of its own loads and shares the same exit. The walker then reads that DWORD withTryReadProtectedBacking: straight from the backing, or after a download (waiting as before) when its bytes are in the GPU-written ranges or a shader with address writes, which have no tracked range, is still in flight. The page stays protected.shader: follow both edges of conditions on pending GPU writes: block conditions are evaluated with a reader that fails instead of waiting when the word has pending GPU writes (TryReadSettledBufferBacking). A condition that cannot be read follows both edges, which is what the walker already does for a condition it cannot evaluate: the host binds the sources of both branches and the shader picks its branch on the GPU. If that larger set does not materialize,MaterializeResourcestries again with the waiting reader.shader: keep SRT unknowns that read no pending word: a value that is unknown only because a read did not wait must not stay memoized, or a later waiting read would see it as unknown. A failure counter shared by the session tells which unknowns depend on such a read; only those are marked apart and reset after the condition, also when the condition itself is known. Other unknowns keep main's memo for the session.Test
TestCompiledSrtLoadsFromProtectedPage: SRT tables on a page made unreadable, with a block plan, the same plan interpreted, and a tree plan. Values, captured reads and descriptors match an unprotected run, and no fault falls back to unprotecting the page. Fails when faults of guarded loads are not resumed, when the read table loads without the guard, or when a faulting read keeps its captured address.CheckProtectedSrtRead(GPU, also--protected-srt-read-only): a word beside a pending GPU write is read without a download, a GPU-written word is downloaded, and address writes in flight make the read wait. Fails if the reader always downloads, or ignores address writes.TestPendingConditionFollowsBothEdges: branch on a memory word, source in the branch or after the join, word pending or not, branch slot failing or not; checks the reader used, visited blocks, flat SRT, bound sources, captured reads and the retry. Fails if conditions wait.TestNoWaitUnknownsKeepTheirMemo: an unknown that read no pending word keeps its memo, one that read a pending word is reset, also inside a known condition (a || bwithapending). Fails without the last commit.Without their source changes the tests of the first two commits do not compile.
Validation
Linux, Radeon 8060S (RDNA 3.5), Mesa RADV 26.2.5.
shader_recompiler_compute_testsone case per process: same results as main plus the new case (784 of 848 pass, main 783 of 847).Not tested on Windows.
SetInstructionPointersetsCONTEXT::Ripthere (__ss.__ripon macOS), and the CPU tests only useHostExceptionandVirtualMemory. If #1254 lands first,NoteAddressWritescan go: itsRecordPendingWritesalready records the tick of address writes.AI use
I used Claude Code (AI agent) to profile the GPU thread, write the changes and the tests, and run the tests and game runs above on my machine. I reviewed the code and the results.
@coderabbitai[bot] on GitHub · 2026-10-22 12:02 UTC · original · edited 2026-10-23 17:40 UTC
📝 Walkthrough
The SRT walker now compiles eligible scalar and descriptor reads and supports non-waiting condition evaluation. GPU backing readers account for dirty ranges and in-flight shader address writes. Protected-load faults can resume at a generated failure exit. New tests cover compiled reads, conditional traversal, protected pages, and pending GPU writes.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Refactor
Merge Risk: 🟡 Moderate · up to
8e191Protected SRT reads can observe stale backing, and a pending branch can abort binding setup. Resolve these paths before merging unless their impact is explicitly accepted.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 17.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 86 functions across 16 files. (2 skipped: 1 unsupported, 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
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.@ -874,0 +879,4 @@auto& buffers = GetGpuResources().GetBufferCache();// Shader address writes are not tracked by range: they may change any byte.if (buffers.HasGpuDirtyBytes(vaddr, size) || buffers.HasAddressWritesInFlight()) {buffers.ReadMemory(vaddr, size);@coderabbitai[bot] on GitHub · 2026-10-22 12:02 UTC · original · edited 2026-10-23 17:42 UTC
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Wait for shader address writes before reading protected backing.
If an address write is in flight but the requested bytes have no dirty range,
ReadMemoryfinds no download copies and returns before its scheduler wait.TryReadProtectedBackingthen reads backing that the pending write can change. Wait for the address-write tick and ensure affected buffer bytes reach backing before returning them. A wait alone does not supply the missing readback.@coderabbitai[bot] on GitHub · 2026-10-22 12:02 UTC · original · edited 2026-10-23 17:43 UTC
On
src/kernel/memory.cppline 890 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Reject non-waiting reads while address writes are in flight.
If a shader address write targets a mapped SRT value, it leaves no dirty range. This check then accepts the backing read while that write is pending, so a condition can use the old value instead of taking the non-waiting fallback. Include
HasAddressWritesInFlight()in the rejection check.✅ Confirmed as addressed by @NeySlim
@coderabbitai[bot] on GitHub · 2026-10-22 12:02 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
fdcfd2af-1f0c-4a9b-a882-167032c06cb9📥 Commits
Reviewing files that changed from the base of the PR and between
c5016d9455and 32fb5cf9dd0dfaa3b644dea15ca5329de1610939.📒 Files selected for processing: 18
CMakeLists.txtsrc/common/hostException.cppsrc/common/hostException.hsrc/graphics/host_gpu/renderer/cache/bufferCache.cppsrc/graphics/host_gpu/renderer/cache/bufferCache.hsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/host_gpu/renderer/renderContext.cppsrc/graphics/host_gpu/renderer/renderContext.hsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/SrtWalker.cppsrc/graphics/shader/recompiler/ir/passes/SrtWalker.hsrc/kernel/memory.cppsrc/kernel/memory.hsrc/loader/runtimeLinker.cpptests/ResourceMaterializationTests.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ -874,0 +879,4 @@auto& buffers = GetGpuResources().GetBufferCache();// Shader address writes are not tracked by range: they may change any byte.if (buffers.HasGpuDirtyBytes(vaddr, size) || buffers.HasAddressWritesInFlight()) {buffers.ReadMemory(vaddr, size);@NeySlim on GitHub · 2026-10-23 17:34 UTC · original
This matches the regular fault path: a read fault on a protected page calls the same
ReadMemoryand then reads backing. Address writes are not downloaded anywhere today since they leave no dirty range, so waiting here would not bring their bytes back either. Making them visible to the CPU is a separate change from this PR.@NeySlim on GitHub · 2026-10-23 17:34 UTC · original
On
src/kernel/memory.cppline 890 (outdated):Right, fixed: the settled reader now fails while address writes are in flight, so the condition falls back to the waiting read. Added checks for it in
ProtectedSrtRead.@coderabbitai[bot] on GitHub · 2026-10-23 17:40 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
3f589e58-8c89-4799-a707-b91cd52f030f📥 Commits
Reviewing files that changed from the base of the PR and between 79c90a0eb85315f774f0132234380a02a794ae5d and
8e19144b97.📒 Files selected for processing: 11
CMakeLists.txtsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/host_gpu/renderer/renderContext.cppsrc/graphics/host_gpu/renderer/renderContext.hsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/SrtWalker.hsrc/kernel/memory.cpptests/ResourceMaterializationTests.cpptests/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.
@ -1569,2 +1571,4 @@bool MaterializeResources(const ResourcePlan& program, const SrtRuntime& runtime,ResourceSnapshot& snapshot, ResourceSpecialization& specialization) {if (MaterializeOnce(program, runtime, snapshot, specialization)) return true;@coderabbitai[bot] on GitHub · 2026-10-23 17:40 UTC · original
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
Retry when speculative bindings fail the read/write overlap check.
If a pending condition follows both edges, one edge can capture a scalar read while the other binds a buffer write to the same range.
MaterializeOncecan succeed, so this return skips the waiting retry.RenderExecutor::CommitBindingsthen callsEXITon the overlap atsrc/graphics/host_gpu/renderer/pipeline/descriptors.cppLines 941-977, even when the actual branch uses only one edge. Check the speculative resource set before accepting it, and retry with the waiting reader when the extra edge causes this conflict.@ -874,0 +879,4 @@auto& buffers = GetGpuResources().GetBufferCache();// Shader address writes are not tracked by range: they may change any byte.if (buffers.HasGpuDirtyBytes(vaddr, size) || buffers.HasAddressWritesInFlight()) {buffers.ReadMemory(vaddr, size);@coderabbitai[bot] on GitHub · 2026-10-23 17:42 UTC · original
@NeySlim You're right. This path preserves the regular fault path’s behavior. My finding incorrectly treated the existing lack of address-write readback as a defect introduced by this PR. A wait alone would not make those bytes available in backing memory.
I withdraw this finding. CPU visibility for shader address writes belongs in a separate change. Would you like me to open a follow-up issue?
✅ Review thread resolved.
You are interacting with an AI system.
@coderabbitai[bot] on GitHub · 2026-10-23 17:43 UTC · original
On
src/kernel/memory.cppline 890 (outdated):@NeySlim The updated
TryReadSettledBufferBackingrejects reads whenHasAddressWritesInFlight()is true. This addresses the stale backing-read concern. Thanks for adding the regression checks.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.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.