From 00b06c365fa76fb44a1ecf12661d21d6d941df63 Mon Sep 17 00:00:00 2001 From: nyorain Date: Fri, 21 Jan 2022 16:06:11 +0100 Subject: Fix DestroyCommandPool command buffer leak --- scripts/mock_icd_generator.py | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/mock_icd_generator.py b/scripts/mock_icd_generator.py index 310e81e9..5973c005 100644 --- a/scripts/mock_icd_generator.py +++ b/scripts/mock_icd_generator.py @@ -67,6 +67,7 @@ static unordered_map allocated_memory_size_map; static unordered_map>> queue_map; static unordered_map> buffer_map; static unordered_map> image_memory_size_map; +static unordered_map> command_pool_buffer_map; static constexpr uint32_t icd_swapchain_image_count = 1; static unordered_map swapchain_image_map; @@ -444,10 +445,42 @@ CUSTOM_C_INTERCEPTS = { DestroyDispObjHandle((void*)instance); } ''', +'vkAllocateCommandBuffers': ''' + unique_lock_t lock(global_lock); + for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; ++i) { + pCommandBuffers[i] = (VkCommandBuffer)CreateDispObjHandle(); + command_pool_buffer_map[pAllocateInfo->commandPool].push_back(pCommandBuffers[i]); + } + return VK_SUCCESS; +''', 'vkFreeCommandBuffers': ''' - for (auto i = 0u; i < commandBufferCount; ++i) - if (pCommandBuffers[i]) - DestroyDispObjHandle((void*) pCommandBuffers[i]); + unique_lock_t lock(global_lock); + for (auto i = 0u; i < commandBufferCount; ++i) { + if (!pCommandBuffers[i]) { + continue; + } + + for (auto& pair : command_pool_buffer_map) { + auto& cbs = pair.second; + auto it = std::find(cbs.begin(), cbs.end(), pCommandBuffers[i]); + if (it != cbs.end()) { + cbs.erase(it); + } + } + + DestroyDispObjHandle((void*) pCommandBuffers[i]); + } +''', +'vkDestroyCommandPool': ''' + // destroy command buffers for this pool + unique_lock_t lock(global_lock); + auto it = command_pool_buffer_map.find(commandPool); + if (it != command_pool_buffer_map.end()) { + for (auto& cb : it->second) { + DestroyDispObjHandle((void*) cb); + } + command_pool_buffer_map.erase(it); + } ''', 'vkEnumeratePhysicalDevices': ''' VkResult result_code = VK_SUCCESS; @@ -1366,6 +1399,8 @@ class MockICDOutputGenerator(OutputGenerator): 'vkCreateInstance', 'vkDestroyInstance', 'vkFreeCommandBuffers', + 'vkAllocateCommandBuffers', + 'vkDestroyCommandPool', #'vkCreateDebugReportCallbackEXT', #'vkDestroyDebugReportCallbackEXT', 'vkEnumerateInstanceLayerProperties', -- cgit v1.2.3