LVL: Add validation check for CreateImageView
authorJeremy Kniager <jeremyk@lunarg.com>
Mon, 10 Jul 2017 19:12:04 +0000 (13:12 -0600)
committerjeremyk-lunarg <jeremyk@lunarg.com>
Thu, 20 Jul 2017 19:58:20 +0000 (13:58 -0600)
Added validation checks, tests, and updated error database.

Change-Id: Id4dfe66bc325ae0060b7668572026c8a40f83d64

layers/buffer_validation.cpp
layers/vk_validation_error_database.txt
tests/layer_validation_tests.cpp

index 9bc2ef2..dca4247 100644 (file)
@@ -3202,19 +3202,21 @@ bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCr
         skip |= ValidateImageUsageFlags(
             device_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,
+            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(device_data, image_state, "vkCreateImageView()", VALIDATION_ERROR_0ac007f8);
         // Checks imported from image layer
         skip |= ValidateImageSubresourceRange(device_data, image_state, create_info->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY,
-                                              create_info->subresourceRange, "vkCreateImageView", "pCreateInfo->subresourceRange");
+            create_info->subresourceRange, "vkCreateImageView", "pCreateInfo->subresourceRange");
 
         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;
+        VkImageType image_type = image_state->createInfo.imageType;
+        VkImageViewType view_type = create_info->viewType;
 
         // Validate VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT state
         if (image_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) {
@@ -3245,6 +3247,79 @@ bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCr
 
         // Validate correct image aspect bits for desired formats and format consistency
         skip |= ValidateImageAspectMask(device_data, image_state->image, image_format, aspect_mask, "vkCreateImageView()");
+
+        switch (image_type) {
+            case VK_IMAGE_TYPE_1D:
+                if (view_type != VK_IMAGE_VIEW_TYPE_1D && view_type != VK_IMAGE_VIEW_TYPE_1D_ARRAY) {
+                    skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
+                                    __LINE__, VALIDATION_ERROR_0ac007fa, "IMAGE",
+                                    "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s. %s",
+                                    string_VkImageViewType(view_type), string_VkImageType(image_type),
+                                    validation_error_map[VALIDATION_ERROR_0ac007fa]);
+                }
+                break;
+            case VK_IMAGE_TYPE_2D:
+                if (view_type != VK_IMAGE_VIEW_TYPE_2D && view_type != VK_IMAGE_VIEW_TYPE_2D_ARRAY) {
+                    if ((view_type == VK_IMAGE_VIEW_TYPE_CUBE || view_type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) &&
+                        !(image_flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT)) {
+                        skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
+                                        __LINE__, VALIDATION_ERROR_0ac007d6, "IMAGE",
+                                        "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s. %s",
+                                        string_VkImageViewType(view_type), string_VkImageType(image_type),
+                                        validation_error_map[VALIDATION_ERROR_0ac007d6]);
+                    } else if (view_type != VK_IMAGE_VIEW_TYPE_CUBE && view_type != VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {
+                        skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
+                                        __LINE__, VALIDATION_ERROR_0ac007fa, "IMAGE",
+                                        "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s. %s",
+                                        string_VkImageViewType(view_type), string_VkImageType(image_type),
+                                        validation_error_map[VALIDATION_ERROR_0ac007fa]);
+                    }
+                }
+                break;
+            case VK_IMAGE_TYPE_3D:
+                if (GetDeviceExtensions(device_data)->vk_khr_maintenance1) {
+                    if (view_type != VK_IMAGE_VIEW_TYPE_3D) {
+                        if ((view_type == VK_IMAGE_VIEW_TYPE_2D || view_type == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
+                            if (!(image_flags & VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR)) {
+                                skip |= log_msg(
+                                    report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
+                                    __LINE__, VALIDATION_ERROR_0ac007da, "IMAGE",
+                                    "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s. %s",
+                                    string_VkImageViewType(view_type), string_VkImageType(image_type),
+                                    validation_error_map[VALIDATION_ERROR_0ac007da]);
+                            } else if ((image_flags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT |
+                                                       VK_IMAGE_CREATE_SPARSE_ALIASED_BIT))) {
+                                skip |= log_msg(
+                                    report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
+                                    __LINE__, VALIDATION_ERROR_0ac007fa, "IMAGE",
+                                    "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s when the "
+                                    "VK_IMAGE_CREATE_SPARSE_BINDING_BIT, VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT, or "
+                                    "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT flags are enabled. %s",
+                                    string_VkImageViewType(view_type), string_VkImageType(image_type),
+                                    validation_error_map[VALIDATION_ERROR_0ac007fa]);
+                            }
+                        } else {
+                            skip |=
+                                log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
+                                        __LINE__, VALIDATION_ERROR_0ac007fa, "IMAGE",
+                                        "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s. %s",
+                                        string_VkImageViewType(view_type), string_VkImageType(image_type),
+                                        validation_error_map[VALIDATION_ERROR_0ac007fa]);
+                        }
+                    }
+                } else {
+                    if (view_type != VK_IMAGE_VIEW_TYPE_3D) {
+                        skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
+                                        __LINE__, VALIDATION_ERROR_0ac007fa, "IMAGE",
+                                        "vkCreateImageView(): pCreateInfo->viewType %s is not compatible with image type %s. %s",
+                                        string_VkImageViewType(view_type), string_VkImageType(image_type),
+                                        validation_error_map[VALIDATION_ERROR_0ac007fa]);
+                    }
+                }
+                break;
+            default:
+                break;
+        }
     }
     return skip;
 }
