Repository navigation
vk: cache sampler_for's samplers until a sampler registration changes - #901
Merged
Merged
Conversation
…hanges Each texture of each draw found its sampler through reg_mu, a copy of the registration, a hash of it and a map lookup: ~48,000 times a frame at ~3,000 draws. sampler_for now keeps a thread table by id and compare, good while no sampler registration's contents changed (a new generation in vk_bank.cpp, bumped only when register_sampler_copy writes different contents). RX_VK_SAMPLER_CACHE=0: off, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
sampler_for(vk_draw.cpp) runs for every texture slot of every descriptor build. Each call tookreg_muinsampler_of, copied the sampler registration, hashed it word by word and looked the hash up in a thread map: ~48,000 times a frame at ~3,000 draws.It now keeps a thread table indexed by
[compare][id](ids are 12 bits), stamped with a new sampler registration generation (vk_bank.cpp).register_sampler_copybumps that generation only when the registration's contents change, so rewrites of the same sampler don't empty the cache. The generation is read before the lookup, so a registration that lands during a miss makes the next call miss again. Samplers are never destroyed (as the existing per-thread map already assumes), so a cachedVkSamplerstays valid.RX_VK_SAMPLER_CACHE=0turns it off. 24 lines in two files; no shader stamp change (neither file is translator input).Tested
main(b234b43) with the release builder's llvm-mingw toolchain (nx2/build.py --standalone,RX_VK_ONLY=1).RX_VK_PROF_FINE"textures" section 1.76 -> 1.17 ms a frame. No visual issues, no device errors, an area load recovered to 60 quickly.Context and the full profile: #384.
🤖 Generated with Claude Code