Fix image sizes for formats that need a multiple of 2.

All these have in their format definition something like

"Images in this format must be defined with a width that is a multiple
 of two."

in their format definition.

This patch makes sure we actually use even sizes for images with these
formats.

It is not ideal that I have to hardcode these lists but I don't know a
better source to get them from.

Affects:

dEQP-VK.api.invariance.random

Components: Vulkan

VK-GL-CTS issue: 1766

Change-Id: Ie19583db56e7ae483136e1fb4651ae625efb9c02
diff --git a/external/vulkancts/framework/vulkan/vkImageUtil.cpp b/external/vulkancts/framework/vulkan/vkImageUtil.cpp
index b2a02ab..95ece26 100644
--- a/external/vulkancts/framework/vulkan/vkImageUtil.cpp
+++ b/external/vulkancts/framework/vulkan/vkImageUtil.cpp
@@ -199,6 +199,52 @@
 	}
 }
 
+bool isYCbCr420Format (VkFormat format)
+{
+	switch (format)
+	{
+		case VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR:
+		case VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR:
+		case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16_KHR:
+		case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16_KHR:
+		case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16_KHR:
+		case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16_KHR:
+		case VK_FORMAT_G16_B16_R16_3PLANE_420_UNORM_KHR:
+		case VK_FORMAT_G16_B16R16_2PLANE_420_UNORM_KHR:
+			return true;
+
+		default:
+			return false;
+	}
+}
+
+bool isYCbCr422Format (VkFormat format)
+{
+	switch (format)
+	{
+		case VK_FORMAT_G8B8G8R8_422_UNORM_KHR:
+		case VK_FORMAT_B8G8R8G8_422_UNORM_KHR:
+		case VK_FORMAT_G8_B8_R8_3PLANE_422_UNORM_KHR:
+		case VK_FORMAT_G8_B8R8_2PLANE_422_UNORM_KHR:
+		case VK_FORMAT_G10X6B10X6G10X6R10X6_422_UNORM_4PACK16_KHR:
+		case VK_FORMAT_B10X6G10X6R10X6G10X6_422_UNORM_4PACK16_KHR:
+		case VK_FORMAT_G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16_KHR:
+		case VK_FORMAT_G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16_KHR:
+		case VK_FORMAT_G12X4B12X4G12X4R12X4_422_UNORM_4PACK16_KHR:
+		case VK_FORMAT_B12X4G12X4R12X4G12X4_422_UNORM_4PACK16_KHR:
+		case VK_FORMAT_G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16_KHR:
+		case VK_FORMAT_G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16_KHR:
+		case VK_FORMAT_G16B16G16R16_422_UNORM_KHR:
+		case VK_FORMAT_B16G16R16G16_422_UNORM_KHR:
+		case VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM_KHR:
+		case VK_FORMAT_G16_B16R16_2PLANE_422_UNORM_KHR:
+			return true;
+
+		default:
+			return false;
+	}
+}
+
 const PlanarFormatDescription& getYCbCrPlanarFormatDescription (VkFormat format)
 {
 	using tcu::TextureFormat;
diff --git a/external/vulkancts/framework/vulkan/vkImageUtil.hpp b/external/vulkancts/framework/vulkan/vkImageUtil.hpp
index 6dc4a8f..6c43baa 100644
--- a/external/vulkancts/framework/vulkan/vkImageUtil.hpp
+++ b/external/vulkancts/framework/vulkan/vkImageUtil.hpp
@@ -126,6 +126,8 @@
 VkImageAspectFlagBits			getPlaneAspect					(deUint32 planeNdx);
 deUint32						getAspectPlaneNdx				(VkImageAspectFlagBits planeAspect);
 bool							isChromaSubsampled				(VkFormat format);
+bool							isYCbCr422Format				(VkFormat format);
+bool							isYCbCr420Format				(VkFormat format);
 
 tcu::PixelBufferAccess			getChannelAccess				(const PlanarFormatDescription&	formatInfo,
 																 const tcu::UVec2&				size,
diff --git a/external/vulkancts/modules/vulkan/api/vktApiMemoryRequirementInvarianceTests.cpp b/external/vulkancts/modules/vulkan/api/vktApiMemoryRequirementInvarianceTests.cpp
index a7685cf..2063159 100644
--- a/external/vulkancts/modules/vulkan/api/vktApiMemoryRequirementInvarianceTests.cpp
+++ b/external/vulkancts/modules/vulkan/api/vktApiMemoryRequirementInvarianceTests.cpp
@@ -26,6 +26,7 @@
 #include "vkQueryUtil.hpp"
 #include "vkMemUtil.hpp"
 #include "vkRefUtil.hpp"
+#include "vkImageUtil.hpp"
 
 
 namespace vkt
@@ -166,16 +167,20 @@
 	m_dedicated		= dedicated && deRandom_getBool(&random);
 	// If linear formats are supported, pick it randomly
 	m_linear		= (linearformats.size() > 0) && deRandom_getBool(&random);
-	// Random small size for causing potential alignment issues
-	m_size			= tcu::IVec2(deRandom_getUint32(&random) % 16 + 3,
-								 deRandom_getUint32(&random) % 16 + 3);
-	// Pick random memory type from the supported set
-	m_memoryType	= memoryTypes[deRandom_getUint32(&random) % memoryTypes.size()];
 
 	if (m_linear)
 		m_colorFormat = (VkFormat)linearformats[deRandom_getUint32(&random) % linearformats.size()];
 	else
 		m_colorFormat = (VkFormat)optimalformats[deRandom_getUint32(&random) % optimalformats.size()];
+
+	int	widthAlignment	= (isYCbCr420Format(m_colorFormat) || isYCbCr422Format(m_colorFormat)) ? 2 : 1;
+	int	heightAlignment	= isYCbCr420Format(m_colorFormat) ? 2 : 1;
+
+	// Random small size for causing potential alignment issues
+	m_size			= tcu::IVec2((deRandom_getUint32(&random) % 16 + 3) & ~(widthAlignment - 1),
+								 (deRandom_getUint32(&random) % 16 + 3) & ~(heightAlignment - 1));
+	// Pick random memory type from the supported set
+	m_memoryType	= memoryTypes[deRandom_getUint32(&random) % memoryTypes.size()];
 }
 
 ImageAllocator::~ImageAllocator ()