• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2018 Advanced Micro Devices, Inc.
6 * Copyright (c) 2018 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 VK_KHR_driver_properties tests
23 *//*--------------------------------------------------------------------*/
24 
25 #include "vktApiDriverPropertiesTests.hpp"
26 #include "vktTestGroupUtil.hpp"
27 #include "vktTestCaseUtil.hpp"
28 #include "vkQueryUtil.hpp"
29 #include "vkTypeUtil.hpp"
30 #include "vkKnownDriverIds.inl"
31 
32 using namespace vk;
33 
34 namespace vkt
35 {
36 namespace api
37 {
38 namespace
39 {
40 
41 enum TestType
42 {
43 	TEST_TYPE_DRIVER_ID_MATCH			= 0,
44 	TEST_TYPE_NAME_IS_NOT_EMPTY,
45 	TEST_TYPE_NAME_ZERO_TERMINATED,
46 	TEST_TYPE_INFO_ZERO_TERMINATED,
47 	TEST_TYPE_VERSION,
48 };
49 
50 static const VkConformanceVersionKHR knownConformanceVersions[] =
51 {
52 	makeConformanceVersion(1, 2, 8, 0),
53 	makeConformanceVersion(1, 2, 7, 2),
54 	makeConformanceVersion(1, 2, 7, 1),
55 	makeConformanceVersion(1, 2, 7, 0),
56 	makeConformanceVersion(1, 2, 6, 2),
57 	makeConformanceVersion(1, 2, 6, 1),
58 	makeConformanceVersion(1, 2, 6, 0),
59 	makeConformanceVersion(1, 2, 5, 2),
60 	makeConformanceVersion(1, 2, 5, 1),
61 	makeConformanceVersion(1, 2, 5, 0),
62 	makeConformanceVersion(1, 2, 4, 1),
63 	makeConformanceVersion(1, 2, 4, 0),
64 	makeConformanceVersion(1, 2, 3, 3),
65 	makeConformanceVersion(1, 2, 3, 2),
66 	makeConformanceVersion(1, 2, 3, 1),
67 	makeConformanceVersion(1, 2, 3, 0),
68 	makeConformanceVersion(1, 2, 2, 2),
69 	makeConformanceVersion(1, 2, 2, 1),
70 	makeConformanceVersion(1, 2, 2, 0),
71 	makeConformanceVersion(1, 2, 1, 2),
72 	makeConformanceVersion(1, 2, 1, 1),
73 	makeConformanceVersion(1, 2, 1, 0),
74 	makeConformanceVersion(1, 2, 0, 2),
75 	makeConformanceVersion(1, 2, 0, 1),
76 	makeConformanceVersion(1, 2, 0, 0),
77 	makeConformanceVersion(1, 1, 6, 3),
78 	makeConformanceVersion(1, 1, 6, 2),
79 	makeConformanceVersion(1, 1, 6, 1),
80 	makeConformanceVersion(1, 1, 6, 0),
81 	makeConformanceVersion(1, 1, 5, 2),
82 	makeConformanceVersion(1, 1, 5, 1),
83 	makeConformanceVersion(1, 1, 5, 0),
84 	makeConformanceVersion(1, 1, 4, 3),
85 	makeConformanceVersion(1, 1, 4, 2),
86 	makeConformanceVersion(1, 1, 4, 1),
87 	makeConformanceVersion(1, 1, 4, 0),
88 	makeConformanceVersion(1, 1, 3, 3),
89 	makeConformanceVersion(1, 1, 3, 2),
90 	makeConformanceVersion(1, 1, 3, 1),
91 	makeConformanceVersion(1, 1, 3, 0),
92 };
93 
isNullTerminated(const char * str,const deUint32 maxSize)94 DE_INLINE bool isNullTerminated(const char* str, const deUint32 maxSize)
95 {
96 	return deStrnlen(str, maxSize) < maxSize;
97 }
98 
operator ==(const VkConformanceVersion & a,const VkConformanceVersion & b)99 DE_INLINE bool operator==(const VkConformanceVersion& a, const VkConformanceVersion& b)
100 {
101 	return ((a.major == b.major)		&&
102 			(a.minor == b.minor)		&&
103 			(a.subminor == b.subminor)	&&
104 			(a.patch == b.patch));
105 }
106 
checkSupport(Context & context,const TestType config)107 void checkSupport (Context& context, const TestType config)
108 {
109 	DE_UNREF(config);
110 	context.requireDeviceFunctionality("VK_KHR_driver_properties");
111 }
112 
testDriverMatch(const VkPhysicalDeviceDriverPropertiesKHR & deviceDriverProperties)113 void testDriverMatch (const VkPhysicalDeviceDriverPropertiesKHR& deviceDriverProperties)
114 {
115 	for (deUint32 driverNdx = 0; driverNdx < DE_LENGTH_OF_ARRAY(driverIds); driverNdx++)
116 	{
117 		if (deviceDriverProperties.driverID == driverIds[driverNdx].id)
118 			return;
119 	}
120 
121 	TCU_FAIL("Driver ID did not match any known driver");
122 }
123 
testNameIsNotEmpty(const VkPhysicalDeviceDriverPropertiesKHR & deviceDriverProperties)124 void testNameIsNotEmpty (const VkPhysicalDeviceDriverPropertiesKHR& deviceDriverProperties)
125 {
126 	if (deviceDriverProperties.driverName[0] == 0)
127 		TCU_FAIL("Driver name is empty");
128 }
129 
testNameZeroTerminated(const VkPhysicalDeviceDriverPropertiesKHR & deviceDriverProperties)130 void testNameZeroTerminated (const VkPhysicalDeviceDriverPropertiesKHR& deviceDriverProperties)
131 {
132 	if (!isNullTerminated(deviceDriverProperties.driverName, VK_MAX_DRIVER_NAME_SIZE_KHR))
133 		TCU_FAIL("Driver name is not a null-terminated string");
134 }
135 
testInfoZeroTerminated(const VkPhysicalDeviceDriverPropertiesKHR & deviceDriverProperties)136 void testInfoZeroTerminated (const VkPhysicalDeviceDriverPropertiesKHR& deviceDriverProperties)
137 {
138 	if (!isNullTerminated(deviceDriverProperties.driverInfo, VK_MAX_DRIVER_INFO_SIZE_KHR))
139 		TCU_FAIL("Driver info is not a null-terminated string");
140 }
141 
testVersion(const VkPhysicalDeviceDriverPropertiesKHR & deviceDriverProperties,deUint32 usedApiVersion)142 void testVersion (const VkPhysicalDeviceDriverPropertiesKHR& deviceDriverProperties, deUint32 usedApiVersion)
143 {
144 	const deUint32 apiMajorVersion = VK_API_VERSION_MAJOR(usedApiVersion);
145 	const deUint32 apiMinorVersion = VK_API_VERSION_MINOR(usedApiVersion);
146 
147 	if (deviceDriverProperties.conformanceVersion.major < apiMajorVersion ||
148 		(deviceDriverProperties.conformanceVersion.major == apiMajorVersion &&
149 		 deviceDriverProperties.conformanceVersion.minor < apiMinorVersion))
150 	{
151 		TCU_FAIL("Wrong driver conformance version (older than used API version)");
152 	}
153 
154 	for (const VkConformanceVersionKHR* pConformanceVersion  = knownConformanceVersions;
155 										pConformanceVersion != DE_ARRAY_END(knownConformanceVersions);
156 									  ++pConformanceVersion)
157 	{
158 		if (deviceDriverProperties.conformanceVersion == *pConformanceVersion)
159 			return;
160 	}
161 
162 	TCU_FAIL("Wrong driver conformance version (not known)");
163 }
164 
testQueryProperties(Context & context,const TestType testType)165 tcu::TestStatus testQueryProperties (Context& context, const TestType testType)
166 {
167 	// Query the driver properties
168 	const VkPhysicalDevice				physDevice			= context.getPhysicalDevice();
169 	const int							memsetPattern		= 0xaa;
170 	VkPhysicalDeviceProperties2			deviceProperties2;
171 	VkPhysicalDeviceDriverProperties	deviceDriverProperties;
172 
173 	deMemset(&deviceDriverProperties, memsetPattern, sizeof(deviceDriverProperties));
174 	deviceDriverProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR;
175 	deviceDriverProperties.pNext = DE_NULL;
176 
177 	deMemset(&deviceProperties2, memsetPattern, sizeof(deviceProperties2));
178 	deviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
179 	deviceProperties2.pNext = &deviceDriverProperties;
180 
181 	context.getInstanceInterface().getPhysicalDeviceProperties2(physDevice, &deviceProperties2);
182 
183 	// Verify the returned values
184 	switch (testType)
185 	{
186 		case TEST_TYPE_DRIVER_ID_MATCH:			testDriverMatch			(deviceDriverProperties);								break;
187 		case TEST_TYPE_NAME_IS_NOT_EMPTY:		testNameIsNotEmpty		(deviceDriverProperties);								break;
188 		case TEST_TYPE_NAME_ZERO_TERMINATED:	testNameZeroTerminated	(deviceDriverProperties);								break;
189 		case TEST_TYPE_INFO_ZERO_TERMINATED:	testInfoZeroTerminated	(deviceDriverProperties);								break;
190 		case TEST_TYPE_VERSION:					testVersion				(deviceDriverProperties, context.getUsedApiVersion());	break;
191 		default:								TCU_THROW(InternalError, "Unknown test type specified");
192 	}
193 
194 	return tcu::TestStatus::pass("Pass");
195 }
196 
createTestCases(tcu::TestCaseGroup * group)197 void createTestCases (tcu::TestCaseGroup* group)
198 {
199 	addFunctionCase(group, "driver_id_match",		"Check driverID is supported",					checkSupport,	testQueryProperties,	TEST_TYPE_DRIVER_ID_MATCH);
200 	addFunctionCase(group, "name_is_not_empty",		"Check name field is not empty",				checkSupport,	testQueryProperties,	TEST_TYPE_NAME_IS_NOT_EMPTY);
201 	addFunctionCase(group, "name_zero_terminated",	"Check name field is zero-terminated",			checkSupport,	testQueryProperties,	TEST_TYPE_NAME_ZERO_TERMINATED);
202 	addFunctionCase(group, "info_zero_terminated",	"Check info field is zero-terminated",			checkSupport,	testQueryProperties,	TEST_TYPE_INFO_ZERO_TERMINATED);
203 	addFunctionCase(group, "conformance_version",	"Check conformanceVersion reported by driver",	checkSupport,	testQueryProperties,	TEST_TYPE_VERSION);
204 }
205 
206 } // anonymous
207 
createDriverPropertiesTests(tcu::TestContext & testCtx)208 tcu::TestCaseGroup*	createDriverPropertiesTests(tcu::TestContext& testCtx)
209 {
210 	return createTestGroup(testCtx, "driver_properties", "VK_KHR_driver_properties tests", createTestCases);
211 }
212 
213 } // api
214 } // vkt
215