Refactor cube compatibility

Image::isCube() is renamed to isCubeCompatible() because image resources
have no prior knowledge of whether they'll be used for cube image views
or just layered 2D image views.

Also the Vulkan spec demands that VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT is
only used when a cube image view can be created from the image, so some
redundant conditionals have been removed.

Bug: b/198674734
Change-Id: Ic1e79e0b21f5cb389c41cfb6ab3195064db70c22
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/56948
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Vulkan/VkImage.cpp b/src/Vulkan/VkImage.cpp
index 534281f..68c67a6 100644
--- a/src/Vulkan/VkImage.cpp
+++ b/src/Vulkan/VkImage.cpp
@@ -734,7 +734,7 @@
 int Image::borderSize() const
 {
 	// We won't add a border to compressed cube textures, we'll add it when we decompress the texture
-	return (isCube() && !format.isCompressed()) ? 1 : 0;
+	return (isCubeCompatible() && !format.isCompressed()) ? 1 : 0;
 }
 
 VkDeviceSize Image::texelOffsetBytesInStorage(const VkOffset3D &offset, const VkImageSubresource &subresource) const
@@ -832,9 +832,13 @@
 	return format.getAspectFormat(aspect);
 }
 
-bool Image::isCube() const
+bool Image::isCubeCompatible() const
 {
-	return (flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) && (imageType == VK_IMAGE_TYPE_2D);
+	bool cubeCompatible = (flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT);
+	ASSERT(!cubeCompatible || (imageType == VK_IMAGE_TYPE_2D));  // VUID-VkImageCreateInfo-flags-00949
+	ASSERT(!cubeCompatible || (arrayLayers >= 6));               // VUID-VkImageCreateInfo-imageType-00954
+
+	return cubeCompatible;
 }
 
 uint8_t *Image::end() const
@@ -1089,7 +1093,7 @@
 
 bool Image::requiresPreprocessing() const
 {
-	return (isCube() && (arrayLayers >= 6)) || decompressedImage;
+	return isCubeCompatible() || decompressedImage;
 }
 
 void Image::contentsChanged(const VkImageSubresourceRange &subresourceRange, ContentsChangedContext contentsChangedContext)
@@ -1299,7 +1303,7 @@
 
 bool Image::updateCube(const VkImageSubresource &subres)
 {
-	if(isCube() && (arrayLayers >= 6))
+	if(isCubeCompatible())
 	{
 		VkImageSubresource subresource = subres;
 
diff --git a/src/Vulkan/VkImage.hpp b/src/Vulkan/VkImage.hpp
index 9274191..4ef5879 100644
--- a/src/Vulkan/VkImage.hpp
+++ b/src/Vulkan/VkImage.hpp
@@ -90,7 +90,7 @@
 	int rowPitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) const;
 	int slicePitchBytes(VkImageAspectFlagBits aspect, uint32_t mipLevel) const;
 	void *getTexelPointer(const VkOffset3D &offset, const VkImageSubresource &subresource) const;
-	bool isCube() const;
+	bool isCubeCompatible() const;
 	bool is3DSlice() const;
 	uint8_t *end() const;
 	VkDeviceSize getLayerSize(VkImageAspectFlagBits aspect) const;
diff --git a/src/Vulkan/VkImageView.cpp b/src/Vulkan/VkImageView.cpp
index 35663c8..d7d3365 100644
--- a/src/Vulkan/VkImageView.cpp
+++ b/src/Vulkan/VkImageView.cpp
@@ -160,11 +160,11 @@
 		       ((imageType == VK_IMAGE_TYPE_3D) &&
 		        (imageArrayLayers == 1));
 	case VK_IMAGE_VIEW_TYPE_CUBE:
-		return image->isCube() &&
+		return image->isCubeCompatible() &&
 		       (imageArrayLayers >= subresourceRange.layerCount) &&
 		       (subresourceRange.layerCount == 6);
 	case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
-		return image->isCube() &&
+		return image->isCubeCompatible() &&
 		       (imageArrayLayers >= subresourceRange.layerCount) &&
 		       (subresourceRange.layerCount >= 6);
 	case VK_IMAGE_VIEW_TYPE_3D: