diff --git a/GPU/Software/DrawPixel.cpp b/GPU/Software/DrawPixel.cpp index 60a96b8450..306522312d 100644 --- a/GPU/Software/DrawPixel.cpp +++ b/GPU/Software/DrawPixel.cpp @@ -744,6 +744,8 @@ SingleFunc PixelJitCache::GenericSingle(const PixelFuncID &id) { return nullptr; } +thread_local PixelJitCache::LastCache PixelJitCache::lastSingle_; + // 256k should be plenty of space for plenty of variations. PixelJitCache::PixelJitCache() : CodeBlock(1024 * 64 * 4), cache_(64) { } @@ -792,14 +794,13 @@ SingleFunc PixelJitCache::GetSingle(const PixelFuncID &id, BinManager *binner) { return nullptr; const size_t key = std::hash()(id); - auto last = lastSingle_.load(); - if (last.key == key) - return last.func; + if (lastSingle_.key == key) + return lastSingle_.func; std::unique_lock guard(jitCacheLock); auto it = cache_.Get(key); if (it != nullptr) { - lastSingle_ = { key, it }; + lastSingle_.Set(key, it); return it; } @@ -826,7 +827,7 @@ SingleFunc PixelJitCache::GetSingle(const PixelFuncID &id, BinManager *binner) { Compile(id); it = cache_.Get(key); - lastSingle_ = { key, it }; + lastSingle_.Set(key, it); return it; } diff --git a/GPU/Software/DrawPixel.h b/GPU/Software/DrawPixel.h index bafde030aa..4bcbf3e834 100644 --- a/GPU/Software/DrawPixel.h +++ b/GPU/Software/DrawPixel.h @@ -19,7 +19,6 @@ #include "ppsspp_config.h" -#include #include #include #include @@ -110,15 +109,20 @@ private: bool Jit_ConvertFrom5551(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha); bool Jit_ConvertFrom4444(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha); - struct LastEntry { + struct LastCache { size_t key; SingleFunc func; + + void Set(size_t k, SingleFunc f) { + key = k; + func = f; + } }; DenseHashMap cache_; std::unordered_map addresses_; std::unordered_set compileQueue_; - std::atomic lastSingle_; + static thread_local LastCache lastSingle_; const u8 *constBlendHalf_11_4s_ = nullptr; const u8 *constBlendInvert_11_4s_ = nullptr; diff --git a/GPU/Software/Sampler.cpp b/GPU/Software/Sampler.cpp index f2a80fddc6..9ad7e9a169 100644 --- a/GPU/Software/Sampler.cpp +++ b/GPU/Software/Sampler.cpp @@ -98,6 +98,10 @@ FetchFunc GetFetchFunc(SamplerID id, BinManager *binner) { return &SampleFetch; } +thread_local SamplerJitCache::LastCache SamplerJitCache::lastFetch_; +thread_local SamplerJitCache::LastCache SamplerJitCache::lastNearest_; +thread_local SamplerJitCache::LastCache SamplerJitCache::lastLinear_; + // 256k should be enough. SamplerJitCache::SamplerJitCache() : Rasterizer::CodeBlock(1024 * 64 * 4), cache_(64) { } @@ -190,12 +194,11 @@ NearestFunc SamplerJitCache::GetNearest(const SamplerID &id, BinManager *binner) return nullptr; const size_t key = std::hash()(id); - auto last = lastNearest_.load(); - if (last.key == key) - return (NearestFunc)last.func; + if (lastNearest_.key == key) + return (NearestFunc)lastNearest_.func; auto func = GetByID(id, key, binner); - lastNearest_ = { key, func }; + lastNearest_.Set(key, func); return (NearestFunc)func; } @@ -204,12 +207,11 @@ LinearFunc SamplerJitCache::GetLinear(const SamplerID &id, BinManager *binner) { return nullptr; const size_t key = std::hash()(id); - auto last = lastLinear_.load(); - if (last.key == key) - return (LinearFunc)last.func; + if (lastLinear_.key == key) + return (LinearFunc)lastLinear_.func; auto func = GetByID(id, key, binner); - lastLinear_ = { key, func }; + lastLinear_.Set(key, func); return (LinearFunc)func; } @@ -218,12 +220,11 @@ FetchFunc SamplerJitCache::GetFetch(const SamplerID &id, BinManager *binner) { return nullptr; const size_t key = std::hash()(id); - auto last = lastFetch_.load(); - if (last.key == key) - return (FetchFunc)last.func; + if (lastFetch_.key == key) + return (FetchFunc)lastFetch_.func; auto func = GetByID(id, key, binner); - lastFetch_ = { key, func }; + lastFetch_.Set(key, func); return (FetchFunc)func; } diff --git a/GPU/Software/Sampler.h b/GPU/Software/Sampler.h index 96e9d4c4a8..cb989e6a32 100644 --- a/GPU/Software/Sampler.h +++ b/GPU/Software/Sampler.h @@ -19,7 +19,6 @@ #include "ppsspp_config.h" -#include #include #include #include "Common/Data/Collections/Hashmaps.h" @@ -129,17 +128,22 @@ private: const u8 *const5551Swizzle_ = nullptr; const u8 *const5650Swizzle_ = nullptr; - struct LastEntry { + struct LastCache { size_t key; NearestFunc func; + + void Set(size_t k, NearestFunc f) { + key = k; + func = f; + } }; DenseHashMap cache_; std::unordered_map addresses_; std::unordered_set compileQueue_; - std::atomic lastFetch_; - std::atomic lastNearest_; - std::atomic lastLinear_; + static thread_local LastCache lastFetch_; + static thread_local LastCache lastNearest_; + static thread_local LastCache lastLinear_; }; #if defined(__clang__) || defined(__GNUC__)