From 37ef9c913028e234509bcf70bad049b0210e4592 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sun, 18 Jul 2021 20:33:20 +0200 Subject: [PATCH] Settings: Add resolution scaling to settings. --- src/common/settings.cpp | 51 +++++++++++++++ src/common/settings.h | 13 ++-- src/yuzu/configuration/config.cpp | 5 ++ src/yuzu/configuration/config.h | 1 + src/yuzu/configuration/configure_graphics.cpp | 26 +++++++- src/yuzu/configuration/configure_graphics.ui | 64 +++++++++++++++++++ 6 files changed, 155 insertions(+), 5 deletions(-) diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 8c6be2c84..dd3a3d456 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -106,6 +106,57 @@ float Volume() { return values.volume.GetValue() / 100.0f; } +void UpdateRescalingInfo() { + auto setup = values.resolution_setup.GetValue(); + auto& info = values.resolution_info; + switch (setup) { + case ResolutionSetup::Res1_2X: { + info.up_scale = 1; + info.down_shift = 1; + break; + } + case ResolutionSetup::Res3_4X: { + info.up_scale = 3; + info.down_shift = 2; + break; + } + case ResolutionSetup::Res1X: { + info.up_scale = 1; + info.down_shift = 0; + break; + } + case ResolutionSetup::Res3_2X: { + info.up_scale = 3; + info.down_shift = 1; + break; + } + case ResolutionSetup::Res2X: { + info.up_scale = 2; + info.down_shift = 0; + break; + } + case ResolutionSetup::Res3X: { + info.up_scale = 3; + info.down_shift = 0; + break; + } + case ResolutionSetup::Res4X: { + info.up_scale = 4; + info.down_shift = 0; + break; + } + default: { + UNREACHABLE(); + info.up_scale = 1; + info.down_shift = 0; + } + } + info.up_factor = static_cast(info.up_scale) / (1U << info.down_shift); + info.down_factor = static_cast(1U << info.down_shift) / info.up_scale; + info.size_up = info.up_scale * info.up_scale; + info.size_shift = info.down_shift * 2; +} + void RestoreGlobalState(bool is_powered_on) { // If a game is running, DO NOT restore the global settings state if (is_powered_on) { diff --git a/src/common/settings.h b/src/common/settings.h index 08f3da055..f4df2fc95 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -56,16 +56,19 @@ enum class ResolutionSetup : u32 { Res1_2X = 0, Res3_4X = 1, Res1X = 2, - Res3_2K = 3, + Res3_2X = 3, Res2X = 4, Res3X = 5, + Res4X = 6, }; struct ResolutionScalingInfo { - u32 up_scale{2}; + u32 up_scale{1}; u32 down_shift{0}; - f32 up_factor{2.0f}; - f32 down_factor{0.5f}; + f32 up_factor{1.0f}; + f32 down_factor{1.0f}; + u32 size_up{1}; + u32 size_shift{0}; }; /** The BasicSetting class is a simple resource manager. It defines a label and default value @@ -613,6 +616,8 @@ std::string GetTimeZoneString(); void LogSettings(); +void UpdateRescalingInfo(); + // Restore the global state of all applicable settings in the Values struct void RestoreGlobalState(bool is_powered_on); diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index faea5dda1..7ddc40b00 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -824,6 +824,7 @@ void Config::ReadRendererValues() { ReadGlobalSetting(Settings::values.vulkan_device); ReadGlobalSetting(Settings::values.fullscreen_mode); ReadGlobalSetting(Settings::values.aspect_ratio); + ReadGlobalSetting(Settings::values.resolution_setup); ReadGlobalSetting(Settings::values.max_anisotropy); ReadGlobalSetting(Settings::values.use_speed_limit); ReadGlobalSetting(Settings::values.speed_limit); @@ -1364,6 +1365,10 @@ void Config::SaveRendererValues() { static_cast(Settings::values.fullscreen_mode.GetDefault()), Settings::values.fullscreen_mode.UsingGlobal()); WriteGlobalSetting(Settings::values.aspect_ratio); + WriteSetting(QString::fromStdString(Settings::values.resolution_setup.GetLabel()), + static_cast(Settings::values.resolution_setup.GetValue(global)), + static_cast(Settings::values.resolution_setup.GetDefault()), + Settings::values.resolution_setup.UsingGlobal()); WriteGlobalSetting(Settings::values.max_anisotropy); WriteGlobalSetting(Settings::values.use_speed_limit); WriteGlobalSetting(Settings::values.speed_limit); diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index a7f4a6720..fbb91d312 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h @@ -189,5 +189,6 @@ Q_DECLARE_METATYPE(Settings::CPUAccuracy); Q_DECLARE_METATYPE(Settings::GPUAccuracy); Q_DECLARE_METATYPE(Settings::FullscreenMode); Q_DECLARE_METATYPE(Settings::NvdecEmulation); +Q_DECLARE_METATYPE(Settings::ResolutionSetup); Q_DECLARE_METATYPE(Settings::RendererBackend); Q_DECLARE_METATYPE(Settings::ShaderBackend); diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index 8e20cc6f3..4f08ae3e0 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp @@ -102,6 +102,8 @@ void ConfigureGraphics::SetConfiguration() { ui->nvdec_emulation->setCurrentIndex( static_cast(Settings::values.nvdec_emulation.GetValue())); ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue()); + ui->resolution_combobox->setCurrentIndex( + static_cast(Settings::values.resolution_setup.GetValue())); } else { ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend); ConfigurationShared::SetHighlight(ui->api_widget, @@ -122,6 +124,11 @@ void ConfigureGraphics::SetConfiguration() { ConfigurationShared::SetHighlight(ui->ar_label, !Settings::values.aspect_ratio.UsingGlobal()); + ConfigurationShared::SetPerGameSetting(ui->resolution_combobox, + &Settings::values.resolution_setup); + ConfigurationShared::SetHighlight(ui->resolution_label, + !Settings::values.resolution_setup.UsingGlobal()); + ui->bg_combobox->setCurrentIndex(Settings::values.bg_red.UsingGlobal() ? 0 : 1); ui->bg_button->setEnabled(!Settings::values.bg_red.UsingGlobal()); ConfigurationShared::SetHighlight(ui->bg_layout, !Settings::values.bg_red.UsingGlobal()); @@ -133,11 +140,14 @@ void ConfigureGraphics::SetConfiguration() { } void ConfigureGraphics::ApplyConfiguration() { + const auto resolution_setup = static_cast( + ui->resolution_combobox->currentIndex() - + ((Settings::IsConfiguringGlobal()) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET)); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.fullscreen_mode, ui->fullscreen_mode_combobox); ConfigurationShared::ApplyPerGameSetting(&Settings::values.aspect_ratio, ui->aspect_ratio_combobox); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_disk_shader_cache, ui->use_disk_shader_cache, use_disk_shader_cache); ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_gpu_emulation, @@ -165,7 +175,16 @@ void ConfigureGraphics::ApplyConfiguration() { Settings::values.bg_green.SetValue(static_cast(bg_color.green())); Settings::values.bg_blue.SetValue(static_cast(bg_color.blue())); } + if (Settings::values.resolution_setup.UsingGlobal()) { + Settings::values.resolution_setup.SetValue(resolution_setup); + } } else { + if (ui->resolution_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + Settings::values.resolution_setup.SetGlobal(true); + } else { + Settings::values.resolution_setup.SetGlobal(false); + Settings::values.resolution_setup.SetValue(resolution_setup); + } if (ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { Settings::values.renderer_backend.SetGlobal(true); Settings::values.shader_backend.SetGlobal(true); @@ -207,6 +226,7 @@ void ConfigureGraphics::ApplyConfiguration() { Settings::values.bg_blue.SetValue(static_cast(bg_color.blue())); } } + Settings::UpdateRescalingInfo(); } void ConfigureGraphics::changeEvent(QEvent* event) { @@ -312,6 +332,7 @@ void ConfigureGraphics::SetupPerGameUI() { ui->device->setEnabled(Settings::values.renderer_backend.UsingGlobal()); ui->fullscreen_mode_combobox->setEnabled(Settings::values.fullscreen_mode.UsingGlobal()); ui->aspect_ratio_combobox->setEnabled(Settings::values.aspect_ratio.UsingGlobal()); + ui->resolution_combobox->setEnabled(Settings::values.resolution_setup.UsingGlobal()); ui->use_asynchronous_gpu_emulation->setEnabled( Settings::values.use_asynchronous_gpu_emulation.UsingGlobal()); ui->nvdec_emulation->setEnabled(Settings::values.nvdec_emulation.UsingGlobal()); @@ -340,6 +361,9 @@ void ConfigureGraphics::SetupPerGameUI() { ConfigurationShared::SetColoredComboBox( ui->fullscreen_mode_combobox, ui->fullscreen_mode_label, static_cast(Settings::values.fullscreen_mode.GetValue(true))); + ConfigurationShared::SetColoredComboBox( + ui->resolution_combobox, ui->resolution_label, + static_cast(Settings::values.resolution_setup.GetValue(true))); ConfigurationShared::InsertGlobalItem( ui->api, static_cast(Settings::values.renderer_backend.GetValue(true))); ConfigurationShared::InsertGlobalItem( diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui index beae74344..1b6ac3cbb 100644 --- a/src/yuzu/configuration/configure_graphics.ui +++ b/src/yuzu/configuration/configure_graphics.ui @@ -309,6 +309,70 @@ + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Resolution: + + + + + + + + 0.5X (360p/540p) + + + + + 0.75X (540p/810p) + + + + + 1X (720p/1080p) + + + + + 1.5X (1080p/1620p) + + + + + 2X (1440p/2160[4K]p) + + + + + 3X (2160p[4K]/3240p[6K]) + + + + + 4X (2880p/4320p[8K]) + + + + + + +