layers:Share image aspect validation code
Mult-purpose the image aspect mask validation code to run both at
CreateImageView time and at ValidateBarriers time. There was some basic
image aspect mask validation at ValidateBarriers, but this makes it
more complete and will catch some escapes.
Update the tests related to these checks to account changes in error
messages and also trying to remove some unexpected errors.
diff --git a/tests/layer_validation_tests.cpp b/tests/layer_validation_tests.cpp
index 649b052..013e9b1 100644
--- a/tests/layer_validation_tests.cpp
+++ b/tests/layer_validation_tests.cpp
@@ -7941,9 +7941,12 @@
m_errorMonitor->VerifyFound();
// Now exercise barrier aspect bit errors, first DS
- m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth and stencil format and thus must "
- "have either one or both of VK_IMAGE_ASPECT_DEPTH_BIT and "
- "VK_IMAGE_ASPECT_STENCIL_BIT set.");
+ m_errorMonitor->SetDesiredFailureMsg(
+ VK_DEBUG_REPORT_ERROR_BIT_EXT,
+ "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
+ m_errorMonitor->SetDesiredFailureMsg(
+ VK_DEBUG_REPORT_ERROR_BIT_EXT,
+ "Depth/stencil image formats must have at least one of VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
VkDepthStencilObj ds_image(m_device);
ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
ASSERT_TRUE(ds_image.initialized());
@@ -7960,8 +7963,10 @@
vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
- m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a depth-only format and thus must "
- "have VK_IMAGE_ASPECT_DEPTH_BIT set.");
+ m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
+ "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
+ m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
+ "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
VkDepthStencilObj d_image(m_device);
d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
ASSERT_TRUE(d_image.initialized());
@@ -7977,8 +7982,8 @@
vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
// Now test stencil-only
- m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a stencil-only format and thus must "
- "have VK_IMAGE_ASPECT_STENCIL_BIT set.");
+ m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
+ "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
VkDepthStencilObj s_image(m_device);
s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
ASSERT_TRUE(s_image.initialized());
@@ -7992,8 +7997,10 @@
m_errorMonitor->VerifyFound();
}
// Finally test color
- m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image is a color format and thus must "
- "have VK_IMAGE_ASPECT_COLOR_BIT set.");
+ m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
+ "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
+ m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
+ "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
VkImageObj c_image(m_device);
c_image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
ASSERT_TRUE(c_image.initialized());
@@ -13533,9 +13540,11 @@
TEST_F(VkLayerTest, InvalidImageViewAspect) {
TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
- m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView: Color image "
+ m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView(): Color image "
"formats must have ONLY the "
"VK_IMAGE_ASPECT_COLOR_BIT set");
+ m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
+ "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
ASSERT_NO_FATAL_FAILURE(InitState());
@@ -13545,12 +13554,13 @@
ASSERT_TRUE(image.initialized());
VkImageViewCreateInfo image_view_create_info = {};
- image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
+ image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
image_view_create_info.image = image.handle();
image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
image_view_create_info.format = tex_format;
image_view_create_info.subresourceRange.baseMipLevel = 0;
image_view_create_info.subresourceRange.levelCount = 1;
+ image_view_create_info.subresourceRange.layerCount = 1;
// Cause an error by setting an invalid image aspect
image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
@@ -13759,6 +13769,9 @@
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCreateImageView called with 0 in "
"pCreateInfo->subresourceRange."
"layerCount");
+ m_errorMonitor->SetDesiredFailureMsg(
+ VK_DEBUG_REPORT_ERROR_BIT_EXT,
+ "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
// View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
imgViewInfo.subresourceRange.layerCount = 0;
vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
@@ -13766,6 +13779,9 @@
imgViewInfo.subresourceRange.layerCount = 1;
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "but both must be color formats");
+ m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Formats MUST be IDENTICAL unless "
+ "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
+ "was set on image creation.");
// Can't use depth format for view into color image - Expect INVALID_FORMAT
imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
@@ -13785,6 +13801,10 @@
m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "can support ImageViews with "
"differing formats but they must be "
"in the same compatibility class.");
+ // TODO: Update framework to easily passing mutable flag into ImageObj init
+ // For now just allowing image for this one test to not have memory bound
+ m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
+ " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
// Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
// VIEW_CREATE_ERROR
VkImageCreateInfo mutImgInfo = image.create_info();