Toast Engine
Loading...
Searching...
No Matches
perf_window.hpp
Go to the documentation of this file.
1
4
5#pragma once
6
7#include "../vulkan_renderer.hpp"
8
9#include <array>
10#include <chrono>
11#include <cstddef>
12#include <string>
13#include <vector>
14
15namespace renderer {
16
18public:
20 void draw();
21
22private:
23 static constexpr size_t k_history = 240;
24 using History = std::array<float, k_history>;
25
27 struct Sample {
28 float render_fps = 0.0f;
29 float game_fps = 0.0f;
30 float tick_rate = 0.0f;
31 float skipped_per_second = 0.0f;
32 float repeated_ratio = 0.0f;
33 float wait_ratio = 0.0f;
34
35 float draw_ms = 0.0f;
36 float upload_ms = 0.0f;
37 float gpu_wait_ms = 0.0f;
38 float acquire_ms = 0.0f;
39 float record_ms = 0.0f;
40 float submit_ms = 0.0f;
41 float present_ms = 0.0f;
42 float frame_wait_ms = 0.0f;
43 float pacing_ms = 0.0f;
44
45 float build_ms = 0.0f;
46 float slot_wait_ms = 0.0f;
47
48 float p99_interval_ms = 0.0f;
49 float max_interval_ms = 0.0f;
50 };
51
52 struct Phase {
53 const char* label;
54 float ms;
55 uint32_t color;
56 };
57
59 struct PassStats {
60 std::string name;
61 uint32_t depth = 0;
62 std::chrono::steady_clock::time_point last_seen;
63
64 // Accumulated since the last publish
65 double gpu_sum = 0.0;
66 double cpu_sum = 0.0;
67 double gpu_peak_acc = 0.0;
68 uint32_t runs_sum = 0;
69 uint32_t frames_run = 0;
70
71 // Published values the table shows
72 float gpu_avg = 0.0f;
73 float gpu_peak = 0.0f;
74 float cpu_avg = 0.0f;
75 float runs = 0.0f;
76 float presence = 0.0f;
77 float baseline = -1.0f;
78
80 [[nodiscard]]
81 auto perFrame() const -> float {
82 return gpu_avg * presence;
83 }
84 };
85
86 struct Verdict {
87 const char* label = "";
88 bool bad = false;
89 bool warn = false;
90 std::string detail;
91 };
92
93 void record(const GpuTimer* timer);
94 void accumulatePasses(const GpuTimer::Timings& frame);
95 void publishPasses();
96 [[nodiscard]]
97 auto heaviestPass(bool by_gpu) const -> const PassStats*;
98 void sample(const VulkanRenderer::PerfCounters& counters, uint32_t skipped);
99
100 [[nodiscard]]
101 auto phases() const -> std::array<Phase, 9>;
102 [[nodiscard]]
103 auto renderVerdict(bool has_gpu) const -> Verdict;
104 [[nodiscard]]
105 auto gameVerdict() const -> Verdict;
106
107 void drawSummary(bool has_gpu);
108 void drawFrameGraph(float width, float height);
109 void drawPhaseBar(float width, float height) const;
110 void drawFrameTab();
111 void drawGpuTab();
112 void drawMemoryTab();
113 void drawSceneTab();
114
115 [[nodiscard]]
116 auto historyOffset() const -> int;
117
118 std::chrono::steady_clock::time_point m_last_sample;
119 VulkanRenderer::PerfCounters m_last_counters {};
120 uint32_t m_last_skipped = 0;
121 bool m_has_sample = false;
122 Sample m_sample;
123
124 History m_interval_history {};
125 History m_gpu_history {};
127 std::vector<PassStats> m_passes;
128 uint64_t m_last_gpu_serial = 0;
129 uint32_t m_window_frames = 0;
130 double m_graphics_sum = 0.0;
131 float m_graphics_avg = 0.0f;
132 float m_graphics_baseline = -1.0f;
133 size_t m_cursor = 0;
134 size_t m_filled = 0;
135
137 float m_graph_scale_ms = 0.0f;
139 float m_budget_ms = 1000.0f / 60.0f;
140 float m_interval_ms = 0.0f;
141 float m_gpu_ms = 0.0f;
142
143 bool m_expanded = false;
145 bool m_apply_expanded_size = false;
146 float m_expanded_width = 0.0f;
147 float m_expanded_height = 0.0f;
148 float m_window_x = 0.0f;
149 float m_window_y = 0.0f;
150 bool m_hide_idle_passes = true;
151 bool m_has_gpu = false;
152};
153
154}
Definition gpu_timer.hpp:16
Definition perf_window.hpp:17
void draw()
Render thread only.
Definition perf_window.cpp:837
Definition gpu_timer.hpp:43
Definition vulkan_renderer.hpp:912