| 1 | // Copyright 2008 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "VideoCommon/Statistics.h" |
| 5 | |
| 6 | #include <cstring> |
| 7 | #include <utility> |
| 8 | |
| 9 | #include <imgui.h> |
| 10 | |
| 11 | #include "Core/DolphinAnalytics.h" |
| 12 | #include "Core/HW/SystemTimers.h" |
| 13 | #include "Core/System.h" |
| 14 | |
| 15 | #include "VideoCommon/BPFunctions.h" |
| 16 | #include "VideoCommon/VideoCommon.h" |
| 17 | #include "VideoCommon/VideoConfig.h" |
| 18 | #include "VideoCommon/VideoEvents.h" |
| 19 | #include "VideoCommon/XFMemory.h" |
| 20 | |
| 21 | Statistics g_stats; |
| 22 | |
| 23 | static Common::EventHook s_before_frame_event; |
| 24 | static Common::EventHook s_after_frame_event; |
| 25 | |
| 26 | static bool clear_scissors; |
| 27 | |
| 28 | void Statistics::ResetFrame() |
| 29 | { |
| 30 | this_frame = {}; |
| 31 | clear_scissors = true; |
| 32 | if (scissors.size() > 1) |
| 33 | { |
| 34 | scissors.erase(scissors.begin(), scissors.end() - 1); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | void Statistics::SwapDL() |
| 39 | { |
| 40 | std::swap(this_frame.num_dl_prims, this_frame.num_prims); |
| 41 | std::swap(this_frame.num_xf_loads_in_dl, this_frame.num_xf_loads); |
| 42 | std::swap(this_frame.num_cp_loads_in_dl, this_frame.num_cp_loads); |
| 43 | std::swap(this_frame.num_bp_loads_in_dl, this_frame.num_bp_loads); |
| 44 | } |
| 45 | |
| 46 | void Statistics::Display() const |
| 47 | { |
| 48 | const float scale = ImGui::GetIO().DisplayFramebufferScale.x; |
| 49 | ImGui::SetNextWindowPos(ImVec2(10.0f * scale, 10.0f * scale), ImGuiCond_FirstUseEver); |
| 50 | ImGui::SetNextWindowSizeConstraints(ImVec2(275.0f * scale, 400.0f * scale), |
| 51 | ImGui::GetIO().DisplaySize); |
| 52 | if (!ImGui::Begin("Statistics", nullptr, ImGuiWindowFlags_NoNavInputs)) |
| 53 | { |
| 54 | ImGui::End(); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | ImGui::Columns(2, "Statistics", true); |
| 59 | |
| 60 | const auto draw_statistic = [](const char* name, const char* format, auto&&... args) { |
| 61 | ImGui::TextUnformatted(name); |
| 62 | ImGui::NextColumn(); |
| 63 | ImGui::Text(format, std::forward<decltype(args)>(args)...); |
| 64 | ImGui::NextColumn(); |
| 65 | }; |
| 66 | |
| 67 | if (g_backend_info.api_type == APIType::Nothing) |
| 68 | { |
| 69 | draw_statistic("Objects", "%d", this_frame.num_drawn_objects); |
| 70 | draw_statistic("Vertices Loaded", "%d", this_frame.num_vertices_loaded); |
| 71 | draw_statistic("Triangles Input", "%d", this_frame.num_triangles_in); |
| 72 | draw_statistic("Triangles Rejected", "%d", this_frame.num_triangles_rejected); |
| 73 | draw_statistic("Triangles Culled", "%d", this_frame.num_triangles_culled); |
| 74 | draw_statistic("Triangles Clipped", "%d", this_frame.num_triangles_clipped); |
| 75 | draw_statistic("Triangles Drawn", "%d", this_frame.num_triangles_drawn); |
| 76 | draw_statistic("Rasterized Pix", "%d", this_frame.rasterized_pixels); |
| 77 | draw_statistic("TEV Pix In", "%d", this_frame.tev_pixels_in); |
| 78 | draw_statistic("TEV Pix Out", "%d", this_frame.tev_pixels_out); |
| 79 | } |
| 80 | |
| 81 | draw_statistic("Textures created", "%d", num_textures_created); |
| 82 | draw_statistic("Textures uploaded", "%d", num_textures_uploaded); |
| 83 | draw_statistic("Textures alive", "%d", num_textures_alive); |
| 84 | draw_statistic("pshaders created", "%d", num_pixel_shaders_created); |
| 85 | draw_statistic("pshaders alive", "%d", num_pixel_shaders_alive); |
| 86 | draw_statistic("vshaders created", "%d", num_vertex_shaders_created); |
| 87 | draw_statistic("vshaders alive", "%d", num_vertex_shaders_alive); |
| 88 | draw_statistic("shaders changes", "%d", this_frame.num_shader_changes); |
| 89 | draw_statistic("dlists called", "%d", this_frame.num_dlists_called); |
| 90 | draw_statistic("Primitive joins", "%d", this_frame.num_primitive_joins); |
| 91 | draw_statistic("Draw calls", "%d", this_frame.num_draw_calls); |
| 92 | draw_statistic("Primitives", "%d", this_frame.num_prims); |
| 93 | draw_statistic("Primitives (DL)", "%d", this_frame.num_dl_prims); |
| 94 | draw_statistic("XF loads", "%d", this_frame.num_xf_loads); |
| 95 | draw_statistic("XF loads (DL)", "%d", this_frame.num_xf_loads_in_dl); |
| 96 | draw_statistic("CP loads", "%d", this_frame.num_cp_loads); |
| 97 | draw_statistic("CP loads (DL)", "%d", this_frame.num_cp_loads_in_dl); |
| 98 | draw_statistic("BP loads", "%d", this_frame.num_bp_loads); |
| 99 | draw_statistic("BP loads (DL)", "%d", this_frame.num_bp_loads_in_dl); |
| 100 | draw_statistic("Vertex streamed", "%i kB", this_frame.bytes_vertex_streamed / 1024); |
| 101 | draw_statistic("Index streamed", "%i kB", this_frame.bytes_index_streamed / 1024); |
| 102 | draw_statistic("Uniform streamed", "%i kB", this_frame.bytes_uniform_streamed / 1024); |
| 103 | draw_statistic("Vertex Loaders", "%d", num_vertex_loaders); |
| 104 | draw_statistic("EFB peeks:", "%d", this_frame.num_efb_peeks); |
| 105 | draw_statistic("EFB pokes:", "%d", this_frame.num_efb_pokes); |
| 106 | draw_statistic("Draw dones:", "%d", this_frame.num_draw_done); |
| 107 | draw_statistic("Tokens:", "%d/%d", this_frame.num_token, this_frame.num_token_int); |
| 108 | |
| 109 | ImGui::Columns(1); |
| 110 | |
| 111 | ImGui::End(); |
| 112 | } |
| 113 | |
| 114 | void Statistics::DisplayProj() const |
| 115 | { |
| 116 | if (!ImGui::Begin("Projection Statistics", nullptr, ImGuiWindowFlags_NoNavInputs)) |
| 117 | { |
| 118 | ImGui::End(); |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | ImGui::TextUnformatted("Projection #: X for Raw 6=0 (X for Raw 6!=0)"); |
| 123 | ImGui::NewLine(); |
| 124 | ImGui::Text("Projection 0: %f (%f) Raw 0: %f", gproj[0], g2proj[0], proj[0]); |
| 125 | ImGui::Text("Projection 1: %f (%f)", gproj[1], g2proj[1]); |
| 126 | ImGui::Text("Projection 2: %f (%f) Raw 1: %f", gproj[2], g2proj[2], proj[1]); |
| 127 | ImGui::Text("Projection 3: %f (%f)", gproj[3], g2proj[3]); |
| 128 | ImGui::Text("Projection 4: %f (%f)", gproj[4], g2proj[4]); |
| 129 | ImGui::Text("Projection 5: %f (%f) Raw 2: %f", gproj[5], g2proj[5], proj[2]); |
| 130 | ImGui::Text("Projection 6: %f (%f) Raw 3: %f", gproj[6], g2proj[6], proj[3]); |
| 131 | ImGui::Text("Projection 7: %f (%f)", gproj[7], g2proj[7]); |
| 132 | ImGui::Text("Projection 8: %f (%f)", gproj[8], g2proj[8]); |
| 133 | ImGui::Text("Projection 9: %f (%f)", gproj[9], g2proj[9]); |
| 134 | ImGui::Text("Projection 10: %f (%f) Raw 4: %f", gproj[10], g2proj[10], proj[4]); |
| 135 | ImGui::Text("Projection 11: %f (%f) Raw 5: %f", gproj[11], g2proj[11], proj[5]); |
| 136 | ImGui::Text("Projection 12: %f (%f)", gproj[12], g2proj[12]); |
| 137 | ImGui::Text("Projection 13: %f (%f)", gproj[13], g2proj[13]); |
| 138 | ImGui::Text("Projection 14: %f (%f)", gproj[14], g2proj[14]); |
| 139 | ImGui::Text("Projection 15: %f (%f)", gproj[15], g2proj[15]); |
| 140 | ImGui::NewLine(); |
| 141 | ImGui::Text("Avg Projection Viewport Ratio Persp(3D): %f", avg_persp_proj_viewport_ratio); |
| 142 | ImGui::Text("Avg Projection Viewport Ratio Ortho(2D): %f", avg_ortho_proj_viewport_ratio); |
| 143 | |
| 144 | ImGui::End(); |
| 145 | } |
| 146 | |
| 147 | void Statistics::AddScissorRect() |
| 148 | { |
| 149 | if (clear_scissors) |
| 150 | { |
| 151 | scissors.clear(); |
| 152 | clear_scissors = false; |
| 153 | } |
| 154 | |
| 155 | BPFunctions::ScissorResult scissor = BPFunctions::ComputeScissorRects( |
| 156 | bpmem.scissorTL, bpmem.scissorBR, bpmem.scissorOffset, xfmem.viewport); |
| 157 | bool add; |
| 158 | if (scissors.empty()) |
| 159 | { |
| 160 | add = true; |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | if (allow_duplicate_scissors) |
| 165 | { |
| 166 | // Only check the last entry |
| 167 | add = !scissors.back().Matches(scissor, show_scissors, show_viewports); |
| 168 | } |
| 169 | else |
| 170 | { |
| 171 | add = std::ranges::find_if(scissors, [&](auto& s) { |
| 172 | return s.Matches(scissor, show_scissors, show_viewports); |
| 173 | }) == scissors.end(); |
| 174 | } |
| 175 | } |
| 176 | if (add) |
| 177 | scissors.push_back(std::move(scissor)); |
| 178 | } |
| 179 | |
| 180 | void Statistics::DisplayScissor() |
| 181 | { |
| 182 | // TODO: This is the same position as the regular statistics text |
| 183 | const float scale = ImGui::GetIO().DisplayFramebufferScale.x; |
| 184 | ImGui::SetNextWindowPos(ImVec2(10.0f * scale, 10.0f * scale), ImGuiCond_FirstUseEver); |
| 185 | |
| 186 | if (!ImGui::Begin("Scissor Rectangles", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) |
| 187 | { |
| 188 | ImGui::End(); |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | if (ImGui::TreeNode("Options")) |
| 193 | { |
| 194 | ImGui::Checkbox("Allow Duplicates", &allow_duplicate_scissors); |
| 195 | ImGui::Checkbox("Show Scissors", &show_scissors); |
| 196 | ImGui::BeginDisabled(!show_scissors); |
| 197 | ImGui::Checkbox("Show Raw Values", &show_raw_scissors); |
| 198 | ImGui::EndDisabled(); |
| 199 | ImGui::Checkbox("Show Viewports", &show_viewports); |
| 200 | ImGui::Checkbox("Show Text", &show_text); |
| 201 | ImGui::DragInt("Scale", &scissor_scale, .2f, 1, 16); |
| 202 | ImGui::DragInt("Expected Scissor Count", &scissor_expected_count, .2f, 0, 16); |
| 203 | ImGui::TreePop(); |
| 204 | } |
| 205 | |
| 206 | ImGui::BeginDisabled(current_scissor == 0); |
| 207 | if (ImGui::ArrowButton("##left", ImGuiDir_Left)) |
| 208 | { |
| 209 | current_scissor--; |
| 210 | } |
| 211 | ImGui::EndDisabled(); |
| 212 | ImGui::SameLine(); |
| 213 | ImGui::BeginDisabled(current_scissor >= scissors.size()); |
| 214 | if (ImGui::ArrowButton("##right", ImGuiDir_Right)) |
| 215 | { |
| 216 | current_scissor++; |
| 217 | if (current_scissor > scissors.size()) |
| 218 | { |
| 219 | current_scissor = scissors.size(); |
| 220 | } |
| 221 | } |
| 222 | ImGui::EndDisabled(); |
| 223 | ImGui::SameLine(); |
| 224 | if (current_scissor == 0) |
| 225 | ImGui::Text("Displaying all %zu rectangle(s)", scissors.size()); |
| 226 | else if (current_scissor <= scissors.size()) |
| 227 | ImGui::Text("Displaying rectangle %zu / %zu", current_scissor, scissors.size()); |
| 228 | else |
| 229 | ImGui::Text("Displaying rectangle %zu / %zu (OoB)", current_scissor, scissors.size()); |
| 230 | |
| 231 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); |
| 232 | ImVec2 p = ImGui::GetCursorScreenPos(); |
| 233 | ImGui::Dummy(ImVec2(1024 * 3 / scissor_scale, 1024 * 3 / scissor_scale)); |
| 234 | |
| 235 | constexpr int DRAW_START = -1024; |
| 236 | constexpr int DRAW_END = DRAW_START + 3 * 1024; |
| 237 | |
| 238 | const auto vec = [&](int x, int y, int xoff = 0, int yoff = 0) { |
| 239 | return ImVec2(p.x + int(float(x - DRAW_START) / scissor_scale) + xoff, |
| 240 | p.y + int(float(y - DRAW_START) / scissor_scale) + yoff); |
| 241 | }; |
| 242 | |
| 243 | const auto light_grey = ImGui::GetColorU32(ImVec4(.5f, .5f, .5f, 1.f)); |
| 244 | |
| 245 | // Draw gridlines |
| 246 | for (int x = DRAW_START; x <= DRAW_END; x += 1024) |
| 247 | draw_list->AddLine(vec(x, DRAW_START), vec(x, DRAW_END), light_grey); |
| 248 | for (int y = DRAW_START; y <= DRAW_END; y += 1024) |
| 249 | draw_list->AddLine(vec(DRAW_START, y), vec(DRAW_END, y), light_grey); |
| 250 | |
| 251 | const auto draw_x = [&](int x, int y, int size, ImU32 col) { |
| 252 | // Add an extra offset on the second parameter as otherwise ImGui seems to give results that are |
| 253 | // too small on one side |
| 254 | draw_list->AddLine(vec(x, y, -size, -size), vec(x, y, +size + 1, +size + 1), col); |
| 255 | draw_list->AddLine(vec(x, y, -size, +size), vec(x, y, +size + 1, -size - 1), col); |
| 256 | }; |
| 257 | const auto draw_rect = [&](int x0, int y0, int x1, int y1, ImU32 col, bool show_oob = true) { |
| 258 | x0 = std::clamp(x0, DRAW_START, DRAW_END); |
| 259 | y0 = std::clamp(y0, DRAW_START, DRAW_END); |
| 260 | x1 = std::clamp(x1, DRAW_START, DRAW_END); |
| 261 | y1 = std::clamp(y1, DRAW_START, DRAW_END); |
| 262 | if (x0 < x1 && y0 < y1) |
| 263 | { |
| 264 | draw_list->AddRect(vec(x0, y0), vec(x1, y1), col); |
| 265 | } |
| 266 | else if (show_oob) |
| 267 | { |
| 268 | // Markers at the two corners, for when they don't form a valid rectangle. |
| 269 | draw_list->AddLine(vec(x0, y0), vec(x0, y0, 8, 0), col); |
| 270 | draw_list->AddLine(vec(x0, y0), vec(x0, y0, 0, 8), col); |
| 271 | draw_list->AddLine(vec(x1, y1), vec(x1, y1, -8, 0), col); |
| 272 | draw_list->AddLine(vec(x1, y1), vec(x1, y1, 0, -8), col); |
| 273 | } |
| 274 | }; |
| 275 | static std::array<ImVec4, 6> COLORS = { |
| 276 | ImVec4(1, 0, 0, 1), ImVec4(1, 1, 0, 1), ImVec4(0, 1, 0, 1), |
| 277 | ImVec4(0, 1, 1, 1), ImVec4(0, 0, 1, 1), ImVec4(1, 0, 1, 1), |
| 278 | }; |
| 279 | const auto draw_scissor = [&](size_t index) { |
| 280 | const auto& info = scissors[index]; |
| 281 | const ImU32 col = ImGui::GetColorU32(COLORS[index % COLORS.size()]); |
| 282 | int x_off = info.scissor_off.x << 1; |
| 283 | int y_off = info.scissor_off.y << 1; |
| 284 | // Subtract 2048 instead of 1024, because when x_off is large enough we need to show two |
| 285 | // rectangles in the upper sections |
| 286 | for (int y = y_off - 2048; y < DRAW_END; y += 1024) |
| 287 | { |
| 288 | for (int x = x_off - 2048; x < DRAW_END; x += 1024) |
| 289 | { |
| 290 | draw_rect(x, y, x + EFB_WIDTH, y + EFB_HEIGHT, col, false); |
| 291 | } |
| 292 | } |
| 293 | // Use the full offset here so that ones that have the extra bit set show up distinctly |
| 294 | draw_x(info.scissor_off.x_full << 1, info.scissor_off.y_full << 1, 4, col); |
| 295 | |
| 296 | if (show_scissors) |
| 297 | { |
| 298 | draw_rect(info.scissor_tl.x, info.scissor_tl.y, info.scissor_br.x + 1, info.scissor_br.y + 1, |
| 299 | col); |
| 300 | } |
| 301 | if (show_viewports) |
| 302 | { |
| 303 | draw_rect(info.viewport_left, info.viewport_top, info.viewport_right, info.viewport_bottom, |
| 304 | col); |
| 305 | } |
| 306 | for (size_t i = 0; i < info.rectangles.size(); i++) |
| 307 | { |
| 308 | // The last entry in the sorted list of results is the one that is used by hardware backends |
| 309 | const u8 new_alpha = (i == info.rectangles.size() - 1) ? 0x40 : 0x80; |
| 310 | const ImU32 new_col = (col & ~IM_COL32_A_MASK) | (new_alpha << IM_COL32_A_SHIFT); |
| 311 | |
| 312 | const auto& r = info.rectangles[i]; |
| 313 | draw_list->AddRectFilled(vec(r.rect.left + r.x_off, r.rect.top + r.y_off), |
| 314 | vec(r.rect.right + r.x_off, r.rect.bottom + r.y_off), new_col); |
| 315 | } |
| 316 | }; |
| 317 | constexpr auto NUM_SCISSOR_COLUMNS = 8; |
| 318 | const auto draw_scissor_table_header = [&] { |
| 319 | ImGui::TableSetupColumn("#"); |
| 320 | ImGui::TableSetupColumn("x0"); |
| 321 | ImGui::TableSetupColumn("y0"); |
| 322 | ImGui::TableSetupColumn("x1"); |
| 323 | ImGui::TableSetupColumn("y1"); |
| 324 | ImGui::TableSetupColumn("xOff"); |
| 325 | ImGui::TableSetupColumn("yOff"); |
| 326 | ImGui::TableSetupColumn("Affected"); |
| 327 | ImGui::TableHeadersRow(); |
| 328 | }; |
| 329 | const auto draw_scissor_table_row = [&](size_t index) { |
| 330 | const auto& info = scissors[index]; |
| 331 | int x_off = (info.scissor_off.x << 1) - info.viewport_top; |
| 332 | int y_off = (info.scissor_off.y << 1) - info.viewport_left; |
| 333 | int x0 = info.scissor_tl.x - info.viewport_top; |
| 334 | int x1 = info.scissor_br.x - info.viewport_left; |
| 335 | int y0 = info.scissor_tl.y - info.viewport_top; |
| 336 | int y1 = info.scissor_br.y - info.viewport_left; |
| 337 | ImGui::TableNextColumn(); |
| 338 | ImGui::TextColored(COLORS[index % COLORS.size()], "%zu", index + 1); |
| 339 | ImGui::TableNextColumn(); |
| 340 | ImGui::Text("%d", x0); |
| 341 | ImGui::TableNextColumn(); |
| 342 | ImGui::Text("%d", y0); |
| 343 | ImGui::TableNextColumn(); |
| 344 | ImGui::Text("%d", x1); |
| 345 | ImGui::TableNextColumn(); |
| 346 | ImGui::Text("%d", y1); |
| 347 | ImGui::TableNextColumn(); |
| 348 | ImGui::Text("%d", x_off); |
| 349 | ImGui::TableNextColumn(); |
| 350 | ImGui::Text("%d", y_off); |
| 351 | |
| 352 | // Visualization of where things are updated on screen with this specific scissor |
| 353 | ImGui::TableNextColumn(); |
| 354 | float scale_height = ImGui::GetTextLineHeight() / EFB_HEIGHT; |
| 355 | if (show_raw_scissors) |
| 356 | scale_height += ImGui::GetTextLineHeightWithSpacing() / EFB_HEIGHT; |
| 357 | ImVec2 p2 = ImGui::GetCursorScreenPos(); |
| 358 | // Use a height of 1 since we want this to span two table rows (if possible) |
| 359 | ImGui::Dummy(ImVec2(EFB_WIDTH * scale_height, 1)); |
| 360 | for (size_t i = 0; i < info.rectangles.size(); i++) |
| 361 | { |
| 362 | // The last entry in the sorted list of results is the one that is used by hardware backends |
| 363 | const u8 new_alpha = (i == info.rectangles.size() - 1) ? 0x80 : 0x40; |
| 364 | const ImU32 col = ImGui::GetColorU32(COLORS[index % COLORS.size()]); |
| 365 | const ImU32 new_col = (col & ~IM_COL32_A_MASK) | (new_alpha << IM_COL32_A_SHIFT); |
| 366 | |
| 367 | const auto& r = info.rectangles[i]; |
| 368 | draw_list->AddRectFilled( |
| 369 | ImVec2(p2.x + r.rect.left * scale_height, p2.y + r.rect.top * scale_height), |
| 370 | ImVec2(p2.x + r.rect.right * scale_height, p2.y + r.rect.bottom * scale_height), new_col); |
| 371 | } |
| 372 | draw_list->AddRect( |
| 373 | p2, ImVec2(p2.x + EFB_WIDTH * scale_height, p2.y + EFB_HEIGHT * scale_height), light_grey); |
| 374 | ImGui::SameLine(); |
| 375 | ImGui::Text("%d", int(info.rectangles.size())); |
| 376 | |
| 377 | if (show_raw_scissors) |
| 378 | { |
| 379 | ImGui::TableNextColumn(); |
| 380 | ImGui::TextColored(COLORS[index % COLORS.size()], "Raw"); |
| 381 | ImGui::TableNextColumn(); |
| 382 | ImGui::Text("%d", info.scissor_tl.x_full.Value()); |
| 383 | ImGui::TableNextColumn(); |
| 384 | ImGui::Text("%d", info.scissor_tl.y_full.Value()); |
| 385 | ImGui::TableNextColumn(); |
| 386 | ImGui::Text("%d", info.scissor_br.x_full.Value()); |
| 387 | ImGui::TableNextColumn(); |
| 388 | ImGui::Text("%d", info.scissor_br.y_full.Value()); |
| 389 | ImGui::TableNextColumn(); |
| 390 | ImGui::Text("%d", info.scissor_off.x_full.Value()); |
| 391 | ImGui::TableNextColumn(); |
| 392 | ImGui::Text("%d", info.scissor_off.y_full.Value()); |
| 393 | ImGui::TableNextColumn(); |
| 394 | } |
| 395 | }; |
| 396 | const auto scissor_table_skip_row = [&](size_t index) { |
| 397 | ImGui::TableNextRow(); |
| 398 | ImGui::TableNextColumn(); |
| 399 | ImGui::TextColored(COLORS[index % COLORS.size()], "%zu", index + 1); |
| 400 | if (show_raw_scissors) |
| 401 | { |
| 402 | ImGui::TableNextRow(); |
| 403 | ImGui::TableNextColumn(); |
| 404 | ImGui::TextColored(COLORS[index % COLORS.size()], "Raw"); |
| 405 | } |
| 406 | }; |
| 407 | constexpr auto NUM_VIEWPORT_COLUMNS = 5; |
| 408 | const auto draw_viewport_table_header = [&] { |
| 409 | ImGui::TableSetupColumn("#"); |
| 410 | ImGui::TableSetupColumn("vx0"); |
| 411 | ImGui::TableSetupColumn("vy0"); |
| 412 | ImGui::TableSetupColumn("vx1"); |
| 413 | ImGui::TableSetupColumn("vy1"); |
| 414 | ImGui::TableHeadersRow(); |
| 415 | }; |
| 416 | const auto draw_viewport_table_row = [&](size_t index) { |
| 417 | const auto& info = scissors[index]; |
| 418 | ImGui::TableNextColumn(); |
| 419 | ImGui::TextColored(COLORS[index % COLORS.size()], "%zu", index + 1); |
| 420 | ImGui::TableNextColumn(); |
| 421 | ImGui::Text("%.1f", info.viewport_left); |
| 422 | ImGui::TableNextColumn(); |
| 423 | ImGui::Text("%.1f", info.viewport_top); |
| 424 | ImGui::TableNextColumn(); |
| 425 | ImGui::Text("%.1f", info.viewport_right); |
| 426 | ImGui::TableNextColumn(); |
| 427 | ImGui::Text("%.1f", info.viewport_bottom); |
| 428 | }; |
| 429 | const auto viewport_table_skip_row = [&](size_t index) { |
| 430 | ImGui::TableNextRow(); |
| 431 | ImGui::TableNextColumn(); |
| 432 | ImGui::TextColored(COLORS[index % COLORS.size()], "%zu", index + 1); |
| 433 | }; |
| 434 | if (current_scissor == 0) |
| 435 | { |
| 436 | for (size_t i = 0; i < scissors.size(); i++) |
| 437 | draw_scissor(i); |
| 438 | if (show_text) |
| 439 | { |
| 440 | if (show_scissors) |
| 441 | { |
| 442 | if (ImGui::BeginTable("Scissors", NUM_SCISSOR_COLUMNS)) |
| 443 | { |
| 444 | draw_scissor_table_header(); |
| 445 | for (size_t i = 0; i < scissors.size(); i++) |
| 446 | draw_scissor_table_row(i); |
| 447 | for (size_t i = scissors.size(); i < static_cast<size_t>(scissor_expected_count); i++) |
| 448 | scissor_table_skip_row(i); |
| 449 | ImGui::EndTable(); |
| 450 | } |
| 451 | } |
| 452 | if (show_viewports) |
| 453 | { |
| 454 | if (ImGui::BeginTable("Viewports", NUM_VIEWPORT_COLUMNS)) |
| 455 | { |
| 456 | draw_viewport_table_header(); |
| 457 | for (size_t i = 0; i < scissors.size(); i++) |
| 458 | draw_viewport_table_row(i); |
| 459 | for (size_t i = scissors.size(); i < static_cast<size_t>(scissor_expected_count); i++) |
| 460 | viewport_table_skip_row(i); |
| 461 | ImGui::EndTable(); |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | else if (current_scissor <= scissors.size()) |
| 467 | { |
| 468 | // This bounds check is needed since we only clamp when changing the value; different frames may |
| 469 | // have different numbers |
| 470 | draw_scissor(current_scissor - 1); |
| 471 | if (show_text) |
| 472 | { |
| 473 | if (show_scissors) |
| 474 | { |
| 475 | if (ImGui::BeginTable("Scissors", NUM_SCISSOR_COLUMNS)) |
| 476 | { |
| 477 | draw_scissor_table_header(); |
| 478 | draw_scissor_table_row(current_scissor - 1); |
| 479 | ImGui::EndTable(); |
| 480 | } |
| 481 | if (ImGui::BeginTable("Viewports", NUM_VIEWPORT_COLUMNS)) |
| 482 | { |
| 483 | draw_viewport_table_header(); |
| 484 | draw_viewport_table_row(current_scissor - 1); |
| 485 | ImGui::EndTable(); |
| 486 | } |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | else if (show_text) |
| 491 | { |
| 492 | if (show_scissors) |
| 493 | ImGui::Text("Scissor %zu: Does not exist", current_scissor); |
| 494 | if (show_viewports) |
| 495 | ImGui::Text("Viewport %zu: Does not exist", current_scissor); |
| 496 | } |
| 497 | |
| 498 | ImGui::End(); |
| 499 | } |
| 500 | |
| 501 | void Statistics::Init() |
| 502 | { |
| 503 | s_before_frame_event = GetVideoEvents().before_frame_event.Register([] { g_stats.ResetFrame(); }); |
| 504 | |
| 505 | s_after_frame_event = GetVideoEvents().after_frame_event.Register([](const Core::System& system) { |
| 506 | DolphinAnalytics::Instance().ReportPerformanceInfo({ |
| 507 | .speed_ratio = system.GetSystemTimers().GetEstimatedEmulationPerformance(), |
| 508 | .num_prims = g_stats.this_frame.num_prims + g_stats.this_frame.num_dl_prims, |
| 509 | .num_draw_calls = g_stats.this_frame.num_draw_calls, |
| 510 | }); |
| 511 | }); |
| 512 | } |
| 513 | |
| 514 | void Statistics::Shutdown() |
| 515 | { |
| 516 | s_before_frame_event.reset(); |
| 517 | s_after_frame_event.reset(); |
| 518 | } |