diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/demangle.cpp | 4 | ||||
| -rw-r--r-- | src/common/host_memory.cpp | 4 | ||||
| -rw-r--r-- | src/common/page_table.cpp | 4 | ||||
| -rw-r--r-- | src/common/ring_buffer.h | 1 | ||||
| -rw-r--r-- | src/common/scope_exit.h | 66 | ||||
| -rw-r--r-- | src/common/settings.h | 6 | ||||
| -rw-r--r-- | src/common/settings_enums.h | 2 | ||||
| -rw-r--r-- | src/common/string_util.cpp | 4 | ||||
| -rw-r--r-- | src/common/string_util.h | 1 |
9 files changed, 67 insertions, 25 deletions
diff --git a/src/common/demangle.cpp b/src/common/demangle.cpp index 6e117cb41..b2c9d126a 100644 --- a/src/common/demangle.cpp +++ b/src/common/demangle.cpp | |||
| @@ -20,7 +20,9 @@ std::string DemangleSymbol(const std::string& mangled) { | |||
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | char* demangled = nullptr; | 22 | char* demangled = nullptr; |
| 23 | SCOPE_EXIT({ std::free(demangled); }); | 23 | SCOPE_EXIT { |
| 24 | std::free(demangled); | ||
| 25 | }; | ||
| 24 | 26 | ||
| 25 | if (is_itanium(mangled)) { | 27 | if (is_itanium(mangled)) { |
| 26 | demangled = llvm::itaniumDemangle(mangled.c_str()); | 28 | demangled = llvm::itaniumDemangle(mangled.c_str()); |
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 860c39e6a..e0b5a6a67 100644 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp | |||
| @@ -430,11 +430,11 @@ public: | |||
| 430 | explicit Impl(size_t backing_size_, size_t virtual_size_) | 430 | explicit Impl(size_t backing_size_, size_t virtual_size_) |
| 431 | : backing_size{backing_size_}, virtual_size{virtual_size_} { | 431 | : backing_size{backing_size_}, virtual_size{virtual_size_} { |
| 432 | bool good = false; | 432 | bool good = false; |
| 433 | SCOPE_EXIT({ | 433 | SCOPE_EXIT { |
| 434 | if (!good) { | 434 | if (!good) { |
| 435 | Release(); | 435 | Release(); |
| 436 | } | 436 | } |
| 437 | }); | 437 | }; |
| 438 | 438 | ||
| 439 | long page_size = sysconf(_SC_PAGESIZE); | 439 | long page_size = sysconf(_SC_PAGESIZE); |
| 440 | if (page_size != 0x1000) { | 440 | if (page_size != 0x1000) { |
diff --git a/src/common/page_table.cpp b/src/common/page_table.cpp index 85dc18c11..3205eb7da 100644 --- a/src/common/page_table.cpp +++ b/src/common/page_table.cpp | |||
| @@ -24,10 +24,10 @@ bool PageTable::ContinueTraversal(TraversalEntry* out_entry, TraversalContext* c | |||
| 24 | out_entry->block_size = page_size; | 24 | out_entry->block_size = page_size; |
| 25 | 25 | ||
| 26 | // Regardless of whether the page was mapped, advance on exit. | 26 | // Regardless of whether the page was mapped, advance on exit. |
| 27 | SCOPE_EXIT({ | 27 | SCOPE_EXIT { |
| 28 | context->next_page += 1; | 28 | context->next_page += 1; |
| 29 | context->next_offset += page_size; | 29 | context->next_offset += page_size; |
| 30 | }); | 30 | }; |
| 31 | 31 | ||
| 32 | // Validate that we can read the actual entry. | 32 | // Validate that we can read the actual entry. |
| 33 | const auto page = context->next_page; | 33 | const auto page = context->next_page; |
diff --git a/src/common/ring_buffer.h b/src/common/ring_buffer.h index e7e9fdb38..b92db6185 100644 --- a/src/common/ring_buffer.h +++ b/src/common/ring_buffer.h | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <atomic> | 8 | #include <atomic> |
| 9 | #include <cstddef> | 9 | #include <cstddef> |
| 10 | #include <cstring> | 10 | #include <cstring> |
| 11 | #include <limits> | ||
| 11 | #include <new> | 12 | #include <new> |
| 12 | #include <span> | 13 | #include <span> |
| 13 | #include <type_traits> | 14 | #include <type_traits> |
diff --git a/src/common/scope_exit.h b/src/common/scope_exit.h index e9c789c88..f3e88cde9 100644 --- a/src/common/scope_exit.h +++ b/src/common/scope_exit.h | |||
| @@ -7,29 +7,61 @@ | |||
| 7 | #include "common/common_funcs.h" | 7 | #include "common/common_funcs.h" |
| 8 | 8 | ||
| 9 | namespace detail { | 9 | namespace detail { |
| 10 | template <typename Func> | 10 | template <class F> |
| 11 | struct ScopeExitHelper { | 11 | class ScopeGuard { |
| 12 | explicit ScopeExitHelper(Func&& func_) : func(std::move(func_)) {} | 12 | YUZU_NON_COPYABLE(ScopeGuard); |
| 13 | ~ScopeExitHelper() { | 13 | |
| 14 | private: | ||
| 15 | F f; | ||
| 16 | bool active; | ||
| 17 | |||
| 18 | public: | ||
| 19 | constexpr ScopeGuard(F f_) : f(std::move(f_)), active(true) {} | ||
| 20 | constexpr ~ScopeGuard() { | ||
| 14 | if (active) { | 21 | if (active) { |
| 15 | func(); | 22 | f(); |
| 16 | } | 23 | } |
| 17 | } | 24 | } |
| 18 | 25 | constexpr void Cancel() { | |
| 19 | void Cancel() { | ||
| 20 | active = false; | 26 | active = false; |
| 21 | } | 27 | } |
| 22 | 28 | ||
| 23 | Func func; | 29 | constexpr ScopeGuard(ScopeGuard&& rhs) : f(std::move(rhs.f)), active(rhs.active) { |
| 24 | bool active{true}; | 30 | rhs.Cancel(); |
| 31 | } | ||
| 32 | |||
| 33 | ScopeGuard& operator=(ScopeGuard&& rhs) = delete; | ||
| 25 | }; | 34 | }; |
| 26 | 35 | ||
| 27 | template <typename Func> | 36 | template <class F> |
| 28 | ScopeExitHelper<Func> ScopeExit(Func&& func) { | 37 | constexpr ScopeGuard<F> MakeScopeGuard(F f) { |
| 29 | return ScopeExitHelper<Func>(std::forward<Func>(func)); | 38 | return ScopeGuard<F>(std::move(f)); |
| 30 | } | 39 | } |
| 40 | |||
| 41 | enum class ScopeGuardOnExit {}; | ||
| 42 | |||
| 43 | template <typename F> | ||
| 44 | constexpr ScopeGuard<F> operator+(ScopeGuardOnExit, F&& f) { | ||
| 45 | return ScopeGuard<F>(std::forward<F>(f)); | ||
| 46 | } | ||
| 47 | |||
| 31 | } // namespace detail | 48 | } // namespace detail |
| 32 | 49 | ||
| 50 | #define CONCATENATE_IMPL(s1, s2) s1##s2 | ||
| 51 | #define CONCATENATE(s1, s2) CONCATENATE_IMPL(s1, s2) | ||
| 52 | |||
| 53 | #ifdef __COUNTER__ | ||
| 54 | #define ANONYMOUS_VARIABLE(pref) CONCATENATE(pref, __COUNTER__) | ||
| 55 | #else | ||
| 56 | #define ANONYMOUS_VARIABLE(pref) CONCATENATE(pref, __LINE__) | ||
| 57 | #endif | ||
| 58 | |||
| 59 | /** | ||
| 60 | * This macro is similar to SCOPE_EXIT, except the object is caller managed. This is intended to be | ||
| 61 | * used when the caller might want to cancel the ScopeExit. | ||
| 62 | */ | ||
| 63 | #define SCOPE_GUARD detail::ScopeGuardOnExit() + [&]() | ||
| 64 | |||
| 33 | /** | 65 | /** |
| 34 | * This macro allows you to conveniently specify a block of code that will run on scope exit. Handy | 66 | * This macro allows you to conveniently specify a block of code that will run on scope exit. Handy |
| 35 | * for doing ad-hoc clean-up tasks in a function with multiple returns. | 67 | * for doing ad-hoc clean-up tasks in a function with multiple returns. |
| @@ -38,7 +70,7 @@ ScopeExitHelper<Func> ScopeExit(Func&& func) { | |||
| 38 | * \code | 70 | * \code |
| 39 | * const int saved_val = g_foo; | 71 | * const int saved_val = g_foo; |
| 40 | * g_foo = 55; | 72 | * g_foo = 55; |
| 41 | * SCOPE_EXIT({ g_foo = saved_val; }); | 73 | * SCOPE_EXIT{ g_foo = saved_val; }; |
| 42 | * | 74 | * |
| 43 | * if (Bar()) { | 75 | * if (Bar()) { |
| 44 | * return 0; | 76 | * return 0; |
| @@ -47,10 +79,4 @@ ScopeExitHelper<Func> ScopeExit(Func&& func) { | |||
| 47 | * } | 79 | * } |
| 48 | * \endcode | 80 | * \endcode |
| 49 | */ | 81 | */ |
| 50 | #define SCOPE_EXIT(body) auto CONCAT2(scope_exit_helper_, __LINE__) = detail::ScopeExit([&]() body) | 82 | #define SCOPE_EXIT auto ANONYMOUS_VARIABLE(SCOPE_EXIT_STATE_) = SCOPE_GUARD |
| 51 | |||
| 52 | /** | ||
| 53 | * This macro is similar to SCOPE_EXIT, except the object is caller managed. This is intended to be | ||
| 54 | * used when the caller might want to cancel the ScopeExit. | ||
| 55 | */ | ||
| 56 | #define SCOPE_GUARD(body) detail::ScopeExit([&]() body) | ||
diff --git a/src/common/settings.h b/src/common/settings.h index aa054dc24..b2b071e7e 100644 --- a/src/common/settings.h +++ b/src/common/settings.h | |||
| @@ -384,6 +384,12 @@ struct Values { | |||
| 384 | AstcRecompression::Bc3, | 384 | AstcRecompression::Bc3, |
| 385 | "astc_recompression", | 385 | "astc_recompression", |
| 386 | Category::RendererAdvanced}; | 386 | Category::RendererAdvanced}; |
| 387 | SwitchableSetting<VramUsageMode, true> vram_usage_mode{linkage, | ||
| 388 | VramUsageMode::Conservative, | ||
| 389 | VramUsageMode::Conservative, | ||
| 390 | VramUsageMode::Aggressive, | ||
| 391 | "vram_usage_mode", | ||
| 392 | Category::RendererAdvanced}; | ||
| 387 | SwitchableSetting<bool> async_presentation{linkage, | 393 | SwitchableSetting<bool> async_presentation{linkage, |
| 388 | #ifdef ANDROID | 394 | #ifdef ANDROID |
| 389 | true, | 395 | true, |
diff --git a/src/common/settings_enums.h b/src/common/settings_enums.h index f42367e67..6e247e930 100644 --- a/src/common/settings_enums.h +++ b/src/common/settings_enums.h | |||
| @@ -122,6 +122,8 @@ ENUM(AstcRecompression, Uncompressed, Bc1, Bc3); | |||
| 122 | 122 | ||
| 123 | ENUM(VSyncMode, Immediate, Mailbox, Fifo, FifoRelaxed); | 123 | ENUM(VSyncMode, Immediate, Mailbox, Fifo, FifoRelaxed); |
| 124 | 124 | ||
| 125 | ENUM(VramUsageMode, Conservative, Aggressive); | ||
| 126 | |||
| 125 | ENUM(RendererBackend, OpenGL, Vulkan, Null); | 127 | ENUM(RendererBackend, OpenGL, Vulkan, Null); |
| 126 | 128 | ||
| 127 | ENUM(ShaderBackend, Glsl, Glasm, SpirV); | 129 | ENUM(ShaderBackend, Glsl, Glasm, SpirV); |
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 72c481798..1909aced5 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp | |||
| @@ -38,6 +38,10 @@ std::string StringFromBuffer(std::span<const u8> data) { | |||
| 38 | return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); | 38 | return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | std::string StringFromBuffer(std::span<const char> data) { | ||
| 42 | return std::string(data.begin(), std::find(data.begin(), data.end(), '\0')); | ||
| 43 | } | ||
| 44 | |||
| 41 | // Turns " hej " into "hej". Also handles tabs. | 45 | // Turns " hej " into "hej". Also handles tabs. |
| 42 | std::string StripSpaces(const std::string& str) { | 46 | std::string StripSpaces(const std::string& str) { |
| 43 | const std::size_t s = str.find_first_not_of(" \t\r\n"); | 47 | const std::size_t s = str.find_first_not_of(" \t\r\n"); |
diff --git a/src/common/string_util.h b/src/common/string_util.h index 9da1ca4e9..53d0549ca 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h | |||
| @@ -19,6 +19,7 @@ namespace Common { | |||
| 19 | [[nodiscard]] std::string ToUpper(std::string str); | 19 | [[nodiscard]] std::string ToUpper(std::string str); |
| 20 | 20 | ||
| 21 | [[nodiscard]] std::string StringFromBuffer(std::span<const u8> data); | 21 | [[nodiscard]] std::string StringFromBuffer(std::span<const u8> data); |
| 22 | [[nodiscard]] std::string StringFromBuffer(std::span<const char> data); | ||
| 22 | 23 | ||
| 23 | [[nodiscard]] std::string StripSpaces(const std::string& s); | 24 | [[nodiscard]] std::string StripSpaces(const std::string& s); |
| 24 | [[nodiscard]] std::string StripQuotes(const std::string& s); | 25 | [[nodiscard]] std::string StripQuotes(const std::string& s); |