From daa31121ee75dedcb636011e02815b816a7cc446 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Thu, 18 May 2023 22:54:58 -0400 Subject: [PATCH] configure_cpu: Generate UI --- src/yuzu/configuration/configure_cpu.cpp | 134 +++++++----------- src/yuzu/configuration/configure_cpu.h | 11 +- src/yuzu/configuration/configure_cpu.ui | 129 ++++------------- src/yuzu/configuration/configure_dialog.cpp | 3 +- src/yuzu/configuration/configure_per_game.cpp | 3 +- 5 files changed, 92 insertions(+), 188 deletions(-) diff --git a/src/yuzu/configuration/configure_cpu.cpp b/src/yuzu/configuration/configure_cpu.cpp index ecaeb1a6bd..0982e006d9 100644 --- a/src/yuzu/configuration/configure_cpu.cpp +++ b/src/yuzu/configuration/configure_cpu.cpp @@ -5,88 +5,83 @@ #include #include "common/common_types.h" #include "common/settings.h" +#include "configuration/shared_widget.h" #include "core/core.h" #include "ui_configure_cpu.h" #include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_cpu.h" -ConfigureCpu::ConfigureCpu(const Core::System& system_, - std::shared_ptr> group, - QWidget* parent) - : Tab(group, parent), ui{std::make_unique()}, system{system_} { +ConfigureCpu::ConfigureCpu( + const Core::System& system_, + std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations_, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent) + : Tab(group, parent), ui{std::make_unique()}, system{system_}, + translations{translations_}, combobox_translations{combobox_translations_} { ui->setupUi(this); - SetupPerGameUI(); + Setup(); SetConfiguration(); - connect(ui->accuracy, qOverload(&QComboBox::currentIndexChanged), this, + connect(accuracy_combobox, qOverload(&QComboBox::currentIndexChanged), this, &ConfigureCpu::UpdateGroup); } ConfigureCpu::~ConfigureCpu() = default; -void ConfigureCpu::SetConfiguration() { +void ConfigureCpu::SetConfiguration() {} +void ConfigureCpu::Setup() { const bool runtime_lock = !system.IsPoweredOn(); + auto* accuracy_layout = ui->widget_accuracy->layout(); + auto* unsafe_layout = ui->unsafe_widget->layout(); + std::map unsafe_hold{}; - ui->accuracy->setEnabled(runtime_lock); - ui->cpuopt_unsafe_unfuse_fma->setEnabled(runtime_lock); - ui->cpuopt_unsafe_reduce_fp_error->setEnabled(runtime_lock); - ui->cpuopt_unsafe_ignore_standard_fpcr->setEnabled(runtime_lock); - ui->cpuopt_unsafe_inaccurate_nan->setEnabled(runtime_lock); - ui->cpuopt_unsafe_fastmem_check->setEnabled(runtime_lock); - ui->cpuopt_unsafe_ignore_global_monitor->setEnabled(runtime_lock); + std::forward_list settings; + const auto push = [&](Settings::Category category) { + for (const auto setting : Settings::values.linkage.by_category[category]) { + settings.push_front(setting); + } + }; - ui->cpuopt_unsafe_unfuse_fma->setChecked(Settings::values.cpuopt_unsafe_unfuse_fma.GetValue()); - ui->cpuopt_unsafe_reduce_fp_error->setChecked( - Settings::values.cpuopt_unsafe_reduce_fp_error.GetValue()); - ui->cpuopt_unsafe_ignore_standard_fpcr->setChecked( - Settings::values.cpuopt_unsafe_ignore_standard_fpcr.GetValue()); - ui->cpuopt_unsafe_inaccurate_nan->setChecked( - Settings::values.cpuopt_unsafe_inaccurate_nan.GetValue()); - ui->cpuopt_unsafe_fastmem_check->setChecked( - Settings::values.cpuopt_unsafe_fastmem_check.GetValue()); - ui->cpuopt_unsafe_ignore_global_monitor->setChecked( - Settings::values.cpuopt_unsafe_ignore_global_monitor.GetValue()); + push(Settings::Category::Cpu); + push(Settings::Category::CpuUnsafe); - if (Settings::IsConfiguringGlobal()) { - ui->accuracy->setCurrentIndex(static_cast(Settings::values.cpu_accuracy.GetValue())); - } else { - ConfigurationShared::SetPerGameSetting(ui->accuracy, &Settings::values.cpu_accuracy); - ConfigurationShared::SetHighlight(ui->widget_accuracy, - !Settings::values.cpu_accuracy.UsingGlobal()); + for (const auto setting : settings) { + auto* widget = new ConfigurationShared::Widget(setting, translations, combobox_translations, + this, runtime_lock, apply_funcs); + + if (!widget->Valid()) { + delete widget; + continue; + } + + if (setting->Id() == Settings::values.cpu_accuracy.Id()) { + accuracy_layout->addWidget(widget); + accuracy_combobox = widget->combobox; + } else { + unsafe_hold.insert({setting->GetLabel(), widget}); + } } - UpdateGroup(ui->accuracy->currentIndex()); + + for (const auto& [label, widget] : unsafe_hold) { + unsafe_layout->addWidget(widget); + } + + UpdateGroup(accuracy_combobox->currentIndex()); } void ConfigureCpu::UpdateGroup(int index) { - if (!Settings::IsConfiguringGlobal()) { - index -= ConfigurationShared::USE_GLOBAL_OFFSET; - } - const auto accuracy = static_cast(index); + const auto accuracy = static_cast( + combobox_translations.at(typeid(Settings::CPUAccuracy))[index].first); ui->unsafe_group->setVisible(accuracy == Settings::CPUAccuracy::Unsafe); } void ConfigureCpu::ApplyConfiguration() { - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpu_accuracy, ui->accuracy); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpuopt_unsafe_unfuse_fma, - ui->cpuopt_unsafe_unfuse_fma, - cpuopt_unsafe_unfuse_fma); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpuopt_unsafe_reduce_fp_error, - ui->cpuopt_unsafe_reduce_fp_error, - cpuopt_unsafe_reduce_fp_error); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpuopt_unsafe_ignore_standard_fpcr, - ui->cpuopt_unsafe_ignore_standard_fpcr, - cpuopt_unsafe_ignore_standard_fpcr); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpuopt_unsafe_inaccurate_nan, - ui->cpuopt_unsafe_inaccurate_nan, - cpuopt_unsafe_inaccurate_nan); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpuopt_unsafe_fastmem_check, - ui->cpuopt_unsafe_fastmem_check, - cpuopt_unsafe_fastmem_check); - ConfigurationShared::ApplyPerGameSetting(&Settings::values.cpuopt_unsafe_ignore_global_monitor, - ui->cpuopt_unsafe_ignore_global_monitor, - cpuopt_unsafe_ignore_global_monitor); + const bool is_powered_on = system.IsPoweredOn(); + for (const auto& apply_func : apply_funcs) { + apply_func(is_powered_on); + } } void ConfigureCpu::changeEvent(QEvent* event) { @@ -100,32 +95,3 @@ void ConfigureCpu::changeEvent(QEvent* event) { void ConfigureCpu::RetranslateUI() { ui->retranslateUi(this); } - -void ConfigureCpu::SetupPerGameUI() { - if (Settings::IsConfiguringGlobal()) { - return; - } - - ConfigurationShared::SetColoredComboBox( - ui->accuracy, ui->widget_accuracy, - static_cast(Settings::values.cpu_accuracy.GetValue(true))); - - ConfigurationShared::SetColoredTristate(ui->cpuopt_unsafe_unfuse_fma, - Settings::values.cpuopt_unsafe_unfuse_fma, - cpuopt_unsafe_unfuse_fma); - ConfigurationShared::SetColoredTristate(ui->cpuopt_unsafe_reduce_fp_error, - Settings::values.cpuopt_unsafe_reduce_fp_error, - cpuopt_unsafe_reduce_fp_error); - ConfigurationShared::SetColoredTristate(ui->cpuopt_unsafe_ignore_standard_fpcr, - Settings::values.cpuopt_unsafe_ignore_standard_fpcr, - cpuopt_unsafe_ignore_standard_fpcr); - ConfigurationShared::SetColoredTristate(ui->cpuopt_unsafe_inaccurate_nan, - Settings::values.cpuopt_unsafe_inaccurate_nan, - cpuopt_unsafe_inaccurate_nan); - ConfigurationShared::SetColoredTristate(ui->cpuopt_unsafe_fastmem_check, - Settings::values.cpuopt_unsafe_fastmem_check, - cpuopt_unsafe_fastmem_check); - ConfigurationShared::SetColoredTristate(ui->cpuopt_unsafe_ignore_global_monitor, - Settings::values.cpuopt_unsafe_ignore_global_monitor, - cpuopt_unsafe_ignore_global_monitor); -} diff --git a/src/yuzu/configuration/configure_cpu.h b/src/yuzu/configuration/configure_cpu.h index 187d080b6f..fb970122d0 100644 --- a/src/yuzu/configuration/configure_cpu.h +++ b/src/yuzu/configuration/configure_cpu.h @@ -19,6 +19,8 @@ class ConfigureCpu : public ConfigurationShared::Tab { public: explicit ConfigureCpu(const Core::System& system_, std::shared_ptr> group, + const ConfigurationShared::TranslationMap& translations, + const ConfigurationShared::ComboboxTranslationMap& combobox_translations, QWidget* parent = nullptr); ~ConfigureCpu() override; @@ -31,7 +33,7 @@ private: void UpdateGroup(int index); - void SetupPerGameUI(); + void Setup(); std::unique_ptr ui; @@ -43,4 +45,11 @@ private: ConfigurationShared::CheckState cpuopt_unsafe_ignore_global_monitor; const Core::System& system; + + const ConfigurationShared::TranslationMap& translations; + const ConfigurationShared::ComboboxTranslationMap& combobox_translations; + + std::forward_list> apply_funcs{}; + + QComboBox* accuracy_combobox; }; diff --git a/src/yuzu/configuration/configure_cpu.ui b/src/yuzu/configuration/configure_cpu.ui index 8ae569ee67..835788c1f6 100644 --- a/src/yuzu/configuration/configure_cpu.ui +++ b/src/yuzu/configuration/configure_cpu.ui @@ -27,38 +27,19 @@ - - - - - Accuracy: - - - - - - - - Auto - - - - - Accurate - - - - - Unsafe - - - - - Paranoid (disables most optimizations) - - - - + + + 0 + + + 0 + + + 0 + + + 0 + @@ -96,75 +77,21 @@ - - - - <div>This option improves speed by reducing accuracy of fused-multiply-add instructions on CPUs without native FMA support.</div> - - - - Unfuse FMA (improve performance on CPUs without FMA) - - - - - - - - <div>This option improves the speed of some approximate floating-point functions by using less accurate native approximations.</div> - - - - Faster FRSQRTE and FRECPE - - - - - - - - <div>This option improves the speed of 32 bits ASIMD floating-point functions by running with incorrect rounding modes.</div> - - - - Faster ASIMD instructions (32 bits only) - - - - - - - - <div>This option improves speed by removing NaN checking. Please note this also reduces accuracy of certain floating-point instructions.</div> - - - - Inaccurate NaN handling - - - - - - - - <div>This option improves speed by eliminating a safety check before every memory read/write in guest. Disabling it may allow a game to read/write the emulator's memory.</div> - - - - Disable address space checks - - - - - - - - <div>This option improves speed by relying only on the semantics of cmpxchg to ensure safety of exclusive access instructions. Please note this may result in deadlocks and other race conditions.</div> - - - - Ignore global monitor - + + + + 0 + + + 0 + + + 0 + + + 0 + + diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 1a339a227a..c7d132fc86 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -37,7 +37,8 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, combobox_translations{ConfigurationShared::ComboboxEnumeration(this)}, audio_tab{std::make_unique(system_, nullptr, *translations, *combobox_translations, this)}, - cpu_tab{std::make_unique(system_, nullptr, this)}, + cpu_tab{std::make_unique(system_, nullptr, *translations, + *combobox_translations, this)}, debug_tab_tab{std::make_unique(system_, this)}, filesystem_tab{std::make_unique(this)}, general_tab{std::make_unique(system_, nullptr, *translations, diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp index 845ffeeb83..5863beca08 100644 --- a/src/yuzu/configuration/configure_per_game.cpp +++ b/src/yuzu/configuration/configure_per_game.cpp @@ -53,7 +53,8 @@ ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const std::st addons_tab = std::make_unique(system_, this); audio_tab = std::make_unique(system_, tab_group, *translations, *combobox_translations, this); - cpu_tab = std::make_unique(system_, tab_group, this); + cpu_tab = std::make_unique(system_, tab_group, *translations, + *combobox_translations, this); graphics_advanced_tab = std::make_unique( system_, tab_group, *translations, *combobox_translations, this); graphics_tab = std::make_unique(