System: Handle GPU device loss in BP-only mode

This commit is contained in:
Stenzek 2024-11-10 15:48:41 +10:00
parent 5b600789d6
commit 8611f4f438
No known key found for this signature in database
1 changed files with 30 additions and 13 deletions

View File

@ -1256,6 +1256,8 @@ void System::HandleHostGPUDeviceLost()
} }
s_last_gpu_reset_time = current_time; s_last_gpu_reset_time = current_time;
if (g_gpu)
{
// Little bit janky, but because the device is lost, the VRAM readback is going to give us garbage. // Little bit janky, but because the device is lost, the VRAM readback is going to give us garbage.
// So back up what we have, it's probably missing bits, but whatever... // So back up what we have, it's probably missing bits, but whatever...
DynamicHeapArray<u8> vram_backup(VRAM_SIZE); DynamicHeapArray<u8> vram_backup(VRAM_SIZE);
@ -1265,12 +1267,27 @@ void System::HandleHostGPUDeviceLost()
// Let's just toss out everything, and try to hobble on. // Let's just toss out everything, and try to hobble on.
if (!RecreateGPU(g_gpu->IsHardwareRenderer() ? g_settings.gpu_renderer : GPURenderer::Software, true, false)) if (!RecreateGPU(g_gpu->IsHardwareRenderer() ? g_settings.gpu_renderer : GPURenderer::Software, true, false))
{ {
Panic("Failed to recreate GS device after loss."); Panic("Failed to recreate GPU device after loss.");
return; return;
} }
// Restore backed-up VRAM. // Restore backed-up VRAM.
std::memcpy(g_vram, vram_backup.data(), VRAM_SIZE); std::memcpy(g_vram, vram_backup.data(), VRAM_SIZE);
}
else
{
// Only big picture mode was running.
const bool fsui_running = FullscreenUI::IsInitialized();
const bool fullscreen = Host::IsFullscreen();
const RenderAPI api = g_gpu_device->GetRenderAPI();
Host::ReleaseGPUDevice();
Host::ReleaseRenderWindow();
if (!Host::CreateGPUDevice(api, fullscreen, nullptr) || (fsui_running && !FullscreenUI::Initialize()))
{
Panic("Failed to recreate GPU device after loss.");
return;
}
}
// First frame after reopening is definitely going to be trash, so skip it. // First frame after reopening is definitely going to be trash, so skip it.
Host::AddIconOSDWarning( Host::AddIconOSDWarning(