winevulkan: Convert VkPhysicalDeviceFeatures2 in VkDeviceCreateInfo chain.
[wine.git] / dlls / winevulkan / vulkan.c
blobf86064c4b661668d40d86be64f7454eddeae019b
1 /* Wine Vulkan ICD implementation
3 * Copyright 2017 Roderick Colenbrander
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winuser.h"
26 #include "vulkan_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(vulkan);
30 /* For now default to 4 as it felt like a reasonable version feature wise to support.
31 * Don't support the optional vk_icdGetPhysicalDeviceProcAddr introduced in this version
32 * as it is unlikely we will implement physical device extensions, which the loader is not
33 * aware of. Version 5 adds more extensive version checks. Something to tackle later.
35 #define WINE_VULKAN_ICD_VERSION 4
37 #define wine_vk_find_struct(s, t) wine_vk_find_struct_((void *)s, VK_STRUCTURE_TYPE_##t)
38 static void *wine_vk_find_struct_(void *s, VkStructureType t)
40 VkBaseOutStructure *header;
42 for (header = s; header; header = header->pNext)
44 if (header->sType == t)
45 return header;
48 return NULL;
51 static void *wine_vk_get_global_proc_addr(const char *name);
53 static const struct vulkan_funcs *vk_funcs;
54 static VkResult (*p_vkEnumerateInstanceVersion)(uint32_t *version);
56 void WINAPI wine_vkGetPhysicalDeviceProperties(VkPhysicalDevice physical_device,
57 VkPhysicalDeviceProperties *properties);
59 static void wine_vk_physical_device_free(struct VkPhysicalDevice_T *phys_dev)
61 if (!phys_dev)
62 return;
64 heap_free(phys_dev->extensions);
65 heap_free(phys_dev);
68 static struct VkPhysicalDevice_T *wine_vk_physical_device_alloc(struct VkInstance_T *instance,
69 VkPhysicalDevice phys_dev)
71 struct VkPhysicalDevice_T *object;
72 uint32_t num_host_properties, num_properties = 0;
73 VkExtensionProperties *host_properties = NULL;
74 VkResult res;
75 unsigned int i, j;
77 if (!(object = heap_alloc_zero(sizeof(*object))))
78 return NULL;
80 object->base.loader_magic = VULKAN_ICD_MAGIC_VALUE;
81 object->instance = instance;
82 object->phys_dev = phys_dev;
84 res = instance->funcs.p_vkEnumerateDeviceExtensionProperties(phys_dev,
85 NULL, &num_host_properties, NULL);
86 if (res != VK_SUCCESS)
88 ERR("Failed to enumerate device extensions, res=%d\n", res);
89 goto err;
92 host_properties = heap_calloc(num_host_properties, sizeof(*host_properties));
93 if (!host_properties)
95 ERR("Failed to allocate memory for device properties!\n");
96 goto err;
99 res = instance->funcs.p_vkEnumerateDeviceExtensionProperties(phys_dev,
100 NULL, &num_host_properties, host_properties);
101 if (res != VK_SUCCESS)
103 ERR("Failed to enumerate device extensions, res=%d\n", res);
104 goto err;
107 /* Count list of extensions for which we have an implementation.
108 * TODO: perform translation for platform specific extensions.
110 for (i = 0; i < num_host_properties; i++)
112 if (wine_vk_device_extension_supported(host_properties[i].extensionName))
114 TRACE("Enabling extension '%s' for physical device %p\n", host_properties[i].extensionName, object);
115 num_properties++;
117 else
119 TRACE("Skipping extension '%s', no implementation found in winevulkan.\n", host_properties[i].extensionName);
123 TRACE("Host supported extensions %u, Wine supported extensions %u\n", num_host_properties, num_properties);
125 if (!(object->extensions = heap_calloc(num_properties, sizeof(*object->extensions))))
127 ERR("Failed to allocate memory for device extensions!\n");
128 goto err;
131 for (i = 0, j = 0; i < num_host_properties; i++)
133 if (wine_vk_device_extension_supported(host_properties[i].extensionName))
135 object->extensions[j] = host_properties[i];
136 j++;
139 object->extension_count = num_properties;
141 heap_free(host_properties);
142 return object;
144 err:
145 wine_vk_physical_device_free(object);
146 heap_free(host_properties);
147 return NULL;
150 static void wine_vk_free_command_buffers(struct VkDevice_T *device,
151 struct wine_cmd_pool *pool, uint32_t count, const VkCommandBuffer *buffers)
153 unsigned int i;
155 for (i = 0; i < count; i++)
157 if (!buffers[i])
158 continue;
160 device->funcs.p_vkFreeCommandBuffers(device->device, pool->command_pool, 1, &buffers[i]->command_buffer);
161 list_remove(&buffers[i]->pool_link);
162 heap_free(buffers[i]);
166 static struct VkQueue_T *wine_vk_device_alloc_queues(struct VkDevice_T *device,
167 uint32_t family_index, uint32_t queue_count, VkDeviceQueueCreateFlags flags)
169 VkDeviceQueueInfo2 queue_info;
170 struct VkQueue_T *queues;
171 unsigned int i;
173 if (!(queues = heap_calloc(queue_count, sizeof(*queues))))
175 ERR("Failed to allocate memory for queues\n");
176 return NULL;
179 for (i = 0; i < queue_count; i++)
181 struct VkQueue_T *queue = &queues[i];
183 queue->base.loader_magic = VULKAN_ICD_MAGIC_VALUE;
184 queue->device = device;
185 queue->flags = flags;
187 /* The Vulkan spec says:
189 * "vkGetDeviceQueue must only be used to get queues that were created
190 * with the flags parameter of VkDeviceQueueCreateInfo set to zero."
192 if (flags && device->funcs.p_vkGetDeviceQueue2)
194 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2;
195 queue_info.pNext = NULL;
196 queue_info.flags = flags;
197 queue_info.queueFamilyIndex = family_index;
198 queue_info.queueIndex = i;
199 device->funcs.p_vkGetDeviceQueue2(device->device, &queue_info, &queue->queue);
201 else
203 device->funcs.p_vkGetDeviceQueue(device->device, family_index, i, &queue->queue);
207 return queues;
210 static void *convert_VkPhysicalDeviceFeatures2(const void *src)
212 const VkPhysicalDeviceFeatures2 *in = src;
213 VkPhysicalDeviceFeatures2 *out;
215 if (!(out = heap_alloc(sizeof(*out))))
216 return NULL;
218 *out = *in;
219 out->pNext = NULL;
221 return out;
224 static void *convert_VkDeviceGroupDeviceCreateInfo(const void *src)
226 const VkDeviceGroupDeviceCreateInfo *in = src;
227 VkDeviceGroupDeviceCreateInfo *out;
228 VkPhysicalDevice *physical_devices;
229 unsigned int i;
231 if (!(out = heap_alloc(sizeof(*out))))
232 return NULL;
234 *out = *in;
235 out->pNext = NULL;
236 if (!(physical_devices = heap_calloc(in->physicalDeviceCount, sizeof(*physical_devices))))
238 heap_free(out);
239 return NULL;
241 for (i = 0; i < in->physicalDeviceCount; ++i)
242 physical_devices[i] = in->pPhysicalDevices[i]->phys_dev;
243 out->pPhysicalDevices = physical_devices;
245 return out;
248 static void *convert_VkPhysicalDeviceHostQueryResetFeaturesEXT(const void *src)
250 const VkPhysicalDeviceHostQueryResetFeaturesEXT *in = src;
251 VkPhysicalDeviceHostQueryResetFeaturesEXT *out;
253 if (!(out = heap_alloc(sizeof(*out))))
254 return NULL;
256 *out = *in;
257 out->pNext = NULL;
259 return out;
262 static void wine_vk_device_free_create_info(VkDeviceCreateInfo *create_info)
264 VkPhysicalDeviceHostQueryResetFeaturesEXT *host_query_reset_features;
265 VkPhysicalDeviceFeatures2 *device_features;
266 VkDeviceGroupDeviceCreateInfo *group_info;
268 device_features = wine_vk_find_struct(create_info, PHYSICAL_DEVICE_FEATURES_2);
269 group_info = wine_vk_find_struct(create_info, DEVICE_GROUP_DEVICE_CREATE_INFO);
270 host_query_reset_features = wine_vk_find_struct(create_info, PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT);
271 create_info->pNext = NULL;
273 heap_free(device_features);
274 if (group_info)
276 heap_free((void *)group_info->pPhysicalDevices);
277 heap_free(group_info);
279 heap_free(host_query_reset_features);
282 static VkResult wine_vk_device_convert_create_info(const VkDeviceCreateInfo *src,
283 VkDeviceCreateInfo *dst)
285 unsigned int i;
287 *dst = *src;
289 /* Application and loader can pass in a chain of extensions through pNext.
290 * We can't blindly pass these through as often these contain callbacks or
291 * they can even be pass structures for loader / ICD internal use.
293 if (src->pNext)
295 const VkBaseInStructure *header;
296 VkBaseOutStructure *dst_header;
298 dst->pNext = NULL;
299 dst_header = (VkBaseOutStructure *)dst;
300 for (header = src->pNext; header; header = header->pNext)
302 switch (header->sType)
304 case VK_STRUCTURE_TYPE_LOADER_DEVICE_CREATE_INFO:
305 /* Used for loader to ICD communication. Ignore to not confuse
306 * host loader.
308 break;
310 case VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO:
311 if (!(dst_header->pNext = convert_VkDeviceGroupDeviceCreateInfo(header)))
312 goto err;
313 dst_header = dst_header->pNext;
314 break;
316 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2:
317 if (!(dst_header->pNext = convert_VkPhysicalDeviceFeatures2(header)))
318 goto err;
319 dst_header = dst_header->pNext;
320 break;
322 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT:
323 if (!(dst_header->pNext = convert_VkPhysicalDeviceHostQueryResetFeaturesEXT(header)))
324 goto err;
325 dst_header = dst_header->pNext;
326 break;
328 default:
329 FIXME("Application requested a linked structure of type %u.\n", header->sType);
334 /* Should be filtered out by loader as ICDs don't support layers. */
335 dst->enabledLayerCount = 0;
336 dst->ppEnabledLayerNames = NULL;
338 TRACE("Enabled %u extensions.\n", dst->enabledExtensionCount);
339 for (i = 0; i < dst->enabledExtensionCount; i++)
341 const char *extension_name = dst->ppEnabledExtensionNames[i];
342 TRACE("Extension %u: %s.\n", i, debugstr_a(extension_name));
343 if (!wine_vk_device_extension_supported(extension_name))
345 WARN("Extension %s is not supported.\n", debugstr_a(extension_name));
346 return VK_ERROR_EXTENSION_NOT_PRESENT;
350 return VK_SUCCESS;
352 err:
353 wine_vk_device_free_create_info(dst);
354 return VK_ERROR_OUT_OF_HOST_MEMORY;
357 /* Helper function used for freeing a device structure. This function supports full
358 * and partial object cleanups and can thus be used for vkCreateDevice failures.
360 static void wine_vk_device_free(struct VkDevice_T *device)
362 if (!device)
363 return;
365 if (device->queues)
367 unsigned int i;
368 for (i = 0; i < device->max_queue_families; i++)
370 heap_free(device->queues[i]);
372 heap_free(device->queues);
373 device->queues = NULL;
376 if (device->device && device->funcs.p_vkDestroyDevice)
378 device->funcs.p_vkDestroyDevice(device->device, NULL /* pAllocator */);
381 heap_free(device);
384 static BOOL wine_vk_init(void)
386 HDC hdc;
388 hdc = GetDC(0);
389 vk_funcs = __wine_get_vulkan_driver(hdc, WINE_VULKAN_DRIVER_VERSION);
390 ReleaseDC(0, hdc);
391 if (!vk_funcs)
393 ERR("Failed to load Wine graphics driver supporting Vulkan.\n");
394 return FALSE;
397 p_vkEnumerateInstanceVersion = vk_funcs->p_vkGetInstanceProcAddr(NULL, "vkEnumerateInstanceVersion");
399 return TRUE;
402 /* Helper function for converting between win32 and host compatible VkInstanceCreateInfo.
403 * This function takes care of extensions handled at winevulkan layer, a Wine graphics
404 * driver is responsible for handling e.g. surface extensions.
406 static VkResult wine_vk_instance_convert_create_info(const VkInstanceCreateInfo *src,
407 VkInstanceCreateInfo *dst)
409 unsigned int i;
411 *dst = *src;
413 /* Application and loader can pass in a chain of extensions through pNext.
414 * We can't blindly pass these through as often these contain callbacks or
415 * they can even be pass structures for loader / ICD internal use. For now
416 * we ignore everything in pNext chain, but we print FIXMEs.
418 if (src->pNext)
420 const VkBaseInStructure *header;
422 for (header = src->pNext; header; header = header->pNext)
424 switch (header->sType)
426 case VK_STRUCTURE_TYPE_LOADER_INSTANCE_CREATE_INFO:
427 /* Can be used to register new dispatchable object types
428 * to the loader. We should ignore it as it will confuse the
429 * host its loader.
431 break;
433 default:
434 FIXME("Application requested a linked structure of type %u.\n", header->sType);
438 /* For now don't support anything. */
439 dst->pNext = NULL;
441 /* ICDs don't support any layers, so nothing to copy. Modern versions of the loader
442 * filter this data out as well.
444 dst->enabledLayerCount = 0;
445 dst->ppEnabledLayerNames = NULL;
447 TRACE("Enabled %u instance extensions.\n", dst->enabledExtensionCount);
448 for (i = 0; i < dst->enabledExtensionCount; i++)
450 const char *extension_name = dst->ppEnabledExtensionNames[i];
451 TRACE("Extension %u: %s.\n", i, debugstr_a(extension_name));
452 if (!wine_vk_instance_extension_supported(extension_name))
454 WARN("Extension %s is not supported.\n", debugstr_a(extension_name));
455 return VK_ERROR_EXTENSION_NOT_PRESENT;
459 return VK_SUCCESS;
462 /* Helper function which stores wrapped physical devices in the instance object. */
463 static VkResult wine_vk_instance_load_physical_devices(struct VkInstance_T *instance)
465 VkPhysicalDevice *tmp_phys_devs;
466 uint32_t phys_dev_count;
467 unsigned int i;
468 VkResult res;
470 res = instance->funcs.p_vkEnumeratePhysicalDevices(instance->instance, &phys_dev_count, NULL);
471 if (res != VK_SUCCESS)
473 ERR("Failed to enumerate physical devices, res=%d\n", res);
474 return res;
476 if (!phys_dev_count)
477 return res;
479 if (!(tmp_phys_devs = heap_calloc(phys_dev_count, sizeof(*tmp_phys_devs))))
480 return VK_ERROR_OUT_OF_HOST_MEMORY;
482 res = instance->funcs.p_vkEnumeratePhysicalDevices(instance->instance, &phys_dev_count, tmp_phys_devs);
483 if (res != VK_SUCCESS)
485 heap_free(tmp_phys_devs);
486 return res;
489 instance->phys_devs = heap_calloc(phys_dev_count, sizeof(*instance->phys_devs));
490 if (!instance->phys_devs)
492 heap_free(tmp_phys_devs);
493 return VK_ERROR_OUT_OF_HOST_MEMORY;
496 /* Wrap each native physical device handle into a dispatchable object for the ICD loader. */
497 for (i = 0; i < phys_dev_count; i++)
499 struct VkPhysicalDevice_T *phys_dev = wine_vk_physical_device_alloc(instance, tmp_phys_devs[i]);
500 if (!phys_dev)
502 ERR("Unable to allocate memory for physical device!\n");
503 heap_free(tmp_phys_devs);
504 return VK_ERROR_OUT_OF_HOST_MEMORY;
507 instance->phys_devs[i] = phys_dev;
508 instance->phys_dev_count = i + 1;
510 instance->phys_dev_count = phys_dev_count;
512 heap_free(tmp_phys_devs);
513 return VK_SUCCESS;
516 static struct VkPhysicalDevice_T *wine_vk_instance_wrap_physical_device(struct VkInstance_T *instance,
517 VkPhysicalDevice physical_device)
519 unsigned int i;
521 for (i = 0; i < instance->phys_dev_count; ++i)
523 struct VkPhysicalDevice_T *current = instance->phys_devs[i];
524 if (current->phys_dev == physical_device)
525 return current;
528 ERR("Unrecognized physical device %p.\n", physical_device);
529 return NULL;
532 /* Helper function used for freeing an instance structure. This function supports full
533 * and partial object cleanups and can thus be used for vkCreateInstance failures.
535 static void wine_vk_instance_free(struct VkInstance_T *instance)
537 if (!instance)
538 return;
540 if (instance->phys_devs)
542 unsigned int i;
544 for (i = 0; i < instance->phys_dev_count; i++)
546 wine_vk_physical_device_free(instance->phys_devs[i]);
548 heap_free(instance->phys_devs);
551 if (instance->instance)
552 vk_funcs->p_vkDestroyInstance(instance->instance, NULL /* allocator */);
554 heap_free(instance);
557 VkResult WINAPI wine_vkAllocateCommandBuffers(VkDevice device,
558 const VkCommandBufferAllocateInfo *allocate_info, VkCommandBuffer *buffers)
560 struct wine_cmd_pool *pool;
561 VkResult res = VK_SUCCESS;
562 unsigned int i;
564 TRACE("%p, %p, %p\n", device, allocate_info, buffers);
566 pool = wine_cmd_pool_from_handle(allocate_info->commandPool);
568 memset(buffers, 0, allocate_info->commandBufferCount * sizeof(*buffers));
570 for (i = 0; i < allocate_info->commandBufferCount; i++)
572 #if defined(USE_STRUCT_CONVERSION)
573 VkCommandBufferAllocateInfo_host allocate_info_host;
574 #else
575 VkCommandBufferAllocateInfo allocate_info_host;
576 #endif
577 /* TODO: future extensions (none yet) may require pNext conversion. */
578 allocate_info_host.pNext = allocate_info->pNext;
579 allocate_info_host.sType = allocate_info->sType;
580 allocate_info_host.commandPool = pool->command_pool;
581 allocate_info_host.level = allocate_info->level;
582 allocate_info_host.commandBufferCount = 1;
584 TRACE("Allocating command buffer %u from pool 0x%s.\n",
585 i, wine_dbgstr_longlong(allocate_info_host.commandPool));
587 if (!(buffers[i] = heap_alloc_zero(sizeof(**buffers))))
589 res = VK_ERROR_OUT_OF_HOST_MEMORY;
590 break;
593 buffers[i]->base.loader_magic = VULKAN_ICD_MAGIC_VALUE;
594 buffers[i]->device = device;
595 list_add_tail(&pool->command_buffers, &buffers[i]->pool_link);
596 res = device->funcs.p_vkAllocateCommandBuffers(device->device,
597 &allocate_info_host, &buffers[i]->command_buffer);
598 if (res != VK_SUCCESS)
600 ERR("Failed to allocate command buffer, res=%d.\n", res);
601 buffers[i]->command_buffer = VK_NULL_HANDLE;
602 break;
606 if (res != VK_SUCCESS)
608 wine_vk_free_command_buffers(device, pool, i + 1, buffers);
609 memset(buffers, 0, allocate_info->commandBufferCount * sizeof(*buffers));
612 return res;
615 void WINAPI wine_vkCmdExecuteCommands(VkCommandBuffer buffer, uint32_t count,
616 const VkCommandBuffer *buffers)
618 VkCommandBuffer *tmp_buffers;
619 unsigned int i;
621 TRACE("%p %u %p\n", buffer, count, buffers);
623 if (!buffers || !count)
624 return;
626 /* Unfortunately we need a temporary buffer as our command buffers are wrapped.
627 * This call is called often and if a performance concern, we may want to use
628 * alloca as we shouldn't need much memory and it needs to be cleaned up after
629 * the call anyway.
631 if (!(tmp_buffers = heap_alloc(count * sizeof(*tmp_buffers))))
633 ERR("Failed to allocate memory for temporary command buffers\n");
634 return;
637 for (i = 0; i < count; i++)
638 tmp_buffers[i] = buffers[i]->command_buffer;
640 buffer->device->funcs.p_vkCmdExecuteCommands(buffer->command_buffer, count, tmp_buffers);
642 heap_free(tmp_buffers);
645 VkResult WINAPI wine_vkCreateDevice(VkPhysicalDevice phys_dev,
646 const VkDeviceCreateInfo *create_info,
647 const VkAllocationCallbacks *allocator, VkDevice *device)
649 VkDeviceCreateInfo create_info_host;
650 uint32_t max_queue_families;
651 struct VkDevice_T *object;
652 unsigned int i;
653 VkResult res;
655 TRACE("%p, %p, %p, %p\n", phys_dev, create_info, allocator, device);
657 if (allocator)
658 FIXME("Support for allocation callbacks not implemented yet\n");
660 if (TRACE_ON(vulkan))
662 VkPhysicalDeviceProperties properties;
664 wine_vkGetPhysicalDeviceProperties(phys_dev, &properties);
666 TRACE("Device name: %s.\n", debugstr_a(properties.deviceName));
667 TRACE("Vendor ID: %#x, Device ID: %#x.\n", properties.vendorID, properties.deviceID);
668 TRACE("Driver version: %#x.\n", properties.driverVersion);
671 if (!(object = heap_alloc_zero(sizeof(*object))))
672 return VK_ERROR_OUT_OF_HOST_MEMORY;
674 object->base.loader_magic = VULKAN_ICD_MAGIC_VALUE;
676 res = wine_vk_device_convert_create_info(create_info, &create_info_host);
677 if (res != VK_SUCCESS)
679 if (res != VK_ERROR_EXTENSION_NOT_PRESENT)
680 ERR("Failed to convert VkDeviceCreateInfo, res=%d.\n", res);
681 wine_vk_device_free(object);
682 return res;
685 res = phys_dev->instance->funcs.p_vkCreateDevice(phys_dev->phys_dev,
686 &create_info_host, NULL /* allocator */, &object->device);
687 wine_vk_device_free_create_info(&create_info_host);
688 if (res != VK_SUCCESS)
690 ERR("Failed to create device.\n");
691 wine_vk_device_free(object);
692 return res;
695 /* Just load all function pointers we are aware off. The loader takes care of filtering.
696 * We use vkGetDeviceProcAddr as opposed to vkGetInstanceProcAddr for efficiency reasons
697 * as functions pass through fewer dispatch tables within the loader.
699 #define USE_VK_FUNC(name) \
700 object->funcs.p_##name = (void *)vk_funcs->p_vkGetDeviceProcAddr(object->device, #name); \
701 if (object->funcs.p_##name == NULL) \
702 TRACE("Not found %s\n", #name);
703 ALL_VK_DEVICE_FUNCS()
704 #undef USE_VK_FUNC
706 /* We need to cache all queues within the device as each requires wrapping since queues are
707 * dispatchable objects.
709 phys_dev->instance->funcs.p_vkGetPhysicalDeviceQueueFamilyProperties(phys_dev->phys_dev,
710 &max_queue_families, NULL);
711 object->max_queue_families = max_queue_families;
712 TRACE("Max queue families: %u\n", object->max_queue_families);
714 object->queues = heap_calloc(max_queue_families, sizeof(*object->queues));
715 if (!object->queues)
717 wine_vk_device_free(object);
718 return VK_ERROR_OUT_OF_HOST_MEMORY;
721 for (i = 0; i < create_info_host.queueCreateInfoCount; i++)
723 uint32_t flags = create_info_host.pQueueCreateInfos[i].flags;
724 uint32_t family_index = create_info_host.pQueueCreateInfos[i].queueFamilyIndex;
725 uint32_t queue_count = create_info_host.pQueueCreateInfos[i].queueCount;
727 TRACE("queueFamilyIndex %u, queueCount %u\n", family_index, queue_count);
729 object->queues[family_index] = wine_vk_device_alloc_queues(object, family_index,
730 queue_count, flags);
731 if (!object->queues[family_index])
733 ERR("Failed to allocate memory for queues\n");
734 wine_vk_device_free(object);
735 return VK_ERROR_OUT_OF_HOST_MEMORY;
739 object->quirks = phys_dev->instance->quirks;
741 *device = object;
742 TRACE("Created device %p (native device %p).\n", object, object->device);
743 return VK_SUCCESS;
746 VkResult WINAPI wine_vkCreateInstance(const VkInstanceCreateInfo *create_info,
747 const VkAllocationCallbacks *allocator, VkInstance *instance)
749 VkInstanceCreateInfo create_info_host;
750 const VkApplicationInfo *app_info;
751 struct VkInstance_T *object;
752 VkResult res;
754 TRACE("create_info %p, allocator %p, instance %p\n", create_info, allocator, instance);
756 if (allocator)
757 FIXME("Support for allocation callbacks not implemented yet\n");
759 if (!(object = heap_alloc_zero(sizeof(*object))))
761 ERR("Failed to allocate memory for instance\n");
762 return VK_ERROR_OUT_OF_HOST_MEMORY;
764 object->base.loader_magic = VULKAN_ICD_MAGIC_VALUE;
766 res = wine_vk_instance_convert_create_info(create_info, &create_info_host);
767 if (res != VK_SUCCESS)
769 wine_vk_instance_free(object);
770 return res;
773 res = vk_funcs->p_vkCreateInstance(&create_info_host, NULL /* allocator */, &object->instance);
774 if (res != VK_SUCCESS)
776 ERR("Failed to create instance, res=%d\n", res);
777 wine_vk_instance_free(object);
778 return res;
781 /* Load all instance functions we are aware of. Note the loader takes care
782 * of any filtering for extensions which were not requested, but which the
783 * ICD may support.
785 #define USE_VK_FUNC(name) \
786 object->funcs.p_##name = (void *)vk_funcs->p_vkGetInstanceProcAddr(object->instance, #name);
787 ALL_VK_INSTANCE_FUNCS()
788 #undef USE_VK_FUNC
790 /* Cache physical devices for vkEnumeratePhysicalDevices within the instance as
791 * each vkPhysicalDevice is a dispatchable object, which means we need to wrap
792 * the native physical devices and present those to the application.
793 * Cleanup happens as part of wine_vkDestroyInstance.
795 res = wine_vk_instance_load_physical_devices(object);
796 if (res != VK_SUCCESS)
798 ERR("Failed to load physical devices, res=%d\n", res);
799 wine_vk_instance_free(object);
800 return res;
803 if ((app_info = create_info->pApplicationInfo))
805 TRACE("Application name %s, application version %#x.\n",
806 debugstr_a(app_info->pApplicationName), app_info->applicationVersion);
807 TRACE("Engine name %s, engine version %#x.\n", debugstr_a(app_info->pEngineName),
808 app_info->engineVersion);
809 TRACE("API version %#x.\n", app_info->apiVersion);
811 if (app_info->pEngineName && !strcmp(app_info->pEngineName, "idTech"))
812 object->quirks |= WINEVULKAN_QUIRK_GET_DEVICE_PROC_ADDR;
815 *instance = object;
816 TRACE("Created instance %p (native instance %p).\n", object, object->instance);
817 return VK_SUCCESS;
820 void WINAPI wine_vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *allocator)
822 TRACE("%p %p\n", device, allocator);
824 if (allocator)
825 FIXME("Support for allocation callbacks not implemented yet\n");
827 wine_vk_device_free(device);
830 void WINAPI wine_vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *allocator)
832 TRACE("%p, %p\n", instance, allocator);
834 if (allocator)
835 FIXME("Support allocation allocators\n");
837 wine_vk_instance_free(instance);
840 VkResult WINAPI wine_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice phys_dev,
841 const char *layer_name, uint32_t *count, VkExtensionProperties *properties)
843 TRACE("%p, %p, %p, %p\n", phys_dev, layer_name, count, properties);
845 /* This shouldn't get called with layer_name set, the ICD loader prevents it. */
846 if (layer_name)
848 ERR("Layer enumeration not supported from ICD.\n");
849 return VK_ERROR_LAYER_NOT_PRESENT;
852 if (!properties)
854 *count = phys_dev->extension_count;
855 return VK_SUCCESS;
858 *count = min(*count, phys_dev->extension_count);
859 memcpy(properties, phys_dev->extensions, *count * sizeof(*properties));
861 TRACE("Returning %u extensions.\n", *count);
862 return *count < phys_dev->extension_count ? VK_INCOMPLETE : VK_SUCCESS;
865 VkResult WINAPI wine_vkEnumerateInstanceExtensionProperties(const char *layer_name,
866 uint32_t *count, VkExtensionProperties *properties)
868 uint32_t num_properties = 0, num_host_properties;
869 VkExtensionProperties *host_properties;
870 unsigned int i, j;
871 VkResult res;
873 TRACE("%p, %p, %p\n", layer_name, count, properties);
875 if (layer_name)
877 WARN("Layer enumeration not supported from ICD.\n");
878 return VK_ERROR_LAYER_NOT_PRESENT;
881 res = vk_funcs->p_vkEnumerateInstanceExtensionProperties(NULL, &num_host_properties, NULL);
882 if (res != VK_SUCCESS)
883 return res;
885 if (!(host_properties = heap_calloc(num_host_properties, sizeof(*host_properties))))
886 return VK_ERROR_OUT_OF_HOST_MEMORY;
888 res = vk_funcs->p_vkEnumerateInstanceExtensionProperties(NULL, &num_host_properties, host_properties);
889 if (res != VK_SUCCESS)
891 ERR("Failed to retrieve host properties, res=%d.\n", res);
892 heap_free(host_properties);
893 return res;
896 /* The Wine graphics driver provides us with all extensions supported by the host side
897 * including extension fixup (e.g. VK_KHR_xlib_surface -> VK_KHR_win32_surface). It is
898 * up to us here to filter the list down to extensions for which we have thunks.
900 for (i = 0; i < num_host_properties; i++)
902 if (wine_vk_instance_extension_supported(host_properties[i].extensionName))
903 num_properties++;
904 else
905 TRACE("Instance extension '%s' is not supported.\n", host_properties[i].extensionName);
908 if (!properties)
910 TRACE("Returning %u extensions.\n", num_properties);
911 *count = num_properties;
912 heap_free(host_properties);
913 return VK_SUCCESS;
916 for (i = 0, j = 0; i < num_host_properties && j < *count; i++)
918 if (wine_vk_instance_extension_supported(host_properties[i].extensionName))
920 TRACE("Enabling extension '%s'.\n", host_properties[i].extensionName);
921 properties[j++] = host_properties[i];
924 *count = min(*count, num_properties);
926 heap_free(host_properties);
927 return *count < num_properties ? VK_INCOMPLETE : VK_SUCCESS;
930 VkResult WINAPI wine_vkEnumerateInstanceLayerProperties(uint32_t *count, VkLayerProperties *properties)
932 TRACE("%p, %p\n", count, properties);
934 if (!properties)
936 *count = 0;
937 return VK_SUCCESS;
940 return VK_ERROR_LAYER_NOT_PRESENT;
943 VkResult WINAPI wine_vkEnumerateInstanceVersion(uint32_t *version)
945 VkResult res;
947 TRACE("%p\n", version);
949 if (p_vkEnumerateInstanceVersion)
951 res = p_vkEnumerateInstanceVersion(version);
953 else
955 *version = VK_API_VERSION_1_0;
956 res = VK_SUCCESS;
959 TRACE("API version %u.%u.%u.\n",
960 VK_VERSION_MAJOR(*version), VK_VERSION_MINOR(*version), VK_VERSION_PATCH(*version));
961 *version = min(WINE_VK_VERSION, *version);
962 return res;
965 VkResult WINAPI wine_vkEnumeratePhysicalDevices(VkInstance instance, uint32_t *count,
966 VkPhysicalDevice *devices)
968 unsigned int i;
970 TRACE("%p %p %p\n", instance, count, devices);
972 if (!devices)
974 *count = instance->phys_dev_count;
975 return VK_SUCCESS;
978 *count = min(*count, instance->phys_dev_count);
979 for (i = 0; i < *count; i++)
981 devices[i] = instance->phys_devs[i];
984 TRACE("Returning %u devices.\n", *count);
985 return *count < instance->phys_dev_count ? VK_INCOMPLETE : VK_SUCCESS;
988 void WINAPI wine_vkFreeCommandBuffers(VkDevice device, VkCommandPool pool_handle,
989 uint32_t count, const VkCommandBuffer *buffers)
991 struct wine_cmd_pool *pool = wine_cmd_pool_from_handle(pool_handle);
993 TRACE("%p, 0x%s, %u, %p\n", device, wine_dbgstr_longlong(pool_handle), count, buffers);
995 wine_vk_free_command_buffers(device, pool, count, buffers);
998 PFN_vkVoidFunction WINAPI wine_vkGetDeviceProcAddr(VkDevice device, const char *name)
1000 void *func;
1001 TRACE("%p, %s\n", device, debugstr_a(name));
1003 /* The spec leaves return value undefined for a NULL device, let's just return NULL. */
1004 if (!device || !name)
1005 return NULL;
1007 /* Per the spec, we are only supposed to return device functions as in functions
1008 * for which the first parameter is vkDevice or a child of vkDevice like a
1009 * vkCommandBuffer or vkQueue.
1010 * Loader takes care of filtering of extensions which are enabled or not.
1012 func = wine_vk_get_device_proc_addr(name);
1013 if (func)
1014 return func;
1016 /* vkGetDeviceProcAddr was intended for loading device and subdevice functions.
1017 * idTech 6 titles such as Doom and Wolfenstein II, however use it also for
1018 * loading of instance functions. This is undefined behavior as the specification
1019 * disallows using any of the returned function pointers outside of device /
1020 * subdevice objects. The games don't actually use the function pointers and if they
1021 * did, they would crash as VkInstance / VkPhysicalDevice parameters need unwrapping.
1022 * Khronos clarified behavior in the Vulkan spec and expects drivers to get updated,
1023 * however it would require both driver and game fixes.
1024 * https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/issues/2323
1025 * https://github.com/KhronosGroup/Vulkan-Docs/issues/655
1027 if (device->quirks & WINEVULKAN_QUIRK_GET_DEVICE_PROC_ADDR
1028 && (func = wine_vk_get_instance_proc_addr(name)))
1030 WARN("Returning instance function %s.\n", debugstr_a(name));
1031 return func;
1034 WARN("Unsupported device function: %s.\n", debugstr_a(name));
1035 return NULL;
1038 void WINAPI wine_vkGetDeviceQueue(VkDevice device, uint32_t family_index,
1039 uint32_t queue_index, VkQueue *queue)
1041 TRACE("%p, %u, %u, %p\n", device, family_index, queue_index, queue);
1043 *queue = &device->queues[family_index][queue_index];
1046 void WINAPI wine_vkGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *info, VkQueue *queue)
1048 struct VkQueue_T *matching_queue;
1049 const VkBaseInStructure *chain;
1051 TRACE("%p, %p, %p\n", device, info, queue);
1053 if ((chain = info->pNext))
1054 FIXME("Ignoring a linked structure of type %u.\n", chain->sType);
1056 matching_queue = &device->queues[info->queueFamilyIndex][info->queueIndex];
1057 if (matching_queue->flags != info->flags)
1059 WARN("No matching flags were specified %#x, %#x.\n", matching_queue->flags, info->flags);
1060 matching_queue = VK_NULL_HANDLE;
1062 *queue = matching_queue;
1065 PFN_vkVoidFunction WINAPI wine_vkGetInstanceProcAddr(VkInstance instance, const char *name)
1067 void *func;
1069 TRACE("%p, %s\n", instance, debugstr_a(name));
1071 if (!name)
1072 return NULL;
1074 /* vkGetInstanceProcAddr can load most Vulkan functions when an instance is passed in, however
1075 * for a NULL instance it can only load global functions.
1077 func = wine_vk_get_global_proc_addr(name);
1078 if (func)
1080 return func;
1082 if (!instance)
1084 WARN("Global function %s not found.\n", debugstr_a(name));
1085 return NULL;
1088 func = wine_vk_get_instance_proc_addr(name);
1089 if (func) return func;
1091 /* vkGetInstanceProcAddr also loads any children of instance, so device functions as well. */
1092 func = wine_vk_get_device_proc_addr(name);
1093 if (func) return func;
1095 WARN("Unsupported device or instance function: %s.\n", debugstr_a(name));
1096 return NULL;
1099 void * WINAPI wine_vk_icdGetInstanceProcAddr(VkInstance instance, const char *name)
1101 TRACE("%p, %s\n", instance, debugstr_a(name));
1103 /* Initial version of the Vulkan ICD spec required vkGetInstanceProcAddr to be
1104 * exported. vk_icdGetInstanceProcAddr was added later to separate ICD calls from
1105 * Vulkan API. One of them in our case should forward to the other, so just forward
1106 * to the older vkGetInstanceProcAddr.
1108 return wine_vkGetInstanceProcAddr(instance, name);
1111 VkResult WINAPI wine_vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *supported_version)
1113 uint32_t req_version;
1115 TRACE("%p\n", supported_version);
1117 /* The spec is not clear how to handle this. Mesa drivers don't check, but it
1118 * is probably best to not explode. VK_INCOMPLETE seems to be the closest value.
1120 if (!supported_version)
1121 return VK_INCOMPLETE;
1123 req_version = *supported_version;
1124 *supported_version = min(req_version, WINE_VULKAN_ICD_VERSION);
1125 TRACE("Loader requested ICD version %u, returning %u\n", req_version, *supported_version);
1127 return VK_SUCCESS;
1130 VkResult WINAPI wine_vkQueueSubmit(VkQueue queue, uint32_t count,
1131 const VkSubmitInfo *submits, VkFence fence)
1133 VkSubmitInfo *submits_host;
1134 VkResult res;
1135 VkCommandBuffer *command_buffers;
1136 unsigned int i, j, num_command_buffers;
1138 TRACE("%p %u %p 0x%s\n", queue, count, submits, wine_dbgstr_longlong(fence));
1140 if (count == 0)
1142 return queue->device->funcs.p_vkQueueSubmit(queue->queue, 0, NULL, fence);
1145 submits_host = heap_calloc(count, sizeof(*submits_host));
1146 if (!submits_host)
1148 ERR("Unable to allocate memory for submit buffers!\n");
1149 return VK_ERROR_OUT_OF_HOST_MEMORY;
1152 for (i = 0; i < count; i++)
1154 memcpy(&submits_host[i], &submits[i], sizeof(*submits_host));
1156 num_command_buffers = submits[i].commandBufferCount;
1157 command_buffers = heap_calloc(num_command_buffers, sizeof(*submits_host));
1158 if (!command_buffers)
1160 ERR("Unable to allocate memory for comman buffers!\n");
1161 res = VK_ERROR_OUT_OF_HOST_MEMORY;
1162 goto done;
1165 for (j = 0; j < num_command_buffers; j++)
1167 command_buffers[j] = submits[i].pCommandBuffers[j]->command_buffer;
1169 submits_host[i].pCommandBuffers = command_buffers;
1172 res = queue->device->funcs.p_vkQueueSubmit(queue->queue, count, submits_host, fence);
1174 done:
1175 for (i = 0; i < count; i++)
1177 heap_free((void *)submits_host[i].pCommandBuffers);
1179 heap_free(submits_host);
1181 TRACE("Returning %d\n", res);
1182 return res;
1185 VkResult WINAPI wine_vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *info,
1186 const VkAllocationCallbacks *allocator, VkCommandPool *command_pool)
1188 struct wine_cmd_pool *object;
1189 VkResult res;
1191 TRACE("%p, %p, %p, %p\n", device, info, allocator, command_pool);
1193 if (allocator)
1194 FIXME("Support for allocation callbacks not implemented yet\n");
1196 if (!(object = heap_alloc_zero(sizeof(*object))))
1197 return VK_ERROR_OUT_OF_HOST_MEMORY;
1199 list_init(&object->command_buffers);
1201 res = device->funcs.p_vkCreateCommandPool(device->device, info, NULL, &object->command_pool);
1203 if (res == VK_SUCCESS)
1204 *command_pool = wine_cmd_pool_to_handle(object);
1205 else
1206 heap_free(object);
1208 return res;
1211 void WINAPI wine_vkDestroyCommandPool(VkDevice device, VkCommandPool handle,
1212 const VkAllocationCallbacks *allocator)
1214 struct wine_cmd_pool *pool = wine_cmd_pool_from_handle(handle);
1215 struct VkCommandBuffer_T *buffer, *cursor;
1217 TRACE("%p, 0x%s, %p\n", device, wine_dbgstr_longlong(handle), allocator);
1219 if (!handle)
1220 return;
1222 if (allocator)
1223 FIXME("Support for allocation callbacks not implemented yet\n");
1225 /* The Vulkan spec says:
1227 * "When a pool is destroyed, all command buffers allocated from the pool are freed."
1229 LIST_FOR_EACH_ENTRY_SAFE(buffer, cursor, &pool->command_buffers, struct VkCommandBuffer_T, pool_link)
1231 heap_free(buffer);
1234 device->funcs.p_vkDestroyCommandPool(device->device, pool->command_pool, NULL);
1235 heap_free(pool);
1238 static VkResult wine_vk_enumerate_physical_device_groups(struct VkInstance_T *instance,
1239 VkResult (*p_vkEnumeratePhysicalDeviceGroups)(VkInstance, uint32_t *, VkPhysicalDeviceGroupProperties *),
1240 uint32_t *count, VkPhysicalDeviceGroupProperties *properties)
1242 unsigned int i, j;
1243 VkResult res;
1245 res = p_vkEnumeratePhysicalDeviceGroups(instance->instance, count, properties);
1246 if (res < 0 || !properties)
1247 return res;
1249 for (i = 0; i < *count; ++i)
1251 VkPhysicalDeviceGroupProperties *current = &properties[i];
1252 for (j = 0; j < current->physicalDeviceCount; ++j)
1254 VkPhysicalDevice dev = current->physicalDevices[j];
1255 if (!(current->physicalDevices[j] = wine_vk_instance_wrap_physical_device(instance, dev)))
1256 return VK_ERROR_INITIALIZATION_FAILED;
1260 return res;
1263 VkResult WINAPI wine_vkEnumeratePhysicalDeviceGroups(VkInstance instance,
1264 uint32_t *count, VkPhysicalDeviceGroupProperties *properties)
1266 TRACE("%p, %p, %p\n", instance, count, properties);
1267 return wine_vk_enumerate_physical_device_groups(instance,
1268 instance->funcs.p_vkEnumeratePhysicalDeviceGroups, count, properties);
1271 VkResult WINAPI wine_vkEnumeratePhysicalDeviceGroupsKHR(VkInstance instance,
1272 uint32_t *count, VkPhysicalDeviceGroupProperties *properties)
1274 TRACE("%p, %p, %p\n", instance, count, properties);
1275 return wine_vk_enumerate_physical_device_groups(instance,
1276 instance->funcs.p_vkEnumeratePhysicalDeviceGroupsKHR, count, properties);
1279 void WINAPI wine_vkGetPhysicalDeviceExternalFenceProperties(VkPhysicalDevice phys_dev,
1280 const VkPhysicalDeviceExternalFenceInfo *fence_info, VkExternalFenceProperties *properties)
1282 TRACE("%p, %p, %p\n", phys_dev, fence_info, properties);
1283 properties->exportFromImportedHandleTypes = 0;
1284 properties->compatibleHandleTypes = 0;
1285 properties->externalFenceFeatures = 0;
1288 void WINAPI wine_vkGetPhysicalDeviceExternalFencePropertiesKHR(VkPhysicalDevice phys_dev,
1289 const VkPhysicalDeviceExternalFenceInfo *fence_info, VkExternalFenceProperties *properties)
1291 TRACE("%p, %p, %p\n", phys_dev, fence_info, properties);
1292 properties->exportFromImportedHandleTypes = 0;
1293 properties->compatibleHandleTypes = 0;
1294 properties->externalFenceFeatures = 0;
1297 void WINAPI wine_vkGetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice phys_dev,
1298 const VkPhysicalDeviceExternalBufferInfo *buffer_info, VkExternalBufferProperties *properties)
1300 TRACE("%p, %p, %p\n", phys_dev, buffer_info, properties);
1301 memset(&properties->externalMemoryProperties, 0, sizeof(properties->externalMemoryProperties));
1304 void WINAPI wine_vkGetPhysicalDeviceExternalBufferPropertiesKHR(VkPhysicalDevice phys_dev,
1305 const VkPhysicalDeviceExternalBufferInfo *buffer_info, VkExternalBufferProperties *properties)
1307 TRACE("%p, %p, %p\n", phys_dev, buffer_info, properties);
1308 memset(&properties->externalMemoryProperties, 0, sizeof(properties->externalMemoryProperties));
1311 VkResult WINAPI wine_vkGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice phys_dev,
1312 const VkPhysicalDeviceImageFormatInfo2 *format_info, VkImageFormatProperties2 *properties)
1314 VkExternalImageFormatProperties *external_image_properties;
1315 VkResult res;
1317 TRACE("%p, %p, %p\n", phys_dev, format_info, properties);
1319 res = thunk_vkGetPhysicalDeviceImageFormatProperties2(phys_dev, format_info, properties);
1321 if ((external_image_properties = wine_vk_find_struct(properties, EXTERNAL_IMAGE_FORMAT_PROPERTIES)))
1323 VkExternalMemoryProperties *p = &external_image_properties->externalMemoryProperties;
1324 p->externalMemoryFeatures = 0;
1325 p->exportFromImportedHandleTypes = 0;
1326 p->compatibleHandleTypes = 0;
1329 return res;
1332 VkResult WINAPI wine_vkGetPhysicalDeviceImageFormatProperties2KHR(VkPhysicalDevice phys_dev,
1333 const VkPhysicalDeviceImageFormatInfo2 *format_info, VkImageFormatProperties2 *properties)
1335 VkExternalImageFormatProperties *external_image_properties;
1336 VkResult res;
1338 TRACE("%p, %p, %p\n", phys_dev, format_info, properties);
1340 res = thunk_vkGetPhysicalDeviceImageFormatProperties2KHR(phys_dev, format_info, properties);
1342 if ((external_image_properties = wine_vk_find_struct(properties, EXTERNAL_IMAGE_FORMAT_PROPERTIES)))
1344 VkExternalMemoryProperties *p = &external_image_properties->externalMemoryProperties;
1345 p->externalMemoryFeatures = 0;
1346 p->exportFromImportedHandleTypes = 0;
1347 p->compatibleHandleTypes = 0;
1350 return res;
1353 void WINAPI wine_vkGetPhysicalDeviceExternalSemaphoreProperties(VkPhysicalDevice phys_dev,
1354 const VkPhysicalDeviceExternalSemaphoreInfo *semaphore_info, VkExternalSemaphoreProperties *properties)
1356 TRACE("%p, %p, %p\n", phys_dev, semaphore_info, properties);
1357 properties->exportFromImportedHandleTypes = 0;
1358 properties->compatibleHandleTypes = 0;
1359 properties->externalSemaphoreFeatures = 0;
1362 void WINAPI wine_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(VkPhysicalDevice phys_dev,
1363 const VkPhysicalDeviceExternalSemaphoreInfo *semaphore_info, VkExternalSemaphoreProperties *properties)
1365 TRACE("%p, %p, %p\n", phys_dev, semaphore_info, properties);
1366 properties->exportFromImportedHandleTypes = 0;
1367 properties->compatibleHandleTypes = 0;
1368 properties->externalSemaphoreFeatures = 0;
1371 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *reserved)
1373 TRACE("%p, %u, %p\n", hinst, reason, reserved);
1375 switch (reason)
1377 case DLL_PROCESS_ATTACH:
1378 DisableThreadLibraryCalls(hinst);
1379 return wine_vk_init();
1381 return TRUE;
1384 static const struct vulkan_func vk_global_dispatch_table[] =
1386 {"vkCreateInstance", &wine_vkCreateInstance},
1387 {"vkEnumerateInstanceExtensionProperties", &wine_vkEnumerateInstanceExtensionProperties},
1388 {"vkEnumerateInstanceLayerProperties", &wine_vkEnumerateInstanceLayerProperties},
1389 {"vkEnumerateInstanceVersion", &wine_vkEnumerateInstanceVersion},
1390 {"vkGetInstanceProcAddr", &wine_vkGetInstanceProcAddr},
1393 static void *wine_vk_get_global_proc_addr(const char *name)
1395 unsigned int i;
1397 for (i = 0; i < ARRAY_SIZE(vk_global_dispatch_table); i++)
1399 if (strcmp(name, vk_global_dispatch_table[i].name) == 0)
1401 TRACE("Found name=%s in global table\n", debugstr_a(name));
1402 return vk_global_dispatch_table[i].func;
1405 return NULL;
1409 * Wrapper around driver vkGetInstanceProcAddr implementation.
1410 * Allows winelib applications to access Vulkan functions with Wine
1411 * additions and native ABI.
1413 void *native_vkGetInstanceProcAddrWINE(VkInstance instance, const char *name)
1415 return vk_funcs->p_vkGetInstanceProcAddr(instance, name);