From 8123cc27dbe1903b37fffc672f55d0ac5e12c471 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Wed, 8 Sep 2021 22:38:01 -0500 Subject: [PATCH] GS: Improved SW renderer debug stats --- pcsx2/GS/Renderers/Common/GSFunctionMap.h | 38 ++++++++++++++--------- pcsx2/GS/Renderers/SW/GSRasterizer.cpp | 7 +++-- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/pcsx2/GS/Renderers/Common/GSFunctionMap.h b/pcsx2/GS/Renderers/Common/GSFunctionMap.h index 93d9f09f4e..59726b0ada 100644 --- a/pcsx2/GS/Renderers/Common/GSFunctionMap.h +++ b/pcsx2/GS/Renderers/Common/GSFunctionMap.h @@ -19,6 +19,7 @@ #include "GS/GSCodeBuffer.h" #include "GS/Renderers/SW/GSScanlineEnvironment.h" +#include "common/General.h" #include @@ -28,12 +29,11 @@ class GSFunctionMap protected: struct ActivePtr { - uint64 frame, frames; + uint64 frame, frames, prims; uint64 ticks, actual, total; VALUE f; }; - std::unordered_map m_map; std::unordered_map m_map_active; ActivePtr* m_active; @@ -64,15 +64,13 @@ public: } else { - auto i = m_map.find(key); - ActivePtr* p = new ActivePtr(); memset(p, 0, sizeof(*p)); p->frame = (uint64)-1; - p->f = i != m_map.end() ? i->second : GetDefaultFunction(key); + p->f = GetDefaultFunction(key); m_map_active[key] = p; @@ -92,6 +90,7 @@ public: m_active->frames++; } + m_active->prims++; m_active->ticks += ticks; m_active->actual += actual; m_active->total += total; @@ -114,25 +113,36 @@ public: } } + uint64_t million = 1000 * 1000; + uint64_t billion = 1000 * million; + uint64_t tps = GetTickFrequency(); + printf("GS stats\n"); + printf(" key | frames | prims | runtime | pixels\n"); + printf(" | | #/f | pct µs/f ns/px | #/f #/prim overdraw\n"); + for (const auto& i : m_map_active) { KEY key = i.first; ActivePtr* p = i.second; - if (p->frames && ttpf) + if (p->frames && p->actual && ttpf) { - uint64 tpp = p->actual > 0 ? p->ticks / p->actual : 0; - uint64 tpf = p->frames > 0 ? p->ticks / p->frames : 0; - uint64 ppf = p->frames > 0 ? p->actual / p->frames : 0; + uint64 tpp = p->ticks / p->actual; + uint64 tpf = p->ticks / p->frames; + uint64 ppf = p->actual / p->frames; - printf("[%014llx]%c %6.2f%% %5.2f%% f %4llu t %12llu p %12llu w %12lld tpp %4llu tpf %9llu ppf %9llu\n", - (uint64)key, m_map.find(key) == m_map.end() ? '*' : ' ', - (float)(tpf * 10000 / 34000000) / 100, + printf("%014llx | %6llu | %5llu | %5.2f%% %6llu %4llu | %8llu %6llu %5.2f%%\n", + (uint64)key, + p->frames, + p->prims / p->frames, (float)(tpf * 10000 / ttpf) / 100, - p->frames, p->ticks, p->actual, p->total - p->actual, - tpp, tpf, ppf); + (tpf * million) / tps, + (tpp * billion) / tps, + ppf, + p->actual / p->prims, + (float)((p->total - p->actual) * 10000 / p->total) / 100); } } } diff --git a/pcsx2/GS/Renderers/SW/GSRasterizer.cpp b/pcsx2/GS/Renderers/SW/GSRasterizer.cpp index ba6b4052c6..c3cd313a73 100644 --- a/pcsx2/GS/Renderers/SW/GSRasterizer.cpp +++ b/pcsx2/GS/Renderers/SW/GSRasterizer.cpp @@ -17,6 +17,7 @@ #include "PrecompiledHeader.h" #include "GSRasterizer.h" +#include "common/General.h" int GSRasterizerData::s_counter = 0; @@ -138,7 +139,7 @@ void GSRasterizer::Draw(GSRasterizerData* data) m_pixels.actual = 0; m_pixels.total = 0; - data->start = __rdtsc(); + data->start = GetCPUTicks(); m_ds->BeginDraw(data); @@ -244,7 +245,7 @@ void GSRasterizer::Draw(GSRasterizerData* data) data->pixels = m_pixels.actual; - uint64 ticks = __rdtsc() - data->start; + uint64 ticks = GetCPUTicks() - data->start; m_pixels.sum += m_pixels.actual; @@ -1146,7 +1147,7 @@ void GSRasterizer::Flush(const GSVertexSW* vertex, const uint32* index, const GS void GSRasterizer::DrawScanline(int pixels, int left, int top, const GSVertexSW& scan) { m_pixels.actual += pixels; - m_pixels.total += ((left + pixels + (PIXELS_PER_LOOP - 1)) & ~(PIXELS_PER_LOOP - 1)) - (left & (PIXELS_PER_LOOP - 1)); + m_pixels.total += ((left + pixels + (PIXELS_PER_LOOP - 1)) & ~(PIXELS_PER_LOOP - 1)) - (left & ~(PIXELS_PER_LOOP - 1)); //m_pixels.total += ((left + pixels + (PIXELS_PER_LOOP - 1)) & ~(PIXELS_PER_LOOP - 1)) - left; ASSERT(m_pixels.actual <= m_pixels.total);