mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-07-04 23:31:19 +01:00
Core: Make PerfStats internally locked
More ergonomic to use and will be required for upcoming changes.
This commit is contained in:
parent
f273959205
commit
b285c2a4ed
7 changed files with 25 additions and 16 deletions
|
@ -110,8 +110,7 @@ void System::PrepareReschedule() {
|
||||||
}
|
}
|
||||||
|
|
||||||
PerfStats::Results System::GetAndResetPerfStats() {
|
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() {
|
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
|
// Reset counters and set time origin to current frame
|
||||||
GetAndResetPerfStats();
|
GetAndResetPerfStats();
|
||||||
perf_stats.Lock()->BeginSystemFrame();
|
perf_stats.BeginSystemFrame();
|
||||||
|
|
||||||
return ResultStatus::Success;
|
return ResultStatus::Success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/synchronized_wrapper.h"
|
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
#include "core/perf_stats.h"
|
#include "core/perf_stats.h"
|
||||||
|
|
||||||
|
@ -94,7 +93,7 @@ public:
|
||||||
return *cpu_core;
|
return *cpu_core;
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::SynchronizedWrapper<PerfStats> perf_stats;
|
PerfStats perf_stats;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -104,7 +104,7 @@ void EmuWindow::AccelerometerChanged(float x, float y, float z) {
|
||||||
void EmuWindow::GyroscopeChanged(float x, float y, float z) {
|
void EmuWindow::GyroscopeChanged(float x, float y, float z) {
|
||||||
constexpr float FULL_FPS = 60;
|
constexpr float FULL_FPS = 60;
|
||||||
float coef = GetGyroscopeRawToDpsCoefficient();
|
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);
|
std::lock_guard<std::mutex> lock(gyro_mutex);
|
||||||
gyro_x = static_cast<s16>(x * coef * stretch);
|
gyro_x = static_cast<s16>(x * coef * stretch);
|
||||||
gyro_y = static_cast<s16>(y * coef * stretch);
|
gyro_y = static_cast<s16>(y * coef * stretch);
|
||||||
|
|
|
@ -281,8 +281,7 @@ ResultCode SetBufferSwap(u32 screen_id, const FrameBufferInfo& info) {
|
||||||
|
|
||||||
if (screen_id == 0) {
|
if (screen_id == 0) {
|
||||||
MicroProfileFlip();
|
MicroProfileFlip();
|
||||||
auto perf_stats = Core::System::GetInstance().perf_stats.Lock();
|
Core::System::GetInstance().perf_stats.EndGameFrame();
|
||||||
perf_stats->EndGameFrame();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <mutex>
|
||||||
#include "core/hw/gpu.h"
|
#include "core/hw/gpu.h"
|
||||||
#include "core/perf_stats.h"
|
#include "core/perf_stats.h"
|
||||||
|
|
||||||
|
@ -12,10 +13,14 @@ using std::chrono::duration_cast;
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
void PerfStats::BeginSystemFrame() {
|
void PerfStats::BeginSystemFrame() {
|
||||||
|
std::lock_guard<std::mutex> lock(object_mutex);
|
||||||
|
|
||||||
frame_begin = Clock::now();
|
frame_begin = Clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerfStats::EndSystemFrame() {
|
void PerfStats::EndSystemFrame() {
|
||||||
|
std::lock_guard<std::mutex> lock(object_mutex);
|
||||||
|
|
||||||
auto frame_end = Clock::now();
|
auto frame_end = Clock::now();
|
||||||
accumulated_frametime += frame_end - frame_begin;
|
accumulated_frametime += frame_end - frame_begin;
|
||||||
system_frames += 1;
|
system_frames += 1;
|
||||||
|
@ -25,10 +30,14 @@ void PerfStats::EndSystemFrame() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerfStats::EndGameFrame() {
|
void PerfStats::EndGameFrame() {
|
||||||
|
std::lock_guard<std::mutex> lock(object_mutex);
|
||||||
|
|
||||||
game_frames += 1;
|
game_frames += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) {
|
PerfStats::Results PerfStats::GetAndResetStats(u64 current_system_time_us) {
|
||||||
|
std::lock_guard<std::mutex> lock(object_mutex);
|
||||||
|
|
||||||
auto now = Clock::now();
|
auto now = Clock::now();
|
||||||
// Walltime elapsed since stats were reset
|
// Walltime elapsed since stats were reset
|
||||||
auto interval = duration_cast<DoubleSecs>(now - reset_point).count();
|
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() {
|
double PerfStats::GetLastFrameTimeScale() {
|
||||||
|
std::lock_guard<std::mutex> lock(object_mutex);
|
||||||
|
|
||||||
constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE;
|
constexpr double FRAME_LENGTH = 1.0 / GPU::SCREEN_REFRESH_RATE;
|
||||||
return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH;
|
return duration_cast<DoubleSecs>(previous_frame_length).count() / FRAME_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <mutex>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to manage and query performance/timing statistics. All public functions of this class are
|
||||||
|
* thread-safe unless stated otherwise.
|
||||||
|
*/
|
||||||
class PerfStats {
|
class PerfStats {
|
||||||
public:
|
public:
|
||||||
using Clock = std::chrono::high_resolution_clock;
|
using Clock = std::chrono::high_resolution_clock;
|
||||||
|
@ -37,6 +42,8 @@ public:
|
||||||
double GetLastFrameTimeScale();
|
double GetLastFrameTimeScale();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::mutex object_mutex;
|
||||||
|
|
||||||
Clock::time_point reset_point = Clock::now();
|
Clock::time_point reset_point = Clock::now();
|
||||||
|
|
||||||
Clock::time_point frame_begin = reset_point;
|
Clock::time_point frame_begin = reset_point;
|
||||||
|
|
|
@ -145,10 +145,7 @@ void RendererOpenGL::SwapBuffers() {
|
||||||
|
|
||||||
DrawScreens();
|
DrawScreens();
|
||||||
|
|
||||||
{
|
Core::System::GetInstance().perf_stats.EndSystemFrame();
|
||||||
auto perf_stats = Core::System::GetInstance().perf_stats.Lock();
|
|
||||||
perf_stats->EndSystemFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Swap buffers
|
// Swap buffers
|
||||||
render_window->PollEvents();
|
render_window->PollEvents();
|
||||||
|
@ -156,10 +153,7 @@ void RendererOpenGL::SwapBuffers() {
|
||||||
|
|
||||||
prev_state.Apply();
|
prev_state.Apply();
|
||||||
|
|
||||||
{
|
Core::System::GetInstance().perf_stats.BeginSystemFrame();
|
||||||
auto perf_stats = Core::System::GetInstance().perf_stats.Lock();
|
|
||||||
perf_stats->BeginSystemFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
RefreshRasterizerSetting();
|
RefreshRasterizerSetting();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue