Merge vk-gl-cts/vulkan-cts-1.3.2 into vk-gl-cts/vulkan-cts-1.3.3

Change-Id: Icf1eec1fba1f1272f424878113e510fa6fb8a92a
diff --git a/external/vulkancts/framework/vulkan/vkRef.hpp b/external/vulkancts/framework/vulkan/vkRef.hpp
index 2416d7c..4a721c3 100644
--- a/external/vulkancts/framework/vulkan/vkRef.hpp
+++ b/external/vulkancts/framework/vulkan/vkRef.hpp
@@ -273,18 +273,18 @@
 class RefBase
 {
 public:
-						~RefBase	(void);
+						~RefBase		(void);
 
-	inline const T&		get			(void) const throw() { return m_data.object;	}
-	inline const T&		operator*	(void) const throw() { return get();			}
-	inline operator		bool		(void) const throw() { return !!get();			}
+	inline const T&		get				(void) const throw() { return m_data.object;	}
+	inline const T&		operator*		(void) const throw() { return get();			}
+	inline explicit		operator bool	(void) const throw() { return !!get();			}
 
 protected:
-						RefBase		(RefData<T> data) : m_data(data)	{}
+						RefBase			(RefData<T> data) : m_data(data)	{}
 
-	void				reset		(void);				//!< Release previous object, set to null.
-	RefData<T>			disown		(void) throw();		//!< Disown and return object (ownership transferred to caller).
-	void				assign		(RefData<T> data);	//!< Set new pointer, release previous pointer.
+	void				reset			(void);				//!< Release previous object, set to null.
+	RefData<T>			disown			(void) throw();		//!< Disown and return object (ownership transferred to caller).
+	void				assign			(RefData<T> data);	//!< Set new pointer, release previous pointer.
 
 private:
 	RefData<T>			m_data;
diff --git a/external/vulkancts/modules/vulkan/dynamic_state/vktDynamicStateComputeTests.cpp b/external/vulkancts/modules/vulkan/dynamic_state/vktDynamicStateComputeTests.cpp
index d5a4739..2491f45 100644
--- a/external/vulkancts/modules/vulkan/dynamic_state/vktDynamicStateComputeTests.cpp
+++ b/external/vulkancts/modules/vulkan/dynamic_state/vktDynamicStateComputeTests.cpp
@@ -42,6 +42,7 @@
 #include <cstring>
 #include <iterator>
 #include <numeric>
+#include <memory>
 
 namespace vkt
 {
@@ -53,8 +54,6 @@
 
 using namespace vk;
 
-de::SharedPtr<Move<vk::VkDevice>>	g_singletonDevice;
-
 // Additional objects needed to set a given dynamic state that need to exist beyond the state-setting call. Empty by default.
 struct DynamicStateData
 {
@@ -567,64 +566,141 @@
 	return itr->second;
 }
 
-VkDevice getDevice(Context& context, VkDynamicState dynamicState)
+// Device helper: this is needed in some tests when we create custom devices.
+class DeviceHelper
 {
-	const auto stateInfo = getDynamicStateInfo(dynamicState);
-	if (de::contains(stateInfo.requirements.begin(), stateInfo.requirements.end(), "VK_NV_shading_rate_image"))
+public:
+	virtual ~DeviceHelper () {}
+	virtual const DeviceInterface&	getDeviceInterface	(void) const = 0;
+	virtual VkDevice				getDevice			(void) const = 0;
+	virtual uint32_t				getQueueFamilyIndex	(void) const = 0;
+	virtual VkQueue					getQueue			(void) const = 0;
+	virtual Allocator&				getAllocator		(void) const = 0;
+};
+
+// This one just reuses the default device from the context.
+class ContextDeviceHelper : public DeviceHelper
+{
+public:
+	ContextDeviceHelper (Context& context)
+		: m_deviceInterface		(context.getDeviceInterface())
+		, m_device				(context.getDevice())
+		, m_queueFamilyIndex	(context.getUniversalQueueFamilyIndex())
+		, m_queue				(context.getUniversalQueue())
+		, m_allocator			(context.getDefaultAllocator())
+		{}
+
+	virtual ~ContextDeviceHelper () {}
+
+	const DeviceInterface&	getDeviceInterface	(void) const override	{ return m_deviceInterface;		}
+	VkDevice				getDevice			(void) const override	{ return m_device;				}
+	uint32_t				getQueueFamilyIndex	(void) const override	{ return m_queueFamilyIndex;	}
+	VkQueue					getQueue			(void) const override	{ return m_queue;				}
+	Allocator&				getAllocator		(void) const override	{ return m_allocator;			}
+
+protected:
+	const DeviceInterface&	m_deviceInterface;
+	const VkDevice			m_device;
+	const uint32_t			m_queueFamilyIndex;
+	const VkQueue			m_queue;
+	Allocator&				m_allocator;
+};
+
+// This one creates a new device with VK_NV_shading_rate_image.
+class ShadingRateImageDeviceHelper : public DeviceHelper
+{
+public:
+	ShadingRateImageDeviceHelper (Context& context)
 	{
-		if (!g_singletonDevice)
+		const auto&	vkp				= context.getPlatformInterface();
+		const auto&	vki				= context.getInstanceInterface();
+		const auto	instance		= context.getInstance();
+		const auto	physicalDevice	= context.getPhysicalDevice();
+		const auto	queuePriority	= 1.0f;
+
+		// Queue index first.
+		m_queueFamilyIndex = context.getUniversalQueueFamilyIndex();
+
+		// Create a universal queue that supports graphics and compute.
+		const VkDeviceQueueCreateInfo queueParams =
 		{
-			const float queuePriority = 1.0f;
+			VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,	// VkStructureType				sType;
+			DE_NULL,									// const void*					pNext;
+			0u,											// VkDeviceQueueCreateFlags		flags;
+			m_queueFamilyIndex,							// deUint32						queueFamilyIndex;
+			1u,											// deUint32						queueCount;
+			&queuePriority								// const float*					pQueuePriorities;
+		};
 
-			// Create a universal queue that supports graphics and compute
-			const VkDeviceQueueCreateInfo	queueParams =
-			{
-				VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,	// VkStructureType				sType;
-				DE_NULL,									// const void*					pNext;
-				0u,											// VkDeviceQueueCreateFlags		flags;
-				context.getUniversalQueueFamilyIndex(),		// deUint32						queueFamilyIndex;
-				1u,											// deUint32						queueCount;
-				&queuePriority								// const float*					pQueuePriorities;
-			};
-
-			const char* extensions[] =
-			{
-				"VK_NV_shading_rate_image",
-			};
+		const char* extensions[] =
+		{
+			"VK_NV_shading_rate_image",
+		};
 
 #ifndef CTS_USES_VULKANSC
-			VkPhysicalDeviceShadingRateImageFeaturesNV			shadingRateImageFeatures = initVulkanStructure();
-			VkPhysicalDeviceFeatures2							features2 = initVulkanStructure(&shadingRateImageFeatures);
+		VkPhysicalDeviceShadingRateImageFeaturesNV	shadingRateImageFeatures	= initVulkanStructure();
+		VkPhysicalDeviceFeatures2					features2					= initVulkanStructure(&shadingRateImageFeatures);
 
-			context.getInstanceInterface().getPhysicalDeviceFeatures2(context.getPhysicalDevice(), &features2);
+		vki.getPhysicalDeviceFeatures2(physicalDevice, &features2);
 #endif // CTS_USES_VULKANSC
 
-			const VkDeviceCreateInfo					deviceCreateInfo =
-			{
-				VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,							//sType;
+		const VkDeviceCreateInfo deviceCreateInfo =
+		{
+			VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,					//sType;
 #ifndef CTS_USES_VULKANSC
-				&features2,														//pNext;
+			&features2,												//pNext;
 #else
-				DE_NULL,														//pNext;
+			DE_NULL,
 #endif // CTS_USES_VULKANSC
-				(VkDeviceCreateFlags)0u,										//flags
-				1,																//queueRecordCount;
-				&queueParams,													//pRequestedQueues;
-				0,																//layerCount;
-				DE_NULL,														//ppEnabledLayerNames;
-				DE_LENGTH_OF_ARRAY(extensions),									// deUint32							enabledExtensionCount;
-				extensions,														// const char* const*				ppEnabledExtensionNames;
-				DE_NULL,														//pEnabledFeatures;
-			};
+			0u,														//flags
+			1u,														//queueRecordCount;
+			&queueParams,											//pRequestedQueues;
+			0u,														//layerCount;
+			nullptr,												//ppEnabledLayerNames;
+			static_cast<uint32_t>(de::arrayLength(extensions)),		// deUint32							enabledExtensionCount;
+			extensions,												// const char* const*				ppEnabledExtensionNames;
+			nullptr,												//pEnabledFeatures;
+		};
 
-			Move<VkDevice> device = createCustomDevice(context.getTestContext().getCommandLine().isValidationEnabled(), context.getPlatformInterface(), context.getInstance(), context.getInstanceInterface(), context.getPhysicalDevice(), &deviceCreateInfo);
-			g_singletonDevice = de::SharedPtr<Move<VkDevice>>(new Move<VkDevice>(device));
-		}
-
-		return g_singletonDevice->get();
+		m_device	= createCustomDevice(context.getTestContext().getCommandLine().isValidationEnabled(), vkp, instance, vki, physicalDevice, &deviceCreateInfo);
+		m_vkd		.reset(new DeviceDriver(vkp, instance, m_device.get()));
+		m_queue		= getDeviceQueue(*m_vkd, *m_device, m_queueFamilyIndex, 0u);
+		m_allocator	.reset(new SimpleAllocator(*m_vkd, m_device.get(), getPhysicalDeviceMemoryProperties(vki, physicalDevice)));
 	}
 
-	return context.getDevice();
+	virtual ~ShadingRateImageDeviceHelper () {}
+
+	const DeviceInterface&	getDeviceInterface	(void) const override	{ return *m_vkd;				}
+	VkDevice				getDevice			(void) const override	{ return m_device.get();		}
+	uint32_t				getQueueFamilyIndex	(void) const override	{ return m_queueFamilyIndex;	}
+	VkQueue					getQueue			(void) const override	{ return m_queue;				}
+	Allocator&				getAllocator		(void) const override	{ return *m_allocator;			}
+
+protected:
+	Move<VkDevice>						m_device;
+	std::unique_ptr<DeviceDriver>		m_vkd;
+	deUint32							m_queueFamilyIndex;
+	VkQueue								m_queue;
+	std::unique_ptr<SimpleAllocator>	m_allocator;
+};
+
+std::unique_ptr<DeviceHelper> g_shadingRateDeviceHelper;
+std::unique_ptr<DeviceHelper> g_contextDeviceHelper;
+
+DeviceHelper& getDeviceHelper(Context& context, VkDynamicState dynamicState)
+{
+	const auto& stateInfo = getDynamicStateInfo(dynamicState);
+
+	if (de::contains(stateInfo.requirements.begin(), stateInfo.requirements.end(), "VK_NV_shading_rate_image"))
+	{
+		if (!g_shadingRateDeviceHelper)
+			g_shadingRateDeviceHelper.reset(new ShadingRateImageDeviceHelper(context));
+		return *g_shadingRateDeviceHelper;
+	}
+
+	if (!g_contextDeviceHelper)
+		g_contextDeviceHelper.reset(new ContextDeviceHelper(context));
+	return *g_contextDeviceHelper;
 }
 
 // Returns the set of auxiliary data needed to set a given state.
@@ -766,13 +842,14 @@
 
 tcu::TestStatus DynamicStateComputeInstance::iterateTransfer (void)
 {
-	const auto&	vki		= m_context.getInstanceInterface();
-	const auto	phyDev	= m_context.getPhysicalDevice();
-	const auto&	vkd		= m_context.getDeviceInterface();
-	const auto	device	= getDevice(m_context, m_params.states[0]);
-	auto&		alloc	= m_context.getDefaultAllocator();
-	const auto	qIndex	= m_context.getUniversalQueueFamilyIndex();
-	const auto	queue	= getDeviceQueue(vkd, device, qIndex, 0U);
+	const auto&	vki			= m_context.getInstanceInterface();
+	const auto	phyDev		= m_context.getPhysicalDevice();
+	auto&		devHelper	= getDeviceHelper(m_context, m_params.states.at(0));
+	const auto&	vkd			= devHelper.getDeviceInterface();
+	const auto	device		= devHelper.getDevice();
+	const auto	qIndex		= devHelper.getQueueFamilyIndex();
+	const auto	queue		= devHelper.getQueue();
+	auto&		alloc		= devHelper.getAllocator();
 
 	const auto	cmdPool			= makeCommandPool(vkd, device, qIndex);
 	const auto	cmdBufferPtr	= allocateCommandBuffer(vkd, device, cmdPool.get(), VK_COMMAND_BUFFER_LEVEL_PRIMARY);
@@ -855,13 +932,14 @@
 
 tcu::TestStatus DynamicStateComputeInstance::iterateCompute (void)
 {
-	const auto&	vki		= m_context.getInstanceInterface();
-	const auto	phyDev	= m_context.getPhysicalDevice();
-	const auto&	vkd		= m_context.getDeviceInterface();
-	const auto	device	= getDevice(m_context, m_params.states[0]);
-	auto&		alloc	= m_context.getDefaultAllocator();
-	const auto	qIndex	= m_context.getUniversalQueueFamilyIndex();
-	const auto	queue	= getDeviceQueue(vkd, device, qIndex, 0U);
+	const auto&	vki			= m_context.getInstanceInterface();
+	const auto	phyDev		= m_context.getPhysicalDevice();
+	auto&		devHelper	= getDeviceHelper(m_context, m_params.states.at(0));
+	const auto&	vkd			= devHelper.getDeviceInterface();
+	const auto	device		= devHelper.getDevice();
+	const auto	qIndex		= devHelper.getQueueFamilyIndex();
+	const auto	queue		= devHelper.getQueue();
+	auto&		alloc		= devHelper.getAllocator();
 
 	const auto	cmdPool			= makeCommandPool(vkd, device, qIndex);
 	const auto	cmdBufferPtr	= allocateCommandBuffer(vkd, device, cmdPool.get(), VK_COMMAND_BUFFER_LEVEL_PRIMARY);
@@ -1104,7 +1182,8 @@
 
 void cleanupDevice()
 {
-	g_singletonDevice.clear();
+	g_shadingRateDeviceHelper.reset(nullptr);
+	g_contextDeviceHelper.reset(nullptr);
 }
 
 } // DynamicState
diff --git a/external/vulkancts/modules/vulkan/modifiers/vktModifiersTests.cpp b/external/vulkancts/modules/vulkan/modifiers/vktModifiersTests.cpp
index a15f395..180449c 100644
--- a/external/vulkancts/modules/vulkan/modifiers/vktModifiersTests.cpp
+++ b/external/vulkancts/modules/vulkan/modifiers/vktModifiersTests.cpp
@@ -64,13 +64,13 @@
 		TCU_THROW(NotSupportedError, "VK_EXT_image_drm_format_modifier is not supported");
 
 	if (!context.isInstanceFunctionalitySupported("VK_KHR_get_physical_device_properties2"))
-		TCU_THROW(TestError, "VK_KHR_get_physical_device_properties2 not supported");
+		TCU_THROW(NotSupportedError, "VK_KHR_get_physical_device_properties2 not supported");
 
 	if (!context.isDeviceFunctionalitySupported("VK_KHR_bind_memory2"))
-		TCU_THROW(TestError, "VK_KHR_bind_memory2 not supported");
+		TCU_THROW(NotSupportedError, "VK_KHR_bind_memory2 not supported");
 
 	if (!context.isDeviceFunctionalitySupported("VK_KHR_image_format_list"))
-		TCU_THROW(TestError, "VK_KHR_image_format_list not supported");
+		TCU_THROW(NotSupportedError, "VK_KHR_image_format_list not supported");
 }
 
 void checkModifiersList2Supported (Context& context, VkFormat fmt)
@@ -78,7 +78,7 @@
 	checkModifiersSupported(context, fmt);
 
 	if (!context.isDeviceFunctionalitySupported("VK_KHR_format_feature_flags2"))
-		TCU_THROW(TestError, "VK_KHR_format_feature_flags2 not supported");
+		TCU_THROW(NotSupportedError, "VK_KHR_format_feature_flags2 not supported");
 }
 
 std::string getFormatCaseName (VkFormat format)
