Merge "Add glu::BufferOffsetAsPointer utility" into pie-cts-dev
diff --git a/external/vulkancts/modules/vulkan/api/vktApiFeatureInfo.cpp b/external/vulkancts/modules/vulkan/api/vktApiFeatureInfo.cpp
index f79a6da..c1c5ad1 100644
--- a/external/vulkancts/modules/vulkan/api/vktApiFeatureInfo.cpp
+++ b/external/vulkancts/modules/vulkan/api/vktApiFeatureInfo.cpp
@@ -2516,9 +2516,10 @@
 																	properties.maxExtent.height	>= deviceLimits.maxImageDimension3D &&
 																	properties.maxExtent.depth	>= deviceLimits.maxImageDimension3D),
 								  "Reported dimensions smaller than device limits");
-					results.check(properties.maxMipLevels == fullMipPyramidSize, "maxMipLevels is not full mip pyramid size");
-					results.check(imageType == VK_IMAGE_TYPE_3D || properties.maxArrayLayers >= deviceLimits.maxImageArrayLayers,
-								  "maxArrayLayers smaller than device limits");
+					results.check((isYCbCrFormat(format) && (properties.maxMipLevels == 1)) || properties.maxMipLevels == fullMipPyramidSize,
+					              "Invalid mip pyramid size");
+					results.check((isYCbCrFormat(format) && (properties.maxArrayLayers == 1)) || imageType == VK_IMAGE_TYPE_3D ||
+					              properties.maxArrayLayers >= deviceLimits.maxImageArrayLayers, "Invalid maxArrayLayers");
 				}
 				else
 				{
diff --git a/external/vulkancts/modules/vulkan/api/vktApiObjectManagementTests.cpp b/external/vulkancts/modules/vulkan/api/vktApiObjectManagementTests.cpp
index 05fbeeb..ef6d871 100644
--- a/external/vulkancts/modules/vulkan/api/vktApiObjectManagementTests.cpp
+++ b/external/vulkancts/modules/vulkan/api/vktApiObjectManagementTests.cpp
@@ -2410,6 +2410,7 @@
 // Creating VkDevice and VkInstance can take significantly longer than other object types
 template<>					int getCreateCount<Instance>	(void) { return 20;		}
 template<>					int getCreateCount<Device>		(void) { return 20;		}
+template<>					int getCreateCount<DeviceGroup>	(void) { return 20;		}
 
 template<typename Object>
 class CreateThread : public ThreadGroupThread
@@ -2590,8 +2591,9 @@
 	return tcu::TestStatus::pass("Ok");
 }
 
-template<typename Object>	deUint32	getOomIterLimit			(void) { return 1024;	}
-template<>					deUint32	getOomIterLimit<Device>	(void) { return 20;		}
+template<typename Object>	deUint32	getOomIterLimit					(void) { return 1024;	}
+template<>					deUint32	getOomIterLimit<Device>         (void) { return 20;		}
+template<>					deUint32	getOomIterLimit<DeviceGroup>	(void) { return 20;		}
 
 template<typename Object>
 tcu::TestStatus allocCallbackFailTest (Context& context, typename Object::Parameters params)
diff --git a/external/vulkancts/modules/vulkan/image/vktImageCompressionTranscodingSupport.cpp b/external/vulkancts/modules/vulkan/image/vktImageCompressionTranscodingSupport.cpp
index bb3a9e3..a6ae4df 100644
--- a/external/vulkancts/modules/vulkan/image/vktImageCompressionTranscodingSupport.cpp
+++ b/external/vulkancts/modules/vulkan/image/vktImageCompressionTranscodingSupport.cpp
@@ -51,6 +51,7 @@
 #include "tcuSurface.hpp"
 
 #include <vector>
+
 using namespace vk;
 namespace vkt
 {
@@ -111,6 +112,7 @@
 	VkImageUsageFlags	uncompressedImageUsage;
 	bool				useMipmaps;
 	VkFormat			formatForVerify;
+	bool				formatIsASTC;
 };
 
 template<typename T>
@@ -128,6 +130,93 @@
 const deUint32 SINGLE_LEVEL = 1u;
 const deUint32 SINGLE_LAYER = 1u;
 
