From 68bffb05ebae84543f3632f9a6d8193f480415da Mon Sep 17 00:00:00 2001 From: Tobin Ehlis Date: Wed, 12 Oct 2016 11:48:21 -0600 Subject: [PATCH] layers:Refactor DestroyFramebuffer Add validation flag for DestroyFramebuffer and update it to follow the Pre/Post pattern. This function didn't previously perform an in-use check so added that check. Updated database file. --- layers/core_validation.cpp | 34 ++++++++++++++++++++++++++------- layers/core_validation.h | 1 + layers/vk_validation_error_database.txt | 2 +- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index a398c13..824c0bf 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -6331,18 +6331,38 @@ void invalidateCommandBuffers(std::unordered_set cb_nodes, VK_ } } +static bool PreCallValidateDestroyFramebuffer(layer_data *dev_data, VkFramebuffer framebuffer, FRAMEBUFFER_NODE **framebuffer_state, + VK_OBJECT *obj_struct) { + if (dev_data->instance_state->disabled.destroy_framebuffer) + return false; + bool skip = false; + *framebuffer_state = getFramebuffer(dev_data, framebuffer); + if (*framebuffer_state) { + *obj_struct = {reinterpret_cast(framebuffer), VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT}; + skip |= ValidateObjectNotInUse(dev_data, *framebuffer_state, *obj_struct, VALIDATION_ERROR_00422); + } + return skip; +} + +static void PostCallRecordDestroyFramebuffer(layer_data *dev_data, VkFramebuffer framebuffer, FRAMEBUFFER_NODE *framebuffer_state, + VK_OBJECT obj_struct) { + invalidateCommandBuffers(framebuffer_state->cb_bindings, obj_struct); + dev_data->frameBufferMap.erase(framebuffer); +} + VKAPI_ATTR void VKAPI_CALL DestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer, const VkAllocationCallbacks *pAllocator) { layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map); + FRAMEBUFFER_NODE *framebuffer_state = nullptr; + VK_OBJECT obj_struct; std::unique_lock lock(global_lock); - auto fb_node = getFramebuffer(dev_data, framebuffer); - if (fb_node) { - invalidateCommandBuffers(fb_node->cb_bindings, - {reinterpret_cast(fb_node->framebuffer), VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT}); - dev_data->frameBufferMap.erase(fb_node->framebuffer); + bool skip = PreCallValidateDestroyFramebuffer(dev_data, framebuffer, &framebuffer_state, &obj_struct); + if (!skip) { + lock.unlock(); + dev_data->dispatch_table.DestroyFramebuffer(device, framebuffer, pAllocator); + lock.lock(); + PostCallRecordDestroyFramebuffer(dev_data, framebuffer, framebuffer_state, obj_struct); } - lock.unlock(); - dev_data->dispatch_table.DestroyFramebuffer(device, framebuffer, pAllocator); } VKAPI_ATTR void VKAPI_CALL diff --git a/layers/core_validation.h b/layers/core_validation.h index 26d87f8..2c8608f 100644 --- a/layers/core_validation.h +++ b/layers/core_validation.h @@ -75,6 +75,7 @@ struct CHECK_DISABLED { bool destroy_image_view; // Skip validation at DestroyImageView time bool destroy_pipeline; // Skip validation at DestroyPipeline time bool destroy_descriptor_pool; // Skip validation at DestroyDescriptorPool time + bool destroy_framebuffer; // Skip validation at DestroyFramebuffer time bool object_in_use; // Skip all object in_use checking bool idle_descriptor_set; // Skip check to verify that descriptor set is no in-use bool push_constant_range; // Skip push constant range checks diff --git a/layers/vk_validation_error_database.txt b/layers/vk_validation_error_database.txt index c85a802..b4b0c8b 100644 --- a/layers/vk_validation_error_database.txt +++ b/layers/vk_validation_error_database.txt @@ -428,7 +428,7 @@ VALIDATION_ERROR_00418~^~U~^~Unknown~^~For more information refer to Vulkan Spec VALIDATION_ERROR_00419~^~U~^~Unknown~^~For more information refer to Vulkan Spec Section '7.3. Framebuffers' which states 'renderPass must be a valid VkRenderPass handle' (https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#renderpass-noattachments) VALIDATION_ERROR_00420~^~U~^~Unknown~^~For more information refer to Vulkan Spec Section '7.3. Framebuffers' which states 'If attachmentCount is not 0, pAttachments must be a pointer to an array of attachmentCount valid VkImageView handles' (https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#renderpass-noattachments) VALIDATION_ERROR_00421~^~U~^~Unknown~^~For more information refer to Vulkan Spec Section '7.3. Framebuffers' which states 'Both of renderPass, and the elements of pAttachments that are valid handles must have been created, allocated, or retrieved from the same VkDevice' (https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#renderpass-noattachments) -VALIDATION_ERROR_00422~^~U~^~Unknown~^~For more information refer to Vulkan Spec Section '7.3. Framebuffers' which states 'All submitted commands that refer to framebuffer must have completed execution' (https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#vkDestroyFramebuffer) +VALIDATION_ERROR_00422~^~Y~^~None~^~For more information refer to Vulkan Spec Section '7.3. Framebuffers' which states 'All submitted commands that refer to framebuffer must have completed execution' (https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#vkDestroyFramebuffer) VALIDATION_ERROR_00423~^~U~^~Unknown~^~For more information refer to Vulkan Spec Section '7.3. Framebuffers' which states 'If VkAllocationCallbacks were provided when framebuffer was created, a compatible set of callbacks must be provided here' (https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#vkDestroyFramebuffer) VALIDATION_ERROR_00424~^~U~^~Unknown~^~For more information refer to Vulkan Spec Section '7.3. Framebuffers' which states 'If no VkAllocationCallbacks were provided when framebuffer was created, pAllocator must be NULL' (https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#vkDestroyFramebuffer) VALIDATION_ERROR_00425~^~Y~^~Unknown~^~For more information refer to Vulkan Spec Section '7.3. Framebuffers' which states 'device must be a valid VkDevice handle' (https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#vkDestroyFramebuffer) -- 2.7.4