shcore: Use CRT allocation functions.
[wine.git] / dlls / winemac.drv / vulkan.c
blob00f5e8465ab468dab669fb188f5c8b2c904a4dff
1 /* Mac Driver Vulkan implementation
3 * Copyright 2017 Roderick Colenbrander
4 * Copyright 2018 Andrew Eikum for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 /* NOTE: If making changes here, consider whether they should be reflected in
22 * the other drivers. */
24 #if 0
25 #pragma makedep unix
26 #endif
28 #include "config.h"
30 #include <stdarg.h>
31 #include <stdio.h>
32 #include <dlfcn.h>
34 #include "macdrv.h"
35 #include "wine/debug.h"
37 #define VK_NO_PROTOTYPES
38 #define WINE_VK_HOST
40 #include "wine/vulkan.h"
41 #include "wine/vulkan_driver.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(vulkan);
45 #ifdef SONAME_LIBMOLTENVK
47 WINE_DECLARE_DEBUG_CHANNEL(fps);
49 typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
50 #define VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK 1000123000
52 typedef VkFlags VkMetalSurfaceCreateFlagsEXT;
53 #define VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT 1000217000
55 struct wine_vk_surface
57 macdrv_metal_device device;
58 macdrv_metal_view view;
59 VkSurfaceKHR surface; /* native surface */
62 typedef struct VkMacOSSurfaceCreateInfoMVK
64 VkStructureType sType;
65 const void *pNext;
66 VkMacOSSurfaceCreateFlagsMVK flags;
67 const void *pView; /* NSView */
68 } VkMacOSSurfaceCreateInfoMVK;
70 typedef struct VkMetalSurfaceCreateInfoEXT
72 VkStructureType sType;
73 const void *pNext;
74 VkMetalSurfaceCreateFlagsEXT flags;
75 const void *pLayer; /* CAMetalLayer */
76 } VkMetalSurfaceCreateInfoEXT;
78 static VkResult (*pvkCreateInstance)(const VkInstanceCreateInfo *, const VkAllocationCallbacks *, VkInstance *);
79 static VkResult (*pvkCreateSwapchainKHR)(VkDevice, const VkSwapchainCreateInfoKHR *, const VkAllocationCallbacks *, VkSwapchainKHR *);
80 static VkResult (*pvkCreateMacOSSurfaceMVK)(VkInstance, const VkMacOSSurfaceCreateInfoMVK*, const VkAllocationCallbacks *, VkSurfaceKHR *);
81 static VkResult (*pvkCreateMetalSurfaceEXT)(VkInstance, const VkMetalSurfaceCreateInfoEXT*, const VkAllocationCallbacks *, VkSurfaceKHR *);
82 static void (*pvkDestroyInstance)(VkInstance, const VkAllocationCallbacks *);
83 static void (*pvkDestroySurfaceKHR)(VkInstance, VkSurfaceKHR, const VkAllocationCallbacks *);
84 static void (*pvkDestroySwapchainKHR)(VkDevice, VkSwapchainKHR, const VkAllocationCallbacks *);
85 static VkResult (*pvkEnumerateInstanceExtensionProperties)(const char *, uint32_t *, VkExtensionProperties *);
86 static void * (*pvkGetDeviceProcAddr)(VkDevice, const char *);
87 static void * (*pvkGetInstanceProcAddr)(VkInstance, const char *);
88 static VkResult (*pvkGetPhysicalDeviceSurfaceCapabilities2KHR)(VkPhysicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *, VkSurfaceCapabilities2KHR *);
89 static VkResult (*pvkGetPhysicalDeviceSurfaceCapabilitiesKHR)(VkPhysicalDevice, VkSurfaceKHR, VkSurfaceCapabilitiesKHR *);
90 static VkResult (*pvkGetPhysicalDeviceSurfaceFormats2KHR)(VkPhysicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *, uint32_t *, VkSurfaceFormat2KHR *);
91 static VkResult (*pvkGetPhysicalDeviceSurfaceFormatsKHR)(VkPhysicalDevice, VkSurfaceKHR, uint32_t *, VkSurfaceFormatKHR *);
92 static VkResult (*pvkGetPhysicalDeviceSurfacePresentModesKHR)(VkPhysicalDevice, VkSurfaceKHR, uint32_t *, VkPresentModeKHR *);
93 static VkResult (*pvkGetPhysicalDeviceSurfaceSupportKHR)(VkPhysicalDevice, uint32_t, VkSurfaceKHR, VkBool32 *);
94 static VkResult (*pvkGetSwapchainImagesKHR)(VkDevice, VkSwapchainKHR, uint32_t *, VkImage *);
95 static VkResult (*pvkQueuePresentKHR)(VkQueue, const VkPresentInfoKHR *);
97 static void *macdrv_get_vk_device_proc_addr(const char *name);
98 static void *macdrv_get_vk_instance_proc_addr(VkInstance instance, const char *name);
100 static inline struct wine_vk_surface *surface_from_handle(VkSurfaceKHR handle)
102 return (struct wine_vk_surface *)(uintptr_t)handle;
105 static void *vulkan_handle;
107 static void wine_vk_init(void)
109 if (!(vulkan_handle = dlopen(SONAME_LIBMOLTENVK, RTLD_NOW)))
111 ERR("Failed to load %s\n", SONAME_LIBMOLTENVK);
112 return;
115 #define LOAD_FUNCPTR(f) if ((p##f = dlsym(vulkan_handle, #f)) == NULL) goto fail;
116 LOAD_FUNCPTR(vkCreateInstance)
117 LOAD_FUNCPTR(vkCreateSwapchainKHR)
118 LOAD_FUNCPTR(vkCreateMacOSSurfaceMVK)
119 LOAD_FUNCPTR(vkCreateMetalSurfaceEXT)
120 LOAD_FUNCPTR(vkDestroyInstance)
121 LOAD_FUNCPTR(vkDestroySurfaceKHR)
122 LOAD_FUNCPTR(vkDestroySwapchainKHR)
123 LOAD_FUNCPTR(vkEnumerateInstanceExtensionProperties)
124 LOAD_FUNCPTR(vkGetDeviceProcAddr)
125 LOAD_FUNCPTR(vkGetInstanceProcAddr)
126 LOAD_FUNCPTR(vkGetPhysicalDeviceSurfaceCapabilities2KHR)
127 LOAD_FUNCPTR(vkGetPhysicalDeviceSurfaceCapabilitiesKHR)
128 LOAD_FUNCPTR(vkGetPhysicalDeviceSurfaceFormats2KHR)
129 LOAD_FUNCPTR(vkGetPhysicalDeviceSurfaceFormatsKHR)
130 LOAD_FUNCPTR(vkGetPhysicalDeviceSurfacePresentModesKHR)
131 LOAD_FUNCPTR(vkGetPhysicalDeviceSurfaceSupportKHR)
132 LOAD_FUNCPTR(vkGetSwapchainImagesKHR)
133 LOAD_FUNCPTR(vkQueuePresentKHR)
134 #undef LOAD_FUNCPTR
136 return;
138 fail:
139 dlclose(vulkan_handle);
140 vulkan_handle = NULL;
143 /* Helper function for converting between win32 and MoltenVK compatible VkInstanceCreateInfo.
144 * Caller is responsible for allocation and cleanup of 'dst'.
146 static VkResult wine_vk_instance_convert_create_info(const VkInstanceCreateInfo *src,
147 VkInstanceCreateInfo *dst)
149 unsigned int i;
150 const char **enabled_extensions = NULL;
152 dst->sType = src->sType;
153 dst->flags = src->flags;
154 dst->pApplicationInfo = src->pApplicationInfo;
155 dst->pNext = src->pNext;
156 dst->enabledLayerCount = 0;
157 dst->ppEnabledLayerNames = NULL;
158 dst->enabledExtensionCount = 0;
159 dst->ppEnabledExtensionNames = NULL;
161 if (src->enabledExtensionCount > 0)
163 enabled_extensions = calloc(src->enabledExtensionCount, sizeof(*src->ppEnabledExtensionNames));
164 if (!enabled_extensions)
166 ERR("Failed to allocate memory for enabled extensions\n");
167 return VK_ERROR_OUT_OF_HOST_MEMORY;
170 for (i = 0; i < src->enabledExtensionCount; i++)
172 /* Substitute extension with MoltenVK ones else copy. Long-term, when we
173 * support more extensions, we should store these in a list.
175 if (!strcmp(src->ppEnabledExtensionNames[i], "VK_KHR_win32_surface"))
177 enabled_extensions[i] = pvkCreateMetalSurfaceEXT ? "VK_EXT_metal_surface" : "VK_MVK_macos_surface";
179 else
181 enabled_extensions[i] = src->ppEnabledExtensionNames[i];
184 dst->ppEnabledExtensionNames = enabled_extensions;
185 dst->enabledExtensionCount = src->enabledExtensionCount;
188 return VK_SUCCESS;
191 static void wine_vk_surface_destroy(VkInstance instance, struct wine_vk_surface *surface)
193 /* vkDestroySurfaceKHR must handle VK_NULL_HANDLE (0) for surface. */
194 if (!surface)
195 return;
197 pvkDestroySurfaceKHR(instance, surface->surface, NULL /* allocator */);
199 if (surface->view)
200 macdrv_view_release_metal_view(surface->view);
202 if (surface->device)
203 macdrv_release_metal_device(surface->device);
205 free(surface);
208 static VkResult macdrv_vkCreateInstance(const VkInstanceCreateInfo *create_info,
209 const VkAllocationCallbacks *allocator, VkInstance *instance)
211 VkInstanceCreateInfo create_info_host;
212 VkResult res;
213 TRACE("create_info %p, allocator %p, instance %p\n", create_info, allocator, instance);
215 if (allocator)
216 FIXME("Support for allocation callbacks not implemented yet\n");
218 /* Perform a second pass on converting VkInstanceCreateInfo. Winevulkan
219 * performed a first pass in which it handles everything except for WSI
220 * functionality such as VK_KHR_win32_surface. Handle this now.
222 res = wine_vk_instance_convert_create_info(create_info, &create_info_host);
223 if (res != VK_SUCCESS)
225 ERR("Failed to convert instance create info, res=%d\n", res);
226 return res;
229 res = pvkCreateInstance(&create_info_host, NULL /* allocator */, instance);
231 free((void *)create_info_host.ppEnabledExtensionNames);
232 return res;
235 static VkResult macdrv_vkCreateSwapchainKHR(VkDevice device,
236 const VkSwapchainCreateInfoKHR *create_info,
237 const VkAllocationCallbacks *allocator, VkSwapchainKHR *swapchain)
239 VkSwapchainCreateInfoKHR create_info_host;
240 TRACE("%p %p %p %p\n", device, create_info, allocator, swapchain);
242 if (allocator)
243 FIXME("Support for allocation callbacks not implemented yet\n");
245 create_info_host = *create_info;
246 create_info_host.surface = surface_from_handle(create_info->surface)->surface;
248 return pvkCreateSwapchainKHR(device, &create_info_host, NULL /* allocator */,
249 swapchain);
252 static VkResult macdrv_vkCreateWin32SurfaceKHR(VkInstance instance,
253 const VkWin32SurfaceCreateInfoKHR *create_info,
254 const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface)
256 VkResult res;
257 struct wine_vk_surface *mac_surface;
258 struct macdrv_win_data *data;
260 TRACE("%p %p %p %p\n", instance, create_info, allocator, surface);
262 if (allocator)
263 FIXME("Support for allocation callbacks not implemented yet\n");
265 if (!(data = get_win_data(create_info->hwnd)))
267 FIXME("DC for window %p of other process: not implemented\n", create_info->hwnd);
268 return VK_ERROR_INCOMPATIBLE_DRIVER;
271 mac_surface = calloc(1, sizeof(*mac_surface));
272 if (!mac_surface)
274 release_win_data(data);
275 return VK_ERROR_OUT_OF_HOST_MEMORY;
278 mac_surface->device = macdrv_create_metal_device();
279 if (!mac_surface->device)
281 ERR("Failed to allocate Metal device for hwnd=%p\n", create_info->hwnd);
282 res = VK_ERROR_OUT_OF_HOST_MEMORY;
283 goto err;
286 mac_surface->view = macdrv_view_create_metal_view(data->client_cocoa_view, mac_surface->device);
287 if (!mac_surface->view)
289 ERR("Failed to allocate Metal view for hwnd=%p\n", create_info->hwnd);
291 /* VK_KHR_win32_surface only allows out of host and device memory as errors. */
292 res = VK_ERROR_OUT_OF_HOST_MEMORY;
293 goto err;
296 if (pvkCreateMetalSurfaceEXT)
298 VkMetalSurfaceCreateInfoEXT create_info_host;
299 create_info_host.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
300 create_info_host.pNext = NULL;
301 create_info_host.flags = 0; /* reserved */
302 create_info_host.pLayer = macdrv_view_get_metal_layer(mac_surface->view);
304 res = pvkCreateMetalSurfaceEXT(instance, &create_info_host, NULL /* allocator */, &mac_surface->surface);
306 else
308 VkMacOSSurfaceCreateInfoMVK create_info_host;
309 create_info_host.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
310 create_info_host.pNext = NULL;
311 create_info_host.flags = 0; /* reserved */
312 create_info_host.pView = macdrv_view_get_metal_layer(mac_surface->view);
314 res = pvkCreateMacOSSurfaceMVK(instance, &create_info_host, NULL /* allocator */, &mac_surface->surface);
316 if (res != VK_SUCCESS)
318 ERR("Failed to create MoltenVK surface, res=%d\n", res);
319 goto err;
322 *surface = (uintptr_t)mac_surface;
324 release_win_data(data);
326 TRACE("Created surface=0x%s\n", wine_dbgstr_longlong(*surface));
327 return VK_SUCCESS;
329 err:
330 wine_vk_surface_destroy(instance, mac_surface);
331 release_win_data(data);
332 return res;
335 static void macdrv_vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *allocator)
337 TRACE("%p %p\n", instance, allocator);
339 if (allocator)
340 FIXME("Support for allocation callbacks not implemented yet\n");
342 pvkDestroyInstance(instance, NULL /* allocator */);
345 static void macdrv_vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
346 const VkAllocationCallbacks *allocator)
348 struct wine_vk_surface *mac_surface = surface_from_handle(surface);
350 TRACE("%p 0x%s %p\n", instance, wine_dbgstr_longlong(surface), allocator);
352 if (allocator)
353 FIXME("Support for allocation callbacks not implemented yet\n");
355 wine_vk_surface_destroy(instance, mac_surface);
358 static void macdrv_vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
359 const VkAllocationCallbacks *allocator)
361 TRACE("%p, 0x%s %p\n", device, wine_dbgstr_longlong(swapchain), allocator);
363 if (allocator)
364 FIXME("Support for allocation callbacks not implemented yet\n");
366 pvkDestroySwapchainKHR(device, swapchain, NULL /* allocator */);
369 static VkResult macdrv_vkEnumerateInstanceExtensionProperties(const char *layer_name,
370 uint32_t *count, VkExtensionProperties* properties)
372 unsigned int i;
373 BOOL seen_surface = FALSE;
374 VkResult res;
376 TRACE("layer_name %s, count %p, properties %p\n", debugstr_a(layer_name), count, properties);
378 /* This shouldn't get called with layer_name set, the ICD loader prevents it. */
379 if (layer_name)
381 ERR("Layer enumeration not supported from ICD.\n");
382 return VK_ERROR_LAYER_NOT_PRESENT;
385 /* We will return at most the same number of instance extensions reported by the host back to
386 * winevulkan. Along the way we may replace MoltenVK extensions with their win32 equivalents,
387 * or remove redundant extensions outright.
388 * Winevulkan will perform more detailed filtering as it knows whether it has thunks
389 * for a particular extension.
391 res = pvkEnumerateInstanceExtensionProperties(layer_name, count, properties);
392 if (!properties || res < 0)
393 return res;
395 for (i = 0; i < *count; i++)
397 /* For now the only MoltenVK extensions we need to fixup. Long-term we may need an array. */
398 if (!strcmp(properties[i].extensionName, "VK_MVK_macos_surface") ||
399 !strcmp(properties[i].extensionName, "VK_EXT_metal_surface"))
401 if (seen_surface)
403 /* If we've already seen a surface extension, just hide this one. */
404 memmove(properties + i, properties + i + 1, (*count - i - 1) * sizeof(*properties));
405 --*count;
406 --i;
407 continue;
409 TRACE("Substituting %s for VK_KHR_win32_surface\n", properties[i].extensionName);
411 snprintf(properties[i].extensionName, sizeof(properties[i].extensionName),
412 VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
413 properties[i].specVersion = VK_KHR_WIN32_SURFACE_SPEC_VERSION;
414 seen_surface = TRUE;
418 TRACE("Returning %u extensions.\n", *count);
419 return res;
422 static const char *wine_vk_native_fn_name(const char *name)
424 const char *create_surface_name =
425 pvkCreateMetalSurfaceEXT ? "vkCreateMetalSurfaceEXT" : "vkCreateMacOSSurfaceMVK";
427 if (!strcmp(name, "vkCreateWin32SurfaceKHR"))
428 return create_surface_name;
429 /* We just need something where non-NULL is returned if the correct extension is enabled.
430 * So since there is no native equivalent of this function check for the create
431 * surface function.
433 if (!strcmp(name, "vkGetPhysicalDeviceWin32PresentationSupportKHR"))
434 return create_surface_name;
436 return name;
439 static void *macdrv_vkGetDeviceProcAddr(VkDevice device, const char *name)
441 void *proc_addr;
443 TRACE("%p, %s\n", device, debugstr_a(name));
445 if (!pvkGetDeviceProcAddr(device, wine_vk_native_fn_name(name)))
446 return NULL;
448 if ((proc_addr = macdrv_get_vk_device_proc_addr(name)))
449 return proc_addr;
451 return pvkGetDeviceProcAddr(device, name);
454 static void *macdrv_vkGetInstanceProcAddr(VkInstance instance, const char *name)
456 void *proc_addr;
458 TRACE("%p, %s\n", instance, debugstr_a(name));
460 if (!pvkGetInstanceProcAddr(instance, wine_vk_native_fn_name(name)))
461 return NULL;
463 if ((proc_addr = macdrv_get_vk_instance_proc_addr(instance, name)))
464 return proc_addr;
466 return pvkGetInstanceProcAddr(instance, name);
469 static VkResult macdrv_vkGetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice phys_dev,
470 const VkPhysicalDeviceSurfaceInfo2KHR *surface_info, VkSurfaceCapabilities2KHR *capabilities)
472 VkPhysicalDeviceSurfaceInfo2KHR surface_info_host;
474 TRACE("%p, %p, %p\n", phys_dev, surface_info, capabilities);
476 surface_info_host = *surface_info;
477 surface_info_host.surface = surface_from_handle(surface_info->surface)->surface;
479 return pvkGetPhysicalDeviceSurfaceCapabilities2KHR(phys_dev, &surface_info_host, capabilities);
482 static VkResult macdrv_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice phys_dev,
483 VkSurfaceKHR surface, VkSurfaceCapabilitiesKHR *capabilities)
485 struct wine_vk_surface *mac_surface = surface_from_handle(surface);
487 TRACE("%p, 0x%s, %p\n", phys_dev, wine_dbgstr_longlong(surface), capabilities);
489 return pvkGetPhysicalDeviceSurfaceCapabilitiesKHR(phys_dev, mac_surface->surface,
490 capabilities);
493 static VkResult macdrv_vkGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice phys_dev,
494 const VkPhysicalDeviceSurfaceInfo2KHR *surface_info, uint32_t *count, VkSurfaceFormat2KHR *formats)
496 VkPhysicalDeviceSurfaceInfo2KHR surface_info_host;
498 TRACE("%p, %p, %p, %p\n", phys_dev, surface_info, count, formats);
500 surface_info_host = *surface_info;
501 surface_info_host.surface = surface_from_handle(surface_info->surface)->surface;
503 return pvkGetPhysicalDeviceSurfaceFormats2KHR(phys_dev, &surface_info_host, count, formats);
506 static VkResult macdrv_vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice phys_dev,
507 VkSurfaceKHR surface, uint32_t *count, VkSurfaceFormatKHR *formats)
509 struct wine_vk_surface *mac_surface = surface_from_handle(surface);
511 TRACE("%p, 0x%s, %p, %p\n", phys_dev, wine_dbgstr_longlong(surface), count, formats);
513 return pvkGetPhysicalDeviceSurfaceFormatsKHR(phys_dev, mac_surface->surface,
514 count, formats);
517 static VkResult macdrv_vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice phys_dev,
518 VkSurfaceKHR surface, uint32_t *count, VkPresentModeKHR *modes)
520 struct wine_vk_surface *mac_surface = surface_from_handle(surface);
522 TRACE("%p, 0x%s, %p, %p\n", phys_dev, wine_dbgstr_longlong(surface), count, modes);
524 return pvkGetPhysicalDeviceSurfacePresentModesKHR(phys_dev, mac_surface->surface, count,
525 modes);
528 static VkResult macdrv_vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice phys_dev,
529 uint32_t index, VkSurfaceKHR surface, VkBool32 *supported)
531 struct wine_vk_surface *mac_surface = surface_from_handle(surface);
533 TRACE("%p, %u, 0x%s, %p\n", phys_dev, index, wine_dbgstr_longlong(surface), supported);
535 return pvkGetPhysicalDeviceSurfaceSupportKHR(phys_dev, index, mac_surface->surface,
536 supported);
539 static VkBool32 macdrv_vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice phys_dev,
540 uint32_t index)
542 TRACE("%p %u\n", phys_dev, index);
544 return VK_TRUE;
547 static VkResult macdrv_vkGetSwapchainImagesKHR(VkDevice device,
548 VkSwapchainKHR swapchain, uint32_t *count, VkImage *images)
550 TRACE("%p, 0x%s %p %p\n", device, wine_dbgstr_longlong(swapchain), count, images);
551 return pvkGetSwapchainImagesKHR(device, swapchain, count, images);
554 static VkResult macdrv_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *present_info)
556 TRACE("%p, %p\n", queue, present_info);
557 VkResult res = pvkQueuePresentKHR(queue, present_info);
559 if (TRACE_ON(fps))
561 static unsigned long frames, frames_total;
562 static long prev_time, start_time;
563 DWORD time;
565 time = NtGetTickCount();
566 frames++;
567 frames_total++;
568 if (time - prev_time > 1500)
570 TRACE_(fps)("%p @ approx %.2ffps, total %.2ffps\n",
571 queue, 1000.0 * frames / (time - prev_time),
572 1000.0 * frames_total / (time - start_time));
573 prev_time = time;
574 frames = 0;
575 if (!start_time)
576 start_time = time;
580 return res;
583 static VkSurfaceKHR macdrv_wine_get_native_surface(VkSurfaceKHR surface)
585 struct wine_vk_surface *mac_surface = surface_from_handle(surface);
587 TRACE("0x%s\n", wine_dbgstr_longlong(surface));
589 return mac_surface->surface;
592 static const struct vulkan_funcs vulkan_funcs =
594 macdrv_vkCreateInstance,
595 macdrv_vkCreateSwapchainKHR,
596 macdrv_vkCreateWin32SurfaceKHR,
597 macdrv_vkDestroyInstance,
598 macdrv_vkDestroySurfaceKHR,
599 macdrv_vkDestroySwapchainKHR,
600 macdrv_vkEnumerateInstanceExtensionProperties,
601 NULL,
602 macdrv_vkGetDeviceProcAddr,
603 macdrv_vkGetInstanceProcAddr,
604 NULL,
605 macdrv_vkGetPhysicalDeviceSurfaceCapabilities2KHR,
606 macdrv_vkGetPhysicalDeviceSurfaceCapabilitiesKHR,
607 macdrv_vkGetPhysicalDeviceSurfaceFormats2KHR,
608 macdrv_vkGetPhysicalDeviceSurfaceFormatsKHR,
609 macdrv_vkGetPhysicalDeviceSurfacePresentModesKHR,
610 macdrv_vkGetPhysicalDeviceSurfaceSupportKHR,
611 macdrv_vkGetPhysicalDeviceWin32PresentationSupportKHR,
612 macdrv_vkGetSwapchainImagesKHR,
613 macdrv_vkQueuePresentKHR,
615 macdrv_wine_get_native_surface,
618 static void *macdrv_get_vk_device_proc_addr(const char *name)
620 return get_vulkan_driver_device_proc_addr(&vulkan_funcs, name);
623 static void *macdrv_get_vk_instance_proc_addr(VkInstance instance, const char *name)
625 return get_vulkan_driver_instance_proc_addr(&vulkan_funcs, instance, name);
628 static const struct vulkan_funcs *get_vulkan_driver(UINT version)
630 static pthread_once_t init_once = PTHREAD_ONCE_INIT;
632 if (version != WINE_VULKAN_DRIVER_VERSION)
634 ERR("version mismatch, vulkan wants %u but driver has %u\n", version, WINE_VULKAN_DRIVER_VERSION);
635 return NULL;
638 pthread_once(&init_once, wine_vk_init);
639 if (vulkan_handle)
640 return &vulkan_funcs;
642 return NULL;
645 #else /* No vulkan */
647 static const struct vulkan_funcs *get_vulkan_driver(UINT version)
649 ERR("Wine was built without Vulkan support.\n");
650 return NULL;
653 #endif /* SONAME_LIBMOLTENVK */
655 const struct vulkan_funcs *macdrv_wine_get_vulkan_driver(UINT version)
657 return get_vulkan_driver( version );