From 579d8c7dfcfaeb44fc7a650cd151539d87eedcd2 Mon Sep 17 00:00:00 2001 From: Geoff Lang Date: Wed, 21 Jun 2017 14:56:55 -0400 Subject: [PATCH] Only use the last context for the texture completeness cache. The frequency of contexts switches is very slow compared to draw calls. Instead of doing a map lookup, only store the completeness cache for the last context used with the texture. BUG=angleproject:2078 Change-Id: Ia24c891e1b5781b61fd463ce70e90d4b394c6f8a Reviewed-on: https://chromium-review.googlesource.com/542946 Reviewed-by: Jamie Madill Reviewed-by: Corentin Wallez Commit-Queue: Geoff Lang --- src/libANGLE/Texture.cpp | 26 ++++++++------------------ src/libANGLE/Texture.h | 5 ++++- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/libANGLE/Texture.cpp b/src/libANGLE/Texture.cpp index ddbb5d482..9619087ad 100644 --- a/src/libANGLE/Texture.cpp +++ b/src/libANGLE/Texture.cpp @@ -200,30 +200,20 @@ bool TextureState::isCubeComplete() const bool TextureState::isSamplerComplete(const SamplerState &samplerState, const ContextState &data) const { - bool newEntry = false; - auto cacheIter = mCompletenessCache.find(data.getContextID()); - if (cacheIter == mCompletenessCache.end()) + if (data.getContextID() != mCompletenessCache.context || + mCompletenessCache.samplerState != samplerState) { - // Add a new cache entry - cacheIter = mCompletenessCache - .insert(std::make_pair(data.getContextID(), SamplerCompletenessCache())) - .first; - newEntry = true; + mCompletenessCache.context = data.getContextID(); + mCompletenessCache.samplerState = samplerState; + mCompletenessCache.samplerComplete = computeSamplerCompleteness(samplerState, data); } - SamplerCompletenessCache *cacheEntry = &cacheIter->second; - if (newEntry || cacheEntry->samplerState != samplerState) - { - cacheEntry->samplerState = samplerState; - cacheEntry->samplerComplete = computeSamplerCompleteness(samplerState, data); - } - - return cacheEntry->samplerComplete; + return mCompletenessCache.samplerComplete; } void TextureState::invalidateCompletenessCache() { - mCompletenessCache.clear(); + mCompletenessCache.context = 0; } bool TextureState::computeSamplerCompleteness(const SamplerState &samplerState, @@ -514,7 +504,7 @@ void TextureState::clearImageDescs() } TextureState::SamplerCompletenessCache::SamplerCompletenessCache() - : samplerState(), samplerComplete(false) + : context(0), samplerState(), samplerComplete(false) { } diff --git a/src/libANGLE/Texture.h b/src/libANGLE/Texture.h index 13c755a62..31fd0fbe7 100644 --- a/src/libANGLE/Texture.h +++ b/src/libANGLE/Texture.h @@ -160,6 +160,9 @@ struct TextureState final : private angle::NonCopyable { SamplerCompletenessCache(); + // Context used to generate this cache entry + ContextID context; + // All values that affect sampler completeness that are not stored within // the texture itself SamplerState samplerState; @@ -168,7 +171,7 @@ struct TextureState final : private angle::NonCopyable bool samplerComplete; }; - mutable std::unordered_map mCompletenessCache; + mutable SamplerCompletenessCache mCompletenessCache; }; bool operator==(const TextureState &a, const TextureState &b);