mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
softgpu: Avoid atomic structs.
Apparently we don't link libatomic and rather than fighting that, I'll just use thread local values.
This commit is contained in:
parent
400f6abf9a
commit
eda3ce556e
4 changed files with 35 additions and 25 deletions
|
@ -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<PixelFuncID>()(id);
|
||||
auto last = lastSingle_.load();
|
||||
if (last.key == key)
|
||||
return last.func;
|
||||
if (lastSingle_.key == key)
|
||||
return lastSingle_.func;
|
||||
|
||||
std::unique_lock<std::mutex> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
#include "ppsspp_config.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
@ -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<size_t, SingleFunc, nullptr> cache_;
|
||||
std::unordered_map<PixelFuncID, const u8 *> addresses_;
|
||||
std::unordered_set<PixelFuncID> compileQueue_;
|
||||
std::atomic<LastEntry> lastSingle_;
|
||||
static thread_local LastCache lastSingle_;
|
||||
|
||||
const u8 *constBlendHalf_11_4s_ = nullptr;
|
||||
const u8 *constBlendInvert_11_4s_ = nullptr;
|
||||
|
|
|
@ -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<SamplerID>()(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<SamplerID>()(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<SamplerID>()(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;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
#include "ppsspp_config.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#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<size_t, NearestFunc, nullptr> cache_;
|
||||
std::unordered_map<SamplerID, const u8 *> addresses_;
|
||||
std::unordered_set<SamplerID> compileQueue_;
|
||||
std::atomic<LastEntry> lastFetch_;
|
||||
std::atomic<LastEntry> lastNearest_;
|
||||
std::atomic<LastEntry> lastLinear_;
|
||||
static thread_local LastCache lastFetch_;
|
||||
static thread_local LastCache lastNearest_;
|
||||
static thread_local LastCache lastLinear_;
|
||||
};
|
||||
|
||||
#if defined(__clang__) || defined(__GNUC__)
|
||||
|
|
Loading…
Add table
Reference in a new issue