Skip to content

Commit

Permalink
GS: Track hash cache memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek authored and lightningterror committed Feb 21, 2022
1 parent 5d33af1 commit b3a2d3c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
31 changes: 23 additions & 8 deletions pcsx2/GS/GS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,29 @@ void GSgetStats(std::string& info)
}
else
{
info = format("%s HW | %d P | %d D | %d DC | %d RB | %d TC | %d TU",
api_name,
(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)));
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",
api_name,
(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)));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/Renderers/Common/GSTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,5 @@ class GSTexture
float OffsetHack_mody;

// 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); }
};
2 changes: 2 additions & 0 deletions pcsx2/GS/Renderers/HW/GSRendererHW.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class GSRendererHW : public GSRenderer
GSRendererHW();
virtual ~GSRendererHW() override;

__fi GSTextureCache* GetTextureCache() const { return m_tc; }

void Destroy() override;

void SetGameCRC(u32 crc, int options) override;
Expand Down
3 changes: 3 additions & 0 deletions pcsx2/GS/Renderers/HW/GSTextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void GSTextureCache::RemoveAll()
for (auto it : m_hash_cache)
g_gs_device->Recycle(it.second.texture);
m_hash_cache.clear();
m_hash_cache_memory_usage = 0;

m_palette_map.Clear();
}
Expand Down Expand Up @@ -1132,6 +1133,7 @@ void GSTextureCache::IncAge()
HashCacheEntry& e = it->second;
if (e.refcount == 0 && ++e.age > max_hash_cache_age)
{
m_hash_cache_memory_usage -= e.texture->GetMemUsage();
g_gs_device->Recycle(e.texture);
m_hash_cache.erase(it++);
}
Expand Down Expand Up @@ -1465,6 +1467,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
// insert it into the hash cache
HashCacheEntry entry{ src->m_texture, 1, 0 };
it = m_hash_cache.emplace(key, entry).first;
m_hash_cache_memory_usage += src->m_texture->GetMemUsage();
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions pcsx2/GS/Renderers/HW/GSTextureCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class GSTextureCache
PaletteMap m_palette_map;
SourceMap m_src;
std::unordered_map<HashCacheKey, HashCacheEntry, HashCacheKeyHash> m_hash_cache;
u64 m_hash_cache_memory_usage = 0;
FastList<Target*> m_dst[2];
bool m_preload_frame;
static u8* m_temp;
Expand All @@ -298,6 +299,9 @@ class GSTextureCache
public:
GSTextureCache(GSRenderer* r);
~GSTextureCache();

__fi u64 GetHashCacheMemoryUsage() const { return m_hash_cache_memory_usage; }

void Read(Target* t, const GSVector4i& r);
void Read(Source* t, const GSVector4i& r);
void RemoveAll();
Expand Down

0 comments on commit b3a2d3c

Please sign in to comment.