VK_KHR_maintenance2: Point clipping

Updated tests:
 * dEQP-VK.clipping.clip_volume.clipped.large_points
 * dEQP-VK.rasterization.primitives.lines_wide
 * dEQP-VK.rasterization.primitives.line_strip_wide
 * dEQP-VK.rasterization.primitives_multisample_2_bit.lines_wide
 * dEQP-VK.rasterization.primitives_multisample_4_bit.lines_wide
 * dEQP-VK.rasterization.primitives_multisample_8_bit.lines_wide

Components: Vulkan

VK-GL-CTS issue: 126

Change-Id: Id0cecb96e8a448ec3eb09e2a25d6c82acd837057
(cherry picked from commit 14bfa832d795dca9057699e867d0273db95c7de4)
diff --git a/external/vulkancts/modules/vulkan/clipping/vktClippingTests.cpp b/external/vulkancts/modules/vulkan/clipping/vktClippingTests.cpp
index a354198..15d1443 100644
--- a/external/vulkancts/modules/vulkan/clipping/vktClippingTests.cpp
+++ b/external/vulkancts/modules/vulkan/clipping/vktClippingTests.cpp
@@ -732,6 +732,30 @@
 	LINE_ORIENTATION_DIAGONAL,
 };
 
+const VkPointClippingBehaviorKHR invalidClippingBehavior = VK_POINT_CLIPPING_BEHAVIOR_KHR_LAST;
+
+VkPointClippingBehaviorKHR getClippingBehavior (const InstanceInterface& vk, VkPhysicalDevice physicalDevice)
+{
+	VkPhysicalDevicePointClippingPropertiesKHR	behaviorProperties	=
+	{
+		VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR,	// VkStructureType				sType
+		DE_NULL,															// void*						pNext
+		invalidClippingBehavior												// VkPointClippingBehaviorKHR	pointClippingBehavior
+	};
+	VkPhysicalDeviceProperties2KHR				properties2;
+
+	DE_ASSERT(getPointClippingBehaviorKHRName(invalidClippingBehavior) == DE_NULL);
+
+	deMemset(&properties2, 0, sizeof(properties2));
+
+	properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
+	properties2.pNext = &behaviorProperties;
+
+	vk.getPhysicalDeviceProperties2KHR(physicalDevice, &properties2);
+
+	return behaviorProperties.pointClippingBehavior;
+}
+
 void addSimplePrograms (SourceCollections& programCollection, const float pointSize = 0.0f)
 {
 	// Vertex shader
@@ -984,6 +1008,29 @@
 {
 	requireFeatures(context.getInstanceInterface(), context.getPhysicalDevice(), FEATURE_LARGE_POINTS);
 
+	bool pointClippingOutside = true;
+
+	if (de::contains(context.getDeviceExtensions().begin(), context.getDeviceExtensions().end(), "VK_KHR_maintenance2"))
+	{
+		VkPointClippingBehaviorKHR clippingBehavior = getClippingBehavior(context.getInstanceInterface(), context.getPhysicalDevice());
+
+		switch (clippingBehavior)
+		{
+			case VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR:		pointClippingOutside = true;				break;
+			case VK_POINT_CLIPPING_BEHAVIOR_USER_CLIP_PLANES_ONLY_KHR:	pointClippingOutside = false;				break;
+			case invalidClippingBehavior:								TCU_FAIL("Clipping behavior read failure");	break;
+			default:
+			{
+				TCU_FAIL("Unexpected clipping behavior reported");
+			}
+		}
+	}
+	else
+	{
+		//TODO: Now we have 2 cases {some-points-drawn|nothing}, we should have {all-points-drawn|some-points-drawn|nothing}
+		return tcu::TestStatus::pass("OK");
+	}
+
 	std::vector<Shader> shaders;
 	shaders.push_back(Shader(VK_SHADER_STAGE_VERTEX_BIT,	context.getBinaryCollection().get("vert")));
 	shaders.push_back(Shader(VK_SHADER_STAGE_FRAGMENT_BIT,	context.getBinaryCollection().get("frag")));
@@ -1010,10 +1057,21 @@
 	DrawContext drawContext(context, shaders, vertices, VK_PRIMITIVE_TOPOLOGY_POINT_LIST);
 	drawContext.draw();
 
-	// All pixels must be black -- nothing is drawn.
-	const int numBlackPixels = countPixels(drawContext.getColorPixels(), Vec4(0.0f, 0.0f, 0.0f, 1.0f), Vec4());
+	const int	numBlackPixels	= countPixels(drawContext.getColorPixels(), Vec4(0.0f, 0.0f, 0.0f, 1.0f), Vec4());
+	bool		result			= false;
 
-	return (numBlackPixels == NUM_RENDER_PIXELS ? tcu::TestStatus::pass("OK") : tcu::TestStatus::fail("Rendered image(s) are incorrect"));
+	if (pointClippingOutside)
+	{
+		// All pixels must be black -- nothing is drawn.
+		result = (numBlackPixels == NUM_RENDER_PIXELS);
+	}
+	else
+	{
+		// Rendering pixels without clipping: some pixels should not be black -- something is drawn.
+		result = (numBlackPixels < NUM_RENDER_PIXELS);
+	}
+
+	return (result ? tcu::TestStatus::pass("OK") : tcu::TestStatus::fail("Rendered image(s) are incorrect"));
 }
 
 //! Wide line clipping