diff --git a/Core/Config.cpp b/Core/Config.cpp index 88c1e59d1f..41623efcde 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -761,6 +761,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { INFO_LOG(LOADER, "Loading config: %s", iniFilename_.c_str()); bSaveSettings = true; + bShowFrameProfiler = true; IniFile iniFile; if (!iniFile.Load(iniFilename_)) { diff --git a/Core/Config.h b/Core/Config.h index 428d614765..eaa832e527 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -374,6 +374,9 @@ public: bool bSkipDeadbeefFilling; bool bFuncHashMap; + // Volatile development settings + bool bShowFrameProfiler; + std::string currentDirectory; std::string externalDirectory; std::string memStickDirectory; diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 44596dafa7..dbbf582cec 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -20,6 +20,8 @@ #include "native/thread/thread.h" #include "native/thread/threadutil.h" +#include "profiler/profiler.h" + #include "Core/Core.h" #include "Core/Config.h" #include "Core/Debugger/Breakpoints.h" @@ -760,6 +762,7 @@ static u32 npdrmRead(FileNode *f, u8 *data, int size) { } static bool __IoRead(int &result, int id, u32 data_addr, int size, int &us) { + PROFILE_THIS_SCOPE("ioread"); // Low estimate, may be improved later from the ReadFile result. us = size / 100; if (us < 100) { diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index 9cce143ced..15598c1c5b 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -16,6 +16,8 @@ // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #include "base/basictypes.h" +#include "profiler/profiler.h" + #include "Globals.h" #include "Core/MemMapHelpers.h" #include "Core/HLE/sceAtrac.h" @@ -525,6 +527,8 @@ void SasInstance::MixVoice(SasVoice &voice) { } void SasInstance::Mix(u32 outAddr, u32 inAddr, int leftVol, int rightVol) { + PROFILE_THIS_SCOPE("mixer"); + int voicesPlayingCount = 0; for (int v = 0; v < PSP_SAS_VOICES_MAX; v++) { diff --git a/GPU/Common/SplineCommon.cpp b/GPU/Common/SplineCommon.cpp index e330218198..e095bffa05 100644 --- a/GPU/Common/SplineCommon.cpp +++ b/GPU/Common/SplineCommon.cpp @@ -25,6 +25,8 @@ #include #include +#include "profiler/profiler.h" + #include "Common/CPUDetect.h" #include "Core/Config.h" @@ -752,6 +754,7 @@ u32 DrawEngineCommon::NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, const GEPrimitiveType primType[] = { GE_PRIM_TRIANGLES, GE_PRIM_LINES, GE_PRIM_POINTS }; void DrawEngineCommon::SubmitSpline(const void *control_points, const void *indices, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, u32 vertType) { + PROFILE_THIS_SCOPE("spline"); DispatchFlush(); // TODO: Verify correct functionality with < 4. @@ -830,6 +833,8 @@ void DrawEngineCommon::SubmitSpline(const void *control_points, const void *indi } void DrawEngineCommon::SubmitBezier(const void *control_points, const void *indices, int count_u, int count_v, GEPatchPrimType prim_type, u32 vertType) { + PROFILE_THIS_SCOPE("bezier"); + DispatchFlush(); // TODO: Verify correct functionality with < 4. diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index bef26c0b30..56bdc18d4b 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -17,6 +17,7 @@ #include "base/logging.h" #include "gfx_es2/gl_state.h" +#include "profiler/profiler.h" #include "Common/ChunkFile.h" diff --git a/GPU/GLES/StateMapping.cpp b/GPU/GLES/StateMapping.cpp index 12b354e19a..0eb81780d4 100644 --- a/GPU/GLES/StateMapping.cpp +++ b/GPU/GLES/StateMapping.cpp @@ -21,7 +21,8 @@ #include "StateMapping.h" -#include "native/gfx_es2/gl_state.h" +#include "gfx_es2/gl_state.h" +#include "profiler/profiler.h" #include "GPU/Math3D.h" #include "GPU/GPUState.h" @@ -568,6 +569,8 @@ 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. if (gstate_c.textureChanged != TEXCHANGE_UNCHANGED && !gstate.isModeClear() && gstate.isTextureMapEnabled()) { diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index a66bd8b84f..ad1f237211 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -18,6 +18,8 @@ #include #include +#include "profiler/profiler.h" + #include "Common/ColorConv.h" #include "Core/Host.h" #include "Core/MemMap.h" @@ -1116,6 +1118,7 @@ bool TextureCache::SetOffsetTexture(u32 offset) { } void TextureCache::SetTexture(bool force) { + PROFILE_THIS_SCOPE("settexture"); #ifdef DEBUG_TEXTURES if (SetDebugTexture()) { // A different texture was bound, let's rebind next time. diff --git a/GPU/GLES/TransformPipeline.cpp b/GPU/GLES/TransformPipeline.cpp index 748bc9fae4..aec9acc0d8 100644 --- a/GPU/GLES/TransformPipeline.cpp +++ b/GPU/GLES/TransformPipeline.cpp @@ -72,7 +72,8 @@ #include "Core/Config.h" #include "Core/CoreTiming.h" -#include "native/gfx_es2/gl_state.h" +#include "gfx_es2/gl_state.h" +#include "profiler/profiler.h" #include "GPU/Math3D.h" #include "GPU/GPUState.h" @@ -334,6 +335,8 @@ void TransformDrawEngine::DecodeVerts() { } void TransformDrawEngine::DecodeVertsStep() { + PROFILE_THIS_SCOPE("vertdec"); + const int i = decodeCounter_; const DeferredDrawCall &dc = drawCalls[i]; diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 15c2699111..5676a606ce 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -24,6 +24,7 @@ #include "ui/view.h" #include "ui/viewgroup.h" #include "ui/ui.h" +#include "profiler/profiler.h" #include "Common/LogManager.h" #include "Common/CPUDetect.h" @@ -69,6 +70,9 @@ void DevMenu::CreatePopupContents(UI::ViewGroup *parent) { parent->Add(new Choice(de->T("Toggle Freeze")))->OnClick.Handle(this, &DevMenu::OnFreezeFrame); parent->Add(new Choice(de->T("Dump Frame GPU Commands")))->OnClick.Handle(this, &DevMenu::OnDumpFrame); parent->Add(new Choice(de->T("Toggle Audio Debug")))->OnClick.Handle(this, &DevMenu::OnToggleAudioDebug); +#ifdef USE_PROFILER + parent->Add(new CheckBox(&g_Config.bShowFrameProfiler, de->T("Frame Profiler"), "")); +#endif RingbufferLogListener *ring = LogManager::GetInstance()->GetRingbufferListener(); if (ring) { @@ -776,3 +780,71 @@ UI::EventReturn JitCompareScreen::OnCurrentBlock(UI::EventParams &e) { UpdateDisasm(); return UI::EVENT_DONE; } + +void DrawProfile(UIContext &ui) { + int numCategories = Profiler_GetNumCategories(); + int historyLength = Profiler_GetHistoryLength(); + + float legendStartY = ui.GetBounds().centerY(); + float legendStartX = ui.GetBounds().x2() - 100; + + float rowH = 30; + + for (int i = 0; i < numCategories; i++) { + const char *name = Profiler_GetCategoryName(i); + uint32_t color = Profiler_GetCategoryColor(i); + + float y = legendStartY + i * rowH; + ui.FillRect(UI::Drawable(color), Bounds(legendStartX, y, rowH - 2, rowH - 2)); + ui.DrawTextShadow(name, legendStartX + rowH + 2, y, 0xFFFFFFFF, ALIGN_VBASELINE); + } + + float graphWidth = ui.GetBounds().x2() - 120; + float graphHeight = ui.GetBounds().h * 0.8f; + + std::vector history; + std::vector total; + history.resize(historyLength); + total.resize(historyLength); + + float dx = graphWidth / historyLength; + + /* + ui.Flush(); + + ui.BeginNoTex(); + */ + + bool area = true; + + 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; + UI::Drawable color(col); + + if (area) { + for (int n = 0; n < historyLength; n++) { + float val = history[n]; + 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)); + x += dx; + total[n] += val; + } + } else { + for (int n = 0; n < historyLength; n++) { + float val = history[n]; + float valY = ui.GetBounds().y2() - 10 - history[n] * scale; + ui.FillRect(color, Bounds(x, valY, dx, 5)); + x += dx; + } + } + } +} diff --git a/UI/DevScreens.h b/UI/DevScreens.h index 45a79073ca..928f6576b7 100644 --- a/UI/DevScreens.h +++ b/UI/DevScreens.h @@ -141,3 +141,6 @@ private: UI::LinearLayout *leftDisasm_; UI::LinearLayout *rightDisasm_; }; + + +void DrawProfile(UIContext &ui); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 280cdcb6db..7a372df8a0 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -874,7 +874,7 @@ void EmuScreen::render() { if (useBufferedRendering && g_Config.iGPUBackend == GPU_BACKEND_OPENGL) fbo_unbind(); - if (!osm.IsEmpty() || g_Config.bShowDebugStats || g_Config.iShowFPSCounter || g_Config.bShowTouchControls || g_Config.bShowDeveloperMenu || g_Config.bShowAudioDebug || saveStatePreview_->GetVisibility() != UI::V_GONE) { + if (!osm.IsEmpty() || g_Config.bShowDebugStats || g_Config.iShowFPSCounter || g_Config.bShowTouchControls || g_Config.bShowDeveloperMenu || g_Config.bShowAudioDebug || saveStatePreview_->GetVisibility() != UI::V_GONE || g_Config.bShowFrameProfiler) { Thin3DContext *thin3d = screenManager()->getThin3DContext(); // This sets up some important states but not the viewport. @@ -908,6 +908,10 @@ void EmuScreen::render() { DrawFPS(draw2d, screenManager()->getUIContext()->GetBounds()); } + if (g_Config.bShowFrameProfiler) { + // DrawProfile(*screenManager()->getUIContext()); + } + screenManager()->getUIContext()->End(); }