Finality Engine
Loading...
Searching...
No Matches
PerformancePanel.h
Go to the documentation of this file.
1
6#pragma once
7#include <Finality.h>
9#include <algorithm>
10
11namespace FINALITY
12{
13 inline void DrawPerformancePanel(float fps, int offset, const float* history, float average, const RenderTarget* scene, const RenderTarget* game, bool* open = nullptr)
14 {
15 if (!ImGui::Begin("Performance Overlay",open)) { ImGui::End(); return; }
16 ImGui::Text("FPS: %.1f | Frame average: %.2f ms",fps,average);
17 std::vector<float> samples;
18 for (int i = 0; i < 120; ++i) if (history[i] > 0) samples.push_back(history[i]);
19 if (!samples.empty())
20 {
21 std::sort(samples.begin(),samples.end());
22 auto percentile = [&](float fraction) { return samples[static_cast<size_t>(fraction*(samples.size()-1))]; };
23 ImGui::Text("CPU wall frame p50 / p95 / p99: %.2f / %.2f / %.2f ms",percentile(0.5f),percentile(0.95f),percentile(0.99f));
24 }
25 ImGui::Text("GPU main/postprocess only: %.2f ms",Renderer::GetDevice()->GetGPUTimeMS());
26 if (const auto* active = SceneManager::GetInstance().GetActiveScene())
27 ImGui::Text("Script update + cleanup CPU: %.3f ms | Calls: %llu",SceneManager::GetInstance().IsSimulationEnabled() ? active->GetScriptTimeMS() : 0,
28 static_cast<unsigned long long>(SceneManager::GetInstance().IsSimulationEnabled() ? active->GetScriptCalls() : 0));
29 if (scene && ImGui::CollapsingHeader("Scene View",ImGuiTreeNodeFlags_DefaultOpen)) ImGui::TextUnformatted(FormatViewportStatistics(*scene).c_str());
30 if (game && ImGui::CollapsingHeader("Game View",ImGuiTreeNodeFlags_DefaultOpen)) ImGui::TextUnformatted(FormatViewportStatistics(*game).c_str());
31 ImGui::PlotLines("##FrameHistory",history,120,offset,"Frame history (ms)",0,50,{0,80});
32 ImGui::TextDisabled("GPU viewport measurements are delayed until their frame fence completes.");
33 ImGui::End();
34 }
35}
static RenderDevice * GetDevice()
Definition Renderer.h:57
static SceneManager & GetInstance()
void DrawPerformancePanel(float fps, int offset, const float *history, float average, const RenderTarget *scene, const RenderTarget *game, bool *open=nullptr)
std::string FormatViewportStatistics(const RenderTarget &target)