shader: walk SRT plans through compiled nodes #1287
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!1287
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1287/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-09 07:38 UTC · original
NeySlim:perf/srt-walker→main· +729 −166 · 5 files · 3 commits · closed without mergingProblem
Every draw and dispatch materializes the resources of its shaders: the SRT walker evaluates the shader's resource plan (user data, SRT reads, descriptor DWORDs) to refresh the flattened SRT and the descriptors. In God of War Ragnarök (PPSA08332, 05.005) that is about 3,700 materializations per frame (vertex and pixel shader per draw, one per dispatch), about 11.5 µs each: 43 to 46 ms per frame, about half of the GPU command thread's time.
The walker interprets the plan's IR instructions in place. Each operand goes through
Value::Resolve(identity chains), the instruction's evaluation index, then the opcode and argument fields of anInstallocated in astd::list, so every step chases pointers into scattered IR nodes. A walk evaluates about 120 values, finds about 200 more in its memo and reads about 70 SRT DWORDs; in the profile,Value::Resolvealone is 18% of the materialization samples andEvaluateWide17%.Change
ResourcePlan::WalkerNode, stored densely by evaluation index: opcode, operand references (another node, or an immediate; U32 immediates below 2^30 are held in the reference) and what the interpreter worked out on every evaluation (user data slot, raw-read acceptance, clean flag and offset, extract component, invariant phi, denormal flag of FP compares).SrtWalkerevaluates these nodes with the same rules as before: the same memo per walk and per EXEC context, the same lazy selects and logical operators, the same delegation to the clean evaluator, the same readers in the same order and the same failures. A memo hit outside an EXEC context is resolved inline. One difference on malformed IR: compilation covers every operand reachable from a root (both arms of a select, every phi input, every SRT read), so a malformed node exits even on a path the interpreter would not have evaluated. The plans built by resource tracking do not contain such nodes (SRT reads only hold instructions).walker_layout), so a nested walker that compiled nodes cannot leave an outer one reading moved arrays.memcpywithout a reader (separate commit).ExtractResourcePlankeep it across walks (walker_cached), any other plan (aProgramin the tests) compiles it again for each walk. The roots that are plain plan fields are compared with the value they were compiled from: a replaced SRT read value drops the compiled form at the start of the next walk, and a descriptor DWORD gets a new reference when it changed.Test
New cases in
resource_materialization_tests:TestWalkerFollowsInputsAcrossWalks: an extracted plan walked again with other user data, other memory contents, a replaced SRT read instruction, an appended descriptor source and a replaced descriptor DWORD gives the new values each time.TestWalkerRecompilesChangedProgram: aProgramchanged between two walks is evaluated in its new form.TestWalkerKeepsLazyReads(memory reads counted): the other operand of a select and the right operand of a logical AND after a false left one are not read, and a failed read stops its consumer before its other operand.TestBufferReadPastAddressSpaceFails: a constant-buffer DWORD past the 48-bit address space fails before reading, and the last DWORD below it is read. It fails without the check.Apart from the address check, the walker's results do not change, so the other cases also pass with the previous interpreter; they cover what the compiled form adds. Mutation check: dropping the check of SRT read values, the check of descriptor DWORDs, the per-walk compilation of other plans, the per-walk memo or select laziness each fails one of these cases.
I also ran the game with a local build that materializes every stage twice, with the previous interpreter and with the new walker, and compares descriptors, flattened SRT, captured reads, uniform fill and specialization: 22.4 million materializations from the main menu to gameplay, no difference except 2 where a second interpreter walk also differed from the first (guest memory changed between the walks).
Validation
Linux, Ryzen AI Max+ 395, Radeon 8060S, Mesa RADV 26.2.3.
dbe5353f) and on current main; the rebased walker passes the same tests and mutation checks. Per frame:(13 and 21 paired 5 s periods, about 3,700 materializations per frame.)
What remains of the materialization is mostly waiting for GPU-written SRT tables (about 11 ms per frame in these scenes, the same with both walkers) and the evaluation itself. Screenshots of the same scenes show no rendering difference.
resource_materialization_tests,resource_tracking_tests,scalar_provenance_testsandshader_cfg_testspass.shader_recompiler_compute_tests, one case per process: same results as main (602 of 612 cases pass; the same 10 fail on both on this RADV setup).ImageAtomicAnd64GlcAndExecaborted once in the full run and passed 5 reruns.Not tested on Windows or macOS; the change is platform-independent (standard C++ only).
AI use
I used Claude Code (AI agent) to profile the GPU command thread, write the change and the tests, and run the measurements and tests above on my machine. I reviewed the diff and the results before opening this PR.
@coderabbitai[bot] on GitHub · 2026-10-09 07:42 UTC · original · edited 2026-10-09 18:37 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
fa8e7c23-ae14-4a8e-b9bd-eb7707bd61a8📥 Commits
Reviewing files that changed from the base of the PR and between cb80a7d30fb8c3b5a8ffc6b31e5e4f36f2a3a55e and
1d5801e79d.📒 Files selected for processing (5)
src/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.htests/ResourceMaterializationTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.
📝 Walkthrough
Walkthrough
The resource walker now compiles reachable instructions and roots into plan-owned references and nodes. It evaluates nodes with generation-based memoization and uses cached roots for descriptor and flat-buffer refreshes. Extracted plans enable node caching. New tests cover changing pointers and memory across walks, updated program instructions, lazy reads, and reads at the 48-bit address-space boundary.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Refactor
Merge Risk: ⚪ Minimal · up to
1d580SRT resource walking now uses compiled, cached nodes for faster materialization. The author reports that behavior is preserved and tests pass. No concrete merge-blocking defects were identified.
🚥 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.@NeySlim on GitHub · 2026-10-09 09:57 UTC · original
Follow-up to an independent review, in cb80a7d3:
walker_layout) and evaluation exits if a walker evaluates without having refreshed since the last one, so a nested walker that compiled nodes cannot leave an outer one reading moved arrays. Nothing reaches that check today (all tests and the GPU suite pass unchanged); it guards the invariant.@NeySlim on GitHub · 2026-10-09 18:33 UTC · original
Rebased on current main (no conflicts) and added
1d5801e7: a constant-buffer or structured buffer DWORD past the 48-bit address space now fails before reading, like a scalar read. Found in review of #1322; the interpreter on main has the same unchecked addition. New testTestBufferReadPastAddressSpaceFails(fails without the check); description updated.@NeySlim on GitHub · 2026-10-12 15:17 UTC · original
Closing.
f848d276went the x86 way and this rewrites the interpreter instead. The God of War plans this was for (block conditions and captured reads) are now compiled on top of the x86 walker in #1456.Pull request closed