diff --git a/external/vulkancts/modules/vulkan/pipeline/vktPipelineLibraryTests.cpp b/external/vulkancts/modules/vulkan/pipeline/vktPipelineLibraryTests.cpp
index ff463ce..f67f6a1 100644
--- a/external/vulkancts/modules/vulkan/pipeline/vktPipelineLibraryTests.cpp
+++ b/external/vulkancts/modules/vulkan/pipeline/vktPipelineLibraryTests.cpp
@@ -1799,7 +1799,7 @@
 
 		VkPipelineLibraryCreateInfoKHR	linkingInfo			= makePipelineLibraryCreateInfo(pipelinesToLink);
 		VkGraphicsPipelineCreateInfo	finalPipelineInfo	= initVulkanStructure();
-		finalPipelineInfo.layout = layout;
+		finalPipelineInfo.layout = *layout;
 
 		appendStructurePtrToVulkanChain(&finalPipelineInfo.pNext, &linkingInfo);
 
diff --git a/external/vulkancts/modules/vulkan/renderpass/vktRenderPassTests.cpp b/external/vulkancts/modules/vulkan/renderpass/vktRenderPassTests.cpp
index 664f920..e82e9b5 100644
--- a/external/vulkancts/modules/vulkan/renderpass/vktRenderPassTests.cpp
+++ b/external/vulkancts/modules/vulkan/renderpass/vktRenderPassTests.cpp
@@ -2367,7 +2367,7 @@
 
 	bool isSecondary (void) const
 	{
-		return m_commandBuffer;
+		return !!m_commandBuffer;
 	}
 
 	VkCommandBuffer getCommandBuffer (void) const