diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 702375717c..5acb3a20eb 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -237,6 +237,29 @@ struct fmt_class_string : fmt_class_string { }; +namespace fmt +{ + template + concept StringConvertible = requires (T & t) + { + { t.to_string() } -> std::convertible_to; + }; +} + +template +struct fmt_class_string +{ + static FORCE_INLINE SAFE_BUFFERS(const T&) get_object(u64 arg) + { + return *reinterpret_cast(static_cast(arg)); + } + + static void format(std::string& out, u64 arg) + { + out += get_object(arg).to_string(); + } +}; + namespace fmt { // Both uchar and std::byte are allowed diff --git a/rpcs3/Emu/RSX/Common/expected.hpp b/rpcs3/Emu/RSX/Common/expected.hpp index f2735210ff..0a8e53ae7e 100644 --- a/rpcs3/Emu/RSX/Common/expected.hpp +++ b/rpcs3/Emu/RSX/Common/expected.hpp @@ -3,6 +3,12 @@ #include #include +namespace fmt +{ + template + static std::string format(const CharT(&)[N], const Args&...); +} + namespace rsx { namespace exception_utils @@ -26,6 +32,21 @@ namespace rsx { return error == soft_exception_error_code::none; } + + std::string to_string() const + { + switch (error) + { + case soft_exception_error_code::none: + return "No error"; + case soft_exception_error_code::range_exception: + return "Bad Range"; + case soft_exception_error_code::invalid_enum: + return "Invalid enum"; + default: + return "Unknown Error"; + } + } }; } @@ -79,5 +100,20 @@ namespace rsx { return error.empty() && value == other; } + + std::string to_string() const + { + if (error.empty()) + { + return fmt::format("%s", value); + } + + if constexpr (std::is_same_v) + { + return error.to_string(); + } + + return fmt::format("%s", error); + } }; } diff --git a/rpcs3/Emu/RSX/rsx_decode.h b/rpcs3/Emu/RSX/rsx_decode.h index ece8785bd7..c041ae4161 100644 --- a/rpcs3/Emu/RSX/rsx_decode.h +++ b/rpcs3/Emu/RSX/rsx_decode.h @@ -2820,7 +2820,7 @@ struct registers_decoder static std::string dump(const decoded_type& decoded) { - return fmt::format("NV3089: source fmt: %s", *decoded.transfer_source_fmt()); + return fmt::format("NV3089: source fmt: %s", decoded.transfer_source_fmt()); } }; @@ -2866,7 +2866,7 @@ struct registers_decoder static std::string dump(const decoded_type& decoded) { - return fmt::format("NV3062: output fmt: %s", *decoded.transfer_dest_fmt()); + return fmt::format("NV3062: output fmt: %s", decoded.transfer_dest_fmt()); } }; @@ -3759,7 +3759,7 @@ struct registers_decoder static std::string dump(const decoded_type& decoded) { - return fmt::format("NV309E: output fmt: %s log2-width: %u log2-height: %u", *decoded.format(), + return fmt::format("NV309E: output fmt: %s log2-width: %u log2-height: %u", decoded.format(), decoded.sw_width_log2(), decoded.sw_height_log2()); } }; diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index 9ff45e96e5..4bcc6ab645 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -520,6 +520,7 @@ + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index 6002b65491..900040a7b8 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -2227,6 +2227,9 @@ Emu\GPU\RSX\Core + + Emu\GPU\RSX\Common +