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
isNullTerminated(const char * str,const uint32_t maxSize)50 DE_INLINE bool isNullTerminated(const char *str, const uint32_t maxSize)
51 {
52 return deStrnlen(str, maxSize) < maxSize;
53 }
54
operator ==(const VkConformanceVersion & a,const VkConformanceVersion & b)55 DE_INLINE bool operator==(const VkConformanceVersion &a, const VkConformanceVersion &b)
56 {
57 return ((a.major == b.major) && (a.minor == b.minor) && (a.subminor == b.subminor) && (a.patch == b.patch));
58 }
59
checkSupport(Context & context,const TestType config)60 void checkSupport(Context &context, const TestType config)
61 {
62 DE_UNREF(config);
63 context.requireDeviceFunctionality("VK_KHR_driver_properties");
64 }
65
testDriverMatch(const VkPhysicalDeviceDriverProperties & deviceDriverProperties)66 void testDriverMatch(const VkPhysicalDeviceDriverProperties &deviceDriverProperties)
67 {
68 for (uint32_t driverNdx = 0; driverNdx < DE_LENGTH_OF_ARRAY(driverIds); driverNdx++)
69 {
70 if (deviceDriverProperties.driverID == driverIds[driverNdx].id)
71 return;
72 }
73
74 TCU_FAIL("Driver ID did not match any known driver");
75 }
76
testNameIsNotEmpty(const VkPhysicalDeviceDriverProperties & deviceDriverProperties)77 void testNameIsNotEmpty(const VkPhysicalDeviceDriverProperties &deviceDriverProperties)
78 {
79 if (deviceDriverProperties.driverName[0] == 0)
80 TCU_FAIL("Driver name is empty");
81 }
82
testNameZeroTerminated(const VkPhysicalDeviceDriverProperties & deviceDriverProperties)83 void testNameZeroTerminated(const VkPhysicalDeviceDriverProperties &deviceDriverProperties)
84 {
85 if (!isNullTerminated(deviceDriverProperties.driverName, VK_MAX_DRIVER_NAME_SIZE))
86 TCU_FAIL("Driver name is not a null-terminated string");
87 }
88
testInfoZeroTerminated(const VkPhysicalDeviceDriverProperties & deviceDriverProperties)89 void testInfoZeroTerminated(const VkPhysicalDeviceDriverProperties &deviceDriverProperties)
90 {
91 if (!isNullTerminated(deviceDriverProperties.driverInfo, VK_MAX_DRIVER_INFO_SIZE))
92 TCU_FAIL("Driver info is not a null-terminated string");
93 }
94
testVersion(const VkPhysicalDeviceDriverProperties & deviceDriverProperties,uint32_t usedApiVersion)95 void testVersion(const VkPhysicalDeviceDriverProperties &deviceDriverProperties, uint32_t usedApiVersion)
96 {
97
98 #include "vkKnownConformanceVersions.inl"
99
100 const uint32_t apiMajorVersion = VK_API_VERSION_MAJOR(usedApiVersion);
101 const uint32_t apiMinorVersion = VK_API_VERSION_MINOR(usedApiVersion);
102
103 if (deviceDriverProperties.conformanceVersion.major < apiMajorVersion ||
104 (deviceDriverProperties.conformanceVersion.major == apiMajorVersion &&
105 deviceDriverProperties.conformanceVersion.minor < apiMinorVersion))
106 {
107 TCU_FAIL("Wrong driver conformance version (older than used API version)");
108 }
109
110 for (const VkConformanceVersion *pConformanceVersion = knownConformanceVersions;
111 pConformanceVersion != DE_ARRAY_END(knownConformanceVersions); ++pConformanceVersion)
112 {
113 if (deviceDriverProperties.conformanceVersion == *pConformanceVersion)
114 return;
115 }
116
117 TCU_FAIL("Wrong driver conformance version (not known)");
118 }
119
testQueryProperties(Context & context,const TestType testType)120 tcu::TestStatus testQueryProperties(Context &context, const TestType testType)
121 {
122 // Query the driver properties
123 const VkPhysicalDevice physDevice = context.getPhysicalDevice();
124 const int memsetPattern = 0xaa;
125 VkPhysicalDeviceProperties2 deviceProperties2;
126 VkPhysicalDeviceDriverProperties deviceDriverProperties;
127
128 deMemset(&deviceDriverProperties, memsetPattern, sizeof(deviceDriverProperties));
129 deviceDriverProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
130 deviceDriverProperties.pNext = DE_NULL;
131
132 deMemset(&deviceProperties2, memsetPattern, sizeof(deviceProperties2));
133 deviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
134 deviceProperties2.pNext = &deviceDriverProperties;
135
136 context.getInstanceInterface().getPhysicalDeviceProperties2(physDevice, &deviceProperties2);
137
138 // Verify the returned values
139 switch (testType)
140 {
141 case TEST_TYPE_DRIVER_ID_MATCH:
142 testDriverMatch(deviceDriverProperties);
143 break;
144 case TEST_TYPE_NAME_IS_NOT_EMPTY:
145 testNameIsNotEmpty(deviceDriverProperties);
146 break;
147 case TEST_TYPE_NAME_ZERO_TERMINATED:
148 testNameZeroTerminated(deviceDriverProperties);
149 break;
150 case TEST_TYPE_INFO_ZERO_TERMINATED:
151 testInfoZeroTerminated(deviceDriverProperties);
152 break;
153 case TEST_TYPE_VERSION:
154 testVersion(deviceDriverProperties, context.getUsedApiVersion());
155 break;
156 default:
157 TCU_THROW(InternalError, "Unknown test type specified");
158 }
159
160 return tcu::TestStatus::pass("Pass");
161 }
162
createTestCases(tcu::TestCaseGroup * group)163 void createTestCases(tcu::TestCaseGroup *group)
164 {
165 addFunctionCase(group, "driver_id_match", checkSupport, testQueryProperties, TEST_TYPE_DRIVER_ID_MATCH);
166 addFunctionCase(group, "name_is_not_empty", checkSupport, testQueryProperties, TEST_TYPE_NAME_IS_NOT_EMPTY);
167 addFunctionCase(group, "name_zero_terminated", checkSupport, testQueryProperties, TEST_TYPE_NAME_ZERO_TERMINATED);
168 addFunctionCase(group, "info_zero_terminated", checkSupport, testQueryProperties, TEST_TYPE_INFO_ZERO_TERMINATED);
169 addFunctionCase(group, "conformance_version", checkSupport, testQueryProperties, TEST_TYPE_VERSION);
170 }
171
172 } // namespace
173
createDriverPropertiesTests(tcu::TestContext & testCtx)174 tcu::TestCaseGroup *createDriverPropertiesTests(tcu::TestContext &testCtx)
175 {
176 return createTestGroup(testCtx, "driver_properties", createTestCases);
177 }
178
179 } // namespace api
180 } // namespace vkt
181