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.
This commit is contained in:
lat9nq 2021-05-15 20:46:48 -04:00
parent 904584e4ba
commit e169fdad4f
7 changed files with 47 additions and 41 deletions

View file

@ -42,7 +42,7 @@ void LogSettings() {
log_setting("System_RegionIndex", values.region_index.GetValue()); log_setting("System_RegionIndex", values.region_index.GetValue());
log_setting("System_TimeZoneIndex", values.time_zone_index.GetValue()); log_setting("System_TimeZoneIndex", values.time_zone_index.GetValue());
log_setting("Core_UseMultiCore", values.use_multi_core.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_UseResolutionFactor", values.resolution_factor.GetValue());
log_setting("Renderer_UseFrameLimit", values.use_frame_limit.GetValue()); log_setting("Renderer_UseFrameLimit", values.use_frame_limit.GetValue());
log_setting("Renderer_FrameLimit", values.frame_limit.GetValue()); log_setting("Renderer_FrameLimit", values.frame_limit.GetValue());

View file

@ -115,7 +115,7 @@ struct Values {
Setting<bool> use_multi_core; Setting<bool> use_multi_core;
// Cpu // Cpu
CPUAccuracy cpu_accuracy; Setting<CPUAccuracy> cpu_accuracy;
bool cpuopt_page_tables; bool cpuopt_page_tables;
bool cpuopt_block_linking; bool cpuopt_block_linking;
@ -126,9 +126,9 @@ struct Values {
bool cpuopt_misc_ir; bool cpuopt_misc_ir;
bool cpuopt_reduce_misalign_checks; bool cpuopt_reduce_misalign_checks;
bool cpuopt_unsafe_unfuse_fma; Setting<bool> cpuopt_unsafe_unfuse_fma;
bool cpuopt_unsafe_reduce_fp_error; Setting<bool> cpuopt_unsafe_reduce_fp_error;
bool cpuopt_unsafe_inaccurate_nan; Setting<bool> cpuopt_unsafe_inaccurate_nan;
// Renderer // Renderer
Setting<RendererBackend> renderer_backend; Setting<RendererBackend> renderer_backend;

View file

@ -142,7 +142,7 @@ std::shared_ptr<Dynarmic::A32::Jit> ARM_Dynarmic_32::MakeJit(Common::PageTable*
config.far_code_offset = 256 * 1024 * 1024; config.far_code_offset = 256 * 1024 * 1024;
// Safe optimizations // 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) { if (!Settings::values.cpuopt_page_tables) {
config.page_table = nullptr; config.page_table = nullptr;
} }
@ -170,15 +170,15 @@ std::shared_ptr<Dynarmic::A32::Jit> ARM_Dynarmic_32::MakeJit(Common::PageTable*
} }
// Unsafe optimizations // Unsafe optimizations
if (Settings::values.cpu_accuracy == Settings::CPUAccuracy::Unsafe) { if (Settings::values.cpu_accuracy.GetValue() == Settings::CPUAccuracy::Unsafe) {
config.unsafe_optimizations = true; 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; 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; 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; config.optimizations |= Dynarmic::OptimizationFlag::Unsafe_InaccurateNaN;
} }
} }

View file

@ -182,7 +182,7 @@ std::shared_ptr<Dynarmic::A64::Jit> ARM_Dynarmic_64::MakeJit(Common::PageTable*
config.far_code_offset = 256 * 1024 * 1024; config.far_code_offset = 256 * 1024 * 1024;
// Safe optimizations // 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) { if (!Settings::values.cpuopt_page_tables) {
config.page_table = nullptr; config.page_table = nullptr;
} }
@ -210,15 +210,15 @@ std::shared_ptr<Dynarmic::A64::Jit> ARM_Dynarmic_64::MakeJit(Common::PageTable*
} }
// Unsafe optimizations // Unsafe optimizations
if (Settings::values.cpu_accuracy == Settings::CPUAccuracy::Unsafe) { if (Settings::values.cpu_accuracy.GetValue() == Settings::CPUAccuracy::Unsafe) {
config.unsafe_optimizations = true; 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; 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; 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; config.optimizations |= Dynarmic::OptimizationFlag::Unsafe_InaccurateNaN;
} }
} }

View file

