From e36af17afa0496cc5d9696dd578fd94392e984d9 Mon Sep 17 00:00:00 2001 From: Mike Weiblen Date: Tue, 21 Feb 2017 14:32:53 -0700 Subject: layers: Move code to preferred cpp file PreCallValidateGetImageSubresourceLayout() from core_validation.cpp to buffer_validation.cpp Change-Id: Ic55e049fab28384d30768e8c590f158e603dd343 --- layers/buffer_validation.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'layers/buffer_validation.cpp') diff --git a/layers/buffer_validation.cpp b/layers/buffer_validation.cpp index 118df5e2..76389cfc 100644 --- a/layers/buffer_validation.cpp +++ b/layers/buffer_validation.cpp @@ -2846,3 +2846,69 @@ void PreCallRecordCmdCopyBufferToImage(layer_data *device_data, GLOBAL_CB_NODE * core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_COPYBUFFERTOIMAGE); } + +bool PreCallValidateGetImageSubresourceLayout(layer_data *device_data, VkImage image, const VkImageSubresource *pSubresource) { + const auto report_data = core_validation::GetReportData(device_data); + bool skip = false; + const VkImageAspectFlags sub_aspect = pSubresource->aspectMask; + + // VU 00733: The aspectMask member of pSubresource must only have a single bit set + const int num_bits = sizeof(sub_aspect) * CHAR_BIT; + std::bitset aspect_mask_bits(sub_aspect); + if (aspect_mask_bits.count() != 1) { + skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, + VALIDATION_ERROR_00733, "IMAGE", + "vkGetImageSubresourceLayout(): VkImageSubresource.aspectMask must have exactly 1 bit set. %s", + validation_error_map[VALIDATION_ERROR_00733]); + } + + IMAGE_STATE *image_entry = GetImageState(device_data, image); + if (!image_entry) { + return skip; + } + + // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR + if (image_entry->createInfo.tiling != VK_IMAGE_TILING_LINEAR) { + skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, + __LINE__, VALIDATION_ERROR_00732, "IMAGE", + "vkGetImageSubresourceLayout(): Image must have tiling of VK_IMAGE_TILING_LINEAR. %s", + validation_error_map[VALIDATION_ERROR_00732]); + } + + // VU 00739: mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created + if (pSubresource->mipLevel >= image_entry->createInfo.mipLevels) { + skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, + __LINE__, VALIDATION_ERROR_00739, "IMAGE", + "vkGetImageSubresourceLayout(): pSubresource.mipLevel (%d) must be less than %d. %s", + pSubresource->mipLevel, image_entry->createInfo.mipLevels, validation_error_map[VALIDATION_ERROR_00739]); + } + + // VU 00740: arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created + if (pSubresource->arrayLayer >= image_entry->createInfo.arrayLayers) { + skip |= log_msg( + report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, __LINE__, + VALIDATION_ERROR_00740, "IMAGE", "vkGetImageSubresourceLayout(): pSubresource.arrayLayer (%d) must be less than %d. %s", + pSubresource->arrayLayer, image_entry->createInfo.arrayLayers, validation_error_map[VALIDATION_ERROR_00740]); + } + + // VU 00741: subresource's aspect must be compatible with image's format. + const VkFormat img_format = image_entry->createInfo.format; + if (vk_format_is_color(img_format)) { + if (sub_aspect != VK_IMAGE_ASPECT_COLOR_BIT) { + skip |= log_msg( + report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, __LINE__, + VALIDATION_ERROR_00741, "IMAGE", + "vkGetImageSubresourceLayout(): For color formats, VkImageSubresource.aspectMask must be VK_IMAGE_ASPECT_COLOR. %s", + validation_error_map[VALIDATION_ERROR_00741]); + } + } else if (vk_format_is_depth_or_stencil(img_format)) { + if ((sub_aspect != VK_IMAGE_ASPECT_DEPTH_BIT) && (sub_aspect != VK_IMAGE_ASPECT_STENCIL_BIT)) { + skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, (uint64_t)image, + __LINE__, VALIDATION_ERROR_00741, "IMAGE", + "vkGetImageSubresourceLayout(): For depth/stencil formats, VkImageSubresource.aspectMask must be " + "either VK_IMAGE_ASPECT_DEPTH_BIT or VK_IMAGE_ASPECT_STENCIL_BIT. %s", + validation_error_map[VALIDATION_ERROR_00741]); + } + } + return skip; +} -- cgit v1.2.3