layers: Move DestroyImage code into buffer module
authorMark Lobodzinski <mark@lunarg.com>
Fri, 27 Jan 2017 19:28:30 +0000 (12:28 -0700)
committerMark Lobodzinski <mark@lunarg.com>
Tue, 31 Jan 2017 16:55:10 +0000 (09:55 -0700)
Moved CHECK_DISABLED into CV_types.h, moved validation and recording
routines into buffer_validation.cpp.

Change-Id: I103d0fc9c2e985d98943471ec6f83898c58bfdfe

layers/buffer_validation.cpp
layers/buffer_validation.h
layers/core_validation.cpp
layers/core_validation.h
layers/core_validation_types.h

index e886b13..76a743f 100644 (file)
@@ -197,3 +197,41 @@ void PostCallRecordCreateImage(std::unordered_map<VkImage, std::unique_ptr<IMAGE
     (*imageSubresourceMap)[*pImage].push_back(subpair);
     (*imageLayoutMap)[subpair] = image_state;
 }
+
+bool PreCallValidateDestroyImage(core_validation::layer_data *device_data, VkImage image, IMAGE_STATE **image_state,
+                                 VK_OBJECT *obj_struct) {
+    const CHECK_DISABLED *disabled = core_validation::GetDisables(device_data);
+    *image_state = core_validation::getImageState(device_data, image);
+    *obj_struct = {reinterpret_cast<uint64_t &>(image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT};
+    if (disabled->destroy_image) return false;
+    bool skip = false;
+    if (*image_state) {
+        skip |= core_validation::ValidateObjectNotInUse(device_data, *image_state, *obj_struct, VALIDATION_ERROR_00743);
+    }
+    return skip;
+}
+
+void PostCallRecordDestroyImage(core_validation::layer_data *device_data, VkImage image, IMAGE_STATE *image_state,
+                                VK_OBJECT obj_struct) {
+    core_validation::invalidateCommandBuffers(device_data, image_state->cb_bindings, obj_struct);
+    // Clean up memory mapping, bindings and range references for image
+    for (auto mem_binding : image_state->GetBoundMemory()) {
+        auto mem_info = core_validation::getMemObjInfo(device_data, mem_binding);
+        if (mem_info) {
+            core_validation::RemoveImageMemoryRange(obj_struct.handle, mem_info);
+        }
+    }
+    core_validation::ClearMemoryObjectBindings(device_data, obj_struct.handle, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT);
+    // Remove image from imageMap
+    core_validation::GetImageMap(device_data)->erase(image);
+    std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *imageSubresourceMap =
+        core_validation::GetImageSubresourceMap(device_data);
+
+    const auto &sub_entry = imageSubresourceMap->find(image);
+    if (sub_entry != imageSubresourceMap->end()) {
+        for (const auto &pair : sub_entry->second) {
+            core_validation::GetImageLayoutMap(device_data)->erase(pair);
+        }
+        imageSubresourceMap->erase(sub_entry);
+    }
+}
index 88342a1..dab6ac2 100644 (file)
@@ -26,6 +26,7 @@
 #include <memory>
 #include <unordered_map>
 #include <vector>
+#include <utility>
 
 
 bool PreCallValidateCreateImage(core_validation::layer_data *device_data, const VkImageCreateInfo *pCreateInfo,
@@ -36,4 +37,10 @@ void PostCallRecordCreateImage(std::unordered_map<VkImage, std::unique_ptr<IMAGE
                                std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> *imageLayoutMap,
                                const VkImageCreateInfo *pCreateInfo, VkImage *pImage);
 
+void PostCallRecordDestroyImage(core_validation::layer_data *device_data, VkImage image, IMAGE_STATE *image_state,
+                                VK_OBJECT obj_struct);
+
+bool PreCallValidateDestroyImage(core_validation::layer_data *device_data, VkImage image, IMAGE_STATE **image_state,
+                                 VK_OBJECT *obj_struct);
+
 #endif  // CORE_VALIDATION_BUFFER_VALIDATION_H_
index 4d1e30e..01d6f41 100644 (file)
@@ -712,7 +712,7 @@ static bool ClearMemoryObjectBinding(layer_data *dev_data, uint64_t handle, VkDe
 // ClearMemoryObjectBindings clears the binding of objects to memory
 //  For the given object it pulls the memory bindings and makes sure that the bindings
 //  no longer refer to the object being cleared. This occurs when objects are destroyed.
-static bool ClearMemoryObjectBindings(layer_data *dev_data, uint64_t handle, VkDebugReportObjectTypeEXT type) {
+bool ClearMemoryObjectBindings(layer_data *dev_data, uint64_t handle, VkDebugReportObjectTypeEXT type) {
     bool skip = false;
     BINDABLE *mem_binding = GetObjectMemBinding(dev_data, handle, type);
     if (mem_binding) {
@@ -5634,7 +5634,7 @@ static void RemoveMemoryRange(uint64_t handle, DEVICE_MEM_INFO *mem_info, bool i
 
 static void RemoveBufferMemoryRange(uint64_t handle, DEVICE_MEM_INFO *mem_info) { RemoveMemoryRange(handle, mem_info, false); }
 
-static void RemoveImageMemoryRange(uint64_t handle, DEVICE_MEM_INFO *mem_info) { RemoveMemoryRange(handle, mem_info, true); }
+void RemoveImageMemoryRange(uint64_t handle, DEVICE_MEM_INFO *mem_info) { RemoveMemoryRange(handle, mem_info, true); }
 
 static bool PreCallValidateDestroyBuffer(layer_data *dev_data, VkBuffer buffer, BUFFER_STATE **buffer_state,
                                          VK_OBJECT *obj_struct) {
@@ -5709,39 +5709,6 @@ VKAPI_ATTR void VKAPI_CALL DestroyBufferView(VkDevice device, VkBufferView buffe
     }
 }
 
-static bool PreCallValidateDestroyImage(layer_data *dev_data, VkImage image, IMAGE_STATE **image_state, VK_OBJECT *obj_struct) {
-    *image_state = getImageState(dev_data, image);
-    *obj_struct = {reinterpret_cast<uint64_t &>(image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT};
-    if (dev_data->instance_data->disabled.destroy_image) return false;
-    bool skip = false;
-    if (*image_state) {
-        skip |= ValidateObjectNotInUse(dev_data, *image_state, *obj_struct, VALIDATION_ERROR_00743);
-    }
-    return skip;
-}
-
-static void PostCallRecordDestroyImage(layer_data *dev_data, VkImage image, IMAGE_STATE *image_state, VK_OBJECT obj_struct) {
-    invalidateCommandBuffers(dev_data, image_state->cb_bindings, obj_struct);
-    // Clean up memory mapping, bindings and range references for image
-    for (auto mem_binding : image_state->GetBoundMemory()) {
-        auto mem_info = getMemObjInfo(dev_data, mem_binding);
-        if (mem_info) {
-            RemoveImageMemoryRange(obj_struct.handle, mem_info);
-        }
-    }
-    ClearMemoryObjectBindings(dev_data, obj_struct.handle, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT);
-    // Remove image from imageMap
-    dev_data->imageMap.erase(image);
-
-    const auto &sub_entry = dev_data->imageSubresourceMap.find(image);
-    if (sub_entry != dev_data->imageSubresourceMap.end()) {
-        for (const auto &pair : sub_entry->second) {
-            dev_data->imageLayoutMap.erase(pair);
-        }
-        dev_data->imageSubresourceMap.erase(sub_entry);
-    }
-}
-
 VKAPI_ATTR void VKAPI_CALL DestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
     layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
     IMAGE_STATE *image_state = nullptr;
@@ -6411,6 +6378,20 @@ const VkPhysicalDeviceProperties *GetPhysicalDeviceProperties(core_validation::l
     return &device_data->phys_dev_props;
 }
 
+const CHECK_DISABLED *GetDisables(core_validation::layer_data *device_data) { return &device_data->instance_data->disabled; }
+
+std::unordered_map<VkImage, std::unique_ptr<IMAGE_STATE>> *GetImageMap(core_validation::layer_data *device_data) {
+    return &device_data->imageMap;
+}
+
+std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *GetImageSubresourceMap(core_validation::layer_data *device_data) {
+    return &device_data->imageSubresourceMap;
+}
+
+std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> *GetImageLayoutMap(layer_data *device_data) {
+    return &device_data->imageLayoutMap;
+}
+
 VKAPI_ATTR VkResult VKAPI_CALL CreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
                                            const VkAllocationCallbacks *pAllocator, VkImage *pImage) {
     VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
index e6c92b2..fba1a76 100644 (file)
 #include <deque>
 
 /*
- * CHECK_DISABLED struct is a container for bools that can block validation checks from being performed.
- * The end goal is to have all checks guarded by a bool. The bools are all "false" by default meaning that all checks
- * are enabled. At CreateInstance time, the user can use the VK_EXT_validation_flags extension to pass in enum values
- * of VkValidationCheckEXT that will selectively disable checks.
- */
-struct CHECK_DISABLED {
-    bool command_buffer_state;
-    bool create_descriptor_set_layout;
-    bool destroy_buffer_view;       // Skip validation at DestroyBufferView time
-    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 destroy_renderpass;        // Skip validation at DestroyRenderpass time
-    bool destroy_image;             // Skip validation at DestroyImage time
-    bool destroy_sampler;           // Skip validation at DestroySampler time
-    bool destroy_command_pool;      // Skip validation at DestroyCommandPool time
-    bool destroy_event;             // Skip validation at DestroyEvent time
-    bool free_memory;               // Skip validation at FreeMemory 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
-    bool free_descriptor_sets;      // Skip validation prior to vkFreeDescriptorSets()
-    bool allocate_descriptor_sets;  // Skip validation prior to vkAllocateDescriptorSets()
-    bool update_descriptor_sets;    // Skip validation prior to vkUpdateDescriptorSets()
-    bool wait_for_fences;
-    bool get_fence_state;
-    bool queue_wait_idle;
-    bool device_wait_idle;
-    bool destroy_fence;
-    bool destroy_semaphore;
-    bool destroy_query_pool;
-    bool get_query_pool_results;
-    bool destroy_buffer;
-};
-
-/*
  * MTMTODO : Update this comment
  * Data Structure overview
  *  There are 4 global STL(' maps
index 22090a8..b93ad66 100644 (file)
@@ -57,6 +57,7 @@
 #include <unordered_map>
 #include <unordered_set>
 #include <vector>
+#include <memory>
 
 // Fwd declarations
 namespace cvdescriptorset {
@@ -671,6 +672,41 @@ struct IMAGE_LAYOUT_NODE {
     VkFormat format;
 };
 
+// CHECK_DISABLED struct is a container for bools that can block validation checks from being performed.
+// The end goal is to have all checks guarded by a bool. The bools are all "false" by default meaning that all checks
+// are enabled. At CreateInstance time, the user can use the VK_EXT_validation_flags extension to pass in enum values
+// of VkValidationCheckEXT that will selectively disable checks.
+struct CHECK_DISABLED {
+    bool command_buffer_state;
+    bool create_descriptor_set_layout;
+    bool destroy_buffer_view;       // Skip validation at DestroyBufferView time
+    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 destroy_renderpass;        // Skip validation at DestroyRenderpass time
+    bool destroy_image;             // Skip validation at DestroyImage time
+    bool destroy_sampler;           // Skip validation at DestroySampler time
+    bool destroy_command_pool;      // Skip validation at DestroyCommandPool time
+    bool destroy_event;             // Skip validation at DestroyEvent time
+    bool free_memory;               // Skip validation at FreeMemory 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
+    bool free_descriptor_sets;      // Skip validation prior to vkFreeDescriptorSets()
+    bool allocate_descriptor_sets;  // Skip validation prior to vkAllocateDescriptorSets()
+    bool update_descriptor_sets;    // Skip validation prior to vkUpdateDescriptorSets()
+    bool wait_for_fences;
+    bool get_fence_state;
+    bool queue_wait_idle;
+    bool device_wait_idle;
+    bool destroy_fence;
+    bool destroy_semaphore;
+    bool destroy_query_pool;
+    bool get_query_pool_results;
+    bool destroy_buffer;
+};
+
 // Fwd declarations of layer_data and helpers to look-up/validate state from layer_data maps
 namespace core_validation {
 struct layer_data;
@@ -693,6 +729,10 @@ void AddCommandBufferBindingImage(const layer_data *, GLOBAL_CB_NODE *, IMAGE_ST
 void AddCommandBufferBindingImageView(const layer_data *, GLOBAL_CB_NODE *, IMAGE_VIEW_STATE *);
 void AddCommandBufferBindingBuffer(const layer_data *, GLOBAL_CB_NODE *, BUFFER_STATE *);
 void AddCommandBufferBindingBufferView(const layer_data *, GLOBAL_CB_NODE *, BUFFER_VIEW_STATE *);
+bool ValidateObjectNotInUse(const layer_data *dev_data, BASE_NODE *obj_node, VK_OBJECT obj_struct, UNIQUE_VALIDATION_ERROR_CODE error_code);
+void invalidateCommandBuffers(const layer_data *dev_data, std::unordered_set<GLOBAL_CB_NODE *> const &cb_nodes, VK_OBJECT obj);
+void RemoveImageMemoryRange(uint64_t handle, DEVICE_MEM_INFO *mem_info);
+bool ClearMemoryObjectBindings(layer_data *dev_data, uint64_t handle, VkDebugReportObjectTypeEXT type);
 
 // Prototypes for layer_data accessor functions.  These should be in their own header file at some point
 PFN_vkGetPhysicalDeviceFormatProperties GetFormatPropertiesPointer(layer_data *);
@@ -700,6 +740,10 @@ PFN_vkGetPhysicalDeviceImageFormatProperties GetImageFormatPropertiesPointer(lay
 VkPhysicalDevice GetPhysicalDevice(layer_data *);
 const debug_report_data *GetReportData(layer_data *);
 const VkPhysicalDeviceProperties *GetPhysicalDeviceProperties(layer_data *);
+const CHECK_DISABLED *GetDisables(layer_data *);
+std::unordered_map<VkImage, std::unique_ptr<IMAGE_STATE>> *GetImageMap(core_validation::layer_data *);
+std::unordered_map<VkImage, std::vector<ImageSubresourcePair>> *GetImageSubresourceMap(layer_data *);
+std::unordered_map<ImageSubresourcePair, IMAGE_LAYOUT_NODE> *GetImageLayoutMap(layer_data *);
 }
 
 #endif  // CORE_VALIDATION_TYPES_H_