diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index 8990177c70..00409ab23f 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -199,6 +199,14 @@ VKRGraphicsPipeline::~VKRGraphicsPipeline() { desc->Release(); } +void VKRGraphicsPipeline::BlockUntilCompiled() { + for (size_t i = 0; i < (size_t)RenderPassType::TYPE_COUNT; i++) { + if (pipeline[i]) { + pipeline[i]->BlockUntilReady(); + } + } +} + void VKRGraphicsPipeline::QueueForDeletion(VulkanContext *vulkan) { // Can't destroy variants here, the pipeline still lives for a while. vulkan->Delete().QueueCallback([](VulkanContext *vulkan, void *p) { diff --git a/Common/GPU/Vulkan/VulkanRenderManager.h b/Common/GPU/Vulkan/VulkanRenderManager.h index 1c912cd0fe..16c7123f6b 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.h +++ b/Common/GPU/Vulkan/VulkanRenderManager.h @@ -131,6 +131,10 @@ struct VKRGraphicsPipeline { // This deletes the whole VKRGraphicsPipeline, you must remove your last pointer to it when doing this. void QueueForDeletion(VulkanContext *vulkan); + // This blocks until any background compiles are finished. + // Used during game shutdown before we clear out shaders that these compiles depend on. + void BlockUntilCompiled(); + u32 GetVariantsBitmask() const; void LogCreationFailure() const; diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 6846a1d52e..ae3f4d9d13 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -186,12 +186,16 @@ GPU_Vulkan::~GPU_Vulkan() { } SaveCache(shaderCachePath_); + + // Super important to delete pipeline manager FIRST, before clearing shaders, so we wait for all pending pipelines to finish compiling. + delete pipelineManager_; + pipelineManager_ = nullptr; + // Note: We save the cache in DeviceLost DestroyDeviceObjects(); drawEngine_.DeviceLost(); shaderManager_->ClearShaders(); - delete pipelineManager_; // other managers are deleted in ~GPUCommonHW. if (draw_) { diff --git a/GPU/Vulkan/PipelineManagerVulkan.cpp b/GPU/Vulkan/PipelineManagerVulkan.cpp index dea7a0201a..43f67709da 100644 --- a/GPU/Vulkan/PipelineManagerVulkan.cpp +++ b/GPU/Vulkan/PipelineManagerVulkan.cpp @@ -29,6 +29,15 @@ PipelineManagerVulkan::PipelineManagerVulkan(VulkanContext *vulkan) : pipelines_ } PipelineManagerVulkan::~PipelineManagerVulkan() { + // Block on all pipelines to make sure any background compiles are done. + // This is very important to do before we start trying to tear down the shaders - otherwise, we might + // be deleting shaders before queued pipeline creations that use them are performed. + pipelines_.Iterate([&](const VulkanPipelineKey &key, VulkanPipeline *value) { + if (value->pipeline) { + value->pipeline->BlockUntilCompiled(); + } + }); + Clear(); if (pipelineCache_ != VK_NULL_HANDLE) vulkan_->Delete().QueueDeletePipelineCache(pipelineCache_);