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
32 #include "vulkan_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(vulkan
);
36 DEFINE_DEVPROPKEY(DEVPROPKEY_GPU_LUID
, 0x60b193cb, 0x5276, 0x4d0f, 0x96, 0xfc, 0xf1, 0x73, 0xab, 0xad, 0x3e, 0xc6, 2);
37 DEFINE_DEVPROPKEY(WINE_DEVPROPKEY_GPU_VULKAN_UUID
, 0x233a9ef3, 0xafc4, 0x4abd, 0xb5, 0x64, 0xc3, 0x2f, 0x21, 0xf1, 0x53, 0x5c, 2);
39 /* For now default to 4 as it felt like a reasonable version feature wise to support.
40 * Don't support the optional vk_icdGetPhysicalDeviceProcAddr introduced in this version
41 * as it is unlikely we will implement physical device extensions, which the loader is not
42 * aware of. Version 5 adds more extensive version checks. Something to tackle later.
44 #define WINE_VULKAN_ICD_VERSION 4
46 #define wine_vk_find_struct(s, t) wine_vk_find_struct_((void *)s, VK_STRUCTURE_TYPE_##t)
47 static void *wine_vk_find_struct_(void *s
, VkStructureType t
)
49 VkBaseOutStructure
*header
;
51 for (header
= s
; header
; header
= header
->pNext
)
53 if (header
->sType
== t
)
60 #define wine_vk_count_struct(s, t) wine_vk_count_struct_((void *)s, VK_STRUCTURE_TYPE_##t)
61 static uint32_t wine_vk_count_struct_(void *s
, VkStructureType t
)
63 const VkBaseInStructure
*header
;
66 for (header
= s
; header
; header
= header
->pNext
)
68 if (header
->sType
== t
)
75 static void *wine_vk_get_global_proc_addr(const char *name
);
77 static HINSTANCE hinstance
;
78 static const struct vulkan_funcs
*vk_funcs
;
79 static VkResult (*p_vkEnumerateInstanceVersion
)(uint32_t *version
);
81 void WINAPI
wine_vkGetPhysicalDeviceProperties(VkPhysicalDevice physical_device
,
82 VkPhysicalDeviceProperties
*properties
);
84 #define WINE_VK_ADD_DISPATCHABLE_MAPPING(instance, object, native_handle) \
85 wine_vk_add_handle_mapping((instance), (uint64_t) (uintptr_t) (object), (uint64_t) (uintptr_t) (native_handle), &(object)->mapping)
86 #define WINE_VK_ADD_NON_DISPATCHABLE_MAPPING(instance, object, native_handle) \
87 wine_vk_add_handle_mapping((instance), (uint64_t) (uintptr_t) (object), (uint64_t) (native_handle), &(object)->mapping)
88 static void wine_vk_add_handle_mapping(struct VkInstance_T
*instance
, uint64_t wrapped_handle
,
89 uint64_t native_handle
, struct wine_vk_mapping
*mapping
)
91 if (instance
->enable_wrapper_list
)
93 mapping
->native_handle
= native_handle
;
94 mapping
->wine_wrapped_handle
= wrapped_handle
;
95 AcquireSRWLockExclusive(&instance
->wrapper_lock
);
96 list_add_tail(&instance
->wrappers
, &mapping
->link
);
97 ReleaseSRWLockExclusive(&instance
->wrapper_lock
);
101 #define WINE_VK_REMOVE_HANDLE_MAPPING(instance, object) \
102 wine_vk_remove_handle_mapping((instance), &(object)->mapping)
103 static void wine_vk_remove_handle_mapping(struct VkInstance_T
*instance
, struct wine_vk_mapping
*mapping
)
105 if (instance
->enable_wrapper_list
)
107 AcquireSRWLockExclusive(&instance
->wrapper_lock
);
108 list_remove(&mapping
->link
);
109 ReleaseSRWLockExclusive(&instance
->wrapper_lock
);
113 static uint64_t wine_vk_get_wrapper(struct VkInstance_T
*instance
, uint64_t native_handle
)
115 struct wine_vk_mapping
*mapping
;
118 AcquireSRWLockShared(&instance
->wrapper_lock
);
119 LIST_FOR_EACH_ENTRY(mapping
, &instance
->wrappers
, struct wine_vk_mapping
, link
)
121 if (mapping
->native_handle
== native_handle
)
123 result
= mapping
->wine_wrapped_handle
;
127 ReleaseSRWLockShared(&instance
->wrapper_lock
);
131 static VkBool32
debug_utils_callback_conversion(VkDebugUtilsMessageSeverityFlagBitsEXT severity
,
132 VkDebugUtilsMessageTypeFlagsEXT message_types
,
133 #if defined(USE_STRUCT_CONVERSION)
134 const VkDebugUtilsMessengerCallbackDataEXT_host
*callback_data
,
136 const VkDebugUtilsMessengerCallbackDataEXT
*callback_data
,
140 struct VkDebugUtilsMessengerCallbackDataEXT wine_callback_data
;
141 VkDebugUtilsObjectNameInfoEXT
*object_name_infos
;
142 struct wine_debug_utils_messenger
*object
;
146 TRACE("%i, %u, %p, %p\n", severity
, message_types
, callback_data
, user_data
);
150 if (!object
->instance
->instance
)
152 /* instance wasn't yet created, this is a message from the native loader */
156 wine_callback_data
= *((VkDebugUtilsMessengerCallbackDataEXT
*) callback_data
);
158 object_name_infos
= heap_calloc(wine_callback_data
.objectCount
, sizeof(*object_name_infos
));
160 for (i
= 0; i
< wine_callback_data
.objectCount
; i
++)
162 object_name_infos
[i
].sType
= callback_data
->pObjects
[i
].sType
;
163 object_name_infos
[i
].pNext
= callback_data
->pObjects
[i
].pNext
;
164 object_name_infos
[i
].objectType
= callback_data
->pObjects
[i
].objectType
;
165 object_name_infos
[i
].pObjectName
= callback_data
->pObjects
[i
].pObjectName
;
167 if (wine_vk_is_type_wrapped(callback_data
->pObjects
[i
].objectType
))
169 object_name_infos
[i
].objectHandle
= wine_vk_get_wrapper(object
->instance
, callback_data
->pObjects
[i
].objectHandle
);
170 if (!object_name_infos
[i
].objectHandle
)
172 WARN("handle conversion failed 0x%s\n", wine_dbgstr_longlong(callback_data
->pObjects
[i
].objectHandle
));
173 heap_free(object_name_infos
);
179 object_name_infos
[i
].objectHandle
= callback_data
->pObjects
[i
].objectHandle
;
183 wine_callback_data
.pObjects
= object_name_infos
;
185 /* applications should always return VK_FALSE */
186 result
= object
->user_callback(severity
, message_types
, &wine_callback_data
, object
->user_data
);
188 heap_free(object_name_infos
);
193 static void wine_vk_physical_device_free(struct VkPhysicalDevice_T
*phys_dev
)
198 WINE_VK_REMOVE_HANDLE_MAPPING(phys_dev
->instance
, phys_dev
);
199 heap_free(phys_dev
->extensions
);
203 static struct VkPhysicalDevice_T
*wine_vk_physical_device_alloc(struct VkInstance_T
*instance
,
204 VkPhysicalDevice phys_dev
)
206 struct VkPhysicalDevice_T
*object
;
207 uint32_t num_host_properties
, num_properties
= 0;
208 VkExtensionProperties
*host_properties
= NULL
;
212 if (!(object
= heap_alloc_zero(sizeof(*object
))))
215 object
->base
.loader_magic
= VULKAN_ICD_MAGIC_VALUE
;
216 object
->instance
= instance
;
217 object
->phys_dev
= phys_dev
;
219 WINE_VK_ADD_DISPATCHABLE_MAPPING(instance
, object
, phys_dev
);
221 res
= instance
->funcs
.p_vkEnumerateDeviceExtensionProperties(phys_dev
,
222 NULL
, &num_host_properties
, NULL
);
223 if (res
!= VK_SUCCESS
)
225 ERR("Failed to enumerate device extensions, res=%d\n", res
);
229 host_properties
= heap_calloc(num_host_properties
, sizeof(*host_properties
));
230 if (!host_properties
)
232 ERR("Failed to allocate memory for device properties!\n");
236 res
= instance
->funcs
.p_vkEnumerateDeviceExtensionProperties(phys_dev
,
237 NULL
, &num_host_properties
, host_properties
);
238 if (res
!= VK_SUCCESS
)
240 ERR("Failed to enumerate device extensions, res=%d\n", res
);
244 /* Count list of extensions for which we have an implementation.
245 * TODO: perform translation for platform specific extensions.
247 for (i
= 0; i
< num_host_properties
; i
++)
249 if (wine_vk_device_extension_supported(host_properties
[i
].extensionName
))
251 TRACE("Enabling extension '%s' for physical device %p\n", host_properties
[i
].extensionName
, object
);
256 TRACE("Skipping extension '%s', no implementation found in winevulkan.\n", host_properties
[i
].extensionName
);
260 TRACE("Host supported extensions %u, Wine supported extensions %u\n", num_host_properties
, num_properties
);
262 if (!(object
->extensions
= heap_calloc(num_properties
, sizeof(*object
->extensions
))))
264 ERR("Failed to allocate memory for device extensions!\n");
268 for (i
= 0, j
= 0; i
< num_host_properties
; i
++)
270 if (wine_vk_device_extension_supported(host_properties
[i
].extensionName
))
272 object
->extensions
[j
] = host_properties
[i
];
276 object
->extension_count
= num_properties
;
278 heap_free(host_properties
);
282 wine_vk_physical_device_free(object
);
283 heap_free(host_properties
);
287 static void wine_vk_free_command_buffers(struct VkDevice_T
*device
,
288 struct wine_cmd_pool
*pool
, uint32_t count
, const VkCommandBuffer
*buffers
)
292 for (i
= 0; i
< count
; i
++)
297 device
->funcs
.p_vkFreeCommandBuffers(device
->device
, pool
->command_pool
, 1, &buffers
[i
]->command_buffer
);
298 list_remove(&buffers
[i
]->pool_link
);
299 WINE_VK_REMOVE_HANDLE_MAPPING(device
->phys_dev
->instance
, buffers
[i
]);
300 heap_free(buffers
[i
]);
304 static struct VkQueue_T
*wine_vk_device_alloc_queues(struct VkDevice_T
*device
,
305 uint32_t family_index
, uint32_t queue_count
, VkDeviceQueueCreateFlags flags
)
307 VkDeviceQueueInfo2 queue_info
;
308 struct VkQueue_T
*queues
;
311 if (!(queues
= heap_calloc(queue_count
, sizeof(*queues
))))
313 ERR("Failed to allocate memory for queues\n");
317 for (i
= 0; i
< queue_count
; i
++)
319 struct VkQueue_T
*queue
= &queues
[i
];
321 queue
->base
.loader_magic
= VULKAN_ICD_MAGIC_VALUE
;
322 queue
->device
= device
;
323 queue
->flags
= flags
;
325 /* The Vulkan spec says:
327 * "vkGetDeviceQueue must only be used to get queues that were created
328 * with the flags parameter of VkDeviceQueueCreateInfo set to zero."
330 if (flags
&& device
->funcs
.p_vkGetDeviceQueue2
)
332 queue_info
.sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
;
333 queue_info
.pNext
= NULL
;
334 queue_info
.flags
= flags
;
335 queue_info
.queueFamilyIndex
= family_index
;
336 queue_info
.queueIndex
= i
;
337 device
->funcs
.p_vkGetDeviceQueue2(device
->device
, &queue_info
, &queue
->queue
);
341 device
->funcs
.p_vkGetDeviceQueue(device
->device
, family_index
, i
, &queue
->queue
);
344 WINE_VK_ADD_DISPATCHABLE_MAPPING(device
->phys_dev
->instance
, queue
, queue
->queue
);
350 static void wine_vk_device_free_create_info(VkDeviceCreateInfo
*create_info
)
352 VkDeviceGroupDeviceCreateInfo
*group_info
;
354 if ((group_info
= wine_vk_find_struct(create_info
, DEVICE_GROUP_DEVICE_CREATE_INFO
)))
356 heap_free((void *)group_info
->pPhysicalDevices
);
359 free_VkDeviceCreateInfo_struct_chain(create_info
);
362 static VkResult
wine_vk_device_convert_create_info(const VkDeviceCreateInfo
*src
,
363 VkDeviceCreateInfo
*dst
)
365 VkDeviceGroupDeviceCreateInfo
*group_info
;
371 if ((res
= convert_VkDeviceCreateInfo_struct_chain(src
->pNext
, dst
)) < 0)
373 WARN("Failed to convert VkDeviceCreateInfo pNext chain, res=%d.\n", res
);
377 /* FIXME: convert_VkDeviceCreateInfo_struct_chain() should unwrap handles for us. */
378 if ((group_info
= wine_vk_find_struct(dst
, DEVICE_GROUP_DEVICE_CREATE_INFO
)))
380 VkPhysicalDevice
*physical_devices
;
382 if (!(physical_devices
= heap_calloc(group_info
->physicalDeviceCount
, sizeof(*physical_devices
))))
384 free_VkDeviceCreateInfo_struct_chain(dst
);
385 return VK_ERROR_OUT_OF_HOST_MEMORY
;
387 for (i
= 0; i
< group_info
->physicalDeviceCount
; ++i
)
389 physical_devices
[i
] = group_info
->pPhysicalDevices
[i
]->phys_dev
;
391 group_info
->pPhysicalDevices
= physical_devices
;
394 /* Should be filtered out by loader as ICDs don't support layers. */
395 dst
->enabledLayerCount
= 0;
396 dst
->ppEnabledLayerNames
= NULL
;
398 TRACE("Enabled %u extensions.\n", dst
->enabledExtensionCount
);
399 for (i
= 0; i
< dst
->enabledExtensionCount
; i
++)
401 const char *extension_name
= dst
->ppEnabledExtensionNames
[i
];
402 TRACE("Extension %u: %s.\n", i
, debugstr_a(extension_name
));
403 if (!wine_vk_device_extension_supported(extension_name
))
405 WARN("Extension %s is not supported.\n", debugstr_a(extension_name
));
406 wine_vk_device_free_create_info(dst
);
407 return VK_ERROR_EXTENSION_NOT_PRESENT
;
414 /* Helper function used for freeing a device structure. This function supports full
415 * and partial object cleanups and can thus be used for vkCreateDevice failures.
417 static void wine_vk_device_free(struct VkDevice_T
*device
)
425 for (i
= 0; i
< device
->max_queue_families
; i
++)
427 if (device
->queues
[i
] && device
->queues
[i
]->queue
)
428 WINE_VK_REMOVE_HANDLE_MAPPING(device
->phys_dev
->instance
, device
->queues
[i
]);
429 heap_free(device
->queues
[i
]);
431 heap_free(device
->queues
);
432 device
->queues
= NULL
;
435 if (device
->device
&& device
->funcs
.p_vkDestroyDevice
)
437 WINE_VK_REMOVE_HANDLE_MAPPING(device
->phys_dev
->instance
, device
);
438 device
->funcs
.p_vkDestroyDevice(device
->device
, NULL
/* pAllocator */);
444 static BOOL WINAPI
wine_vk_init(INIT_ONCE
*once
, void *param
, void **context
)
449 vk_funcs
= __wine_get_vulkan_driver(hdc
, WINE_VULKAN_DRIVER_VERSION
);
452 ERR("Failed to load Wine graphics driver supporting Vulkan.\n");
454 p_vkEnumerateInstanceVersion
= vk_funcs
->p_vkGetInstanceProcAddr(NULL
, "vkEnumerateInstanceVersion");
459 static void wine_vk_init_once(void)
461 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
463 InitOnceExecuteOnce(&init_once
, wine_vk_init
, NULL
, NULL
);
466 /* Helper function for converting between win32 and host compatible VkInstanceCreateInfo.
467 * This function takes care of extensions handled at winevulkan layer, a Wine graphics
468 * driver is responsible for handling e.g. surface extensions.
470 static VkResult
wine_vk_instance_convert_create_info(const VkInstanceCreateInfo
*src
,
471 VkInstanceCreateInfo
*dst
, struct VkInstance_T
*object
)
473 VkDebugUtilsMessengerCreateInfoEXT
*debug_utils_messenger
;
474 VkBaseInStructure
*header
;
480 if ((res
= convert_VkInstanceCreateInfo_struct_chain(src
->pNext
, dst
)) < 0)
482 WARN("Failed to convert VkInstanceCreateInfo pNext chain, res=%d.\n", res
);
486 object
->utils_messenger_count
= wine_vk_count_struct(dst
, DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT
);
487 object
->utils_messengers
= heap_calloc(object
->utils_messenger_count
, sizeof(*object
->utils_messengers
));
488 header
= (VkBaseInStructure
*) dst
;
489 for (i
= 0; i
< object
->utils_messenger_count
; i
++)
491 header
= wine_vk_find_struct(header
->pNext
, DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT
);
492 debug_utils_messenger
= (VkDebugUtilsMessengerCreateInfoEXT
*) header
;
494 object
->utils_messengers
[i
].instance
= object
;
495 object
->utils_messengers
[i
].debug_messenger
= VK_NULL_HANDLE
;
496 object
->utils_messengers
[i
].user_callback
= debug_utils_messenger
->pfnUserCallback
;
497 object
->utils_messengers
[i
].user_data
= debug_utils_messenger
->pUserData
;
499 /* convert_VkInstanceCreateInfo_struct_chain already copied the chain,
500 * so we can modify it in-place.
502 debug_utils_messenger
->pfnUserCallback
= (void *) &debug_utils_callback_conversion
;
503 debug_utils_messenger
->pUserData
= &object
->utils_messengers
[i
];
506 /* ICDs don't support any layers, so nothing to copy. Modern versions of the loader
507 * filter this data out as well.
509 if (object
->quirks
& WINEVULKAN_QUIRK_IGNORE_EXPLICIT_LAYERS
) {
510 dst
->enabledLayerCount
= 0;
511 dst
->ppEnabledLayerNames
= NULL
;
512 WARN("Ignoring explicit layers!\n");
513 } else if (dst
->enabledLayerCount
) {
514 FIXME("Loading explicit layers is not supported by winevulkan!\n");
515 return VK_ERROR_LAYER_NOT_PRESENT
;
518 TRACE("Enabled %u instance extensions.\n", dst
->enabledExtensionCount
);
519 for (i
= 0; i
< dst
->enabledExtensionCount
; i
++)
521 const char *extension_name
= dst
->ppEnabledExtensionNames
[i
];
522 TRACE("Extension %u: %s.\n", i
, debugstr_a(extension_name
));
523 if (!wine_vk_instance_extension_supported(extension_name
))
525 WARN("Extension %s is not supported.\n", debugstr_a(extension_name
));
526 free_VkInstanceCreateInfo_struct_chain(dst
);
527 return VK_ERROR_EXTENSION_NOT_PRESENT
;
529 if (!strcmp(extension_name
, "VK_EXT_debug_utils"))
531 object
->enable_wrapper_list
= VK_TRUE
;
538 /* Helper function which stores wrapped physical devices in the instance object. */
539 static VkResult
wine_vk_instance_load_physical_devices(struct VkInstance_T
*instance
)
541 VkPhysicalDevice
*tmp_phys_devs
;
542 uint32_t phys_dev_count
;
546 res
= instance
->funcs
.p_vkEnumeratePhysicalDevices(instance
->instance
, &phys_dev_count
, NULL
);
547 if (res
!= VK_SUCCESS
)
549 ERR("Failed to enumerate physical devices, res=%d\n", res
);
555 if (!(tmp_phys_devs
= heap_calloc(phys_dev_count
, sizeof(*tmp_phys_devs
))))
556 return VK_ERROR_OUT_OF_HOST_MEMORY
;
558 res
= instance
->funcs
.p_vkEnumeratePhysicalDevices(instance
->instance
, &phys_dev_count
, tmp_phys_devs
);
559 if (res
!= VK_SUCCESS
)
561 heap_free(tmp_phys_devs
);
565 instance
->phys_devs
= heap_calloc(phys_dev_count
, sizeof(*instance
->phys_devs
));
566 if (!instance
->phys_devs
)
568 heap_free(tmp_phys_devs
);
569 return VK_ERROR_OUT_OF_HOST_MEMORY
;
572 /* Wrap each native physical device handle into a dispatchable object for the ICD loader. */
573 for (i
= 0; i
< phys_dev_count
; i
++)
575 struct VkPhysicalDevice_T
*phys_dev
= wine_vk_physical_device_alloc(instance
, tmp_phys_devs
[i
]);
578 ERR("Unable to allocate memory for physical device!\n");
579 heap_free(tmp_phys_devs
);
580 return VK_ERROR_OUT_OF_HOST_MEMORY
;
583 instance
->phys_devs
[i
] = phys_dev
;
584 instance
->phys_dev_count
= i
+ 1;
586 instance
->phys_dev_count
= phys_dev_count
;
588 heap_free(tmp_phys_devs
);
592 static struct VkPhysicalDevice_T
*wine_vk_instance_wrap_physical_device(struct VkInstance_T
*instance
,
593 VkPhysicalDevice physical_device
)
597 for (i
= 0; i
< instance
->phys_dev_count
; ++i
)
599 struct VkPhysicalDevice_T
*current
= instance
->phys_devs
[i
];
600 if (current
->phys_dev
== physical_device
)
604 ERR("Unrecognized physical device %p.\n", physical_device
);
608 /* Helper function used for freeing an instance structure. This function supports full
609 * and partial object cleanups and can thus be used for vkCreateInstance failures.
611 static void wine_vk_instance_free(struct VkInstance_T
*instance
)
616 if (instance
->phys_devs
)
620 for (i
= 0; i
< instance
->phys_dev_count
; i
++)
622 wine_vk_physical_device_free(instance
->phys_devs
[i
]);
624 heap_free(instance
->phys_devs
);
627 if (instance
->instance
)
629 vk_funcs
->p_vkDestroyInstance(instance
->instance
, NULL
/* allocator */);
630 WINE_VK_REMOVE_HANDLE_MAPPING(instance
, instance
);
633 heap_free(instance
->utils_messengers
);
638 VkResult WINAPI
wine_vkAllocateCommandBuffers(VkDevice device
,
639 const VkCommandBufferAllocateInfo
*allocate_info
, VkCommandBuffer
*buffers
)
641 struct wine_cmd_pool
*pool
;
642 VkResult res
= VK_SUCCESS
;
645 TRACE("%p, %p, %p\n", device
, allocate_info
, buffers
);
647 pool
= wine_cmd_pool_from_handle(allocate_info
->commandPool
);
649 memset(buffers
, 0, allocate_info
->commandBufferCount
* sizeof(*buffers
));
651 for (i
= 0; i
< allocate_info
->commandBufferCount
; i
++)
653 #if defined(USE_STRUCT_CONVERSION)
654 VkCommandBufferAllocateInfo_host allocate_info_host
;
656 VkCommandBufferAllocateInfo allocate_info_host
;
658 /* TODO: future extensions (none yet) may require pNext conversion. */
659 allocate_info_host
.pNext
= allocate_info
->pNext
;
660 allocate_info_host
.sType
= allocate_info
->sType
;
661 allocate_info_host
.commandPool
= pool
->command_pool
;
662 allocate_info_host
.level
= allocate_info
->level
;
663 allocate_info_host
.commandBufferCount
= 1;
665 TRACE("Allocating command buffer %u from pool 0x%s.\n",
666 i
, wine_dbgstr_longlong(allocate_info_host
.commandPool
));
668 if (!(buffers
[i
] = heap_alloc_zero(sizeof(**buffers
))))
670 res
= VK_ERROR_OUT_OF_HOST_MEMORY
;
674 buffers
[i
]->base
.loader_magic
= VULKAN_ICD_MAGIC_VALUE
;
675 buffers
[i
]->device
= device
;
676 list_add_tail(&pool
->command_buffers
, &buffers
[i
]->pool_link
);
677 res
= device
->funcs
.p_vkAllocateCommandBuffers(device
->device
,
678 &allocate_info_host
, &buffers
[i
]->command_buffer
);
679 WINE_VK_ADD_DISPATCHABLE_MAPPING(device
->phys_dev
->instance
, buffers
[i
], buffers
[i
]->command_buffer
);
680 if (res
!= VK_SUCCESS
)
682 ERR("Failed to allocate command buffer, res=%d.\n", res
);
683 buffers
[i
]->command_buffer
= VK_NULL_HANDLE
;
688 if (res
!= VK_SUCCESS
)
690 wine_vk_free_command_buffers(device
, pool
, i
+ 1, buffers
);
691 memset(buffers
, 0, allocate_info
->commandBufferCount
* sizeof(*buffers
));
697 void WINAPI
wine_vkCmdExecuteCommands(VkCommandBuffer buffer
, uint32_t count
,
698 const VkCommandBuffer
*buffers
)
700 VkCommandBuffer
*tmp_buffers
;
703 TRACE("%p %u %p\n", buffer
, count
, buffers
);
705 if (!buffers
|| !count
)
708 /* Unfortunately we need a temporary buffer as our command buffers are wrapped.
709 * This call is called often and if a performance concern, we may want to use
710 * alloca as we shouldn't need much memory and it needs to be cleaned up after
713 if (!(tmp_buffers
= heap_alloc(count
* sizeof(*tmp_buffers
))))
715 ERR("Failed to allocate memory for temporary command buffers\n");
719 for (i
= 0; i
< count
; i
++)
720 tmp_buffers
[i
] = buffers
[i
]->command_buffer
;
722 buffer
->device
->funcs
.p_vkCmdExecuteCommands(buffer
->command_buffer
, count
, tmp_buffers
);
724 heap_free(tmp_buffers
);
727 VkResult WINAPI
wine_vkCreateDevice(VkPhysicalDevice phys_dev
,
728 const VkDeviceCreateInfo
*create_info
,
729 const VkAllocationCallbacks
*allocator
, VkDevice
*device
)
731 VkDeviceCreateInfo create_info_host
;
732 uint32_t max_queue_families
;
733 struct VkDevice_T
*object
;
737 TRACE("%p, %p, %p, %p\n", phys_dev
, create_info
, allocator
, device
);
740 FIXME("Support for allocation callbacks not implemented yet\n");
742 if (TRACE_ON(vulkan
))
744 VkPhysicalDeviceProperties properties
;
746 wine_vkGetPhysicalDeviceProperties(phys_dev
, &properties
);
748 TRACE("Device name: %s.\n", debugstr_a(properties
.deviceName
));
749 TRACE("Vendor ID: %#x, Device ID: %#x.\n", properties
.vendorID
, properties
.deviceID
);
750 TRACE("Driver version: %#x.\n", properties
.driverVersion
);
753 if (!(object
= heap_alloc_zero(sizeof(*object
))))
754 return VK_ERROR_OUT_OF_HOST_MEMORY
;
756 object
->base
.loader_magic
= VULKAN_ICD_MAGIC_VALUE
;
757 object
->phys_dev
= phys_dev
;
759 res
= wine_vk_device_convert_create_info(create_info
, &create_info_host
);
760 if (res
!= VK_SUCCESS
)
763 res
= phys_dev
->instance
->funcs
.p_vkCreateDevice(phys_dev
->phys_dev
,
764 &create_info_host
, NULL
/* allocator */, &object
->device
);
765 wine_vk_device_free_create_info(&create_info_host
);
766 WINE_VK_ADD_DISPATCHABLE_MAPPING(phys_dev
->instance
, object
, object
->device
);
767 if (res
!= VK_SUCCESS
)
769 WARN("Failed to create device, res=%d.\n", res
);
773 /* Just load all function pointers we are aware off. The loader takes care of filtering.
774 * We use vkGetDeviceProcAddr as opposed to vkGetInstanceProcAddr for efficiency reasons
775 * as functions pass through fewer dispatch tables within the loader.
777 #define USE_VK_FUNC(name) \
778 object->funcs.p_##name = (void *)vk_funcs->p_vkGetDeviceProcAddr(object->device, #name); \
779 if (object->funcs.p_##name == NULL) \
780 TRACE("Not found '%s'.\n", #name);
781 ALL_VK_DEVICE_FUNCS()
784 /* We need to cache all queues within the device as each requires wrapping since queues are
785 * dispatchable objects.
787 phys_dev
->instance
->funcs
.p_vkGetPhysicalDeviceQueueFamilyProperties(phys_dev
->phys_dev
,
788 &max_queue_families
, NULL
);
789 object
->max_queue_families
= max_queue_families
;
790 TRACE("Max queue families: %u.\n", object
->max_queue_families
);
792 if (!(object
->queues
= heap_calloc(max_queue_families
, sizeof(*object
->queues
))))
794 res
= VK_ERROR_OUT_OF_HOST_MEMORY
;
798 for (i
= 0; i
< create_info_host
.queueCreateInfoCount
; i
++)
800 uint32_t flags
= create_info_host
.pQueueCreateInfos
[i
].flags
;
801 uint32_t family_index
= create_info_host
.pQueueCreateInfos
[i
].queueFamilyIndex
;
802 uint32_t queue_count
= create_info_host
.pQueueCreateInfos
[i
].queueCount
;
804 TRACE("Queue family index %u, queue count %u.\n", family_index
, queue_count
);
806 if (!(object
->queues
[family_index
] = wine_vk_device_alloc_queues(object
, family_index
, queue_count
, flags
)))
808 ERR("Failed to allocate memory for queues.\n");
809 res
= VK_ERROR_OUT_OF_HOST_MEMORY
;
814 object
->quirks
= phys_dev
->instance
->quirks
;
817 TRACE("Created device %p (native device %p).\n", object
, object
->device
);
821 wine_vk_device_free(object
);
825 VkResult WINAPI
wine_vkCreateInstance(const VkInstanceCreateInfo
*create_info
,
826 const VkAllocationCallbacks
*allocator
, VkInstance
*instance
)
828 VkInstanceCreateInfo create_info_host
;
829 const VkApplicationInfo
*app_info
;
830 struct VkInstance_T
*object
;
833 TRACE("create_info %p, allocator %p, instance %p\n", create_info
, allocator
, instance
);
837 return VK_ERROR_INITIALIZATION_FAILED
;
840 FIXME("Support for allocation callbacks not implemented yet\n");
842 if (!(object
= heap_alloc_zero(sizeof(*object
))))
844 ERR("Failed to allocate memory for instance\n");
845 return VK_ERROR_OUT_OF_HOST_MEMORY
;
847 object
->base
.loader_magic
= VULKAN_ICD_MAGIC_VALUE
;
848 list_init(&object
->wrappers
);
849 InitializeSRWLock(&object
->wrapper_lock
);
851 res
= wine_vk_instance_convert_create_info(create_info
, &create_info_host
, object
);
852 if (res
!= VK_SUCCESS
)
854 wine_vk_instance_free(object
);
858 res
= vk_funcs
->p_vkCreateInstance(&create_info_host
, NULL
/* allocator */, &object
->instance
);
859 free_VkInstanceCreateInfo_struct_chain(&create_info_host
);
860 if (res
!= VK_SUCCESS
)
862 ERR("Failed to create instance, res=%d\n", res
);
863 wine_vk_instance_free(object
);
867 WINE_VK_ADD_DISPATCHABLE_MAPPING(object
, object
, object
->instance
);
869 /* Load all instance functions we are aware of. Note the loader takes care
870 * of any filtering for extensions which were not requested, but which the
873 #define USE_VK_FUNC(name) \
874 object->funcs.p_##name = (void *)vk_funcs->p_vkGetInstanceProcAddr(object->instance, #name);
875 ALL_VK_INSTANCE_FUNCS()
878 /* Cache physical devices for vkEnumeratePhysicalDevices within the instance as
879 * each vkPhysicalDevice is a dispatchable object, which means we need to wrap
880 * the native physical devices and present those to the application.
881 * Cleanup happens as part of wine_vkDestroyInstance.
883 res
= wine_vk_instance_load_physical_devices(object
);
884 if (res
!= VK_SUCCESS
)
886 ERR("Failed to load physical devices, res=%d\n", res
);
887 wine_vk_instance_free(object
);
891 if ((app_info
= create_info
->pApplicationInfo
))
893 TRACE("Application name %s, application version %#x.\n",
894 debugstr_a(app_info
->pApplicationName
), app_info
->applicationVersion
);
895 TRACE("Engine name %s, engine version %#x.\n", debugstr_a(app_info
->pEngineName
),
896 app_info
->engineVersion
);
897 TRACE("API version %#x.\n", app_info
->apiVersion
);
899 if (app_info
->pEngineName
&& !strcmp(app_info
->pEngineName
, "idTech"))
900 object
->quirks
|= WINEVULKAN_QUIRK_GET_DEVICE_PROC_ADDR
;
903 object
->quirks
|= WINEVULKAN_QUIRK_ADJUST_MAX_IMAGE_COUNT
;
906 TRACE("Created instance %p (native instance %p).\n", object
, object
->instance
);
910 void WINAPI
wine_vkDestroyDevice(VkDevice device
, const VkAllocationCallbacks
*allocator
)
912 TRACE("%p %p\n", device
, allocator
);
915 FIXME("Support for allocation callbacks not implemented yet\n");
917 wine_vk_device_free(device
);
920 void WINAPI
wine_vkDestroyInstance(VkInstance instance
, const VkAllocationCallbacks
*allocator
)
922 TRACE("%p, %p\n", instance
, allocator
);
925 FIXME("Support allocation allocators\n");
927 wine_vk_instance_free(instance
);
930 VkResult WINAPI
wine_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice phys_dev
,
931 const char *layer_name
, uint32_t *count
, VkExtensionProperties
*properties
)
933 TRACE("%p, %p, %p, %p\n", phys_dev
, layer_name
, count
, properties
);
935 /* This shouldn't get called with layer_name set, the ICD loader prevents it. */
938 ERR("Layer enumeration not supported from ICD.\n");
939 return VK_ERROR_LAYER_NOT_PRESENT
;
944 *count
= phys_dev
->extension_count
;
948 *count
= min(*count
, phys_dev
->extension_count
);
949 memcpy(properties
, phys_dev
->extensions
, *count
* sizeof(*properties
));
951 TRACE("Returning %u extensions.\n", *count
);
952 return *count
< phys_dev
->extension_count
? VK_INCOMPLETE
: VK_SUCCESS
;
955 VkResult WINAPI
wine_vkEnumerateInstanceExtensionProperties(const char *layer_name
,
956 uint32_t *count
, VkExtensionProperties
*properties
)
958 uint32_t num_properties
= 0, num_host_properties
;
959 VkExtensionProperties
*host_properties
;
963 TRACE("%p, %p, %p\n", layer_name
, count
, properties
);
967 WARN("Layer enumeration not supported from ICD.\n");
968 return VK_ERROR_LAYER_NOT_PRESENT
;
978 res
= vk_funcs
->p_vkEnumerateInstanceExtensionProperties(NULL
, &num_host_properties
, NULL
);
979 if (res
!= VK_SUCCESS
)
982 if (!(host_properties
= heap_calloc(num_host_properties
, sizeof(*host_properties
))))
983 return VK_ERROR_OUT_OF_HOST_MEMORY
;
985 res
= vk_funcs
->p_vkEnumerateInstanceExtensionProperties(NULL
, &num_host_properties
, host_properties
);
986 if (res
!= VK_SUCCESS
)
988 ERR("Failed to retrieve host properties, res=%d.\n", res
);
989 heap_free(host_properties
);
993 /* The Wine graphics driver provides us with all extensions supported by the host side
994 * including extension fixup (e.g. VK_KHR_xlib_surface -> VK_KHR_win32_surface). It is
995 * up to us here to filter the list down to extensions for which we have thunks.
997 for (i
= 0; i
< num_host_properties
; i
++)
999 if (wine_vk_instance_extension_supported(host_properties
[i
].extensionName
))
1002 TRACE("Instance extension '%s' is not supported.\n", host_properties
[i
].extensionName
);
1007 TRACE("Returning %u extensions.\n", num_properties
);
1008 *count
= num_properties
;
1009 heap_free(host_properties
);
1013 for (i
= 0, j
= 0; i
< num_host_properties
&& j
< *count
; i
++)
1015 if (wine_vk_instance_extension_supported(host_properties
[i
].extensionName
))
1017 TRACE("Enabling extension '%s'.\n", host_properties
[i
].extensionName
);
1018 properties
[j
++] = host_properties
[i
];
1021 *count
= min(*count
, num_properties
);
1023 heap_free(host_properties
);
1024 return *count
< num_properties
? VK_INCOMPLETE
: VK_SUCCESS
;
1027 VkResult WINAPI
wine_vkEnumerateInstanceLayerProperties(uint32_t *count
, VkLayerProperties
*properties
)
1029 TRACE("%p, %p\n", count
, properties
);
1037 return VK_ERROR_LAYER_NOT_PRESENT
;
1040 VkResult WINAPI
wine_vkEnumerateInstanceVersion(uint32_t *version
)
1044 TRACE("%p\n", version
);
1046 wine_vk_init_once();
1048 if (p_vkEnumerateInstanceVersion
)
1050 res
= p_vkEnumerateInstanceVersion(version
);
1054 *version
= VK_API_VERSION_1_0
;
1058 TRACE("API version %u.%u.%u.\n",
1059 VK_VERSION_MAJOR(*version
), VK_VERSION_MINOR(*version
), VK_VERSION_PATCH(*version
));
1060 *version
= min(WINE_VK_VERSION
, *version
);
1064 VkResult WINAPI
wine_vkEnumeratePhysicalDevices(VkInstance instance
, uint32_t *count
,
1065 VkPhysicalDevice
*devices
)
1069 TRACE("%p %p %p\n", instance
, count
, devices
);
1073 *count
= instance
->phys_dev_count
;
1077 *count
= min(*count
, instance
->phys_dev_count
);
1078 for (i
= 0; i
< *count
; i
++)
1080 devices
[i
] = instance
->phys_devs
[i
];
1083 TRACE("Returning %u devices.\n", *count
);
1084 return *count
< instance
->phys_dev_count
? VK_INCOMPLETE
: VK_SUCCESS
;
1087 void WINAPI
wine_vkFreeCommandBuffers(VkDevice device
, VkCommandPool pool_handle
,
1088 uint32_t count
, const VkCommandBuffer
*buffers
)
1090 struct wine_cmd_pool
*pool
= wine_cmd_pool_from_handle(pool_handle
);
1092 TRACE("%p, 0x%s, %u, %p\n", device
, wine_dbgstr_longlong(pool_handle
), count
, buffers
);
1094 wine_vk_free_command_buffers(device
, pool
, count
, buffers
);
1097 PFN_vkVoidFunction WINAPI
wine_vkGetDeviceProcAddr(VkDevice device
, const char *name
)
1100 TRACE("%p, %s\n", device
, debugstr_a(name
));
1102 /* The spec leaves return value undefined for a NULL device, let's just return NULL. */
1103 if (!device
|| !name
)
1106 /* Per the spec, we are only supposed to return device functions as in functions
1107 * for which the first parameter is vkDevice or a child of vkDevice like a
1108 * vkCommandBuffer or vkQueue.
1109 * Loader takes care of filtering of extensions which are enabled or not.
1111 func
= wine_vk_get_device_proc_addr(name
);
1115 /* vkGetDeviceProcAddr was intended for loading device and subdevice functions.
1116 * idTech 6 titles such as Doom and Wolfenstein II, however use it also for
1117 * loading of instance functions. This is undefined behavior as the specification
1118 * disallows using any of the returned function pointers outside of device /
1119 * subdevice objects. The games don't actually use the function pointers and if they
1120 * did, they would crash as VkInstance / VkPhysicalDevice parameters need unwrapping.
1121 * Khronos clarified behavior in the Vulkan spec and expects drivers to get updated,
1122 * however it would require both driver and game fixes.
1123 * https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/issues/2323
1124 * https://github.com/KhronosGroup/Vulkan-Docs/issues/655
1126 if (device
->quirks
& WINEVULKAN_QUIRK_GET_DEVICE_PROC_ADDR
1127 && (func
= wine_vk_get_instance_proc_addr(name
)))
1129 WARN("Returning instance function %s.\n", debugstr_a(name
));
1133 WARN("Unsupported device function: %s.\n", debugstr_a(name
));
1137 void WINAPI
wine_vkGetDeviceQueue(VkDevice device
, uint32_t family_index
,
1138 uint32_t queue_index
, VkQueue
*queue
)
1140 TRACE("%p, %u, %u, %p\n", device
, family_index
, queue_index
, queue
);
1142 *queue
= &device
->queues
[family_index
][queue_index
];
1145 void WINAPI
wine_vkGetDeviceQueue2(VkDevice device
, const VkDeviceQueueInfo2
*info
, VkQueue
*queue
)
1147 struct VkQueue_T
*matching_queue
;
1148 const VkBaseInStructure
*chain
;
1150 TRACE("%p, %p, %p\n", device
, info
, queue
);
1152 if ((chain
= info
->pNext
))
1153 FIXME("Ignoring a linked structure of type %u.\n", chain
->sType
);
1155 matching_queue
= &device
->queues
[info
->queueFamilyIndex
][info
->queueIndex
];
1156 if (matching_queue
->flags
!= info
->flags
)
1158 WARN("No matching flags were specified %#x, %#x.\n", matching_queue
->flags
, info
->flags
);
1159 matching_queue
= VK_NULL_HANDLE
;
1161 *queue
= matching_queue
;
1164 PFN_vkVoidFunction WINAPI
wine_vkGetInstanceProcAddr(VkInstance instance
, const char *name
)
1168 TRACE("%p, %s\n", instance
, debugstr_a(name
));
1173 /* vkGetInstanceProcAddr can load most Vulkan functions when an instance is passed in, however
1174 * for a NULL instance it can only load global functions.
1176 func
= wine_vk_get_global_proc_addr(name
);
1183 WARN("Global function %s not found.\n", debugstr_a(name
));
1187 func
= wine_vk_get_instance_proc_addr(name
);
1188 if (func
) return func
;
1190 /* vkGetInstanceProcAddr also loads any children of instance, so device functions as well. */
1191 func
= wine_vk_get_device_proc_addr(name
);
1192 if (func
) return func
;
1194 WARN("Unsupported device or instance function: %s.\n", debugstr_a(name
));
1198 void * WINAPI
wine_vk_icdGetInstanceProcAddr(VkInstance instance
, const char *name
)
1200 TRACE("%p, %s\n", instance
, debugstr_a(name
));
1202 /* Initial version of the Vulkan ICD spec required vkGetInstanceProcAddr to be
1203 * exported. vk_icdGetInstanceProcAddr was added later to separate ICD calls from
1204 * Vulkan API. One of them in our case should forward to the other, so just forward
1205 * to the older vkGetInstanceProcAddr.
1207 return wine_vkGetInstanceProcAddr(instance
, name
);
1210 VkResult WINAPI
wine_vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *supported_version
)
1212 uint32_t req_version
;
1214 TRACE("%p\n", supported_version
);
1216 /* The spec is not clear how to handle this. Mesa drivers don't check, but it
1217 * is probably best to not explode. VK_INCOMPLETE seems to be the closest value.
1219 if (!supported_version
)
1220 return VK_INCOMPLETE
;
1222 req_version
= *supported_version
;
1223 *supported_version
= min(req_version
, WINE_VULKAN_ICD_VERSION
);
1224 TRACE("Loader requested ICD version %u, returning %u\n", req_version
, *supported_version
);
1229 VkResult WINAPI
wine_vkQueueSubmit(VkQueue queue
, uint32_t count
,
1230 const VkSubmitInfo
*submits
, VkFence fence
)
1232 VkSubmitInfo
*submits_host
;
1234 VkCommandBuffer
*command_buffers
;
1235 unsigned int i
, j
, num_command_buffers
;
1237 TRACE("%p %u %p 0x%s\n", queue
, count
, submits
, wine_dbgstr_longlong(fence
));
1241 return queue
->device
->funcs
.p_vkQueueSubmit(queue
->queue
, 0, NULL
, fence
);
1244 submits_host
= heap_calloc(count
, sizeof(*submits_host
));
1247 ERR("Unable to allocate memory for submit buffers!\n");
1248 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1251 for (i
= 0; i
< count
; i
++)
1253 memcpy(&submits_host
[i
], &submits
[i
], sizeof(*submits_host
));
1255 num_command_buffers
= submits
[i
].commandBufferCount
;
1256 command_buffers
= heap_calloc(num_command_buffers
, sizeof(*submits_host
));
1257 if (!command_buffers
)
1259 ERR("Unable to allocate memory for command buffers!\n");
1260 res
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1264 for (j
= 0; j
< num_command_buffers
; j
++)
1266 command_buffers
[j
] = submits
[i
].pCommandBuffers
[j
]->command_buffer
;
1268 submits_host
[i
].pCommandBuffers
= command_buffers
;
1271 res
= queue
->device
->funcs
.p_vkQueueSubmit(queue
->queue
, count
, submits_host
, fence
);
1274 for (i
= 0; i
< count
; i
++)
1276 heap_free((void *)submits_host
[i
].pCommandBuffers
);
1278 heap_free(submits_host
);
1280 TRACE("Returning %d\n", res
);
1284 VkResult WINAPI
wine_vkCreateCommandPool(VkDevice device
, const VkCommandPoolCreateInfo
*info
,
1285 const VkAllocationCallbacks
*allocator
, VkCommandPool
*command_pool
)
1287 struct wine_cmd_pool
*object
;
1290 TRACE("%p, %p, %p, %p\n", device
, info
, allocator
, command_pool
);
1293 FIXME("Support for allocation callbacks not implemented yet\n");
1295 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1296 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1298 list_init(&object
->command_buffers
);
1300 res
= device
->funcs
.p_vkCreateCommandPool(device
->device
, info
, NULL
, &object
->command_pool
);
1302 if (res
== VK_SUCCESS
)
1304 WINE_VK_ADD_NON_DISPATCHABLE_MAPPING(device
->phys_dev
->instance
, object
, object
->command_pool
);
1305 *command_pool
= wine_cmd_pool_to_handle(object
);
1315 void WINAPI
wine_vkDestroyCommandPool(VkDevice device
, VkCommandPool handle
,
1316 const VkAllocationCallbacks
*allocator
)
1318 struct wine_cmd_pool
*pool
= wine_cmd_pool_from_handle(handle
);
1319 struct VkCommandBuffer_T
*buffer
, *cursor
;
1321 TRACE("%p, 0x%s, %p\n", device
, wine_dbgstr_longlong(handle
), allocator
);
1327 FIXME("Support for allocation callbacks not implemented yet\n");
1329 /* The Vulkan spec says:
1331 * "When a pool is destroyed, all command buffers allocated from the pool are freed."
1333 LIST_FOR_EACH_ENTRY_SAFE(buffer
, cursor
, &pool
->command_buffers
, struct VkCommandBuffer_T
, pool_link
)
1335 WINE_VK_REMOVE_HANDLE_MAPPING(device
->phys_dev
->instance
, buffer
);
1339 WINE_VK_REMOVE_HANDLE_MAPPING(device
->phys_dev
->instance
, pool
);
1341 device
->funcs
.p_vkDestroyCommandPool(device
->device
, pool
->command_pool
, NULL
);
1345 static VkResult
wine_vk_enumerate_physical_device_groups(struct VkInstance_T
*instance
,
1346 VkResult (*p_vkEnumeratePhysicalDeviceGroups
)(VkInstance
, uint32_t *, VkPhysicalDeviceGroupProperties
*),
1347 uint32_t *count
, VkPhysicalDeviceGroupProperties
*properties
)
1352 res
= p_vkEnumeratePhysicalDeviceGroups(instance
->instance
, count
, properties
);
1353 if (res
< 0 || !properties
)
1356 for (i
= 0; i
< *count
; ++i
)
1358 VkPhysicalDeviceGroupProperties
*current
= &properties
[i
];
1359 for (j
= 0; j
< current
->physicalDeviceCount
; ++j
)
1361 VkPhysicalDevice dev
= current
->physicalDevices
[j
];
1362 if (!(current
->physicalDevices
[j
] = wine_vk_instance_wrap_physical_device(instance
, dev
)))
1363 return VK_ERROR_INITIALIZATION_FAILED
;
1370 VkResult WINAPI
wine_vkEnumeratePhysicalDeviceGroups(VkInstance instance
,
1371 uint32_t *count
, VkPhysicalDeviceGroupProperties
*properties
)
1373 TRACE("%p, %p, %p\n", instance
, count
, properties
);
1374 return wine_vk_enumerate_physical_device_groups(instance
,
1375 instance
->funcs
.p_vkEnumeratePhysicalDeviceGroups
, count
, properties
);
1378 VkResult WINAPI
wine_vkEnumeratePhysicalDeviceGroupsKHR(VkInstance instance
,
1379 uint32_t *count
, VkPhysicalDeviceGroupProperties
*properties
)
1381 TRACE("%p, %p, %p\n", instance
, count
, properties
);
1382 return wine_vk_enumerate_physical_device_groups(instance
,
1383 instance
->funcs
.p_vkEnumeratePhysicalDeviceGroupsKHR
, count
, properties
);
1386 void WINAPI
wine_vkGetPhysicalDeviceExternalFenceProperties(VkPhysicalDevice phys_dev
,
1387 const VkPhysicalDeviceExternalFenceInfo
*fence_info
, VkExternalFenceProperties
*properties
)
1389 TRACE("%p, %p, %p\n", phys_dev
, fence_info
, properties
);
1390 properties
->exportFromImportedHandleTypes
= 0;
1391 properties
->compatibleHandleTypes
= 0;
1392 properties
->externalFenceFeatures
= 0;
1395 void WINAPI
wine_vkGetPhysicalDeviceExternalFencePropertiesKHR(VkPhysicalDevice phys_dev
,
1396 const VkPhysicalDeviceExternalFenceInfo
*fence_info
, VkExternalFenceProperties
*properties
)
1398 TRACE("%p, %p, %p\n", phys_dev
, fence_info
, properties
);
1399 properties
->exportFromImportedHandleTypes
= 0;
1400 properties
->compatibleHandleTypes
= 0;
1401 properties
->externalFenceFeatures
= 0;
1404 void WINAPI
wine_vkGetPhysicalDeviceExternalBufferProperties(VkPhysicalDevice phys_dev
,
1405 const VkPhysicalDeviceExternalBufferInfo
*buffer_info
, VkExternalBufferProperties
*properties
)
1407 TRACE("%p, %p, %p\n", phys_dev
, buffer_info
, properties
);
1408 memset(&properties
->externalMemoryProperties
, 0, sizeof(properties
->externalMemoryProperties
));
1411 void WINAPI
wine_vkGetPhysicalDeviceExternalBufferPropertiesKHR(VkPhysicalDevice phys_dev
,
1412 const VkPhysicalDeviceExternalBufferInfo
*buffer_info
, VkExternalBufferProperties
*properties
)
1414 TRACE("%p, %p, %p\n", phys_dev
, buffer_info
, properties
);
1415 memset(&properties
->externalMemoryProperties
, 0, sizeof(properties
->externalMemoryProperties
));
1418 VkResult WINAPI
wine_vkGetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice phys_dev
,
1419 const VkPhysicalDeviceImageFormatInfo2
*format_info
, VkImageFormatProperties2
*properties
)
1421 VkExternalImageFormatProperties
*external_image_properties
;
1424 TRACE("%p, %p, %p\n", phys_dev
, format_info
, properties
);
1426 res
= thunk_vkGetPhysicalDeviceImageFormatProperties2(phys_dev
, format_info
, properties
);
1428 if ((external_image_properties
= wine_vk_find_struct(properties
, EXTERNAL_IMAGE_FORMAT_PROPERTIES
)))
1430 VkExternalMemoryProperties
*p
= &external_image_properties
->externalMemoryProperties
;
1431 p
->externalMemoryFeatures
= 0;
1432 p
->exportFromImportedHandleTypes
= 0;
1433 p
->compatibleHandleTypes
= 0;
1439 VkResult WINAPI
wine_vkGetPhysicalDeviceImageFormatProperties2KHR(VkPhysicalDevice phys_dev
,
1440 const VkPhysicalDeviceImageFormatInfo2
*format_info
, VkImageFormatProperties2
*properties
)
1442 VkExternalImageFormatProperties
*external_image_properties
;
1445 TRACE("%p, %p, %p\n", phys_dev
, format_info
, properties
);
1447 res
= thunk_vkGetPhysicalDeviceImageFormatProperties2KHR(phys_dev
, format_info
, properties
);
1449 if ((external_image_properties
= wine_vk_find_struct(properties
, EXTERNAL_IMAGE_FORMAT_PROPERTIES
)))
1451 VkExternalMemoryProperties
*p
= &external_image_properties
->externalMemoryProperties
;
1452 p
->externalMemoryFeatures
= 0;
1453 p
->exportFromImportedHandleTypes
= 0;
1454 p
->compatibleHandleTypes
= 0;
1460 /* From ntdll/unix/sync.c */
1461 #define NANOSECONDS_IN_A_SECOND 1000000000
1462 #define TICKSPERSEC 10000000
1464 static inline VkTimeDomainEXT
get_performance_counter_time_domain(void)
1466 #if !defined(__APPLE__) && defined(HAVE_CLOCK_GETTIME)
1467 # ifdef CLOCK_MONOTONIC_RAW
1468 return VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
;
1470 return VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
;
1473 FIXME("No mapping for VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT on this platform.");
1474 return VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT
;
1478 static VkTimeDomainEXT
map_to_host_time_domain(VkTimeDomainEXT domain
)
1480 /* Matches ntdll/unix/sync.c's performance counter implementation. */
1481 if (domain
== VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT
)
1482 return get_performance_counter_time_domain();
1487 static inline uint64_t convert_monotonic_timestamp(uint64_t value
)
1489 return value
/ (NANOSECONDS_IN_A_SECOND
/ TICKSPERSEC
);
1492 static inline uint64_t convert_timestamp(VkTimeDomainEXT host_domain
, VkTimeDomainEXT target_domain
, uint64_t value
)
1494 if (host_domain
== target_domain
)
1497 /* Convert between MONOTONIC time in ns -> QueryPerformanceCounter */
1498 if ((host_domain
== VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
|| host_domain
== VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
)
1499 && target_domain
== VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT
)
1500 return convert_monotonic_timestamp(value
);
1502 FIXME("Couldn't translate between host domain %d and target domain %d", host_domain
, target_domain
);
1506 VkResult WINAPI
wine_vkGetCalibratedTimestampsEXT(VkDevice device
,
1507 uint32_t timestamp_count
, const VkCalibratedTimestampInfoEXT
*timestamp_infos
,
1508 uint64_t *timestamps
, uint64_t *max_deviation
)
1510 VkCalibratedTimestampInfoEXT
* host_timestamp_infos
;
1513 TRACE("%p, %u, %p, %p, %p\n", device
, timestamp_count
, timestamp_infos
, timestamps
, max_deviation
);
1515 if (!(host_timestamp_infos
= heap_alloc(sizeof(VkCalibratedTimestampInfoEXT
) * timestamp_count
)))
1516 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1518 for (i
= 0; i
< timestamp_count
; i
++)
1520 host_timestamp_infos
[i
].sType
= timestamp_infos
[i
].sType
;
1521 host_timestamp_infos
[i
].pNext
= timestamp_infos
[i
].pNext
;
1522 host_timestamp_infos
[i
].timeDomain
= map_to_host_time_domain(timestamp_infos
[i
].timeDomain
);
1525 res
= device
->funcs
.p_vkGetCalibratedTimestampsEXT(device
->device
, timestamp_count
, host_timestamp_infos
, timestamps
, max_deviation
);
1526 if (res
!= VK_SUCCESS
)
1529 for (i
= 0; i
< timestamp_count
; i
++)
1530 timestamps
[i
] = convert_timestamp(host_timestamp_infos
[i
].timeDomain
, timestamp_infos
[i
].timeDomain
, timestamps
[i
]);
1532 heap_free(host_timestamp_infos
);
1537 VkResult WINAPI
wine_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(VkPhysicalDevice phys_dev
,
1538 uint32_t *time_domain_count
, VkTimeDomainEXT
*time_domains
)
1540 BOOL supports_device
= FALSE
, supports_monotonic
= FALSE
, supports_monotonic_raw
= FALSE
;
1541 const VkTimeDomainEXT performance_counter_domain
= get_performance_counter_time_domain();
1542 VkTimeDomainEXT
*host_time_domains
;
1543 uint32_t host_time_domain_count
;
1544 VkTimeDomainEXT out_time_domains
[2];
1545 uint32_t out_time_domain_count
;
1549 TRACE("%p, %p, %p\n", phys_dev
, time_domain_count
, time_domains
);
1551 /* Find out the time domains supported on the host */
1552 res
= phys_dev
->instance
->funcs
.p_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(phys_dev
->phys_dev
, &host_time_domain_count
, NULL
);
1553 if (res
!= VK_SUCCESS
)
1556 if (!(host_time_domains
= heap_alloc(sizeof(VkTimeDomainEXT
) * host_time_domain_count
)))
1557 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1559 res
= phys_dev
->instance
->funcs
.p_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT(phys_dev
->phys_dev
, &host_time_domain_count
, host_time_domains
);
1560 if (res
!= VK_SUCCESS
)
1562 heap_free(host_time_domains
);
1566 for (i
= 0; i
< host_time_domain_count
; i
++)
1568 if (host_time_domains
[i
] == VK_TIME_DOMAIN_DEVICE_EXT
)
1569 supports_device
= TRUE
;
1570 else if (host_time_domains
[i
] == VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
)
1571 supports_monotonic
= TRUE
;
1572 else if (host_time_domains
[i
] == VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
)
1573 supports_monotonic_raw
= TRUE
;
1575 FIXME("Unknown time domain %d", host_time_domains
[i
]);
1578 heap_free(host_time_domains
);
1580 out_time_domain_count
= 0;
1582 /* Map our monotonic times -> QPC */
1583 if (supports_monotonic_raw
&& performance_counter_domain
== VK_TIME_DOMAIN_CLOCK_MONOTONIC_RAW_EXT
)
1584 out_time_domains
[out_time_domain_count
++] = VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT
;
1585 else if (supports_monotonic
&& performance_counter_domain
== VK_TIME_DOMAIN_CLOCK_MONOTONIC_EXT
)
1586 out_time_domains
[out_time_domain_count
++] = VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT
;
1588 FIXME("VK_TIME_DOMAIN_QUERY_PERFORMANCE_COUNTER_EXT not supported on this platform.");
1590 /* Forward the device domain time */
1591 if (supports_device
)
1592 out_time_domains
[out_time_domain_count
++] = VK_TIME_DOMAIN_DEVICE_EXT
;
1594 /* Send the count/domains back to the app */
1597 *time_domain_count
= out_time_domain_count
;
1601 for (i
= 0; i
< min(*time_domain_count
, out_time_domain_count
); i
++)
1602 time_domains
[i
] = out_time_domains
[i
];
1604 res
= *time_domain_count
< out_time_domain_count
? VK_INCOMPLETE
: VK_SUCCESS
;
1605 *time_domain_count
= out_time_domain_count
;
1609 static HANDLE
get_display_device_init_mutex(void)
1611 static const WCHAR init_mutexW
[] = {'d','i','s','p','l','a','y','_','d','e','v','i','c','e','_','i','n','i','t',0};
1612 HANDLE mutex
= CreateMutexW(NULL
, FALSE
, init_mutexW
);
1614 WaitForSingleObject(mutex
, INFINITE
);
1618 static void release_display_device_init_mutex(HANDLE mutex
)
1620 ReleaseMutex(mutex
);
1624 /* Wait until graphics driver is loaded by explorer */
1625 static void wait_graphics_driver_ready(void)
1627 static BOOL ready
= FALSE
;
1631 SendMessageW(GetDesktopWindow(), WM_NULL
, 0, 0);
1636 static void fill_luid_property(VkPhysicalDeviceProperties2
*properties2
)
1638 static const WCHAR pci
[] = {'P','C','I',0};
1639 VkPhysicalDeviceIDProperties
*id
;
1640 SP_DEVINFO_DATA device_data
;
1641 DWORD type
, device_idx
= 0;
1647 if (!(id
= wine_vk_find_struct(properties2
, PHYSICAL_DEVICE_ID_PROPERTIES
)))
1650 wait_graphics_driver_ready();
1651 mutex
= get_display_device_init_mutex();
1652 devinfo
= SetupDiGetClassDevsW(&GUID_DEVCLASS_DISPLAY
, pci
, NULL
, 0);
1653 device_data
.cbSize
= sizeof(device_data
);
1654 while (SetupDiEnumDeviceInfo(devinfo
, device_idx
++, &device_data
))
1656 if (!SetupDiGetDevicePropertyW(devinfo
, &device_data
, &WINE_DEVPROPKEY_GPU_VULKAN_UUID
,
1657 &type
, (BYTE
*)&uuid
, sizeof(uuid
), NULL
, 0))
1660 if (!IsEqualGUID(&uuid
, id
->deviceUUID
))
1663 if (SetupDiGetDevicePropertyW(devinfo
, &device_data
, &DEVPROPKEY_GPU_LUID
, &type
,
1664 (BYTE
*)&luid
, sizeof(luid
), NULL
, 0))
1666 memcpy(&id
->deviceLUID
, &luid
, sizeof(id
->deviceLUID
));
1667 id
->deviceLUIDValid
= VK_TRUE
;
1668 id
->deviceNodeMask
= 1;
1672 SetupDiDestroyDeviceInfoList(devinfo
);
1673 release_display_device_init_mutex(mutex
);
1675 TRACE("deviceName:%s deviceLUIDValid:%d LUID:%08x:%08x deviceNodeMask:%#x.\n",
1676 properties2
->properties
.deviceName
, id
->deviceLUIDValid
, luid
.HighPart
, luid
.LowPart
,
1677 id
->deviceNodeMask
);
1680 void WINAPI
wine_vkGetPhysicalDeviceProperties2(VkPhysicalDevice phys_dev
,
1681 VkPhysicalDeviceProperties2
*properties2
)
1683 TRACE("%p, %p\n", phys_dev
, properties2
);
1685 thunk_vkGetPhysicalDeviceProperties2(phys_dev
, properties2
);
1686 fill_luid_property(properties2
);
1689 void WINAPI
wine_vkGetPhysicalDeviceProperties2KHR(VkPhysicalDevice phys_dev
,
1690 VkPhysicalDeviceProperties2
*properties2
)
1692 TRACE("%p, %p\n", phys_dev
, properties2
);
1694 thunk_vkGetPhysicalDeviceProperties2KHR(phys_dev
, properties2
);
1695 fill_luid_property(properties2
);
1698 void WINAPI
wine_vkGetPhysicalDeviceExternalSemaphoreProperties(VkPhysicalDevice phys_dev
,
1699 const VkPhysicalDeviceExternalSemaphoreInfo
*semaphore_info
, VkExternalSemaphoreProperties
*properties
)
1701 TRACE("%p, %p, %p\n", phys_dev
, semaphore_info
, properties
);
1702 properties
->exportFromImportedHandleTypes
= 0;
1703 properties
->compatibleHandleTypes
= 0;
1704 properties
->externalSemaphoreFeatures
= 0;
1707 void WINAPI
wine_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(VkPhysicalDevice phys_dev
,
1708 const VkPhysicalDeviceExternalSemaphoreInfo
*semaphore_info
, VkExternalSemaphoreProperties
*properties
)
1710 TRACE("%p, %p, %p\n", phys_dev
, semaphore_info
, properties
);
1711 properties
->exportFromImportedHandleTypes
= 0;
1712 properties
->compatibleHandleTypes
= 0;
1713 properties
->externalSemaphoreFeatures
= 0;
1716 VkResult WINAPI
wine_vkSetPrivateDataEXT(VkDevice device
, VkObjectType object_type
, uint64_t object_handle
,
1717 VkPrivateDataSlotEXT private_data_slot
, uint64_t data
)
1719 TRACE("%p, %#x, 0x%s, 0x%s, 0x%s\n", device
, object_type
, wine_dbgstr_longlong(object_handle
),
1720 wine_dbgstr_longlong(private_data_slot
), wine_dbgstr_longlong(data
));
1722 object_handle
= wine_vk_unwrap_handle(object_type
, object_handle
);
1723 return device
->funcs
.p_vkSetPrivateDataEXT(device
->device
, object_type
, object_handle
, private_data_slot
, data
);
1726 void WINAPI
wine_vkGetPrivateDataEXT(VkDevice device
, VkObjectType object_type
, uint64_t object_handle
,
1727 VkPrivateDataSlotEXT private_data_slot
, uint64_t *data
)
1729 TRACE("%p, %#x, 0x%s, 0x%s, %p\n", device
, object_type
, wine_dbgstr_longlong(object_handle
),
1730 wine_dbgstr_longlong(private_data_slot
), data
);
1732 object_handle
= wine_vk_unwrap_handle(object_type
, object_handle
);
1733 device
->funcs
.p_vkGetPrivateDataEXT(device
->device
, object_type
, object_handle
, private_data_slot
, data
);
1736 static inline void adjust_max_image_count(VkPhysicalDevice phys_dev
, VkSurfaceCapabilitiesKHR
* capabilities
)
1738 /* Many Windows games, for example Strange Brigade, No Man's Sky, Path of Exile
1739 * and World War Z, do not expect that maxImageCount can be set to 0.
1740 * A value of 0 means that there is no limit on the number of images.
1741 * Nvidia reports 8 on Windows, AMD 16.
1742 * https://vulkan.gpuinfo.org/displayreport.php?id=9122#surface
1743 * https://vulkan.gpuinfo.org/displayreport.php?id=9121#surface
1745 if ((phys_dev
->instance
->quirks
& WINEVULKAN_QUIRK_ADJUST_MAX_IMAGE_COUNT
) && !capabilities
->maxImageCount
)
1747 capabilities
->maxImageCount
= max(capabilities
->minImageCount
, 16);
1751 VkResult WINAPI
wine_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice phys_dev
,
1752 VkSurfaceKHR surface
, VkSurfaceCapabilitiesKHR
*capabilities
)
1756 TRACE("%p, 0x%s, %p\n", phys_dev
, wine_dbgstr_longlong(surface
), capabilities
);
1758 res
= thunk_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(phys_dev
, surface
, capabilities
);
1760 if (res
== VK_SUCCESS
)
1761 adjust_max_image_count(phys_dev
, capabilities
);
1766 VkResult WINAPI
wine_vkGetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice phys_dev
,
1767 const VkPhysicalDeviceSurfaceInfo2KHR
*surface_info
, VkSurfaceCapabilities2KHR
*capabilities
)
1771 TRACE("%p, %p, %p\n", phys_dev
, surface_info
, capabilities
);
1773 res
= thunk_vkGetPhysicalDeviceSurfaceCapabilities2KHR(phys_dev
, surface_info
, capabilities
);
1775 if (res
== VK_SUCCESS
)
1776 adjust_max_image_count(phys_dev
, &capabilities
->surfaceCapabilities
);
1781 VkResult WINAPI
wine_vkCreateDebugUtilsMessengerEXT(VkInstance instance
, const VkDebugUtilsMessengerCreateInfoEXT
*create_info
,
1782 const VkAllocationCallbacks
*allocator
, VkDebugUtilsMessengerEXT
*messenger
)
1784 VkDebugUtilsMessengerCreateInfoEXT wine_create_info
;
1785 struct wine_debug_utils_messenger
*object
;
1788 TRACE("%p, %p, %p, %p\n", instance
, create_info
, allocator
, messenger
);
1791 FIXME("Support for allocation callbacks not implemented yet\n");
1793 if (!(object
= heap_alloc_zero(sizeof(*object
))))
1794 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1796 object
->instance
= instance
;
1797 object
->user_callback
= create_info
->pfnUserCallback
;
1798 object
->user_data
= create_info
->pUserData
;
1800 wine_create_info
= *create_info
;
1802 wine_create_info
.pfnUserCallback
= (void *) &debug_utils_callback_conversion
;
1803 wine_create_info
.pUserData
= object
;
1805 res
= instance
->funcs
.p_vkCreateDebugUtilsMessengerEXT(instance
->instance
, &wine_create_info
, NULL
, &object
->debug_messenger
);
1807 if (res
!= VK_SUCCESS
)
1813 WINE_VK_ADD_NON_DISPATCHABLE_MAPPING(instance
, object
, object
->debug_messenger
);
1814 *messenger
= wine_debug_utils_messenger_to_handle(object
);
1819 void WINAPI
wine_vkDestroyDebugUtilsMessengerEXT(
1820 VkInstance instance
, VkDebugUtilsMessengerEXT messenger
, const VkAllocationCallbacks
*allocator
)
1822 struct wine_debug_utils_messenger
*object
;
1824 TRACE("%p, 0x%s, %p\n", instance
, wine_dbgstr_longlong(messenger
), allocator
);
1826 object
= wine_debug_utils_messenger_from_handle(messenger
);
1828 instance
->funcs
.p_vkDestroyDebugUtilsMessengerEXT(instance
->instance
, object
->debug_messenger
, NULL
);
1829 WINE_VK_REMOVE_HANDLE_MAPPING(instance
, object
);
1834 void WINAPI
wine_vkSubmitDebugUtilsMessageEXT(VkInstance instance
, VkDebugUtilsMessageSeverityFlagBitsEXT severity
,
1835 VkDebugUtilsMessageTypeFlagsEXT types
, const VkDebugUtilsMessengerCallbackDataEXT
*callback_data
)
1837 VkDebugUtilsMessengerCallbackDataEXT native_callback_data
;
1838 VkDebugUtilsObjectNameInfoEXT
*object_names
;
1841 TRACE("%p, %#x, %#x, %p\n", instance
, severity
, types
, callback_data
);
1843 native_callback_data
= *callback_data
;
1844 object_names
= heap_calloc(callback_data
->objectCount
, sizeof(*object_names
));
1845 memcpy(object_names
, callback_data
->pObjects
, callback_data
->objectCount
* sizeof(*object_names
));
1846 native_callback_data
.pObjects
= object_names
;
1848 for (i
= 0; i
< callback_data
->objectCount
; i
++)
1850 object_names
[i
].objectHandle
=
1851 wine_vk_unwrap_handle(callback_data
->pObjects
[i
].objectType
, callback_data
->pObjects
[i
].objectHandle
);
1854 thunk_vkSubmitDebugUtilsMessageEXT(instance
, severity
, types
, &native_callback_data
);
1856 heap_free(object_names
);
1859 VkResult WINAPI
wine_vkSetDebugUtilsObjectTagEXT(VkDevice device
, const VkDebugUtilsObjectTagInfoEXT
*tag_info
)
1861 VkDebugUtilsObjectTagInfoEXT wine_tag_info
;
1863 TRACE("%p, %p\n", device
, tag_info
);
1865 wine_tag_info
= *tag_info
;
1866 wine_tag_info
.objectHandle
= wine_vk_unwrap_handle(tag_info
->objectType
, tag_info
->objectHandle
);
1868 return thunk_vkSetDebugUtilsObjectTagEXT(device
, &wine_tag_info
);
1871 VkResult WINAPI
wine_vkSetDebugUtilsObjectNameEXT(VkDevice device
, const VkDebugUtilsObjectNameInfoEXT
*name_info
)
1873 VkDebugUtilsObjectNameInfoEXT wine_name_info
;
1875 TRACE("%p, %p\n", device
, name_info
);
1877 wine_name_info
= *name_info
;
1878 wine_name_info
.objectHandle
= wine_vk_unwrap_handle(name_info
->objectType
, name_info
->objectHandle
);
1880 return thunk_vkSetDebugUtilsObjectNameEXT(device
, &wine_name_info
);
1883 BOOL WINAPI
DllMain(HINSTANCE hinst
, DWORD reason
, void *reserved
)
1885 TRACE("%p, %u, %p\n", hinst
, reason
, reserved
);
1889 case DLL_PROCESS_ATTACH
:
1891 DisableThreadLibraryCalls(hinst
);
1897 static const struct vulkan_func vk_global_dispatch_table
[] =
1899 /* These functions must call wine_vk_init_once() before accessing vk_funcs. */
1900 {"vkCreateInstance", &wine_vkCreateInstance
},
1901 {"vkEnumerateInstanceExtensionProperties", &wine_vkEnumerateInstanceExtensionProperties
},
1902 {"vkEnumerateInstanceLayerProperties", &wine_vkEnumerateInstanceLayerProperties
},
1903 {"vkEnumerateInstanceVersion", &wine_vkEnumerateInstanceVersion
},
1904 {"vkGetInstanceProcAddr", &wine_vkGetInstanceProcAddr
},
1907 static void *wine_vk_get_global_proc_addr(const char *name
)
1911 for (i
= 0; i
< ARRAY_SIZE(vk_global_dispatch_table
); i
++)
1913 if (strcmp(name
, vk_global_dispatch_table
[i
].name
) == 0)
1915 TRACE("Found name=%s in global table\n", debugstr_a(name
));
1916 return vk_global_dispatch_table
[i
].func
;
1923 * Wrapper around driver vkGetInstanceProcAddr implementation.
1924 * Allows winelib applications to access Vulkan functions with Wine
1925 * additions and native ABI.
1927 void *native_vkGetInstanceProcAddrWINE(VkInstance instance
, const char *name
)
1929 return vk_funcs
->p_vkGetInstanceProcAddr(instance
, name
);
1933 static const WCHAR winevulkan_json_resW
[] = {'w','i','n','e','v','u','l','k','a','n','_','j','s','o','n',0};
1934 static const WCHAR winevulkan_json_pathW
[] = {'\\','w','i','n','e','v','u','l','k','a','n','.','j','s','o','n',0};
1935 static const WCHAR vulkan_driversW
[] = {'S','o','f','t','w','a','r','e','\\','K','h','r','o','n','o','s','\\',
1936 'V','u','l','k','a','n','\\','D','r','i','v','e','r','s',0};
1938 HRESULT WINAPI
DllRegisterServer(void)
1940 WCHAR json_path
[MAX_PATH
];
1943 DWORD datalen
, written
, zero
= 0;
1947 /* Create the JSON manifest and registry key to register this ICD with the official Vulkan loader. */
1949 rsrc
= FindResourceW(hinstance
, winevulkan_json_resW
, (const WCHAR
*)RT_RCDATA
);
1950 data
= LockResource(LoadResource(hinstance
, rsrc
));
1951 datalen
= SizeofResource(hinstance
, rsrc
);
1953 GetSystemDirectoryW(json_path
, ARRAY_SIZE(json_path
));
1954 lstrcatW(json_path
, winevulkan_json_pathW
);
1955 file
= CreateFileW(json_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1956 if (file
== INVALID_HANDLE_VALUE
)
1958 ERR("Unable to create JSON manifest.\n");
1959 return E_UNEXPECTED
;
1961 WriteFile(file
, data
, datalen
, &written
, NULL
);
1964 if (!RegCreateKeyExW(HKEY_LOCAL_MACHINE
, vulkan_driversW
, 0, NULL
, 0, KEY_SET_VALUE
, NULL
, &key
, NULL
))
1966 RegSetValueExW(key
, json_path
, 0, REG_DWORD
, (const BYTE
*)&zero
, sizeof(zero
));
1972 HRESULT WINAPI
DllUnregisterServer(void)
1974 WCHAR json_path
[MAX_PATH
];
1977 /* Remove the JSON manifest and registry key */
1979 GetSystemDirectoryW(json_path
, ARRAY_SIZE(json_path
));
1980 lstrcatW(json_path
, winevulkan_json_pathW
);
1981 DeleteFileW(json_path
);
1983 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, vulkan_driversW
, 0, KEY_SET_VALUE
, &key
) == ERROR_SUCCESS
)
1985 RegDeleteValueW(key
, json_path
);