index 020d9fa..c5440e2 100644 (file)
@@ -729,9 +729,9 @@ VALIDATION_ERROR_0a800c03~^~Y~^~Unknown~^~vkCreateImageView~^~VUID-VkImageSubres
 VALIDATION_ERROR_0aa007c6~^~N~^~Unknown~^~vkCreateImage~^~VUID-VkImageSwapchainCreateInfoKHX-swapchain-00995~^~core~^~The spec valid usage text states 'If swapchain is not VK_NULL_HANDLE, the fields of VkImageCreateInfo must match the implied image creation parameters of the swapchain' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageSwapchainCreateInfoKHX-swapchain-00995)~^~
 VALIDATION_ERROR_0aa2b00b~^~N~^~Unknown~^~vkCreateImage~^~VUID-VkImageSwapchainCreateInfoKHX-sType-sType~^~core~^~The spec valid usage text states 'sType must be VK_STRUCTURE_TYPE_IMAGE_SWAPCHAIN_CREATE_INFO_KHX' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageSwapchainCreateInfoKHX-sType-sType)~^~implicit
 VALIDATION_ERROR_0aa2f001~^~N~^~Unknown~^~vkCreateImage~^~VUID-VkImageSwapchainCreateInfoKHX-swapchain-parameter~^~core~^~The spec valid usage text states 'If swapchain is not VK_NULL_HANDLE, swapchain must be a valid VkSwapchainKHR handle' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageSwapchainCreateInfoKHX-swapchain-parameter)~^~implicit
-VALIDATION_ERROR_0ac007d6~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01003~^~core~^~The spec valid usage text states 'If image was not created with VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT then viewType must not be VK_IMAGE_VIEW_TYPE_CUBE or VK_IMAGE_VIEW_TYPE_CUBE_ARRAY' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01003)~^~
+VALIDATION_ERROR_0ac007d6~^~Y~^~CreateImageViewBreaksParameterCompatibilityRequirements~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01003~^~core~^~The spec valid usage text states 'If image was not created with VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT then viewType must not be VK_IMAGE_VIEW_TYPE_CUBE or VK_IMAGE_VIEW_TYPE_CUBE_ARRAY' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01003)~^~
 VALIDATION_ERROR_0ac007d8~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-viewType-01004~^~core~^~The spec valid usage text states 'If the image cubemap arrays feature is not enabled, viewType must not be VK_IMAGE_VIEW_TYPE_CUBE_ARRAY' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-viewType-01004)~^~
-VALIDATION_ERROR_0ac007da~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01005~^~(VK_KHR_maintenance1)~^~The spec valid usage text states 'If image was created with VK_IMAGE_TYPE_3D but without VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR set then viewType must not be VK_IMAGE_VIEW_TYPE_2D or VK_IMAGE_VIEW_TYPE_2D_ARRAY' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01005)~^~
+VALIDATION_ERROR_0ac007da~^~Y~^~CreateImageViewBreaksParameterCompatibilityRequirements~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01005~^~(VK_KHR_maintenance1)~^~The spec valid usage text states 'If image was created with VK_IMAGE_TYPE_3D but without VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR set then viewType must not be VK_IMAGE_VIEW_TYPE_2D or VK_IMAGE_VIEW_TYPE_2D_ARRAY' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01005)~^~
 VALIDATION_ERROR_0ac007dc~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01006~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_LINEAR, format must be format that has at least one supported feature bit present in the value of VkFormatProperties::linearTilingFeatures returned by vkGetPhysicalDeviceFormatProperties with the same value of format' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01006)~^~
 VALIDATION_ERROR_0ac007de~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01007~^~core~^~The spec valid usage text states 'image must have been created with a usage value containing at least one of VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01007)~^~
 VALIDATION_ERROR_0ac007e0~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01008~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_LINEAR and usage contains VK_IMAGE_USAGE_SAMPLED_BIT, format must be supported for sampled images, as specified by the VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT flag in VkFormatProperties::linearTilingFeatures returned by vkGetPhysicalDeviceFormatProperties with the same value of format' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01008)~^~
