yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

Merge pull request #12424 from t895/vsync-per-game-qt

qt: settings: Fix per-game vsync combobox
This commit is contained in:
liamwhite 2023-12-21 10:53:06 -05:00 committed by GitHub
commit 3d268b8480
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 30 deletions

View File

@ -106,10 +106,9 @@ ConfigureGraphics::ConfigureGraphics(
Settings::values.bg_green.GetValue(), Settings::values.bg_green.GetValue(),
Settings::values.bg_blue.GetValue())); Settings::values.bg_blue.GetValue()));
UpdateAPILayout(); UpdateAPILayout();
PopulateVSyncModeSelection(); //< must happen after UpdateAPILayout PopulateVSyncModeSelection(false); //< must happen after UpdateAPILayout
// VSync setting needs to be determined after populating the VSync combobox // 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_setting = Settings::values.vsync_mode.GetValue();
const auto vsync_mode = VSyncSettingToMode(vsync_mode_setting); const auto vsync_mode = VSyncSettingToMode(vsync_mode_setting);
int index{}; int index{};
@ -122,16 +121,15 @@ ConfigureGraphics::ConfigureGraphics(
if (static_cast<unsigned long>(index) < vsync_mode_combobox_enum_map.size()) { if (static_cast<unsigned long>(index) < vsync_mode_combobox_enum_map.size()) {
vsync_mode_combobox->setCurrentIndex(index); vsync_mode_combobox->setCurrentIndex(index);
} }
}
connect(api_combobox, qOverload<int>(&QComboBox::activated), this, [this] { connect(api_combobox, qOverload<int>(&QComboBox::activated), this, [this] {
UpdateAPILayout(); UpdateAPILayout();
PopulateVSyncModeSelection(); PopulateVSyncModeSelection(false);
}); });
connect(vulkan_device_combobox, qOverload<int>(&QComboBox::activated), this, connect(vulkan_device_combobox, qOverload<int>(&QComboBox::activated), this,
[this](int device) { [this](int device) {
UpdateDeviceSelection(device); UpdateDeviceSelection(device);
PopulateVSyncModeSelection(); PopulateVSyncModeSelection(false);
}); });
connect(shader_backend_combobox, qOverload<int>(&QComboBox::activated), this, connect(shader_backend_combobox, qOverload<int>(&QComboBox::activated), this,
[this](int backend) { UpdateShaderBackendSelection(backend); }); [this](int backend) { UpdateShaderBackendSelection(backend); });
@ -147,8 +145,9 @@ ConfigureGraphics::ConfigureGraphics(
const auto& update_screenshot_info = [this, &builder]() { const auto& update_screenshot_info = [this, &builder]() {
const auto& combobox_enumerations = builder.ComboboxTranslations().at( const auto& combobox_enumerations = builder.ComboboxTranslations().at(
Settings::EnumMetadata<Settings::AspectRatio>::Index()); Settings::EnumMetadata<Settings::AspectRatio>::Index());
const auto index = aspect_ratio_combobox->currentIndex(); const auto ratio_index = aspect_ratio_combobox->currentIndex();
const auto ratio = static_cast<Settings::AspectRatio>(combobox_enumerations[index].first); const auto ratio =
static_cast<Settings::AspectRatio>(combobox_enumerations[ratio_index].first);
const auto& combobox_enumerations_resolution = builder.ComboboxTranslations().at( const auto& combobox_enumerations_resolution = builder.ComboboxTranslations().at(
Settings::EnumMetadata<Settings::ResolutionSetup>::Index()); Settings::EnumMetadata<Settings::ResolutionSetup>::Index());
@ -174,11 +173,7 @@ ConfigureGraphics::ConfigureGraphics(
} }
} }
void ConfigureGraphics::PopulateVSyncModeSelection() { void ConfigureGraphics::PopulateVSyncModeSelection(bool use_setting) {
if (!Settings::IsConfiguringGlobal()) {
return;
}
const Settings::RendererBackend backend{GetCurrentGraphicsBackend()}; const Settings::RendererBackend backend{GetCurrentGraphicsBackend()};
if (backend == Settings::RendererBackend::Null) { if (backend == Settings::RendererBackend::Null) {
vsync_mode_combobox->setEnabled(false); vsync_mode_combobox->setEnabled(false);
@ -189,7 +184,8 @@ void ConfigureGraphics::PopulateVSyncModeSelection() {
const int current_index = //< current selected vsync mode from combobox const int current_index = //< current selected vsync mode from combobox
vsync_mode_combobox->currentIndex(); vsync_mode_combobox->currentIndex();
const auto current_mode = //< current selected vsync mode as a VkPresentModeKHR const auto current_mode = //< current selected vsync mode as a VkPresentModeKHR
current_index == -1 ? VSyncSettingToMode(Settings::values.vsync_mode.GetValue()) current_index == -1 || use_setting
? VSyncSettingToMode(Settings::values.vsync_mode.GetValue())
: vsync_mode_combobox_enum_map[current_index]; : vsync_mode_combobox_enum_map[current_index];
int index{}; int index{};
const int device{vulkan_device_combobox->currentIndex()}; //< current selected Vulkan device const int device{vulkan_device_combobox->currentIndex()}; //< current selected Vulkan device
@ -214,6 +210,23 @@ void ConfigureGraphics::PopulateVSyncModeSelection() {
} }
index++; 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) { 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()) { } else if (setting->Id() == Settings::values.vsync_mode.Id()) {
// Keep track of vsync_mode's combobox so we can populate it // Keep track of vsync_mode's combobox so we can populate it
vsync_mode_combobox = widget->combobox; 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<void()> set_non_global = [restore_button, this]() {
Settings::values.vsync_mode.SetGlobal(false);
UpdateVsyncSetting();
restore_button->setVisible(true);
};
QObject::connect(widget->combobox, QOverload<int>::of(&QComboBox::activated),
[set_non_global]() { set_non_global(); });
vsync_restore_global_button = restore_button;
}
hold_graphics.emplace(setting->Id(), widget); hold_graphics.emplace(setting->Id(), widget);
} else if (setting->Id() == Settings::values.aspect_ratio.Id()) { } else if (setting->Id() == Settings::values.aspect_ratio.Id()) {
// Keep track of the aspect ratio combobox to update other UI tabs that need it // 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); func(powered_on);
} }
if (Settings::IsConfiguringGlobal()) { UpdateVsyncSetting();
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);
}
Settings::values.vulkan_device.SetGlobal(true); Settings::values.vulkan_device.SetGlobal(true);
Settings::values.shader_backend.SetGlobal(true); Settings::values.shader_backend.SetGlobal(true);

View File

@ -62,7 +62,8 @@ private:
void Setup(const ConfigurationShared::Builder& builder); void Setup(const ConfigurationShared::Builder& builder);
void PopulateVSyncModeSelection(); void PopulateVSyncModeSelection(bool use_setting);
void UpdateVsyncSetting() const;
void UpdateBackgroundColorButton(QColor color); void UpdateBackgroundColorButton(QColor color);
void UpdateAPILayout(); void UpdateAPILayout();
void UpdateDeviceSelection(int device); void UpdateDeviceSelection(int device);
@ -104,6 +105,7 @@ private:
QComboBox* api_combobox; QComboBox* api_combobox;
QComboBox* shader_backend_combobox; QComboBox* shader_backend_combobox;
QComboBox* vsync_mode_combobox; QComboBox* vsync_mode_combobox;
QPushButton* vsync_restore_global_button;
QWidget* vulkan_device_widget; QWidget* vulkan_device_widget;
QWidget* api_widget; QWidget* api_widget;
QWidget* shader_backend_widget; QWidget* shader_backend_widget;