layers: Migrate image layer CmdClearColorImage
authorMark Lobodzinski <mark@lunarg.com>
Fri, 27 Jan 2017 22:16:01 +0000 (15:16 -0700)
committerMark Lobodzinski <mark@lunarg.com>
Tue, 31 Jan 2017 16:55:10 +0000 (09:55 -0700)
The image layer checks for this API were moved to the
buffer_validation module and a call was added to CV.

Change-Id: I04b23843519d2354c952afebc3a3428b196339e3

layers/buffer_validation.cpp
layers/buffer_validation.h
layers/core_validation.cpp
layers/image.cpp

index 8fca611..2dfbf40 100644 (file)
@@ -232,3 +232,34 @@ void PostCallRecordDestroyImage(core_validation::layer_data *device_data, VkImag
         imageSubresourceMap->erase(sub_entry);
     }
 }
+
+bool ValidateImageAttributes(core_validation::layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range) {
+    bool skip = false;
+    const debug_report_data *report_data = core_validation::GetReportData(device_data);
+
+    if (range.aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) {
+        char const str[] = "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT";
+        skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
+                        reinterpret_cast<uint64_t &>(image_state->image), __LINE__, DRAWSTATE_INVALID_IMAGE_ASPECT, "IMAGE", str);
+    }
+
+    if (vk_format_is_depth_or_stencil(image_state->createInfo.format)) {
+        char const str[] = "vkCmdClearColorImage called with depth/stencil image.";
+        skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
+                        reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str,
+                        validation_error_map[VALIDATION_ERROR_01088]);
+    } else if (vk_format_is_compressed(image_state->createInfo.format)) {
+        char const str[] = "vkCmdClearColorImage called with compressed image.";
+        skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
+                        reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str,
+                        validation_error_map[VALIDATION_ERROR_01088]);
+    }
+
+    if (!(image_state->createInfo.usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) {
+        char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT.";
+        skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
+                        reinterpret_cast<uint64_t &>(image_state->image), __LINE__, VALIDATION_ERROR_01084, "IMAGE", "%s. %s", str,
+                        validation_error_map[VALIDATION_ERROR_01084]);
+    }
+    return skip;
+}
index b2d5274..653057a 100644 (file)
@@ -40,4 +40,6 @@ void PostCallRecordDestroyImage(core_validation::layer_data *device_data, VkImag
 bool PreCallValidateDestroyImage(core_validation::layer_data *device_data, VkImage image, IMAGE_STATE **image_state,
                                  VK_OBJECT *obj_struct);
 
+bool ValidateImageAttributes(core_validation::layer_data *device_data, IMAGE_STATE *image_state, VkImageSubresourceRange range);
+
 #endif  // CORE_VALIDATION_BUFFER_VALIDATION_H_
index 4b8c7a9..0267a15 100644 (file)
@@ -8879,6 +8879,7 @@ VKAPI_ATTR void VKAPI_CALL CmdClearColorImage(VkCommandBuffer commandBuffer, VkI
         assert(0);
     }
     for (uint32_t i = 0; i < rangeCount; ++i) {
+        skip_call |= ValidateImageAttributes(dev_data, image_state, pRanges[i]);
         skip_call |= VerifyClearImageLayout(dev_data, cb_node, image, pRanges[i], imageLayout, "vkCmdClearColorImage()");
     }
     lock.unlock();
index 25c67c5..4110893 100644 (file)
@@ -241,51 +241,6 @@ VKAPI_ATTR void VKAPI_CALL DestroyImage(VkDevice device, VkImage image, const Vk
     device_data->device_dispatch_table->DestroyImage(device, image, pAllocator);
 }
 
-VKAPI_ATTR void VKAPI_CALL CmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout,
-                                              const VkClearColorValue *pColor, uint32_t rangeCount,
-                                              const VkImageSubresourceRange *pRanges) {
-    bool skipCall = false;
-    layer_data *device_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
-
-    // For each range, image aspect must be color only
-    // TODO: this is a 'must' in the spec, so there should be a VU enum for it
-    for (uint32_t i = 0; i < rangeCount; i++) {
-        if (pRanges[i].aspectMask != VK_IMAGE_ASPECT_COLOR_BIT) {
-            char const str[] =
-                "vkCmdClearColorImage aspectMasks for all subresource ranges must be set to VK_IMAGE_ASPECT_COLOR_BIT";
-            skipCall |=
-                log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
-                        (uint64_t)commandBuffer, __LINE__, IMAGE_INVALID_IMAGE_ASPECT, "IMAGE", str);
-        }
-    }
-
-    auto image_state = getImageState(device_data, image);
-    if (image_state) {
-        if (vk_format_is_depth_or_stencil(image_state->format)) {
-            char const str[] = "vkCmdClearColorImage called with depth/stencil image.";
-            skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
-                                reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str,
-                                validation_error_map[VALIDATION_ERROR_01088]);
-        } else if (vk_format_is_compressed(image_state->format)) {
-            char const str[] = "vkCmdClearColorImage called with compressed image.";
-            skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
-                                reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01088, "IMAGE", "%s. %s", str,
-                                validation_error_map[VALIDATION_ERROR_01088]);
-        }
-
-        if (!(image_state->usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)) {
-            char const str[] = "vkCmdClearColorImage called with image created without VK_IMAGE_USAGE_TRANSFER_DST_BIT.";
-            skipCall |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
-                                reinterpret_cast<uint64_t &>(image), __LINE__, VALIDATION_ERROR_01084, "IMAGE", "%s. %s", str,
-                                validation_error_map[VALIDATION_ERROR_01084]);
-        }
-    }
-
-    if (!skipCall) {
-        device_data->device_dispatch_table->CmdClearColorImage(commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
-    }
-}
-
 VKAPI_ATTR void VKAPI_CALL CmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout,
                                                      const VkClearDepthStencilValue *pDepthStencil, uint32_t rangeCount,
                                                      const VkImageSubresourceRange *pRanges) {
@@ -1151,7 +1106,6 @@ static PFN_vkVoidFunction intercept_core_device_command(const char *name) {
         {"vkDestroyDevice", reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice)},
         {"vkCreateImage", reinterpret_cast<PFN_vkVoidFunction>(CreateImage)},
         {"vkDestroyImage", reinterpret_cast<PFN_vkVoidFunction>(DestroyImage)},
-        {"vkCmdClearColorImage", reinterpret_cast<PFN_vkVoidFunction>(CmdClearColorImage)},
         {"vkCmdClearDepthStencilImage", reinterpret_cast<PFN_vkVoidFunction>(CmdClearDepthStencilImage)},
         {"vkCmdClearAttachments", reinterpret_cast<PFN_vkVoidFunction>(CmdClearAttachments)},
         {"vkCmdCopyImage", reinterpret_cast<PFN_vkVoidFunction>(CmdCopyImage)},