From e169fdad4f89675f5b56a3ca5004d593792426a0 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Sat, 15 May 2021 20:46:48 -0400 Subject: [PATCH] general: Make CPU accuracy and related a Settings::Setting Required to make CPU accuracy and unsafe settings available to use as a per-game setting. --- src/common/settings.cpp | 2 +- src/common/settings.h | 8 +++--- src/core/arm/dynarmic/arm_dynarmic_32.cpp | 10 +++---- src/core/arm/dynarmic/arm_dynarmic_64.cpp | 10 +++---- src/yuzu/configuration/config.cpp | 33 ++++++++++++----------- src/yuzu/configuration/config.h | 1 + src/yuzu/configuration/configure_cpu.cpp | 24 ++++++++++------- 7 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 702b6598df..b9a549c817 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -42,7 +42,7 @@ void LogSettings() { log_setting("System_RegionIndex", values.region_index.GetValue()); log_setting("System_TimeZoneIndex", values.time_zone_index.GetValue()); log_setting("Core_UseMultiCore", values.use_multi_core.GetValue()); - log_setting("CPU_Accuracy", values.cpu_accuracy); + log_setting("CPU_Accuracy", values.cpu_accuracy.GetValue()); log_setting("Renderer_UseResolutionFactor", values.resolution_factor.GetValue()); log_setting("Renderer_UseFrameLimit", values.use_frame_limit.GetValue()); log_setting("Renderer_FrameLimit", values.frame_limit.GetValue()); diff --git a/src/common/settings.h b/src/common/settings.h index d39b4aa457..68dc2ea7d0 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -115,7 +115,7 @@ struct Values { Setting use_multi_core; // Cpu - CPUAccuracy cpu_accuracy; + Setting cpu_accuracy; bool cpuopt_page_tables; bool cpuopt_block_linking; @@ -126,9 +126,9 @@ struct Values { bool cpuopt_misc_ir; bool cpuopt_reduce_misalign_checks; - bool cpuopt_unsafe_unfuse_fma; - bool cpuopt_unsafe_reduce_fp_error; - bool cpuopt_unsafe_inaccurate_nan; + Setting cpuopt_unsafe_unfuse_fma; + Setting cpuopt_unsafe_reduce_fp_error; + Setting cpuopt_unsafe_inaccurate_nan; // Renderer Setting renderer_backend; diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.cpp b/src/core/arm/dynarmic/arm_dynarmic_32.cpp index 42a37e84f6..3535a3d114 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_32.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_32.cpp @@ -142,7 +142,7 @@ std::shared_ptr ARM_Dynarmic_32::MakeJit(Common::PageTable* config.far_code_offset = 256 * 1024 * 1024; // Safe optimizations - if (Settings::values.cpu_accuracy == Settings::CPUAccuracy::DebugMode) { + if (Settings::values.cpu_accuracy.GetValue() == Settings::CPUAccuracy::DebugMode) { if (!Settings::values.cpuopt_page_tables) { config.page_table = nullptr; } @@ -170,15 +170,15 @@ std::shared_ptr ARM_Dynarmic_32::MakeJit(Common::PageTable* } // Unsafe optimizations - if (Settings::values.cpu_accuracy == Settings::CPUAccuracy::Unsafe) { + if (Settings::values.cpu_accuracy.GetValue() == Settings::CPUAccuracy::Unsafe) { config.unsafe_optimizations = true; - if (Settings::values.cpuopt_unsafe_unfuse_fma) { + if (Settings::values.cpuopt_unsafe_unfuse_fma.GetValue()) { config.optimizations |= Dynarmic::OptimizationFlag::Unsafe_UnfuseFMA; } - if (Settings::values.cpuopt_unsafe_reduce_fp_error) { + if (Settings::values.cpuopt_unsafe_reduce_fp_error.GetValue()) { config.optimizations |= Dynarmic::OptimizationFlag::Unsafe_ReducedErrorFP; } - if (Settings::values.cpuopt_unsafe_inaccurate_nan) { + if (Settings::values.cpuopt_unsafe_inaccurate_nan.GetValue()) { config.optimizations |= Dynarmic::OptimizationFlag::Unsafe_InaccurateNaN; } } diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.cpp b/src/core/arm/dynarmic/arm_dynarmic_64.cpp index 653bb7a771..7e1f654db7 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_64.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_64.cpp @@ -182,7 +182,7 @@ std::shared_ptr ARM_Dynarmic_64::MakeJit(Common::PageTable* config.far_code_offset = 256 * 1024 * 1024; // Safe optimizations - if (Settings::values.cpu_accuracy == Settings::CPUAccuracy::DebugMode) { + if (Settings::values.cpu_accuracy.GetValue() == Settings::CPUAccuracy::DebugMode) { if (!Settings::values.cpuopt_page_tables) { config.page_table = nullptr; } @@ -210,15 +210,15 @@ std::shared_ptr ARM_Dynarmic_64::MakeJit(Common::PageTable* } // Unsafe optimizations - if (Settings::values.cpu_accuracy == Settings::CPUAccuracy::Unsafe) { + if (Settings::values.cpu_accuracy.GetValue() == Settings::CPUAccuracy::Unsafe) { config.unsafe_optimizations = true; - if (Settings::values.cpuopt_unsafe_unfuse_fma) { + if (Settings::values.cpuopt_unsafe_unfuse_fma.GetValue()) { config.optimizations |= Dynarmic::OptimizationFlag::Unsafe_UnfuseFMA; } - if (Settings::values.cpuopt_unsafe_reduce_fp_error) { + if (Settings::values.cpuopt_unsafe_reduce_fp_error.GetValue()) { config.optimizations |= Dynarmic::OptimizationFlag::Unsafe_ReducedErrorFP; } - if (Settings::values.cpuopt_unsafe_inaccurate_nan) { + if (Settings::values.cpuopt_unsafe_inaccurate_nan.GetValue()) { config.optimizations |= Dynarmic::OptimizationFlag::Unsafe_InaccurateNaN; } } diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index e80a3df776..24d46c7ccd 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -737,8 +737,7 @@ void Config::ReadCpuValues() { qt_config->beginGroup(QStringLiteral("Cpu")); if (global) { - Settings::values.cpu_accuracy = static_cast( - ReadSetting(QStringLiteral("cpu_accuracy"), 0).toInt()); + ReadSettingGlobal(Settings::values.cpu_accuracy, QStringLiteral("cpu_accuracy"), 0); Settings::values.cpuopt_page_tables = ReadSetting(QStringLiteral("cpuopt_page_tables"), true).toBool(); @@ -757,12 +756,12 @@ void Config::ReadCpuValues() { Settings::values.cpuopt_reduce_misalign_checks = ReadSetting(QStringLiteral("cpuopt_reduce_misalign_checks"), true).toBool(); - Settings::values.cpuopt_unsafe_unfuse_fma = - ReadSetting(QStringLiteral("cpuopt_unsafe_unfuse_fma"), true).toBool(); - Settings::values.cpuopt_unsafe_reduce_fp_error = - ReadSetting(QStringLiteral("cpuopt_unsafe_reduce_fp_error"), true).toBool(); - Settings::values.cpuopt_unsafe_inaccurate_nan = - ReadSetting(QStringLiteral("cpuopt_unsafe_inaccurate_nan"), true).toBool(); + ReadSettingGlobal(Settings::values.cpuopt_unsafe_unfuse_fma, + QStringLiteral("cpuopt_unsafe_unfuse_fma"), true); + ReadSettingGlobal(Settings::values.cpuopt_unsafe_reduce_fp_error, + QStringLiteral("cpuopt_unsafe_reduce_fp_error"), true); + ReadSettingGlobal(Settings::values.cpuopt_unsafe_inaccurate_nan, + QStringLiteral("cpuopt_unsafe_inaccurate_nan"), true); } qt_config->endGroup(); @@ -1314,8 +1313,10 @@ void Config::SaveCpuValues() { qt_config->beginGroup(QStringLiteral("Cpu")); if (global) { - WriteSetting(QStringLiteral("cpu_accuracy"), - static_cast(Settings::values.cpu_accuracy), 0); + WriteSettingGlobal(QStringLiteral("cpu_accuracy"), + static_cast(Settings::values.cpu_accuracy.GetValue(global)), + Settings::values.renderer_backend.UsingGlobal(), + static_cast(Settings::CPUAccuracy::Accurate)); WriteSetting(QStringLiteral("cpuopt_page_tables"), Settings::values.cpuopt_page_tables, true); @@ -1332,12 +1333,12 @@ void Config::SaveCpuValues() { WriteSetting(QStringLiteral("cpuopt_reduce_misalign_checks"), Settings::values.cpuopt_reduce_misalign_checks, true); - WriteSetting(QStringLiteral("cpuopt_unsafe_unfuse_fma"), - Settings::values.cpuopt_unsafe_unfuse_fma, true); - WriteSetting(QStringLiteral("cpuopt_unsafe_reduce_fp_error"), - Settings::values.cpuopt_unsafe_reduce_fp_error, true); - WriteSetting(QStringLiteral("cpuopt_unsafe_inaccurate_nan"), - Settings::values.cpuopt_unsafe_inaccurate_nan, true); + WriteSettingGlobal(QStringLiteral("cpuopt_unsafe_unfuse_fma"), + Settings::values.cpuopt_unsafe_unfuse_fma, true); + WriteSettingGlobal(QStringLiteral("cpuopt_unsafe_reduce_fp_error"), + Settings::values.cpuopt_unsafe_reduce_fp_error, true); + WriteSettingGlobal(QStringLiteral("cpuopt_unsafe_inaccurate_nan"), + Settings::values.cpuopt_unsafe_inaccurate_nan, true); } qt_config->endGroup(); diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index 5a2c026b35..ce3355588b 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h @@ -132,5 +132,6 @@ private: }; // These metatype declarations cannot be in common/settings.h because core is devoid of QT +Q_DECLARE_METATYPE(Settings::CPUAccuracy); Q_DECLARE_METATYPE(Settings::RendererBackend); Q_DECLARE_METATYPE(Settings::GPUAccuracy); diff --git a/src/yuzu/configuration/configure_cpu.cpp b/src/yuzu/configuration/configure_cpu.cpp index 4f99bc80fa..a59ea30879 100644 --- a/src/yuzu/configuration/configure_cpu.cpp +++ b/src/yuzu/configuration/configure_cpu.cpp @@ -29,15 +29,17 @@ void ConfigureCpu::SetConfiguration() { const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn(); ui->accuracy->setEnabled(runtime_lock); - ui->accuracy->setCurrentIndex(static_cast(Settings::values.cpu_accuracy)); - UpdateGroup(static_cast(Settings::values.cpu_accuracy)); + ui->accuracy->setCurrentIndex(static_cast(Settings::values.cpu_accuracy.GetValue())); + UpdateGroup(static_cast(Settings::values.cpu_accuracy.GetValue())); ui->cpuopt_unsafe_unfuse_fma->setEnabled(runtime_lock); - ui->cpuopt_unsafe_unfuse_fma->setChecked(Settings::values.cpuopt_unsafe_unfuse_fma); + ui->cpuopt_unsafe_unfuse_fma->setChecked(Settings::values.cpuopt_unsafe_unfuse_fma.GetValue()); ui->cpuopt_unsafe_reduce_fp_error->setEnabled(runtime_lock); - ui->cpuopt_unsafe_reduce_fp_error->setChecked(Settings::values.cpuopt_unsafe_reduce_fp_error); + ui->cpuopt_unsafe_reduce_fp_error->setChecked( + Settings::values.cpuopt_unsafe_reduce_fp_error.GetValue()); ui->cpuopt_unsafe_inaccurate_nan->setEnabled(runtime_lock); - ui->cpuopt_unsafe_inaccurate_nan->setChecked(Settings::values.cpuopt_unsafe_inaccurate_nan); + ui->cpuopt_unsafe_inaccurate_nan->setChecked( + Settings::values.cpuopt_unsafe_inaccurate_nan.GetValue()); } void ConfigureCpu::AccuracyUpdated(int index) { @@ -59,11 +61,13 @@ void ConfigureCpu::UpdateGroup(int index) { } void ConfigureCpu::ApplyConfiguration() { - Settings::values.cpu_accuracy = - static_cast(ui->accuracy->currentIndex()); - Settings::values.cpuopt_unsafe_unfuse_fma = ui->cpuopt_unsafe_unfuse_fma->isChecked(); - Settings::values.cpuopt_unsafe_reduce_fp_error = ui->cpuopt_unsafe_reduce_fp_error->isChecked(); - Settings::values.cpuopt_unsafe_inaccurate_nan = ui->cpuopt_unsafe_inaccurate_nan->isChecked(); + Settings::values.cpu_accuracy.SetValue( + static_cast(ui->accuracy->currentIndex())); + Settings::values.cpuopt_unsafe_unfuse_fma.SetValue(ui->cpuopt_unsafe_unfuse_fma->isChecked()); + Settings::values.cpuopt_unsafe_reduce_fp_error.SetValue( + ui->cpuopt_unsafe_reduce_fp_error->isChecked()); + Settings::values.cpuopt_unsafe_inaccurate_nan.SetValue( + ui->cpuopt_unsafe_inaccurate_nan->isChecked()); } void ConfigureCpu::changeEvent(QEvent* event) {