From bb5196aaae66a664ba6ee5a1c1a1b6a6330905d6 Mon Sep 17 00:00:00 2001 From: t895 Date: Tue, 19 Dec 2023 21:43:33 -0500 Subject: qt: settings: Fix per-game vsync combobox --- src/yuzu/configuration/configure_graphics.cpp | 94 ++++++++++++++++++--------- src/yuzu/configuration/configure_graphics.h | 4 +- 2 files changed, 68 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index fd6bebf0f..0836bcb7e 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp @@ -106,32 +106,30 @@ ConfigureGraphics::ConfigureGraphics( Settings::values.bg_green.GetValue(), Settings::values.bg_blue.GetValue())); UpdateAPILayout(); - PopulateVSyncModeSelection(); //< must happen after UpdateAPILayout + PopulateVSyncModeSelection(false); //< must happen after UpdateAPILayout // VSync setting needs to be determined after populating the VSync combobox - if (Settings::IsConfiguringGlobal()) { - const auto vsync_mode_setting = Settings::values.vsync_mode.GetValue(); - const auto vsync_mode = VSyncSettingToMode(vsync_mode_setting); - int index{}; - for (const auto mode : vsync_mode_combobox_enum_map) { - if (mode == vsync_mode) { - break; - } - index++; - } - if (static_cast(index) < vsync_mode_combobox_enum_map.size()) { - vsync_mode_combobox->setCurrentIndex(index); + const auto vsync_mode_setting = Settings::values.vsync_mode.GetValue(); + const auto vsync_mode = VSyncSettingToMode(vsync_mode_setting); + int index{}; + for (const auto mode : vsync_mode_combobox_enum_map) { + if (mode == vsync_mode) { + break; } + index++; + } + if (static_cast(index) < vsync_mode_combobox_enum_map.size()) { + vsync_mode_combobox->setCurrentIndex(index); } connect(api_combobox, qOverload(&QComboBox::activated), this, [this] { UpdateAPILayout(); - PopulateVSyncModeSelection(); + PopulateVSyncModeSelection(false); }); connect(vulkan_device_combobox, qOverload(&QComboBox::activated), this, [this](int device) { UpdateDeviceSelection(device); - PopulateVSyncModeSelection(); + PopulateVSyncModeSelection(false); }); connect(shader_backend_combobox, qOverload(&QComboBox::activated), this, [this](int backend) { UpdateShaderBackendSelection(backend); }); @@ -147,8 +145,9 @@ ConfigureGraphics::ConfigureGraphics( const auto& update_screenshot_info = [this, &builder]() { const auto& combobox_enumerations = builder.ComboboxTranslations().at( Settings::EnumMetadata::Index()); - const auto index = aspect_ratio_combobox->currentIndex(); - const auto ratio = static_cast(combobox_enumerations[index].first); + const auto ratio_index = aspect_ratio_combobox->currentIndex(); + const auto ratio = + static_cast(combobox_enumerations[ratio_index].first); const auto& combobox_enumerations_resolution = builder.ComboboxTranslations().at( Settings::EnumMetadata::Index()); @@ -174,11 +173,7 @@ ConfigureGraphics::ConfigureGraphics( } } -void ConfigureGraphics::PopulateVSyncModeSelection() { - if (!Settings::IsConfiguringGlobal()) { - return; - } - +void ConfigureGraphics::PopulateVSyncModeSelection(bool use_setting) { const Settings::RendererBackend backend{GetCurrentGraphicsBackend()}; if (backend == Settings::RendererBackend::Null) { vsync_mode_combobox->setEnabled(false); @@ -189,8 +184,9 @@ void ConfigureGraphics::PopulateVSyncModeSelection() { const int current_index = //< current selected vsync mode from combobox vsync_mode_combobox->currentIndex(); const auto current_mode = //< current selected vsync mode as a VkPresentModeKHR - current_index == -1 ? VSyncSettingToMode(Settings::values.vsync_mode.GetValue()) - : vsync_mode_combobox_enum_map[current_index]; + current_index == -1 || use_setting + ? VSyncSettingToMode(Settings::values.vsync_mode.GetValue()) + : vsync_mode_combobox_enum_map[current_index]; int index{}; const int device{vulkan_device_combobox->currentIndex()}; //< current selected Vulkan device @@ -214,6 +210,23 @@ void ConfigureGraphics::PopulateVSyncModeSelection() { } index++; } + + if (!Settings::IsConfiguringGlobal()) { + vsync_restore_global_button->setVisible(!Settings::values.vsync_mode.UsingGlobal()); + + const Settings::VSyncMode global_vsync_mode = Settings::values.vsync_mode.GetValue(true); + vsync_restore_global_button->setEnabled( + (backend == Settings::RendererBackend::OpenGL && + (global_vsync_mode == Settings::VSyncMode::Immediate || + global_vsync_mode == Settings::VSyncMode::Fifo)) || + backend == Settings::RendererBackend::Vulkan); + } +} + +void ConfigureGraphics::UpdateVsyncSetting() const { + const auto mode = vsync_mode_combobox_enum_map[vsync_mode_combobox->currentIndex()]; + const auto vsync_mode = PresentModeToSetting(mode); + Settings::values.vsync_mode.SetValue(vsync_mode); } void ConfigureGraphics::UpdateDeviceSelection(int device) { @@ -299,6 +312,33 @@ void ConfigureGraphics::Setup(const ConfigurationShared::Builder& builder) { } else if (setting->Id() == Settings::values.vsync_mode.Id()) { // Keep track of vsync_mode's combobox so we can populate it vsync_mode_combobox = widget->combobox; + + // Since vsync is populated at runtime, we have to manually set up the button for + // restoring the global setting. + if (!Settings::IsConfiguringGlobal()) { + QPushButton* restore_button = + ConfigurationShared::Widget::CreateRestoreGlobalButton( + Settings::values.vsync_mode.UsingGlobal(), widget); + restore_button->setEnabled(true); + widget->layout()->addWidget(restore_button); + + QObject::connect(restore_button, &QAbstractButton::clicked, + [restore_button, this](bool) { + Settings::values.vsync_mode.SetGlobal(true); + PopulateVSyncModeSelection(true); + + restore_button->setVisible(false); + }); + + std::function set_non_global = [restore_button, this]() { + Settings::values.vsync_mode.SetGlobal(false); + UpdateVsyncSetting(); + restore_button->setVisible(true); + }; + QObject::connect(widget->combobox, QOverload::of(&QComboBox::activated), + [set_non_global]() { set_non_global(); }); + vsync_restore_global_button = restore_button; + } hold_graphics.emplace(setting->Id(), widget); } else if (setting->Id() == Settings::values.aspect_ratio.Id()) { // Keep track of the aspect ratio combobox to update other UI tabs that need it @@ -400,11 +440,7 @@ void ConfigureGraphics::ApplyConfiguration() { func(powered_on); } - if (Settings::IsConfiguringGlobal()) { - const auto mode = vsync_mode_combobox_enum_map[vsync_mode_combobox->currentIndex()]; - const auto vsync_mode = PresentModeToSetting(mode); - Settings::values.vsync_mode.SetValue(vsync_mode); - } + UpdateVsyncSetting(); Settings::values.vulkan_device.SetGlobal(true); Settings::values.shader_backend.SetGlobal(true); diff --git a/src/yuzu/configuration/configure_graphics.h b/src/yuzu/configuration/configure_graphics.h index 9c24a56db..5c8286836 100644 --- a/src/yuzu/configuration/configure_graphics.h +++ b/src/yuzu/configuration/configure_graphics.h @@ -62,7 +62,8 @@ private: void Setup(const ConfigurationShared::Builder& builder); - void PopulateVSyncModeSelection(); + void PopulateVSyncModeSelection(bool use_setting); + void UpdateVsyncSetting() const; void UpdateBackgroundColorButton(QColor color); void UpdateAPILayout(); void UpdateDeviceSelection(int device); @@ -104,6 +105,7 @@ private: QComboBox* api_combobox; QComboBox* shader_backend_combobox; QComboBox* vsync_mode_combobox; + QPushButton* vsync_restore_global_button; QWidget* vulkan_device_widget; QWidget* api_widget; QWidget* shader_backend_widget; -- cgit v1.2.3