diff options
| -rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/common/logging/formatter.h | 23 | ||||
| -rw-r--r-- | src/common/logging/log.h | 16 | ||||
| -rw-r--r-- | src/shader_recompiler/backend/glasm/reg_alloc.h | 8 | ||||
| -rw-r--r-- | src/shader_recompiler/exception.h | 2 | ||||
| -rw-r--r-- | src/shader_recompiler/frontend/ir/patch.cpp | 4 |
6 files changed, 32 insertions, 22 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 790193b00..adf70eb8b 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -85,6 +85,7 @@ add_library(common STATIC | |||
| 85 | logging/backend.h | 85 | logging/backend.h |
| 86 | logging/filter.cpp | 86 | logging/filter.cpp |
| 87 | logging/filter.h | 87 | logging/filter.h |
| 88 | logging/formatter.h | ||
| 88 | logging/log.h | 89 | logging/log.h |
| 89 | logging/log_entry.h | 90 | logging/log_entry.h |
| 90 | logging/text_formatter.cpp | 91 | logging/text_formatter.cpp |
diff --git a/src/common/logging/formatter.h b/src/common/logging/formatter.h new file mode 100644 index 000000000..552cde75a --- /dev/null +++ b/src/common/logging/formatter.h | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | // Copyright 2022 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 <type_traits> | ||
| 8 | |||
| 9 | #include <fmt/format.h> | ||
| 10 | |||
| 11 | // adapted from https://github.com/fmtlib/fmt/issues/2704 | ||
| 12 | // a generic formatter for enum classes | ||
| 13 | #if FMT_VERSION >= 80100 | ||
| 14 | template <typename T> | ||
| 15 | struct fmt::formatter<T, std::enable_if_t<std::is_enum_v<T>, char>> | ||
| 16 | : formatter<std::underlying_type_t<T>> { | ||
| 17 | template <typename FormatContext> | ||
| 18 | auto format(const T& value, FormatContext& ctx) -> decltype(ctx.out()) { | ||
| 19 | return fmt::formatter<std::underlying_type_t<T>>::format( | ||
| 20 | static_cast<std::underlying_type_t<T>>(value), ctx); | ||
| 21 | } | ||
| 22 | }; | ||
| 23 | #endif | ||
diff --git a/src/common/logging/log.h b/src/common/logging/log.h index 096a441b8..0c80d01ee 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h | |||
| @@ -6,26 +6,12 @@ | |||
| 6 | 6 | ||
| 7 | #include <algorithm> | 7 | #include <algorithm> |
| 8 | #include <string_view> | 8 | #include <string_view> |
| 9 | #include <type_traits> | ||
| 10 | 9 | ||
| 11 | #include <fmt/format.h> | 10 | #include <fmt/format.h> |
| 12 | 11 | ||
| 12 | #include "common/logging/formatter.h" | ||
| 13 | #include "common/logging/types.h" | 13 | #include "common/logging/types.h" |
| 14 | 14 | ||
| 15 | // adapted from https://github.com/fmtlib/fmt/issues/2704 | ||
| 16 | // a generic formatter for enum classes (<= 32 bits) | ||
| 17 | #if FMT_VERSION >= 80100 | ||
| 18 | template <typename T> | ||
| 19 | struct fmt::formatter<T, std::enable_if_t<std::is_enum_v<T>, char>> | ||
| 20 | : formatter<std::underlying_type_t<T>> { | ||
| 21 | template <typename FormatContext> | ||
| 22 | auto format(const T& value, FormatContext& ctx) -> decltype(ctx.out()) { | ||
| 23 | return fmt::formatter<std::underlying_type_t<T>>::format( | ||
| 24 | static_cast<std::underlying_type_t<T>>(value), ctx); | ||
| 25 | } | ||
| 26 | }; | ||
| 27 | #endif | ||
| 28 | |||
| 29 | namespace Common::Log { | 15 | namespace Common::Log { |
| 30 | 16 | ||
| 31 | // trims up to and including the last of ../, ..\, src/, src\ in a string | 17 | // trims up to and including the last of ../, ..\, src/, src\ in a string |
diff --git a/src/shader_recompiler/backend/glasm/reg_alloc.h b/src/shader_recompiler/backend/glasm/reg_alloc.h index 812d3cdbc..82aec66c6 100644 --- a/src/shader_recompiler/backend/glasm/reg_alloc.h +++ b/src/shader_recompiler/backend/glasm/reg_alloc.h | |||
| @@ -235,7 +235,7 @@ struct fmt::formatter<Shader::Backend::GLASM::ScalarU32> { | |||
| 235 | case Shader::Backend::GLASM::Type::U64: | 235 | case Shader::Backend::GLASM::Type::U64: |
| 236 | break; | 236 | break; |
| 237 | } | 237 | } |
| 238 | throw Shader::InvalidArgument("Invalid value type {}", static_cast<u32>(value.type)); | 238 | throw Shader::InvalidArgument("Invalid value type {}", value.type); |
| 239 | } | 239 | } |
| 240 | }; | 240 | }; |
| 241 | 241 | ||
| @@ -256,7 +256,7 @@ struct fmt::formatter<Shader::Backend::GLASM::ScalarS32> { | |||
| 256 | case Shader::Backend::GLASM::Type::U64: | 256 | case Shader::Backend::GLASM::Type::U64: |
| 257 | break; | 257 | break; |
| 258 | } | 258 | } |
| 259 | throw Shader::InvalidArgument("Invalid value type {}", static_cast<u32>(value.type)); | 259 | throw Shader::InvalidArgument("Invalid value type {}", value.type); |
| 260 | } | 260 | } |
| 261 | }; | 261 | }; |
| 262 | 262 | ||
| @@ -277,7 +277,7 @@ struct fmt::formatter<Shader::Backend::GLASM::ScalarF32> { | |||
| 277 | case Shader::Backend::GLASM::Type::U64: | 277 | case Shader::Backend::GLASM::Type::U64: |
| 278 | break; | 278 | break; |
| 279 | } | 279 | } |
| 280 | throw Shader::InvalidArgument("Invalid value type {}", static_cast<u32>(value.type)); | 280 | throw Shader::InvalidArgument("Invalid value type {}", value.type); |
| 281 | } | 281 | } |
| 282 | }; | 282 | }; |
| 283 | 283 | ||
| @@ -298,6 +298,6 @@ struct fmt::formatter<Shader::Backend::GLASM::ScalarF64> { | |||
| 298 | case Shader::Backend::GLASM::Type::U64: | 298 | case Shader::Backend::GLASM::Type::U64: |
| 299 | return fmt::format_to(ctx.out(), "{}", Common::BitCast<f64>(value.imm_u64)); | 299 | return fmt::format_to(ctx.out(), "{}", Common::BitCast<f64>(value.imm_u64)); |
| 300 | } | 300 | } |
| 301 | throw Shader::InvalidArgument("Invalid value type {}", static_cast<u32>(value.type)); | 301 | throw Shader::InvalidArgument("Invalid value type {}", value.type); |
| 302 | } | 302 | } |
| 303 | }; | 303 | }; |
diff --git a/src/shader_recompiler/exception.h b/src/shader_recompiler/exception.h index 277be8541..d98b6029b 100644 --- a/src/shader_recompiler/exception.h +++ b/src/shader_recompiler/exception.h | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | #include <string_view> | 9 | #include <string_view> |
| 10 | #include <utility> | 10 | #include <utility> |
| 11 | 11 | ||
| 12 | #include <fmt/format.h> | 12 | #include "common/logging/formatter.h" |
| 13 | 13 | ||
| 14 | namespace Shader { | 14 | namespace Shader { |
| 15 | 15 | ||
diff --git a/src/shader_recompiler/frontend/ir/patch.cpp b/src/shader_recompiler/frontend/ir/patch.cpp index d8730284e..4c956a970 100644 --- a/src/shader_recompiler/frontend/ir/patch.cpp +++ b/src/shader_recompiler/frontend/ir/patch.cpp | |||
| @@ -13,14 +13,14 @@ bool IsGeneric(Patch patch) noexcept { | |||
| 13 | 13 | ||
| 14 | u32 GenericPatchIndex(Patch patch) { | 14 | u32 GenericPatchIndex(Patch patch) { |
| 15 | if (!IsGeneric(patch)) { | 15 | if (!IsGeneric(patch)) { |
| 16 | throw InvalidArgument("Patch {} is not generic", static_cast<u64>(patch)); | 16 | throw InvalidArgument("Patch {} is not generic", patch); |
| 17 | } | 17 | } |
| 18 | return (static_cast<u32>(patch) - static_cast<u32>(Patch::Component0)) / 4; | 18 | return (static_cast<u32>(patch) - static_cast<u32>(Patch::Component0)) / 4; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | u32 GenericPatchElement(Patch patch) { | 21 | u32 GenericPatchElement(Patch patch) { |
| 22 | if (!IsGeneric(patch)) { | 22 | if (!IsGeneric(patch)) { |
| 23 | throw InvalidArgument("Patch {} is not generic", static_cast<u64>(patch)); | 23 | throw InvalidArgument("Patch {} is not generic", patch); |
| 24 | } | 24 | } |
| 25 | return (static_cast<u32>(patch) - static_cast<u32>(Patch::Component0)) % 4; | 25 | return (static_cast<u32>(patch) - static_cast<u32>(Patch::Component0)) % 4; |
| 26 | } | 26 | } |