summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 4e5633edb..93d23de21 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 = 25000us; 79 constexpr microseconds MAX_LAG_TIME_US = 25000us;
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 69383330f..827a1bbd0 100644
--- a/src/core/telemetry_session.cpp
+++ b/src/core/telemetry_session.cpp
@@ -106,8 +106,9 @@ TelemetrySession::TelemetrySession() {
106 Settings::values.use_multi_core); 106 Settings::values.use_multi_core);
107 AddField(Telemetry::FieldType::UserConfig, "Renderer_ResolutionFactor", 107 AddField(Telemetry::FieldType::UserConfig, "Renderer_ResolutionFactor",
108 Settings::values.resolution_factor); 108 Settings::values.resolution_factor);
109 AddField(Telemetry::FieldType::UserConfig, "Renderer_ToggleFramelimit", 109 AddField(Telemetry::FieldType::UserConfig, "Renderer_UseFrameLimit",
110 Settings::values.toggle_framelimit); 110 Settings::values.use_frame_limit);
111 AddField(Telemetry::FieldType::UserConfig, "Renderer_FrameLimit", Settings::values.frame_limit);
111 AddField(Telemetry::FieldType::UserConfig, "Renderer_UseAccurateFramebuffers", 112 AddField(Telemetry::FieldType::UserConfig, "Renderer_UseAccurateFramebuffers",
112 Settings::values.use_accurate_framebuffers); 113 Settings::values.use_accurate_framebuffers);
113 AddField(Telemetry::FieldType::UserConfig, "System_UseDockedMode", 114 AddField(Telemetry::FieldType::UserConfig, "System_UseDockedMode",
diff --git a/src/video_core/renderer_base.cpp b/src/video_core/renderer_base.cpp
index 645d1521a..be17a2b9c 100644
--- a/src/video_core/renderer_base.cpp
+++ b/src/video_core/renderer_base.cpp
@@ -18,7 +18,7 @@ RendererBase::~RendererBase() = default;
18void RendererBase::RefreshBaseSettings() { 18void RendererBase::RefreshBaseSettings() {
19 UpdateCurrentFramebufferLayout(); 19 UpdateCurrentFramebufferLayout();
20 20
21 renderer_settings.use_framelimiter = Settings::values.toggle_framelimit; 21 renderer_settings.use_framelimiter = Settings::values.use_frame_limit;
22} 22}
23 23
24void RendererBase::UpdateCurrentFramebufferLayout() { 24void RendererBase::UpdateCurrentFramebufferLayout() {
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 9fd372419..62ff7a2d7 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -237,6 +237,10 @@ void GMainWindow::InitializeHotkeys() {
237 Qt::ApplicationShortcut); 237 Qt::ApplicationShortcut);
238 hotkey_registry.RegisterHotkey("Main Window", "Toggle Speed Limit", QKeySequence("CTRL+Z"), 238 hotkey_registry.RegisterHotkey("Main Window", "Toggle Speed Limit", QKeySequence("CTRL+Z"),
239 Qt::ApplicationShortcut); 239 Qt::ApplicationShortcut);
240 hotkey_registry.RegisterHotkey("Main Window", "Increase Speed Limit", QKeySequence("+"),
241 Qt::ApplicationShortcut);
242 hotkey_registry.RegisterHotkey("Main Window", "Decrease Speed Limit", QKeySequence("-"),
243 Qt::ApplicationShortcut);
240 hotkey_registry.LoadHotkeys(); 244 hotkey_registry.LoadHotkeys();
241 245
242 connect(hotkey_registry.GetHotkey("Main Window", "Load File", this), &QShortcut::activated, 246 connect(hotkey_registry.GetHotkey("Main Window", "Load File", this), &QShortcut::activated,
@@ -272,9 +276,24 @@ void GMainWindow::InitializeHotkeys() {
272 }); 276 });
273 connect(hotkey_registry.GetHotkey("Main Window", "Toggle Speed Limit", this), 277 connect(hotkey_registry.GetHotkey("Main Window", "Toggle Speed Limit", this),
274 &QShortcut::activated, this, [&] { 278 &QShortcut::activated, this, [&] {
275 Settings::values.toggle_framelimit = !Settings::values.toggle_framelimit; 279 Settings::values.use_frame_limit = !Settings::values.use_frame_limit;
276 UpdateStatusBar(); 280 UpdateStatusBar();
277 }); 281 });
282 constexpr u16 SPEED_LIMIT_STEP = 5;
283 connect(hotkey_registry.GetHotkey("Main Window", "Increase Speed Limit", this),
284 &QShortcut::activated, this, [&] {
285 if (Settings::values.frame_limit < 9999 - SPEED_LIMIT_STEP) {
286 Settings::values.frame_limit += SPEED_LIMIT_STEP;
287 UpdateStatusBar();
288 }
289 });
290 connect(hotkey_registry.GetHotkey("Main Window", "Decrease Speed Limit", this),
291 &QShortcut::activated, this, [&] {
292 if (Settings::values.frame_limit > SPEED_LIMIT_STEP) {
293 Settings::values.frame_limit -= SPEED_LIMIT_STEP;
294 UpdateStatusBar();
295 }
296 });
278} 297}
279 298
280void GMainWindow::SetDefaultUIGeometry() { 299void GMainWindow::SetDefaultUIGeometry() {
@@ -934,7 +953,13 @@ void GMainWindow::UpdateStatusBar() {
934 953
935 auto results = Core::System::GetInstance().GetAndResetPerfStats(); 954 auto results = Core::System::GetInstance().GetAndResetPerfStats();
936 955
937 emu_speed_label->setText(tr("Speed: %1%").arg(results.emulation_speed * 100.0, 0, 'f', 0)); 956 if (Settings::values.use_frame_limit) {
957 emu_speed_label->setText(tr("Speed: %1% / %2%")
958 .arg(results.emulation_speed * 100.0, 0, 'f', 0)
959 .arg(Settings::values.frame_limit));
960 } else {
961 emu_speed_label->setText(tr("Speed: %1%").arg(results.emulation_speed * 100.0, 0, 'f', 0));
962 }
938 game_fps_label->setText(tr("Game: %1 FPS").arg(results.game_fps, 0, 'f', 0)); 963 game_fps_label->setText(tr("Game: %1 FPS").arg(results.game_fps, 0, 'f', 0));
939 emu_frametime_label->setText(tr("Frame: %1 ms").arg(results.frametime * 1000.0, 0, 'f', 2)); 964 emu_frametime_label->setText(tr("Frame: %1 ms").arg(results.frametime * 1000.0, 0, 'f', 2));
940 965
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