diff --git a/ps2xRuntime/CMakeLists.txt b/ps2xRuntime/CMakeLists.txt index 8921b5d..2684ee5 100644 --- a/ps2xRuntime/CMakeLists.txt +++ b/ps2xRuntime/CMakeLists.txt @@ -373,6 +373,7 @@ endif() if(PS2X_ENABLE_AGRESSIVE_LOGS) target_compile_definitions(ps2_runtime PUBLIC AGRESSIVE_LOGS=1 + PS2_FUNCTION_LOG_TRACKER=1 ) endif() diff --git a/ps2xRuntime/include/ps2_log.h b/ps2xRuntime/include/ps2_log.h index 395b44d..341dfcc 100644 --- a/ps2xRuntime/include/ps2_log.h +++ b/ps2xRuntime/include/ps2_log.h @@ -12,13 +12,11 @@ #include #ifndef PS2_RUNTIME_LOGS -#define PS2_RUNTIME_LOGS 1 +#define PS2_RUNTIME_LOGS 0 #endif -#if defined(AGRESSIVE_LOGS) -#define PS2_AGRESSIVE_LOGS_ENABLED 1 -#else -#define PS2_AGRESSIVE_LOGS_ENABLED 0 +#ifndef AGRESSIVE_LOGS +#define AGRESSIVE_LOGS 0 #endif namespace ps2_log @@ -106,7 +104,7 @@ inline void clear_runtime_log_entries() } } -#if defined(PS2_RUNTIME_LOGS) || defined(AGRESSIVE_LOGS) +#if PS2_RUNTIME_LOGS || AGRESSIVE_LOGS #define RUNTIME_LOG(x) \ do \ { \ @@ -127,12 +125,10 @@ inline void clear_runtime_log_entries() #define RUNTIME_LOG(x) do {} while(0) #endif -#ifdef AGRESSIVE_LOGS +#if AGRESSIVE_LOGS namespace ps2_log { -inline constexpr bool agressive_logs_enabled = PS2_AGRESSIVE_LOGS_ENABLED != 0; - inline std::string log_path() { static std::string path; @@ -181,17 +177,13 @@ inline void print_saved_location() #define PS2_IF_AGRESSIVE_LOGS(code) \ do \ { \ - if constexpr (ps2_log::agressive_logs_enabled) \ - { \ - code; \ - } \ + code; \ } while (0) #else namespace ps2_log { -inline constexpr bool agressive_logs_enabled = false; inline std::string log_path() { return (std::filesystem::current_path() / "ps2_log.txt").string(); diff --git a/ps2xRuntime/include/runtime/ps2_gs_gpu.h b/ps2xRuntime/include/runtime/ps2_gs_gpu.h index 40b9459..1991f95 100644 --- a/ps2xRuntime/include/runtime/ps2_gs_gpu.h +++ b/ps2xRuntime/include/runtime/ps2_gs_gpu.h @@ -344,7 +344,6 @@ public: void setDebugHistoryPaused(bool paused); bool getPreferredDisplaySource(GSFrameReg &outSource, uint32_t &outDestFbp) const; void latchHostPresentationFrame(); - bool tryLatchHostPresentationFrame(); bool copyLatchedHostPresentationFrame(std::vector &outPixels, uint32_t &outWidth, uint32_t &outHeight, @@ -456,7 +455,7 @@ private: uint64_t m_debugNextSeq = 1; uint32_t m_debugFrameIndex = 0; uint64_t m_debugLastVsyncTick = UINT64_MAX; - bool m_debugHistoryPaused = false; + bool m_debugHistoryPaused = true; GSRasterizer m_rasterizer; diff --git a/ps2xRuntime/src/lib/Kernel/Stubs/MPEG.cpp b/ps2xRuntime/src/lib/Kernel/Stubs/MPEG.cpp index 8bd093f..c9f5029 100644 --- a/ps2xRuntime/src/lib/Kernel/Stubs/MPEG.cpp +++ b/ps2xRuntime/src/lib/Kernel/Stubs/MPEG.cpp @@ -41,7 +41,11 @@ namespace ps2_stubs { static std::once_flag s_once; std::call_once(s_once, [] { - av_log_set_level(ps2_log::agressive_logs_enabled ? AV_LOG_WARNING : AV_LOG_ERROR); +#if AGRESSIVE_LOGS + av_log_set_level(AV_LOG_WARNING); +#else + av_log_set_level(AV_LOG_ERROR); +#endif }); } diff --git a/ps2xRuntime/src/lib/Kernel/Syscalls/System.cpp b/ps2xRuntime/src/lib/Kernel/Syscalls/System.cpp index e6ec466..c6e0647 100644 --- a/ps2xRuntime/src/lib/Kernel/Syscalls/System.cpp +++ b/ps2xRuntime/src/lib/Kernel/Syscalls/System.cpp @@ -857,11 +857,9 @@ namespace ps2_syscalls const FindAddressMatchSample *matches, uint32_t matchCount) { - if constexpr (!ps2_log::agressive_logs_enabled) - { - return; - } - +#if !AGRESSIVE_LOGS + return; +#else static std::atomic s_findAddressHitLogs{0u}; static std::atomic s_findAddressMissLogs{0u}; constexpr uint32_t kMaxFindAddressHitLogs = 16u; @@ -942,6 +940,7 @@ namespace ps2_syscalls std::cerr << std::dec; } std::cerr << std::endl; +#endif } // 0x83 FindAddress: diff --git a/ps2xRuntime/src/lib/ps2_gs_gpu.cpp b/ps2xRuntime/src/lib/ps2_gs_gpu.cpp index d97e564..f1f2bde 100644 --- a/ps2xRuntime/src/lib/ps2_gs_gpu.cpp +++ b/ps2xRuntime/src/lib/ps2_gs_gpu.cpp @@ -642,6 +642,11 @@ void GS::recordDebugEventUnlocked(GSDebugHistoryEntry entry) void GS::recordGifTagDebugEventUnlocked(uint32_t sizeBytes, uint32_t nloop, uint8_t flg, uint32_t nreg) { + if (m_debugHistoryPaused) + { + return; + } + GSDebugHistoryEntry entry = makeDebugEventUnlocked(GSDebugEventKind::GifTag); entry.gifSizeBytes = sizeBytes; entry.gifNloop = nloop; @@ -652,6 +657,11 @@ void GS::recordGifTagDebugEventUnlocked(uint32_t sizeBytes, uint32_t nloop, uint void GS::recordRegisterDebugEventUnlocked(uint8_t regAddr, uint64_t value) { + if (m_debugHistoryPaused) + { + return; + } + switch (regAddr) { case GS_REG_PRIM: @@ -690,6 +700,11 @@ void GS::recordRegisterDebugEventUnlocked(uint8_t regAddr, uint64_t value) void GS::recordDrawDebugEventUnlocked(int vertexCount) { + if (m_debugHistoryPaused) + { + return; + } + if (vertexCount <= 0) { return; @@ -722,6 +737,11 @@ void GS::recordDrawDebugEventUnlocked(int vertexCount) void GS::recordTransferDebugEventUnlocked() { + if (m_debugHistoryPaused) + { + return; + } + GSDebugHistoryEntry entry = makeDebugEventUnlocked(GSDebugEventKind::Transfer); entry.transferPixels = m_transferState.total_pixels; recordDebugEventUnlocked(entry); @@ -729,6 +749,11 @@ void GS::recordTransferDebugEventUnlocked() void GS::recordPresentDebugEventUnlocked(uint32_t displayFbp, uint32_t sourceFbp, uint32_t width, uint32_t height, bool usedPreferred) { + if (m_debugHistoryPaused) + { + return; + } + GSDebugHistoryEntry entry = makeDebugEventUnlocked(GSDebugEventKind::Present); entry.displayFbp = displayFbp; entry.sourceFbp = sourceFbp; @@ -918,18 +943,6 @@ void GS::latchHostPresentationFrame() latchHostPresentationFrameUnlocked(); } -bool GS::tryLatchHostPresentationFrame() -{ - if (!m_stateMutex.try_lock()) - { - return false; - } - - std::lock_guard lock(m_stateMutex, std::adopt_lock); - latchHostPresentationFrameUnlocked(); - return true; -} - void GS::latchHostPresentationFrameUnlocked() { if (!m_privRegs || !m_vram || m_vramSize == 0u) diff --git a/ps2xRuntime/src/lib/ps2_runtime.cpp b/ps2xRuntime/src/lib/ps2_runtime.cpp index 667a6d3..17bcb17 100644 --- a/ps2xRuntime/src/lib/ps2_runtime.cpp +++ b/ps2xRuntime/src/lib/ps2_runtime.cpp @@ -371,21 +371,14 @@ static void UploadFrame(Texture2D &tex, PS2Runtime *rt, uint32_t &outWidth, uint static std::vector s_uploadBuffer(DEFAULT_FB_SIZE, 0u); const uint64_t currentTick = ps2_syscalls::GetCurrentVSyncTick(); - bool latchedThisCall = false; - if (!s_hasLatchedInitialFrame) + const bool needsLatch = !s_hasLatchedInitialFrame || currentTick != s_lastPresentationTick; + if (needsLatch) { rt->gs().latchHostPresentationFrame(); s_lastPresentationTick = currentTick; s_hasLatchedInitialFrame = true; - latchedThisCall = true; } - else if (currentTick != s_lastPresentationTick && rt->gs().tryLatchHostPresentationFrame()) - { - s_lastPresentationTick = currentTick; - latchedThisCall = true; - } - - if (!latchedThisCall && s_hasUploadedFrame) + else if (s_hasUploadedFrame) { outWidth = (s_lastWidth != 0u) ? s_lastWidth : FB_WIDTH; outHeight = (s_lastHeight != 0u) ? s_lastHeight : DEFAULT_DISPLAY_HEIGHT;