samplerjit: Prevent thread local stale cache read.

If the generation count happens to match, would still get a stale pointer
and crash.  Let's just make the generation count static so it always
increases.
This commit is contained in:
Unknown W. Brackets committed 2023-02-22 21:15:03 -08:00
1 parent cbc1ed4bfe
commit cd3fc26190
4 files changed
+6 -2

No files matched your search

+2
View File
@@ -802,10 +802,12 @@ SingleFunc PixelJitCache::GenericSingle(const PixelFuncID &id) {
}
thread_local PixelJitCache::LastCache PixelJitCache::lastSingle_;
int PixelJitCache::clearGen_ = 0;
// 256k should be plenty of space for plenty of variations.
PixelJitCache::PixelJitCache() : CodeBlock(1024 * 64 * 4), cache_(64) {
lastSingle_.gen = -1;
clearGen_++;
}
void PixelJitCache::Clear() {
+1 -1
View File
@@ -128,7 +128,7 @@ private:
DenseHashMap<size_t, SingleFunc, nullptr> cache_;
std::unordered_map<PixelFuncID, const u8 *> addresses_;
std::unordered_set<PixelFuncID> compileQueue_;
int clearGen_ = 0;
static int clearGen_;
static thread_local LastCache lastSingle_;
const u8 *constBlendHalf_11_4s_ = nullptr;
+2
View File
@@ -109,12 +109,14 @@ FetchFunc GetFetchFunc(SamplerID id, BinManager *binner) {
thread_local SamplerJitCache::LastCache SamplerJitCache::lastFetch_;
thread_local SamplerJitCache::LastCache SamplerJitCache::lastNearest_;
thread_local SamplerJitCache::LastCache SamplerJitCache::lastLinear_;
int SamplerJitCache::clearGen_ = 0;
// 256k should be enough.
SamplerJitCache::SamplerJitCache() : Rasterizer::CodeBlock(1024 * 64 * 4), cache_(64) {
lastFetch_.gen = -1;
lastNearest_.gen = -1;
lastLinear_.gen = -1;
clearGen_++;
}
void SamplerJitCache::Clear() {
+1 -1
View File
@@ -147,7 +147,7 @@ private:
DenseHashMap<size_t, NearestFunc, nullptr> cache_;
std::unordered_map<SamplerID, const u8 *> addresses_;
std::unordered_set<SamplerID> compileQueue_;
int clearGen_ = 0;
static int clearGen_;
static thread_local LastCache lastFetch_;
static thread_local LastCache lastNearest_;
static thread_local LastCache lastLinear_;