@@ -747,7 +747,7 @@ VALIDATION_ERROR_0ac007f2~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCr
 VALIDATION_ERROR_0ac007f4~^~Y~^~CreateImageViewDifferentClass~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01018~^~core~^~The spec valid usage text states 'If image was created with the VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT flag, format must be compatible with the format used to create image, as defined in Format Compatibility Classes' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01018)~^~Multi-purposing this for some format compatibility checks, need unique enums.
 VALIDATION_ERROR_0ac007f6~^~Y~^~CreateImageViewNoMutableFormatBit~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01019~^~core~^~The spec valid usage text states 'If image was not created with the VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT flag, format must be identical to the format used to create image' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01019)~^~
 VALIDATION_ERROR_0ac007f8~^~Y~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01020~^~core~^~The spec valid usage text states 'If image is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01020)~^~
-VALIDATION_ERROR_0ac007fa~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-subResourceRange-01021~^~core~^~The spec valid usage text states 'subresourceRange and viewType must be compatible with the image, as described in the compatibility table' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-subResourceRange-01021)~^~
+VALIDATION_ERROR_0ac007fa~^~Y~^~CreateImageViewBreaksParameterCompatibilityRequirements~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-subResourceRange-01021~^~core~^~The spec valid usage text states 'subresourceRange and viewType must be compatible with the image, as described in the compatibility table' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-subResourceRange-01021)~^~
 VALIDATION_ERROR_0ac00b8c~^~N~^~None~^~VkImageViewCreateInfo~^~VUID-VkImageViewCreateInfo-subresourceRange-01478~^~core~^~The spec valid usage text states 'subresourceRange::baseMipLevel must be less than the mipLevels specified in VkImageCreateInfo when image was created' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-subresourceRange-01478)~^~
 VALIDATION_ERROR_0ac00b8e~^~N~^~None~^~VkImageViewCreateInfo~^~VUID-VkImageViewCreateInfo-subresourceRange-01479~^~core~^~The spec valid usage text states 'If subresourceRange::levelCount is not VK_REMAINING_MIP_LEVELS, subresourceRange::levelCount must be non-zero and subresourceRange::baseMipLevel + subresourceRange::levelCount must be less than or equal to the mipLevels specified in VkImageCreateInfo when image was created' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-subresourceRange-01479)~^~
 VALIDATION_ERROR_0ac00b90~^~N~^~None~^~VkImageViewCreateInfo~^~VUID-VkImageViewCreateInfo-subresourceRange-01480~^~!(VK_KHR_maintenance1)~^~The spec valid usage text states 'subresourceRange::baseArrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when image was created' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-subresourceRange-01480)~^~
index fe9c1f6..53b2249 100644 (file)
@@ -13816,6 +13816,219 @@ TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
     vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
 }
 
