From d22a29a08da5e25fc43ba3478f221f128a7ed904 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 21 Jun 2016 13:24:04 +1200 Subject: layers: Untangle check & update in FreeCommandBuffers Fixes crash later in new test case Signed-off-by: Chris Forbes --- layers/core_validation.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'layers/core_validation.cpp') diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index b856c6d4..0e073a2f 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -5361,14 +5361,29 @@ static void clearCommandBuffersInFlight(layer_data *dev_data, COMMAND_POOL_NODE VKAPI_ATTR void VKAPI_CALL FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) { layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); - bool skip_call = false; std::unique_lock lock(global_lock); + for (uint32_t i = 0; i < commandBufferCount; i++) { auto cb_pair = dev_data->commandBufferMap.find(pCommandBuffers[i]); // Delete CB information structure, and remove from commandBufferMap if (cb_pair != dev_data->commandBufferMap.end()) { skip_call |= checkCommandBufferInFlight(dev_data, cb_pair->second, "free"); + } + } + lock.unlock(); + + if (skip_call) + return; + + dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers); + + lock.lock(); + auto pPool = getCommandPoolNode(dev_data, commandPool); + for (uint32_t i = 0; i < commandBufferCount; i++) { + auto cb_pair = dev_data->commandBufferMap.find(pCommandBuffers[i]); + // Delete CB information structure, and remove from commandBufferMap + if (cb_pair != dev_data->commandBufferMap.end()) { dev_data->globalInFlightCmdBuffers.erase(cb_pair->first); // reset prior to delete for data clean-up resetCB(dev_data, (*cb_pair).second->commandBuffer); @@ -5377,13 +5392,10 @@ FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandB } // Remove commandBuffer reference from commandPoolMap - dev_data->commandPoolMap[commandPool].commandBuffers.remove(pCommandBuffers[i]); + pPool->commandBuffers.remove(pCommandBuffers[i]); } printCBList(dev_data); lock.unlock(); - - if (!skip_call) - dev_data->device_dispatch_table->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers); } VKAPI_ATTR VkResult VKAPI_CALL CreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo, -- cgit v1.2.3