From f14551ef3329542f3ff807f6397142fd5a19c359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 30 Oct 2024 09:37:26 +0100 Subject: [PATCH 1/4] Logging improvement in NPDRMBlockDevice --- Core/FileSystems/BlockDevices.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Core/FileSystems/BlockDevices.cpp b/Core/FileSystems/BlockDevices.cpp index c5e2add3fd..4b968722d7 100644 --- a/Core/FileSystems/BlockDevices.cpp +++ b/Core/FileSystems/BlockDevices.cpp @@ -398,7 +398,7 @@ NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader) u32 psar_id; fileLoader->ReadAt(psarOffset, 4, 1, &psar_id); - INFO_LOG(Log::Loader, "NPDRM: PSAR ID: %08x"); + INFO_LOG(Log::Loader, "NPDRM: PSAR ID: %08x", psar_id); // PS1 PSAR begins with "PSISOIMG0000" if (psar_id == 'SISP') { lbaSize_ = 0; // Mark invalid @@ -424,8 +424,11 @@ NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FileLoader *fileLoader) lbaSize_ = (lbaEnd-lbaStart+1); // LBA size of ISO blockLBAs_ = *(u32*)(np_header+0x0c); // block size in LBA + char psarStr[5] = {}; + memcpy(psarStr, &psar_id, 4); + // Protect against a badly decrypted header, and send information through the assert about what's being played (implicitly). - _assert_msg_(blockLBAs_ <= 4096, "Bad blockLBAs in header: %08x (%s)", blockLBAs_, fileLoader->GetPath().ToVisualString().c_str()); + _assert_msg_(blockLBAs_ <= 4096, "Bad blockLBAs in header: %08x (%s) psar: %s", blockLBAs_, fileLoader->GetPath().ToVisualString().c_str(), psarStr); // When we remove the above assert, let's just try to survive. if (blockLBAs_ > 4096) { From 2adbc231f0b3ffd8f5b81b72a8e025b0ce7d8fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 31 Oct 2024 23:09:47 +0100 Subject: [PATCH 2/4] EmuScreen: Turn the pass asserts into dbg_asserts and add safe workarounds --- UI/EmuScreen.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 2fe797db2e..b396f2157f 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1398,7 +1398,11 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) { Draw::BackendState state = draw->GetCurrentBackendState(); if (state.valid) { - _assert_msg_(state.passes >= 1, "skipB: %d sw: %d mode: %d back: %d tag: %s", (int)skipBufferEffects, (int)g_Config.bSoftwareRendering, (int)mode, (int)g_Config.iGPUBackend, screenManager()->topScreen()->tag()); + _dbg_assert_msg_(state.passes >= 1, "skipB: %d sw: %d mode: %d back: %d tag: %s", (int)skipBufferEffects, (int)g_Config.bSoftwareRendering, (int)mode, (int)g_Config.iGPUBackend, screenManager()->topScreen()->tag()); + // Workaround any remaining bugs like this. + if (state.passes == 0) { + draw->BindFramebufferAsRenderTarget(nullptr, { RPAction::CLEAR, RPAction::CLEAR, RPAction::CLEAR, }, "EmuScreen_SafeFallback"); + } } // Need to make sure the UI texture is available, for "darken". @@ -1527,7 +1531,11 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) { // State.valid just states whether the passes parameter has a meaningful value. if (state.valid) { - _assert_msg_(state.passes >= 1, "skipB: %d sw: %d mode: %d back: %d bound: %d", (int)skipBufferEffects, (int)g_Config.bSoftwareRendering, (int)mode, (int)g_Config.iGPUBackend, (int)framebufferBound); + _dbg_assert_msg_(state.passes >= 1, "skipB: %d sw: %d mode: %d back: %d bound: %d", (int)skipBufferEffects, (int)g_Config.bSoftwareRendering, (int)mode, (int)g_Config.iGPUBackend, (int)framebufferBound); + if (state.passes == 0) { + // Workaround any remaining bugs like this. + draw->BindFramebufferAsRenderTarget(nullptr, { RPAction::CLEAR, RPAction::CLEAR, RPAction::CLEAR, }, "EmuScreen_SafeFallback"); + } } screenManager()->getUIContext()->BeginFrame(); From f690cb99a41e41bd63dbedc2900f148de5869030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 31 Oct 2024 23:15:08 +0100 Subject: [PATCH 3/4] If upnp is disabled, poll the check less aggressively. TODO: should wait for a cond instead. --- Core/Util/PortManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/Util/PortManager.cpp b/Core/Util/PortManager.cpp index d3221242a8..0f6112970d 100644 --- a/Core/Util/PortManager.cpp +++ b/Core/Util/PortManager.cpp @@ -477,6 +477,9 @@ int upnpService(const unsigned int timeout) // Service Loop while (upnpServiceRunning && coreState != CORE_POWERDOWN) { + // Sleep for 1ms for faster response if active, otherwise sleep longer (TODO: Improve on this). + sleep_ms(g_Config.bEnableUPnP ? 1 : 100); + // Attempts to reconnect if not connected yet or got disconnected if (g_Config.bEnableUPnP && g_PortManager.GetInitState() == UPNP_INITSTATE_NONE) { g_PortManager.Initialize(timeout); @@ -506,9 +509,6 @@ int upnpService(const unsigned int timeout) upnpLock.unlock(); } } - - // Sleep for 1ms for faster response - sleep_ms(1); } // Cleaning up regardless of g_Config.bEnableUPnP to prevent lingering open ports on the router From e93427c433bd750ab97c3064e94098eb10d0669f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 31 Oct 2024 23:56:36 +0100 Subject: [PATCH 4/4] CPU_Init: Bail out earlier if we fail to identify a file. --- Common/File/AndroidStorage.cpp | 8 ++++++++ Core/System.cpp | 4 ++-- android/src/org/ppsspp/ppsspp/PpssppActivity.java | 3 +-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Common/File/AndroidStorage.cpp b/Common/File/AndroidStorage.cpp index 2ec63fb47c..2325657c79 100644 --- a/Common/File/AndroidStorage.cpp +++ b/Common/File/AndroidStorage.cpp @@ -6,6 +6,7 @@ #include "Common/TimeUtil.h" #include "android/jni/app-android.h" +#include "Common/Thread/ThreadUtil.h" #if PPSSPP_PLATFORM(ANDROID) && !defined(__LIBRETRO__) @@ -70,6 +71,13 @@ int Android_OpenContentUriFd(std::string_view filename, Android_OpenContentUriMo return -1; } + /* + // Should breakpoint here to try to find and move as many of these off the EmuThread as possible + if (!strcmp(GetCurrentThreadName(), "EmuThread")) { + WARN_LOG(Log::IO, "Content URI opened on EmuThread: %.*s", (int)filename.size(), filename.data()); + } + */ + std::string fname(filename); // PPSSPP adds an ending slash to directories before looking them up. // TODO: Fix that in the caller (or don't call this for directories). diff --git a/Core/System.cpp b/Core/System.cpp index 6764e6901c..2cf51d96c4 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -289,8 +289,8 @@ bool CPU_Init(std::string *errorString, FileLoader *loadedFile) { break; default: // Can we even get here? - WARN_LOG(Log::Loader, "CPU_Init didn't recognize file. %s", errorString->c_str()); - break; + ERROR_LOG(Log::Loader, "CPU_Init didn't recognize file. %s", errorString->c_str()); + return false; } // Here we have read the PARAM.SFO, let's see if we need any compatibility overrides. diff --git a/android/src/org/ppsspp/ppsspp/PpssppActivity.java b/android/src/org/ppsspp/ppsspp/PpssppActivity.java index af45a2d75d..e6a3ac3aa2 100644 --- a/android/src/org/ppsspp/ppsspp/PpssppActivity.java +++ b/android/src/org/ppsspp/ppsspp/PpssppActivity.java @@ -237,8 +237,7 @@ public class PpssppActivity extends NativeActivity { public long computeRecursiveDirectorySize(String uriString) { try { Uri uri = Uri.parse(uriString); - long totalSize = directorySizeRecursion(uri); - return totalSize; + return directorySizeRecursion(uri); } catch (Exception e) { Log.e(TAG, "computeRecursiveSize exception: " + e);