+TEST_F(VkLayerTest, CreateImageViewBreaksParameterCompatibilityRequirements) {
+    TEST_DESCRIPTION(
+        "Attempts to create an Image View with a view type that does not match the image type it is being created from.");
+
+    ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor));
+    if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME)) {
+        m_device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
+    }
+    ASSERT_NO_FATAL_FAILURE(InitState());
+
+    VkPhysicalDeviceMemoryProperties memProps;
+    vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memProps);
+
+    // Test mismatch detection for image of type VK_IMAGE_TYPE_1D
+    VkImageCreateInfo imgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+                                 nullptr,
+                                 VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
+                                 VK_IMAGE_TYPE_1D,
+                                 VK_FORMAT_R8G8B8A8_UNORM,
+                                 {1, 1, 1},
+                                 1,
+                                 1,
+                                 VK_SAMPLE_COUNT_1_BIT,
+                                 VK_IMAGE_TILING_OPTIMAL,
+                                 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+                                 VK_SHARING_MODE_EXCLUSIVE,
+                                 0,
+                                 nullptr,
+                                 VK_IMAGE_LAYOUT_UNDEFINED};
+    VkImageObj image1D(m_device);
+    image1D.init(&imgInfo);
+    ASSERT_TRUE(image1D.initialized());
+
+    // Initialize VkImageViewCreateInfo with mismatched viewType
+    VkImageView imageView;
+    VkImageViewCreateInfo ivci = {};
+    ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
+    ivci.image = image1D.handle();
+    ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
+    ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
+    ivci.subresourceRange.layerCount = 1;
+    ivci.subresourceRange.baseMipLevel = 0;
+    ivci.subresourceRange.levelCount = 1;
+    ivci.subresourceRange.baseArrayLayer = 0;
+    ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+
+    // Test for error message
+    m_errorMonitor->SetDesiredFailureMsg(
+        VK_DEBUG_REPORT_ERROR_BIT_EXT,
+        "vkCreateImageView(): pCreateInfo->viewType VK_IMAGE_VIEW_TYPE_2D is not compatible with image");
+    vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
+    m_errorMonitor->VerifyFound();
+
+    // Test mismatch detection for image of type VK_IMAGE_TYPE_2D
+    imgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+               nullptr,
+               VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
+               VK_IMAGE_TYPE_2D,
+               VK_FORMAT_R8G8B8A8_UNORM,
+               {1, 1, 1},
+               1,
+               6,
+               VK_SAMPLE_COUNT_1_BIT,
+               VK_IMAGE_TILING_OPTIMAL,
+               VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+               VK_SHARING_MODE_EXCLUSIVE,
+               0,
+               nullptr,
+               VK_IMAGE_LAYOUT_UNDEFINED};
+    VkImageObj image2D(m_device);
+    image2D.init(&imgInfo);
+    ASSERT_TRUE(image2D.initialized());
+
+    // Initialize VkImageViewCreateInfo with mismatched viewType
+    ivci = {};
+    ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
+    ivci.image = image2D.handle();
+    ivci.viewType = VK_IMAGE_VIEW_TYPE_3D;
+    ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
+    ivci.subresourceRange.layerCount = 1;
+    ivci.subresourceRange.baseMipLevel = 0;
+    ivci.subresourceRange.levelCount = 1;
+    ivci.subresourceRange.baseArrayLayer = 0;
+    ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+
+    // Test for error message
+    m_errorMonitor->SetDesiredFailureMsg(
+        VK_DEBUG_REPORT_ERROR_BIT_EXT,
+        "vkCreateImageView(): pCreateInfo->viewType VK_IMAGE_VIEW_TYPE_3D is not compatible with image");
+    vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
+    m_errorMonitor->VerifyFound();
+
+    // Change VkImageViewCreateInfo to different mismatched viewType
+    ivci.viewType = VK_IMAGE_VIEW_TYPE_CUBE;
+    ivci.subresourceRange.layerCount = 6;
+
+    // Test for error message
+    m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_0ac007d6);
+    vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
+    m_errorMonitor->VerifyFound();
+
+    // Test mismatch detection for image of type VK_IMAGE_TYPE_3D
+    imgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+               nullptr,
+               VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
+               VK_IMAGE_TYPE_3D,
+               VK_FORMAT_R8G8B8A8_UNORM,
+               {1, 1, 1},
+               1,
+               1,
+               VK_SAMPLE_COUNT_1_BIT,
+               VK_IMAGE_TILING_OPTIMAL,
+               VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+               VK_SHARING_MODE_EXCLUSIVE,
+               0,
+               nullptr,
+               VK_IMAGE_LAYOUT_UNDEFINED};
+    VkImageObj image3D(m_device);
+    image3D.init(&imgInfo);
+    ASSERT_TRUE(image3D.initialized());
+
+    // Initialize VkImageViewCreateInfo with mismatched viewType
+    ivci = {};
+    ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
+    ivci.image = image3D.handle();
+    ivci.viewType = VK_IMAGE_VIEW_TYPE_1D;
+    ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
+    ivci.subresourceRange.layerCount = 1;
+    ivci.subresourceRange.baseMipLevel = 0;
+    ivci.subresourceRange.levelCount = 1;
+    ivci.subresourceRange.baseArrayLayer = 0;
+    ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+
+    // Test for error message
+    m_errorMonitor->SetDesiredFailureMsg(
+        VK_DEBUG_REPORT_ERROR_BIT_EXT,
+        "vkCreateImageView(): pCreateInfo->viewType VK_IMAGE_VIEW_TYPE_1D is not compatible with image");
+    vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
+    m_errorMonitor->VerifyFound();
+
+    // Change VkImageViewCreateInfo to different mismatched viewType
+    ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
+
+    // Test for error message
+    if (DeviceExtensionSupported(gpu(), nullptr, VK_KHR_MAINTENANCE1_EXTENSION_NAME)) {
+        m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_0ac007da);
+    } else {
+        m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_0ac007fa);
+    }
+
+    vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
+    m_errorMonitor->VerifyFound();
+
+    // Check if the device can make the image required for this test case.
+    VkImageFormatProperties formProps = {{0, 0, 0}, 0, 0, 0, 0};
+    VkResult res = vkGetPhysicalDeviceImageFormatProperties(
+        m_device->phy().handle(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_3D, VK_IMAGE_TILING_OPTIMAL,
+        VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+        VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR | VK_IMAGE_CREATE_SPARSE_BINDING_BIT,
+        &formProps);
+
+    // If not, skip this part of the test.
+    if (res) {
+        return;
+    }
+
+    // Initialize VkImageCreateInfo with VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR and VK_IMAGE_CREATE_SPARSE_BINDING_BIT which
+    // are incompatible create flags.
+    imgInfo = {
+        VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+        nullptr,
+        VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR | VK_IMAGE_CREATE_SPARSE_BINDING_BIT,
+        VK_IMAGE_TYPE_3D,
+        VK_FORMAT_R8G8B8A8_UNORM,
+        {1, 1, 1},
+        1,
+        1,
+        VK_SAMPLE_COUNT_1_BIT,
+        VK_IMAGE_TILING_OPTIMAL,
+        VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+        VK_SHARING_MODE_EXCLUSIVE,
+        0,
+        nullptr,
+        VK_IMAGE_LAYOUT_UNDEFINED};
+    VkImage imageSparse;
+
+    // Creating a sparse image means we should not bind memory to it.
+    res = vkCreateImage(m_device->device(), &imgInfo, NULL, &imageSparse);
+    ASSERT_FALSE(res);
+
+    // Initialize VkImageViewCreateInfo to create a view that will attempt to utilize VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR.
+    ivci = {};
+    ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
+    ivci.image = imageSparse;
+    ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
+    ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
+    ivci.subresourceRange.layerCount = 1;
+    ivci.subresourceRange.baseMipLevel = 0;
+    ivci.subresourceRange.levelCount = 1;
+    ivci.subresourceRange.baseArrayLayer = 0;
+    ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+
+    // Test for error message
+    m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
+                                         " when the VK_IMAGE_CREATE_SPARSE_BINDING_BIT, VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT, or "
+                                         "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT flags are enabled.");
+    vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
+    m_errorMonitor->VerifyFound();
+
+    // Clean up
+    vkDestroyImage(m_device->device(), imageSparse, nullptr);
+}
+
 TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
     TEST_DESCRIPTION("Delete in-use imageView.");
 
