perf(recompiler): memoize SRT evaluation in a flat table and inline IrValue's hot accessors #415
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/415"
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?
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T22:06:20Z.
What
Every draw stage's capture walks the shader's SRT plan with
Detail::Evaluator. Its per-value memo was astd::unordered_map<IrValue*, std::uint64_t>: one node allocation per evaluated value. Every step of the walk also made out-of-line calls toIrValue::Opcode,IsIdentity,ResolveandArgument. In a profile of my integration branch at PPSA21564's title, the walk took about 17 us of every capture, about 1.25 s of the graphics queue worker's 10 s.Detail::EvaluatedValues, an open-addressing table keyed by the value pointer (linear probing, power-of-two size starting at 64, grown at half load).Insertkeeps the first value for a key, asemplacedid, and failed evaluations are still not memoized.IrValue::Opcode,Type,HasImmediate,IsIdentity,ArgumentCount,ArgumentandResolvemove to the header as inline definitions, unchanged, including their throws.<unordered_map>is no longer used bySrtEvaluator.hppand is dropped.Evaluation order, results and failures are unchanged. In the same profile the capture walk drops to about 10 us (title capture total about 1.25 s to 0.7 s per 10 s).
Test:
verifyEvaluatedValuesinagc_shader_memory_testsinserts 1000 keys (several grows), finds each with its value (including a stored 0), checks that a second insert does not replace the first, and that empty tables and absent keys find nothing. The existing SRT walker tests cover the evaluator itself.Relation to #218 (slick-daddy, "cut hot-path overhead in recompile cache lookups"): the two are complementary. #218 changes the evaluator's cycle stack (
_visiting, a vector to anunordered_set) and the cache key, snapshot hash and memo lookups inRecompiler.cpp. This PR changes the evaluator's value memo (_cache) and theIrValueaccessors. They touch adjacent lines inSrtEvaluator.hpponly: the member pair and the include block. Whichever lands second resolves toEvaluatedValues _cache;beside #218'sstd::unordered_set<IrValue*> _visiting;, with<unordered_set>kept.SrtEvaluator.cppmerges cleanly.Shader disk cache: on
mainthe cache'sSourceVersionis a hash of the recompiler and AGC driver sources, so this change, like any edit there, gives a new version and cached shaders are recompiled once. The disk key format and the cached data are unchanged.Tested
ctest125/125 pass, including the newverifyEvaluatedValuesinagc_shader_memory_tests.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T23:47:25Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtEvaluator.hppL9, L36-37