From b0b9e24d4eaa8af89c630c3b1d2a39c02fbc2269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 8 Mar 2020 17:03:58 +0100 Subject: [PATCH] Vulkan: Fix minor vulkan resource leak if inflight frames isn't max. --- ext/native/thin3d/VulkanRenderManager.cpp | 5 +++-- ext/native/thin3d/VulkanRenderManager.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ext/native/thin3d/VulkanRenderManager.cpp b/ext/native/thin3d/VulkanRenderManager.cpp index ab8680a59..7a639b7d4 100644 --- a/ext/native/thin3d/VulkanRenderManager.cpp +++ b/ext/native/thin3d/VulkanRenderManager.cpp @@ -113,7 +113,8 @@ VulkanRenderManager::VulkanRenderManager(VulkanContext *vulkan) : vulkan_(vulkan res = vkCreateSemaphore(vulkan_->GetDevice(), &semaphoreCreateInfo, nullptr, &renderingCompleteSemaphore_); assert(res == VK_SUCCESS); - for (int i = 0; i < vulkan_->GetInflightFrames(); i++) { + inflightFramesAtStart_ = vulkan_->GetInflightFrames(); + for (int i = 0; i < inflightFramesAtStart_; i++) { VkCommandPoolCreateInfo cmd_pool_info = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO }; cmd_pool_info.queueFamilyIndex = vulkan_->GetGraphicsQueueFamilyIndex(); cmd_pool_info.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT | VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; @@ -298,7 +299,7 @@ VulkanRenderManager::~VulkanRenderManager() { VkDevice device = vulkan_->GetDevice(); vkDestroySemaphore(device, acquireSemaphore_, nullptr); vkDestroySemaphore(device, renderingCompleteSemaphore_, nullptr); - for (int i = 0; i < vulkan_->GetInflightFrames(); i++) { + for (int i = 0; i < inflightFramesAtStart_; i++) { vkFreeCommandBuffers(device, frameData_[i].cmdPoolInit, 1, &frameData_[i].initCmd); vkFreeCommandBuffers(device, frameData_[i].cmdPoolMain, 1, &frameData_[i].mainCmd); vkDestroyCommandPool(device, frameData_[i].cmdPoolInit, nullptr); diff --git a/ext/native/thin3d/VulkanRenderManager.h b/ext/native/thin3d/VulkanRenderManager.h index 27fc2deca..ff65ad94a 100644 --- a/ext/native/thin3d/VulkanRenderManager.h +++ b/ext/native/thin3d/VulkanRenderManager.h @@ -307,6 +307,7 @@ private: FrameData frameData_[VulkanContext::MAX_INFLIGHT_FRAMES]; int newInflightFrames_ = -1; + int inflightFramesAtStart_ = 0; // Submission time state int curWidth_ = -1;