@@ -21374,6 +21587,48 @@ TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
     m_errorMonitor->VerifyNotFound();
 }
 
+TEST_F(VkPositiveLayerTest, CreateImageViewFollowsParameterCompatibilityRequirements) {
+    TEST_DESCRIPTION("Verify that creating an ImageView with valid usage does not generate validation errors.");
+
+    ASSERT_NO_FATAL_FAILURE(Init());
+
+    m_errorMonitor->ExpectSuccess();
+    
+    VkImageCreateInfo imgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+                                 nullptr,
+                                 VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT,
+                                 VK_IMAGE_TYPE_2D,
+                                 VK_FORMAT_R8G8B8A8_UNORM,
+                                 {128, 128, 1},
+                                 1,
+                                 1,
+                                 VK_SAMPLE_COUNT_1_BIT,
+                                 VK_IMAGE_TILING_OPTIMAL,
+                                 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
+                                 VK_SHARING_MODE_EXCLUSIVE,
+                                 0,
+                                 nullptr,
+                                 VK_IMAGE_LAYOUT_UNDEFINED};
+    VkImageObj image(m_device);
+    image.init(&imgInfo);
+    ASSERT_TRUE(image.initialized());
+    VkImageView imageView;
+    VkImageViewCreateInfo ivci = {};
+    ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
+    ivci.image = image.handle();
+    ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
+    ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
+    ivci.subresourceRange.layerCount = 1;
+    ivci.subresourceRange.baseMipLevel = 0;
+    ivci.subresourceRange.levelCount = 1;
+    ivci.subresourceRange.baseArrayLayer = 0;
+    ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+
+    vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
+    m_errorMonitor->VerifyNotFound();
+    vkDestroyImageView(m_device->device(), imageView, NULL);
+}
+
 TEST_F(VkPositiveLayerTest, ValidUsage) {
     TEST_DESCRIPTION(
         "Verify that creating an image view from an image with valid usage "