graphics: index the SRT evaluator memo by dense plan slots #628
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!628
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/628/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?
@MehmetCambaz on GitHub · 2026-09-15 23:37 UTC · original
MehmetCambaz:perf/srt-dense-memo→main· +1271 −15 · 7 files · 4 commits · closed without mergingMotivation
MaterializeResourcesruns the SRT evaluator repeatedly to resolve descriptorsources, flat SRT reads and clean-slot values. Memoization used a
std::pmr::unordered_map<const Inst*, uint64_t>, so every memo access hashed apointer and walked a bucket, and every evaluation built and tore down a map.
ResourcePlanconstruction is rare compared with evaluation, andExtractResourcePlanalready clones the reachable instruction graph into stableper-plan storage. Numbering those instructions during extraction moves work out
of the hot path and into the plan build.
Implementation
ExtractResourcePlanhands each instruction it clones a densememo_slot(
plan.memo_slot_count++), unique within the plan. Anything it did not clonekeeps
Inst::NoMemoSlot.Evaluation memoizes into a generation-stamped array instead of a hash map. The
arrays live in thread-local arenas leased per evaluator; each evaluator takes a
fresh generation, so invalidation is O(1) and the main evaluator, the clean
evaluator and every
ReadFirstLanechild keep the separate memo namespaces theyhad with private maps.
Correctness
Dense slot numbers are local to a
ResourcePlan, so a slot number alone does notidentify an instruction - two plans hand the same number to different
instructions. A memo entry therefore records the
Inst*that claimed it, and isreused only when its generation is current and its owner matches. An
instruction from another plan may claim a slot that is free in the current
generation; once another instruction owns that slot it falls back to the
pointer-keyed memo. Values outside the evaluator's plan keep exactly the
pointer-distinct semantics they had before.
Other points worth noting:
memo_slotis assigned only during plan extraction; nothing else sets it.ResourcePlan::value_storageis astd::list<Inst>, so owner pointers stayvalid across plan moves, and
Instcopy/move are deleted.never names an instruction that has since been destroyed.
thread_local; no memo state is shared between threads.inputs are re-read every time.
ReadConstresolves against theevaluator's plan, so evaluating one from another plan can recurse into a local
instruction that claims the equally numbered slot first.
Performance
Focused testing against the base showed roughly a one-third reduction in
EvaluateRuntimeSourcesandMaterializeResourcesCPU cost.EvaluateRuntimeSourcesMaterializeResourcesIn a same-process paired capture on a commercial title, every usable pair
favoured the dense memo:
EvaluateRuntimeSourcesMaterializeResourcesControl metrics outside the modified evaluator stayed comparatively flat. These
are normalized subsystem timings, not an FPS measurement; the effect on frame
rate depends entirely on whether a given workload is bound by this path.
Testing
tests/SrtEvaluatorMemoTests.cppruns each evaluation three ways - dense slots,the map with pooled storage, and the map with unpooled storage - and requires
identical return status, outputs and guest reader-call order, so the dense memo
is held to the map's behaviour case by case. Coverage includes reused arenas,
generation wrap across plans of different slot counts, cross-plan slot
collisions, recursive slot claims, mixed dense/foreign graphs,
ReadFirstLane,the clean evaluator, failure and recovery, allocation failure, thread exit and
concurrent evaluation.
srt_evaluator_memo- pass (1204 checks)resource_materialization- passresource_tracking- passSome other test targets are currently unavailable on this revision due to
unrelated pre-existing build and link failures (
shader_recompiler_compute_testsreferences a removed
RenderContext::GetGpuResources();kernel_file_systemfails to link against SDL's
main).AI assistance was used during investigation, implementation and testing. I reviewed the resulting change and validation before submitting it.
Summary by CodeRabbit
Performance
Reliability
Tests
@coderabbitai[bot] on GitHub · 2026-09-15 23:37 UTC · original · edited 2026-09-15 23:49 UTC
📝 Walkthrough
Walkthrough
The change adds dense memo slots to resource plans and instructions. The SRT evaluator now uses reusable generation-stamped memo arenas with fallback maps. Test hooks and a standalone CTest executable validate memoization behavior across multiple evaluation scenarios.
Changes
SRT evaluator memoization
src/graphics/shader/recompiler/ir/ShaderIR.h,src/graphics/shader/recompiler/ir/Value.h,src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppResourcePlantracks dense memo slots.Instexposes slot accessors. Resource-plan extraction assigns slots to cloned instructions.src/graphics/shader/recompiler/ir/passes/SrtWalker.cpp,src/graphics/shader/recompiler/ir/passes/SrtWalker.hEvaluatoruses generation-stamped dense memo arenas and PMR fallback maps. Ownership checks preserve results for conflicting or foreign instructions. Test hooks control memo resources, dense mode, and generations.tests/SrtEvaluatorMemoTests.cpp,CMakeLists.txtPriority: ⬇️ Low
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Refactor
Sequence Diagram(s)
Suggested reviewers:
nmzikMerge Risk: 🔵 Low · up to
5d946The new memoization test may not link on some supported Linux toolchains. This is a localized build issue and straightforward to fix.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 14.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 90 functions across 6 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-09-15 23:49 UTC · original · reviewed
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID:
67c20e45-b4b2-460c-9896-e3dc4fd392c2📥 Commits
Reviewing files that changed from the base of the PR and between
e6156bef05and5d946865aa.📒 Files selected for processing (7)
CMakeLists.txtsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/Value.hsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/SrtWalker.cppsrc/graphics/shader/recompiler/ir/passes/SrtWalker.htests/SrtEvaluatorMemoTests.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -459,0 +466,4 @@target_link_libraries(srt_evaluator_memo_tests fmt::fmt)target_include_directories(srt_evaluator_memo_tests PRIVATE ${inc_headers})target_compile_definitions(srt_evaluator_memo_tests PRIVATE KYTY_SRT_TEST_HOOKS=1)@coderabbitai[bot] on GitHub · 2026-09-15 23:49 UTC · original
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Link
srt_evaluator_memo_testswithThreads::Threadson Linux.SrtEvaluatorMemoTests.cppcreatesstd::threadinstances. The Linuxfind_package(Threads REQUIRED)setup addsThreads::Threadsonly tokyty_emulator_link_libraries. This target links onlyfmt::fmt, which provides no thread-link dependency. On supported Linux toolchains that require explicit pthread linkage, the test can fail to link with an undefined reference topthread_create.🤖 Prompt for AI Agents
@Nmzik on GitHub · 2026-10-03 13:41 UTC · original
I think its stale :) A lot of rewrites happened
Pull request closed