shader: run SRT slot and descriptor reads of block plans from a table #1456
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!1456
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1456/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-12 15:17 UTC · original
NeySlim:perf/srt-jit-blocks→main· +882 −5 · 4 files · 2 commits · closed without mergingFollow-up to
f848d276. Tested in God of War Ragnarok (PPSA08332, 05.005).The x86 SRT walker only takes flat plans. In God of War Ragnarok 86-88% of stage walks are plans with block conditions and captured reads, so they all go through the interpreter, even though their reads have the shape the walker already handles (
LoadAddressU32at a constant offset under user-data pointers or a parent table). Only 7-9% of walks use the compiled path, andRefreshFlatBuffercosts 27-35 ms per frame on the GPU command thread. The descriptors of these plans are also evaluated one DWORD at a time by the interpreter.Change
shader: run SRT slot reads of block and captured plans from a table: when the whole-plan walker rejects a plan, each SRT slot read is compiled into a small data table (ResourcePlan::SrtReadTable): one record per memoized read, with its pointer words (user data or another record) and its constant offset. A short loop runs the records with the same order, bounds, 48-bit mask, alignment, memo and captured addresses asEvaluateRawRead.RefreshFlatBufferstill walks blocks and conditions in C++ and runs the table for those slots. Clean reads and other shapes stay interpreted. If a table read fails, the interpreter evaluates the slot again, so failures behave as before.shader: read SRT descriptors and constant buffers from the read table: a descriptor whose DWORDs are all such reads, user data or immediates gets an entry in the same table, also for plans the whole-plan walker takes.ReadConstBufferreads with a constant or shifted-index offset become records too, with the walker's bounds (records, or stride * records bytes). An out-of-bounds constant-buffer DWORD fails the table read and the interpreter returns 0 for it, as on main.The first version of this PR generated x86 code per plan. Profiling the GPU command thread in game showed that code was limited by the front end, not by memory: 24% of the thread's cycles for 4% of its micro-ops, 98% of its loads hitting L1, samples spread over about 11,000 addresses on 2,100 code pages. Every plan had its own code buffer, so each materialization (about 2,000 per frame) ran cold code. The table loop stays hot, is faster in game (below) and adds no generated code; the whole-plan walker is unchanged.
Test
TestCompiledSrtReadsFollowBlocks(from the first version): a plan with a memory-dependent branch and a nested table, both branches compared with the interpreter (flat DWORDs, captured and strict reads, memo reuse, truncated user data, address underflow/overflow).TestCompiledSrtDescriptorReads: compiled descriptors against the interpreter (values, captured reads and their order, strict reads), memo reuse after a compiled slot, truncated user data, address underflow and overflow, constant-buffer bounds with and without stride, shifted index overflow.TestCompiledSrtReadTable: table layout (one record per shared read, order, descriptor words) and 540 stride, records, index and truncated user data configurations compared with the interpreter (success, values, descriptors, captured reads).Performance
God of War Ragnarok, new game, warm caches, on top of my other open PRs (main alone does not get in game), same build except this PR. Fps, and CPU time of the GPU command thread per frame:
Means of 2, 4, 3 and 6 runs, each run within 0.4 fps of its mean. The stack has none of the later SRT changes (#1828 and after), so the frame rates are lower than in my other PRs. The later Freya window is not comparable (deaths and tip screens at different times).
Not tested on Windows. Nothing platform specific is added: no generated code, no calling convention. The Windows run on this PR was on the first version; the tests are the same plus the descriptor and table ones.
AI use
I used Claude Code to write the change and the tests and to run the measurements above. I reviewed the code and the results before opening the PR.
@coderabbitai[bot] on GitHub · 2026-10-12 15:23 UTC · original · edited 2026-10-22 19:53 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
8f5de54b-f5db-4794-9073-e8dc1f65628f📥 Commits
Reviewing files that changed from the base of the PR and between 9fc67da73d0be0178872edd3f71a3dff353344d8 and
9b9ede47b4.📒 Files selected for processing: 4
src/graphics/shader/recompiler/ir/ShaderIR.hsrc/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; 7 remain after this review.
📝 Walkthrough
The resource plan now stores compiled SRT read tables and per-slot entry maps. The compiler builds entries for eligible reads and descriptor words. SrtWalker evaluates compiled entries when memory access and capture conditions allow, and uses interpreted evaluation when compiled evaluation is unavailable or fails. Tests compare compiled and interpreted results across control-flow, descriptor, and address-boundary cases.
Suggested reviewers:
nmzikPriority: ⬆️ High
Change: Feature
Merge Risk: ⚪ Minimal · up to
9b9edThis change compiles SRT slot and descriptor reads into a table-driven path and falls back to the existing interpreter when a compiled read fails. No actionable merge-blocking risk was found. The reported tests and in-game comparisons support parity with the interpreted path.
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.@Nawid3333 on GitHub · 2026-10-20 18:09 UTC · original
Tested this on Windows, since that was still open: 9fc67da7 applied cleanly on main
7b7f9a70, Windows 11, clang-cl 19.1.5, Release, RX 9070 XT and Ryzen 7600X iGPU.resource_materialization_tests(with the newTestCompiledSrtReadsFollowBlocks),resource_tracking_testsandshader_cfg_testspass; the last two print the same output as on main.KYTY_SYSV_ABIcall), I made a memo hit return the entry's generation instead of its value:resource_materialization_teststhen crashes, so the compiled path runs and the test catches a broken routine.IndirectBufferStorefailure on this GPU).I also measured it in Demon's Souls (PPSA01341, main
0cad4672plus #1630 to get past #1660, a CPU-bound character-creation scene at about 6 fps on a Ryzen 7600X), two runs each, both sides with the same lab counters aroundRefreshFlatBuffer:@NeySlim on GitHub · 2026-10-20 19:39 UTC · original
Thanks for the Windows run, that was the missing piece. Makes sense for Demon's Souls: GoW spends its time in the interpreted walk, DeS in the whole-plan walker. I'll look at that one separately.
@Nawid3333 on GitHub · 2026-10-20 20:20 UTC · original
@NeySlim I measured the whole-plan walker in that Demon's Souls scene with counters around the compiled call and in the fault handler: about 99% of its time is spent in page faults on its guest reads, each followed by a buffer readback (about 2 ms). Without the faults a walk takes under 1 µs. About 95% of those faults read bytes that the buffer cache tracks as GPU-modified, so the readback itself is needed there; only about 5% are pages protected for other bytes. So the cost is the readback of GPU-written SRT data, not the walker code. #1254 lowers the CPU waits in that scene a lot but not these readbacks (numbers on #1254).
@NeySlim on GitHub · 2026-10-22 19:49 UTC · original
I reworked this one: the compiled reads are now a data table run by a small loop instead of x86 code generated per plan. A profile of the GPU command thread showed the generated code was bound by the front end (each plan had its own code buffer, so every materialization ran cold code), and the table is faster in game: in the opening cutscene the GPU command thread goes from 53.6 to 48.3 ms per frame with the slots alone, and to 45.5 ms with the descriptors (15.6 -> 17.6 fps). It also removes the platform question, since nothing is generated or called with a special ABI anymore. I moved the descriptor reads from #1828 in here too, as they use the same table. @Nawid3333 your Windows run was on the old version; the tests are the same plus the descriptor and table ones, in case you want to run them again.
@Nawid3333 on GitHub · 2026-10-22 23:39 UTC · original
@NeySlim I reran it on Windows with the table version:
9b9ede47(both commits) applied cleanly on main79837b42, Windows 11, clang-cl 19.1.5, Release, RX 9070 XT and Ryzen 7600X iGPU.resource_materialization_testspasses, including the three new tests (TestCompiledSrtReadsFollowBlocks,TestCompiledSrtDescriptorReads,TestCompiledSrtReadTable).resource_tracking_testsandshader_cfg_testspass and print the same output as on main.I also ran it in Demon's Souls (PPSA01341, the character-creation scene from my earlier comment): main
79837b42+ #1630 (to get past #1660), with and without this PR, two 11-minute runs each with the same input script.@NeySlim on GitHub · 2026-10-23 17:34 UTC · original
Thanks for rerunning it, and for the two deliberate bugs, that's a good check of the table path. No regression in Demon's Souls is what I wanted to see; as you say that scene is bound by the readbacks, not the walk.
@NeySlim on GitHub · 2026-10-24 22:56 UTC · original
Closing this. The x86 SRT walker now on main (
d7856753e) covers it, and on GoW Ragnarök it gives the same frame rate as this branch, so there is nothing left to land here.Pull request closed