+enum BinaryCompareMode
+{
+	COMPARE_MODE_NORMAL,
+	COMPARE_MODE_ALLOW_ASTC_ERROR_COLOUR_WARNING,
+};
+
+enum BinaryCompareResult
+{
+	COMPARE_RESULT_OK,
+	COMPARE_RESULT_ASTC_QUALITY_WARNING,
+	COMPARE_RESULT_FAILED,
+};
+
+const deUint32 ASTC_LDR_ERROR_COLOUR = 0xFFFF00FF;
+const deUint32 ASTC_HDR_ERROR_COLOUR = 0x00000000;
+
+static BinaryCompareResult BinaryCompare(const void				*reference,
+										 const void				*result,
+										 VkDeviceSize			sizeInBytes,
+										 VkFormat				formatForVerify,
+										 BinaryCompareMode		mode)
+{
+	DE_UNREF(formatForVerify);
+
+	// Compare quickly using deMemCmp
+	if (deMemCmp(reference, result, (size_t)sizeInBytes) == 0)
+	{
+		return COMPARE_RESULT_OK;
+	}
+	// If deMemCmp indicated a mismatch, we can re-check with a manual comparison of
+	// the ref and res images that allows for ASTC error colour mismatches if the ASTC
+	// comparison mode was selected. This slows down the affected ASTC tests if you
+	// didn't pass in the first comparison, but means in the general case the
+	// comparion is still fast.
+	else if (mode == COMPARE_MODE_ALLOW_ASTC_ERROR_COLOUR_WARNING)
+	{
+		bool bWarn = false;
+		bool bFail = false;
+		const deUint32 *pui32RefVal = (deUint32*)reference;
+		const deUint32 *pui32ResVal = (deUint32*)result;
+
+		DE_ASSERT(formatForVerify == VK_FORMAT_R8G8B8A8_UNORM);
+		size_t numPixels = (size_t)(sizeInBytes / 4) /* bytes */;
+		for (size_t i = 0; i < numPixels; i++)
+		{
+			const deUint32 ref = *pui32RefVal++;
+			const deUint32 res = *pui32ResVal++;
+
+			if (ref != res)
+			{
+				// QualityWarning !1231: If the astc pixel was the ASTC LDR error colour
+				// and the result image has the HDR error colour (or vice versa as the test
+				// cases below sometimes reverse the operands) then issue a quality warning
+				// instead of a failure.
+				if ((ref == ASTC_LDR_ERROR_COLOUR && res == ASTC_HDR_ERROR_COLOUR) ||
+					(ref == ASTC_HDR_ERROR_COLOUR && res == ASTC_LDR_ERROR_COLOUR))
+				{
+					bWarn = true;
+				}
+				else
+				{
+					bFail = true;
+				}
+			}
+		}
+
+		if (!bFail)
+		{
+			return (bWarn)
+				? (COMPARE_RESULT_ASTC_QUALITY_WARNING)
+				: (COMPARE_RESULT_OK);
+		}
+	}
+
+	return COMPARE_RESULT_FAILED;
+}
+
+static bool FormatIsASTC(VkFormat format)
+{
+	return deInRange32(format, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_ASTC_12x12_SRGB_BLOCK);
+}
+
+static TestStatus TestStatusASTCQualityWarning()
+{
+	return TestStatus(QP_TEST_RESULT_QUALITY_WARNING, "ASTC HDR error colour output instead of LDR error colour");
+}
+
 class BasicTranscodingTestInstance : public TestInstance
 {
 public:
@@ -153,6 +242,10 @@
 	const deUint32			m_levelCount;
 	const UVec3				m_layerSize;
 
+	// Detected error colour mismatch while verifying image. Output
+	// the ASTC quality warning instead of a pass
+	bool					m_bASTCErrorColourMismatch;
+
 private:
 	deUint32				findMipMapLevelCount			();
 };
@@ -193,6 +286,7 @@
 	, m_blockHeight	(getBlockHeight(m_parameters.formatCompressed))
 	, m_levelCount	(findMipMapLevelCount())
 	, m_layerSize	(getLayerSize(m_parameters.imageType, m_parameters.size))
+	, m_bASTCErrorColourMismatch(false)
 {
 	DE_ASSERT(deLog2Floor32(m_parameters.size.x()) == deLog2Floor32(m_parameters.size.y()));
 }
@@ -542,6 +636,13 @@
 	};
 	if (!decompressImage(*cmdBuffer, imageData, mipMapSizes))
 			return TestStatus::fail("Fail");
+
+	if (m_bASTCErrorColourMismatch)
+	{
+		DE_ASSERT(m_parameters.formatIsASTC);
+		return TestStatusASTCQualityWarning();
+	}
+
 	return TestStatus::pass("Pass");
 }
 
@@ -907,7 +1008,7 @@
 			DE_NULL,															// const void*				pNext;
 			0u,																	// VkImageCreateFlags		flags;
 			VK_IMAGE_TYPE_2D,													// VkImageType				imageType;
-			VK_FORMAT_R8G8B8A8_UNORM,											// VkFormat					format;
+			m_parameters.formatForVerify,										// VkFormat					format;
 			extentCompressed,													// VkExtent3D				extent;
 			1u,																	// deUint32					mipLevels;
 			1u,																	// deUint32					arrayLayers;
