From a272f3e3b9f1c46710b69f6de512fffc3c0dfe84 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Tue, 3 Jan 2023 22:32:19 +0300 Subject: [PATCH] rsx: Improve performance by using an integral type to indicate error --- rpcs3/Emu/RSX/Common/expected.hpp | 36 +++++++++++++++++++++++++------ rpcs3/Emu/RSX/RSXTexture.cpp | 2 +- rpcs3/Emu/RSX/gcm_enums.h | 12 +++++------ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/expected.hpp b/rpcs3/Emu/RSX/Common/expected.hpp index 0f0844d0c0..f2735210ff 100644 --- a/rpcs3/Emu/RSX/Common/expected.hpp +++ b/rpcs3/Emu/RSX/Common/expected.hpp @@ -5,13 +5,37 @@ namespace rsx { - template - concept ErrorType = requires (E& e) - { - { e.empty() } -> std::same_as; - }; + namespace exception_utils + { + enum soft_exception_error_code + { + none = 0, + range_exception = 1, + invalid_enum = 2 + }; - template + struct soft_exception_t + { + soft_exception_error_code error = soft_exception_error_code::none; + + soft_exception_t() = default; + soft_exception_t(soft_exception_error_code code) + : error(code) {} + + bool empty() const + { + return error == soft_exception_error_code::none; + } + }; + } + + template + concept ErrorType = requires (E & e) + { + { e.empty() } -> std::same_as; + }; + + template class expected { T value; diff --git a/rpcs3/Emu/RSX/RSXTexture.cpp b/rpcs3/Emu/RSX/RSXTexture.cpp index 2ef7e4cfce..d308bb83c4 100644 --- a/rpcs3/Emu/RSX/RSXTexture.cpp +++ b/rpcs3/Emu/RSX/RSXTexture.cpp @@ -97,7 +97,7 @@ namespace rsx rsx::comparison_function fragment_texture::zfunc() const { - return static_cast((registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 28) & 0xf); + return rsx::to_comparison_function((registers[NV4097_SET_TEXTURE_ADDRESS + (m_index * 8)] >> 28) & 0xf); } u8 fragment_texture::unsigned_remap() const diff --git a/rpcs3/Emu/RSX/gcm_enums.h b/rpcs3/Emu/RSX/gcm_enums.h index 89347ca4ba..4f52bbd1b3 100644 --- a/rpcs3/Emu/RSX/gcm_enums.h +++ b/rpcs3/Emu/RSX/gcm_enums.h @@ -973,7 +973,7 @@ namespace rsx return static_cast(value); } - return fmt::format("Enum out of range 0x%x", value); + return exception_utils::soft_exception_t{ rsx::exception_utils::invalid_enum }; } template @@ -987,7 +987,7 @@ namespace rsx } } - return fmt::format("Invalid enum value 0x%x", value); + return exception_utils::soft_exception_t{ rsx::exception_utils::invalid_enum }; } template @@ -1001,7 +1001,7 @@ namespace rsx } } - return fmt::format("Enum is out of range 0x%x", value); + return exception_utils::soft_exception_t{ rsx::exception_utils::invalid_enum }; } enum class vertex_base_type : u8 @@ -1083,8 +1083,8 @@ namespace rsx enum class surface_depth_format2 : u8 { - z16_uint, // unsigned 16 bits depth - z24s8_uint, // unsigned 24 bits depth + 8 bits stencil + z16_uint = surface_depth_format::z16, // unsigned 16 bits depth + z24s8_uint = surface_depth_format::z24s8, // unsigned 24 bits depth + 8 bits stencil z16_float, // floating point 16 bits depth z24s8_float, // floating point 24 bits depth + 8 bits stencil }; @@ -1270,7 +1270,7 @@ namespace rsx { return gcm_enum_cast< texture_wrap_mode, - CELL_GCM_TEXTURE_CLAMP, + CELL_GCM_TEXTURE_WRAP, CELL_GCM_TEXTURE_MIRROR_ONCE_CLAMP>(in); }