summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt2
-rw-r--r--src/common/assert.h2
-rw-r--r--src/common/bit_field.h2
-rw-r--r--src/common/bit_set.h3
-rw-r--r--src/common/code_block.h6
-rw-r--r--src/common/common_funcs.h4
-rw-r--r--src/common/emu_window.h52
-rw-r--r--src/common/file_util.cpp109
-rw-r--r--src/common/file_util.h41
-rw-r--r--src/common/logging/backend.cpp3
-rw-r--r--src/common/logging/log.h3
-rw-r--r--src/common/make_unique.h17
-rw-r--r--src/common/microprofile.h4
-rw-r--r--src/common/microprofileui.h3
-rw-r--r--src/common/profiler.cpp82
-rw-r--r--src/common/profiler.h152
-rw-r--r--src/common/profiler_reporting.h27
-rw-r--r--src/common/string_util.cpp16
-rw-r--r--src/common/string_util.h2
-rw-r--r--src/common/thread.h46
-rw-r--r--src/common/x64/emitter.cpp28
-rw-r--r--src/common/x64/emitter.h4
22 files changed, 220 insertions, 388 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 1c9be718f..aa6eee2a3 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -42,13 +42,11 @@ set(HEADERS
logging/filter.h
logging/log.h
logging/backend.h
- make_unique.h
math_util.h
memory_util.h
microprofile.h
microprofileui.h
platform.h
- profiler.h
profiler_reporting.h
scm_rev.h
scope_exit.h
diff --git a/src/common/assert.h b/src/common/assert.h
index 6849778b7..cd9b819a9 100644
--- a/src/common/assert.h
+++ b/src/common/assert.h
@@ -39,6 +39,7 @@ static void assert_noinline_call(const Fn& fn) {
}); } while (0)
#define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!")
+#define UNREACHABLE_MSG(...) ASSERT_MSG(false, __VA_ARGS__)
#ifdef _DEBUG
#define DEBUG_ASSERT(_a_) ASSERT(_a_)
@@ -49,3 +50,4 @@ static void assert_noinline_call(const Fn& fn) {
#endif
#define UNIMPLEMENTED() DEBUG_ASSERT_MSG(false, "Unimplemented code!")
+#define UNIMPLEMENTED_MSG(_a_, ...) ASSERT_MSG(false, _a_, __VA_ARGS__) \ No newline at end of file
diff --git a/src/common/bit_field.h b/src/common/bit_field.h
index 371eb17a1..4748999ed 100644
--- a/src/common/bit_field.h
+++ b/src/common/bit_field.h
@@ -186,5 +186,5 @@ private:
#pragma pack()
#if (__GNUC__ >= 5) || defined(__clang__) || defined(_MSC_VER)
-static_assert(std::is_trivially_copyable<BitField<0, 1, u32>>::value, "BitField must be trivially copyable");
+static_assert(std::is_trivially_copyable<BitField<0, 1, unsigned>>::value, "BitField must be trivially copyable");
#endif
diff --git a/src/common/bit_set.h b/src/common/bit_set.h
index 85f91e786..7f5de8df2 100644
--- a/src/common/bit_set.h
+++ b/src/common/bit_set.h
@@ -7,6 +7,7 @@
#include <intrin.h>
#endif
#include <initializer_list>
+#include <new>
#include <type_traits>
#include "common/common_types.h"
@@ -186,4 +187,4 @@ public:
typedef Common::BitSet<u8> BitSet8;
typedef Common::BitSet<u16> BitSet16;
typedef Common::BitSet<u32> BitSet32;
-typedef Common::BitSet<u64> BitSet64; \ No newline at end of file
+typedef Common::BitSet<u64> BitSet64;
diff --git a/src/common/code_block.h b/src/common/code_block.h
index 9ef7296d3..2fa4a0090 100644
--- a/src/common/code_block.h
+++ b/src/common/code_block.h
@@ -4,8 +4,10 @@
#pragma once
-#include "common_types.h"
-#include "memory_util.h"
+#include <cstddef>
+
+#include "common/common_types.h"
+#include "common/memory_util.h"
// Everything that needs to generate code should inherit from this.
// You get memory management for free, plus, you can use all emitter functions without
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index aa6aff7b9..ab3515683 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -4,6 +4,10 @@
#pragma once
+#if !defined(ARCHITECTURE_x86_64) && !defined(_M_ARM)
+#include <cstdlib> // for exit
+#endif
+
#include "common_types.h"
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
diff --git a/src/common/emu_window.h b/src/common/emu_window.h
index a0ae4c9fa..7c3486dea 100644
--- a/src/common/emu_window.h
+++ b/src/common/emu_window.h
@@ -105,7 +105,7 @@ public:
* @todo Fix this function to be thread-safe.
* @return PadState object indicating the current pad state
*/
- const Service::HID::PadState GetPadState() const {
+ Service::HID::PadState GetPadState() const {
return pad_state;
}
@@ -116,11 +116,59 @@ public:
* @return std::tuple of (x, y, pressed) where `x` and `y` are the touch coordinates and
* `pressed` is true if the touch screen is currently being pressed
*/
- const std::tuple<u16, u16, bool> GetTouchState() const {
+ std::tuple<u16, u16, bool> GetTouchState() const {
return std::make_tuple(touch_x, touch_y, touch_pressed);
}
/**
+ * Gets the current accelerometer state (acceleration along each three axis).
+ * Axis explained:
+ * +x is the same direction as LEFT on D-pad.
+ * +y is normal to the touch screen, pointing outward.
+ * +z is the same direction as UP on D-pad.
+ * Units:
+ * 1 unit of return value = 1/512 g (measured by hw test),
+ * where g is the gravitational acceleration (9.8 m/sec2).
+ * @note This should be called by the core emu thread to get a state set by the window thread.
+ * @todo Implement accelerometer input in front-end.
+ * @return std::tuple of (x, y, z)
+ */
+ std::tuple<s16, s16, s16> GetAccelerometerState() const {
+ // stubbed
+ return std::make_tuple(0, -512, 0);
+ }
+
+ /**
+ * Gets the current gyroscope state (angular rates about each three axis).
+ * Axis explained:
+ * +x is the same direction as LEFT on D-pad.
+ * +y is normal to the touch screen, pointing outward.
+ * +z is the same direction as UP on D-pad.
+ * Orientation is determined by right-hand rule.
+ * Units:
+ * 1 unit of return value = (1/coef) deg/sec,
+ * where coef is the return value of GetGyroscopeRawToDpsCoefficient().
+ * @note This should be called by the core emu thread to get a state set by the window thread.
+ * @todo Implement gyroscope input in front-end.
+ * @return std::tuple of (x, y, z)
+ */
+ std::tuple<s16, s16, s16> GetGyroscopeState() const {
+ // stubbed
+ return std::make_tuple(0, 0, 0);
+ }
+
+ /**
+ * Gets the coefficient for units conversion of gyroscope state.
+ * The conversion formula is r = coefficient * v,
+ * where v is angular rate in deg/sec,
+ * and r is the gyroscope state.
+ * @return float-type coefficient
+ */
+ f32 GetGyroscopeRawToDpsCoefficient() const {
+ return 14.375f; // taken from hw test, and gyroscope's document
+ }
+
+ /**
* Returns currently active configuration.
* @note Accesses to the returned object need not be consistent because it may be modified in another thread
*/
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index c3061479a..6e2867658 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -69,9 +69,10 @@ static void StripTailDirSlashes(std::string &fname)
{
if (fname.length() > 1)
{
- size_t i = fname.length() - 1;
- while (fname[i] == DIR_SEP_CHR)
- fname[i--] = '\0';
+ size_t i = fname.length();
+ while (i > 0 && fname[i - 1] == DIR_SEP_CHR)
+ --i;
+ fname.resize(i);
}
return;
}
@@ -85,7 +86,11 @@ bool Exists(const std::string &filename)
StripTailDirSlashes(copy);
#ifdef _WIN32
- int result = _tstat64(Common::UTF8ToTStr(copy).c_str(), &file_info);
+ // Windows needs a slash to identify a driver root
+ if (copy.size() != 0 && copy.back() == ':')
+ copy += DIR_SEP_CHR;
+
+ int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info);
#else
int result = stat64(copy.c_str(), &file_info);
#endif
@@ -102,7 +107,11 @@ bool IsDirectory(const std::string &filename)
StripTailDirSlashes(copy);
#ifdef _WIN32
- int result = _tstat64(Common::UTF8ToTStr(copy).c_str(), &file_info);
+ // Windows needs a slash to identify a driver root
+ if (copy.size() != 0 && copy.back() == ':')
+ copy += DIR_SEP_CHR;
+
+ int result = _wstat64(Common::UTF8ToUTF16W(copy).c_str(), &file_info);
#else
int result = stat64(copy.c_str(), &file_info);
#endif
@@ -138,7 +147,7 @@ bool Delete(const std::string &filename)
}
#ifdef _WIN32
- if (!DeleteFile(Common::UTF8ToTStr(filename).c_str()))
+ if (!DeleteFileW(Common::UTF8ToUTF16W(filename).c_str()))
{
LOG_ERROR(Common_Filesystem, "DeleteFile failed on %s: %s",
filename.c_str(), GetLastErrorMsg());
@@ -160,7 +169,7 @@ bool CreateDir(const std::string &path)
{
LOG_TRACE(Common_Filesystem, "directory %s", path.c_str());
#ifdef _WIN32
- if (::CreateDirectory(Common::UTF8ToTStr(path).c_str(), nullptr))
+ if (::CreateDirectoryW(Common::UTF8ToUTF16W(path).c_str(), nullptr))
return true;
DWORD error = GetLastError();
if (error == ERROR_ALREADY_EXISTS)
@@ -241,7 +250,7 @@ bool DeleteDir(const std::string &filename)
}
#ifdef _WIN32
- if (::RemoveDirectory(Common::UTF8ToTStr(filename).c_str()))
+ if (::RemoveDirectoryW(Common::UTF8ToUTF16W(filename).c_str()))
return true;
#else
if (rmdir(filename.c_str()) == 0)
@@ -257,8 +266,13 @@ bool Rename(const std::string &srcFilename, const std::string &destFilename)
{
LOG_TRACE(Common_Filesystem, "%s --> %s",
srcFilename.c_str(), destFilename.c_str());
+#ifdef _WIN32
+ if (_wrename(Common::UTF8ToUTF16W(srcFilename).c_str(), Common::UTF8ToUTF16W(destFilename).c_str()) == 0)
+ return true;
+#else
if (rename(srcFilename.c_str(), destFilename.c_str()) == 0)
return true;
+#endif
LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s",
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
return false;
@@ -270,7 +284,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
LOG_TRACE(Common_Filesystem, "%s --> %s",
srcFilename.c_str(), destFilename.c_str());
#ifdef _WIN32
- if (CopyFile(Common::UTF8ToTStr(srcFilename).c_str(), Common::UTF8ToTStr(destFilename).c_str(), FALSE))
+ if (CopyFileW(Common::UTF8ToUTF16W(srcFilename).c_str(), Common::UTF8ToUTF16W(destFilename).c_str(), FALSE))
return true;
LOG_ERROR(Common_Filesystem, "failed %s --> %s: %s",
@@ -358,7 +372,7 @@ u64 GetSize(const std::string &filename)
struct stat64 buf;
#ifdef _WIN32
- if (_tstat64(Common::UTF8ToTStr(filename).c_str(), &buf) == 0)
+ if (_wstat64(Common::UTF8ToUTF16W(filename).c_str(), &buf) == 0)
#else
if (stat64(filename.c_str(), &buf) == 0)
#endif
@@ -432,16 +446,16 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo
#ifdef _WIN32
// Find the first file in the directory.
- WIN32_FIND_DATA ffd;
+ WIN32_FIND_DATAW ffd;
- HANDLE handle_find = FindFirstFile(Common::UTF8ToTStr(directory + "\\*").c_str(), &ffd);
+ HANDLE handle_find = FindFirstFileW(Common::UTF8ToUTF16W(directory + "\\*").c_str(), &ffd);
if (handle_find == INVALID_HANDLE_VALUE) {
FindClose(handle_find);
return false;
}
// windows loop
do {
- const std::string virtual_name(Common::TStrToUTF8(ffd.cFileName));
+ const std::string virtual_name(Common::UTF16ToUTF8(ffd.cFileName));
#else
struct dirent dirent, *result = nullptr;
@@ -465,7 +479,7 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo
found_entries += ret_entries;
#ifdef _WIN32
- } while (FindNextFile(handle_find, &ffd) != 0);
+ } while (FindNextFileW(handle_find, &ffd) != 0);
FindClose(handle_find);
#else
}
@@ -572,15 +586,23 @@ void CopyDir(const std::string &source_path, const std::string &dest_path)
// Returns the current directory
std::string GetCurrentDir()
{
- char *dir;
// Get the current working directory (getcwd uses malloc)
+#ifdef _WIN32
+ wchar_t *dir;
+ if (!(dir = _wgetcwd(nullptr, 0))) {
+#else
+ char *dir;
if (!(dir = getcwd(nullptr, 0))) {
-
+#endif
LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: %s",
GetLastErrorMsg());
return nullptr;
}
+#ifdef _WIN32
+ std::string strDir = Common::UTF16ToUTF8(dir);
+#else
std::string strDir = dir;
+#endif
free(dir);
return strDir;
}
@@ -588,7 +610,11 @@ std::string GetCurrentDir()
// Sets the current directory to the given directory
bool SetCurrentDir(const std::string &directory)
{
+#ifdef _WIN32
+ return _wchdir(Common::UTF8ToUTF16W(directory).c_str()) == 0;
+#else
return chdir(directory.c_str()) == 0;
+#endif
}
#if defined(__APPLE__)
@@ -613,9 +639,9 @@ std::string& GetExeDirectory()
static std::string exe_path;
if (exe_path.empty())
{
- TCHAR tchar_exe_path[2048];
- GetModuleFileName(nullptr, tchar_exe_path, 2048);
- exe_path = Common::TStrToUTF8(tchar_exe_path);
+ wchar_t wchar_exe_path[2048];
+ GetModuleFileNameW(nullptr, wchar_exe_path, 2048);
+ exe_path = Common::UTF16ToUTF8(wchar_exe_path);
exe_path = exe_path.substr(0, exe_path.find_last_of('\\'));
}
return exe_path;
@@ -807,13 +833,12 @@ size_t WriteStringToFile(bool text_file, const std::string &str, const char *fil
size_t ReadFileToString(bool text_file, const char *filename, std::string &str)
{
- FileUtil::IOFile file(filename, text_file ? "r" : "rb");
- auto const f = file.GetHandle();
+ IOFile file(filename, text_file ? "r" : "rb");
- if (!f)
+ if (!file)
return false;
- str.resize(static_cast<u32>(GetSize(f)));
+ str.resize(static_cast<u32>(file.GetSize()));
return file.ReadArray(&str[0], str.size());
}
@@ -860,15 +885,10 @@ void SplitFilename83(const std::string& filename, std::array<char, 9>& short_nam
}
IOFile::IOFile()
- : m_file(nullptr), m_good(true)
-{}
-
-IOFile::IOFile(std::FILE* file)
- : m_file(file), m_good(true)
-{}
+{
+}
IOFile::IOFile(const std::string& filename, const char openmode[])
- : m_file(nullptr), m_good(true)
{
Open(filename, openmode);
}
@@ -879,7 +899,6 @@ IOFile::~IOFile()
}
IOFile::IOFile(IOFile&& other)
- : m_file(nullptr), m_good(true)
{
Swap(other);
}
@@ -900,7 +919,7 @@ bool IOFile::Open(const std::string& filename, const char openmode[])
{
Close();
#ifdef _WIN32
- _tfopen_s(&m_file, Common::UTF8ToTStr(filename).c_str(), Common::UTF8ToTStr(openmode).c_str());
+ _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(), Common::UTF8ToUTF16W(openmode).c_str());
#else
m_file = fopen(filename.c_str(), openmode);
#endif
@@ -918,26 +937,12 @@ bool IOFile::Close()
return m_good;
}
-std::FILE* IOFile::ReleaseHandle()
-{
- std::FILE* const ret = m_file;
- m_file = nullptr;
- return ret;
-}
-
-void IOFile::SetHandle(std::FILE* file)
-{
- Close();
- Clear();
- m_file = file;
-}
-
-u64 IOFile::GetSize()
+u64 IOFile::GetSize() const
{
if (IsOpen())
return FileUtil::GetSize(m_file);
- else
- return 0;
+
+ return 0;
}
bool IOFile::Seek(s64 off, int origin)
@@ -948,12 +953,12 @@ bool IOFile::Seek(s64 off, int origin)
return m_good;
}
-u64 IOFile::Tell()
+u64 IOFile::Tell() const
{
if (IsOpen())
return ftello(m_file);
- else
- return -1;
+
+ return -1;
}
bool IOFile::Flush()
diff --git a/src/common/file_util.h b/src/common/file_util.h
index a85121aa6..c6a8694ce 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -7,13 +7,17 @@
#include <array>
#include <fstream>
#include <functional>
-#include <cstddef>
#include <cstdio>
#include <string>
+#include <type_traits>
#include <vector>
#include "common/common_types.h"
+#ifdef _MSC_VER
+#include "common/string_util.h"
+#endif
+
// User directory indices for GetUserPath
enum {
D_USER_IDX,
@@ -172,7 +176,6 @@ class IOFile : public NonCopyable
{
public:
IOFile();
- IOFile(std::FILE* file);
IOFile(const std::string& filename, const char openmode[]);
~IOFile();
@@ -188,6 +191,11 @@ public:
template <typename T>
size_t ReadArray(T* data, size_t length)
{
+ static_assert(std::is_standard_layout<T>(), "Given array does not consist of standard layout objects");
+#if (__GNUC__ >= 5) || defined(__clang__) || defined(_MSC_VER)
+ static_assert(std::is_trivially_copyable<T>(), "Given array does not consist of trivially copyable objects");
+#endif
+
if (!IsOpen()) {
m_good = false;
return -1;
@@ -203,9 +211,10 @@ public:
template <typename T>
size_t WriteArray(const T* data, size_t length)
{
- static_assert(std::is_standard_layout<T>::value, "Given array does not consist of standard layout objects");
- // TODO: gcc 4.8 does not support is_trivially_copyable, but we really should check for it here.
- //static_assert(std::is_trivially_copyable<T>::value, "Given array does not consist of trivially copyable objects");
+ static_assert(std::is_standard_layout<T>(), "Given array does not consist of standard layout objects");
+#if (__GNUC__ >= 5) || defined(__clang__) || defined(_MSC_VER)
+ static_assert(std::is_trivially_copyable<T>(), "Given array does not consist of trivially copyable objects");
+#endif
if (!IsOpen()) {
m_good = false;
@@ -235,32 +244,24 @@ public:
return WriteArray(&object, 1);
}
- bool IsOpen() { return nullptr != m_file; }
+ bool IsOpen() const { return nullptr != m_file; }
// m_good is set to false when a read, write or other function fails
- bool IsGood() { return m_good; }
- operator void*() { return m_good ? m_file : nullptr; }
-
- std::FILE* ReleaseHandle();
-
- std::FILE* GetHandle() { return m_file; }
-
- void SetHandle(std::FILE* file);
+ bool IsGood() const { return m_good; }
+ explicit operator bool() const { return IsGood(); }
bool Seek(s64 off, int origin);
- u64 Tell();
- u64 GetSize();
+ u64 Tell() const;
+ u64 GetSize() const;
bool Resize(u64 size);
bool Flush();
// clear error state
void Clear() { m_good = true; std::clearerr(m_file); }
- std::FILE* m_file;
- bool m_good;
private:
- IOFile(IOFile&);
- IOFile& operator=(IOFile& other);
+ std::FILE* m_file = nullptr;
+ bool m_good = true;
};
} // namespace
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 4c86151ab..3d39f94d5 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -34,6 +34,7 @@ namespace Log {
SUB(Kernel, SVC) \
CLS(Service) \
SUB(Service, SRV) \
+ SUB(Service, FRD) \
SUB(Service, FS) \
SUB(Service, ERR) \
SUB(Service, APT) \
@@ -46,8 +47,10 @@ namespace Log {
SUB(Service, NIM) \
SUB(Service, NWM) \
SUB(Service, CAM) \
+ SUB(Service, CECD) \
SUB(Service, CFG) \
SUB(Service, DSP) \
+ SUB(Service, DLP) \
SUB(Service, HID) \
SUB(Service, SOC) \
SUB(Service, IR) \
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index e4c39c308..521362317 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -49,6 +49,7 @@ enum class Class : ClassType {
Service, ///< HLE implementation of system services. Each major service
/// should have its own subclass.
Service_SRV, ///< The SRV (Service Directory) implementation
+ Service_FRD, ///< The FRD (Friends) service
Service_FS, ///< The FS (Filesystem) service implementation
Service_ERR, ///< The ERR (Error) port implementation
Service_APT, ///< The APT (Applets) service
@@ -61,8 +62,10 @@ enum class Class : ClassType {
Service_NIM, ///< The NIM (Network interface manager) service
Service_NWM, ///< The NWM (Network wlan manager) service
Service_CAM, ///< The CAM (Camera) service
+ Service_CECD, ///< The CECD (StreetPass) service
Service_CFG, ///< The CFG (Configuration) service
Service_DSP, ///< The DSP (DSP control) service
+ Service_DLP, ///< The DLP (Download Play) service
Service_HID, ///< The HID (Human interface device) service
Service_SOC, ///< The SOC (Socket) service
Service_IR, ///< The IR service
diff --git a/src/common/make_unique.h b/src/common/make_unique.h
deleted file mode 100644
index f6e7f017c..000000000
--- a/src/common/make_unique.h
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <algorithm>
-#include <memory>
-
-namespace Common {
-
-template <typename T, typename... Args>
-std::unique_ptr<T> make_unique(Args&&... args) {
- return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
-}
-
-} // namespace
diff --git a/src/common/microprofile.h b/src/common/microprofile.h
index d3b6cb97c..ef312c6e1 100644
--- a/src/common/microprofile.h
+++ b/src/common/microprofile.h
@@ -4,6 +4,10 @@
#pragma once
+// Uncomment this to disable microprofile. This will get you cleaner profiles when using
+// external sampling profilers like "Very Sleepy", and will improve performance somewhat.
+// #define MICROPROFILE_ENABLED 0
+
// Customized Citra settings.
// This file wraps the MicroProfile header so that these are consistent everywhere.
#define MICROPROFILE_WEBSERVER 0
diff --git a/src/common/microprofileui.h b/src/common/microprofileui.h
index 97c369bd9..41abe6b75 100644
--- a/src/common/microprofileui.h
+++ b/src/common/microprofileui.h
@@ -13,4 +13,7 @@
#define MICROPROFILE_HELP_ALT "Right-Click"
#define MICROPROFILE_HELP_MOD "Ctrl"
+// This isn't included by microprofileui.h :(
+#include <cstdlib> // For std::abs
+
#include <microprofileui.h>
diff --git a/src/common/profiler.cpp b/src/common/profiler.cpp
index 7792edd2f..49eb3f40c 100644
--- a/src/common/profiler.cpp
+++ b/src/common/profiler.cpp
@@ -7,71 +7,16 @@
#include <vector>
#include "common/assert.h"
-#include "common/profiler.h"
#include "common/profiler_reporting.h"
#include "common/synchronized_wrapper.h"
-#if defined(_MSC_VER) && _MSC_VER <= 1800 // MSVC 2013.
- #define WIN32_LEAN_AND_MEAN
- #include <Windows.h> // For QueryPerformanceCounter/Frequency
-#endif
-
namespace Common {
namespace Profiling {
-#if ENABLE_PROFILING
-thread_local Timer* Timer::current_timer = nullptr;
-#endif
-
-#if defined(_MSC_VER) && _MSC_VER <= 1800 // MSVC 2013
-QPCClock::time_point QPCClock::now() {
- static LARGE_INTEGER freq;
- // Use this dummy local static to ensure this gets initialized once.
- static BOOL dummy = QueryPerformanceFrequency(&freq);
-
- LARGE_INTEGER ticks;
- QueryPerformanceCounter(&ticks);
-
- // This is prone to overflow when multiplying, which is why I'm using micro instead of nano. The
- // correct way to approach this would be to just return ticks as a time_point and then subtract
- // and do this conversion when creating a duration from two time_points, however, as far as I
- // could tell the C++ requirements for these types are incompatible with this approach.
- return time_point(duration(ticks.QuadPart * std::micro::den / freq.QuadPart));
-}
-#endif
-
-TimingCategory::TimingCategory(const char* name, TimingCategory* parent)
- : accumulated_duration(0) {
-
- ProfilingManager& manager = GetProfilingManager();
- category_id = manager.RegisterTimingCategory(this, name);
- if (parent != nullptr)
- manager.SetTimingCategoryParent(category_id, parent->category_id);
-}
-
ProfilingManager::ProfilingManager()
: last_frame_end(Clock::now()), this_frame_start(Clock::now()) {
}
-unsigned int ProfilingManager::RegisterTimingCategory(TimingCategory* category, const char* name) {
- TimingCategoryInfo info;
- info.category = category;
- info.name = name;
- info.parent = TimingCategoryInfo::NO_PARENT;
-
- unsigned int id = (unsigned int)timing_categories.size();
- timing_categories.push_back(std::move(info));
-
- return id;
-}
-
-void ProfilingManager::SetTimingCategoryParent(unsigned int category, unsigned int parent) {
- ASSERT(category < timing_categories.size());
- ASSERT(parent < timing_categories.size());
-
- timing_categories[category].parent = parent;
-}
-
void ProfilingManager::BeginFrame() {
this_frame_start = Clock::now();
}
@@ -82,11 +27,6 @@ void ProfilingManager::FinishFrame() {
results.interframe_time = now - last_frame_end;
results.frame_time = now - this_frame_start;
- results.time_per_category.resize(timing_categories.size());
- for (size_t i = 0; i < timing_categories.size(); ++i) {
- results.time_per_category[i] = timing_categories[i].category->GetAccumulatedTime();
- }
-
last_frame_end = now;
}
@@ -100,26 +40,9 @@ void TimingResultsAggregator::Clear() {
window_size = cursor = 0;
}
-void TimingResultsAggregator::SetNumberOfCategories(size_t n) {
- size_t old_size = times_per_category.size();
- if (n == old_size)
- return;
-
- times_per_category.resize(n);
-
- for (size_t i = old_size; i < n; ++i) {
- times_per_category[i].resize(max_window_size, Duration::zero());
- }
-}
-
void TimingResultsAggregator::AddFrame(const ProfilingFrameResult& frame_result) {
- SetNumberOfCategories(frame_result.time_per_category.size());
-
interframe_times[cursor] = frame_result.interframe_time;
frame_times[cursor] = frame_result.frame_time;
- for (size_t i = 0; i < frame_result.time_per_category.size(); ++i) {
- times_per_category[i][cursor] = frame_result.time_per_category[i];
- }
++cursor;
if (cursor == max_window_size)
@@ -162,11 +85,6 @@ AggregatedFrameResult TimingResultsAggregator::GetAggregatedResults() const {
result.fps = 0.0f;
}
- result.time_per_category.resize(times_per_category.size());
- for (size_t i = 0; i < times_per_category.size(); ++i) {
- result.time_per_category[i] = AggregateField(times_per_category[i], window_size);
- }
-
return result;
}
diff --git a/src/common/profiler.h b/src/common/profiler.h
deleted file mode 100644
index 3e967b4bc..000000000
--- a/src/common/profiler.h
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright 2015 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <atomic>
-#include <chrono>
-
-#include "common/assert.h"
-#include "common/thread.h"
-
-namespace Common {
-namespace Profiling {
-
-// If this is defined to 0, it turns all Timers into no-ops.
-#ifndef ENABLE_PROFILING
-#define ENABLE_PROFILING 1
-#endif
-
-#if defined(_MSC_VER) && _MSC_VER <= 1800 // MSVC 2013
-// MSVC up to 2013 doesn't use QueryPerformanceCounter for high_resolution_clock, so it has bad
-// precision. We manually implement a clock based on QPC to get good results.
-
-struct QPCClock {
- using duration = std::chrono::microseconds;
- using time_point = std::chrono::time_point<QPCClock>;
- using rep = duration::rep;
- using period = duration::period;
- static const bool is_steady = false;
-
- static time_point now();
-};
-
-using Clock = QPCClock;
-#else
-using Clock = std::chrono::high_resolution_clock;
-#endif
-
-using Duration = Clock::duration;
-
-/**
- * Represents a timing category that measured time can be accounted towards. Should be declared as a
- * global variable and passed to Timers.
- */
-class TimingCategory final {
-public:
- TimingCategory(const char* name, TimingCategory* parent = nullptr);
-
- unsigned int GetCategoryId() const {
- return category_id;
- }
-
- /// Adds some time to this category. Can safely be called from multiple threads at the same time.
- void AddTime(Duration amount) {
- std::atomic_fetch_add_explicit(
- &accumulated_duration, amount.count(),
- std::memory_order_relaxed);
- }
-
- /**
- * Atomically retrieves the accumulated measured time for this category and resets the counter
- * to zero. Can be safely called concurrently with AddTime.
- */
- Duration GetAccumulatedTime() {
- return Duration(std::atomic_exchange_explicit(
- &accumulated_duration, (Duration::rep)0,
- std::memory_order_relaxed));
- }
-
-private:
- unsigned int category_id;
- std::atomic<Duration::rep> accumulated_duration;
-};
-
-/**
- * Measures time elapsed between a call to Start and a call to Stop and attributes it to the given
- * TimingCategory. Start/Stop can be called multiple times on the same timer, but each call must be
- * appropriately paired.
- *
- * When a Timer is started, it automatically pauses a previously running timer on the same thread,
- * which is resumed when it is stopped. As such, no special action needs to be taken to avoid
- * double-accounting of time on two categories.
- */
-class Timer {
-public:
- Timer(TimingCategory& category) : category(category) {
- }
-
- void Start() {
-#if ENABLE_PROFILING
- ASSERT(!running);
- previous_timer = current_timer;
- current_timer = this;
- if (previous_timer != nullptr)
- previous_timer->StopTiming();
-
- StartTiming();
-#endif
- }
-
- void Stop() {
-#if ENABLE_PROFILING
- ASSERT(running);
- StopTiming();
-
- if (previous_timer != nullptr)
- previous_timer->StartTiming();
- current_timer = previous_timer;
-#endif
- }
-
-private:
-#if ENABLE_PROFILING
- void StartTiming() {
- start = Clock::now();
- running = true;
- }
-
- void StopTiming() {
- auto duration = Clock::now() - start;
- running = false;
- category.AddTime(std::chrono::duration_cast<Duration>(duration));
- }
-
- Clock::time_point start;
- bool running = false;
-
- Timer* previous_timer;
- static thread_local Timer* current_timer;
-#endif
-
- TimingCategory& category;
-};
-
-/**
- * A Timer that automatically starts timing when created and stops at the end of the scope. Should
- * be used in the majority of cases.
- */
-class ScopeTimer : public Timer {
-public:
- ScopeTimer(TimingCategory& category) : Timer(category) {
- Start();
- }
-
- ~ScopeTimer() {
- Stop();
- }
-};
-
-} // namespace Profiling
-} // namespace Common
diff --git a/src/common/profiler_reporting.h b/src/common/profiler_reporting.h
index df98e05b7..fa1ac883f 100644
--- a/src/common/profiler_reporting.h
+++ b/src/common/profiler_reporting.h
@@ -4,22 +4,17 @@
#pragma once
+#include <chrono>
#include <cstddef>
#include <vector>
-#include "common/profiler.h"
#include "common/synchronized_wrapper.h"
namespace Common {
namespace Profiling {
-struct TimingCategoryInfo {
- static const unsigned int NO_PARENT = -1;
-
- TimingCategory* category;
- const char* name;
- unsigned int parent;
-};
+using Clock = std::chrono::high_resolution_clock;
+using Duration = Clock::duration;
struct ProfilingFrameResult {
/// Time since the last delivered frame
@@ -27,22 +22,12 @@ struct ProfilingFrameResult {
/// Time spent processing a frame, excluding VSync
Duration frame_time;
-
- /// Total amount of time spent inside each category in this frame. Indexed by the category id
- std::vector<Duration> time_per_category;
};
class ProfilingManager final {
public:
ProfilingManager();
- unsigned int RegisterTimingCategory(TimingCategory* category, const char* name);
- void SetTimingCategoryParent(unsigned int category, unsigned int parent);
-
- const std::vector<TimingCategoryInfo>& GetTimingCategoriesInfo() const {
- return timing_categories;
- }
-
/// This should be called after swapping screen buffers.
void BeginFrame();
/// This should be called before swapping screen buffers.
@@ -54,7 +39,6 @@ public:
}
private:
- std::vector<TimingCategoryInfo> timing_categories;
Clock::time_point last_frame_end;
Clock::time_point this_frame_start;
@@ -73,9 +57,6 @@ struct AggregatedFrameResult {
AggregatedDuration frame_time;
float fps;
-
- /// Total amount of time spent inside each category in this frame. Indexed by the category id
- std::vector<AggregatedDuration> time_per_category;
};
class TimingResultsAggregator final {
@@ -83,7 +64,6 @@ public:
TimingResultsAggregator(size_t window_size);
void Clear();
- void SetNumberOfCategories(size_t n);
void AddFrame(const ProfilingFrameResult& frame_result);
@@ -95,7 +75,6 @@ public:
std::vector<Duration> interframe_times;
std::vector<Duration> frame_times;
- std::vector<std::vector<Duration>> times_per_category;
};
ProfilingManager& GetProfilingManager();
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index 6d6fc591f..f0aa072db 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -320,27 +320,27 @@ std::u16string UTF8ToUTF16(const std::string& input)
#endif
}
-static std::string UTF16ToUTF8(const std::wstring& input)
+static std::wstring CPToUTF16(u32 code_page, const std::string& input)
{
- auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr);
+ auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0);
- std::string output;
+ std::wstring output;
output.resize(size);
- if (size == 0 || size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()), nullptr, nullptr))
+ if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size())))
output.clear();
return output;
}
-static std::wstring CPToUTF16(u32 code_page, const std::string& input)
+std::string UTF16ToUTF8(const std::wstring& input)
{
- auto const size = MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), nullptr, 0);
+ auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), nullptr, 0, nullptr, nullptr);
- std::wstring output;
+ std::string output;
output.resize(size);
- if (size == 0 || size != MultiByteToWideChar(code_page, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size())))
+ if (size == 0 || size != WideCharToMultiByte(CP_UTF8, 0, input.data(), static_cast<int>(input.size()), &output[0], static_cast<int>(output.size()), nullptr, nullptr))
output.clear();
return output;
diff --git a/src/common/string_util.h b/src/common/string_util.h
index c5c474c6f..89d9f133e 100644
--- a/src/common/string_util.h
+++ b/src/common/string_util.h
@@ -95,7 +95,7 @@ std::string CP1252ToUTF8(const std::string& str);
std::string SHIFTJISToUTF8(const std::string& str);
#ifdef _WIN32
-
+std::string UTF16ToUTF8(const std::wstring& input);
std::wstring UTF8ToUTF16W(const std::string& str);
#ifdef _UNICODE
diff --git a/src/common/thread.h b/src/common/thread.h
index 8255ee6d3..bbfa8befa 100644
--- a/src/common/thread.h
+++ b/src/common/thread.h
@@ -30,8 +30,7 @@
# endif
#endif
-namespace Common
-{
+namespace Common {
int CurrentThreadId();
@@ -43,55 +42,55 @@ public:
Event() : is_set(false) {}
void Set() {
- std::lock_guard<std::mutex> lk(m_mutex);
+ std::lock_guard<std::mutex> lk(mutex);
if (!is_set) {
is_set = true;
- m_condvar.notify_one();
+ condvar.notify_one();
}
}
void Wait() {
- std::unique_lock<std::mutex> lk(m_mutex);
- m_condvar.wait(lk, [&]{ return is_set; });
+ std::unique_lock<std::mutex> lk(mutex);
+ condvar.wait(lk, [&]{ return is_set; });
is_set = false;
}
void Reset() {
- std::unique_lock<std::mutex> lk(m_mutex);
+ std::unique_lock<std::mutex> lk(mutex);
// no other action required, since wait loops on the predicate and any lingering signal will get cleared on the first iteration
is_set = false;
}
private:
bool is_set;
- std::condition_variable m_condvar;
- std::mutex m_mutex;
+ std::condition_variable condvar;
+ std::mutex mutex;
};
class Barrier {
public:
- Barrier(size_t count) : m_count(count), m_waiting(0) {}
+ explicit Barrier(size_t count_) : count(count_), waiting(0), generation(0) {}
/// Blocks until all "count" threads have called Sync()
void Sync() {
- std::unique_lock<std::mutex> lk(m_mutex);
+ std::unique_lock<std::mutex> lk(mutex);
+ const size_t current_generation = generation;
- // TODO: broken when next round of Sync()s
- // is entered before all waiting threads return from the notify_all
-
- if (++m_waiting == m_count) {
- m_waiting = 0;
- m_condvar.notify_all();
+ if (++waiting == count) {
+ generation++;
+ waiting = 0;
+ condvar.notify_all();
} else {
- m_condvar.wait(lk, [&]{ return m_waiting == 0; });
+ condvar.wait(lk, [this, current_generation]{ return current_generation != generation; });
}
}
private:
- std::condition_variable m_condvar;
- std::mutex m_mutex;
- const size_t m_count;
- size_t m_waiting;
+ std::condition_variable condvar;
+ std::mutex mutex;
+ const size_t count;
+ size_t waiting;
+ size_t generation; // Incremented once each time the barrier is used
};
void SleepCurrentThread(int ms);
@@ -100,8 +99,7 @@ void SwitchCurrentThread(); // On Linux, this is equal to sleep 1ms
// Use this function during a spin-wait to make the current thread
// relax while another thread is working. This may be more efficient
// than using events because event functions use kernel calls.
-inline void YieldCPU()
-{
+inline void YieldCPU() {
std::this_thread::yield();
}
diff --git a/src/common/x64/emitter.cpp b/src/common/x64/emitter.cpp
index 1dcf2416c..5662f7f86 100644
--- a/src/common/x64/emitter.cpp
+++ b/src/common/x64/emitter.cpp
@@ -455,6 +455,18 @@ void XEmitter::CALL(const void* fnptr)
Write32(u32(distance));
}
+FixupBranch XEmitter::CALL()
+{
+ FixupBranch branch;
+ branch.type = 1;
+ branch.ptr = code + 5;
+
+ Write8(0xE8);
+ Write32(0);
+
+ return branch;
+}
+
FixupBranch XEmitter::J(bool force5bytes)
{
FixupBranch branch;
@@ -531,6 +543,22 @@ void XEmitter::SetJumpTarget(const FixupBranch& branch)
}
}
+void XEmitter::SetJumpTarget(const FixupBranch& branch, const u8* target)
+{
+ if (branch.type == 0)
+ {
+ s64 distance = (s64)(target - branch.ptr);
+ ASSERT_MSG(distance >= -0x80 && distance < 0x80, "Jump target too far away, needs force5Bytes = true");
+ branch.ptr[-1] = (u8)(s8)distance;
+ }
+ else if (branch.type == 1)
+ {
+ s64 distance = (s64)(target - branch.ptr);
+ ASSERT_MSG(distance >= -0x80000000LL && distance < 0x80000000LL, "Jump target too far away, needs indirect register");
+ ((s32*)branch.ptr)[-1] = (s32)distance;
+ }
+}
+
//Single byte opcodes
//There is no PUSHAD/POPAD in 64-bit mode.
void XEmitter::INT3() {Write8(0xCC);}
diff --git a/src/common/x64/emitter.h b/src/common/x64/emitter.h
index 7c6548fb5..60a77dfe1 100644
--- a/src/common/x64/emitter.h
+++ b/src/common/x64/emitter.h
@@ -17,6 +17,8 @@
#pragma once
+#include <cstddef>
+
#include "common/assert.h"
#include "common/bit_set.h"
#include "common/common_types.h"
@@ -425,12 +427,14 @@ public:
#undef CALL
#endif
void CALL(const void* fnptr);
+ FixupBranch CALL();
void CALLptr(OpArg arg);
FixupBranch J_CC(CCFlags conditionCode, bool force5bytes = false);
void J_CC(CCFlags conditionCode, const u8* addr, bool force5Bytes = false);
void SetJumpTarget(const FixupBranch& branch);
+ void SetJumpTarget(const FixupBranch& branch, const u8* target);
void SETcc(CCFlags flag, OpArg dest);
// Note: CMOV brings small if any benefit on current cpus.