@@ -976,7 +1077,7 @@
 		Move<VkDescriptorSet>			descriptorSet			= makeDescriptorSet(vk, device, *descriptorPool, *descriptorSetLayout);
 		const Unique<VkPipelineLayout>	pipelineLayout			(makePipelineLayout(vk, device, *descriptorSetLayout));
 		const Unique<VkPipeline>		pipeline				(makeComputePipeline(vk, device, *pipelineLayout, *shaderModule));
-		const VkDeviceSize				bufferSize				= getImageSizeBytes(IVec3((int)extentCompressed.width, (int)extentCompressed.height, (int)extentCompressed.depth), VK_FORMAT_R8G8B8A8_UNORM);
+		const VkDeviceSize				bufferSize				= getImageSizeBytes(IVec3((int)extentCompressed.width, (int)extentCompressed.height, (int)extentCompressed.depth), m_parameters.formatForVerify);
 		Buffer							resultBuffer			(vk, device, allocator,
 																	makeBufferCreateInfo(bufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT), MemoryRequirement::HostVisible);
 		Buffer							referenceBuffer			(vk, device, allocator,
@@ -1162,7 +1263,18 @@
 		invalidateMappedMemoryRange(vk, device, resultAlloc.getMemory(), resultAlloc.getOffset(), bufferSize);
 		invalidateMappedMemoryRange(vk, device, referenceAlloc.getMemory(), referenceAlloc.getOffset(), bufferSize);
 
-		if (deMemCmp(resultAlloc.getHostPtr(), referenceAlloc.getHostPtr(), (size_t)bufferSize) != 0)
+		BinaryCompareMode compareMode =
+			(m_parameters.formatIsASTC)
+				?(COMPARE_MODE_ALLOW_ASTC_ERROR_COLOUR_WARNING)
+				:(COMPARE_MODE_NORMAL);
+
+		BinaryCompareResult res = BinaryCompare(referenceAlloc.getHostPtr(),
+												resultAlloc.getHostPtr(),
+												(size_t)bufferSize,
+												m_parameters.formatForVerify,
+												compareMode);
+
+		if (res == COMPARE_RESULT_FAILED)
 		{
 			ConstPixelBufferAccess	resultPixels		(mapVkFormat(decompressedImageInfo.format), decompressedImageInfo.extent.width, decompressedImageInfo.extent.height, decompressedImageInfo.extent.depth, resultAlloc.getHostPtr());
 			ConstPixelBufferAccess	referencePixels		(mapVkFormat(decompressedImageInfo.format), decompressedImageInfo.extent.width, decompressedImageInfo.extent.height, decompressedImageInfo.extent.depth, referenceAlloc.getHostPtr());
@@ -1170,6 +1282,10 @@
 			if(!fuzzyCompare(m_context.getTestContext().getLog(), "Image Comparison", "Image Comparison", resultPixels, referencePixels, 0.001f, tcu::COMPARE_LOG_EVERYTHING))
 				return false;
 		}
+		else if (res == COMPARE_RESULT_ASTC_QUALITY_WARNING)
+		{
+			m_bASTCErrorColourMismatch = true;
+		}
 	}
 
 	return true;
@@ -1420,6 +1536,12 @@
 					return TestStatus::fail("Images difference detected");
 			}
 
+	if (m_bASTCErrorColourMismatch)
+	{
+		DE_ASSERT(m_parameters.formatIsASTC);
+		return TestStatusASTCQualityWarning();
+	}
+
 	return TestStatus::pass("Pass");
 }
 
@@ -2006,7 +2128,18 @@
 		const Allocation&	resDstBufferAlloc	= resDstBuffer->getAllocation();
 		invalidateMappedMemoryRange(vk, device, resDstBufferAlloc.getMemory(), resDstBufferAlloc.getOffset(), dstBufferSize);
 
-		if (deMemCmp(refDstBufferAlloc.getHostPtr(), resDstBufferAlloc.getHostPtr(), (size_t)dstBufferSize) != 0)
+		BinaryCompareMode compareMode =
+			(m_parameters.formatIsASTC)
+				?(COMPARE_MODE_ALLOW_ASTC_ERROR_COLOUR_WARNING)
+				:(COMPARE_MODE_NORMAL);
+
+		BinaryCompareResult res = BinaryCompare(refDstBufferAlloc.getHostPtr(),
+												resDstBufferAlloc.getHostPtr(),
+												dstBufferSize,
+												m_parameters.formatForVerify,
+												compareMode);
+
+		if (res == COMPARE_RESULT_FAILED)
 		{
 			// Do fuzzy to log error mask
 			invalidateMappedMemoryRange(vk, device, resDstBufferAlloc.getMemory(), resDstBufferAlloc.getOffset(), dstBufferSize);
@@ -2024,6 +2157,10 @@
 
 			return false;
 		}
