Repository navigation
perf(recompiler): memoize SRT evaluation in a flat table and inline IrValue's hot accessors - #415
Merged
oneandonlydean merged 1 commit intoOct 3, 2026
Conversation
…rValue's hot accessors Every draw stage's capture walks the shader's SRT plan with an Evaluator whose per-value memo was a std::unordered_map: a node allocation per evaluated value, and out-of-line calls for Opcode, IsIdentity, Resolve and Argument on every step. The walk took ~17 us of every capture at PPSA21564's title (about 1.25 s of the queue worker's 10 s). The memo is now an open-addressing table keyed by the value pointer, and the accessors are inline. Evaluation order, results and failures are unchanged. The capture walk drops to ~10 us.
9 tasks done
9 tasks done
|
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.
|
8 of 9 tasks
oneandonlydean
added a commit
to oneandonlydean/AnyPS5
that referenced
this pull request
Oct 3, 2026
…heir PR heads The code of the three open PRs is unchanged on their heads apart from the opt-outs and comments astrobot keeps. Their heads add tests: boykopovar#415's EvaluatedValues table test (and drops an unused include), boykopovar#417's flip test releases its GPU work without an interrupt select, and boykopovar#418's linux_entry_argv relinks a fixture whose entry checks argc and argv.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)