• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2020 Valve Corporation.
6  * Copyright (c) 2020 The Khronos Group Inc.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief Amber tests in the GLSL group.
23  *//*--------------------------------------------------------------------*/
24 
25 #include "vktAmberDepthTests.hpp"
26 #include "vktAmberTestCase.hpp"
27 #include "vktCustomInstancesDevices.hpp"
28 #include "vktTestGroupUtil.hpp"
29 
30 #include "vkQueryUtil.hpp"
31 
32 #include "tcuCommandLine.hpp"
33 
34 #include <vector>
35 #include <utility>
36 #include <string>
37 
38 namespace vkt
39 {
40 namespace cts_amber
41 {
42 
43 using namespace vk;
44 
45 de::SharedPtr<Move<vk::VkDevice>> g_singletonDeviceDepthGroup;
46 
47 class DepthTestCase : public AmberTestCase
48 {
49 	bool m_useCustomDevice;
50 
51 public:
DepthTestCase(tcu::TestContext & testCtx,const char * name,const char * description,bool useCustomDevice,const std::string & readFilename)52 	DepthTestCase  (tcu::TestContext&	testCtx,
53 					const char*			name,
54 					const char*			description,
55 					bool				useCustomDevice,
56 					const std::string&	readFilename)
57 		:	AmberTestCase(testCtx, name, description, readFilename),
58 			m_useCustomDevice(useCustomDevice)
59 	{ }
60 
createInstance(Context & ctx) const61 	TestInstance* createInstance (Context& ctx) const
62 	{
63 		// Create a custom device to ensure that VK_EXT_depth_range_unrestricted is not enabled
64 		if (!g_singletonDeviceDepthGroup)
65 		{
66 			const float queuePriority = 1.0f;
67 
68 			// Create a universal queue that supports graphics and compute
69 			const VkDeviceQueueCreateInfo queueParams =
70 			{
71 				VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,	// sType
72 				DE_NULL,									// pNext
73 				0u,											// flags
74 				ctx.getUniversalQueueFamilyIndex(),			// queueFamilyIndex
75 				1u,											// queueCount
76 				&queuePriority								// pQueuePriorities
77 			};
78 
79 			const char *ext = "VK_EXT_depth_clamp_zero_one";
80 
81 			VkPhysicalDeviceFeatures2 features2 = initVulkanStructure();
82 
83 			VkPhysicalDeviceDepthClampZeroOneFeaturesEXT clampParams =
84 			{
85 				VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLAMP_ZERO_ONE_FEATURES_EXT,	// sType
86 				DE_NULL,																// pNext
87 				VK_TRUE,																// depthClampZeroOne
88 			};
89 
90 			features2.pNext = &clampParams;
91 
92 			ctx.getInstanceInterface().getPhysicalDeviceFeatures2(ctx.getPhysicalDevice(), &features2);
93 
94 			const VkDeviceCreateInfo deviceCreateInfo =
95 			{
96 				VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,		// sType
97 				&features2,									// pNext
98 				(VkDeviceCreateFlags)0u,					// flags
99 				1,											// queueRecordCount
100 				&queueParams,								// pRequestedQueues
101 				0,											// layerCount
102 				DE_NULL,									// ppEnabledLayerNames
103 				1,											// enabledExtensionCount
104 				&ext,										// ppEnabledExtensionNames
105 				DE_NULL,									// pEnabledFeatures
106 			};
107 
108 			Move<VkDevice> device = createCustomDevice(ctx.getTestContext().getCommandLine().isValidationEnabled(), ctx.getPlatformInterface(), ctx.getInstance(), ctx.getInstanceInterface(), ctx.getPhysicalDevice(), &deviceCreateInfo);
109 			g_singletonDeviceDepthGroup = de::SharedPtr<Move<VkDevice>>(new Move<VkDevice>(device));
110 		}
111 		return new AmberTestInstance(ctx, m_recipe, m_useCustomDevice ? g_singletonDeviceDepthGroup->get() : nullptr);
112 	}
113 };
114 
115 struct TestInfo
116 {
117 	std::string					name;
118 	std::string					desc;
119 	std::vector<std::string>	base_required_features;
120 	bool						unrestricted;
121 };
122 
createDepthTestCase(tcu::TestContext & testCtx,const TestInfo & testInfo,const char * category,const std::string & filename)123 DepthTestCase* createDepthTestCase (tcu::TestContext&   testCtx,
124 									const TestInfo&		testInfo,
125 									const char*			category,
126 									const std::string&	filename)
127 
128 {
129 	// shader_test files are saved in <path>/external/vulkancts/data/vulkan/amber/<categoryname>/
130 	std::string readFilename("vulkan/amber/");
131 	readFilename.append(category);
132 	readFilename.append("/");
133 	readFilename.append(filename);
134 
135 	DepthTestCase *testCase = new DepthTestCase(testCtx, testInfo.name.c_str(), testInfo.desc.c_str(), !testInfo.unrestricted, readFilename);
136 
137 	for (auto req : testInfo.base_required_features)
138 		testCase->addRequirement(req);
139 
140 	if (testInfo.unrestricted)
141 		testCase->addRequirement("VK_EXT_depth_range_unrestricted");
142 
143 	return testCase;
144 }
145 
createTests(tcu::TestCaseGroup * g)146 static void createTests(tcu::TestCaseGroup *g)
147 {
148 	static const std::vector<TestInfo>	tests		=
149 	{
150 		{ "fs_clamp",						"Test fragment shader depth value clamping",					{ "VK_EXT_depth_clamp_zero_one", "Features.fragmentStoresAndAtomics", "Features.depthClamp" },	false },
151 		{ "out_of_range",					"Test late clamping of out-of-range depth values",				{ "VK_EXT_depth_clamp_zero_one" },																false },
152 		{ "ez_fs_clamp",					"Test fragment shader depth value with early fragment tests",	{ "VK_EXT_depth_clamp_zero_one", "Features.fragmentStoresAndAtomics", "Features.depthClamp" },	false },
153 		{ "bias_fs_clamp",					"Test fragment shader depth value with depthBias enabled",		{ "VK_EXT_depth_clamp_zero_one", "Features.fragmentStoresAndAtomics", "Features.depthClamp" },	false },
154 		{ "bias_outside_range",				"Test biasing depth values out of the depth range",				{ "VK_EXT_depth_clamp_zero_one", "Features.fragmentStoresAndAtomics" },							false },
155 		{ "bias_outside_range_fs_clamp",	"Test fragment shader depth value when biasing out of range",	{ "VK_EXT_depth_clamp_zero_one", "Features.fragmentStoresAndAtomics" },							false },
156 
157 		// Rerun any tests that will get different results with VK_EXT_depth_range_unrestricted
158 		{ "out_of_range_unrestricted",					"Test late clamping of out-of-range depth values",				{ "VK_EXT_depth_clamp_zero_one" },										true },
159 		{ "bias_outside_range_fs_clamp_unrestricted",	"Test fragment shader depth value when biasing out of range",	{ "VK_EXT_depth_clamp_zero_one", "Features.fragmentStoresAndAtomics" },	true },
160 	};
161 
162    tcu::TestContext& testCtx = g->getTestContext();
163 
164 	for (const auto& test : tests)
165 	{
166 		g->addChild(createDepthTestCase(testCtx, test, g->getName(), test.name + ".amber"));
167 	}
168 }
169 
cleanupGroup(tcu::TestCaseGroup *)170 static void cleanupGroup(tcu::TestCaseGroup*)
171 {
172 	// Destroy custom device object
173 	g_singletonDeviceDepthGroup.clear();
174 }
175 
createAmberDepthGroup(tcu::TestContext & testCtx)176 tcu::TestCaseGroup*	createAmberDepthGroup (tcu::TestContext& testCtx)
177 {
178 	return createTestGroup(testCtx, "depth", "Depth pipeline test group", createTests, cleanupGroup);
179 }
180 
181 } // cts_amber
182 } // vkt
183