From e5c46a54b74bcdc8eb51618b8c2685ef0fb59a20 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 6 Aug 2020 23:19:52 +1000 Subject: [PATCH] System: Restore/reset state on recreating GPU/updating settings Fixes display corruption on RetroArch when switching renderers. --- src/core/host_interface.cpp | 6 ++++++ src/core/system.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 6e945922c..2f9d6cdc6 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -487,7 +487,9 @@ void HostInterface::CheckForSettingsChanges(const Settings& old_settings) g_settings.display_crop_mode != old_settings.display_crop_mode || g_settings.display_aspect_ratio != old_settings.display_aspect_ratio) { + g_gpu->RestoreGraphicsAPIState(); g_gpu->UpdateSettings(); + g_gpu->ResetGraphicsAPIState(); } if (g_settings.gpu_pgxp_enable != old_settings.gpu_pgxp_enable || @@ -662,7 +664,11 @@ void HostInterface::ModifyResolutionScale(s32 increment) GPU::VRAM_HEIGHT * g_settings.gpu_resolution_scale); if (!System::IsShutdown()) + { + g_gpu->RestoreGraphicsAPIState(); g_gpu->UpdateSettings(); + g_gpu->ResetGraphicsAPIState(); + } } void HostInterface::UpdateSoftwareCursor() diff --git a/src/core/system.cpp b/src/core/system.cpp index 661a26fa1..f1b40e436 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -222,6 +222,8 @@ ConsoleRegion GetConsoleRegionForDiscRegion(DiscRegion region) bool RecreateGPU(GPURenderer renderer) { + g_gpu->RestoreGraphicsAPIState(); + // save current state std::unique_ptr state_stream = ByteStream_CreateGrowableMemoryStream(); StateWrapper sw(state_stream.get(), StateWrapper::Mode::Write); @@ -229,6 +231,8 @@ bool RecreateGPU(GPURenderer renderer) if (!state_valid) Log_ErrorPrintf("Failed to save old GPU state when switching renderers"); + g_gpu->ResetGraphicsAPIState(); + // create new renderer g_gpu.reset(); if (!CreateGPU(renderer)) @@ -241,8 +245,10 @@ bool RecreateGPU(GPURenderer renderer) { state_stream->SeekAbsolute(0); sw.SetMode(StateWrapper::Mode::Read); + g_gpu->RestoreGraphicsAPIState(); g_gpu->DoState(sw); TimingEvents::DoState(sw, TimingEvents::GetGlobalTickCounter()); + g_gpu->ResetGraphicsAPIState(); } return true;