diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | src/common/assert.h | 7 | ||||
| -rw-r--r-- | src/common/color.h | 4 | ||||
| -rw-r--r-- | src/common/common_funcs.h | 14 | ||||
| -rw-r--r-- | src/common/hex_util.h | 10 | ||||
| -rw-r--r-- | src/common/math_util.h | 6 | ||||
| -rw-r--r-- | src/common/param_package.h | 2 | ||||
| -rw-r--r-- | src/common/quaternion.h | 30 | ||||
| -rw-r--r-- | src/common/thread.cpp | 12 | ||||
| -rw-r--r-- | src/common/thread.h | 9 | ||||
| -rw-r--r-- | src/common/vector_math.h | 75 | ||||
| -rw-r--r-- | src/common/wall_clock.cpp | 2 | ||||
| -rw-r--r-- | src/common/wall_clock.h | 2 | ||||
| -rw-r--r-- | src/common/web_result.h | 25 | ||||
| -rw-r--r-- | src/common/x64/native_clock.h | 2 | ||||
| -rw-r--r-- | src/common/x64/xbyak_abi.h | 32 |
16 files changed, 164 insertions, 76 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 78c3bfb3b..0fb5d9708 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -172,7 +172,6 @@ add_library(common STATIC | |||
| 172 | virtual_buffer.h | 172 | virtual_buffer.h |
| 173 | wall_clock.cpp | 173 | wall_clock.cpp |
| 174 | wall_clock.h | 174 | wall_clock.h |
| 175 | web_result.h | ||
| 176 | zstd_compression.cpp | 175 | zstd_compression.cpp |
| 177 | zstd_compression.h | 176 | zstd_compression.h |
| 178 | ) | 177 | ) |
| @@ -193,4 +192,9 @@ create_target_directory_groups(common) | |||
| 193 | find_package(Boost 1.71 COMPONENTS context headers REQUIRED) | 192 | find_package(Boost 1.71 COMPONENTS context headers REQUIRED) |
| 194 | 193 | ||
| 195 | target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile) | 194 | target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile) |
| 196 | target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd xbyak) | 195 | target_link_libraries(common PRIVATE lz4::lz4 xbyak) |
| 196 | if (MSVC) | ||
| 197 | target_link_libraries(common PRIVATE zstd::zstd) | ||
| 198 | else() | ||
| 199 | target_link_libraries(common PRIVATE zstd) | ||
| 200 | endif() | ||
diff --git a/src/common/assert.h b/src/common/assert.h index 5b67c5c52..06d7b5612 100644 --- a/src/common/assert.h +++ b/src/common/assert.h | |||
| @@ -17,11 +17,12 @@ | |||
| 17 | // enough for our purposes. | 17 | // enough for our purposes. |
| 18 | template <typename Fn> | 18 | template <typename Fn> |
| 19 | #if defined(_MSC_VER) | 19 | #if defined(_MSC_VER) |
| 20 | __declspec(noinline, noreturn) | 20 | [[msvc::noinline, noreturn]] |
| 21 | #elif defined(__GNUC__) | 21 | #elif defined(__GNUC__) |
| 22 | __attribute__((noinline, noreturn, cold)) | 22 | [[gnu::cold, gnu::noinline, noreturn]] |
| 23 | #endif | 23 | #endif |
| 24 | static void assert_noinline_call(const Fn& fn) { | 24 | static void |
| 25 | assert_noinline_call(const Fn& fn) { | ||
| 25 | fn(); | 26 | fn(); |
| 26 | Crash(); | 27 | Crash(); |
| 27 | exit(1); // Keeps GCC's mouth shut about this actually returning | 28 | exit(1); // Keeps GCC's mouth shut about this actually returning |
diff --git a/src/common/color.h b/src/common/color.h index 381d6332e..bbcac858e 100644 --- a/src/common/color.h +++ b/src/common/color.h | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | #include "common/swap.h" | 10 | #include "common/swap.h" |
| 11 | #include "common/vector_math.h" | 11 | #include "common/vector_math.h" |
| 12 | 12 | ||
| 13 | namespace Color { | 13 | namespace Common::Color { |
| 14 | 14 | ||
| 15 | /// Convert a 1-bit color component to 8 bit | 15 | /// Convert a 1-bit color component to 8 bit |
| 16 | [[nodiscard]] constexpr u8 Convert1To8(u8 value) { | 16 | [[nodiscard]] constexpr u8 Convert1To8(u8 value) { |
| @@ -268,4 +268,4 @@ inline void EncodeX24S8(u8 stencil, u8* bytes) { | |||
| 268 | bytes[3] = stencil; | 268 | bytes[3] = stencil; |
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | } // namespace Color | 271 | } // namespace Common::Color |
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 98421bced..367b6bf6e 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h | |||
| @@ -64,14 +64,20 @@ __declspec(dllimport) void __stdcall DebugBreak(void); | |||
| 64 | using T = std::underlying_type_t<type>; \ | 64 | using T = std::underlying_type_t<type>; \ |
| 65 | return static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ | 65 | return static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ |
| 66 | } \ | 66 | } \ |
| 67 | constexpr type& operator|=(type& a, type b) noexcept { \ | 67 | [[nodiscard]] constexpr type operator^(type a, type b) noexcept { \ |
| 68 | using T = std::underlying_type_t<type>; \ | 68 | using T = std::underlying_type_t<type>; \ |
| 69 | a = static_cast<type>(static_cast<T>(a) | static_cast<T>(b)); \ | 69 | return static_cast<type>(static_cast<T>(a) ^ static_cast<T>(b)); \ |
| 70 | } \ | ||
| 71 | constexpr type& operator|=(type& a, type b) noexcept { \ | ||
| 72 | a = a | b; \ | ||
| 70 | return a; \ | 73 | return a; \ |
| 71 | } \ | 74 | } \ |
| 72 | constexpr type& operator&=(type& a, type b) noexcept { \ | 75 | constexpr type& operator&=(type& a, type b) noexcept { \ |
| 73 | using T = std::underlying_type_t<type>; \ | 76 | a = a & b; \ |
| 74 | a = static_cast<type>(static_cast<T>(a) & static_cast<T>(b)); \ | 77 | return a; \ |
| 78 | } \ | ||
| 79 | constexpr type& operator^=(type& a, type b) noexcept { \ | ||
| 80 | a = a ^ b; \ | ||
| 75 | return a; \ | 81 | return a; \ |
| 76 | } \ | 82 | } \ |
| 77 | [[nodiscard]] constexpr type operator~(type key) noexcept { \ | 83 | [[nodiscard]] constexpr type operator~(type key) noexcept { \ |
diff --git a/src/common/hex_util.h b/src/common/hex_util.h index 120f1a5e6..a8d414fb8 100644 --- a/src/common/hex_util.h +++ b/src/common/hex_util.h | |||
| @@ -16,14 +16,14 @@ namespace Common { | |||
| 16 | 16 | ||
| 17 | [[nodiscard]] constexpr u8 ToHexNibble(char c) { | 17 | [[nodiscard]] constexpr u8 ToHexNibble(char c) { |
| 18 | if (c >= 65 && c <= 70) { | 18 | if (c >= 65 && c <= 70) { |
| 19 | return c - 55; | 19 | return static_cast<u8>(c - 55); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | if (c >= 97 && c <= 102) { | 22 | if (c >= 97 && c <= 102) { |
| 23 | return c - 87; | 23 | return static_cast<u8>(c - 87); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | return c - 48; | 26 | return static_cast<u8>(c - 48); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | [[nodiscard]] std::vector<u8> HexStringToVector(std::string_view str, bool little_endian); | 29 | [[nodiscard]] std::vector<u8> HexStringToVector(std::string_view str, bool little_endian); |
| @@ -33,11 +33,11 @@ template <std::size_t Size, bool le = false> | |||
| 33 | std::array<u8, Size> out{}; | 33 | std::array<u8, Size> out{}; |
| 34 | if constexpr (le) { | 34 | if constexpr (le) { |
| 35 | for (std::size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) { | 35 | for (std::size_t i = 2 * Size - 2; i <= 2 * Size; i -= 2) { |
| 36 | out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); | 36 | out[i / 2] = static_cast<u8>((ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1])); |
| 37 | } | 37 | } |
| 38 | } else { | 38 | } else { |
| 39 | for (std::size_t i = 0; i < 2 * Size; i += 2) { | 39 | for (std::size_t i = 0; i < 2 * Size; i += 2) { |
| 40 | out[i / 2] = (ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1]); | 40 | out[i / 2] = static_cast<u8>((ToHexNibble(str[i]) << 4) | ToHexNibble(str[i + 1])); |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | return out; | 43 | return out; |
diff --git a/src/common/math_util.h b/src/common/math_util.h index cc35c90ee..7cec80d57 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | 9 | ||
| 10 | namespace Common { | 10 | namespace Common { |
| 11 | 11 | ||
| 12 | constexpr float PI = 3.14159265f; | 12 | constexpr float PI = 3.1415926535f; |
| 13 | 13 | ||
| 14 | template <class T> | 14 | template <class T> |
| 15 | struct Rectangle { | 15 | struct Rectangle { |
| @@ -20,8 +20,8 @@ struct Rectangle { | |||
| 20 | 20 | ||
| 21 | constexpr Rectangle() = default; | 21 | constexpr Rectangle() = default; |
| 22 | 22 | ||
| 23 | constexpr Rectangle(T left, T top, T right, T bottom) | 23 | constexpr Rectangle(T left_, T top_, T right_, T bottom_) |
| 24 | : left(left), top(top), right(right), bottom(bottom) {} | 24 | : left(left_), top(top_), right(right_), bottom(bottom_) {} |
| 25 | 25 | ||
| 26 | [[nodiscard]] T GetWidth() const { | 26 | [[nodiscard]] T GetWidth() const { |
| 27 | if constexpr (std::is_floating_point_v<T>) { | 27 | if constexpr (std::is_floating_point_v<T>) { |
diff --git a/src/common/param_package.h b/src/common/param_package.h index c8a70bfa9..c13e45479 100644 --- a/src/common/param_package.h +++ b/src/common/param_package.h | |||
| @@ -19,7 +19,7 @@ public: | |||
| 19 | explicit ParamPackage(const std::string& serialized); | 19 | explicit ParamPackage(const std::string& serialized); |
| 20 | ParamPackage(std::initializer_list<DataType::value_type> list); | 20 | ParamPackage(std::initializer_list<DataType::value_type> list); |
| 21 | ParamPackage(const ParamPackage& other) = default; | 21 | ParamPackage(const ParamPackage& other) = default; |
| 22 | ParamPackage(ParamPackage&& other) = default; | 22 | ParamPackage(ParamPackage&& other) noexcept = default; |
| 23 | 23 | ||
| 24 | ParamPackage& operator=(const ParamPackage& other) = default; | 24 | ParamPackage& operator=(const ParamPackage& other) = default; |
| 25 | ParamPackage& operator=(ParamPackage&& other) = default; | 25 | ParamPackage& operator=(ParamPackage&& other) = default; |
diff --git a/src/common/quaternion.h b/src/common/quaternion.h index da44f35cd..4d0871eb4 100644 --- a/src/common/quaternion.h +++ b/src/common/quaternion.h | |||
| @@ -36,6 +36,36 @@ public: | |||
| 36 | T length = std::sqrt(xyz.Length2() + w * w); | 36 | T length = std::sqrt(xyz.Length2() + w * w); |
| 37 | return {xyz / length, w / length}; | 37 | return {xyz / length, w / length}; |
| 38 | } | 38 | } |
| 39 | |||
| 40 | [[nodiscard]] std::array<decltype(-T{}), 16> ToMatrix() const { | ||
| 41 | const T x2 = xyz[0] * xyz[0]; | ||
| 42 | const T y2 = xyz[1] * xyz[1]; | ||
| 43 | const T z2 = xyz[2] * xyz[2]; | ||
| 44 | |||
| 45 | const T xy = xyz[0] * xyz[1]; | ||
| 46 | const T wz = w * xyz[2]; | ||
| 47 | const T xz = xyz[0] * xyz[2]; | ||
| 48 | const T wy = w * xyz[1]; | ||
| 49 | const T yz = xyz[1] * xyz[2]; | ||
| 50 | const T wx = w * xyz[0]; | ||
| 51 | |||
| 52 | return {1.0f - 2.0f * (y2 + z2), | ||
| 53 | 2.0f * (xy + wz), | ||
| 54 | 2.0f * (xz - wy), | ||
| 55 | 0.0f, | ||
| 56 | 2.0f * (xy - wz), | ||
| 57 | 1.0f - 2.0f * (x2 + z2), | ||
| 58 | 2.0f * (yz + wx), | ||
| 59 | 0.0f, | ||
| 60 | 2.0f * (xz + wy), | ||
| 61 | 2.0f * (yz - wx), | ||
| 62 | 1.0f - 2.0f * (x2 + y2), | ||
| 63 | 0.0f, | ||
| 64 | 0.0f, | ||
| 65 | 0.0f, | ||
| 66 | 0.0f, | ||
| 67 | 1.0f}; | ||
| 68 | } | ||
| 39 | }; | 69 | }; |
| 40 | 70 | ||
| 41 | template <typename T> | 71 | template <typename T> |
diff --git a/src/common/thread.cpp b/src/common/thread.cpp index 8e5935e6a..d2c1ac60d 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/common_funcs.h" | ||
| 6 | #include "common/logging/log.h" | ||
| 5 | #include "common/thread.h" | 7 | #include "common/thread.h" |
| 6 | #ifdef __APPLE__ | 8 | #ifdef __APPLE__ |
| 7 | #include <mach/mach.h> | 9 | #include <mach/mach.h> |
| @@ -19,6 +21,8 @@ | |||
| 19 | #include <unistd.h> | 21 | #include <unistd.h> |
| 20 | #endif | 22 | #endif |
| 21 | 23 | ||
| 24 | #include <string> | ||
| 25 | |||
| 22 | #ifdef __FreeBSD__ | 26 | #ifdef __FreeBSD__ |
| 23 | #define cpu_set_t cpuset_t | 27 | #define cpu_set_t cpuset_t |
| 24 | #endif | 28 | #endif |
| @@ -110,6 +114,14 @@ void SetCurrentThreadName(const char* name) { | |||
| 110 | pthread_set_name_np(pthread_self(), name); | 114 | pthread_set_name_np(pthread_self(), name); |
| 111 | #elif defined(__NetBSD__) | 115 | #elif defined(__NetBSD__) |
| 112 | pthread_setname_np(pthread_self(), "%s", (void*)name); | 116 | pthread_setname_np(pthread_self(), "%s", (void*)name); |
| 117 | #elif defined(__linux__) | ||
| 118 | // Linux limits thread names to 15 characters and will outright reject any | ||
| 119 | // attempt to set a longer name with ERANGE. | ||
| 120 | std::string truncated(name, std::min(strlen(name), static_cast<size_t>(15))); | ||
| 121 | if (int e = pthread_setname_np(pthread_self(), truncated.c_str())) { | ||
| 122 | errno = e; | ||
| 123 | LOG_ERROR(Common, "Failed to set thread name to '{}': {}", truncated, GetLastErrorMsg()); | ||
| 124 | } | ||
| 113 | #else | 125 | #else |
| 114 | pthread_setname_np(pthread_self(), name); | 126 | pthread_setname_np(pthread_self(), name); |
| 115 | #endif | 127 | #endif |
diff --git a/src/common/thread.h b/src/common/thread.h index 52b359413..a8c17c71a 100644 --- a/src/common/thread.h +++ b/src/common/thread.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <atomic> | ||
| 7 | #include <chrono> | 8 | #include <chrono> |
| 8 | #include <condition_variable> | 9 | #include <condition_variable> |
| 9 | #include <cstddef> | 10 | #include <cstddef> |
| @@ -25,13 +26,13 @@ public: | |||
| 25 | 26 | ||
| 26 | void Wait() { | 27 | void Wait() { |
| 27 | std::unique_lock lk{mutex}; | 28 | std::unique_lock lk{mutex}; |
| 28 | condvar.wait(lk, [&] { return is_set; }); | 29 | condvar.wait(lk, [&] { return is_set.load(); }); |
| 29 | is_set = false; | 30 | is_set = false; |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | bool WaitFor(const std::chrono::nanoseconds& time) { | 33 | bool WaitFor(const std::chrono::nanoseconds& time) { |
| 33 | std::unique_lock lk{mutex}; | 34 | std::unique_lock lk{mutex}; |
| 34 | if (!condvar.wait_for(lk, time, [this] { return is_set; })) | 35 | if (!condvar.wait_for(lk, time, [this] { return is_set.load(); })) |
| 35 | return false; | 36 | return false; |
| 36 | is_set = false; | 37 | is_set = false; |
| 37 | return true; | 38 | return true; |
| @@ -40,7 +41,7 @@ public: | |||
| 40 | template <class Clock, class Duration> | 41 | template <class Clock, class Duration> |
| 41 | bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) { | 42 | bool WaitUntil(const std::chrono::time_point<Clock, Duration>& time) { |
| 42 | std::unique_lock lk{mutex}; | 43 | std::unique_lock lk{mutex}; |
| 43 | if (!condvar.wait_until(lk, time, [this] { return is_set; })) | 44 | if (!condvar.wait_until(lk, time, [this] { return is_set.load(); })) |
| 44 | return false; | 45 | return false; |
| 45 | is_set = false; | 46 | is_set = false; |
| 46 | return true; | 47 | return true; |
| @@ -54,9 +55,9 @@ public: | |||
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | private: | 57 | private: |
| 57 | bool is_set = false; | ||
| 58 | std::condition_variable condvar; | 58 | std::condition_variable condvar; |
| 59 | std::mutex mutex; | 59 | std::mutex mutex; |
| 60 | std::atomic_bool is_set{false}; | ||
| 60 | }; | 61 | }; |
| 61 | 62 | ||
| 62 | class Barrier { | 63 | class Barrier { |
diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 2a0fcf541..22dba3c2d 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h | |||
| @@ -87,7 +87,13 @@ public: | |||
| 87 | 87 | ||
| 88 | template <typename V> | 88 | template <typename V> |
| 89 | [[nodiscard]] constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const { | 89 | [[nodiscard]] constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const { |
| 90 | return {x * f, y * f}; | 90 | using TV = decltype(T{} * V{}); |
| 91 | using C = std::common_type_t<T, V>; | ||
| 92 | |||
| 93 | return { | ||
| 94 | static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)), | ||
| 95 | static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)), | ||
| 96 | }; | ||
| 91 | } | 97 | } |
| 92 | 98 | ||
| 93 | template <typename V> | 99 | template <typename V> |
| @@ -98,7 +104,13 @@ public: | |||
| 98 | 104 | ||
| 99 | template <typename V> | 105 | template <typename V> |
| 100 | [[nodiscard]] constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const { | 106 | [[nodiscard]] constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const { |
| 101 | return {x / f, y / f}; | 107 | using TV = decltype(T{} / V{}); |
| 108 | using C = std::common_type_t<T, V>; | ||
| 109 | |||
| 110 | return { | ||
| 111 | static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)), | ||
| 112 | static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)), | ||
| 113 | }; | ||
| 102 | } | 114 | } |
| 103 | 115 | ||
| 104 | template <typename V> | 116 | template <typename V> |
| @@ -168,7 +180,10 @@ public: | |||
| 168 | 180 | ||
| 169 | template <typename T, typename V> | 181 | template <typename T, typename V> |
| 170 | [[nodiscard]] constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) { | 182 | [[nodiscard]] constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) { |
| 171 | return Vec2<T>(f * vec.x, f * vec.y); | 183 | using C = std::common_type_t<T, V>; |
| 184 | |||
| 185 | return Vec2<T>(static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.x)), | ||
| 186 | static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.y))); | ||
| 172 | } | 187 | } |
| 173 | 188 | ||
| 174 | using Vec2f = Vec2<float>; | 189 | using Vec2f = Vec2<float>; |
| @@ -237,7 +252,14 @@ public: | |||
| 237 | 252 | ||
| 238 | template <typename V> | 253 | template <typename V> |
| 239 | [[nodiscard]] constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const { | 254 | [[nodiscard]] constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const { |
| 240 | return {x * f, y * f, z * f}; | 255 | using TV = decltype(T{} * V{}); |
| 256 | using C = std::common_type_t<T, V>; | ||
| 257 | |||
| 258 | return { | ||
| 259 | static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)), | ||
| 260 | static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)), | ||
| 261 | static_cast<TV>(static_cast<C>(z) * static_cast<C>(f)), | ||
| 262 | }; | ||
| 241 | } | 263 | } |
| 242 | 264 | ||
| 243 | template <typename V> | 265 | template <typename V> |
| @@ -247,7 +269,14 @@ public: | |||
| 247 | } | 269 | } |
| 248 | template <typename V> | 270 | template <typename V> |
| 249 | [[nodiscard]] constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const { | 271 | [[nodiscard]] constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const { |
| 250 | return {x / f, y / f, z / f}; | 272 | using TV = decltype(T{} / V{}); |
| 273 | using C = std::common_type_t<T, V>; | ||
| 274 | |||
| 275 | return { | ||
| 276 | static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)), | ||
| 277 | static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)), | ||
| 278 | static_cast<TV>(static_cast<C>(z) / static_cast<C>(f)), | ||
| 279 | }; | ||
| 251 | } | 280 | } |
| 252 | 281 | ||
| 253 | template <typename V> | 282 | template <typename V> |
| @@ -367,7 +396,11 @@ public: | |||
| 367 | 396 | ||
| 368 | template <typename T, typename V> | 397 | template <typename T, typename V> |
| 369 | [[nodiscard]] constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) { | 398 | [[nodiscard]] constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) { |
| 370 | return Vec3<T>(f * vec.x, f * vec.y, f * vec.z); | 399 | using C = std::common_type_t<T, V>; |
| 400 | |||
| 401 | return Vec3<T>(static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.x)), | ||
| 402 | static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.y)), | ||
| 403 | static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.z))); | ||
| 371 | } | 404 | } |
| 372 | 405 | ||
| 373 | template <> | 406 | template <> |
| @@ -446,7 +479,15 @@ public: | |||
| 446 | 479 | ||
| 447 | template <typename V> | 480 | template <typename V> |
| 448 | [[nodiscard]] constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const { | 481 | [[nodiscard]] constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const { |
| 449 | return {x * f, y * f, z * f, w * f}; | 482 | using TV = decltype(T{} * V{}); |
| 483 | using C = std::common_type_t<T, V>; | ||
| 484 | |||
| 485 | return { | ||
| 486 | static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)), | ||
| 487 | static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)), | ||
| 488 | static_cast<TV>(static_cast<C>(z) * static_cast<C>(f)), | ||
| 489 | static_cast<TV>(static_cast<C>(w) * static_cast<C>(f)), | ||
| 490 | }; | ||
| 450 | } | 491 | } |
| 451 | 492 | ||
| 452 | template <typename V> | 493 | template <typename V> |
| @@ -457,7 +498,15 @@ public: | |||
| 457 | 498 | ||
| 458 | template <typename V> | 499 | template <typename V> |
| 459 | [[nodiscard]] constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const { | 500 | [[nodiscard]] constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const { |
| 460 | return {x / f, y / f, z / f, w / f}; | 501 | using TV = decltype(T{} / V{}); |
| 502 | using C = std::common_type_t<T, V>; | ||
| 503 | |||
| 504 | return { | ||
| 505 | static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)), | ||
| 506 | static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)), | ||
| 507 | static_cast<TV>(static_cast<C>(z) / static_cast<C>(f)), | ||
| 508 | static_cast<TV>(static_cast<C>(w) / static_cast<C>(f)), | ||
| 509 | }; | ||
| 461 | } | 510 | } |
| 462 | 511 | ||
| 463 | template <typename V> | 512 | template <typename V> |
| @@ -582,7 +631,15 @@ public: | |||
| 582 | 631 | ||
| 583 | template <typename T, typename V> | 632 | template <typename T, typename V> |
| 584 | [[nodiscard]] constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) { | 633 | [[nodiscard]] constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) { |
| 585 | return {f * vec.x, f * vec.y, f * vec.z, f * vec.w}; | 634 | using TV = decltype(V{} * T{}); |
| 635 | using C = std::common_type_t<T, V>; | ||
| 636 | |||
| 637 | return { | ||
| 638 | static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.x)), | ||
| 639 | static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.y)), | ||
| 640 | static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.z)), | ||
| 641 | static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.w)), | ||
| 642 | }; | ||
| 586 | } | 643 | } |
| 587 | 644 | ||
| 588 | using Vec4f = Vec4<float>; | 645 | using Vec4f = Vec4<float>; |
diff --git a/src/common/wall_clock.cpp b/src/common/wall_clock.cpp index 3afbdb898..7a20e95b7 100644 --- a/src/common/wall_clock.cpp +++ b/src/common/wall_clock.cpp | |||
| @@ -15,7 +15,7 @@ namespace Common { | |||
| 15 | using base_timer = std::chrono::steady_clock; | 15 | using base_timer = std::chrono::steady_clock; |
| 16 | using base_time_point = std::chrono::time_point<base_timer>; | 16 | using base_time_point = std::chrono::time_point<base_timer>; |
| 17 | 17 | ||
| 18 | class StandardWallClock : public WallClock { | 18 | class StandardWallClock final : public WallClock { |
| 19 | public: | 19 | public: |
| 20 | StandardWallClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency) | 20 | StandardWallClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency) |
| 21 | : WallClock(emulated_cpu_frequency, emulated_clock_frequency, false) { | 21 | : WallClock(emulated_cpu_frequency, emulated_clock_frequency, false) { |
diff --git a/src/common/wall_clock.h b/src/common/wall_clock.h index 5db30083d..bc7adfbf8 100644 --- a/src/common/wall_clock.h +++ b/src/common/wall_clock.h | |||
| @@ -13,6 +13,8 @@ namespace Common { | |||
| 13 | 13 | ||
| 14 | class WallClock { | 14 | class WallClock { |
| 15 | public: | 15 | public: |
| 16 | virtual ~WallClock() = default; | ||
| 17 | |||
| 16 | /// Returns current wall time in nanoseconds | 18 | /// Returns current wall time in nanoseconds |
| 17 | [[nodiscard]] virtual std::chrono::nanoseconds GetTimeNS() = 0; | 19 | [[nodiscard]] virtual std::chrono::nanoseconds GetTimeNS() = 0; |
| 18 | 20 | ||
diff --git a/src/common/web_result.h b/src/common/web_result.h deleted file mode 100644 index 8bfa2141d..000000000 --- a/src/common/web_result.h +++ /dev/null | |||
| @@ -1,25 +0,0 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <string> | ||
| 8 | #include "common/common_types.h" | ||
| 9 | |||
| 10 | namespace Common { | ||
| 11 | struct WebResult { | ||
| 12 | enum class Code : u32 { | ||
| 13 | Success, | ||
| 14 | InvalidURL, | ||
| 15 | CredentialsMissing, | ||
| 16 | LibError, | ||
| 17 | HttpError, | ||
| 18 | WrongContent, | ||
| 19 | NoWebservice, | ||
| 20 | }; | ||
| 21 | Code result_code; | ||
| 22 | std::string result_string; | ||
| 23 | std::string returned_data; | ||
| 24 | }; | ||
| 25 | } // namespace Common | ||
diff --git a/src/common/x64/native_clock.h b/src/common/x64/native_clock.h index 891a3bbfd..7c503df26 100644 --- a/src/common/x64/native_clock.h +++ b/src/common/x64/native_clock.h | |||
| @@ -12,7 +12,7 @@ | |||
| 12 | namespace Common { | 12 | namespace Common { |
| 13 | 13 | ||
| 14 | namespace X64 { | 14 | namespace X64 { |
| 15 | class NativeClock : public WallClock { | 15 | class NativeClock final : public WallClock { |
| 16 | public: | 16 | public: |
| 17 | NativeClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency, u64 rtsc_frequency); | 17 | NativeClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency, u64 rtsc_frequency); |
| 18 | 18 | ||
diff --git a/src/common/x64/xbyak_abi.h b/src/common/x64/xbyak_abi.h index a5f5d4fc1..26e4bfda5 100644 --- a/src/common/x64/xbyak_abi.h +++ b/src/common/x64/xbyak_abi.h | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | namespace Common::X64 { | 12 | namespace Common::X64 { |
| 13 | 13 | ||
| 14 | inline std::size_t RegToIndex(const Xbyak::Reg& reg) { | 14 | constexpr std::size_t RegToIndex(const Xbyak::Reg& reg) { |
| 15 | using Kind = Xbyak::Reg::Kind; | 15 | using Kind = Xbyak::Reg::Kind; |
| 16 | ASSERT_MSG((reg.getKind() & (Kind::REG | Kind::XMM)) != 0, | 16 | ASSERT_MSG((reg.getKind() & (Kind::REG | Kind::XMM)) != 0, |
| 17 | "RegSet only support GPRs and XMM registers."); | 17 | "RegSet only support GPRs and XMM registers."); |
| @@ -19,17 +19,17 @@ inline std::size_t RegToIndex(const Xbyak::Reg& reg) { | |||
| 19 | return reg.getIdx() + (reg.getKind() == Kind::REG ? 0 : 16); | 19 | return reg.getIdx() + (reg.getKind() == Kind::REG ? 0 : 16); |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | inline Xbyak::Reg64 IndexToReg64(std::size_t reg_index) { | 22 | constexpr Xbyak::Reg64 IndexToReg64(std::size_t reg_index) { |
| 23 | ASSERT(reg_index < 16); | 23 | ASSERT(reg_index < 16); |
| 24 | return Xbyak::Reg64(static_cast<int>(reg_index)); | 24 | return Xbyak::Reg64(static_cast<int>(reg_index)); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | inline Xbyak::Xmm IndexToXmm(std::size_t reg_index) { | 27 | constexpr Xbyak::Xmm IndexToXmm(std::size_t reg_index) { |
| 28 | ASSERT(reg_index >= 16 && reg_index < 32); | 28 | ASSERT(reg_index >= 16 && reg_index < 32); |
| 29 | return Xbyak::Xmm(static_cast<int>(reg_index - 16)); | 29 | return Xbyak::Xmm(static_cast<int>(reg_index - 16)); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | inline Xbyak::Reg IndexToReg(std::size_t reg_index) { | 32 | constexpr Xbyak::Reg IndexToReg(std::size_t reg_index) { |
| 33 | if (reg_index < 16) { | 33 | if (reg_index < 16) { |
| 34 | return IndexToReg64(reg_index); | 34 | return IndexToReg64(reg_index); |
| 35 | } else { | 35 | } else { |
| @@ -45,17 +45,17 @@ inline std::bitset<32> BuildRegSet(std::initializer_list<Xbyak::Reg> regs) { | |||
| 45 | return bits; | 45 | return bits; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | const std::bitset<32> ABI_ALL_GPRS(0x0000FFFF); | 48 | constexpr inline std::bitset<32> ABI_ALL_GPRS(0x0000FFFF); |
| 49 | const std::bitset<32> ABI_ALL_XMMS(0xFFFF0000); | 49 | constexpr inline std::bitset<32> ABI_ALL_XMMS(0xFFFF0000); |
| 50 | 50 | ||
| 51 | #ifdef _WIN32 | 51 | #ifdef _WIN32 |
| 52 | 52 | ||
| 53 | // Microsoft x64 ABI | 53 | // Microsoft x64 ABI |
| 54 | const Xbyak::Reg ABI_RETURN = Xbyak::util::rax; | 54 | constexpr inline Xbyak::Reg ABI_RETURN = Xbyak::util::rax; |
| 55 | const Xbyak::Reg ABI_PARAM1 = Xbyak::util::rcx; | 55 | constexpr inline Xbyak::Reg ABI_PARAM1 = Xbyak::util::rcx; |
| 56 | const Xbyak::Reg ABI_PARAM2 = Xbyak::util::rdx; | 56 | constexpr inline Xbyak::Reg ABI_PARAM2 = Xbyak::util::rdx; |
| 57 | const Xbyak::Reg ABI_PARAM3 = Xbyak::util::r8; | 57 | constexpr inline Xbyak::Reg ABI_PARAM3 = Xbyak::util::r8; |
| 58 | const Xbyak::Reg ABI_PARAM4 = Xbyak::util::r9; | 58 | constexpr inline Xbyak::Reg ABI_PARAM4 = Xbyak::util::r9; |
| 59 | 59 | ||
| 60 | const std::bitset<32> ABI_ALL_CALLER_SAVED = BuildRegSet({ | 60 | const std::bitset<32> ABI_ALL_CALLER_SAVED = BuildRegSet({ |
| 61 | // GPRs | 61 | // GPRs |
| @@ -102,11 +102,11 @@ constexpr size_t ABI_SHADOW_SPACE = 0x20; | |||
| 102 | #else | 102 | #else |
| 103 | 103 | ||
| 104 | // System V x86-64 ABI | 104 | // System V x86-64 ABI |
| 105 | const Xbyak::Reg ABI_RETURN = Xbyak::util::rax; | 105 | constexpr inline Xbyak::Reg ABI_RETURN = Xbyak::util::rax; |
| 106 | const Xbyak::Reg ABI_PARAM1 = Xbyak::util::rdi; | 106 | constexpr inline Xbyak::Reg ABI_PARAM1 = Xbyak::util::rdi; |
| 107 | const Xbyak::Reg ABI_PARAM2 = Xbyak::util::rsi; | 107 | constexpr inline Xbyak::Reg ABI_PARAM2 = Xbyak::util::rsi; |
| 108 | const Xbyak::Reg ABI_PARAM3 = Xbyak::util::rdx; | 108 | constexpr inline Xbyak::Reg ABI_PARAM3 = Xbyak::util::rdx; |
| 109 | const Xbyak::Reg ABI_PARAM4 = Xbyak::util::rcx; | 109 | constexpr inline Xbyak::Reg ABI_PARAM4 = Xbyak::util::rcx; |
| 110 | 110 | ||
| 111 | const std::bitset<32> ABI_ALL_CALLER_SAVED = BuildRegSet({ | 111 | const std::bitset<32> ABI_ALL_CALLER_SAVED = BuildRegSet({ |
| 112 | // GPRs | 112 | // GPRs |