softjit: Switch to DenseHashMap.

This commit is contained in:
Unknown W. Brackets 2022-12-02 20:59:13 -08:00
parent 7dee26eae4
commit 778a0487cb
4 changed files with 46 additions and 32 deletions

View File

@ -744,12 +744,12 @@ SingleFunc PixelJitCache::GenericSingle(const PixelFuncID &id) {
}
// 256k should be plenty of space for plenty of variations.
PixelJitCache::PixelJitCache() : CodeBlock(1024 * 64 * 4) {
PixelJitCache::PixelJitCache() : CodeBlock(1024 * 64 * 4), cache_(64) {
}
void PixelJitCache::Clear() {
CodeBlock::Clear();
cache_.clear();
cache_.Clear();
addresses_.clear();
constBlendHalf_11_4s_ = nullptr;
@ -777,8 +777,12 @@ std::string PixelJitCache::DescribeCodePtr(const u8 *ptr) {
void PixelJitCache::Flush() {
std::unique_lock<std::mutex> guard(jitCacheLock);
for (const auto &queued : compileQueue_)
Compile(queued);
for (const auto &queued : compileQueue_) {
// Might've been compiled after enqueue, but before now.
size_t queuedKey = std::hash<PixelFuncID>()(queued);
if (!cache_.Get(queuedKey))
Compile(queued);
}
compileQueue_.clear();
}
@ -787,10 +791,11 @@ SingleFunc PixelJitCache::GetSingle(const PixelFuncID &id, std::function<void()>
return nullptr;
std::unique_lock<std::mutex> guard(jitCacheLock);
const size_t key = std::hash<PixelFuncID>()(id);
auto it = cache_.find(id);
if (it != cache_.end()) {
return it->second;
auto it = cache_.Get(key);
if (it != nullptr) {
return it;
}
if (!flushForCompile) {
@ -803,16 +808,17 @@ SingleFunc PixelJitCache::GetSingle(const PixelFuncID &id, std::function<void()>
flushForCompile();
guard.lock();
for (const auto &queued : compileQueue_)
Compile(queued);
for (const auto &queued : compileQueue_) {
// Might've been compiled after enqueue, but before now.
size_t queuedKey = std::hash<PixelFuncID>()(queued);
if (!cache_.Get(queuedKey))
Compile(queued);
}
compileQueue_.clear();
Compile(id);
it = cache_.find(id);
if (it != cache_.end())
return it->second;
return nullptr;
return cache_.Get(key);
}
void PixelJitCache::Compile(const PixelFuncID &id) {
@ -824,7 +830,7 @@ void PixelJitCache::Compile(const PixelFuncID &id) {
#if PPSSPP_ARCH(AMD64) && !PPSSPP_PLATFORM(UWP)
addresses_[id] = GetCodePointer();
SingleFunc func = CompileSingle(id);
cache_[id] = func;
cache_.Insert(std::hash<PixelFuncID>()(id), func);
#endif
}

View File

@ -24,6 +24,7 @@
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include "Common/Data/Collections/Hashmaps.h"
#include "GPU/Math3D.h"
#include "GPU/Software/FuncId.h"
#include "GPU/Software/RasterizerRegCache.h"
@ -107,7 +108,7 @@ 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);
std::unordered_map<PixelFuncID, SingleFunc> cache_;
DenseHashMap<size_t, SingleFunc, nullptr> cache_;
std::unordered_map<PixelFuncID, const u8 *> addresses_;
std::unordered_set<PixelFuncID> compileQueue_;

View File

@ -98,12 +98,12 @@ FetchFunc GetFetchFunc(SamplerID id, std::function<void()> flushForCompile) {
}
// 256k should be enough.
SamplerJitCache::SamplerJitCache() : Rasterizer::CodeBlock(1024 * 64 * 4) {
SamplerJitCache::SamplerJitCache() : Rasterizer::CodeBlock(1024 * 64 * 4), cache_(64) {
}
void SamplerJitCache::Clear() {
CodeBlock::Clear();
cache_.clear();
cache_.Clear();
addresses_.clear();
const10All16_ = nullptr;
@ -144,8 +144,12 @@ std::string SamplerJitCache::DescribeCodePtr(const u8 *ptr) {
void SamplerJitCache::Flush() {
std::unique_lock<std::mutex> guard(jitCacheLock);
for (const auto &queued : compileQueue_)
Compile(queued);
for (const auto &queued : compileQueue_) {
// Might've been compiled after enqueue, but before now.
size_t queuedKey = std::hash<SamplerID>()(queued);
if (!cache_.Get(queuedKey))
Compile(queued);
}
compileQueue_.clear();
}
@ -154,10 +158,11 @@ NearestFunc SamplerJitCache::GetByID(const SamplerID &id, std::function<void()>
return nullptr;
std::unique_lock<std::mutex> guard(jitCacheLock);
const size_t key = std::hash<SamplerID>()(id);
auto it = cache_.find(id);
if (it != cache_.end())
return it->second;
auto it = cache_.Get(key);
if (it != nullptr)
return it;
if (!flushForCompile) {
// Can't compile, let's try to do it later when there's an opportunity.
@ -169,17 +174,18 @@ NearestFunc SamplerJitCache::GetByID(const SamplerID &id, std::function<void()>
flushForCompile();
guard.lock();
for (const auto &queued : compileQueue_)
Compile(queued);
for (const auto &queued : compileQueue_) {
// Might've been compiled after enqueue, but before now.
size_t queuedKey = std::hash<SamplerID>()(queued);
if (!cache_.Get(queuedKey))
Compile(queued);
}
compileQueue_.clear();
Compile(id);
// Okay, should be there now.
it = cache_.find(id);
if (it != cache_.end())
return it->second;
return nullptr;
return cache_.Get(key);
}
NearestFunc SamplerJitCache::GetNearest(const SamplerID &id, std::function<void()> flushForCompile) {
@ -207,19 +213,19 @@ void SamplerJitCache::Compile(const SamplerID &id) {
fetchID.linear = false;
fetchID.fetch = true;
addresses_[fetchID] = GetCodePointer();
cache_[fetchID] = (NearestFunc)CompileFetch(fetchID);
cache_.Insert(std::hash<SamplerID>()(fetchID), (NearestFunc)CompileFetch(fetchID));
SamplerID nearestID = id;
nearestID.linear = false;
nearestID.fetch = false;
addresses_[nearestID] = GetCodePointer();
cache_[nearestID] = (NearestFunc)CompileNearest(nearestID);
cache_.Insert(std::hash<SamplerID>()(nearestID), (NearestFunc)CompileNearest(nearestID));
SamplerID linearID = id;
linearID.linear = true;
linearID.fetch = false;
addresses_[linearID] = GetCodePointer();
cache_[linearID] = (NearestFunc)CompileLinear(linearID);
cache_.Insert(std::hash<SamplerID>()(linearID), (NearestFunc)CompileLinear(linearID));
#endif
}

View File

@ -22,6 +22,7 @@
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include "Common/Data/Collections/Hashmaps.h"
#include "GPU/Math3D.h"
#include "GPU/Software/FuncId.h"
#include "GPU/Software/RasterizerRegCache.h"
@ -126,7 +127,7 @@ private:
const u8 *const5551Swizzle_ = nullptr;
const u8 *const5650Swizzle_ = nullptr;
std::unordered_map<SamplerID, NearestFunc> cache_;
DenseHashMap<size_t, NearestFunc, nullptr> cache_;
std::unordered_map<SamplerID, const u8 *> addresses_;
std::unordered_set<SamplerID> compileQueue_;
};