diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/common/common_funcs.h | 13 | ||||
| -rw-r--r-- | src/common/error.cpp (renamed from src/common/misc.cpp) | 6 | ||||
| -rw-r--r-- | src/common/error.h | 21 | ||||
| -rw-r--r-- | src/common/logging/backend.cpp | 1 | ||||
| -rw-r--r-- | src/common/logging/filter.cpp | 1 | ||||
| -rw-r--r-- | src/common/logging/types.h | 1 | ||||
| -rw-r--r-- | src/common/lru_cache.h | 140 | ||||
| -rw-r--r-- | src/common/settings.cpp | 6 | ||||
| -rw-r--r-- | src/common/settings.h | 9 | ||||
| -rw-r--r-- | src/common/thread.cpp | 6 |
11 files changed, 184 insertions, 23 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 57922b51c..b18a2a2f5 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -53,6 +53,8 @@ add_library(common STATIC | |||
| 53 | div_ceil.h | 53 | div_ceil.h |
| 54 | dynamic_library.cpp | 54 | dynamic_library.cpp |
| 55 | dynamic_library.h | 55 | dynamic_library.h |
| 56 | error.cpp | ||
| 57 | error.h | ||
| 56 | fiber.cpp | 58 | fiber.cpp |
| 57 | fiber.h | 59 | fiber.h |
| 58 | fs/file.cpp | 60 | fs/file.cpp |
| @@ -88,7 +90,6 @@ add_library(common STATIC | |||
| 88 | microprofile.cpp | 90 | microprofile.cpp |
| 89 | microprofile.h | 91 | microprofile.h |
| 90 | microprofileui.h | 92 | microprofileui.h |
| 91 | misc.cpp | ||
| 92 | nvidia_flags.cpp | 93 | nvidia_flags.cpp |
| 93 | nvidia_flags.h | 94 | nvidia_flags.h |
| 94 | page_table.cpp | 95 | page_table.cpp |
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 53bd7da60..1e74d6930 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h | |||
| @@ -4,9 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <algorithm> | ||
| 8 | #include <array> | 7 | #include <array> |
| 9 | #include <string> | 8 | #include <iterator> |
| 10 | 9 | ||
| 11 | #if !defined(ARCHITECTURE_x86_64) | 10 | #if !defined(ARCHITECTURE_x86_64) |
| 12 | #include <cstdlib> // for exit | 11 | #include <cstdlib> // for exit |
| @@ -49,16 +48,6 @@ __declspec(dllimport) void __stdcall DebugBreak(void); | |||
| 49 | 48 | ||
| 50 | #endif // _MSC_VER ndef | 49 | #endif // _MSC_VER ndef |
| 51 | 50 | ||
| 52 | // Generic function to get last error message. | ||
| 53 | // Call directly after the command or use the error num. | ||
| 54 | // This function might change the error code. | ||
| 55 | // Defined in misc.cpp. | ||
| 56 | [[nodiscard]] std::string GetLastErrorMsg(); | ||
| 57 | |||
| 58 | // Like GetLastErrorMsg(), but passing an explicit error code. | ||
| 59 | // Defined in misc.cpp. | ||
| 60 | [[nodiscard]] std::string NativeErrorToString(int e); | ||
| 61 | |||
| 62 | #define DECLARE_ENUM_FLAG_OPERATORS(type) \ | 51 | #define DECLARE_ENUM_FLAG_OPERATORS(type) \ |
| 63 | [[nodiscard]] constexpr type operator|(type a, type b) noexcept { \ | 52 | [[nodiscard]] constexpr type operator|(type a, type b) noexcept { \ |
| 64 | using T = std::underlying_type_t<type>; \ | 53 | using T = std::underlying_type_t<type>; \ |
diff --git a/src/common/misc.cpp b/src/common/error.cpp index 495385b9e..d4455e310 100644 --- a/src/common/misc.cpp +++ b/src/common/error.cpp | |||
| @@ -10,7 +10,9 @@ | |||
| 10 | #include <cstring> | 10 | #include <cstring> |
| 11 | #endif | 11 | #endif |
| 12 | 12 | ||
| 13 | #include "common/common_funcs.h" | 13 | #include "common/error.h" |
| 14 | |||
| 15 | namespace Common { | ||
| 14 | 16 | ||
| 15 | std::string NativeErrorToString(int e) { | 17 | std::string NativeErrorToString(int e) { |
| 16 | #ifdef _WIN32 | 18 | #ifdef _WIN32 |
| @@ -50,3 +52,5 @@ std::string GetLastErrorMsg() { | |||
| 50 | return NativeErrorToString(errno); | 52 | return NativeErrorToString(errno); |
| 51 | #endif | 53 | #endif |
| 52 | } | 54 | } |
| 55 | |||
| 56 | } // namespace Common | ||
diff --git a/src/common/error.h b/src/common/error.h new file mode 100644 index 000000000..e084d4b0f --- /dev/null +++ b/src/common/error.h | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | // Copyright 2013 Dolphin Emulator Project / 2014 Citra 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 | |||
| 9 | namespace Common { | ||
| 10 | |||
| 11 | // Generic function to get last error message. | ||
| 12 | // Call directly after the command or use the error num. | ||
| 13 | // This function might change the error code. | ||
| 14 | // Defined in error.cpp. | ||
| 15 | [[nodiscard]] std::string GetLastErrorMsg(); | ||
| 16 | |||
| 17 | // Like GetLastErrorMsg(), but passing an explicit error code. | ||
| 18 | // Defined in error.cpp. | ||
| 19 | [[nodiscard]] std::string NativeErrorToString(int e); | ||
| 20 | |||
| 21 | } // namespace Common | ||
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 949384fd3..e40d117d6 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include "common/fs/fs_paths.h" | 18 | #include "common/fs/fs_paths.h" |
| 19 | #include "common/fs/path_util.h" | 19 | #include "common/fs/path_util.h" |
| 20 | #include "common/literals.h" | 20 | #include "common/literals.h" |
| 21 | #include "common/thread.h" | ||
| 21 | 22 | ||
| 22 | #include "common/logging/backend.h" | 23 | #include "common/logging/backend.h" |
| 23 | #include "common/logging/log.h" | 24 | #include "common/logging/log.h" |
diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp index f055f0e11..42744c994 100644 --- a/src/common/logging/filter.cpp +++ b/src/common/logging/filter.cpp | |||
| @@ -111,6 +111,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) { | |||
| 111 | SUB(Service, NCM) \ | 111 | SUB(Service, NCM) \ |
| 112 | SUB(Service, NFC) \ | 112 | SUB(Service, NFC) \ |
| 113 | SUB(Service, NFP) \ | 113 | SUB(Service, NFP) \ |
| 114 | SUB(Service, NGCT) \ | ||
| 114 | SUB(Service, NIFM) \ | 115 | SUB(Service, NIFM) \ |
| 115 | SUB(Service, NIM) \ | 116 | SUB(Service, NIM) \ |
| 116 | SUB(Service, NPNS) \ | 117 | SUB(Service, NPNS) \ |
diff --git a/src/common/logging/types.h b/src/common/logging/types.h index 7ad0334fc..ddf9d27ca 100644 --- a/src/common/logging/types.h +++ b/src/common/logging/types.h | |||
| @@ -81,6 +81,7 @@ enum class Class : u8 { | |||
| 81 | Service_NCM, ///< The NCM service | 81 | Service_NCM, ///< The NCM service |
| 82 | Service_NFC, ///< The NFC (Near-field communication) service | 82 | Service_NFC, ///< The NFC (Near-field communication) service |
| 83 | Service_NFP, ///< The NFP service | 83 | Service_NFP, ///< The NFP service |
| 84 | Service_NGCT, ///< The NGCT (No Good Content for Terra) service | ||
| 84 | Service_NIFM, ///< The NIFM (Network interface) service | 85 | Service_NIFM, ///< The NIFM (Network interface) service |
| 85 | Service_NIM, ///< The NIM service | 86 | Service_NIM, ///< The NIM service |
| 86 | Service_NPNS, ///< The NPNS service | 87 | Service_NPNS, ///< The NPNS service |
diff --git a/src/common/lru_cache.h b/src/common/lru_cache.h new file mode 100644 index 000000000..365488ba5 --- /dev/null +++ b/src/common/lru_cache.h | |||
| @@ -0,0 +1,140 @@ | |||
| 1 | // Copyright 2021 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 <deque> | ||
| 8 | #include <memory> | ||
| 9 | #include <type_traits> | ||
| 10 | |||
| 11 | #include "common/common_types.h" | ||
| 12 | |||
| 13 | namespace Common { | ||
| 14 | |||
| 15 | template <class Traits> | ||
| 16 | class LeastRecentlyUsedCache { | ||
| 17 | using ObjectType = typename Traits::ObjectType; | ||
| 18 | using TickType = typename Traits::TickType; | ||
| 19 | |||
| 20 | struct Item { | ||
| 21 | ObjectType obj; | ||
| 22 | TickType tick; | ||
| 23 | Item* next{}; | ||
| 24 | Item* prev{}; | ||
| 25 | }; | ||
| 26 | |||
| 27 | public: | ||
| 28 | LeastRecentlyUsedCache() : first_item{}, last_item{} {} | ||
| 29 | ~LeastRecentlyUsedCache() = default; | ||
| 30 | |||
| 31 | size_t Insert(ObjectType obj, TickType tick) { | ||
| 32 | const auto new_id = Build(); | ||
| 33 | auto& item = item_pool[new_id]; | ||
| 34 | item.obj = obj; | ||
| 35 | item.tick = tick; | ||
| 36 | Attach(item); | ||
| 37 | return new_id; | ||
| 38 | } | ||
| 39 | |||
| 40 | void Touch(size_t id, TickType tick) { | ||
| 41 | auto& item = item_pool[id]; | ||
| 42 | if (item.tick >= tick) { | ||
| 43 | return; | ||
| 44 | } | ||
| 45 | item.tick = tick; | ||
| 46 | if (&item == last_item) { | ||
| 47 | return; | ||
| 48 | } | ||
| 49 | Detach(item); | ||
| 50 | Attach(item); | ||
| 51 | } | ||
| 52 | |||
| 53 | void Free(size_t id) { | ||
| 54 | auto& item = item_pool[id]; | ||
| 55 | Detach(item); | ||
| 56 | item.prev = nullptr; | ||
| 57 | item.next = nullptr; | ||
| 58 | free_items.push_back(id); | ||
| 59 | } | ||
| 60 | |||
| 61 | template <typename Func> | ||
| 62 | void ForEachItemBelow(TickType tick, Func&& func) { | ||
| 63 | static constexpr bool RETURNS_BOOL = | ||
| 64 | std::is_same_v<std::invoke_result<Func, ObjectType>, bool>; | ||
| 65 | Item* iterator = first_item; | ||
| 66 | while (iterator) { | ||
| 67 | if (static_cast<s64>(tick) - static_cast<s64>(iterator->tick) < 0) { | ||
| 68 | return; | ||
| 69 | } | ||
| 70 | Item* next = iterator->next; | ||
| 71 | if constexpr (RETURNS_BOOL) { | ||
| 72 | if (func(iterator->obj)) { | ||
| 73 | return; | ||
| 74 | } | ||
| 75 | } else { | ||
| 76 | func(iterator->obj); | ||
| 77 | } | ||
| 78 | iterator = next; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | private: | ||
| 83 | size_t Build() { | ||
| 84 | if (free_items.empty()) { | ||
| 85 | const size_t item_id = item_pool.size(); | ||
| 86 | auto& item = item_pool.emplace_back(); | ||
| 87 | item.next = nullptr; | ||
| 88 | item.prev = nullptr; | ||
| 89 | return item_id; | ||
| 90 | } | ||
| 91 | const size_t item_id = free_items.front(); | ||
| 92 | free_items.pop_front(); | ||
| 93 | auto& item = item_pool[item_id]; | ||
| 94 | item.next = nullptr; | ||
| 95 | item.prev = nullptr; | ||
| 96 | return item_id; | ||
| 97 | } | ||
| 98 | |||
| 99 | void Attach(Item& item) { | ||
| 100 | if (!first_item) { | ||
| 101 | first_item = &item; | ||
| 102 | } | ||
| 103 | if (!last_item) { | ||
| 104 | last_item = &item; | ||
| 105 | } else { | ||
| 106 | item.prev = last_item; | ||
| 107 | last_item->next = &item; | ||
| 108 | item.next = nullptr; | ||
| 109 | last_item = &item; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | void Detach(Item& item) { | ||
| 114 | if (item.prev) { | ||
| 115 | item.prev->next = item.next; | ||
| 116 | } | ||
| 117 | if (item.next) { | ||
| 118 | item.next->prev = item.prev; | ||
| 119 | } | ||
| 120 | if (&item == first_item) { | ||
| 121 | first_item = item.next; | ||
| 122 | if (first_item) { | ||
| 123 | first_item->prev = nullptr; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | if (&item == last_item) { | ||
| 127 | last_item = item.prev; | ||
| 128 | if (last_item) { | ||
| 129 | last_item->next = nullptr; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | std::deque<Item> item_pool; | ||
| 135 | std::deque<size_t> free_items; | ||
| 136 | Item* first_item{}; | ||
| 137 | Item* last_item{}; | ||
| 138 | }; | ||
| 139 | |||
| 140 | } // namespace Common | ||
diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 996315999..0d2df80a8 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp | |||
| @@ -54,12 +54,11 @@ void LogSettings() { | |||
| 54 | log_setting("Renderer_GPUAccuracyLevel", values.gpu_accuracy.GetValue()); | 54 | log_setting("Renderer_GPUAccuracyLevel", values.gpu_accuracy.GetValue()); |
| 55 | log_setting("Renderer_UseAsynchronousGpuEmulation", | 55 | log_setting("Renderer_UseAsynchronousGpuEmulation", |
| 56 | values.use_asynchronous_gpu_emulation.GetValue()); | 56 | values.use_asynchronous_gpu_emulation.GetValue()); |
| 57 | log_setting("Renderer_UseNvdecEmulation", values.use_nvdec_emulation.GetValue()); | 57 | log_setting("Renderer_NvdecEmulation", values.nvdec_emulation.GetValue()); |
| 58 | log_setting("Renderer_AccelerateASTC", values.accelerate_astc.GetValue()); | 58 | log_setting("Renderer_AccelerateASTC", values.accelerate_astc.GetValue()); |
| 59 | log_setting("Renderer_UseVsync", values.use_vsync.GetValue()); | 59 | log_setting("Renderer_UseVsync", values.use_vsync.GetValue()); |
| 60 | log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue()); | 60 | log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue()); |
| 61 | log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue()); | 61 | log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue()); |
| 62 | log_setting("Renderer_UseGarbageCollection", values.use_caches_gc.GetValue()); | ||
| 63 | log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue()); | 62 | log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue()); |
| 64 | log_setting("Audio_OutputEngine", values.sink_id.GetValue()); | 63 | log_setting("Audio_OutputEngine", values.sink_id.GetValue()); |
| 65 | log_setting("Audio_EnableAudioStretching", values.enable_audio_stretching.GetValue()); | 64 | log_setting("Audio_EnableAudioStretching", values.enable_audio_stretching.GetValue()); |
| @@ -137,13 +136,12 @@ void RestoreGlobalState(bool is_powered_on) { | |||
| 137 | values.use_disk_shader_cache.SetGlobal(true); | 136 | values.use_disk_shader_cache.SetGlobal(true); |
| 138 | values.gpu_accuracy.SetGlobal(true); | 137 | values.gpu_accuracy.SetGlobal(true); |
| 139 | values.use_asynchronous_gpu_emulation.SetGlobal(true); | 138 | values.use_asynchronous_gpu_emulation.SetGlobal(true); |
| 140 | values.use_nvdec_emulation.SetGlobal(true); | 139 | values.nvdec_emulation.SetGlobal(true); |
| 141 | values.accelerate_astc.SetGlobal(true); | 140 | values.accelerate_astc.SetGlobal(true); |
| 142 | values.use_vsync.SetGlobal(true); | 141 | values.use_vsync.SetGlobal(true); |
| 143 | values.shader_backend.SetGlobal(true); | 142 | values.shader_backend.SetGlobal(true); |
| 144 | values.use_asynchronous_shaders.SetGlobal(true); | 143 | values.use_asynchronous_shaders.SetGlobal(true); |
| 145 | values.use_fast_gpu_time.SetGlobal(true); | 144 | values.use_fast_gpu_time.SetGlobal(true); |
| 146 | values.use_caches_gc.SetGlobal(true); | ||
| 147 | values.bg_red.SetGlobal(true); | 145 | values.bg_red.SetGlobal(true); |
| 148 | values.bg_green.SetGlobal(true); | 146 | values.bg_green.SetGlobal(true); |
| 149 | values.bg_blue.SetGlobal(true); | 147 | values.bg_blue.SetGlobal(true); |
diff --git a/src/common/settings.h b/src/common/settings.h index 20769d310..b7195670b 100644 --- a/src/common/settings.h +++ b/src/common/settings.h | |||
| @@ -48,6 +48,12 @@ enum class FullscreenMode : u32 { | |||
| 48 | Exclusive = 1, | 48 | Exclusive = 1, |
| 49 | }; | 49 | }; |
| 50 | 50 | ||
| 51 | enum class NvdecEmulation : u32 { | ||
| 52 | Off = 0, | ||
| 53 | CPU = 1, | ||
| 54 | GPU = 2, | ||
| 55 | }; | ||
| 56 | |||
| 51 | /** The BasicSetting class is a simple resource manager. It defines a label and default value | 57 | /** The BasicSetting class is a simple resource manager. It defines a label and default value |
| 52 | * alongside the actual value of the setting for simpler and less-error prone use with frontend | 58 | * alongside the actual value of the setting for simpler and less-error prone use with frontend |
| 53 | * configurations. Setting a default value and label is required, though subclasses may deviate from | 59 | * configurations. Setting a default value and label is required, though subclasses may deviate from |
| @@ -466,7 +472,7 @@ struct Values { | |||
| 466 | RangedSetting<GPUAccuracy> gpu_accuracy{GPUAccuracy::High, GPUAccuracy::Normal, | 472 | RangedSetting<GPUAccuracy> gpu_accuracy{GPUAccuracy::High, GPUAccuracy::Normal, |
| 467 | GPUAccuracy::Extreme, "gpu_accuracy"}; | 473 | GPUAccuracy::Extreme, "gpu_accuracy"}; |
| 468 | Setting<bool> use_asynchronous_gpu_emulation{true, "use_asynchronous_gpu_emulation"}; | 474 | Setting<bool> use_asynchronous_gpu_emulation{true, "use_asynchronous_gpu_emulation"}; |
| 469 | Setting<bool> use_nvdec_emulation{true, "use_nvdec_emulation"}; | 475 | Setting<NvdecEmulation> nvdec_emulation{NvdecEmulation::GPU, "nvdec_emulation"}; |
| 470 | Setting<bool> accelerate_astc{true, "accelerate_astc"}; | 476 | Setting<bool> accelerate_astc{true, "accelerate_astc"}; |
| 471 | Setting<bool> use_vsync{true, "use_vsync"}; | 477 | Setting<bool> use_vsync{true, "use_vsync"}; |
| 472 | BasicRangedSetting<u16> fps_cap{1000, 1, 1000, "fps_cap"}; | 478 | BasicRangedSetting<u16> fps_cap{1000, 1, 1000, "fps_cap"}; |
| @@ -475,7 +481,6 @@ struct Values { | |||
| 475 | ShaderBackend::SPIRV, "shader_backend"}; | 481 | ShaderBackend::SPIRV, "shader_backend"}; |
| 476 | Setting<bool> use_asynchronous_shaders{false, "use_asynchronous_shaders"}; | 482 | Setting<bool> use_asynchronous_shaders{false, "use_asynchronous_shaders"}; |
| 477 | Setting<bool> use_fast_gpu_time{true, "use_fast_gpu_time"}; | 483 | Setting<bool> use_fast_gpu_time{true, "use_fast_gpu_time"}; |
| 478 | Setting<bool> use_caches_gc{false, "use_caches_gc"}; | ||
| 479 | 484 | ||
| 480 | Setting<u8> bg_red{0, "bg_red"}; | 485 | Setting<u8> bg_red{0, "bg_red"}; |
| 481 | Setting<u8> bg_green{0, "bg_green"}; | 486 | Setting<u8> bg_green{0, "bg_green"}; |
diff --git a/src/common/thread.cpp b/src/common/thread.cpp index d2c1ac60d..946a1114d 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp | |||
| @@ -2,7 +2,9 @@ | |||
| 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" | 5 | #include <string> |
| 6 | |||
| 7 | #include "common/error.h" | ||
| 6 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 7 | #include "common/thread.h" | 9 | #include "common/thread.h" |
| 8 | #ifdef __APPLE__ | 10 | #ifdef __APPLE__ |
| @@ -21,8 +23,6 @@ | |||
| 21 | #include <unistd.h> | 23 | #include <unistd.h> |
| 22 | #endif | 24 | #endif |
| 23 | 25 | ||
| 24 | #include <string> | ||
| 25 | |||
| 26 | #ifdef __FreeBSD__ | 26 | #ifdef __FreeBSD__ |
| 27 | #define cpu_set_t cpuset_t | 27 | #define cpu_set_t cpuset_t |
| 28 | #endif | 28 | #endif |