diff options
author | Yuri Kunde Schlesner <yuriks@yuriks.net> | 2017-02-20 22:56:58 +0100 |
---|---|---|
committer | Yuri Kunde Schlesner <yuriks@yuriks.net> | 2017-02-27 02:22:03 +0100 |
commit | b285c2a4ed29a126b5bcfe46e2784bd1870bdf82 (patch) | |
tree | a671ac87427fb63a64f51be260928cb39b8d3737 | |
parent | Qt: Add tooltips to status bar displays (diff) | |
download | yuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.tar yuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.tar.gz yuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.tar.bz2 yuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.tar.lz yuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.tar.xz yuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.tar.zst yuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.zip |
-rw-r--r-- | src/core/core.cpp | 5 | ||||
-rw-r--r-- | src/core/core.h | 3 | ||||
-rw-r--r-- | src/core/frontend/emu_window.cpp | 2 | ||||
-rw-r--r-- | src/core/hle/service/gsp_gpu.cpp | 3 | ||||
-rw-r--r-- | src/core/perf_stats.cpp | 11 | ||||
-rw-r--r-- | src/core/perf_stats.h | 7 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 10 |
7 files changed, 25 insertions, 16 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index ca2c28ce4..140ff6451 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -110,8 +110,7 @@ void System::PrepareReschedule() { } PerfStats::Results System::GetAndResetPerfStats() { - auto perf_stats = this->perf_stats.Lock(); - return perf_stats->GetAndResetStats(CoreTiming::GetGlobalTimeUs()); + return perf_stats.GetAndResetStats(CoreTiming::GetGlobalTimeUs()); } void System::Reschedule() { @@ -147,7 +146,7 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { // Reset counters and set time origin to current frame GetAndResetPerfStats(); - perf_stats.Lock()->BeginSystemFrame(); + perf_stats.BeginSystemFrame(); return ResultStatus::Success; } diff --git a/src/core/core.h b/src/core/core.h index 3efc20c3d..db3b98a05 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -7,7 +7,6 @@ #include <memory> #include <string> #include "common/common_types.h" -#include "common/synchronized_wrapper.h" #include "core/memory.h" #include "core/perf_stats.h" @@ -94,7 +93,7 @@ public: return *cpu_core; } - Common::SynchronizedWrapper<PerfStats> perf_stats; + PerfStats perf_stats; private: /** diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp index b65d6ff58..a155b657d 100644 --- a/src/core/frontend/emu_window.cpp +++ b/src/core/frontend/emu_window.cpp @@ -104,7 +104,7 @@ void EmuWindow::AccelerometerChanged(float x, float y, float z) { void EmuWindow::GyroscopeChanged(float x, float y, float z) { constexpr float FULL_FPS = 60; float coef = GetGyroscopeRawToDpsCoefficient(); - float stretch = Core::System::GetInstance().perf_stats.Lock()->GetLastFrameTimeScale(); + float stretch = Core::System::GetInstance().perf_stats.GetLastFrameTimeScale(); std::lock_guard<std::mutex> lock(gyro_mutex); gyro_x = static_cast<s16>(x * coef * stretch); gyro_y = static_cast<s16>(y * coef * stretch); diff --git a/src/core/hle/service/gsp_gpu.cpp b/src/core/hle/service/gsp_gpu.cpp index 67bab38da..097ed87e4 100644 --- a/src/core/hle/service/gsp_gpu.cpp +++ b/src/core/hle/service/gsp_gpu.cpp @@ -281,8 +281,7 @@ ResultCode SetBufferSwap(u32 screen_id, const FrameBufferInfo& info) { if (screen_id == 0) { MicroProfileFlip(); - auto perf_stats = Core::System::GetInstance().perf_stats.Lock(); - perf_stats->EndGameFrame(); + Core::System::GetInstance().perf_stats.EndGameFrame(); } return RESULT_SUCCESS; diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index 8d9e521a3..06bc788bd 100644 --- a/src/core/perf_stats.cpp +++ b/src/core/perf_stats.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include <chrono> +#include <mutex> #include "core/hw/gpu.h" #include "core/perf_stats.h" @@ -12,10 +13,14 @@ using std::chrono::duration_cast; namespace Core { void PerfStats::BeginSystemFrame() { + std::lock_guard<std::mutex> lock(object_mutex); + frame_begin = Clock::now(); } void PerfStats::EndSystemFrame() { + std::lock_guard<std::mutex> lock(object_mutex); + auto frame_end = Clock::now(); accumulated_frametime += frame_end - frame_begin; system_frames += 1; @@ -25,10 +30,14 @@ void PerfStats::EndSystemFrame() { } void PerfStats::EndGameFrame() { + std::lock_guard<std::mutex> lock(object_mutex); + game_frames += 1; } PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) { + std::lock_guard<std::mutex> lock(object_mutex); + auto now = Clock::now(); // Walltime elapsed since stats were reset auto interval = duration_cast<DoubleSecs>(now - reset_point).count(); @@ -54,6 +63,8 @@ PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) { } double PerfStats::GetLastFrameTimeScale() { + std::lock_guard<std::mutex> lock(object_mutex); + constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE; return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH; } diff --git a/src/core/perf_stats.h b/src/core/perf_stats.h index 8a03c511a..4098fc1f2 100644 --- a/src/core/perf_stats.h +++ b/src/core/perf_stats.h @@ -5,10 +5,15 @@ #pragma once #include <chrono> +#include <mutex> #include "common/common_types.h" namespace Core { +/** + * Class to manage and query performance/timing statistics. All public functions of this class are + * thread-safe unless stated otherwise. + */ class PerfStats { public: using Clock = std::chrono::high_resolution_clock; @@ -37,6 +42,8 @@ public: double GetLastFrameTimeScale(); private: + std::mutex object_mutex; + Clock::time_point reset_point = Clock::now(); Clock::time_point frame_begin = reset_point; diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 6bc142148..b3604106c 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -145,10 +145,7 @@ void RendererOpenGL::SwapBuffers() { DrawScreens(); - { - auto perf_stats = Core::System::GetInstance().perf_stats.Lock(); - perf_stats->EndSystemFrame(); - } + Core::System::GetInstance().perf_stats.EndSystemFrame(); // Swap buffers render_window->PollEvents(); @@ -156,10 +153,7 @@ void RendererOpenGL::SwapBuffers() { prev_state.Apply(); - { - auto perf_stats = Core::System::GetInstance().perf_stats.Lock(); - perf_stats->BeginSystemFrame(); - } + Core::System::GetInstance().perf_stats.BeginSystemFrame(); RefreshRasterizerSetting(); |