98ecb52a836b28da7e7ad08936990c47d754a1c1
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / api / vktApiDriverPropertiesTests.cpp
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
31 using namespace vk;
32
33 namespace vkt
34 {
35 namespace api
36 {
37 namespace
38 {
39
40 static const deUint32 knownDriverIds[] =
41 {
42         // Specified in the Vulkan registry (vk.xml)
43         1,      // author = "Advanced Micro Devices, Inc."   comment = "AMD proprietary driver"
44         2,      // author = "Advanced Micro Devices, Inc."   comment = "AMD open-source driver"
45         3,      // author = "Mesa open source project"       comment = "Mesa RADV driver"
46         4,      // author = "NVIDIA Corporation"             comment = "NVIDIA proprietary driver"
47         5,      // author = "Intel Corporation"              comment = "Intel proprietary Windows driver"
48         6,      // author = "Intel Corporation"              comment = "Intel open-source Mesa driver"
49         7,      // author = "Imagination Technologies"       comment = "Imagination proprietary driver"
50         8,      // author = "Qualcomm Technologies, Inc."    comment = "Qualcomm proprietary driver"
51         9,      // author = "Arm Limited"                    comment = "Arm proprietary driver"
52 };
53
54 static const VkConformanceVersionKHR knownConformanceVersions[] =
55 {
56         makeConformanceVersionKHR(1, 1, 3, 0),
57         makeConformanceVersionKHR(1, 1, 2, 3),
58         makeConformanceVersionKHR(1, 1, 2, 2),
59         makeConformanceVersionKHR(1, 1, 2, 1),
60         makeConformanceVersionKHR(1, 1, 2, 0),
61         makeConformanceVersionKHR(1, 1, 1, 3),
62         makeConformanceVersionKHR(1, 1, 1, 2),
63         makeConformanceVersionKHR(1, 1, 1, 1),
64         makeConformanceVersionKHR(1, 1, 1, 0),
65         makeConformanceVersionKHR(1, 1, 0, 3),
66         makeConformanceVersionKHR(1, 0, 2, 6),
67         makeConformanceVersionKHR(1, 0, 2, 5),
68         makeConformanceVersionKHR(1, 0, 2, 4),
69         makeConformanceVersionKHR(1, 0, 2, 3),
70         makeConformanceVersionKHR(1, 0, 2, 2),
71         makeConformanceVersionKHR(1, 0, 2, 1),
72         makeConformanceVersionKHR(1, 0, 2, 0),
73 };
74
75 DE_INLINE bool isNullTerminated(const char* str, const deUint32 maxSize)
76 {
77         return deStrnlen(str, maxSize) < maxSize;
78 }
79
80 DE_INLINE bool operator==(const VkConformanceVersionKHR& a, const VkConformanceVersionKHR& b)
81 {
82         return ((a.major == b.major)            &&
83                         (a.minor == b.minor)            &&
84                         (a.subminor == b.subminor)      &&
85                         (a.patch == b.patch));
86 }
87
88 tcu::TestStatus testQueryProperties (Context& context)
89 {
90         // Check extension support
91
92         if (!isDeviceExtensionSupported(context.getUsedApiVersion(), context.getDeviceExtensions(), "VK_KHR_driver_properties"))
93                 TCU_THROW(NotSupportedError, "Unsupported extension: VK_KHR_driver_properties");
94
95         // Query the driver properties
96
97         const VkPhysicalDevice                          physDevice                      = context.getPhysicalDevice();
98         const int                                                       memsetPattern           = 0xaa;
99         VkPhysicalDeviceProperties2                     deviceProperties2;
100         VkPhysicalDeviceDriverPropertiesKHR     deviceDriverProperties;
101
102         deMemset(&deviceDriverProperties, memsetPattern, sizeof(deviceDriverProperties));
103         deviceDriverProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR;
104         deviceDriverProperties.pNext = DE_NULL;
105
106         deMemset(&deviceProperties2, memsetPattern, sizeof(deviceProperties2));
107         deviceProperties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
108         deviceProperties2.pNext = &deviceDriverProperties;
109
110         context.getInstanceInterface().getPhysicalDeviceProperties2(physDevice, &deviceProperties2);
111
112         // Verify the returned values
113
114         bool match = false;
115
116         for (const deUint32* pDriverId = knownDriverIds; (pDriverId != DE_ARRAY_END(knownDriverIds)) && !match; ++pDriverId)
117         {
118                 if (deviceDriverProperties.driverID == *pDriverId)
119                 {
120                         match = true;
121
122                         if (!isNullTerminated(deviceDriverProperties.driverName, VK_MAX_DRIVER_NAME_SIZE_KHR))
123                                 TCU_FAIL("Driver name is not a null-terminated string");
124
125                         if (deviceDriverProperties.driverName[0] == 0)
126                                 TCU_FAIL("Driver name is empty");
127
128                         if (!isNullTerminated(deviceDriverProperties.driverInfo, VK_MAX_DRIVER_INFO_SIZE_KHR))
129                                 TCU_FAIL("Driver info is not a null-terminated string");
130
131                         bool conformanceVersionMatch = false;
132
133                         for (const VkConformanceVersionKHR* pConformanceVersion  = knownConformanceVersions;
134                                                                                                 pConformanceVersion != DE_ARRAY_END(knownConformanceVersions);
135                                                                                           ++pConformanceVersion)
136                         {
137                                 if (deviceDriverProperties.conformanceVersion == *pConformanceVersion)
138                                 {
139                                         conformanceVersionMatch = true;
140                                         break;
141                                 }
142                         }
143
144                         if (!conformanceVersionMatch)
145                                 TCU_FAIL("Wrong driver conformance version");
146                 }
147         }
148
149         if (!match)
150                 TCU_FAIL("Driver ID did not match any known driver");
151
152         return tcu::TestStatus::pass("Pass");
153 }
154
155 void createTestCases (tcu::TestCaseGroup* group)
156 {
157         addFunctionCase(group, "properties", "Query VkPhysicalDeviceDriverPropertiesKHR and check its values", testQueryProperties);
158 }
159
160 } // anonymous
161
162 tcu::TestCaseGroup*     createDriverPropertiesTests(tcu::TestContext& testCtx)
163 {
164         return createTestGroup(testCtx, "driver_properties", "VK_KHR_driver_properties tests", createTestCases);
165 }
166
167 } // api
168 } // vkt