Skip to content

Commit

Permalink
samplerjit: Compile sampler funcs together.
Browse files Browse the repository at this point in the history
We can't have the cache clear between nearest/linear, because then we'll
call a bunch of int3's.
  • Loading branch information
unknownbrackets committed Jan 30, 2022
1 parent 0d93200 commit d200ef4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
79 changes: 43 additions & 36 deletions GPU/Software/Sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,72 +141,79 @@ NearestFunc SamplerJitCache::GetNearest(const SamplerID &id) {
std::lock_guard<std::mutex> guard(jitCacheLock);

auto it = cache_.find(id);
if (it != cache_.end()) {
if (it != cache_.end())
return (NearestFunc)it->second;
}

// TODO: What should be the min size? Can we even hit this?
if (GetSpaceLeft() < 16384) {
Clear();
}
Compile(id);

#if PPSSPP_ARCH(AMD64) && !PPSSPP_PLATFORM(UWP)
if (g_Config.bSoftwareRenderingJit) {
addresses_[id] = GetCodePointer();
NearestFunc func = CompileNearest(id);
cache_[id] = (NearestFunc)func;
return func;
}
#endif
// Okay, should be there now.
it = cache_.find(id);
if (it != cache_.end())
return (NearestFunc)it->second;
return nullptr;
}

LinearFunc SamplerJitCache::GetLinear(const SamplerID &id) {
std::lock_guard<std::mutex> guard(jitCacheLock);

auto it = cache_.find(id);
if (it != cache_.end()) {
if (it != cache_.end())
return (LinearFunc)it->second;
}

// TODO: What should be the min size? Can we even hit this?
if (GetSpaceLeft() < 16384) {
Clear();
}
Compile(id);

#if PPSSPP_ARCH(AMD64) && !PPSSPP_PLATFORM(UWP)
if (g_Config.bSoftwareRenderingJit) {
addresses_[id] = GetCodePointer();
LinearFunc func = CompileLinear(id);
cache_[id] = (NearestFunc)func;
return func;
}
#endif
// Okay, should be there now.
it = cache_.find(id);
if (it != cache_.end())
return (LinearFunc)it->second;
return nullptr;
}

FetchFunc SamplerJitCache::GetFetch(const SamplerID &id) {
std::lock_guard<std::mutex> guard(jitCacheLock);

auto it = cache_.find(id);
if (it != cache_.end()) {
if (it != cache_.end())
return (FetchFunc)it->second;
}

// TODO: What should be the min size? Can we even hit this?
Compile(id);

// Okay, should be there now.
it = cache_.find(id);
if (it != cache_.end())
return (FetchFunc)it->second;
return nullptr;
}

void SamplerJitCache::Compile(const SamplerID &id) {
// This should be sufficient.
if (GetSpaceLeft() < 16384) {
Clear();
}

// We compile them together so the cache can't possibly be cleared in between.
// We might vary between nearest and linear, so we can't clear between.
#if PPSSPP_ARCH(AMD64) && !PPSSPP_PLATFORM(UWP)
if (g_Config.bSoftwareRenderingJit) {
addresses_[id] = GetCodePointer();
FetchFunc func = CompileFetch(id);
cache_[id] = (NearestFunc)func;
return func;
SamplerID fetchID = id;
fetchID.linear = false;
fetchID.fetch = true;
addresses_[fetchID] = GetCodePointer();
cache_[fetchID] = (NearestFunc)CompileFetch(fetchID);

SamplerID nearestID = id;
nearestID.linear = false;
nearestID.fetch = false;
addresses_[nearestID] = GetCodePointer();
cache_[nearestID] = (NearestFunc)CompileNearest(nearestID);

SamplerID linearID = id;
linearID.linear = true;
linearID.fetch = false;
addresses_[linearID] = GetCodePointer();
cache_[linearID] = (NearestFunc)CompileLinear(linearID);
}
#endif
return nullptr;
}

template <uint32_t texel_size_bits>
Expand Down
1 change: 1 addition & 0 deletions GPU/Software/Sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class SamplerJitCache : public Rasterizer::CodeBlock {
std::string DescribeCodePtr(const u8 *ptr) override;

private:
void Compile(const SamplerID &id);
FetchFunc CompileFetch(const SamplerID &id);
NearestFunc CompileNearest(const SamplerID &id);
LinearFunc CompileLinear(const SamplerID &id);
Expand Down

0 comments on commit d200ef4

Please sign in to comment.