summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/perf_stats.cpp17
-rw-r--r--src/core/settings.h3
-rw-r--r--src/core/telemetry_session.cpp5
-rw-r--r--src/video_core/renderer_base.cpp2
-rw-r--r--src/yuzu/configuration/config.cpp6
-rw-r--r--src/yuzu/configuration/configure_graphics.cpp10
-rw-r--r--src/yuzu/configuration/configure_graphics.ui30
-rw-r--r--src/yuzu/main.cpp29
-rw-r--r--src/yuzu_cmd/config.cpp5
-rw-r--r--src/yuzu_cmd/default_ini.h12
10 files changed, 94 insertions, 25 deletions
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp
index 8e09b9b63..c6022c02a 100644
--- a/src/core/perf_stats.cpp
+++ b/src/core/perf_stats.cpp
@@ -78,20 +78,29 @@ void FrameLimiter::DoFrameLimiting(microseconds current_system_time_us) {
78 // values increase the time needed to recover and limit framerate again after spikes. 78 // values increase the time needed to recover and limit framerate again after spikes.
79 constexpr microseconds MAX_LAG_TIME_US = 25us; 79 constexpr microseconds MAX_LAG_TIME_US = 25us;
80 80
81 if (!Settings::values.toggle_framelimit) { 81 if (!Settings::values.use_frame_limit) {
82 return; 82 return;
83 } 83 }
84 84
85 auto now = Clock::now(); 85 auto now = Clock::now();
86 86
87 frame_limiting_delta_err += current_system_time_us - previous_system_time_us; 87 const double sleep_scale = Settings::values.frame_limit / 100.0;
88
89 // Max lag caused by slow frames. Shouldn't be more than the length of a frame at the current
90 // speed percent or it will clamp too much and prevent this from properly limiting to that
91 // percent. High values means it'll take longer after a slow frame to recover and start
92 // limiting
93 const microseconds max_lag_time_us = duration_cast<microseconds>(
94 std::chrono::duration<double, std::chrono::microseconds::period>(25ms / sleep_scale));
95 frame_limiting_delta_err += duration_cast<microseconds>(
96 std::chrono::duration<double, std::chrono::microseconds::period>(
97 (current_system_time_us - previous_system_time_us) / sleep_scale));
88 frame_limiting_delta_err -= duration_cast<microseconds>(now - previous_walltime); 98 frame_limiting_delta_err -= duration_cast<microseconds>(now - previous_walltime);
89 frame_limiting_delta_err = 99 frame_limiting_delta_err =
90 std::clamp(frame_limiting_delta_err, -MAX_LAG_TIME_US, MAX_LAG_TIME_US); 100 std::clamp(frame_limiting_delta_err, -max_lag_time_us, max_lag_time_us);
91 101
92 if (frame_limiting_delta_err > microseconds::zero()) { 102 if (frame_limiting_delta_err > microseconds::zero()) {
93 std::this_thread::sleep_for(frame_limiting_delta_err); 103 std::this_thread::sleep_for(frame_limiting_delta_err);
94
95 auto now_after_sleep = Clock::now(); 104 auto now_after_sleep = Clock::now();
96 frame_limiting_delta_err -= duration_cast<microseconds>(now_after_sleep - now); 105 frame_limiting_delta_err -= duration_cast<microseconds>(now_after_sleep - now);
97 now = now_after_sleep; 106 now = now_after_sleep;
diff --git a/src/core/settings.h b/src/core/settings.h
index 73dc3061f..ed6f42471 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -130,7 +130,8 @@ struct Values {
130 130
131 // Renderer 131 // Renderer
132 float resolution_factor; 132 float resolution_factor;
133 bool toggle_framelimit; 133 bool use_frame_limit;
134 u16 frame_limit;
134 bool use_accurate_framebuffers; 135 bool use_accurate_framebuffers;
135 136
136 float bg_red; 137 float bg_red;
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp
index 69aa7a7be..5bd64f10e 100644
--- a/src/core/telemetry_session.cpp
+++ b/src/core/telemetry_session.cpp
@@ -161,8 +161,9 @@ TelemetrySession::TelemetrySession() {
161 Settings::values.use_multi_core); 161 Settings::values.use_multi_core);
162 AddField(Telemetry::FieldType::UserConfig, "Renderer_ResolutionFactor", 162 AddField(Telemetry::FieldType::UserConfig, "Renderer_ResolutionFactor",
163 Settings::values.resolution_factor); 163 Settings::values.resolution_factor);
164 AddField(Telemetry::FieldType::UserConfig, "Renderer_ToggleFramelimit", 164 AddField(Telemetry::FieldType::UserConfig, "Renderer_UseFrameLimit",
165 Settings::values.toggle_framelimit); 165 Settings::values.use_frame_limit);
166 AddField(Telemetry::FieldType::UserConfig, "Renderer_FrameLimit", Settings::values.frame_limit);
166 AddField(Telemetry::FieldType::UserConfig, "Renderer_UseAccurateFramebuffers", 167 AddField(Telemetry::FieldType::UserConfig, "Renderer_UseAccurateFramebuffers",
167 Settings::values.use_accurate_framebuffers); 168 Settings::values.use_accurate_framebuffers);
168 AddField(Telemetry::FieldType::UserConfig, "System_UseDockedMode", 169 AddField(Telemetry::FieldType::UserConfig, "System_UseDockedMode",
diff --git a/src/video_core/renderer_base.cpp b/src/video_core/renderer_base.cpp
index afd86a83a..c1abdfbfe 100644
--- a/src/video_core/renderer_base.cpp
+++ b/src/video_core/renderer_base.cpp
@@ -20,7 +20,7 @@ void RendererBase::RefreshBaseSettings() {
20 RefreshRasterizerSetting(); 20 RefreshRasterizerSetting();
21 UpdateCurrentFramebufferLayout(); 21 UpdateCurrentFramebufferLayout();
22 22
23 renderer_settings.use_framelimiter = Settings::values.toggle_framelimit; 23 renderer_settings.use_framelimiter = Settings::values.use_frame_limit;
24} 24}
25 25
26void RendererBase::RefreshRasterizerSetting() { 26void RendererBase::RefreshRasterizerSetting() {
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp
index 0bd46dbac..df55c3e3d 100644
--- a/src/yuzu/configuration/config.cpp
+++ b/src/yuzu/configuration/config.cpp
@@ -83,7 +83,8 @@ void Config::ReadValues() {
83 83
84 qt_config->beginGroup("Renderer"); 84 qt_config->beginGroup("Renderer");
85 Settings::values.resolution_factor = qt_config->value("resolution_factor", 1.0).toFloat(); 85 Settings::values.resolution_factor = qt_config->value("resolution_factor", 1.0).toFloat();
86 Settings::values.toggle_framelimit = qt_config->value("toggle_framelimit", true).toBool(); 86 Settings::values.use_frame_limit = qt_config->value("use_frame_limit", true).toBool();
87 Settings::values.frame_limit = qt_config->value("frame_limit", 100).toInt();
87 Settings::values.use_accurate_framebuffers = 88 Settings::values.use_accurate_framebuffers =
88 qt_config->value("use_accurate_framebuffers", false).toBool(); 89 qt_config->value("use_accurate_framebuffers", false).toBool();
89 90
@@ -203,7 +204,8 @@ void Config::SaveValues() {
203 204
204 qt_config->beginGroup("Renderer"); 205 qt_config->beginGroup("Renderer");
205 qt_config->setValue("resolution_factor", (double)Settings::values.resolution_factor); 206 qt_config->setValue("resolution_factor", (double)Settings::values.resolution_factor);
206 qt_config->setValue("toggle_framelimit", Settings::values.toggle_framelimit); 207 qt_config->setValue("use_frame_limit", Settings::values.use_frame_limit);
208 qt_config->setValue("frame_limit", Settings::values.frame_limit);
207 qt_config->setValue("use_accurate_framebuffers", Settings::values.use_accurate_framebuffers); 209 qt_config->setValue("use_accurate_framebuffers", Settings::values.use_accurate_framebuffers);
208 210
209 // Cast to double because Qt's written float values are not human-readable 211 // Cast to double because Qt's written float values are not human-readable
diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp
index 4afe0f81b..ee1287028 100644
--- a/src/yuzu/configuration/configure_graphics.cpp
+++ b/src/yuzu/configuration/configure_graphics.cpp
@@ -12,6 +12,10 @@ ConfigureGraphics::ConfigureGraphics(QWidget* parent)
12 12
13 ui->setupUi(this); 13 ui->setupUi(this);
14 this->setConfiguration(); 14 this->setConfiguration();
15
16 ui->frame_limit->setEnabled(Settings::values.use_frame_limit);
17 connect(ui->toggle_frame_limit, &QCheckBox::stateChanged, ui->frame_limit,
18 &QSpinBox::setEnabled);
15} 19}
16 20
17ConfigureGraphics::~ConfigureGraphics() = default; 21ConfigureGraphics::~ConfigureGraphics() = default;
@@ -58,13 +62,15 @@ Resolution FromResolutionFactor(float factor) {
58void ConfigureGraphics::setConfiguration() { 62void ConfigureGraphics::setConfiguration() {
59 ui->resolution_factor_combobox->setCurrentIndex( 63 ui->resolution_factor_combobox->setCurrentIndex(
60 static_cast<int>(FromResolutionFactor(Settings::values.resolution_factor))); 64 static_cast<int>(FromResolutionFactor(Settings::values.resolution_factor)));
61 ui->toggle_framelimit->setChecked(Settings::values.toggle_framelimit); 65 ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit);
66 ui->frame_limit->setValue(Settings::values.frame_limit);
62 ui->use_accurate_framebuffers->setChecked(Settings::values.use_accurate_framebuffers); 67 ui->use_accurate_framebuffers->setChecked(Settings::values.use_accurate_framebuffers);
63} 68}
64 69
65void ConfigureGraphics::applyConfiguration() { 70void ConfigureGraphics::applyConfiguration() {
66 Settings::values.resolution_factor = 71 Settings::values.resolution_factor =
67 ToResolutionFactor(static_cast<Resolution>(ui->resolution_factor_combobox->currentIndex())); 72 ToResolutionFactor(static_cast<Resolution>(ui->resolution_factor_combobox->currentIndex()));
68 Settings::values.toggle_framelimit = ui->toggle_framelimit->isChecked(); 73 Settings::values.use_frame_limit = ui->toggle_frame_limit->isChecked();
74 Settings::values.frame_limit = ui->frame_limit->value();
69 Settings::values.use_accurate_framebuffers = ui->use_accurate_framebuffers->isChecked(); 75 Settings::values.use_accurate_framebuffers = ui->use_accurate_framebuffers->isChecked();
70} 76}
diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui
index 7d092df03..3bc18c26e 100644
--- a/src/yuzu/configuration/configure_graphics.ui
+++ b/src/yuzu/configuration/configure_graphics.ui
@@ -23,11 +23,31 @@
23 </property> 23 </property>
24 <layout class="QVBoxLayout" name="verticalLayout_2"> 24 <layout class="QVBoxLayout" name="verticalLayout_2">
25 <item> 25 <item>
26 <widget class="QCheckBox" name="toggle_framelimit"> 26 <layout class="QHBoxLayout" name="horizontalLayout_2">
27 <property name="text"> 27 <item>
28 <string>Limit framerate</string> 28 <widget class="QCheckBox" name="toggle_frame_limit">
29 </property> 29 <property name="text">
30 </widget> 30 <string>Limit Speed Percent</string>
31 </property>
32 </widget>
33 </item>
34 <item>
35 <widget class="QSpinBox" name="frame_limit">
36 <property name="suffix">
37 <string>%</string>
38 </property>
39 <property name="minimum">
40 <number>1</number>
41 </property>
42 <property name="maximum">
43 <number>9999</number>
44 </property>
45 <property name="value">
46 <number>100</number>
47 </property>
48 </widget>
49 </item>
50 </layout>
31 </item> 51 </item>
32 <item> 52 <item>
33 <widget class="QCheckBox" name="use_accurate_framebuffers"> 53 <widget class="QCheckBox" name="use_accurate_framebuffers">
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 11d2331df..41f765f12 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -226,6 +226,10 @@ void GMainWindow::InitializeHotkeys() {
226 Qt::ApplicationShortcut); 226 Qt::ApplicationShortcut);
227 hotkey_registry.RegisterHotkey("Main Window", "Toggle Speed Limit", QKeySequence("CTRL+Z"), 227 hotkey_registry.RegisterHotkey("Main Window", "Toggle Speed Limit", QKeySequence("CTRL+Z"),
228 Qt::ApplicationShortcut); 228 Qt::ApplicationShortcut);
229 hotkey_registry.RegisterHotkey("Main Window", "Increase Speed Limit", QKeySequence("+"),
230 Qt::ApplicationShortcut);
231 hotkey_registry.RegisterHotkey("Main Window", "Decrease Speed Limit", QKeySequence("-"),
232 Qt::ApplicationShortcut);
229 hotkey_registry.LoadHotkeys(); 233 hotkey_registry.LoadHotkeys();
230 234
231 connect(hotkey_registry.GetHotkey("Main Window", "Load File", this), &QShortcut::activated, 235 connect(hotkey_registry.GetHotkey("Main Window", "Load File", this), &QShortcut::activated,
@@ -255,9 +259,24 @@ void GMainWindow::InitializeHotkeys() {
255 }); 259 });
256 connect(hotkey_registry.GetHotkey("Main Window", "Toggle Speed Limit", this), 260 connect(hotkey_registry.GetHotkey("Main Window", "Toggle Speed Limit", this),
257 &QShortcut::activated, this, [&] { 261 &QShortcut::activated, this, [&] {
258 Settings::values.toggle_framelimit = !Settings::values.toggle_framelimit; 262 Settings::values.use_frame_limit = !Settings::values.use_frame_limit;
259 UpdateStatusBar(); 263 UpdateStatusBar();
260 }); 264 });
265 constexpr u16 SPEED_LIMIT_STEP = 5;
266 connect(hotkey_registry.GetHotkey("Main Window", "Increase Speed Limit", this),
267 &QShortcut::activated, this, [&] {
268 if (Settings::values.frame_limit < 9999 - SPEED_LIMIT_STEP) {
269 Settings::values.frame_limit += SPEED_LIMIT_STEP;
270 UpdateStatusBar();
271 }
272 });
273 connect(hotkey_registry.GetHotkey("Main Window", "Decrease Speed Limit", this),
274 &QShortcut::activated, this, [&] {
275 if (Settings::values.frame_limit > SPEED_LIMIT_STEP) {
276 Settings::values.frame_limit -= SPEED_LIMIT_STEP;
277 UpdateStatusBar();
278 }
279 });
261} 280}
262 281
263void GMainWindow::SetDefaultUIGeometry() { 282void GMainWindow::SetDefaultUIGeometry() {
@@ -910,7 +929,13 @@ void GMainWindow::UpdateStatusBar() {
910 929
911 auto results = Core::System::GetInstance().GetAndResetPerfStats(); 930 auto results = Core::System::GetInstance().GetAndResetPerfStats();
912 931
913 emu_speed_label->setText(tr("Speed: %1%").arg(results.emulation_speed * 100.0, 0, 'f', 0)); 932 if (Settings::values.use_frame_limit) {
933 emu_speed_label->setText(tr("Speed: %1% / %2%")
934 .arg(results.emulation_speed * 100.0, 0, 'f', 0)
935 .arg(Settings::values.frame_limit));
936 } else {
937 emu_speed_label->setText(tr("Speed: %1%").arg(results.emulation_speed * 100.0, 0, 'f', 0));
938 }
914 game_fps_label->setText(tr("Game: %1 FPS").arg(results.game_fps, 0, 'f', 0)); 939 game_fps_label->setText(tr("Game: %1 FPS").arg(results.game_fps, 0, 'f', 0));
915 emu_frametime_label->setText(tr("Frame: %1 ms").arg(results.frametime * 1000.0, 0, 'f', 2)); 940 emu_frametime_label->setText(tr("Frame: %1 ms").arg(results.frametime * 1000.0, 0, 'f', 2));
916 941
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp
index 9bf26717f..a95580152 100644
--- a/src/yuzu_cmd/config.cpp
+++ b/src/yuzu_cmd/config.cpp
@@ -96,8 +96,9 @@ void Config::ReadValues() {
96 // Renderer 96 // Renderer
97 Settings::values.resolution_factor = 97 Settings::values.resolution_factor =
98 (float)sdl2_config->GetReal("Renderer", "resolution_factor", 1.0); 98 (float)sdl2_config->GetReal("Renderer", "resolution_factor", 1.0);
99 Settings::values.toggle_framelimit = 99 Settings::values.use_frame_limit = sdl2_config->GetBoolean("Renderer", "use_frame_limit", true);
100 sdl2_config->GetBoolean("Renderer", "toggle_framelimit", true); 100 Settings::values.frame_limit =
101 static_cast<u16>(sdl2_config->GetInteger("Renderer", "frame_limit", 100));
101 Settings::values.use_accurate_framebuffers = 102 Settings::values.use_accurate_framebuffers =
102 sdl2_config->GetBoolean("Renderer", "use_accurate_framebuffers", false); 103 sdl2_config->GetBoolean("Renderer", "use_accurate_framebuffers", false);
103 104
diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h
index 9a935a0d5..6ed9e7962 100644
--- a/src/yuzu_cmd/default_ini.h
+++ b/src/yuzu_cmd/default_ini.h
@@ -102,6 +102,14 @@ resolution_factor =
102# 0 (default): Off, 1: On 102# 0 (default): Off, 1: On
103use_vsync = 103use_vsync =
104 104
105# Turns on the frame limiter, which will limit frames output to the target game speed
106# 0: Off, 1: On (default)
107use_frame_limit =
108
109# Limits the speed of the game to run no faster than this value as a percentage of target speed
110# 1 - 9999: Speed limit as a percentage of target game speed. 100 (default)
111frame_limit =
112
105# Whether to use accurate framebuffers 113# Whether to use accurate framebuffers
106# 0 (default): Off (fast), 1 : On (slow) 114# 0 (default): Off (fast), 1 : On (slow)
107use_accurate_framebuffers = 115use_accurate_framebuffers =
@@ -132,10 +140,6 @@ custom_bottom_top =
132custom_bottom_right = 140custom_bottom_right =
133custom_bottom_bottom = 141custom_bottom_bottom =
134 142
135# Whether to toggle frame limiter on or off.
136# 0: Off, 1 (default): On
137toggle_framelimit =
138
139# Swaps the prominent screen with the other screen. 143# Swaps the prominent screen with the other screen.
140# For example, if Single Screen is chosen, setting this to 1 will display the bottom screen instead of the top screen. 144# For example, if Single Screen is chosen, setting this to 1 will display the bottom screen instead of the top screen.
141# 0 (default): Top Screen is prominent, 1: Bottom Screen is prominent 145# 0 (default): Top Screen is prominent, 1: Bottom Screen is prominent