From 3757070fe27d48690448d61ccb52231f9d2dab9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 9 Oct 2017 12:17:54 +0200 Subject: [PATCH] Extra safety when switching GPU backends, fix possible Vulkan shutdown issue. Should help #10005 --- Common/Vulkan/VulkanMemory.cpp | 1 + GPU/Vulkan/TextureCacheVulkan.cpp | 17 +++++++++++------ UI/GameSettingsScreen.cpp | 3 +++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Common/Vulkan/VulkanMemory.cpp b/Common/Vulkan/VulkanMemory.cpp index da2f7f899b..c6db161c8a 100644 --- a/Common/Vulkan/VulkanMemory.cpp +++ b/Common/Vulkan/VulkanMemory.cpp @@ -143,6 +143,7 @@ void VulkanDeviceAllocator::Destroy() { } } + assert(slab.deviceMemory); vulkan_->Delete().QueueDeleteDeviceMemory(slab.deviceMemory); } slabs_.clear(); diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index e23324966e..11e930399d 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -135,13 +135,16 @@ TextureCacheVulkan::TextureCacheVulkan(Draw::DrawContext *draw, VulkanContext *v TextureCacheVulkan::~TextureCacheVulkan() { Clear(true); - allocator_->Destroy(); - // We have to delete on queue, so this can free its queued deletions. - vulkan_->Delete().QueueCallback([](void *ptr) { - auto allocator = static_cast(ptr); - delete allocator; - }, allocator_); + if (allocator_) { + allocator_->Destroy(); + + // We have to delete on queue, so this can free its queued deletions. + vulkan_->Delete().QueueCallback([](void *ptr) { + auto allocator = static_cast(ptr); + delete allocator; + }, allocator_); + } } void TextureCacheVulkan::SetFramebufferManager(FramebufferManagerVulkan *fbManager) { @@ -171,6 +174,8 @@ void TextureCacheVulkan::DeviceLost() { void TextureCacheVulkan::DeviceRestore(VulkanContext *vulkan) { vulkan_ = vulkan; + assert(!allocator_); + allocator_ = new VulkanDeviceAllocator(vulkan_, TEXCACHE_MIN_SLAB_SIZE, TEXCACHE_MAX_SLAB_SIZE); samplerCache_.DeviceRestore(vulkan); } diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index d30aebb853..5baed5463e 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1083,6 +1083,9 @@ void GameSettingsScreen::CallbackRenderingBackend(bool yes) { // If the user ends up deciding not to restart, set the config back to the current backend // so it doesn't get switched by accident. if (yes) { + // Extra save here to make sure the choice really gets saved even if there are shutdown bugs in + // the GPU backend code. + g_Config.Save(); System_SendMessage("graphics_restart", ""); } else { g_Config.iGPUBackend = (int)GetGPUBackend();