@ -737,8 +737,7 @@ void Config::ReadCpuValues() {
qt_config->beginGroup(QStringLiteral("Cpu")); qt_config->beginGroup(QStringLiteral("Cpu"));
if (global) { if (global) {
Settings::values.cpu_accuracy = static_cast<Settings::CPUAccuracy>( ReadSettingGlobal(Settings::values.cpu_accuracy, QStringLiteral("cpu_accuracy"), 0);
ReadSetting(QStringLiteral("cpu_accuracy"), 0).toInt());
Settings::values.cpuopt_page_tables = Settings::values.cpuopt_page_tables =
ReadSetting(QStringLiteral("cpuopt_page_tables"), true).toBool(); ReadSetting(QStringLiteral("cpuopt_page_tables"), true).toBool();
@ -757,12 +756,12 @@ void Config::ReadCpuValues() {
Settings::values.cpuopt_reduce_misalign_checks = Settings::values.cpuopt_reduce_misalign_checks =
ReadSetting(QStringLiteral("cpuopt_reduce_misalign_checks"), true).toBool(); ReadSetting(QStringLiteral("cpuopt_reduce_misalign_checks"), true).toBool();
Settings::values.cpuopt_unsafe_unfuse_fma = ReadSettingGlobal(Settings::values.cpuopt_unsafe_unfuse_fma,
ReadSetting(QStringLiteral("cpuopt_unsafe_unfuse_fma"), true).toBool(); QStringLiteral("cpuopt_unsafe_unfuse_fma"), true);
Settings::values.cpuopt_unsafe_reduce_fp_error = ReadSettingGlobal(Settings::values.cpuopt_unsafe_reduce_fp_error,
ReadSetting(QStringLiteral("cpuopt_unsafe_reduce_fp_error"), true).toBool(); QStringLiteral("cpuopt_unsafe_reduce_fp_error"), true);
Settings::values.cpuopt_unsafe_inaccurate_nan = ReadSettingGlobal(Settings::values.cpuopt_unsafe_inaccurate_nan,
ReadSetting(QStringLiteral("cpuopt_unsafe_inaccurate_nan"), true).toBool(); QStringLiteral("cpuopt_unsafe_inaccurate_nan"), true);
} }
qt_config->endGroup(); qt_config->endGroup();
@ -1314,8 +1313,10 @@ void Config::SaveCpuValues() {
qt_config->beginGroup(QStringLiteral("Cpu")); qt_config->beginGroup(QStringLiteral("Cpu"));
if (global) { if (global) {
WriteSetting(QStringLiteral("cpu_accuracy"), WriteSettingGlobal(QStringLiteral("cpu_accuracy"),
static_cast<int>(Settings::values.cpu_accuracy), 0); static_cast<u32>(Settings::values.cpu_accuracy.GetValue(global)),
Settings::values.renderer_backend.UsingGlobal(),
static_cast<u32>(Settings::CPUAccuracy::Accurate));
WriteSetting(QStringLiteral("cpuopt_page_tables"), Settings::values.cpuopt_page_tables, WriteSetting(QStringLiteral("cpuopt_page_tables"), Settings::values.cpuopt_page_tables,
true); true);
@ -1332,12 +1333,12 @@ void Config::SaveCpuValues() {
WriteSetting(QStringLiteral("cpuopt_reduce_misalign_checks"), WriteSetting(QStringLiteral("cpuopt_reduce_misalign_checks"),
Settings::values.cpuopt_reduce_misalign_checks, true); Settings::values.cpuopt_reduce_misalign_checks, true);
WriteSetting(QStringLiteral("cpuopt_unsafe_unfuse_fma"), WriteSettingGlobal(QStringLiteral("cpuopt_unsafe_unfuse_fma"),
Settings::values.cpuopt_unsafe_unfuse_fma, true); Settings::values.cpuopt_unsafe_unfuse_fma, true);
WriteSetting(QStringLiteral("cpuopt_unsafe_reduce_fp_error"), WriteSettingGlobal(QStringLiteral("cpuopt_unsafe_reduce_fp_error"),
Settings::values.cpuopt_unsafe_reduce_fp_error, true); Settings::values.cpuopt_unsafe_reduce_fp_error, true);
WriteSetting(QStringLiteral("cpuopt_unsafe_inaccurate_nan"), WriteSettingGlobal(QStringLiteral("cpuopt_unsafe_inaccurate_nan"),
Settings::values.cpuopt_unsafe_inaccurate_nan, true); Settings::values.cpuopt_unsafe_inaccurate_nan, true);
} }
qt_config->endGroup(); qt_config->endGroup();

View file

@ -132,5 +132,6 @@ private:
}; };
// These metatype declarations cannot be in common/settings.h because core is devoid of QT // 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::RendererBackend);
Q_DECLARE_METATYPE(Settings::GPUAccuracy); Q_DECLARE_METATYPE(Settings::GPUAccuracy);

View file

@ -29,15 +29,17 @@ void ConfigureCpu::SetConfiguration() {
const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn(); const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn();
ui->accuracy->setEnabled(runtime_lock); ui->accuracy->setEnabled(runtime_lock);
ui->accuracy->setCurrentIndex(static_cast<int>(Settings::values.cpu_accuracy)); ui->accuracy->setCurrentIndex(static_cast<int>(Settings::values.cpu_accuracy.GetValue()));
UpdateGroup(static_cast<int>(Settings::values.cpu_accuracy)); UpdateGroup(static_cast<int>(Settings::values.cpu_accuracy.GetValue()));
ui->cpuopt_unsafe_unfuse_fma->setEnabled(runtime_lock); 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->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->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) { void ConfigureCpu::AccuracyUpdated(int index) {
@ -59,11 +61,13 @@ void ConfigureCpu::UpdateGroup(int index) {
} }
void ConfigureCpu::ApplyConfiguration() { void ConfigureCpu::ApplyConfiguration() {
Settings::values.cpu_accuracy = Settings::values.cpu_accuracy.SetValue(
static_cast<Settings::CPUAccuracy>(ui->accuracy->currentIndex()); static_cast<Settings::CPUAccuracy>(ui->accuracy->currentIndex()));
Settings::values.cpuopt_unsafe_unfuse_fma = ui->cpuopt_unsafe_unfuse_fma->isChecked(); Settings::values.cpuopt_unsafe_unfuse_fma.SetValue(ui->cpuopt_unsafe_unfuse_fma->isChecked());
Settings::values.cpuopt_unsafe_reduce_fp_error = ui->cpuopt_unsafe_reduce_fp_error->isChecked(); Settings::values.cpuopt_unsafe_reduce_fp_error.SetValue(
Settings::values.cpuopt_unsafe_inaccurate_nan = ui->cpuopt_unsafe_inaccurate_nan->isChecked(); 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) { void ConfigureCpu::changeEvent(QEvent* event) {