2 * Copyright 2018 Józef Kucia for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/heap.h"
21 #include "wine/vulkan.h"
22 #include "wine/test.h"
24 static VkResult
create_instance(uint32_t extension_count
,
25 const char * const *enabled_extensions
, VkInstance
*vk_instance
)
27 VkInstanceCreateInfo create_info
;
29 create_info
.sType
= VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
;
30 create_info
.pNext
= NULL
;
31 create_info
.flags
= 0;
32 create_info
.pApplicationInfo
= NULL
;
33 create_info
.enabledLayerCount
= 0;
34 create_info
.ppEnabledLayerNames
= NULL
;
35 create_info
.enabledExtensionCount
= extension_count
;
36 create_info
.ppEnabledExtensionNames
= enabled_extensions
;
38 return vkCreateInstance(&create_info
, NULL
, vk_instance
);
41 #define create_instance_skip(a, b, c) create_instance_skip_(__LINE__, a, b, c)
42 static VkResult
create_instance_skip_(unsigned int line
, uint32_t extension_count
,
43 const char * const *enabled_extensions
, VkInstance
*vk_instance
)
47 if ((vr
= create_instance(extension_count
, enabled_extensions
, vk_instance
)) >= 0)
52 case VK_ERROR_EXTENSION_NOT_PRESENT
:
53 if (extension_count
== 1)
54 skip_(__FILE__
, line
)("Instance extension '%s' not supported.\n", enabled_extensions
[0]);
56 skip_(__FILE__
, line
)("Instance extensions not supported.\n");
60 skip_(__FILE__
, line
)("Failed to create Vulkan instance, vr %d.\n", vr
);
67 static VkBool32
find_queue_family(VkPhysicalDevice vk_physical_device
,
68 VkQueueFlags flags
, uint32_t *family_index
)
70 VkQueueFamilyProperties
*properties
;
71 VkBool32 ret
= VK_FALSE
;
74 vkGetPhysicalDeviceQueueFamilyProperties(vk_physical_device
, &count
, NULL
);
75 properties
= heap_calloc(count
, sizeof(*properties
));
76 ok(!!properties
, "Failed to allocate memory.\n");
77 vkGetPhysicalDeviceQueueFamilyProperties(vk_physical_device
, &count
, properties
);
79 for (i
= 0; i
< count
; ++i
)
81 if ((properties
[i
].queueFlags
& flags
) == flags
)
89 heap_free(properties
);
93 static VkResult
create_device(VkPhysicalDevice vk_physical_device
,
94 uint32_t extension_count
, const char * const *enabled_extensions
,
95 const void *next
, VkDevice
*vk_device
)
97 VkDeviceQueueCreateInfo queue_info
;
98 VkDeviceCreateInfo create_info
;
99 float priority
= 0.0f
;
101 queue_info
.sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO
;
102 queue_info
.pNext
= NULL
;
103 queue_info
.flags
= 0;
104 if (!find_queue_family(vk_physical_device
, VK_QUEUE_GRAPHICS_BIT
, &queue_info
.queueFamilyIndex
))
106 trace("Failed to find queue family.\n");
107 return VK_ERROR_INITIALIZATION_FAILED
;
109 queue_info
.queueCount
= 1;
110 queue_info
.pQueuePriorities
= &priority
;
112 create_info
.sType
= VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
;
113 create_info
.pNext
= next
;
114 create_info
.flags
= 0;
115 create_info
.queueCreateInfoCount
= 1;
116 create_info
.pQueueCreateInfos
= &queue_info
;
117 create_info
.enabledLayerCount
= 0;
118 create_info
.ppEnabledLayerNames
= NULL
;
119 create_info
.enabledExtensionCount
= extension_count
;
120 create_info
.ppEnabledExtensionNames
= enabled_extensions
;
121 create_info
.pEnabledFeatures
= NULL
;
123 return vkCreateDevice(vk_physical_device
, &create_info
, NULL
, vk_device
);
126 static void test_instance_version(void)
128 PFN_vkEnumerateInstanceVersion pfn_vkEnumerateInstanceVersion
;
132 pfn_vkEnumerateInstanceVersion
= (PFN_vkEnumerateInstanceVersion
)vkGetInstanceProcAddr(
133 NULL
, "vkEnumerateInstanceVersion");
134 if (!pfn_vkEnumerateInstanceVersion
)
136 skip("vkEnumerateInstanceVersion() is not available.\n");
140 vr
= pfn_vkEnumerateInstanceVersion(&version
);
141 ok(vr
== VK_SUCCESS
, "Got unexpected VkResult %d.\n", vr
);
142 ok(version
>= VK_API_VERSION_1_0
, "Invalid version %#x.\n", version
);
143 trace("Vulkan version %u.%u.%u.\n",
144 VK_VERSION_MAJOR(version
), VK_VERSION_MINOR(version
), VK_VERSION_PATCH(version
));
147 static void enumerate_physical_device(VkPhysicalDevice vk_physical_device
)
149 VkPhysicalDeviceProperties properties
;
151 vkGetPhysicalDeviceProperties(vk_physical_device
, &properties
);
153 trace("Device '%s', %#x:%#x, driver version %u.%u.%u (%#x), api version %u.%u.%u.\n",
154 properties
.deviceName
, properties
.vendorID
, properties
.deviceID
,
155 VK_VERSION_MAJOR(properties
.driverVersion
), VK_VERSION_MINOR(properties
.driverVersion
),
156 VK_VERSION_PATCH(properties
.driverVersion
), properties
.driverVersion
,
157 VK_VERSION_MAJOR(properties
.apiVersion
), VK_VERSION_MINOR(properties
.apiVersion
),
158 VK_VERSION_PATCH(properties
.apiVersion
));
161 static void test_enumerate_physical_device2(void)
163 static const char *procs
[] = {"vkGetPhysicalDeviceProperties2", "vkGetPhysicalDeviceProperties2KHR"};
164 static const char *extensions
[] = {VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
};
165 PFN_vkGetPhysicalDeviceProperties2 pfn_vkGetPhysicalDeviceProperties2
;
166 VkPhysicalDeviceProperties2 properties2
;
167 VkPhysicalDevice
*vk_physical_devices
;
168 VkPhysicalDeviceIDProperties id
;
169 VkInstance vk_instance
;
175 if ((vr
= create_instance_skip(ARRAY_SIZE(extensions
), extensions
, &vk_instance
)) < 0)
177 ok(vr
== VK_SUCCESS
, "Got unexpected VkResult %d.\n", vr
);
179 vr
= vkEnumeratePhysicalDevices(vk_instance
, &count
, NULL
);
182 skip("No physical devices. VkResult %d.\n", vr
);
183 vkDestroyInstance(vk_instance
, NULL
);
187 vk_physical_devices
= heap_calloc(count
, sizeof(*vk_physical_devices
));
188 ok(!!vk_physical_devices
, "Failed to allocate memory.\n");
189 vr
= vkEnumeratePhysicalDevices(vk_instance
, &count
, vk_physical_devices
);
190 ok(vr
== VK_SUCCESS
, "Got unexpected VkResult %d.\n", vr
);
192 for (i
= 0; i
< ARRAY_SIZE(procs
); ++i
)
194 pfn_vkGetPhysicalDeviceProperties2
195 = (PFN_vkGetPhysicalDeviceProperties2
)vkGetInstanceProcAddr(vk_instance
, procs
[i
]);
196 if (!pfn_vkGetPhysicalDeviceProperties2
)
198 skip("%s is not available.\n", procs
[i
]);
202 for (j
= 0; j
< count
; ++j
)
204 properties2
.sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2
;
205 properties2
.pNext
= &id
;
207 memset(&id
, 0, sizeof(id
));
208 id
.sType
= VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES
;
210 pfn_vkGetPhysicalDeviceProperties2(vk_physical_devices
[j
], &properties2
);
211 luid
= (const LUID
*)id
.deviceLUID
;
212 trace("Device '%s', device UUID: %s, driver UUID: %s, device LUID: %08x:%08x.\n",
213 properties2
.properties
.deviceName
, wine_dbgstr_guid((const GUID
*)id
.deviceUUID
),
214 wine_dbgstr_guid((const GUID
*)id
.driverUUID
), luid
->HighPart
, luid
->LowPart
);
215 todo_wine
ok(id
.deviceLUIDValid
== VK_TRUE
, "Expected valid device LUID.\n");
219 heap_free(vk_physical_devices
);
220 vkDestroyInstance(vk_instance
, NULL
);
223 static void enumerate_device_queues(VkPhysicalDevice vk_physical_device
)
225 VkPhysicalDeviceProperties device_properties
;
226 VkQueueFamilyProperties
*properties
;
229 vkGetPhysicalDeviceProperties(vk_physical_device
, &device_properties
);
231 vkGetPhysicalDeviceQueueFamilyProperties(vk_physical_device
, &count
, NULL
);
232 properties
= heap_calloc(count
, sizeof(*properties
));
233 ok(!!properties
, "Failed to allocate memory.\n");
234 vkGetPhysicalDeviceQueueFamilyProperties(vk_physical_device
, &count
, properties
);
236 for (i
= 0; i
< count
; ++i
)
238 trace("Device '%s', queue family %u: flags %#x count %u.\n",
239 device_properties
.deviceName
, i
, properties
[i
].queueFlags
, properties
[i
].queueCount
);
242 heap_free(properties
);
245 static void test_physical_device_groups(void)
247 PFN_vkEnumeratePhysicalDeviceGroupsKHR vkEnumeratePhysicalDeviceGroupsKHR
;
248 VkPhysicalDeviceGroupProperties
*properties
;
249 VkDeviceGroupDeviceCreateInfo group_info
;
250 VkInstance vk_instance
;
251 uint32_t i
, j
, count
;
255 static const char *extensions
[] =
257 VK_KHR_DEVICE_GROUP_CREATION_EXTENSION_NAME
,
260 if ((vr
= create_instance_skip(ARRAY_SIZE(extensions
), extensions
, &vk_instance
)) < 0)
262 ok(vr
== VK_SUCCESS
, "Got unexpected VkResult %d.\n", vr
);
264 vkEnumeratePhysicalDeviceGroupsKHR
265 = (void *)vkGetInstanceProcAddr(vk_instance
, "vkEnumeratePhysicalDeviceGroupsKHR");
266 ok(!!vkEnumeratePhysicalDeviceGroupsKHR
, "Failed to get proc addr.\n");
268 vr
= vkEnumeratePhysicalDeviceGroupsKHR(vk_instance
, &count
, NULL
);
269 ok(vr
== VK_SUCCESS
, "Got unexpected VkResult %d.\n", vr
);
270 ok(count
> 0, "Unexpected device group count %u.\n", count
);
272 properties
= heap_calloc(count
, sizeof(*properties
));
273 ok(!!properties
, "Failed to allocate memory.\n");
274 vr
= vkEnumeratePhysicalDeviceGroupsKHR(vk_instance
, &count
, properties
);
275 ok(vr
== VK_SUCCESS
, "Got unexpected VkResult %d.\n", vr
);
277 for (i
= 0; i
< count
; ++i
)
279 trace("Group[%u] count %u, subset allocation %#x\n",
280 i
, properties
[i
].physicalDeviceCount
, properties
[i
].subsetAllocation
);
281 for (j
= 0; j
< properties
[i
].physicalDeviceCount
; ++j
)
282 enumerate_physical_device(properties
[i
].physicalDevices
[j
]);
285 if ((vr
= create_device(properties
->physicalDevices
[0], 0, NULL
, NULL
, &vk_device
)) < 0)
287 skip("Failed to create device, vr %d.\n", vr
);
290 ok(vr
== VK_SUCCESS
, "Got unexpected VkResult %d.\n", vr
);
291 vkDestroyDevice(vk_device
, NULL
);
293 group_info
.sType
= VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO
;
294 group_info
.pNext
= NULL
;
295 group_info
.physicalDeviceCount
= properties
->physicalDeviceCount
;
296 group_info
.pPhysicalDevices
= properties
->physicalDevices
;
297 vr
= create_device(group_info
.pPhysicalDevices
[0], 0, NULL
, &group_info
, &vk_device
);
298 ok(vr
== VK_SUCCESS
, "Failed to create device, VkResult %d.\n", vr
);
299 vkDestroyDevice(vk_device
, NULL
);
301 heap_free(properties
);
303 vkDestroyInstance(vk_instance
, NULL
);
306 static void test_destroy_command_pool(VkPhysicalDevice vk_physical_device
)
308 VkCommandBufferAllocateInfo allocate_info
;
309 VkCommandPoolCreateInfo pool_info
;
310 VkCommandBuffer vk_cmd_buffers
[4];
311 uint32_t queue_family_index
;
312 VkCommandPool vk_cmd_pool
;
316 if ((vr
= create_device(vk_physical_device
, 0, NULL
, NULL
, &vk_device
)) < 0)
318 skip("Failed to create device, vr %d.\n", vr
);
322 find_queue_family(vk_physical_device
, VK_QUEUE_GRAPHICS_BIT
, &queue_family_index
);
324 pool_info
.sType
= VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO
;
325 pool_info
.pNext
= NULL
;
327 pool_info
.queueFamilyIndex
= queue_family_index
;
328 vr
= vkCreateCommandPool(vk_device
, &pool_info
, NULL
, &vk_cmd_pool
);
329 ok(vr
== VK_SUCCESS
, "Got unexpected VkResult %d.\n", vr
);
331 allocate_info
.sType
= VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO
;
332 allocate_info
.pNext
= NULL
;
333 allocate_info
.commandPool
= vk_cmd_pool
;
334 allocate_info
.level
= VK_COMMAND_BUFFER_LEVEL_PRIMARY
;
335 allocate_info
.commandBufferCount
= ARRAY_SIZE(vk_cmd_buffers
);
336 vr
= vkAllocateCommandBuffers(vk_device
, &allocate_info
, vk_cmd_buffers
);
337 ok(vr
== VK_SUCCESS
, "Got unexpected VkResult %d.\n", vr
);
339 vkDestroyCommandPool(vk_device
, vk_cmd_pool
, NULL
);
340 vkDestroyCommandPool(vk_device
, VK_NULL_HANDLE
, NULL
);
342 vkDestroyDevice(vk_device
, NULL
);
345 static void test_unsupported_instance_extensions(void)
347 VkInstance vk_instance
;
351 static const char *extensions
[] =
353 "VK_KHR_xcb_surface",
354 "VK_KHR_xlib_surface",
357 for (i
= 0; i
< ARRAY_SIZE(extensions
); ++i
)
359 vr
= create_instance(1, &extensions
[i
], &vk_instance
);
360 ok(vr
== VK_ERROR_EXTENSION_NOT_PRESENT
,
361 "Got VkResult %d for extension %s.\n", vr
, extensions
[i
]);
365 static void test_unsupported_device_extensions(VkPhysicalDevice vk_physical_device
)
371 static const char *extensions
[] =
373 "VK_KHR_external_fence_fd",
374 "VK_KHR_external_memory_fd",
375 "VK_KHR_external_semaphore_fd",
378 for (i
= 0; i
< ARRAY_SIZE(extensions
); ++i
)
380 vr
= create_device(vk_physical_device
, 1, &extensions
[i
], NULL
, &vk_device
);
381 ok(vr
== VK_ERROR_EXTENSION_NOT_PRESENT
,
382 "Got VkResult %d for extension %s.\n", vr
, extensions
[i
]);
386 static void for_each_device(void (*test_func
)(VkPhysicalDevice
))
388 VkPhysicalDevice
*vk_physical_devices
;
389 VkInstance vk_instance
;
394 if ((vr
= create_instance_skip(0, NULL
, &vk_instance
)) < 0)
396 ok(vr
== VK_SUCCESS
, "Got unexpected VkResult %d.\n", vr
);
398 vr
= vkEnumeratePhysicalDevices(vk_instance
, &count
, NULL
);
401 skip("No physical devices. VkResult %d.\n", vr
);
402 vkDestroyInstance(vk_instance
, NULL
);
406 vk_physical_devices
= heap_calloc(count
, sizeof(*vk_physical_devices
));
407 ok(!!vk_physical_devices
, "Failed to allocate memory.\n");
408 vr
= vkEnumeratePhysicalDevices(vk_instance
, &count
, vk_physical_devices
);
409 ok(vr
== VK_SUCCESS
, "Got unexpected VkResult %d.\n", vr
);
411 for (i
= 0; i
< count
; ++i
)
412 test_func(vk_physical_devices
[i
]);
414 heap_free(vk_physical_devices
);
416 vkDestroyInstance(vk_instance
, NULL
);
421 test_instance_version();
422 for_each_device(enumerate_physical_device
);
423 test_enumerate_physical_device2();
424 for_each_device(enumerate_device_queues
);
425 test_physical_device_groups();
426 for_each_device(test_destroy_command_pool
);
427 test_unsupported_instance_extensions();
428 for_each_device(test_unsupported_device_extensions
);