summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2017-02-20 13:56:58 -0800
committerGravatar Yuri Kunde Schlesner2017-02-26 17:22:03 -0800
commitb285c2a4ed29a126b5bcfe46e2784bd1870bdf82 (patch)
treea671ac87427fb63a64f51be260928cb39b8d3737 /src
parentQt: Add tooltips to status bar displays (diff)
downloadyuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.tar.gz
yuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.tar.xz
yuzu-b285c2a4ed29a126b5bcfe46e2784bd1870bdf82.zip
Core: Make PerfStats internally locked
More ergonomic to use and will be required for upcoming changes.
Diffstat (limited to 'src')
-rw-r--r--src/core/core.cpp5
-rw-r--r--src/core/core.h3
-rw-r--r--src/core/frontend/emu_window.cpp2
-rw-r--r--src/core/hle/service/gsp_gpu.cpp3
-rw-r--r--src/core/perf_stats.cpp11
-rw-r--r--src/core/perf_stats.h7
-rw-r--r--src/video_core/renderer_opengl/renderer_opengl.cpp10
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() {
110} 110}
111 111
112PerfStats::Results System::GetAndResetPerfStats() { 112PerfStats::Results System::GetAndResetPerfStats() {
113 auto perf_stats = this->perf_stats.Lock(); 113 return perf_stats.GetAndResetStats(CoreTiming::GetGlobalTimeUs());
114 return perf_stats->GetAndResetStats(CoreTiming::GetGlobalTimeUs());
115} 114}
116 115
117void System::Reschedule() { 116void System::Reschedule() {
@@ -147,7 +146,7 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) {
147 146
148 // Reset counters and set time origin to current frame 147 // Reset counters and set time origin to current frame
149 GetAndResetPerfStats(); 148 GetAndResetPerfStats();
150 perf_stats.Lock()->BeginSystemFrame(); 149 perf_stats.BeginSystemFrame();
151 150
152 return ResultStatus::Success; 151 return ResultStatus::Success;
153} 152}
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 @@
7#include <memory> 7#include <memory>
8#include <string> 8#include <string>
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "common/synchronized_wrapper.h"
11#include "core/memory.h" 10#include "core/memory.h"
12#include "core/perf_stats.h" 11#include "core/perf_stats.h"
13 12
@@ -94,7 +93,7 @@ public:
94 return *cpu_core; 93 return *cpu_core;
95 } 94 }
96 95
97 Common::SynchronizedWrapper<PerfStats> perf_stats; 96 PerfStats perf_stats;
98 97
99private: 98private:
100 /** 99 /**
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) {
104void EmuWindow::GyroscopeChanged(float x, float y, float z) { 104void EmuWindow::GyroscopeChanged(float x, float y, float z) {
105 constexpr float FULL_FPS = 60; 105 constexpr float FULL_FPS = 60;
106 float coef = GetGyroscopeRawToDpsCoefficient(); 106 float coef = GetGyroscopeRawToDpsCoefficient();
107 float stretch = Core::System::GetInstance().perf_stats.Lock()->GetLastFrameTimeScale(); 107 float stretch = Core::System::GetInstance().perf_stats.GetLastFrameTimeScale();
108 std::lock_guard<std::mutex> lock(gyro_mutex); 108 std::lock_guard<std::mutex> lock(gyro_mutex);
109 gyro_x = static_cast<s16>(x * coef * stretch); 109 gyro_x = static_cast<s16>(x * coef * stretch);
110 gyro_y = static_cast<s16>(y * coef * stretch); 110 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) {
281 281
282 if (screen_id == 0) { 282 if (screen_id == 0) {
283 MicroProfileFlip(); 283 MicroProfileFlip();
284 auto perf_stats = Core::System::GetInstance().perf_stats.Lock(); 284 Core::System::GetInstance().perf_stats.EndGameFrame();
285 perf_stats->EndGameFrame();
286 } 285 }
287 286
288 return RESULT_SUCCESS; 287 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 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <chrono> 5#include <chrono>
6#include <mutex>
6#include "core/hw/gpu.h" 7#include "core/hw/gpu.h"
7#include "core/perf_stats.h" 8#include "core/perf_stats.h"
8 9
@@ -12,10 +13,14 @@ using std::chrono::duration_cast;
12namespace Core { 13namespace Core {
13 14
14void PerfStats::BeginSystemFrame() { 15void PerfStats::BeginSystemFrame() {
16 std::lock_guard<std::mutex> lock(object_mutex);
17
15 frame_begin = Clock::now(); 18 frame_begin = Clock::now();
16} 19}
17 20
18void PerfStats::EndSystemFrame() { 21void PerfStats::EndSystemFrame() {
22 std::lock_guard<std::mutex> lock(object_mutex);
23
19 auto frame_end = Clock::now(); 24 auto frame_end = Clock::now();
20 accumulated_frametime += frame_end - frame_begin; 25 accumulated_frametime += frame_end - frame_begin;
21 system_frames += 1; 26 system_frames += 1;
@@ -25,10 +30,14 @@ void PerfStats::EndSystemFrame() {
25} 30}
26 31
27void PerfStats::EndGameFrame() { 32void PerfStats::EndGameFrame() {
33 std::lock_guard<std::mutex> lock(object_mutex);
34
28 game_frames += 1; 35 game_frames += 1;
29} 36}
30 37
31PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) { 38PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) {
39 std::lock_guard<std::mutex> lock(object_mutex);
40
32 auto now = Clock::now(); 41 auto now = Clock::now();
33 // Walltime elapsed since stats were reset 42 // Walltime elapsed since stats were reset
34 auto interval = duration_cast<DoubleSecs>(now - reset_point).count(); 43 auto interval = duration_cast<DoubleSecs>(now - reset_point).count();
@@ -54,6 +63,8 @@ PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) {
54} 63}
55 64
56double PerfStats::GetLastFrameTimeScale() { 65double PerfStats::GetLastFrameTimeScale() {
66 std::lock_guard<std::mutex> lock(object_mutex);
67
57 constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE; 68 constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE;
58 return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH; 69 return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH;
59} 70}
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 @@
5#pragma once 5#pragma once
6 6
7#include <chrono> 7#include <chrono>
8#include <mutex>
8#include "common/common_types.h" 9#include "common/common_types.h"
9 10
10namespace Core { 11namespace Core {
11 12
13/**
14 * Class to manage and query performance/timing statistics. All public functions of this class are
15 * thread-safe unless stated otherwise.
16 */
12class PerfStats { 17class PerfStats {
13public: 18public:
14 using Clock = std::chrono::high_resolution_clock; 19 using Clock = std::chrono::high_resolution_clock;
@@ -37,6 +42,8 @@ public:
37 double GetLastFrameTimeScale(); 42 double GetLastFrameTimeScale();
38 43
39private: 44private:
45 std::mutex object_mutex;
46
40 Clock::time_point reset_point = Clock::now(); 47 Clock::time_point reset_point = Clock::now();
41 48
42 Clock::time_point frame_begin = reset_point; 49 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() {
145 145
146 DrawScreens(); 146 DrawScreens();
147 147
148 { 148 Core::System::GetInstance().perf_stats.EndSystemFrame();
149 auto perf_stats = Core::System::GetInstance().perf_stats.Lock();
150 perf_stats->EndSystemFrame();
151 }
152 149
153 // Swap buffers 150 // Swap buffers
154 render_window->PollEvents(); 151 render_window->PollEvents();
@@ -156,10 +153,7 @@ void RendererOpenGL::SwapBuffers() {
156 153
157 prev_state.Apply(); 154 prev_state.Apply();
158 155
159 { 156 Core::System::GetInstance().perf_stats.BeginSystemFrame();
160 auto perf_stats = Core::System::GetInstance().perf_stats.Lock();
161 perf_stats->BeginSystemFrame();
162 }
163 157
164 RefreshRasterizerSetting(); 158 RefreshRasterizerSetting();
165 159