Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement "Enable TSX" combobox #4766

Merged
merged 2 commits into from
Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Utilities/sysinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ bool utils::has_avx2()

bool utils::has_rtm()
{
// Check RTM and MPX extensions in order to filter out TSX on Haswell CPUs
static const bool g_value = get_cpuid(0, 0)[0] >= 0x7 && (get_cpuid(7, 0)[1] & 0x4800) == 0x4800;
static const bool g_value = get_cpuid(0, 0)[0] >= 0x7 && (get_cpuid(7, 0)[1] & 0x800) == 0x800;
return g_value;
}

bool utils::has_mpx()
{
static const bool g_value = get_cpuid(0, 0)[0] >= 0x7 && (get_cpuid(7, 0)[1] & 0x4000) == 0x4000;
return g_value;
}

Expand Down Expand Up @@ -114,6 +119,10 @@ std::string utils::get_system_info()
if (has_rtm())
{
result += " | TSX";
if (!has_mpx())
{
result += " disabled by default";
}
}

return result;
Expand Down
2 changes: 2 additions & 0 deletions Utilities/sysinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace utils

bool has_rtm();

bool has_mpx();

bool has_512();

bool has_xop();
Expand Down
27 changes: 26 additions & 1 deletion rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@

#include "Utilities/GDBDebugServer.h"

#include "Utilities/sysinfo.h"

#if defined(_WIN32) || defined(HAVE_VULKAN)
#include "Emu/RSX/VK/VulkanAPI.h"
#endif

cfg_root g_cfg;

bool g_use_rtm = utils::has_rtm();
bool g_use_rtm;

std::string g_cfg_defaults;

Expand Down Expand Up @@ -222,6 +224,22 @@ inline void fmt_class_string<detail_level>::format(std::string& out, u64 arg)
});
}

template <>
void fmt_class_string<tsx_usage>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](tsx_usage value)
{
switch (value)
{
case tsx_usage::disabled: return "Disabled";
case tsx_usage::enabled: return "Enabled";
case tsx_usage::forced: return "Forced";
}

return unknown;
});
}

void Emulator::Init()
{
if (!g_tty)
Expand Down Expand Up @@ -626,6 +644,13 @@ void Emulator::Load(bool add_only)
#endif

LOG_NOTICE(LOADER, "Used configuration:\n%s\n", g_cfg.to_string());

// Set RTM usage
g_use_rtm = utils::has_rtm() && ((utils::has_mpx() && g_cfg.core.enable_TSX == tsx_usage::enabled) || g_cfg.core.enable_TSX == tsx_usage::forced);
if (g_use_rtm && !utils::has_mpx())
{
LOG_WARNING(GENERAL, "TSX forced by User");
}

// Load patches from different locations
fxm::check_unlocked<patch_engine>()->append(fs::get_config_dir() + "data/" + m_title_id + "/patch.yml");
Expand Down
8 changes: 8 additions & 0 deletions rpcs3/Emu/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ enum class detail_level
high,
};

enum class tsx_usage
{
disabled,
enabled,
forced,
};

enum CellNetCtlState : s32;
enum CellSysutilLang : s32;

Expand Down Expand Up @@ -326,6 +333,7 @@ struct cfg_root : cfg::node
cfg::_bool spu_accurate_putlluc{this, "Accurate PUTLLUC", false};
cfg::_bool spu_verification{this, "SPU Verification", true}; // Should be enabled
cfg::_bool spu_cache{this, "SPU Cache", true};
cfg::_enum<tsx_usage> enable_TSX{this, "Enable TSX", tsx_usage::enabled}; // Enable TSX. Forcing this on Haswell/Broadwell CPUs should be used carefully

cfg::_enum<lib_loading_type> lib_loading{this, "Lib Loader", lib_loading_type::liblv2only};
cfg::_bool hook_functions{this, "Hook static functions"};
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Json/tooltips.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"debug": {
"ppuDebug": "Never use this.",
"spuDebug": "Never use this.",
"enableTSX": "Enable usage of TSX instructions.\nNeeds to be forced on some Haswell or Broadwell CPUs.\nForcing this on older Hardware can lead to system instability, use it with caution.",
"readColor": "Never use this.",
"dumpDepth": "Never use this.",
"readDepth": "Never use this.",
Expand Down
2 changes: 2 additions & 0 deletions rpcs3/rpcs3qt/emu_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class emu_settings : public QObject
PPUDebug,
SPUDebug,
MaxLLVMThreads,
EnableTSX,

// Graphics
Renderer,
Expand Down Expand Up @@ -205,6 +206,7 @@ public Q_SLOTS:
{ PPUDebug, { "Core", "PPU Debug"}},
{ SPUDebug, { "Core", "SPU Debug"}},
{ MaxLLVMThreads, { "Core", "Max LLVM Compile Threads"}},
{ EnableTSX, { "Core", "Enable TSX"}},

// Graphics Tab
{ Renderer, { "Video", "Renderer"}},
Expand Down
35 changes: 35 additions & 0 deletions rpcs3/rpcs3qt/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "stdafx.h"
#include "Emu/System.h"
#include "Crypto/unself.h"
#include "Utilities/sysinfo.h"

#include <unordered_set>
#include <thread>
Expand Down Expand Up @@ -1079,6 +1080,40 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> guiSettings, std:

xemu_settings->EnhanceCheckBox(ui->spuDebug, emu_settings::SPUDebug);
SubscribeTooltip(ui->spuDebug, json_debug["spuDebug"].toString());

if (utils::has_rtm())
{
xemu_settings->EnhanceComboBox(ui->enableTSX, emu_settings::EnableTSX);
SubscribeTooltip(ui->enableTSX, json_debug["enableTSX"].toString());

static const QString tsx_forced = qstr(fmt::format("%s", tsx_usage::forced));
static const QString tsx_default = qstr(xemu_settings->GetSettingDefault(emu_settings::EnableTSX));

// connect the toogled signal so that the stateChanged signal in EnhanceCheckBox can be prevented
connect(ui->enableTSX, &QComboBox::currentTextChanged, [this](const QString& text)
{
if (text == tsx_forced && !utils::has_mpx() && QMessageBox::No == QMessageBox::critical(this, tr("Haswell/Broadwell TSX Warning"), tr(
R"(
<p style="white-space: nowrap;">
RPCS3 has detected you are using TSX functions on a Haswell or Broadwell CPU.<br>
Intel has deactivated these functions in newer Microcode revisions, since they can lead to unpredicted behaviour.<br>
That means using TSX may break games or even <font color="red"><b>damage</b></font> your data.<br>
We recommend to disable this feature and update your computer BIOS.<br><br>
Do you wish to use TSX anyway?
</p>
)"
), QMessageBox::Yes, QMessageBox::No))
{
// Reset if the messagebox was answered with no. This prevents the currentIndexChanged signal in EnhanceComboBox
ui->enableTSX->setCurrentText(tsx_default);
}
});
}
else
{
ui->label_enableTSX->setHidden(true);
ui->enableTSX->setHidden(true);
}

//
// Layout fix for High Dpi
Expand Down
16 changes: 13 additions & 3 deletions rpcs3/rpcs3qt/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>752</width>
<height>519</height>
<width>849</width>
<height>615</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -36,7 +36,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>7</number>
<number>0</number>
</property>
<widget class="QWidget" name="coreTab">
<attribute name="title">
Expand Down Expand Up @@ -1969,6 +1969,16 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_enableTSX">
<property name="text">
<string>Enable TSX:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="enableTSX"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down