diff --git a/rpcs3/Emu/CMakeLists.txt b/rpcs3/Emu/CMakeLists.txt index 4cd083ab90..04ed28e10f 100644 --- a/rpcs3/Emu/CMakeLists.txt +++ b/rpcs3/Emu/CMakeLists.txt @@ -172,6 +172,7 @@ target_link_libraries(rpcs3_emu # Cell target_sources(rpcs3_emu PRIVATE + Cell/ErrorCodes.cpp Cell/MFC.cpp Cell/PPUAnalyser.cpp Cell/PPUDisAsm.cpp diff --git a/rpcs3/Emu/Cell/ErrorCodes.cpp b/rpcs3/Emu/Cell/ErrorCodes.cpp new file mode 100644 index 0000000000..f81fe16a61 --- /dev/null +++ b/rpcs3/Emu/Cell/ErrorCodes.cpp @@ -0,0 +1,91 @@ +#include "stdafx.h" +#include "ErrorCodes.h" +#include "PPUThread.h" +#include "SPUThread.h" + +LOG_CHANNEL(sys_log, "SYS"); + +bool g_log_all_errors = false; + +s32 error_code::error_report(s32 result, const logs::message* channel, const char* fmt, const fmt_type_info* sup, const u64* args) +{ + static thread_local std::string g_tls_error_str; + static thread_local std::unordered_map g_tls_error_stats; + + if (!channel) + { + channel = &sys_log.error; + } + + if (!sup && !args) + { + if (!fmt) + { + // Report and clean error state + for (auto&& pair : g_tls_error_stats) + { + if (pair.second > 3) + { + channel->operator()("Stat: %s [x%u]", pair.first, pair.second); + } + } + + g_tls_error_stats.clear(); + return 0; + } + } + + ensure(fmt); + + const char* func = "Unknown function"; + + if (auto ppu = get_current_cpu_thread()) + { + if (auto current = ppu->current_function) + { + func = current; + } + } + else if (auto spu = get_current_cpu_thread()) + { + if (auto current = spu->current_func; current && spu->start_time) + { + func = current; + } + } + + // Format log message (use preallocated buffer) + g_tls_error_str.clear(); + + fmt::append(g_tls_error_str, "'%s' failed with 0x%08x", func, result); + + // Add spacer between error and fmt if necessary + if (fmt[0] != ' ') + g_tls_error_str += " : "; + + fmt::raw_append(g_tls_error_str, fmt, sup, args); + + // Update stats and check log threshold + + if (g_log_all_errors) [[unlikely]] + { + if (!g_tls_error_stats.empty()) + { + // Report and clean error state + error_report(0, nullptr, nullptr, nullptr, nullptr); + } + + channel->operator()("%s", g_tls_error_str); + } + else + { + const auto stat = ++g_tls_error_stats[g_tls_error_str]; + + if (stat <= 3) + { + channel->operator()("%s [%u]", g_tls_error_str, stat); + } + } + + return result; +} diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index ced67c8a7e..e7c01608d3 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -67,8 +67,6 @@ LOG_CHANNEL(sys_log, "SYS"); // Preallocate 32 MiB stx::manual_typemap g_fixed_typemap; -bool g_log_all_errors = false; - bool g_use_rtm = false; u64 g_rtm_tx_limit1 = 0; u64 g_rtm_tx_limit2 = 0; @@ -3892,89 +3890,6 @@ std::string Emulator::GetFormattedTitle(double fps) const return rpcs3::get_formatted_title(title_data); } -s32 error_code::error_report(s32 result, const logs::message* channel, const char* fmt, const fmt_type_info* sup, const u64* args) -{ - static thread_local std::string g_tls_error_str; - static thread_local std::unordered_map g_tls_error_stats; - - if (!channel) - { - channel = &sys_log.error; - } - - if (!sup && !args) - { - if (!fmt) - { - // Report and clean error state - for (auto&& pair : g_tls_error_stats) - { - if (pair.second > 3) - { - channel->operator()("Stat: %s [x%u]", pair.first, pair.second); - } - } - - g_tls_error_stats.clear(); - return 0; - } - } - - ensure(fmt); - - const char* func = "Unknown function"; - - if (auto ppu = get_current_cpu_thread()) - { - if (auto current = ppu->current_function) - { - func = current; - } - } - else if (auto spu = get_current_cpu_thread()) - { - if (auto current = spu->current_func; current && spu->start_time) - { - func = current; - } - } - - // Format log message (use preallocated buffer) - g_tls_error_str.clear(); - - fmt::append(g_tls_error_str, "'%s' failed with 0x%08x", func, result); - - // Add spacer between error and fmt if necessary - if (fmt[0] != ' ') - g_tls_error_str += " : "; - - fmt::raw_append(g_tls_error_str, fmt, sup, args); - - // Update stats and check log threshold - - if (g_log_all_errors) [[unlikely]] - { - if (!g_tls_error_stats.empty()) - { - // Report and clean error state - error_report(0, nullptr, nullptr, nullptr, nullptr); - } - - channel->operator()("%s", g_tls_error_str); - } - else - { - const auto stat = ++g_tls_error_stats[g_tls_error_str]; - - if (stat <= 3) - { - channel->operator()("%s [%u]", g_tls_error_str, stat); - } - } - - return result; -} - void Emulator::ConfigurePPUCache() const { auto& _main = g_fxo->get>(); diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 2934253b39..bd127aff4f 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -468,8 +468,6 @@ public: extern Emulator Emu; -extern bool g_log_all_errors; - extern bool g_use_rtm; extern u64 g_rtm_tx_limit1; extern u64 g_rtm_tx_limit2; diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index 0c54d02978..6834ed5530 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -66,6 +66,7 @@ true + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index 90df56b77e..f36b57bb03 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -1327,6 +1327,9 @@ Emu\Audio + + Emu\Cell +