GS: Track hash cache memory usage

This commit is contained in:
Connor McLaughlin 2022-01-23 16:06:31 +10:00 committed by lightningterror
parent 5d33af13ca
commit b3a2d3c1e4
5 changed files with 33 additions and 9 deletions

View File

@ -678,6 +678,20 @@ void GSgetStats(std::string& info)
info = format("%s Null", api_name); info = format("%s Null", api_name);
} }
else else
{
if (GSConfig.TexturePreloading == TexturePreloadingLevel::Full)
{
info = format("%s HW | HC: %d MB | %d P | %d D | %d DC | %d RB | %d TC | %d TU",
api_name,
(int)std::ceil(static_cast<GSRendererHW*>(s_gs.get())->GetTextureCache()->GetHashCacheMemoryUsage() / 1048576.0f),
(int)pm.Get(GSPerfMon::Prim),
(int)pm.Get(GSPerfMon::Draw),
(int)std::ceil(pm.Get(GSPerfMon::DrawCalls)),
(int)std::ceil(pm.Get(GSPerfMon::Readbacks)),
(int)std::ceil(pm.Get(GSPerfMon::TextureCopies)),
(int)std::ceil(pm.Get(GSPerfMon::TextureUploads)));
}
else
{ {
info = format("%s HW | %d P | %d D | %d DC | %d RB | %d TC | %d TU", info = format("%s HW | %d P | %d D | %d DC | %d RB | %d TC | %d TU",
api_name, api_name,
@ -688,6 +702,7 @@ void GSgetStats(std::string& info)
(int)std::ceil(pm.Get(GSPerfMon::TextureCopies)), (int)std::ceil(pm.Get(GSPerfMon::TextureCopies)),
(int)std::ceil(pm.Get(GSPerfMon::TextureUploads))); (int)std::ceil(pm.Get(GSPerfMon::TextureUploads)));
} }
}
} }
void GSgetTitleStats(std::string& info) void GSgetTitleStats(std::string& info)

View File

@ -137,5 +137,5 @@ public:
float OffsetHack_mody; float OffsetHack_mody;
// Typical size of a RGBA texture // Typical size of a RGBA texture
virtual u32 GetMemUsage() { return m_size.x * m_size.y * 4; } virtual u32 GetMemUsage() { return m_size.x * m_size.y * (m_format == Format::UNorm8 ? 1 : 4); }
}; };

View File

@ -164,6 +164,8 @@ public:
GSRendererHW(); GSRendererHW();
virtual ~GSRendererHW() override; virtual ~GSRendererHW() override;
__fi GSTextureCache* GetTextureCache() const { return m_tc; }
void Destroy() override; void Destroy() override;
void SetGameCRC(u32 crc, int options) override; void SetGameCRC(u32 crc, int options) override;

View File

@ -100,6 +100,7 @@ void GSTextureCache::RemoveAll()
for (auto it : m_hash_cache) for (auto it : m_hash_cache)
g_gs_device->Recycle(it.second.texture); g_gs_device->Recycle(it.second.texture);
m_hash_cache.clear(); m_hash_cache.clear();
m_hash_cache_memory_usage = 0;
m_palette_map.Clear(); m_palette_map.Clear();
} }
@ -1132,6 +1133,7 @@ void GSTextureCache::IncAge()
HashCacheEntry& e = it->second; HashCacheEntry& e = it->second;
if (e.refcount == 0 && ++e.age > max_hash_cache_age) if (e.refcount == 0 && ++e.age > max_hash_cache_age)
{ {
m_hash_cache_memory_usage -= e.texture->GetMemUsage();
g_gs_device->Recycle(e.texture); g_gs_device->Recycle(e.texture);
m_hash_cache.erase(it++); m_hash_cache.erase(it++);
} }
@ -1465,6 +1467,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
// insert it into the hash cache // insert it into the hash cache
HashCacheEntry entry{ src->m_texture, 1, 0 }; HashCacheEntry entry{ src->m_texture, 1, 0 };
it = m_hash_cache.emplace(key, entry).first; it = m_hash_cache.emplace(key, entry).first;
m_hash_cache_memory_usage += src->m_texture->GetMemUsage();
} }
else else
{ {

View File

@ -275,6 +275,7 @@ protected:
PaletteMap m_palette_map; PaletteMap m_palette_map;
SourceMap m_src; SourceMap m_src;
std::unordered_map<HashCacheKey, HashCacheEntry, HashCacheKeyHash> m_hash_cache; std::unordered_map<HashCacheKey, HashCacheEntry, HashCacheKeyHash> m_hash_cache;
u64 m_hash_cache_memory_usage = 0;
FastList<Target*> m_dst[2]; FastList<Target*> m_dst[2];
bool m_preload_frame; bool m_preload_frame;
static u8* m_temp; static u8* m_temp;
@ -298,6 +299,9 @@ protected:
public: public:
GSTextureCache(GSRenderer* r); GSTextureCache(GSRenderer* r);
~GSTextureCache(); ~GSTextureCache();
__fi u64 GetHashCacheMemoryUsage() const { return m_hash_cache_memory_usage; }
void Read(Target* t, const GSVector4i& r); void Read(Target* t, const GSVector4i& r);
void Read(Source* t, const GSVector4i& r); void Read(Source* t, const GSVector4i& r);
void RemoveAll(); void RemoveAll();