Minor sampler cache cleanup.
This commit is contained in:
parent
eae20b77a8
commit
e7c93b8ac3
|
@ -49,36 +49,30 @@ void SamplerCache::SetSamplerState(int stage, const TexMode0& tm0, const TexMode
|
||||||
|
|
||||||
// TODO: Should keep a circular buffer for each stage of recently used samplers.
|
// TODO: Should keep a circular buffer for each stage of recently used samplers.
|
||||||
|
|
||||||
auto const& active_sampler = m_active_samplers[stage];
|
auto& active_sampler = m_active_samplers[stage];
|
||||||
if (active_sampler.first != params || !active_sampler.second.sampler_id)
|
if (active_sampler.first != params || !active_sampler.second.sampler_id)
|
||||||
{
|
{
|
||||||
// Active sampler does not match parameters (or is invalid), bind the proper one.
|
// Active sampler does not match parameters (or is invalid), bind the proper one.
|
||||||
auto const new_sampler = GetEntry(params);
|
active_sampler.first = params;
|
||||||
|
active_sampler.second = GetEntry(params);
|
||||||
glBindSampler(stage, new_sampler.second.sampler_id);
|
glBindSampler(stage, active_sampler.second.sampler_id);
|
||||||
m_active_samplers[stage] = new_sampler;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//active_it->second.last_frame_used = frameCount;
|
auto SamplerCache::GetEntry(const Params& params) -> Value&
|
||||||
}
|
|
||||||
|
|
||||||
auto SamplerCache::GetEntry(const Params& params) -> std::pair<Params, Value>
|
|
||||||
{
|
{
|
||||||
auto it = m_cache.find(params);
|
auto& val = m_cache[params];
|
||||||
if (m_cache.end() == it)
|
if (!val.sampler_id)
|
||||||
{
|
{
|
||||||
// Sampler not found in cache, create it.
|
// Sampler not found in cache, create it.
|
||||||
Value val;
|
|
||||||
glGenSamplers(1, &val.sampler_id);
|
glGenSamplers(1, &val.sampler_id);
|
||||||
SetParameters(val.sampler_id, params);
|
SetParameters(val.sampler_id, params);
|
||||||
|
|
||||||
it = m_cache.insert(std::make_pair(params, val)).first;
|
|
||||||
|
|
||||||
// TODO: Maybe kill old samplers if the cache gets huge. It doesn't seem to get huge though.
|
// TODO: Maybe kill old samplers if the cache gets huge. It doesn't seem to get huge though.
|
||||||
//ERROR_LOG(VIDEO, "Sampler cache size is now %ld.", m_cache.size());
|
//ERROR_LOG(VIDEO, "Sampler cache size is now %ld.", m_cache.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return *it;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SamplerCache::SetParameters(GLuint sampler_id, const Params& params)
|
void SamplerCache::SetParameters(GLuint sampler_id, const Params& params)
|
||||||
|
|
|
@ -59,15 +59,13 @@ private:
|
||||||
{
|
{
|
||||||
Value()
|
Value()
|
||||||
: sampler_id()
|
: sampler_id()
|
||||||
// , last_frame_used()
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
GLuint sampler_id;
|
GLuint sampler_id;
|
||||||
//int last_frame_used;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void SetParameters(GLuint sampler_id, const Params& params);
|
void SetParameters(GLuint sampler_id, const Params& params);
|
||||||
std::pair<Params, Value> GetEntry(const Params& params);
|
Value& GetEntry(const Params& params);
|
||||||
|
|
||||||
std::map<Params, Value> m_cache;
|
std::map<Params, Value> m_cache;
|
||||||
std::pair<Params, Value> m_active_samplers[8];
|
std::pair<Params, Value> m_active_samplers[8];
|
||||||
|
|
Loading…
Reference in New Issue