diff --git a/pcsx2/GS/GS.cpp b/pcsx2/GS/GS.cpp index 473f2569bc..25a618fbc5 100644 --- a/pcsx2/GS/GS.cpp +++ b/pcsx2/GS/GS.cpp @@ -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(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))); + } } } diff --git a/pcsx2/GS/Renderers/Common/GSTexture.h b/pcsx2/GS/Renderers/Common/GSTexture.h index 3f5c02b2f5..1d2ccbd966 100644 --- a/pcsx2/GS/Renderers/Common/GSTexture.h +++ b/pcsx2/GS/Renderers/Common/GSTexture.h @@ -137,5 +137,5 @@ public: 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); } }; diff --git a/pcsx2/GS/Renderers/HW/GSRendererHW.h b/pcsx2/GS/Renderers/HW/GSRendererHW.h index bbf9690ef4..87fcbc4c86 100644 --- a/pcsx2/GS/Renderers/HW/GSRendererHW.h +++ b/pcsx2/GS/Renderers/HW/GSRendererHW.h @@ -164,6 +164,8 @@ public: GSRendererHW(); virtual ~GSRendererHW() override; + __fi GSTextureCache* GetTextureCache() const { return m_tc; } + void Destroy() override; void SetGameCRC(u32 crc, int options) override; diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp index 4e8d883529..85961fd07b 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp @@ -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(); } @@ -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++); } @@ -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 { diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.h b/pcsx2/GS/Renderers/HW/GSTextureCache.h index df29593b8d..7657676227 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.h +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.h @@ -275,6 +275,7 @@ protected: PaletteMap m_palette_map; SourceMap m_src; std::unordered_map m_hash_cache; + u64 m_hash_cache_memory_usage = 0; FastList m_dst[2]; bool m_preload_frame; static u8* m_temp; @@ -298,6 +299,9 @@ protected: 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();