summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/alignment.h21
-rw-r--r--src/common/div_ceil.h8
-rw-r--r--src/common/fs/fs_paths.h1
-rw-r--r--src/common/fs/path_util.cpp1
-rw-r--r--src/common/fs/path_util.h1
-rw-r--r--src/common/intrusive_red_black_tree.h17
-rw-r--r--src/common/settings.cpp2
-rw-r--r--src/common/settings.h6
-rw-r--r--src/common/threadsafe_queue.h27
-rw-r--r--src/common/uuid.h7
-rw-r--r--src/common/vector_math.h4
11 files changed, 65 insertions, 30 deletions
diff --git a/src/common/alignment.h b/src/common/alignment.h
index 32d796ffa..1b56569d1 100644
--- a/src/common/alignment.h
+++ b/src/common/alignment.h
@@ -9,41 +9,48 @@
9namespace Common { 9namespace Common {
10 10
11template <typename T> 11template <typename T>
12requires std::is_unsigned_v<T>[[nodiscard]] constexpr T AlignUp(T value, size_t size) { 12requires std::is_unsigned_v<T>
13[[nodiscard]] constexpr T AlignUp(T value, size_t size) {
13 auto mod{static_cast<T>(value % size)}; 14 auto mod{static_cast<T>(value % size)};
14 value -= mod; 15 value -= mod;
15 return static_cast<T>(mod == T{0} ? value : value + size); 16 return static_cast<T>(mod == T{0} ? value : value + size);
16} 17}
17 18
18template <typename T> 19template <typename T>
19requires std::is_unsigned_v<T>[[nodiscard]] constexpr T AlignUpLog2(T value, size_t align_log2) { 20requires std::is_unsigned_v<T>
21[[nodiscard]] constexpr T AlignUpLog2(T value, size_t align_log2) {
20 return static_cast<T>((value + ((1ULL << align_log2) - 1)) >> align_log2 << align_log2); 22 return static_cast<T>((value + ((1ULL << align_log2) - 1)) >> align_log2 << align_log2);
21} 23}
22 24
23template <typename T> 25template <typename T>
24requires std::is_unsigned_v<T>[[nodiscard]] constexpr T AlignDown(T value, size_t size) { 26requires std::is_unsigned_v<T>
27[[nodiscard]] constexpr T AlignDown(T value, size_t size) {
25 return static_cast<T>(value - value % size); 28 return static_cast<T>(value - value % size);
26} 29}
27 30
28template <typename T> 31template <typename T>
29requires std::is_unsigned_v<T>[[nodiscard]] constexpr bool Is4KBAligned(T value) { 32requires std::is_unsigned_v<T>
33[[nodiscard]] constexpr bool Is4KBAligned(T value) {
30 return (value & 0xFFF) == 0; 34 return (value & 0xFFF) == 0;
31} 35}
32 36
33template <typename T> 37template <typename T>
34requires std::is_unsigned_v<T>[[nodiscard]] constexpr bool IsWordAligned(T value) { 38requires std::is_unsigned_v<T>
39[[nodiscard]] constexpr bool IsWordAligned(T value) {
35 return (value & 0b11) == 0; 40 return (value & 0b11) == 0;
36} 41}
37 42
38template <typename T> 43template <typename T>
39requires std::is_integral_v<T>[[nodiscard]] constexpr bool IsAligned(T value, size_t alignment) { 44requires std::is_integral_v<T>
45[[nodiscard]] constexpr bool IsAligned(T value, size_t alignment) {
40 using U = typename std::make_unsigned_t<T>; 46 using U = typename std::make_unsigned_t<T>;
41 const U mask = static_cast<U>(alignment - 1); 47 const U mask = static_cast<U>(alignment - 1);
42 return (value & mask) == 0; 48 return (value & mask) == 0;
43} 49}
44 50
45template <typename T, typename U> 51template <typename T, typename U>
46requires std::is_integral_v<T>[[nodiscard]] constexpr T DivideUp(T x, U y) { 52requires std::is_integral_v<T>
53[[nodiscard]] constexpr T DivideUp(T x, U y) {
47 return (x + (y - 1)) / y; 54 return (x + (y - 1)) / y;
48} 55}
49 56
diff --git a/src/common/div_ceil.h b/src/common/div_ceil.h
index 95e1489a9..e1db35464 100644
--- a/src/common/div_ceil.h
+++ b/src/common/div_ceil.h
@@ -11,15 +11,15 @@ namespace Common {
11 11
12/// Ceiled integer division. 12/// Ceiled integer division.
13template <typename N, typename D> 13template <typename N, typename D>
14requires std::is_integral_v<N>&& std::is_unsigned_v<D>[[nodiscard]] constexpr N DivCeil(N number, 14requires std::is_integral_v<N> && std::is_unsigned_v<D>
15 D divisor) { 15[[nodiscard]] constexpr N DivCeil(N number, D divisor) {
16 return static_cast<N>((static_cast<D>(number) + divisor - 1) / divisor); 16 return static_cast<N>((static_cast<D>(number) + divisor - 1) / divisor);
17} 17}
18 18
19/// Ceiled integer division with logarithmic divisor in base 2 19/// Ceiled integer division with logarithmic divisor in base 2
20template <typename N, typename D> 20template <typename N, typename D>
21requires std::is_integral_v<N>&& std::is_unsigned_v<D>[[nodiscard]] constexpr N DivCeilLog2( 21requires std::is_integral_v<N> && std::is_unsigned_v<D>
22 N value, D alignment_log2) { 22[[nodiscard]] constexpr N DivCeilLog2(N value, D alignment_log2) {
23 return static_cast<N>((static_cast<D>(value) + (D(1) << alignment_log2) - 1) >> alignment_log2); 23 return static_cast<N>((static_cast<D>(value) + (D(1) << alignment_log2) - 1) >> alignment_log2);
24} 24}
25 25
diff --git a/src/common/fs/fs_paths.h b/src/common/fs/fs_paths.h
index b32614797..5d447f108 100644
--- a/src/common/fs/fs_paths.h
+++ b/src/common/fs/fs_paths.h
@@ -21,6 +21,7 @@
21#define SCREENSHOTS_DIR "screenshots" 21#define SCREENSHOTS_DIR "screenshots"
22#define SDMC_DIR "sdmc" 22#define SDMC_DIR "sdmc"
23#define SHADER_DIR "shader" 23#define SHADER_DIR "shader"
24#define TAS_DIR "tas"
24 25
25// yuzu-specific files 26// yuzu-specific files
26 27
diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp
index 6cdd14f13..43b79bd6d 100644
--- a/src/common/fs/path_util.cpp
+++ b/src/common/fs/path_util.cpp
@@ -116,6 +116,7 @@ private:
116 GenerateYuzuPath(YuzuPath::ScreenshotsDir, yuzu_path / SCREENSHOTS_DIR); 116 GenerateYuzuPath(YuzuPath::ScreenshotsDir, yuzu_path / SCREENSHOTS_DIR);
117 GenerateYuzuPath(YuzuPath::SDMCDir, yuzu_path / SDMC_DIR); 117 GenerateYuzuPath(YuzuPath::SDMCDir, yuzu_path / SDMC_DIR);
118 GenerateYuzuPath(YuzuPath::ShaderDir, yuzu_path / SHADER_DIR); 118 GenerateYuzuPath(YuzuPath::ShaderDir, yuzu_path / SHADER_DIR);
119 GenerateYuzuPath(YuzuPath::TASDir, yuzu_path / TAS_DIR);
119 } 120 }
120 121
121 ~PathManagerImpl() = default; 122 ~PathManagerImpl() = default;
diff --git a/src/common/fs/path_util.h b/src/common/fs/path_util.h
index f956ac9a2..0a9e3a145 100644
--- a/src/common/fs/path_util.h
+++ b/src/common/fs/path_util.h
@@ -23,6 +23,7 @@ enum class YuzuPath {
23 ScreenshotsDir, // Where yuzu screenshots are stored. 23 ScreenshotsDir, // Where yuzu screenshots are stored.
24 SDMCDir, // Where the emulated SDMC is stored. 24 SDMCDir, // Where the emulated SDMC is stored.
25 ShaderDir, // Where shaders are stored. 25 ShaderDir, // Where shaders are stored.
26 TASDir, // Where TAS scripts are stored.
26}; 27};
27 28
28/** 29/**
diff --git a/src/common/intrusive_red_black_tree.h b/src/common/intrusive_red_black_tree.h
index 1f696fe80..3173cc449 100644
--- a/src/common/intrusive_red_black_tree.h
+++ b/src/common/intrusive_red_black_tree.h
@@ -235,20 +235,19 @@ public:
235 235
236template <typename T> 236template <typename T>
237concept HasLightCompareType = requires { 237concept HasLightCompareType = requires {
238 { std::is_same<typename T::LightCompareType, void>::value } 238 { std::is_same<typename T::LightCompareType, void>::value } -> std::convertible_to<bool>;
239 ->std::convertible_to<bool>;
240}; 239};
241 240
242namespace impl { 241namespace impl {
243 242
244template <typename T, typename Default> 243 template <typename T, typename Default>
245consteval auto* GetLightCompareType() { 244 consteval auto* GetLightCompareType() {
246 if constexpr (HasLightCompareType<T>) { 245 if constexpr (HasLightCompareType<T>) {
247 return static_cast<typename T::LightCompareType*>(nullptr); 246 return static_cast<typename T::LightCompareType*>(nullptr);
248 } else { 247 } else {
249 return static_cast<Default*>(nullptr); 248 return static_cast<Default*>(nullptr);
249 }
250 } 250 }
251}
252 251
253} // namespace impl 252} // namespace impl
254 253
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index e1fa90c5a..69f0bd8c0 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -61,7 +61,6 @@ void LogSettings() {
61 log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue()); 61 log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue());
62 log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue()); 62 log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue());
63 log_setting("Audio_OutputEngine", values.sink_id.GetValue()); 63 log_setting("Audio_OutputEngine", values.sink_id.GetValue());
64 log_setting("Audio_EnableAudioStretching", values.enable_audio_stretching.GetValue());
65 log_setting("Audio_OutputDevice", values.audio_device_id.GetValue()); 64 log_setting("Audio_OutputDevice", values.audio_device_id.GetValue());
66 log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd.GetValue()); 65 log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd.GetValue());
67 log_path("DataStorage_CacheDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir)); 66 log_path("DataStorage_CacheDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir));
@@ -115,7 +114,6 @@ void RestoreGlobalState(bool is_powered_on) {
115 } 114 }
116 115
117 // Audio 116 // Audio
118 values.enable_audio_stretching.SetGlobal(true);
119 values.volume.SetGlobal(true); 117 values.volume.SetGlobal(true);
120 118
121 // Core 119 // Core
diff --git a/src/common/settings.h b/src/common/settings.h
index e674ccc5c..c53d5acc3 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -414,7 +414,6 @@ struct Values {
414 BasicSetting<std::string> audio_device_id{"auto", "output_device"}; 414 BasicSetting<std::string> audio_device_id{"auto", "output_device"};
415 BasicSetting<std::string> sink_id{"auto", "output_engine"}; 415 BasicSetting<std::string> sink_id{"auto", "output_engine"};
416 BasicSetting<bool> audio_muted{false, "audio_muted"}; 416 BasicSetting<bool> audio_muted{false, "audio_muted"};
417 Setting<bool> enable_audio_stretching{true, "enable_audio_stretching"};
418 RangedSetting<u8> volume{100, 0, 100, "volume"}; 417 RangedSetting<u8> volume{100, 0, 100, "volume"};
419 418
420 // Core 419 // Core
@@ -513,6 +512,11 @@ struct Values {
513 "motion_device"}; 512 "motion_device"};
514 BasicSetting<std::string> udp_input_servers{"127.0.0.1:26760", "udp_input_servers"}; 513 BasicSetting<std::string> udp_input_servers{"127.0.0.1:26760", "udp_input_servers"};
515 514
515 BasicSetting<bool> pause_tas_on_load{true, "pause_tas_on_load"};
516 BasicSetting<bool> tas_enable{false, "tas_enable"};
517 BasicSetting<bool> tas_loop{false, "tas_loop"};
518 BasicSetting<bool> tas_swap_controllers{true, "tas_swap_controllers"};
519
516 BasicSetting<bool> mouse_panning{false, "mouse_panning"}; 520 BasicSetting<bool> mouse_panning{false, "mouse_panning"};
517 BasicRangedSetting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"}; 521 BasicRangedSetting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"};
518 BasicSetting<bool> mouse_enabled{false, "mouse_enabled"}; 522 BasicSetting<bool> mouse_enabled{false, "mouse_enabled"};
diff --git a/src/common/threadsafe_queue.h b/src/common/threadsafe_queue.h
index 8430b9778..2c8c2b90e 100644
--- a/src/common/threadsafe_queue.h
+++ b/src/common/threadsafe_queue.h
@@ -14,7 +14,7 @@
14#include <utility> 14#include <utility>
15 15
16namespace Common { 16namespace Common {
17template <typename T> 17template <typename T, bool with_stop_token = false>
18class SPSCQueue { 18class SPSCQueue {
19public: 19public:
20 SPSCQueue() { 20 SPSCQueue() {
@@ -84,7 +84,7 @@ public:
84 void Wait() { 84 void Wait() {
85 if (Empty()) { 85 if (Empty()) {
86 std::unique_lock lock{cv_mutex}; 86 std::unique_lock lock{cv_mutex};
87 cv.wait(lock, [this]() { return !Empty(); }); 87 cv.wait(lock, [this] { return !Empty(); });
88 } 88 }
89 } 89 }
90 90
@@ -95,6 +95,19 @@ public:
95 return t; 95 return t;
96 } 96 }
97 97
98 T PopWait(std::stop_token stop_token) {
99 if (Empty()) {
100 std::unique_lock lock{cv_mutex};
101 cv.wait(lock, stop_token, [this] { return !Empty(); });
102 }
103 if (stop_token.stop_requested()) {
104 return T{};
105 }
106 T t;
107 Pop(t);
108 return t;
109 }
110
98 // not thread-safe 111 // not thread-safe
99 void Clear() { 112 void Clear() {
100 size.store(0); 113 size.store(0);
@@ -123,13 +136,13 @@ private:
123 ElementPtr* read_ptr; 136 ElementPtr* read_ptr;
124 std::atomic_size_t size{0}; 137 std::atomic_size_t size{0};
125 std::mutex cv_mutex; 138 std::mutex cv_mutex;
126 std::condition_variable cv; 139 std::conditional_t<with_stop_token, std::condition_variable_any, std::condition_variable> cv;
127}; 140};
128 141
129// a simple thread-safe, 142// a simple thread-safe,
130// single reader, multiple writer queue 143// single reader, multiple writer queue
131 144
132template <typename T> 145template <typename T, bool with_stop_token = false>
133class MPSCQueue { 146class MPSCQueue {
134public: 147public:
135 [[nodiscard]] std::size_t Size() const { 148 [[nodiscard]] std::size_t Size() const {
@@ -166,13 +179,17 @@ public:
166 return spsc_queue.PopWait(); 179 return spsc_queue.PopWait();
167 } 180 }
168 181
182 T PopWait(std::stop_token stop_token) {
183 return spsc_queue.PopWait(stop_token);
184 }
185
169 // not thread-safe 186 // not thread-safe
170 void Clear() { 187 void Clear() {
171 spsc_queue.Clear(); 188 spsc_queue.Clear();
172 } 189 }
173 190
174private: 191private:
175 SPSCQueue<T> spsc_queue; 192 SPSCQueue<T, with_stop_token> spsc_queue;
176 std::mutex write_lock; 193 std::mutex write_lock;
177}; 194};
178} // namespace Common 195} // namespace Common
diff --git a/src/common/uuid.h b/src/common/uuid.h
index 2353179d8..8ea01f8da 100644
--- a/src/common/uuid.h
+++ b/src/common/uuid.h
@@ -58,6 +58,13 @@ struct UUID {
58 uuid = INVALID_UUID; 58 uuid = INVALID_UUID;
59 } 59 }
60 60
61 [[nodiscard]] constexpr bool IsInvalid() const {
62 return uuid == INVALID_UUID;
63 }
64 [[nodiscard]] constexpr bool IsValid() const {
65 return !IsInvalid();
66 }
67
61 // TODO(ogniK): Properly generate a Nintendo ID 68 // TODO(ogniK): Properly generate a Nintendo ID
62 [[nodiscard]] constexpr u64 GetNintendoID() const { 69 [[nodiscard]] constexpr u64 GetNintendoID() const {
63 return uuid[0]; 70 return uuid[0];
diff --git a/src/common/vector_math.h b/src/common/vector_math.h
index 22dba3c2d..ba7c363c1 100644
--- a/src/common/vector_math.h
+++ b/src/common/vector_math.h
@@ -667,8 +667,8 @@ template <typename T>
667 667
668// linear interpolation via float: 0.0=begin, 1.0=end 668// linear interpolation via float: 0.0=begin, 1.0=end
669template <typename X> 669template <typename X>
670[[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end, 670[[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{})
671 const float t) { 671 Lerp(const X& begin, const X& end, const float t) {
672 return begin * (1.f - t) + end * t; 672 return begin * (1.f - t) + end * t;
673} 673}
674 674