From 6f9a89dcf2526052513eaf2d1cc2c2f2bc12c0b7 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Fri, 10 Jul 2015 21:11:14 +0200 Subject: [PATCH] gsdx-debug: print memory usage of all textures pools It is a bit crude but it allow to see the impact of code and options. --- plugins/GSdx/GSDevice.cpp | 14 ++++++++++++++ plugins/GSdx/GSDevice.h | 2 ++ plugins/GSdx/GSRendererHW.cpp | 3 +++ plugins/GSdx/GSTexture.h | 3 +++ plugins/GSdx/GSTextureCache.cpp | 32 ++++++++++++++++++++++++++++++++ plugins/GSdx/GSTextureCache.h | 2 ++ plugins/GSdx/GSTextureOGL.cpp | 18 +++++++++++++++++- plugins/GSdx/GSTextureOGL.h | 2 ++ 8 files changed, 75 insertions(+), 1 deletion(-) diff --git a/plugins/GSdx/GSDevice.cpp b/plugins/GSdx/GSDevice.cpp index 69af182383..c0a799e277 100644 --- a/plugins/GSdx/GSDevice.cpp +++ b/plugins/GSdx/GSDevice.cpp @@ -146,6 +146,20 @@ GSTexture* GSDevice::FetchSurface(int type, int w, int h, bool msaa, int format) return CreateSurface(type, w, h, msaa, format); } +void GSDevice::PrintMemoryUsage() +{ +#ifdef ENABLE_OGL_DEBUG + uint32 pool = 0; + for(list::iterator i = m_pool.begin(); i != m_pool.end(); i++) + { + GSTexture* t = *i; + if (t) + pool += t->GetMemUsage(); + } + GL_PERF("MEM: Surface Pool %dMB", pool >> 20u); +#endif +} + void GSDevice::EndScene() { m_vertex.start += m_vertex.count; diff --git a/plugins/GSdx/GSDevice.h b/plugins/GSdx/GSDevice.h index 8fde98d93f..820e911a73 100644 --- a/plugins/GSdx/GSDevice.h +++ b/plugins/GSdx/GSDevice.h @@ -173,6 +173,8 @@ public: bool IsRBSwapped() {return m_rbswapped;} void AgePool(); + + virtual void PrintMemoryUsage(); }; struct GSAdapter diff --git a/plugins/GSdx/GSRendererHW.cpp b/plugins/GSdx/GSRendererHW.cpp index 0046a3fadc..04b6cefc0b 100644 --- a/plugins/GSdx/GSRendererHW.cpp +++ b/plugins/GSdx/GSRendererHW.cpp @@ -137,6 +137,9 @@ void GSRendererHW::VSync(int field) m_tc->IncAge(); + m_tc->PrintMemoryUsage(); + m_dev->PrintMemoryUsage(); + m_skip = 0; } diff --git a/plugins/GSdx/GSTexture.h b/plugins/GSdx/GSTexture.h index 615b9c49b8..4b2626d25b 100644 --- a/plugins/GSdx/GSTexture.h +++ b/plugins/GSdx/GSTexture.h @@ -69,4 +69,7 @@ public: bool LikelyOffset; float OffsetHack_modx; float OffsetHack_mody; + + // Typical size of a RGBA texture + virtual uint32 GetMemUsage() { return m_size.x * m_size.y * 4; } }; diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index 0e2399651d..1ae694fd7a 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -1143,6 +1143,38 @@ GSTextureCache::Target* GSTextureCache::CreateTarget(const GIFRegTEX0& TEX0, int return t; } +void GSTextureCache::PrintMemoryUsage() +{ +#ifdef ENABLE_OGL_DEBUG + uint32 tex = 0; + uint32 tex_rt = 0; + uint32 rt = 0; + uint32 dss = 0; + for(hash_set::iterator i = m_src.m_surfaces.begin(); i != m_src.m_surfaces.end(); i++) { + Source* s = *i; + if (s) { + if (s->m_target) + tex_rt += s->m_texture->GetMemUsage(); + else + tex += s->m_texture->GetMemUsage(); + + } + } + for(list::iterator i = m_dst[RenderTarget].begin(); i != m_dst[RenderTarget].end(); i++) { + Target* t = *i; + if (t) + rt += t->m_texture->GetMemUsage(); + } + for(list::iterator i = m_dst[DepthStencil].begin(); i != m_dst[DepthStencil].end(); i++) { + Target* t = *i; + if (t) + dss += t->m_texture->GetMemUsage(); + } + + GL_PERF("MEM: RO Tex %dMB. RW Tex %dMB. Target %dMB. Depth %dMB", tex >> 20u, tex_rt >> 20u, rt >> 20u, dss >> 20u); +#endif +} + // GSTextureCache::Surface GSTextureCache::Surface::Surface(GSRenderer* r, uint8* temp) diff --git a/plugins/GSdx/GSTextureCache.h b/plugins/GSdx/GSTextureCache.h index 6314955d1b..98dc674f42 100644 --- a/plugins/GSdx/GSTextureCache.h +++ b/plugins/GSdx/GSTextureCache.h @@ -154,4 +154,6 @@ public: const char* to_string(int type) { return (type == DepthStencil) ? "Depth" : "Color"; } + + void PrintMemoryUsage(); }; diff --git a/plugins/GSdx/GSTextureOGL.cpp b/plugins/GSdx/GSTextureOGL.cpp index bdca672851..b666c78dda 100644 --- a/plugins/GSdx/GSTextureOGL.cpp +++ b/plugins/GSdx/GSTextureOGL.cpp @@ -251,7 +251,8 @@ GSTextureOGL::GSTextureOGL(int type, int w, int h, int format, GLuint fbo_read) switch (m_type) { case GSTexture::Offscreen: // 8B is the worst case for depth/stencil - m_local_buffer = (uint8*)_aligned_malloc(m_size.x * m_size.y * 8, 32); + // FIXME I think it is only used for color. So you can save half of the size + m_local_buffer = (uint8*)_aligned_malloc(m_size.x * m_size.y * 4, 32); case GSTexture::Texture: case GSTexture::RenderTarget: case GSTexture::DepthStencil: @@ -567,3 +568,18 @@ bool GSTextureOGL::Save(const string& fn, bool dds) return status; } +uint32 GSTextureOGL::GetMemUsage() +{ + switch (m_type) { + case GSTexture::Offscreen: + return m_size.x * m_size.y * (4 + m_int_alignment); + case GSTexture::Texture: + case GSTexture::RenderTarget: + return m_size.x * m_size.y * m_int_alignment; + case GSTexture::DepthStencil: + return m_size.x * m_size.y * 8; + case GSTexture::Backbuffer: + default: + return 0; + } +} diff --git a/plugins/GSdx/GSTextureOGL.h b/plugins/GSdx/GSTextureOGL.h index 4e1ea213ed..27fdb9222e 100644 --- a/plugins/GSdx/GSTextureOGL.h +++ b/plugins/GSdx/GSTextureOGL.h @@ -76,4 +76,6 @@ class GSTextureOGL : public GSTexture bool HasBeenCleaned() { return m_clean; } void WasAttached() { m_clean = false; m_dirty = true; } void WasCleaned() { m_clean = true; } + + uint32 GetMemUsage(); };