diff --git a/Common/GPU/Vulkan/VulkanContext.cpp b/Common/GPU/Vulkan/VulkanContext.cpp index 8e523d0bf2b7..72bdd3dca9d5 100644 --- a/Common/GPU/Vulkan/VulkanContext.cpp +++ b/Common/GPU/Vulkan/VulkanContext.cpp @@ -761,11 +761,6 @@ VkResult VulkanContext::CreateDevice() { break; } - - for (int i = 0; i < ARRAY_SIZE(frame_); i++) { - frame_[i].profiler.Init(this); - } - return res; } @@ -909,6 +904,10 @@ VkResult VulkanContext::ReinitSurface() { return VK_ERROR_INITIALIZATION_FAILED; } + for (int i = 0; i < ARRAY_SIZE(frame_); i++) { + frame_[i].profiler.Init(this); + } + return VK_SUCCESS; } @@ -938,7 +937,7 @@ bool VulkanContext::ChooseQueue() { } if (presentQueueNodeIndex == UINT32_MAX) { // If didn't find a queue that supports both graphics and present, then - // find a separate present queue. + // find a separate present queue. NOTE: We don't actually currently support this arrangement! for (uint32_t i = 0; i < queue_count; ++i) { if (supportsPresent[i] == VK_TRUE) { presentQueueNodeIndex = i; @@ -1236,13 +1235,13 @@ void VulkanContext::DestroyDevice() { ERROR_LOG(G3D, "DestroyDevice: Surface should have been destroyed."); } - INFO_LOG(G3D, "VulkanContext::DestroyDevice (performing deletes)"); - PerformPendingDeletes(); - for (int i = 0; i < ARRAY_SIZE(frame_); i++) { frame_[i].profiler.Shutdown(); } + INFO_LOG(G3D, "VulkanContext::DestroyDevice (performing deletes)"); + PerformPendingDeletes(); + vmaDestroyAllocator(allocator_); allocator_ = VK_NULL_HANDLE; @@ -1515,6 +1514,10 @@ void VulkanDeleteList::PerformDeletes(VkDevice device, VmaAllocator allocator) { vkDestroyDescriptorSetLayout(device, descSetLayout, nullptr); } descSetLayouts_.clear(); + for (auto &queryPool : queryPools_) { + vkDestroyQueryPool(device, queryPool, nullptr); + } + queryPools_.clear(); } void VulkanContext::GetImageMemoryRequirements(VkImage image, VkMemoryRequirements *mem_reqs, bool *dedicatedAllocation) { diff --git a/Common/GPU/Vulkan/VulkanContext.h b/Common/GPU/Vulkan/VulkanContext.h index 5150e908a827..072bbfa4da5c 100644 --- a/Common/GPU/Vulkan/VulkanContext.h +++ b/Common/GPU/Vulkan/VulkanContext.h @@ -117,6 +117,7 @@ class VulkanDeleteList { void QueueDeleteFramebuffer(VkFramebuffer &framebuffer) { _dbg_assert_(framebuffer != VK_NULL_HANDLE); framebuffers_.push_back(framebuffer); framebuffer = VK_NULL_HANDLE; } void QueueDeletePipelineLayout(VkPipelineLayout &pipelineLayout) { _dbg_assert_(pipelineLayout != VK_NULL_HANDLE); pipelineLayouts_.push_back(pipelineLayout); pipelineLayout = VK_NULL_HANDLE; } void QueueDeleteDescriptorSetLayout(VkDescriptorSetLayout &descSetLayout) { _dbg_assert_(descSetLayout != VK_NULL_HANDLE); descSetLayouts_.push_back(descSetLayout); descSetLayout = VK_NULL_HANDLE; } + void QueueDeleteQueryPool(VkQueryPool &queryPool) { _dbg_assert_(queryPool != VK_NULL_HANDLE); queryPools_.push_back(queryPool); queryPool = VK_NULL_HANDLE; } void QueueCallback(void(*func)(void *userdata), void *userdata) { callbacks_.push_back(Callback(func, userdata)); } void QueueDeleteBufferAllocation(VkBuffer &buffer, VmaAllocation &alloc) { @@ -152,6 +153,7 @@ class VulkanDeleteList { std::vector framebuffers_; std::vector pipelineLayouts_; std::vector descSetLayouts_; + std::vector queryPools_; std::vector callbacks_; }; @@ -386,10 +388,11 @@ class VulkanContext { bool CheckLayers(const std::vector &layer_props, const std::vector &layer_names) const; WindowSystem winsys_; + // Don't use the real types here to avoid having to include platform-specific stuff // that we really don't want in everything that uses VulkanContext. - void *winsysData1_; - void *winsysData2_; + void *winsysData1_ = nullptr; + void *winsysData2_ = nullptr; std::function cbGetDrawSize_; VkInstance instance_ = VK_NULL_HANDLE; diff --git a/Common/GPU/Vulkan/VulkanProfiler.cpp b/Common/GPU/Vulkan/VulkanProfiler.cpp index b073b298a1d5..a31952b1bcf0 100644 --- a/Common/GPU/Vulkan/VulkanProfiler.cpp +++ b/Common/GPU/Vulkan/VulkanProfiler.cpp @@ -8,7 +8,14 @@ using namespace PPSSPP_VK; void VulkanProfiler::Init(VulkanContext *vulkan) { vulkan_ = vulkan; - validBits_ = vulkan_->GetQueueFamilyProperties(vulkan_->GetGraphicsQueueFamilyIndex()).timestampValidBits; + int graphicsQueueFamilyIndex = vulkan_->GetGraphicsQueueFamilyIndex(); + _assert_(graphicsQueueFamilyIndex >= 0); + + if (queryPool_) { + vulkan->Delete().QueueDeleteQueryPool(queryPool_); + } + + validBits_ = vulkan_->GetQueueFamilyProperties(graphicsQueueFamilyIndex).timestampValidBits; if (validBits_) { VkQueryPoolCreateInfo ci{ VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO }; @@ -20,7 +27,7 @@ void VulkanProfiler::Init(VulkanContext *vulkan) { void VulkanProfiler::Shutdown() { if (queryPool_) { - vkDestroyQueryPool(vulkan_->GetDevice(), queryPool_, nullptr); + vulkan_->Delete().QueueDeleteQueryPool(queryPool_); } }