From 2e26a4798ed62faf97fde99803341ec73d2c21c8 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Wed, 13 May 2015 23:07:19 +0200 Subject: [PATCH] Scale the frame profiler graph dynamically --- GPU/GLES/StateMapping.cpp | 4 +++- UI/DevScreens.cpp | 27 ++++++++++++++++++++++++--- UI/EmuScreen.cpp | 7 +++++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/GPU/GLES/StateMapping.cpp b/GPU/GLES/StateMapping.cpp index 0eb81780d4..89708a1b3b 100644 --- a/GPU/GLES/StateMapping.cpp +++ b/GPU/GLES/StateMapping.cpp @@ -569,7 +569,6 @@ void TransformDrawEngine::ApplyBlendState() { } void TransformDrawEngine::ApplyDrawState(int prim) { - PROFILE_THIS_SCOPE("applydrawstate"); // TODO: All this setup is soon so expensive that we'll need dirty flags, or simply do it in the command writes where we detect dirty by xoring. Silly to do all this work on every drawcall. @@ -583,6 +582,9 @@ void TransformDrawEngine::ApplyDrawState(int prim) { } } + // Start profiling here to skip SetTexture which is already accounted for + PROFILE_THIS_SCOPE("applydrawstate"); + // Set blend - unless we need to do it in the shader. ApplyBlendState(); diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 5676a606ce..b8e598239b 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -782,6 +782,7 @@ UI::EventReturn JitCompareScreen::OnCurrentBlock(UI::EventParams &e) { } void DrawProfile(UIContext &ui) { +#ifdef USE_PROFILER int numCategories = Profiler_GetNumCategories(); int historyLength = Profiler_GetHistoryLength(); @@ -816,14 +817,29 @@ void DrawProfile(UIContext &ui) { */ bool area = true; + static float lastMaxVal = 1.0f / 60.0f; + float minVal = 0.0f; + float maxVal = lastMaxVal; // TODO - adjust to frame length + if (maxVal < 0.001f) + maxVal = 0.001f; + if (maxVal > 1.0f / 30.0f) + maxVal = 1.0f / 30.0f; + float scale = (graphHeight) / (maxVal - minVal); + + float y_60th = ui.GetBounds().y2() - 10 - (1.0f / 60.0f) * scale; + float y_1ms = ui.GetBounds().y2() - 10 - (1.0f / 1000.0f) * scale; + + ui.FillRect(UI::Drawable(0x80FFFF00), Bounds(0, y_60th, graphWidth, 2)); + ui.FillRect(UI::Drawable(0x80FFFF00), Bounds(0, y_1ms, graphWidth, 2)); + ui.DrawTextShadow("1/60s", 5, y_60th, 0x80FFFF00); + ui.DrawTextShadow("1ms", 5, y_1ms, 0x80FFFF00); + + maxVal = 0.0f; for (int i = 0; i < numCategories; i++) { Profiler_GetHistory(i, &history[0], historyLength); float x = 10; - float minVal = 0.0f; - float maxVal = 1.0f / 60.0f; // TODO - adjust to frame length - float scale = (graphHeight) / (maxVal - minVal); uint32_t col = Profiler_GetCategoryColor(i); if (area) col &= 0x7FFFFFFF; @@ -832,6 +848,8 @@ void DrawProfile(UIContext &ui) { if (area) { for (int n = 0; n < historyLength; n++) { float val = history[n]; + if (val > maxVal) + maxVal = val; float valY1 = ui.GetBounds().y2() - 10 - (val + total[n]) * scale; float valY2 = ui.GetBounds().y2() - 10 - total[n] * scale; ui.FillRect(color, Bounds(x, valY1, dx, valY2 - valY1)); @@ -847,4 +865,7 @@ void DrawProfile(UIContext &ui) { } } } + + lastMaxVal = lastMaxVal * 0.95f + maxVal * 0.05f; +#endif } diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 7a372df8a0..6089754b60 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -21,6 +21,7 @@ #include "base/display.h" #include "base/logging.h" #include "base/timeutil.h" +#include "profiler/profiler.h" #include "gfx_es2/glsl_program.h" #include "gfx_es2/gl_state.h" @@ -908,9 +909,11 @@ void EmuScreen::render() { DrawFPS(draw2d, screenManager()->getUIContext()->GetBounds()); } +#ifdef USE_PROFILER if (g_Config.bShowFrameProfiler) { - // DrawProfile(*screenManager()->getUIContext()); + DrawProfile(*screenManager()->getUIContext()); } +#endif screenManager()->getUIContext()->End(); } @@ -955,4 +958,4 @@ void EmuScreen::releaseButtons() { input.timestamp = time_now_d(); input.id = 0; touch(input); -} \ No newline at end of file +}