static unordered_map<VkDevice, unordered_map<uint32_t, unordered_map<uint32_t, VkQueue>>> queue_map;
static unordered_map<VkDevice, unordered_map<VkBuffer, VkBufferCreateInfo>> buffer_map;
static unordered_map<VkDevice, unordered_map<VkImage, VkDeviceSize>> image_memory_size_map;
+static unordered_map<VkCommandPool, std::vector<VkCommandBuffer>> command_pool_buffer_map;
static constexpr uint32_t icd_swapchain_image_count = 1;
static unordered_map<VkSwapchainKHR, VkImage[icd_swapchain_image_count]> swapchain_image_map;
VkCommandPool commandPool,
const VkAllocationCallbacks* pAllocator)
{
-//Destroy object
+
+ // 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);
+ }
}
static VKAPI_ATTR VkResult VKAPI_CALL ResetCommandPool(
const VkCommandBufferAllocateInfo* pAllocateInfo,
VkCommandBuffer* pCommandBuffers)
{
+
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;
}
const VkCommandBuffer* pCommandBuffers)
{
- 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]);
+ }
}
static VKAPI_ATTR VkResult VKAPI_CALL BeginCommandBuffer(
static unordered_map<VkDevice, unordered_map<uint32_t, unordered_map<uint32_t, VkQueue>>> queue_map;
static unordered_map<VkDevice, unordered_map<VkBuffer, VkBufferCreateInfo>> buffer_map;
static unordered_map<VkDevice, unordered_map<VkImage, VkDeviceSize>> image_memory_size_map;
+static unordered_map<VkCommandPool, std::vector<VkCommandBuffer>> command_pool_buffer_map;
static constexpr uint32_t icd_swapchain_image_count = 1;
static unordered_map<VkSwapchainKHR, VkImage[icd_swapchain_image_count]> swapchain_image_map;
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;
'vkCreateInstance',
'vkDestroyInstance',
'vkFreeCommandBuffers',
+ 'vkAllocateCommandBuffers',
+ 'vkDestroyCommandPool',
#'vkCreateDebugReportCallbackEXT',
#'vkDestroyDebugReportCallbackEXT',
'vkEnumerateInstanceLayerProperties',