Skip to content

Commit

Permalink
Vulkan: Fix minor vulkan resource leak if inflight frames isn't max.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Mar 8, 2020
1 parent 1712563 commit b0b9e24
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ext/native/thin3d/VulkanRenderManager.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions ext/native/thin3d/VulkanRenderManager.h
Expand Up @@ -307,6 +307,7 @@ class VulkanRenderManager {

FrameData frameData_[VulkanContext::MAX_INFLIGHT_FRAMES];
int newInflightFrames_ = -1;
int inflightFramesAtStart_ = 0;

// Submission time state
int curWidth_ = -1;
Expand Down

0 comments on commit b0b9e24

Please sign in to comment.