Fix issues with savestates and non-buffered rendering

This commit is contained in:
Henrik Rydgård 2024-10-17 21:09:04 +02:00
parent 858f37b8fc
commit b43abd2015
4 changed files with 17 additions and 8 deletions

View File

@ -913,25 +913,26 @@ namespace SaveState
return Status::SUCCESS; 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(); rewindStates.Process();
if (!needsProcess) if (!needsProcess)
return; return false;
needsProcess = false; needsProcess = false;
if (!__KernelIsRunning()) if (!__KernelIsRunning())
{ {
ERROR_LOG(Log::SaveState, "Savestate failure: Unable to load without kernel, this should never happen."); ERROR_LOG(Log::SaveState, "Savestate failure: Unable to load without kernel, this should never happen.");
return; return false;
} }
std::vector<Operation> operations = Flush(); std::vector<Operation> operations = Flush();
SaveStart state; 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]; Operation &op = operations[i];
CChunkFileReader::Error result; CChunkFileReader::Error result;
Status callbackResult; Status callbackResult;
@ -1068,6 +1069,7 @@ namespace SaveState
} else { } else {
screenshotFailures = 0; screenshotFailures = 0;
} }
readbackImage = true;
break; break;
} }
default: default:
@ -1083,6 +1085,8 @@ namespace SaveState
// Avoid triggering frame skipping due to slowdown // Avoid triggering frame skipping due to slowdown
__DisplaySetWasPaused(); __DisplaySetWasPaused();
} }
return readbackImage;
} }
void NotifySaveData() { void NotifySaveData() {

View File

@ -104,7 +104,7 @@ namespace SaveState
bool IsOldVersion(); bool IsOldVersion();
// Check if there's any save stating needing to be done. Normally called once per frame. // 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. // Notify save state code that new save data has been written.
void NotifySaveData(); void NotifySaveData();

View File

@ -623,7 +623,6 @@ void PSP_RunLoopWhileState() {
} }
void PSP_RunLoopUntil(u64 globalticks) { void PSP_RunLoopUntil(u64 globalticks) {
SaveState::Process();
if (coreState == CORE_POWERDOWN || coreState == CORE_BOOT_ERROR || coreState == CORE_RUNTIME_ERROR) { if (coreState == CORE_POWERDOWN || coreState == CORE_BOOT_ERROR || coreState == CORE_RUNTIME_ERROR) {
return; return;
} else if (coreState == CORE_STEPPING) { } else if (coreState == CORE_STEPPING) {

View File

@ -1445,6 +1445,12 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) {
uint32_t clearColor = 0; uint32_t clearColor = 0;
if (!blockedExecution) { if (!blockedExecution) {
PSP_BeginHostFrame(); 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(); PSP_RunLoopWhileState();
flags |= ScreenRenderFlags::HANDLED_THROTTLING; flags |= ScreenRenderFlags::HANDLED_THROTTLING;