From b43abd201556a307f4099445c1c04fcf6fd5d9d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 17 Oct 2024 21:09:04 +0200 Subject: [PATCH] Fix issues with savestates and non-buffered rendering --- Core/SaveState.cpp | 16 ++++++++++------ Core/SaveState.h | 2 +- Core/System.cpp | 1 - UI/EmuScreen.cpp | 6 ++++++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index 9b713943c3..bc3950e15c 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -913,25 +913,26 @@ namespace SaveState return Status::SUCCESS; } - void Process() - { + // NOTE: This can cause ending of the current renderpass, due to the readback needed for the screenshot. + bool Process() { rewindStates.Process(); if (!needsProcess) - return; + return false; needsProcess = false; if (!__KernelIsRunning()) { ERROR_LOG(Log::SaveState, "Savestate failure: Unable to load without kernel, this should never happen."); - return; + return false; } std::vector operations = Flush(); SaveStart state; - for (size_t i = 0, n = operations.size(); i < n; ++i) - { + bool readbackImage = false; + + for (size_t i = 0, n = operations.size(); i < n; ++i) { Operation &op = operations[i]; CChunkFileReader::Error result; Status callbackResult; @@ -1068,6 +1069,7 @@ namespace SaveState } else { screenshotFailures = 0; } + readbackImage = true; break; } default: @@ -1083,6 +1085,8 @@ namespace SaveState // Avoid triggering frame skipping due to slowdown __DisplaySetWasPaused(); } + + return readbackImage; } void NotifySaveData() { diff --git a/Core/SaveState.h b/Core/SaveState.h index b059725d52..32431218ef 100644 --- a/Core/SaveState.h +++ b/Core/SaveState.h @@ -104,7 +104,7 @@ namespace SaveState bool IsOldVersion(); // Check if there's any save stating needing to be done. Normally called once per frame. - void Process(); + bool Process(); // Notify save state code that new save data has been written. void NotifySaveData(); diff --git a/Core/System.cpp b/Core/System.cpp index 155c3bbba3..9bca1c1705 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -623,7 +623,6 @@ void PSP_RunLoopWhileState() { } void PSP_RunLoopUntil(u64 globalticks) { - SaveState::Process(); if (coreState == CORE_POWERDOWN || coreState == CORE_BOOT_ERROR || coreState == CORE_RUNTIME_ERROR) { return; } else if (coreState == CORE_STEPPING) { diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index f374228b64..202dc5052a 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1445,6 +1445,12 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) { uint32_t clearColor = 0; if (!blockedExecution) { PSP_BeginHostFrame(); + if (SaveState::Process()) { + // We might have lost the framebuffer bind if we had one, due to a readback. + if (framebufferBound) { + draw->BindFramebufferAsRenderTarget(nullptr, { RPAction::CLEAR, RPAction::CLEAR, RPAction::CLEAR, clearColor }, "EmuScreen_SavestateRebind"); + } + } PSP_RunLoopWhileState(); flags |= ScreenRenderFlags::HANDLED_THROTTLING;