From 1c40fd85690b87e614f79a161755c02265cd0570 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Jun 2019 01:52:04 -0400 Subject: [PATCH 1/5] VideoCommon/Statistics: Replace DRAW_STAT macro with variadic lambda We don't need to use the preprocessor here. We can just use a variadic lambda function instead and forward the arguments to the formatting function. --- Source/Core/VideoCommon/Statistics.cpp | 83 +++++++++++++------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/Source/Core/VideoCommon/Statistics.cpp b/Source/Core/VideoCommon/Statistics.cpp index 716dee4f73b0..b92c6fadc8b8 100644 --- a/Source/Core/VideoCommon/Statistics.cpp +++ b/Source/Core/VideoCommon/Statistics.cpp @@ -42,53 +42,52 @@ void Statistics::Display() ImGui::Columns(2, "Statistics", true); -#define DRAW_STAT(name, format, ...) \ - ImGui::Text(name); \ - ImGui::NextColumn(); \ - ImGui::Text(format, __VA_ARGS__); \ - ImGui::NextColumn(); + const auto draw_statistic = [](const char* name, const char* format, auto&&... args) { + ImGui::Text(name); + ImGui::NextColumn(); + ImGui::Text(format, std::forward(args)...); + ImGui::NextColumn(); + }; if (g_ActiveConfig.backend_info.api_type == APIType::Nothing) { - DRAW_STAT("Objects", "%d", stats.thisFrame.numDrawnObjects); - DRAW_STAT("Vertices Loaded", "%d", stats.thisFrame.numVerticesLoaded); - DRAW_STAT("Triangles Input", "%d", stats.thisFrame.numTrianglesIn); - DRAW_STAT("Triangles Rejected", "%d", stats.thisFrame.numTrianglesRejected); - DRAW_STAT("Triangles Culled", "%d", stats.thisFrame.numTrianglesCulled); - DRAW_STAT("Triangles Clipped", "%d", stats.thisFrame.numTrianglesClipped); - DRAW_STAT("Triangles Drawn", "%d", stats.thisFrame.numTrianglesDrawn); - DRAW_STAT("Rasterized Pix", "%d", stats.thisFrame.rasterizedPixels); - DRAW_STAT("TEV Pix In", "%d", stats.thisFrame.tevPixelsIn); - DRAW_STAT("TEV Pix Out", "%d", stats.thisFrame.tevPixelsOut); + draw_statistic("Objects", "%d", stats.thisFrame.numDrawnObjects); + draw_statistic("Vertices Loaded", "%d", stats.thisFrame.numVerticesLoaded); + draw_statistic("Triangles Input", "%d", stats.thisFrame.numTrianglesIn); + draw_statistic("Triangles Rejected", "%d", stats.thisFrame.numTrianglesRejected); + draw_statistic("Triangles Culled", "%d", stats.thisFrame.numTrianglesCulled); + draw_statistic("Triangles Clipped", "%d", stats.thisFrame.numTrianglesClipped); + draw_statistic("Triangles Drawn", "%d", stats.thisFrame.numTrianglesDrawn); + draw_statistic("Rasterized Pix", "%d", stats.thisFrame.rasterizedPixels); + draw_statistic("TEV Pix In", "%d", stats.thisFrame.tevPixelsIn); + draw_statistic("TEV Pix Out", "%d", stats.thisFrame.tevPixelsOut); } - DRAW_STAT("Textures created", "%d", stats.numTexturesCreated); - DRAW_STAT("Textures uploaded", "%d", stats.numTexturesUploaded); - DRAW_STAT("Textures alive", "%d", stats.numTexturesAlive); - DRAW_STAT("pshaders created", "%d", stats.numPixelShadersCreated); - DRAW_STAT("pshaders alive", "%d", stats.numPixelShadersAlive); - DRAW_STAT("vshaders created", "%d", stats.numVertexShadersCreated); - DRAW_STAT("vshaders alive", "%d", stats.numVertexShadersAlive); - DRAW_STAT("shaders changes", "%d", stats.thisFrame.numShaderChanges); - DRAW_STAT("dlists called", "%d", stats.thisFrame.numDListsCalled); - DRAW_STAT("Primitive joins", "%d", stats.thisFrame.numPrimitiveJoins); - DRAW_STAT("Draw calls", "%d", stats.thisFrame.numDrawCalls); - DRAW_STAT("Primitives", "%d", stats.thisFrame.numPrims); - DRAW_STAT("Primitives (DL)", "%d", stats.thisFrame.numDLPrims); - DRAW_STAT("XF loads", "%d", stats.thisFrame.numXFLoads); - DRAW_STAT("XF loads (DL)", "%d", stats.thisFrame.numXFLoadsInDL); - DRAW_STAT("CP loads", "%d", stats.thisFrame.numCPLoads); - DRAW_STAT("CP loads (DL)", "%d", stats.thisFrame.numCPLoadsInDL); - DRAW_STAT("BP loads", "%d", stats.thisFrame.numBPLoads); - DRAW_STAT("BP loads (DL)", "%d", stats.thisFrame.numBPLoadsInDL); - DRAW_STAT("Vertex streamed", "%i kB", stats.thisFrame.bytesVertexStreamed / 1024); - DRAW_STAT("Index streamed", "%i kB", stats.thisFrame.bytesIndexStreamed / 1024); - DRAW_STAT("Uniform streamed", "%i kB", stats.thisFrame.bytesUniformStreamed / 1024); - DRAW_STAT("Vertex Loaders", "%d", stats.numVertexLoaders); - DRAW_STAT("EFB peeks:", "%d", stats.thisFrame.numEFBPeeks); - DRAW_STAT("EFB pokes:", "%d", stats.thisFrame.numEFBPokes); - -#undef DRAW_STAT + draw_statistic("Textures created", "%d", stats.numTexturesCreated); + draw_statistic("Textures uploaded", "%d", stats.numTexturesUploaded); + draw_statistic("Textures alive", "%d", stats.numTexturesAlive); + draw_statistic("pshaders created", "%d", stats.numPixelShadersCreated); + draw_statistic("pshaders alive", "%d", stats.numPixelShadersAlive); + draw_statistic("vshaders created", "%d", stats.numVertexShadersCreated); + draw_statistic("vshaders alive", "%d", stats.numVertexShadersAlive); + draw_statistic("shaders changes", "%d", stats.thisFrame.numShaderChanges); + draw_statistic("dlists called", "%d", stats.thisFrame.numDListsCalled); + draw_statistic("Primitive joins", "%d", stats.thisFrame.numPrimitiveJoins); + draw_statistic("Draw calls", "%d", stats.thisFrame.numDrawCalls); + draw_statistic("Primitives", "%d", stats.thisFrame.numPrims); + draw_statistic("Primitives (DL)", "%d", stats.thisFrame.numDLPrims); + draw_statistic("XF loads", "%d", stats.thisFrame.numXFLoads); + draw_statistic("XF loads (DL)", "%d", stats.thisFrame.numXFLoadsInDL); + draw_statistic("CP loads", "%d", stats.thisFrame.numCPLoads); + draw_statistic("CP loads (DL)", "%d", stats.thisFrame.numCPLoadsInDL); + draw_statistic("BP loads", "%d", stats.thisFrame.numBPLoads); + draw_statistic("BP loads (DL)", "%d", stats.thisFrame.numBPLoadsInDL); + draw_statistic("Vertex streamed", "%i kB", stats.thisFrame.bytesVertexStreamed / 1024); + draw_statistic("Index streamed", "%i kB", stats.thisFrame.bytesIndexStreamed / 1024); + draw_statistic("Uniform streamed", "%i kB", stats.thisFrame.bytesUniformStreamed / 1024); + draw_statistic("Vertex Loaders", "%d", stats.numVertexLoaders); + draw_statistic("EFB peeks:", "%d", stats.thisFrame.numEFBPeeks); + draw_statistic("EFB pokes:", "%d", stats.thisFrame.numEFBPokes); ImGui::Columns(1); From e981fa2073ca4d1d34396a49959137c07e9fc615 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Jun 2019 01:54:18 -0400 Subject: [PATCH 2/5] VideoCommon/Statistics: Use ImGui::TextUnformatted() where applicable ImGui::Text() assumes that the incoming text is intended to be formatted, but we don't actually use it to format anything. We can be explicit by using the relevant function. This also has a plus of not needing to go through the formatter itself, but the gains from that are probably minimal. --- Source/Core/VideoCommon/Statistics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/Statistics.cpp b/Source/Core/VideoCommon/Statistics.cpp index b92c6fadc8b8..e8808a684d82 100644 --- a/Source/Core/VideoCommon/Statistics.cpp +++ b/Source/Core/VideoCommon/Statistics.cpp @@ -43,7 +43,7 @@ void Statistics::Display() ImGui::Columns(2, "Statistics", true); const auto draw_statistic = [](const char* name, const char* format, auto&&... args) { - ImGui::Text(name); + ImGui::TextUnformatted(name); ImGui::NextColumn(); ImGui::Text(format, std::forward(args)...); ImGui::NextColumn(); @@ -103,7 +103,7 @@ void Statistics::DisplayProj() return; } - ImGui::Text("Projection #: X for Raw 6=0 (X for Raw 6!=0)"); + ImGui::TextUnformatted("Projection #: X for Raw 6=0 (X for Raw 6!=0)"); ImGui::NewLine(); ImGui::Text("Projection 0: %f (%f) Raw 0: %f", stats.gproj_0, stats.g2proj_0, stats.proj_0); ImGui::Text("Projection 1: %f (%f)", stats.gproj_1, stats.g2proj_1); From 6416fe336cf65c3001b6428ecf2194581ada6aa2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Jun 2019 01:58:56 -0400 Subject: [PATCH 3/5] VideoCommon/Statistics: Replace memset with assignment in ResetFrame() Same behavior, less code, and it doesn't require the type ThisFrame itself to actually be a trivially-copyable type. --- Source/Core/VideoCommon/Statistics.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/Statistics.cpp b/Source/Core/VideoCommon/Statistics.cpp index e8808a684d82..981da2d2c96b 100644 --- a/Source/Core/VideoCommon/Statistics.cpp +++ b/Source/Core/VideoCommon/Statistics.cpp @@ -2,7 +2,6 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include #include #include @@ -17,7 +16,7 @@ Statistics stats; void Statistics::ResetFrame() { - memset(&thisFrame, 0, sizeof(ThisFrame)); + thisFrame = {}; } void Statistics::SwapDL() From 73710c07455ae6043787502281ae8d8b7e445530 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Jun 2019 02:00:58 -0400 Subject: [PATCH 4/5] VideoCommon/Statistics: Remove unused header inclusions These aren't used anywhere, so they can be removed. --- Source/Core/VideoCommon/Statistics.cpp | 3 --- Source/Core/VideoCommon/Statistics.h | 2 -- 2 files changed, 5 deletions(-) diff --git a/Source/Core/VideoCommon/Statistics.cpp b/Source/Core/VideoCommon/Statistics.cpp index 981da2d2c96b..cfed452676c0 100644 --- a/Source/Core/VideoCommon/Statistics.cpp +++ b/Source/Core/VideoCommon/Statistics.cpp @@ -2,14 +2,11 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include #include #include "imgui.h" -#include "Common/StringUtil.h" #include "VideoCommon/Statistics.h" -#include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VideoConfig.h" Statistics stats; diff --git a/Source/Core/VideoCommon/Statistics.h b/Source/Core/VideoCommon/Statistics.h index 431df7d9ded3..a98f73f012ba 100644 --- a/Source/Core/VideoCommon/Statistics.h +++ b/Source/Core/VideoCommon/Statistics.h @@ -4,8 +4,6 @@ #pragma once -#include - struct Statistics { int numPixelShadersCreated; From 5cafce3cc43240ab73cd67fc0376431e9c24d9fb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Jun 2019 02:02:46 -0400 Subject: [PATCH 5/5] VideoCommon/Statistics: Amend imgui include This is a library header, so it should be using '<' and '>' to delineate that. --- Source/Core/VideoCommon/Statistics.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/Statistics.cpp b/Source/Core/VideoCommon/Statistics.cpp index cfed452676c0..6350bb5c81de 100644 --- a/Source/Core/VideoCommon/Statistics.cpp +++ b/Source/Core/VideoCommon/Statistics.cpp @@ -2,11 +2,12 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "VideoCommon/Statistics.h" + #include -#include "imgui.h" +#include -#include "VideoCommon/Statistics.h" #include "VideoCommon/VideoConfig.h" Statistics stats;