+		else if (res == COMPARE_RESULT_ASTC_QUALITY_WARNING)
+		{
+			m_bASTCErrorColourMismatch = true;
+		}
 	}
 
 	return true;
@@ -2608,7 +2745,7 @@
 			!physicalDeviceFeatures.textureCompressionETC2)
 			TCU_THROW(NotSupportedError, "textureCompressionETC2 not supported");
 
-		if (deInRange32(m_parameters.formatCompressed, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_ASTC_12x12_SRGB_BLOCK) &&
+		if (m_parameters.formatIsASTC &&
 			!physicalDeviceFeatures.textureCompressionASTC_LDR)
 			TCU_THROW(NotSupportedError, "textureCompressionASTC_LDR not supported");
 
@@ -2919,7 +3056,8 @@
 								compressedImageViewUsageFlags[operationNdx],
 								uncompressedImageUsageFlags[operationNdx],
 								mipmapTest,
-								VK_FORMAT_R8G8B8A8_UNORM
+								VK_FORMAT_R8G8B8A8_UNORM,
+								FormatIsASTC(formatCompressed)
 							};
 
 							compressedFormatGroup->addChild(new TexelViewCompatibleCase(testCtx, uncompressedFormatGroupName, "", parameters));
diff --git a/external/vulkancts/modules/vulkan/renderpass/vktRenderPassTests.cpp b/external/vulkancts/modules/vulkan/renderpass/vktRenderPassTests.cpp
index d2da6ca..e6afbf7 100644
--- a/external/vulkancts/modules/vulkan/renderpass/vktRenderPassTests.cpp
+++ b/external/vulkancts/modules/vulkan/renderpass/vktRenderPassTests.cpp
@@ -5984,6 +5984,14 @@
 																vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
 																vk::VK_DEPENDENCY_BY_REGION_BIT));
 
+								deps.push_back(SubpassDependency(1, 1,
+																vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+																vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
+
+																vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
+																vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
+																vk::VK_DEPENDENCY_BY_REGION_BIT));
+
 								if (useInputAspect)
 								{
 									const VkInputAttachmentAspectReference inputAspect =
@@ -6220,14 +6228,6 @@
 																vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
 																0u));
 
-								deps.push_back(SubpassDependency(1, 1,
-																vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
-																vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
-
-																vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
-																vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
-																vk::VK_DEPENDENCY_BY_REGION_BIT));
-
 								if (useInputAspect)
 								{
 									const VkInputAttachmentAspectReference inputAspect =
@@ -6296,6 +6296,14 @@
 																vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
 																vk::VK_DEPENDENCY_BY_REGION_BIT));
 
+								deps.push_back(SubpassDependency(1, 1,
+																vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
+																vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
+
+																vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
+																vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
+																vk::VK_DEPENDENCY_BY_REGION_BIT));
+
 
 								if (useInputAspect)
 								{
@@ -6449,10 +6457,10 @@
 																	vk::VK_DEPENDENCY_BY_REGION_BIT));
 
 									deps.push_back(SubpassDependency(1, 1,
-																	vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+																	vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
 																	vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
 
-																	vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
+																	vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
 																	vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
 																	vk::VK_DEPENDENCY_BY_REGION_BIT));
 
@@ -6605,10 +6613,10 @@
 																	vk::VK_DEPENDENCY_BY_REGION_BIT));
 
 									deps.push_back(SubpassDependency(1, 1,
-																	vk::VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+																	vk::VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | vk::VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
 																	vk::VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
 
-																	vk::VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
+																	vk::VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
 																	vk::VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
 																	vk::VK_DEPENDENCY_BY_REGION_BIT));
 
diff --git a/external/vulkancts/modules/vulkan/shaderexecutor/vktShaderBuiltinPrecisionTests.cpp b/external/vulkancts/modules/vulkan/shaderexecutor/vktShaderBuiltinPrecisionTests.cpp
index f55166c..3ee72fb 100644
--- a/external/vulkancts/modules/vulkan/shaderexecutor/vktShaderBuiltinPrecisionTests.cpp
+++ b/external/vulkancts/modules/vulkan/shaderexecutor/vktShaderBuiltinPrecisionTests.cpp
@@ -69,7 +69,7 @@
 	// platforms where toggling floating-point rounding mode is slow (emulated arm on x86).
 	// As a workaround watchdog is kept happy by touching it periodically during reference
 	// interval computation.
-	TOUCH_WATCHDOG_VALUE_FREQUENCY	= 4096
+	TOUCH_WATCHDOG_VALUE_FREQUENCY	= 512
 };
 
 namespace vkt