System: Restore/reset state on recreating GPU/updating settings

Fixes display corruption on RetroArch when switching renderers.
This commit is contained in:
Connor McLaughlin 2020-08-06 23:19:52 +10:00
parent 359234080a
commit e5c46a54b7
2 changed files with 12 additions and 0 deletions

View file

@ -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()

View file

@ -222,6 +222,8 @@ ConsoleRegion GetConsoleRegionForDiscRegion(DiscRegion region)
bool RecreateGPU(GPURenderer renderer)
{
g_gpu->RestoreGraphicsAPIState();
// save current state
std::unique_ptr<ByteStream> 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;