aboutsummaryrefslogtreecommitdiff
path: root/layers/core_validation.cpp
diff options
context:
space:
mode:
authorMark Lobodzinski <mark@lunarg.com>2017-02-09 11:01:33 -0700
committerMark Lobodzinski <mark@lunarg.com>2017-02-10 12:15:31 -0700
commitc5d7baa13cec75197c9a0d500c1c3753ef5015a9 (patch)
tree57a45bc1e1fac20318198fb99945575d33e5feb3 /layers/core_validation.cpp
parent49f30125bb577ac9bd7d98d1ed820ab114a84057 (diff)
downloadusermoji-c5d7baa13cec75197c9a0d500c1c3753ef5015a9.tar.xz
layers: Move pre/post CreateImageView out of CV
Moved PreCallValidateCreateImageView and the postCallRecord routine, along with a couple of helpers: ValidateImageSubrangeLevelLayerCounts and ValidateImageAspectMask. Change-Id: I1d94ecee6244010d71cf910a95aeb320c30fc0fb
Diffstat (limited to 'layers/core_validation.cpp')
-rw-r--r--layers/core_validation.cpp153
1 files changed, 4 insertions, 149 deletions
diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp
index 0f696585..035c0109 100644
--- a/layers/core_validation.cpp
+++ b/layers/core_validation.cpp
@@ -6048,6 +6048,10 @@ std::unordered_map<VkBufferView, std::unique_ptr<BUFFER_VIEW_STATE>> *GetBufferV
return &device_data->bufferViewMap;
}
+std::unordered_map<VkImageView, std::unique_ptr<IMAGE_VIEW_STATE>> *GetImageViewMap(layer_data *device_data) {
+ return &device_data->imageViewMap;
+}
+
VKAPI_ATTR VkResult VKAPI_CALL CreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkImage *pImage) {
VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
@@ -6063,155 +6067,6 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateImage(VkDevice device, const VkImageCreateI
return result;
}
-// For the given format verify that the aspect masks make sense
-static bool ValidateImageAspectMask(layer_data *dev_data, VkImage image, VkFormat format, VkImageAspectFlags aspect_mask,
- const char *func_name) {
- bool skip = false;
- if (vk_format_is_color(format)) {
- if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
- (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE",
- "%s: Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name,
- validation_error_map[VALIDATION_ERROR_00741]);
- } else if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != aspect_mask) {
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
- (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE",
- "%s: Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set. %s", func_name,
- validation_error_map[VALIDATION_ERROR_00741]);
- }
- } else if (vk_format_is_depth_and_stencil(format)) {
- if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) == 0) {
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
- (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE",
- "%s: Depth/stencil image formats must have "
- "at least one of VK_IMAGE_ASPECT_DEPTH_BIT "
- "and VK_IMAGE_ASPECT_STENCIL_BIT set. %s",
- func_name, validation_error_map[VALIDATION_ERROR_00741]);
- } else if ((aspect_mask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != aspect_mask) {
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
- (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE",
- "%s: Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and "
- "VK_IMAGE_ASPECT_STENCIL_BIT set. %s",
- func_name, validation_error_map[VALIDATION_ERROR_00741]);
- }
- } else if (vk_format_is_depth_only(format)) {
- if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != VK_IMAGE_ASPECT_DEPTH_BIT) {
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
- (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE",
- "%s: Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name,
- validation_error_map[VALIDATION_ERROR_00741]);
- } else if ((aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) != aspect_mask) {
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
- (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE",
- "%s: Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set. %s", func_name,
- validation_error_map[VALIDATION_ERROR_00741]);
- }
- } else if (vk_format_is_stencil_only(format)) {
- if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != VK_IMAGE_ASPECT_STENCIL_BIT) {
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
- (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE",
- "%s: Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name,
- validation_error_map[VALIDATION_ERROR_00741]);
- } else if ((aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) != aspect_mask) {
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT,
- (uint64_t)image, __LINE__, VALIDATION_ERROR_00741, "IMAGE",
- "%s: Stencil-only image formats can have only the VK_IMAGE_ASPECT_STENCIL_BIT set. %s", func_name,
- validation_error_map[VALIDATION_ERROR_00741]);
- }
- }
- return skip;
-}
-
-bool ValidateImageSubrangeLevelLayerCounts(layer_data *dev_data, const VkImageSubresourceRange &subresourceRange,
- const char *func_name) {
- bool skip = false;
- if (subresourceRange.levelCount == 0) {
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
- VALIDATION_ERROR_00768, "IMAGE", "%s called with 0 in subresourceRange.levelCount. %s", func_name,
- validation_error_map[VALIDATION_ERROR_00768]);
- }
- if (subresourceRange.layerCount == 0) {
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
- VALIDATION_ERROR_00769, "IMAGE", "%s called with 0 in subresourceRange.layerCount. %s", func_name,
- validation_error_map[VALIDATION_ERROR_00769]);
- }
- return skip;
-}
-
-static bool PreCallValidateCreateImageView(layer_data *dev_data, const VkImageViewCreateInfo *create_info) {
- bool skip = false;
- IMAGE_STATE *image_state = GetImageState(dev_data, create_info->image);
- if (image_state) {
- skip |= ValidateImageUsageFlags(
- dev_data, image_state, VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT |
- VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
- false, -1, "vkCreateImageView()",
- "VK_IMAGE_USAGE_[SAMPLED|STORAGE|COLOR_ATTACHMENT|DEPTH_STENCIL_ATTACHMENT|INPUT_ATTACHMENT]_BIT");
- // If this isn't a sparse image, it needs to have memory backing it at CreateImageView time
- skip |= ValidateMemoryIsBoundToImage(dev_data, image_state, "vkCreateImageView()", VALIDATION_ERROR_02524);
- // Checks imported from image layer
- if (create_info->subresourceRange.baseMipLevel >= image_state->createInfo.mipLevels) {
- std::stringstream ss;
- ss << "vkCreateImageView called with baseMipLevel " << create_info->subresourceRange.baseMipLevel << " for image "
- << create_info->image << " that only has " << image_state->createInfo.mipLevels << " mip levels.";
- skip |=
- log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
- VALIDATION_ERROR_00768, "IMAGE", "%s %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_00768]);
- }
- if (create_info->subresourceRange.baseArrayLayer >= image_state->createInfo.arrayLayers) {
- std::stringstream ss;
- ss << "vkCreateImageView called with baseArrayLayer " << create_info->subresourceRange.baseArrayLayer << " for image "
- << create_info->image << " that only has " << image_state->createInfo.arrayLayers << " array layers.";
- skip |=
- log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
- VALIDATION_ERROR_00769, "IMAGE", "%s %s", ss.str().c_str(), validation_error_map[VALIDATION_ERROR_00769]);
- }
- // TODO: Need new valid usage language for levelCount == 0 & layerCount == 0
- skip |= ValidateImageSubrangeLevelLayerCounts(dev_data, create_info->subresourceRange, "vkCreateImageView()");
-
- VkImageCreateFlags image_flags = image_state->createInfo.flags;
- VkFormat image_format = image_state->createInfo.format;
- VkFormat view_format = create_info->format;
- VkImageAspectFlags aspect_mask = create_info->subresourceRange.aspectMask;
-
- // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state
- if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) {
- // Format MUST be compatible (in the same format compatibility class) as the format the image was created with
- if (vk_format_get_compatibility_class(image_format) != vk_format_get_compatibility_class(view_format)) {
- std::stringstream ss;
- ss << "vkCreateImageView(): ImageView format " << string_VkFormat(view_format)
- << " is not in the same format compatibility class as image (" << (uint64_t)create_info->image << ") format "
- << string_VkFormat(image_format) << ". Images created with the VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
- << "can support ImageViews with differing formats but they must be in the same compatibility class.";
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
- VALIDATION_ERROR_02171, "IMAGE", "%s %s", ss.str().c_str(),
- validation_error_map[VALIDATION_ERROR_02171]);
- }
- } else {
- // Format MUST be IDENTICAL to the format the image was created with
- if (image_format != view_format) {
- std::stringstream ss;
- ss << "vkCreateImageView() format " << string_VkFormat(view_format) << " differs from image "
- << (uint64_t)create_info->image << " format " << string_VkFormat(image_format)
- << ". Formats MUST be IDENTICAL unless VK_IMAGE_CREATE_MUTABLE_FORMAT BIT was set on image creation.";
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__,
- VALIDATION_ERROR_02172, "IMAGE", "%s %s", ss.str().c_str(),
- validation_error_map[VALIDATION_ERROR_02172]);
- }
- }
-
- // Validate correct image aspect bits for desired formats and format consistency
- skip |= ValidateImageAspectMask(dev_data, image_state->image, image_format, aspect_mask, "vkCreateImageView()");
- }
- return skip;
-}
-
-static inline void PostCallRecordCreateImageView(layer_data *dev_data, const VkImageViewCreateInfo *create_info, VkImageView view) {
- dev_data->imageViewMap[view] = unique_ptr<IMAGE_VIEW_STATE>(new IMAGE_VIEW_STATE(view, create_info));
- ResolveRemainingLevelsLayers(dev_data, &dev_data->imageViewMap[view].get()->create_info.subresourceRange,
- GetImageState(dev_data, create_info->image));
-}
-
VKAPI_ATTR VkResult VKAPI_CALL CreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkImageView *pView) {
layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);