From 1754cbda9d028307443ffd1e3e51ec1849d95ade Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Wed, 9 Jul 2014 23:18:11 +0200 Subject: [PATCH 1/4] Move FPSCounter calls to RenderBase. --- Source/Core/VideoBackends/D3D/Render.cpp | 9 --------- Source/Core/VideoBackends/OGL/Render.cpp | 5 ----- Source/Core/VideoCommon/RenderBase.cpp | 8 ++++++++ Source/Core/VideoCommon/RenderBase.h | 2 ++ 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index adb9613213..fd56ca3214 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -27,7 +27,6 @@ #include "VideoCommon/AVIDump.h" #include "VideoCommon/BPFunctions.h" #include "VideoCommon/Fifo.h" -#include "VideoCommon/FPSCounter.h" #include "VideoCommon/ImageWrite.h" #include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/PixelEngine.h" @@ -38,8 +37,6 @@ namespace DX11 { -static int s_fps = 0; - static u32 s_LastAA = 0; static Television s_television; @@ -181,8 +178,6 @@ Renderer::Renderer(void *&window_handle) { int x, y, w_temp, h_temp; - FPSCounter::Initialize(); - Host_GetRenderWindowSize(x, y, w_temp, h_temp); D3D::Create((HWND)window_handle); @@ -952,10 +947,6 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl FramebufferManagerBase::SetLastXfbHeight(h); } - // update FPS counter - if (XFBWrited) - s_fps = FPSCounter::Update(); - // Flip/present backbuffer to frontbuffer here D3D::Present(); diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index f2567c0c8b..a261a28cb6 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -36,7 +36,6 @@ #include "VideoCommon/BPStructs.h" #include "VideoCommon/DriverDetails.h" #include "VideoCommon/Fifo.h" -#include "VideoCommon/FPSCounter.h" #include "VideoCommon/ImageWrite.h" #include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/PixelEngine.h" @@ -85,7 +84,6 @@ VideoConfig g_ogl_config; // Declarations and definitions // ---------------------------- -static int s_fps = 0; static GLuint s_ShowEFBCopyRegions_VBO = 0; static GLuint s_ShowEFBCopyRegions_VAO = 0; static SHADER s_ShowEFBCopyRegions; @@ -340,7 +338,6 @@ Renderer::Renderer() s_fps=0; s_ShowEFBCopyRegions_VBO = 0; s_blendMode = 0; - FPSCounter::Initialize(); bool bSuccess = true; @@ -1583,8 +1580,6 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl } } - if (XFBWrited) - s_fps = FPSCounter::Update(); // --------------------------------------------------------------------- if (!DriverDetails::HasBug(DriverDetails::BUG_BROKENSWAP)) { diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 2c95cdf89d..aa8a9f1d27 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -29,6 +29,7 @@ #include "VideoCommon/CPMemory.h" #include "VideoCommon/Debugger.h" #include "VideoCommon/Fifo.h" +#include "VideoCommon/FPSCounter.h" #include "VideoCommon/FramebufferManagerBase.h" #include "VideoCommon/MainBase.h" #include "VideoCommon/OpcodeDecoding.h" @@ -64,6 +65,8 @@ int Renderer::s_LastEFBScale; bool Renderer::s_skipSwap; bool Renderer::XFBWrited; +unsigned int Renderer::s_fps = 0; + PEControl::PixelFormat Renderer::prev_efb_format = PEControl::INVALID_FMT; unsigned int Renderer::efb_scale_numeratorX = 1; unsigned int Renderer::efb_scale_numeratorY = 1; @@ -84,6 +87,8 @@ Renderer::Renderer() OSDChoice = 0; OSDTime = 0; + + FPSCounter::Initialize(); } Renderer::~Renderer() @@ -521,6 +526,9 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& // TODO: merge more generic parts into VideoCommon g_renderer->SwapImpl(xfbAddr, fbWidth, fbHeight, rc, Gamma); + if (XFBWrited) + s_fps = FPSCounter::Update(); + frameCount++; GFX_DEBUGGER_PAUSE_AT(NEXT_FRAME, true); diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index 16b17ae8de..668a2a42eb 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -150,6 +150,8 @@ protected: static bool s_skipSwap; static bool XFBWrited; + static unsigned int s_fps; + private: static PEControl::PixelFormat prev_efb_format; static unsigned int efb_scale_numeratorX; From 6def4ead01bfcf3b5b12bbb7e16f21217d6088bf Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Wed, 9 Jul 2014 22:30:34 +0200 Subject: [PATCH 2/4] FPSCounter: Flush the logs every second and close them when the renderer is shut down. --- Source/Core/VideoCommon/FPSCounter.cpp | 7 +++++++ Source/Core/VideoCommon/FPSCounter.h | 3 +++ Source/Core/VideoCommon/RenderBase.cpp | 2 ++ 3 files changed, 12 insertions(+) diff --git a/Source/Core/VideoCommon/FPSCounter.cpp b/Source/Core/VideoCommon/FPSCounter.cpp index 10bfebb26f..c9615a2f68 100644 --- a/Source/Core/VideoCommon/FPSCounter.cpp +++ b/Source/Core/VideoCommon/FPSCounter.cpp @@ -34,6 +34,12 @@ void Initialize() s_bench_file.close(); } +void Shutdown() +{ + if (s_bench_file.is_open()) + s_bench_file.close(); +} + static void LogRenderTimeToFile(u64 val) { if (!s_bench_file.is_open()) @@ -49,6 +55,7 @@ int Update() s_update_time.Update(); s_fps = s_counter - s_fps_last_counter; s_fps_last_counter = s_counter; + s_bench_file.flush(); } if (g_ActiveConfig.bLogRenderTimeToFile) diff --git a/Source/Core/VideoCommon/FPSCounter.h b/Source/Core/VideoCommon/FPSCounter.h index 9bdee876eb..2ce61beaec 100644 --- a/Source/Core/VideoCommon/FPSCounter.h +++ b/Source/Core/VideoCommon/FPSCounter.h @@ -9,6 +9,9 @@ namespace FPSCounter // Initializes the FPS counter. void Initialize(); +// Shutdown the FPS counter by closing the logs. +void Shutdown(); + // Called when a frame is rendered. Returns the value to be displayed on // screen as the FPS counter (updated every second). int Update(); diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index aa8a9f1d27..68afa4e11a 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -105,6 +105,8 @@ Renderer::~Renderer() if (pFrameDump.IsOpen()) pFrameDump.Close(); #endif + + FPSCounter::Shutdown(); } void Renderer::RenderToXFB(u32 xfbAddr, const EFBRectangle& sourceRc, u32 fbWidth, u32 fbHeight, float Gamma) From 3b978f7c27fe2552e5bfb0e97ef9c82580d8a9d9 Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Sun, 13 Jul 2014 13:04:25 +0200 Subject: [PATCH 3/4] Turn the FPSCounter namespace into a class. --- Source/Core/VideoBackends/D3D/Render.cpp | 3 +- Source/Core/VideoBackends/OGL/Render.cpp | 4 +- Source/Core/VideoCommon/FPSCounter.cpp | 57 +++++++++--------------- Source/Core/VideoCommon/FPSCounter.h | 35 +++++++++++---- Source/Core/VideoCommon/RenderBase.cpp | 8 +--- Source/Core/VideoCommon/RenderBase.h | 3 +- 6 files changed, 53 insertions(+), 57 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index fd56ca3214..2699b56a46 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -27,6 +27,7 @@ #include "VideoCommon/AVIDump.h" #include "VideoCommon/BPFunctions.h" #include "VideoCommon/Fifo.h" +#include "VideoCommon/FPSCounter.h" #include "VideoCommon/ImageWrite.h" #include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/PixelEngine.h" @@ -898,7 +899,7 @@ void Renderer::SwapImpl(u32 xfbAddr, u32 fbWidth, u32 fbHeight,const EFBRectangl // Finish up the current frame, print some stats if (g_ActiveConfig.bShowFPS) { - std::string fps = StringFromFormat("FPS: %d\n", s_fps); + std::string fps = StringFromFormat("FPS: %d\n", m_fps_counter.m_fps); D3D::font.DrawTextScaled(0, 0, 20, 0.0f, 0xFF00FFFF, fps); } diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index a261a28cb6..d0ec359a2c 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -36,6 +36,7 @@ #include "VideoCommon/BPStructs.h" #include "VideoCommon/DriverDetails.h" #include "VideoCommon/Fifo.h" +#include "VideoCommon/FPSCounter.h" #include "VideoCommon/ImageWrite.h" #include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/PixelEngine.h" @@ -335,7 +336,6 @@ Renderer::Renderer() OSDInternalW = 0; OSDInternalH = 0; - s_fps=0; s_ShowEFBCopyRegions_VBO = 0; s_blendMode = 0; @@ -683,7 +683,7 @@ void Renderer::DrawDebugInfo() std::string debug_info; if (g_ActiveConfig.bShowFPS) - debug_info += StringFromFormat("FPS: %d\n", s_fps); + debug_info += StringFromFormat("FPS: %d\n", m_fps_counter.m_fps); if (SConfig::GetInstance().m_ShowLag) debug_info += StringFromFormat("Lag: %" PRIu64 "\n", Movie::g_currentLagCount); diff --git a/Source/Core/VideoCommon/FPSCounter.cpp b/Source/Core/VideoCommon/FPSCounter.cpp index c9615a2f68..7a912c2fd7 100644 --- a/Source/Core/VideoCommon/FPSCounter.cpp +++ b/Source/Core/VideoCommon/FPSCounter.cpp @@ -10,61 +10,44 @@ #include "VideoCommon/FPSCounter.h" #include "VideoCommon/VideoConfig.h" -namespace FPSCounter -{ #define FPS_REFRESH_INTERVAL 1000 -static unsigned int s_counter = 0; -static unsigned int s_fps = 0; -static unsigned int s_fps_last_counter = 0; -static Common::Timer s_update_time; - -static Common::Timer s_render_time; -static std::ofstream s_bench_file; - -void Initialize() +FPSCounter::FPSCounter() { - s_counter = s_fps_last_counter = 0; - s_fps = 0; - - s_update_time.Update(); - s_render_time.Update(); - - if (s_bench_file.is_open()) - s_bench_file.close(); + m_update_time.Update(); + m_render_time.Update(); } -void Shutdown() +FPSCounter::~FPSCounter() { - if (s_bench_file.is_open()) - s_bench_file.close(); + if (m_bench_file.is_open()) + m_bench_file.close(); } -static void LogRenderTimeToFile(u64 val) +void FPSCounter::LogRenderTimeToFile(u64 val) { - if (!s_bench_file.is_open()) - s_bench_file.open(File::GetUserPath(D_LOGS_IDX) + "render_time.txt"); + if (!m_bench_file.is_open()) + m_bench_file.open(File::GetUserPath(D_LOGS_IDX) + "render_time.txt"); - s_bench_file << val << std::endl; + m_bench_file << val << std::endl; } -int Update() +int FPSCounter::Update() { - if (s_update_time.GetTimeDifference() >= FPS_REFRESH_INTERVAL) + if (m_update_time.GetTimeDifference() >= FPS_REFRESH_INTERVAL) { - s_update_time.Update(); - s_fps = s_counter - s_fps_last_counter; - s_fps_last_counter = s_counter; - s_bench_file.flush(); + m_update_time.Update(); + m_fps = m_counter - m_fps_last_counter; + m_fps_last_counter = m_counter; + m_bench_file.flush(); } if (g_ActiveConfig.bLogRenderTimeToFile) { - LogRenderTimeToFile(s_render_time.GetTimeDifference()); - s_render_time.Update(); + LogRenderTimeToFile(m_render_time.GetTimeDifference()); + m_render_time.Update(); } - s_counter++; - return s_fps; + m_counter++; + return m_fps; } -} \ No newline at end of file diff --git a/Source/Core/VideoCommon/FPSCounter.h b/Source/Core/VideoCommon/FPSCounter.h index 2ce61beaec..b3cb1c3b73 100644 --- a/Source/Core/VideoCommon/FPSCounter.h +++ b/Source/Core/VideoCommon/FPSCounter.h @@ -4,15 +4,32 @@ #pragma once -namespace FPSCounter +#include + +#include "Common/Timer.h" + +class FPSCounter { -// Initializes the FPS counter. -void Initialize(); +public: + unsigned int m_fps; -// Shutdown the FPS counter by closing the logs. -void Shutdown(); + // Initializes the FPS counter. + FPSCounter(); -// Called when a frame is rendered. Returns the value to be displayed on -// screen as the FPS counter (updated every second). -int Update(); -} + // Shutdown the FPS counter by closing the logs. + ~FPSCounter(); + + // Called when a frame is rendered. Returns the value to be displayed on + // screen as the FPS counter (updated every second). + int Update(); + +private: + unsigned int m_counter; + unsigned int m_fps_last_counter; + Common::Timer m_update_time; + + Common::Timer m_render_time; + std::ofstream m_bench_file; + + void LogRenderTimeToFile(u64 val); +}; diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 68afa4e11a..707d918fe9 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -65,8 +65,6 @@ int Renderer::s_LastEFBScale; bool Renderer::s_skipSwap; bool Renderer::XFBWrited; -unsigned int Renderer::s_fps = 0; - PEControl::PixelFormat Renderer::prev_efb_format = PEControl::INVALID_FMT; unsigned int Renderer::efb_scale_numeratorX = 1; unsigned int Renderer::efb_scale_numeratorY = 1; @@ -87,8 +85,6 @@ Renderer::Renderer() OSDChoice = 0; OSDTime = 0; - - FPSCounter::Initialize(); } Renderer::~Renderer() @@ -105,8 +101,6 @@ Renderer::~Renderer() if (pFrameDump.IsOpen()) pFrameDump.Close(); #endif - - FPSCounter::Shutdown(); } void Renderer::RenderToXFB(u32 xfbAddr, const EFBRectangle& sourceRc, u32 fbWidth, u32 fbHeight, float Gamma) @@ -529,7 +523,7 @@ void Renderer::Swap(u32 xfbAddr, u32 fbWidth, u32 fbHeight, const EFBRectangle& g_renderer->SwapImpl(xfbAddr, fbWidth, fbHeight, rc, Gamma); if (XFBWrited) - s_fps = FPSCounter::Update(); + g_renderer->m_fps_counter.Update(); frameCount++; GFX_DEBUGGER_PAUSE_AT(NEXT_FRAME, true); diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index 668a2a42eb..8707219d82 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -19,6 +19,7 @@ #include "Common/MathUtil.h" #include "Common/Thread.h" #include "VideoCommon/BPMemory.h" +#include "VideoCommon/FPSCounter.h" #include "VideoCommon/FramebufferManagerBase.h" #include "VideoCommon/NativeVertexFormat.h" #include "VideoCommon/VideoCommon.h" @@ -150,7 +151,7 @@ protected: static bool s_skipSwap; static bool XFBWrited; - static unsigned int s_fps; + FPSCounter m_fps_counter; private: static PEControl::PixelFormat prev_efb_format; From eaa7460636f01f7779154259d492568c9d2dee1e Mon Sep 17 00:00:00 2001 From: Jules Blok Date: Fri, 18 Jul 2014 12:49:40 +0200 Subject: [PATCH 4/4] FPSCounter: Remove redundant destructor. --- Source/Core/VideoCommon/FPSCounter.cpp | 6 ------ Source/Core/VideoCommon/FPSCounter.h | 3 --- 2 files changed, 9 deletions(-) diff --git a/Source/Core/VideoCommon/FPSCounter.cpp b/Source/Core/VideoCommon/FPSCounter.cpp index 7a912c2fd7..1ce46377c7 100644 --- a/Source/Core/VideoCommon/FPSCounter.cpp +++ b/Source/Core/VideoCommon/FPSCounter.cpp @@ -18,12 +18,6 @@ FPSCounter::FPSCounter() m_render_time.Update(); } -FPSCounter::~FPSCounter() -{ - if (m_bench_file.is_open()) - m_bench_file.close(); -} - void FPSCounter::LogRenderTimeToFile(u64 val) { if (!m_bench_file.is_open()) diff --git a/Source/Core/VideoCommon/FPSCounter.h b/Source/Core/VideoCommon/FPSCounter.h index b3cb1c3b73..bb1dc7922d 100644 --- a/Source/Core/VideoCommon/FPSCounter.h +++ b/Source/Core/VideoCommon/FPSCounter.h @@ -16,9 +16,6 @@ public: // Initializes the FPS counter. FPSCounter(); - // Shutdown the FPS counter by closing the logs. - ~FPSCounter(); - // Called when a frame is rendered. Returns the value to be displayed on // screen as the FPS counter (updated every second). int Update();