From 8202587b4dc6705dfb9e5a51130ea83eff048d9d Mon Sep 17 00:00:00 2001 From: Jeremy Kniager Date: Tue, 18 Jul 2017 11:10:28 -0600 Subject: [PATCH] layers: Add checks for Image/ImageView usage Change-Id: Ibb2ac5b5f4b4176f5745007598c2fe64665237c2 --- layers/buffer_validation.cpp | 65 +++++++++++++ layers/vk_validation_error_database.txt | 20 ++-- tests/layer_validation_tests.cpp | 161 ++++++++++++++++++++++++++++++++ tests/run_wrap_objects_tests.sh | 2 +- 4 files changed, 237 insertions(+), 11 deletions(-) diff --git a/layers/buffer_validation.cpp b/layers/buffer_validation.cpp index 003153f..9b3e1f3 100644 --- a/layers/buffer_validation.cpp +++ b/layers/buffer_validation.cpp @@ -3273,6 +3273,8 @@ bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCr VkImageCreateFlags image_flags = image_state->createInfo.flags; VkFormat image_format = image_state->createInfo.format; + VkImageUsageFlags image_usage = image_state->createInfo.usage; + VkImageTiling image_tiling = image_state->createInfo.tiling; VkFormat view_format = create_info->format; VkImageAspectFlags aspect_mask = create_info->subresourceRange.aspectMask; VkImageType image_type = image_state->createInfo.imageType; @@ -3380,6 +3382,69 @@ bool PreCallValidateCreateImageView(layer_data *device_data, const VkImageViewCr default: break; } + + const VkFormatProperties *format_properties = GetFormatProperties(device_data, view_format); + bool check_tiling_features = false; + VkFormatFeatureFlags tiling_features = 0; + UNIQUE_VALIDATION_ERROR_CODE linear_error_codes[] = { + VALIDATION_ERROR_0ac007dc, VALIDATION_ERROR_0ac007e0, VALIDATION_ERROR_0ac007e2, + VALIDATION_ERROR_0ac007e4, VALIDATION_ERROR_0ac007e6, + }; + UNIQUE_VALIDATION_ERROR_CODE optimal_error_codes[] = { + VALIDATION_ERROR_0ac007e8, VALIDATION_ERROR_0ac007ea, VALIDATION_ERROR_0ac007ec, + VALIDATION_ERROR_0ac007ee, VALIDATION_ERROR_0ac007f0, + }; + UNIQUE_VALIDATION_ERROR_CODE *error_codes = nullptr; + if (image_tiling == VK_IMAGE_TILING_LINEAR) { + tiling_features = format_properties->linearTilingFeatures; + error_codes = linear_error_codes; + check_tiling_features = true; + } else if (image_tiling == VK_IMAGE_TILING_OPTIMAL) { + tiling_features = format_properties->optimalTilingFeatures; + error_codes = optimal_error_codes; + check_tiling_features = true; + } + + if (check_tiling_features) { + if (tiling_features == 0) { + skip |= + log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, + error_codes[0], "IMAGE", + "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the " + "%s flag set. %s", + string_VkFormat(view_format), string_VkImageTiling(image_tiling), validation_error_map[error_codes[0]]); + } else if ((image_usage & VK_IMAGE_USAGE_SAMPLED_BIT) && !(tiling_features & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) { + skip |= + log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, + error_codes[1], "IMAGE", + "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the " + "%s and VK_IMAGE_USAGE_SAMPLED_BIT flags set. %s", + string_VkFormat(view_format), string_VkImageTiling(image_tiling), validation_error_map[error_codes[1]]); + } else if ((image_usage & VK_IMAGE_USAGE_STORAGE_BIT) && !(tiling_features & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)) { + skip |= + log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, + error_codes[2], "IMAGE", + "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the " + "%s and VK_IMAGE_USAGE_STORAGE_BIT flags set. %s", + string_VkFormat(view_format), string_VkImageTiling(image_tiling), validation_error_map[error_codes[2]]); + } else if ((image_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) && + !(tiling_features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) { + skip |= + log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, + error_codes[3], "IMAGE", + "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the " + "%s and VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT flags set. %s", + string_VkFormat(view_format), string_VkImageTiling(image_tiling), validation_error_map[error_codes[3]]); + } else if ((image_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) && + !(tiling_features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) { + skip |= + log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, + error_codes[4], "IMAGE", + "vkCreateImageView() pCreateInfo->format %s cannot be used with an image having the " + "%s and VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT flags set. %s", + string_VkFormat(view_format), string_VkImageTiling(image_tiling), validation_error_map[error_codes[4]]); + } + } } return skip; } diff --git a/layers/vk_validation_error_database.txt b/layers/vk_validation_error_database.txt index 3b2dad9..0690fb7 100644 --- a/layers/vk_validation_error_database.txt +++ b/layers/vk_validation_error_database.txt @@ -741,17 +741,17 @@ VALIDATION_ERROR_0aa2f001~^~N~^~Unknown~^~vkCreateImage~^~VUID-VkImageSwapchainC 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~^~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_0ac007dc~^~Y~^~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)~^~ -VALIDATION_ERROR_0ac007e2~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01009~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_LINEAR and usage contains VK_IMAGE_USAGE_STORAGE_BIT, format must be supported for storage images, as specified by the VK_FORMAT_FEATURE_STORAGE_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-01009)~^~ -VALIDATION_ERROR_0ac007e4~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01010~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_LINEAR and usage contains VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, format must be supported for color attachments, as specified by the VK_FORMAT_FEATURE_COLOR_ATTACHMENT_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-01010)~^~ -VALIDATION_ERROR_0ac007e6~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01011~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_LINEAR and usage contains VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, format must be supported for depth/stencil attachments, as specified by the VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_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-01011)~^~ -VALIDATION_ERROR_0ac007e8~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01012~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_OPTIMAL, format must be format that has at least one supported feature bit present in the value of VkFormatProperties::optimalTilingFeatures returned by vkGetPhysicalDeviceFormatProperties with the same value of format' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01012)~^~ -VALIDATION_ERROR_0ac007ea~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01013~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_OPTIMAL 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::optimalTilingFeatures returned by vkGetPhysicalDeviceFormatProperties with the same value of format' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01013)~^~ -VALIDATION_ERROR_0ac007ec~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01014~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_OPTIMAL and usage contains VK_IMAGE_USAGE_STORAGE_BIT, format must be supported for storage images, as specified by the VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT flag in VkFormatProperties::optimalTilingFeatures returned by vkGetPhysicalDeviceFormatProperties with the same value of format' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01014)~^~ -VALIDATION_ERROR_0ac007ee~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01015~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_OPTIMAL and usage contains VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, format must be supported for color attachments, as specified by the VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT flag in VkFormatProperties::optimalTilingFeatures returned by vkGetPhysicalDeviceFormatProperties with the same value of format' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01015)~^~ -VALIDATION_ERROR_0ac007f0~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01016~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_OPTIMAL and usage contains VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, format must be supported for depth/stencil attachments, as specified by the VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT flag in VkFormatProperties::optimalTilingFeatures returned by vkGetPhysicalDeviceFormatProperties with the same value of format' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01016)~^~ +VALIDATION_ERROR_0ac007e0~^~Y~^~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)~^~ +VALIDATION_ERROR_0ac007e2~^~Y~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01009~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_LINEAR and usage contains VK_IMAGE_USAGE_STORAGE_BIT, format must be supported for storage images, as specified by the VK_FORMAT_FEATURE_STORAGE_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-01009)~^~ +VALIDATION_ERROR_0ac007e4~^~Y~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01010~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_LINEAR and usage contains VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, format must be supported for color attachments, as specified by the VK_FORMAT_FEATURE_COLOR_ATTACHMENT_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-01010)~^~ +VALIDATION_ERROR_0ac007e6~^~Y~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01011~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_LINEAR and usage contains VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, format must be supported for depth/stencil attachments, as specified by the VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_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-01011)~^~ +VALIDATION_ERROR_0ac007e8~^~Y~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01012~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_OPTIMAL, format must be format that has at least one supported feature bit present in the value of VkFormatProperties::optimalTilingFeatures returned by vkGetPhysicalDeviceFormatProperties with the same value of format' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01012)~^~ +VALIDATION_ERROR_0ac007ea~^~Y~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01013~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_OPTIMAL 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::optimalTilingFeatures returned by vkGetPhysicalDeviceFormatProperties with the same value of format' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01013)~^~ +VALIDATION_ERROR_0ac007ec~^~Y~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01014~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_OPTIMAL and usage contains VK_IMAGE_USAGE_STORAGE_BIT, format must be supported for storage images, as specified by the VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT flag in VkFormatProperties::optimalTilingFeatures returned by vkGetPhysicalDeviceFormatProperties with the same value of format' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01014)~^~ +VALIDATION_ERROR_0ac007ee~^~Y~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01015~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_OPTIMAL and usage contains VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, format must be supported for color attachments, as specified by the VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT flag in VkFormatProperties::optimalTilingFeatures returned by vkGetPhysicalDeviceFormatProperties with the same value of format' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01015)~^~ +VALIDATION_ERROR_0ac007f0~^~Y~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-image-01016~^~core~^~The spec valid usage text states 'If image was created with VK_IMAGE_TILING_OPTIMAL and usage contains VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, format must be supported for depth/stencil attachments, as specified by the VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT flag in VkFormatProperties::optimalTilingFeatures returned by vkGetPhysicalDeviceFormatProperties with the same value of format' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-image-01016)~^~ VALIDATION_ERROR_0ac007f2~^~N~^~Unknown~^~vkCreateImageView~^~VUID-VkImageViewCreateInfo-subresourceRange-01017~^~core~^~The spec valid usage text states 'subresourceRange must be a valid image subresource range for image (see Image Views)' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-VkImageViewCreateInfo-subresourceRange-01017)~^~ 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)~^~ diff --git a/tests/layer_validation_tests.cpp b/tests/layer_validation_tests.cpp index 7f53db7..925bbcb 100644 --- a/tests/layer_validation_tests.cpp +++ b/tests/layer_validation_tests.cpp @@ -19,6 +19,7 @@ * Author: Tony Barbour * Author: Cody Northrop * Author: Dave Houlton + * Author: Jeremy Kniager */ #ifdef ANDROID @@ -14015,6 +14016,166 @@ TEST_F(VkLayerTest, CreateImageViewBreaksParameterCompatibilityRequirements) { vkDestroyImage(m_device->device(), imageSparse, nullptr); } +TEST_F(VkLayerTest, CreateImageViewFormatFeatureMismatch) { + TEST_DESCRIPTION("TO BE WRITTEN"); + + // Check for and load required layer + if (InstanceLayerSupported("VK_LAYER_LUNARG_device_profile_api")) { + m_instance_layer_names.push_back("VK_LAYER_LUNARG_device_profile_api"); + } else { + printf(" Did not find VK_LAYER_LUNARG_device_profile_api layer; skipped.\n"); + return; + } + ASSERT_NO_FATAL_FAILURE(InitFramework(myDbgFunc, m_errorMonitor)); + ASSERT_NO_FATAL_FAILURE(InitState()); + + // Load required functions + PFN_vkSetPhysicalDeviceFormatPropertiesEXT fpvkSetPhyiscalDeviceFormatPropertiesEXT = + (PFN_vkSetPhysicalDeviceFormatPropertiesEXT)vkGetInstanceProcAddr(instance(), "vkSetPhysicalDeviceFormatPropertiesEXT"); + PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT = + (PFN_vkGetOriginalPhysicalDeviceFormatPropertiesEXT)vkGetInstanceProcAddr(instance(), + "vkGetOriginalPhysicalDeviceFormatPropertiesEXT"); + + if (!(fpvkSetPhyiscalDeviceFormatPropertiesEXT) || !(fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT)) { + printf(" Can't find device_profile_api functions; skipped.\n"); + return; + } + + // List of features to be tested + VkFormatFeatureFlagBits features[] = {VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT, VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT, + VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT}; + uint32_t feature_count = 4; + // List of usage cases for each feature test + VkImageUsageFlags usages[] = {VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_USAGE_STORAGE_BIT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, + VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT}; + // List of errors that will be thrown in order of tests run + UNIQUE_VALIDATION_ERROR_CODE optimal_error_codes[] = { + VALIDATION_ERROR_0ac007ea, VALIDATION_ERROR_0ac007ec, VALIDATION_ERROR_0ac007ee, VALIDATION_ERROR_0ac007f0, + }; + + VkFormatProperties formatProps; + + // First three tests + uint32_t i = 0; + for (i = 0; i < (feature_count - 1); i++) { + // Modify formats to have mismatched features + + // Format for image + fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_R32G32B32A32_UINT, &formatProps); + formatProps.optimalTilingFeatures |= features[i]; + fpvkSetPhyiscalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_R32G32B32A32_UINT, formatProps); + + memset(&formatProps, 0, sizeof(formatProps)); + + // Format for view + fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_R32G32B32A32_SINT, &formatProps); + formatProps.optimalTilingFeatures = features[(i + 1) % feature_count]; + fpvkSetPhyiscalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_R32G32B32A32_SINT, formatProps); + + // Create image with modified format + VkImageCreateInfo imgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, + nullptr, + VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, + VK_IMAGE_TYPE_2D, + VK_FORMAT_R32G32B32A32_UINT, + {1, 1, 1}, + 1, + 1, + VK_SAMPLE_COUNT_1_BIT, + VK_IMAGE_TILING_OPTIMAL, + usages[i], + VK_SHARING_MODE_EXCLUSIVE, + 0, + nullptr, + VK_IMAGE_LAYOUT_UNDEFINED}; + VkImageObj image(m_device); + image.init(&imgInfo); + ASSERT_TRUE(image.initialized()); + + VkImageView imageView; + + // Initialize VkImageViewCreateInfo with modified format + 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_R32G32B32A32_SINT; + 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, optimal_error_codes[i]); + VkResult res = vkCreateImageView(m_device->device(), &ivci, NULL, &imageView); + m_errorMonitor->VerifyFound(); + + if (!res) { + vkDestroyImageView(m_device->device(), imageView, nullptr); + } + } + + // Test for VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT. Needs special formats + + // Modify formats to have mismatched features + + // Format for image + fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, &formatProps); + formatProps.optimalTilingFeatures |= features[i]; + fpvkSetPhyiscalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, formatProps); + + memset(&formatProps, 0, sizeof(formatProps)); + + // Format for view + fpvkGetOriginalPhysicalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &formatProps); + formatProps.optimalTilingFeatures = features[(i + 1) % feature_count]; + fpvkSetPhyiscalDeviceFormatPropertiesEXT(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, formatProps); + + // Create image with modified format + VkImageCreateInfo imgInfo = {VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, + nullptr, + VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT, + VK_IMAGE_TYPE_2D, + VK_FORMAT_D24_UNORM_S8_UINT, + {1, 1, 1}, + 1, + 1, + VK_SAMPLE_COUNT_1_BIT, + VK_IMAGE_TILING_OPTIMAL, + usages[i], + VK_SHARING_MODE_EXCLUSIVE, + 0, + nullptr, + VK_IMAGE_LAYOUT_UNDEFINED}; + VkImageObj image(m_device); + image.init(&imgInfo); + ASSERT_TRUE(image.initialized()); + + VkImageView imageView; + + // Initialize VkImageViewCreateInfo with modified format + 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_D32_SFLOAT_S8_UINT; + ivci.subresourceRange.layerCount = 1; + ivci.subresourceRange.baseMipLevel = 0; + ivci.subresourceRange.levelCount = 1; + ivci.subresourceRange.baseArrayLayer = 0; + ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; + + // Test for error message + m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, optimal_error_codes[i]); + VkResult res = vkCreateImageView(m_device->device(), &ivci, NULL, &imageView); + m_errorMonitor->VerifyFound(); + + if (!res) { + vkDestroyImageView(m_device->device(), imageView, nullptr); + } +} + TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) { TEST_DESCRIPTION("Delete in-use imageView."); diff --git a/tests/run_wrap_objects_tests.sh b/tests/run_wrap_objects_tests.sh index 09bb6ab..acb8aa4 100755 --- a/tests/run_wrap_objects_tests.sh +++ b/tests/run_wrap_objects_tests.sh @@ -127,7 +127,7 @@ then exit 1 fi -filter=-VkLayerTest.ExceedMemoryAllocationCount +filter=-VkLayerTest.ExceedMemoryAllocationCount:VkLayerTest.CreateImageViewFormatFeatureMismatch # Run the layer validation tests with and without the wrap-objects layer. Diff the results. # Filter out the "Unexpected:" lines because they contain varying object handles. GTEST_PRINT_TIME=0 \ -- 2.7.4