From ad69bb638f91659f9b2c079d9ce2bf45910f622e Mon Sep 17 00:00:00 2001 From: Tobin Ehlis Date: Wed, 12 Oct 2016 09:29:26 -0600 Subject: layers:Add validation to DestroyDescriptorPool Add validation flag for DestroyDescriptorPool and update it with validation code using the Pre/Post pattern. Flag error if descriptor pool is in use and invalidate any cmd buffers that it was bound to. Remove pool state from map when it's destroyed. When the pool is destroyed make sure all of its descriptor sets are also freed. --- layers/core_validation.cpp | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'layers/core_validation.cpp') diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index a16b699c..ac690b18 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -6084,12 +6084,44 @@ DestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetL ->dispatch_table.DestroyDescriptorSetLayout(device, descriptorSetLayout, pAllocator); } +static bool PreCallValidateDestroyDescriptorPool(layer_data *dev_data, VkDescriptorPool pool, + DESCRIPTOR_POOL_NODE **desc_pool_state, VK_OBJECT *obj_struct) { + if (dev_data->instance_state->disabled.destroy_descriptor_pool) + return false; + bool skip = false; + *desc_pool_state = getPoolNode(dev_data, pool); + if (*desc_pool_state) { + *obj_struct = {reinterpret_cast(pool), VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT}; + skip |= ValidateObjectNotInUse(dev_data, *desc_pool_state, *obj_struct); + } + return skip; +} + +static void PostCallRecordDestroyDescriptorPool(layer_data *dev_data, VkDescriptorPool descriptorPool, + DESCRIPTOR_POOL_NODE *desc_pool_state, VK_OBJECT obj_struct) { + // Any bound cmd buffers are now invalid + invalidateCommandBuffers(desc_pool_state->cb_bindings, obj_struct); + // Free sets that were in this pool + for (auto ds : desc_pool_state->sets) { + freeDescriptorSet(dev_data, ds); + } + dev_data->descriptorPoolMap.erase(descriptorPool); +} + VKAPI_ATTR void VKAPI_CALL DestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, const VkAllocationCallbacks *pAllocator) { // TODO : Add checks for VALIDATION_ERROR_00901 - // TODO : Clean up any internal data structures using this obj. - get_my_data_ptr(get_dispatch_key(device), layer_data_map) - ->dispatch_table.DestroyDescriptorPool(device, descriptorPool, pAllocator); + layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); + DESCRIPTOR_POOL_NODE *desc_pool_state = nullptr; + VK_OBJECT obj_struct; + std::unique_lock lock(global_lock); + bool skip = PreCallValidateDestroyDescriptorPool(dev_data, descriptorPool, &desc_pool_state, &obj_struct); + if (!skip) { + lock.unlock(); + dev_data->dispatch_table.DestroyDescriptorPool(device, descriptorPool, pAllocator); + lock.lock(); + PostCallRecordDestroyDescriptorPool(dev_data, descriptorPool, desc_pool_state, obj_struct); + } } // Verify cmdBuffer in given cb_node is not in global in-flight set, and return skip_call result // If this is a secondary command buffer, then make sure its primary is also in-flight -- cgit v1.2.3