From d0ee1eaa28fe91c3718d42c8cb0757d016cfdcda Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Thu, 21 Sep 2023 22:20:22 +0200 Subject: [PATCH] hudelements: frame_timing: draw plot using implot Implot allows us to draw multiple lines in the graph. We draw the frametime as usual but also include thermal and power throttling. Thermal throttling is red and power is yellow. --- README.md | 1 + data/MangoHud.conf | 2 ++ src/amdgpu.h | 8 ++++++ src/hud_elements.cpp | 57 ++++++++++++++++++++++++++++++++++++++++-- src/overlay.cpp | 2 -- src/overlay_params.cpp | 2 +- src/overlay_params.h | 1 + 7 files changed, 68 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 189cf5c2..319b1c40 100644 --- a/README.md +++ b/README.md @@ -404,6 +404,7 @@ Parameters that are enabled by default have to be explicitly disabled. These (cu | `text_outline_color=` | Set the color of `text_outline`. Default = `000000` | | `text_outline_thickness=` | Set the thickness of `text_outline`. Default = `1.5` | | `throttling_status` | Show if GPU is throttling based on Power, current, temp or "other" (Only shows if throttling is currently happening). Currently disabled by default for Nvidia as it causes lag on 3000 series | +| `throttling_status_graph` | Same as `throttling_status` but displays throttling in the frametime graph and only power and temp throttling | | `time`
`time_format=%T` | Display local time. See [std::put_time](https://en.cppreference.com/w/cpp/io/manip/put_time) for formatting help. NOTE: Sometimes apps may set `TZ` (timezone) environment variable to UTC/GMT | | `toggle_fps_limit` | Cycle between FPS limits. Defaults to `Shift_L+F1` | | `toggle_preset` | Cycle between Presets. Defaults to `Shift_R+F10` | diff --git a/data/MangoHud.conf b/data/MangoHud.conf index b449a91e..9f5b3ef5 100644 --- a/data/MangoHud.conf +++ b/data/MangoHud.conf @@ -138,6 +138,8 @@ frametime ### Display GPU throttling status based on Power, current, temp or "other" ## Only shows if throttling is currently happening throttling_status +## Same as throttling_status but displays throttling on the frametime graph +#throttling_status_graph ### Display miscellaneous information # engine_version diff --git a/src/amdgpu.h b/src/amdgpu.h index 79d296c7..54e56036 100644 --- a/src/amdgpu.h +++ b/src/amdgpu.h @@ -10,6 +10,7 @@ #include #include #include +#include #define METRICS_UPDATE_PERIOD_MS 500 #define METRICS_POLLING_PERIOD_MS 25 @@ -227,6 +228,13 @@ class Throttling { thermal.erase(thermal.begin()); } + bool power_throttling(){ + return std::find(power.begin(), power.end(), 0.1f) != power.end(); + } + + bool thermal_throttling(){ + return std::find(thermal.begin(), thermal.end(), 0.1f) != thermal.end(); + } }; extern std::unique_ptr throttling; diff --git a/src/hud_elements.cpp b/src/hud_elements.cpp index 3fb3d731..73d5dbaa 100644 --- a/src/hud_elements.cpp +++ b/src/hud_elements.cpp @@ -19,6 +19,10 @@ #include #include "version.h" #include "blacklist.h" +#ifdef __linux__ +#include "implot.h" +#endif +#include "amdgpu.h" #define CHAR_CELSIUS "\xe2\x84\x83" #define CHAR_FAHRENHEIT "\xe2\x84\x89" @@ -704,6 +708,17 @@ void HudElements::wine(){ } } +static inline double TransformForward_Custom(double v, void*) { + if (v > 50) + v = 49.9; + + return v; +} + +static inline double TransformInverse_Custom(double v, void*) { + return v; +} + void HudElements::frame_timing(){ if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_frame_timing]){ ImguiNextColumnFirstItem(); @@ -726,7 +741,7 @@ void HudElements::frame_timing(){ float width, height = 0; if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_horizontal]){ width = 150; - height = HUDElements.params->font_size; + height = HUDElements.params->font_size * 0.85; } else { width = ImGui::GetWindowContentRegionWidth(); height = max_time; @@ -737,20 +752,58 @@ void HudElements::frame_timing(){ max_time = max_frametime; } - if (ImGui::BeginChild("my_child_window", ImVec2(width, height))) { + if (ImGui::BeginChild("my_child_window", ImVec2(width, height), false, ImGuiWindowFlags_NoDecoration)) { if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_histogram]){ ImGui::PlotHistogram(hash, get_time_stat, HUDElements.sw_stats, ARRAY_SIZE(HUDElements.sw_stats->frames_stats), 0, NULL, min_time, max_time, ImVec2(width, height)); } else { +#ifndef __linux__ ImGui::PlotLines(hash, get_time_stat, HUDElements.sw_stats, ARRAY_SIZE(HUDElements.sw_stats->frames_stats), 0, NULL, min_time, max_time, ImVec2(width, height)); +#else + if (ImPlot::BeginPlot("My Plot", ImVec2(width, height), ImPlotFlags_CanvasOnly | ImPlotFlags_NoInputs)) { + ImPlotStyle& style = ImPlot::GetStyle(); + style.Colors[ImPlotCol_PlotBg] = ImVec4(0.92f, 0.92f, 0.95f, 0.00f); + ImPlotAxisFlags ax_flags = ImPlotAxisFlags_NoDecorations; + ImPlot::SetupAxes(nullptr, nullptr, ax_flags,ax_flags); + ImPlot::SetupAxisScale(ImAxis_Y1, TransformForward_Custom, TransformInverse_Custom); + ImPlot::SetupAxesLimits(0, 200, min_time, max_time); + ImPlot::PushStyleVar(ImPlotStyleVar_PlotPadding, ImVec2(0,0)); + ImPlot::SetNextLineStyle(ImVec4(0.0f, 1.0f, 0.0f, 1.0f), 1.5); + ImPlot::PlotLine("frametime line", frametime_data.data(), frametime_data.size()); + if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_throttling_status_graph] && throttling){ + ImPlot::SetNextLineStyle(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), 1.5); + ImPlot::PlotLine("power line", throttling->power.data(), throttling->power.size()); + ImPlot::SetNextLineStyle(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), 1.5); + ImPlot::PlotLine("thermal line", throttling->thermal.data(), throttling->thermal.size()); + } + ImPlot::EndPlot(); + } +#endif } } ImGui::EndChild(); + if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_throttling_status_graph] && throttling){ + ImGui::Dummy(ImVec2(0.0f, real_font_size.y / 2)); + + if (throttling->power_throttling()) { + ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "%s", ICON_FK_SQUARE); + ImGui::SameLine(); + ImGui::Text("Power throttling"); + } + + ImGui::Dummy(ImVec2(0.0f, real_font_size.y / 2)); + + if (throttling->thermal_throttling()) { + ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "%s", ICON_FK_SQUARE); + ImGui::SameLine(); + ImGui::Text("Thermal throttling"); + } + } ImGui::PopFont(); ImGui::PopStyleColor(); } diff --git a/src/overlay.cpp b/src/overlay.cpp index 36b1f8d5..bd1f44a4 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -673,12 +673,10 @@ void render_imgui(swapchain_stats& data, struct overlay_params& params, ImVec2& if (ImGui::BeginTable("hud", params.table_columns, table_flags )) { HUDElements.place = 0; for (auto& func : HUDElements.ordered_functions){ - ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(-3,-3)); if(!params.enabled[OVERLAY_PARAM_ENABLED_horizontal] && func.first != HudElements::_exec) ImGui::TableNextRow(); func.first(); HUDElements.place += 1; - ImGui::PopStyleVar(); if(!HUDElements.ordered_functions.empty() && params.enabled[OVERLAY_PARAM_ENABLED_horizontal] && func != HUDElements.ordered_functions.back()) horizontal_separator(params); } diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index 32a3eba8..44c319fa 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -1060,7 +1060,7 @@ void presets(int preset, struct overlay_params *params, bool inherit) { case 4: add_to_options(params, "full", "1"); add_to_options(params, "debug", "1"); - add_to_options(params, "throttling_status", "1"); + add_to_options(params, "throttling_status_graph", "1"); add_to_options(params, "io_read", "0"); add_to_options(params, "io_write", "0"); add_to_options(params, "arch", "0"); diff --git a/src/overlay_params.h b/src/overlay_params.h index 73f3994b..b721df25 100644 --- a/src/overlay_params.h +++ b/src/overlay_params.h @@ -85,6 +85,7 @@ typedef unsigned long KeySym; OVERLAY_PARAM_BOOL(hide_fsr_sharpness) \ OVERLAY_PARAM_BOOL(fan) \ OVERLAY_PARAM_BOOL(throttling_status) \ + OVERLAY_PARAM_BOOL(throttling_status_graph) \ OVERLAY_PARAM_BOOL(fcat) \ OVERLAY_PARAM_BOOL(log_versioning) \ OVERLAY_PARAM_BOOL(horizontal) \