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