1
0
Fork 0
forked from suyu/suyu

configuration: Add CPU tab to game properties

Allows setting CPU accuracy to Accurate or Unsafe per-game, as well as
the accuracy options for Unsafe. Debug is not allowed here as a per-game
CPU accuracy.
This commit is contained in:
lat9nq 2021-05-15 23:53:36 -04:00
parent 4aac1ae4b1
commit ab2677f0a1
13 changed files with 181 additions and 88 deletions

View file

@ -106,6 +106,12 @@ void RestoreGlobalState(bool is_powered_on) {
// Core
values.use_multi_core.SetGlobal(true);
// CPU
values.cpu_accuracy.SetGlobal(true);
values.cpuopt_unsafe_unfuse_fma.SetGlobal(true);
values.cpuopt_unsafe_reduce_fp_error.SetGlobal(true);
values.cpuopt_unsafe_inaccurate_nan.SetGlobal(true);
// Renderer
values.renderer_backend.SetGlobal(true);
values.vulkan_device.SetGlobal(true);

View file

@ -736,9 +736,16 @@ void Config::ReadPathValues() {
void Config::ReadCpuValues() {
qt_config->beginGroup(QStringLiteral("Cpu"));
if (global) {
ReadSettingGlobal(Settings::values.cpu_accuracy, QStringLiteral("cpu_accuracy"), 0);
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);
if (global) {
Settings::values.cpuopt_page_tables =
ReadSetting(QStringLiteral("cpuopt_page_tables"), true).toBool();
Settings::values.cpuopt_block_linking =
@ -755,13 +762,6 @@ void Config::ReadCpuValues() {
ReadSetting(QStringLiteral("cpuopt_misc_ir"), true).toBool();
Settings::values.cpuopt_reduce_misalign_checks =
ReadSetting(QStringLiteral("cpuopt_reduce_misalign_checks"), 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();
@ -1312,12 +1312,19 @@ void Config::SavePathValues() {
void Config::SaveCpuValues() {
qt_config->beginGroup(QStringLiteral("Cpu"));
if (global) {
WriteSettingGlobal(QStringLiteral("cpu_accuracy"),
static_cast<u32>(Settings::values.cpu_accuracy.GetValue(global)),
Settings::values.renderer_backend.UsingGlobal(),
Settings::values.cpu_accuracy.UsingGlobal(),
static_cast<u32>(Settings::CPUAccuracy::Accurate));
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);
if (global) {
WriteSetting(QStringLiteral("cpuopt_page_tables"), Settings::values.cpuopt_page_tables,
true);
WriteSetting(QStringLiteral("cpuopt_block_linking"), Settings::values.cpuopt_block_linking,
@ -1332,13 +1339,6 @@ void Config::SaveCpuValues() {
WriteSetting(QStringLiteral("cpuopt_misc_ir"), Settings::values.cpuopt_misc_ir, true);
WriteSetting(QStringLiteral("cpuopt_reduce_misalign_checks"),
Settings::values.cpuopt_reduce_misalign_checks, 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();

View file

@ -84,6 +84,13 @@ void ConfigurationShared::SetPerGameSetting(
ConfigurationShared::USE_GLOBAL_OFFSET);
}
void ConfigurationShared::SetPerGameSetting(
QComboBox* combobox, const Settings::Setting<Settings::CPUAccuracy>* setting) {
combobox->setCurrentIndex(setting->UsingGlobal() ? ConfigurationShared::USE_GLOBAL_INDEX
: static_cast<int>(setting->GetValue()) +
ConfigurationShared::USE_GLOBAL_OFFSET);
}
void ConfigurationShared::SetHighlight(QWidget* widget, bool highlighted) {
if (highlighted) {
widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,203,255,0.5) }")

View file

@ -39,6 +39,8 @@ void SetPerGameSetting(QComboBox* combobox,
const Settings::Setting<Settings::RendererBackend>* setting);
void SetPerGameSetting(QComboBox* combobox,
const Settings::Setting<Settings::GPUAccuracy>* setting);
void SetPerGameSetting(QComboBox* combobox,
const Settings::Setting<Settings::CPUAccuracy>* setting);
// (Un)highlights a Qt UI element
void SetHighlight(QWidget* widget, bool highlighted);

View file

@ -100,8 +100,7 @@ void ConfigureAudio::SetVolumeIndicatorText(int percentage) {
void ConfigureAudio::ApplyConfiguration() {
ConfigurationShared::ApplyPerGameSetting(&Settings::values.enable_audio_stretching,
ui->toggle_audio_stretching,
enable_audio_stretching);
ui->toggle_audio_stretching, enable_audio_stretching);
if (Settings::IsConfiguringGlobal()) {
Settings::values.sink_id =

View file

@ -10,11 +10,14 @@
#include "common/settings.h"
#include "core/core.h"
#include "ui_configure_cpu.h"
#include "yuzu/configuration/configuration_shared.h"
#include "yuzu/configuration/configure_cpu.h"
ConfigureCpu::ConfigureCpu(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureCpu) {
ui->setupUi(this);
SetupPerGameUI();
SetConfiguration();
connect(ui->accuracy, qOverload<int>(&QComboBox::activated), this,
@ -29,21 +32,29 @@ void ConfigureCpu::SetConfiguration() {
const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn();
ui->accuracy->setEnabled(runtime_lock);
ui->accuracy->setCurrentIndex(static_cast<int>(Settings::values.cpu_accuracy.GetValue()));
UpdateGroup(static_cast<int>(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.GetValue());
ui->cpuopt_unsafe_reduce_fp_error->setEnabled(runtime_lock);
ui->cpuopt_unsafe_inaccurate_nan->setEnabled(runtime_lock);
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_inaccurate_nan->setEnabled(runtime_lock);
ui->cpuopt_unsafe_inaccurate_nan->setChecked(
Settings::values.cpuopt_unsafe_inaccurate_nan.GetValue());
if (Settings::IsConfiguringGlobal()) {
ui->accuracy->setCurrentIndex(static_cast<int>(Settings::values.cpu_accuracy.GetValue()));
} else {
ConfigurationShared::SetPerGameSetting(ui->accuracy, &Settings::values.cpu_accuracy);
ConfigurationShared::SetHighlight(ui->widget_accuracy,
!Settings::values.cpu_accuracy.UsingGlobal());
}
UpdateGroup(ui->accuracy->currentIndex());
}
void ConfigureCpu::AccuracyUpdated(int index) {
if (static_cast<Settings::CPUAccuracy>(index) == Settings::CPUAccuracy::DebugMode) {
if (Settings::IsConfiguringGlobal() &&
static_cast<Settings::CPUAccuracy>(index) == Settings::CPUAccuracy::DebugMode) {
const auto result = QMessageBox::warning(this, tr("Setting CPU to Debug Mode"),
tr("CPU Debug Mode is only intended for developer "
"use. Are you sure you want to enable this?"),
@ -56,18 +67,42 @@ void ConfigureCpu::AccuracyUpdated(int index) {
}
void ConfigureCpu::UpdateGroup(int index) {
if (Settings::IsConfiguringGlobal()) {
ui->unsafe_group->setVisible(static_cast<Settings::CPUAccuracy>(index) ==
Settings::CPUAccuracy::Unsafe);
} else {
ui->unsafe_group->setVisible(
static_cast<Settings::CPUAccuracy>(index - ConfigurationShared::USE_GLOBAL_OFFSET) ==
Settings::CPUAccuracy::Unsafe);
}
}
void ConfigureCpu::ApplyConfiguration() {
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_inaccurate_nan,
ui->cpuopt_unsafe_inaccurate_nan,
cpuopt_unsafe_inaccurate_nan);
if (Settings::IsConfiguringGlobal()) {
// Guard if during game and set to game-specific value
if (Settings::values.cpu_accuracy.UsingGlobal()) {
Settings::values.cpu_accuracy.SetValue(
static_cast<Settings::CPUAccuracy>(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());
}
} else {
if (ui->accuracy->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) {
Settings::values.cpu_accuracy.SetGlobal(true);
} else {
Settings::values.cpu_accuracy.SetGlobal(false);
Settings::values.cpu_accuracy.SetValue(static_cast<Settings::CPUAccuracy>(
ui->accuracy->currentIndex() - ConfigurationShared::USE_GLOBAL_OFFSET));
}
}
}
void ConfigureCpu::changeEvent(QEvent* event) {
@ -81,3 +116,25 @@ 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<u32>(Settings::values.cpu_accuracy.GetValue(true)));
ui->accuracy->removeItem(static_cast<u32>(Settings::CPUAccuracy::DebugMode) +
ConfigurationShared::USE_GLOBAL_OFFSET);
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_inaccurate_nan,
Settings::values.cpuopt_unsafe_inaccurate_nan,
cpuopt_unsafe_inaccurate_nan);
}

View file

@ -8,6 +8,10 @@
#include <QWidget>
#include "common/settings.h"
namespace ConfigurationShared {
enum class CheckState;
}
namespace Ui {
class ConfigureCpu;
}
@ -30,5 +34,11 @@ private:
void SetConfiguration();
void SetupPerGameUI();
std::unique_ptr<Ui::ConfigureCpu> ui;
ConfigurationShared::CheckState cpuopt_unsafe_unfuse_fma;
ConfigurationShared::CheckState cpuopt_unsafe_reduce_fp_error;
ConfigurationShared::CheckState cpuopt_unsafe_inaccurate_nan;
};

View file

@ -23,9 +23,10 @@
</property>
<layout class="QVBoxLayout">
<item>
<layout class="QHBoxLayout">
<widget class="QWidget" name="widget_accuracy" native="true">
<layout class="QHBoxLayout" name="layout_accuracy">
<item>
<widget class="QLabel">
<widget class="QLabel" name="label">
<property name="text">
<string>Accuracy:</string>
</property>
@ -51,14 +52,15 @@
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel">
<property name="wordWrap">
<bool>1</bool>
</property>
<widget class="QLabel" name="label">
<property name="text">
<string>We recommend setting accuracy to "Accurate".</string>
<string>We recommend setting accuracy to &quot;Accurate&quot;.</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
@ -76,49 +78,49 @@
</property>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel">
<property name="wordWrap">
<bool>1</bool>
</property>
<widget class="QLabel" name="label">
<property name="text">
<string>These settings reduce accuracy for speed.</string>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_unsafe_unfuse_fma">
<property name="text">
<string>Unfuse FMA (improve performance on CPUs without FMA)</string>
</property>
<property name="toolTip">
<string>
&lt;div&gt;This option improves speed by reducing accuracy of fused-multiply-add instructions on CPUs without native FMA support.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Unfuse FMA (improve performance on CPUs without FMA)</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_unsafe_reduce_fp_error">
<property name="text">
<string>Faster FRSQRTE and FRECPE</string>
</property>
<property name="toolTip">
<string>
&lt;div&gt;This option improves the speed of some approximate floating-point functions by using less accurate native approximations.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Faster FRSQRTE and FRECPE</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cpuopt_unsafe_inaccurate_nan">
<property name="text">
<string>Inaccurate NaN handling</string>
</property>
<property name="toolTip">
<string>
&lt;div&gt;This option improves speed by removing NaN checking. Please note this also reduces accuracy of certain floating-point instructions.&lt;/div&gt;
</string>
</property>
<property name="text">
<string>Inaccurate NaN handling</string>
</property>
</widget>
</item>
</layout>

View file

@ -50,8 +50,8 @@ void ConfigureGeneral::SetConfiguration() {
}
void ConfigureGeneral::ApplyConfiguration() {
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core,
ui->use_multi_core, use_multi_core);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core, ui->use_multi_core,
use_multi_core);
if (Settings::IsConfiguringGlobal()) {
UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked();

View file

@ -56,8 +56,7 @@ void ConfigureGraphicsAdvanced::ApplyConfiguration() {
ConfigurationShared::ApplyPerGameSetting(&Settings::values.max_anisotropy,
ui->anisotropic_filtering_combobox);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_vsync, ui->use_vsync,
use_vsync);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_vsync, ui->use_vsync, use_vsync);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_assembly_shaders,
ui->use_assembly_shaders, use_assembly_shaders);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_shaders,

View file

@ -52,6 +52,7 @@ ConfigurePerGame::~ConfigurePerGame() = default;
void ConfigurePerGame::ApplyConfiguration() {
ui->addonsTab->ApplyConfiguration();
ui->generalTab->ApplyConfiguration();
ui->cpuTab->ApplyConfiguration();
ui->systemTab->ApplyConfiguration();
ui->graphicsTab->ApplyConfiguration();
ui->graphicsAdvancedTab->ApplyConfiguration();

View file

@ -235,6 +235,11 @@
<string>System</string>
</attribute>
</widget>
<widget class="ConfigureCpu" name="cpuTab">
<attribute name="title">
<string>CPU</string>
</attribute>
</widget>
<widget class="ConfigureGraphics" name="graphicsTab">
<attribute name="title">
<string>Graphics</string>
@ -311,6 +316,12 @@
<header>configuration/configure_per_game_addons.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ConfigureCpu</class>
<extends>QWidget</extends>
<header>configuration/configure_cpu.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>

View file

@ -127,8 +127,7 @@ void ConfigureSystem::ApplyConfiguration() {
return;
}
ConfigurationShared::ApplyPerGameSetting(&Settings::values.language_index,
ui->combo_language);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.language_index, ui->combo_language);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.region_index, ui->combo_region);
ConfigurationShared::ApplyPerGameSetting(&Settings::values.time_zone_index,
ui->combo_time_zone);