diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 395523fc..01ac1139 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -196,11 +196,14 @@ set(SWA_USER_CXX_SOURCES set(SWA_THIRDPARTY_SOURCES "${SWA_THIRDPARTY_ROOT}/imgui/backends/imgui_impl_sdl2.cpp" - "${SWA_THIRDPARTY_ROOT}/imgui/imgui.cpp" + "${SWA_THIRDPARTY_ROOT}/imgui/imgui.cpp" "${SWA_THIRDPARTY_ROOT}/imgui/imgui_demo.cpp" "${SWA_THIRDPARTY_ROOT}/imgui/imgui_draw.cpp" "${SWA_THIRDPARTY_ROOT}/imgui/imgui_tables.cpp" "${SWA_THIRDPARTY_ROOT}/imgui/imgui_widgets.cpp" + "${SWA_THIRDPARTY_ROOT}/implot/implot.cpp" + "${SWA_THIRDPARTY_ROOT}/implot/implot_demo.cpp" + "${SWA_THIRDPARTY_ROOT}/implot/implot_items.cpp" "${SWA_THIRDPARTY_ROOT}/libmspack/libmspack/mspack/lzxd.c" "${SWA_THIRDPARTY_ROOT}/tiny-AES-c/aes.c" "${SWA_TOOLS_ROOT}/ShaderRecomp/thirdparty/smol-v/source/smolv.cpp" @@ -209,7 +212,8 @@ set(SWA_THIRDPARTY_SOURCES set(SWA_THIRDPARTY_INCLUDES "${SWA_THIRDPARTY_ROOT}/concurrentqueue" "${SWA_THIRDPARTY_ROOT}/ddspp" - "${SWA_THIRDPARTY_ROOT}/imgui" + "${SWA_THIRDPARTY_ROOT}/imgui" + "${SWA_THIRDPARTY_ROOT}/implot" "${SWA_THIRDPARTY_ROOT}/libmspack/libmspack/mspack" "${SWA_THIRDPARTY_ROOT}/magic_enum/include" "${SWA_THIRDPARTY_ROOT}/stb" diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp index 887aaa2f..f5a3afae 100644 --- a/UnleashedRecomp/gpu/video.cpp +++ b/UnleashedRecomp/gpu/video.cpp @@ -4,6 +4,7 @@ #include "imgui/imgui_snapshot.h" #include "imgui/imgui_font_builder.h" +#include #include #include #include @@ -1317,6 +1318,7 @@ void Video::CreateHostDevice(bool sdlVideoDefault) IMGUI_CHECKVERSION(); ImGui::CreateContext(); + ImPlot::CreateContext(); GameWindow::Init(sdlVideoDefault); @@ -1885,6 +1887,54 @@ static uint32_t HashVertexDeclaration(uint32_t vertexDeclaration) return vertexDeclaration; } +static bool g_profilerVisible; +static bool g_profilerWasToggled; +static constexpr size_t PROFILER_VALUE_COUNT = 256; +static double g_profilerDeltaTimes[PROFILER_VALUE_COUNT]; +static size_t g_profilerValueIndex; + +static void DrawProfiler() +{ + bool toggleProfiler = SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_F1] != 0; + + if (!g_profilerWasToggled && toggleProfiler) + g_profilerVisible = !g_profilerVisible; + + g_profilerWasToggled = toggleProfiler; + + if (!g_profilerVisible) + return; + + ImFont* font = ImFontAtlasSnapshot::GetFont("FOT-SeuratPro-M.otf"); + float defaultScale = font->Scale; + font->Scale = 16.0f / font->FontSize; + ImGui::PushFont(font); + + if (ImGui::Begin("Profiler", &g_profilerVisible)) + { + g_profilerDeltaTimes[g_profilerValueIndex] = App::s_deltaTime * 1000.0; + + if (ImPlot::BeginPlot("Frametimes")) + { + ImPlot::SetupAxisLimits(ImAxis_Y1, 8.0, 32.0); + ImPlot::SetupAxis(ImAxis_Y1, "ms", ImPlotAxisFlags_None); + ImPlot::PlotLine("Application", g_profilerDeltaTimes, PROFILER_VALUE_COUNT, 1.0, 0.0, ImPlotLineFlags_None, g_profilerValueIndex); + + ImPlot::EndPlot(); + } + + g_profilerValueIndex = (g_profilerValueIndex + 1) % PROFILER_VALUE_COUNT; + + const double deltaTimeAvg = std::accumulate(g_profilerDeltaTimes, g_profilerDeltaTimes + PROFILER_VALUE_COUNT, 0.0) / PROFILER_VALUE_COUNT; + + ImGui::Text("Average Application: %g ms (%g FPS)", deltaTimeAvg, 1000.0 / deltaTimeAvg); + } + ImGui::End(); + + ImGui::PopFont(); + font->Scale = defaultScale; +} + static void DrawImGui() { ImGui_ImplSDL2_NewFrame(); @@ -1916,6 +1966,8 @@ static void DrawImGui() MessageWindow::Draw(); ButtonGuide::Draw(); + DrawProfiler(); + ImGui::Render(); auto drawData = ImGui::GetDrawData(); diff --git a/UnleashedRecomp/stdafx.h b/UnleashedRecomp/stdafx.h index 929f0f58..40590b8f 100644 --- a/UnleashedRecomp/stdafx.h +++ b/UnleashedRecomp/stdafx.h @@ -39,6 +39,7 @@ using Microsoft::WRL::ComPtr; #include #include #include +#include #include #include #include @@ -47,6 +48,7 @@ using Microsoft::WRL::ComPtr; #include #include #include +#include #include "framework.h" #include "mutex.h"