From 5ff7d9505f2cb76b53424277f5308272e88544c5 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 22 Aug 2016 20:25:52 +0200 Subject: [PATCH] Simplify Vulkan extension checks Related to #478. --- src/cocoa_window.m | 4 +--- src/internal.h | 5 ++--- src/mir_window.c | 18 +++++------------- src/vulkan.c | 14 ++------------ src/win32_window.c | 18 +++++------------- src/wl_window.c | 18 +++++------------- src/x11_window.c | 19 +++++++------------ 7 files changed, 27 insertions(+), 69 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 5230786f..451cec2a 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1618,10 +1618,8 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) return _glfw.ns.clipboardString; } -char** _glfwPlatformGetRequiredInstanceExtensions(uint32_t* count) +void _glfwPlatformGetRequiredInstanceExtensions(char** extensions) { - *count = 0; - return NULL; } int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, diff --git a/src/internal.h b/src/internal.h index 0f35146b..51745213 100644 --- a/src/internal.h +++ b/src/internal.h @@ -449,8 +449,7 @@ struct _GLFWlibrary struct { GLFWbool available; void* handle; - char** extensions; - uint32_t extensionCount; + char* extensions[2]; #if !defined(_GLFW_VULKAN_STATIC) PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties; PFN_vkGetInstanceProcAddr GetInstanceProcAddr; @@ -792,7 +791,7 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor); /*! @ingroup platform */ -char** _glfwPlatformGetRequiredInstanceExtensions(uint32_t* count); +void _glfwPlatformGetRequiredInstanceExtensions(char** extensions); /*! @ingroup platform */ diff --git a/src/mir_window.c b/src/mir_window.c index 7d7f6322..1a2a5d54 100644 --- a/src/mir_window.c +++ b/src/mir_window.c @@ -758,21 +758,13 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) return NULL; } -char** _glfwPlatformGetRequiredInstanceExtensions(uint32_t* count) +void _glfwPlatformGetRequiredInstanceExtensions(char** extensions) { - char** extensions; + if (!_glfw.vk.KHR_surface || !_glfw.vk.KHR_mir_surface) + return; - *count = 0; - - if (!_glfw.vk.KHR_mir_surface) - return NULL; - - extensions = calloc(2, sizeof(char*)); - extensions[0] = strdup("VK_KHR_surface"); - extensions[1] = strdup("VK_KHR_mir_surface"); - - *count = 2; - return extensions; + extensions[0] = "VK_KHR_surface"; + extensions[1] = "VK_KHR_mir_surface"; } int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, diff --git a/src/vulkan.c b/src/vulkan.c index a2d10b6a..49ca4446 100644 --- a/src/vulkan.c +++ b/src/vulkan.c @@ -124,23 +124,13 @@ GLFWbool _glfwInitVulkan(void) _glfw.vk.available = GLFW_TRUE; - if (_glfw.vk.KHR_surface) - { - _glfw.vk.extensions = - _glfwPlatformGetRequiredInstanceExtensions(&_glfw.vk.extensionCount); - } + _glfwPlatformGetRequiredInstanceExtensions(_glfw.vk.extensions); return GLFW_TRUE; } void _glfwTerminateVulkan(void) { - uint32_t i; - - for (i = 0; i < _glfw.vk.extensionCount; i++) - free(_glfw.vk.extensions[i]); - free(_glfw.vk.extensions); - if (_glfw.vk.handle) _glfw_dlclose(_glfw.vk.handle); } @@ -223,7 +213,7 @@ GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count) return NULL; } - *count = _glfw.vk.extensionCount; + *count = 2; return (const char**) _glfw.vk.extensions; } diff --git a/src/win32_window.c b/src/win32_window.c index 64c3d71a..0bd2e0c1 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1642,21 +1642,13 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) return _glfw.win32.clipboardString; } -char** _glfwPlatformGetRequiredInstanceExtensions(uint32_t* count) +void _glfwPlatformGetRequiredInstanceExtensions(char** extensions) { - char** extensions; + if (!_glfw.vk.KHR_surface || !_glfw.vk.KHR_win32_surface) + return; - *count = 0; - - if (!_glfw.vk.KHR_win32_surface) - return NULL; - - extensions = calloc(2, sizeof(char*)); - extensions[0] = strdup("VK_KHR_surface"); - extensions[1] = strdup("VK_KHR_win32_surface"); - - *count = 2; - return extensions; + extensions[0] = "VK_KHR_surface"; + extensions[1] = "VK_KHR_win32_surface"; } int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, diff --git a/src/wl_window.c b/src/wl_window.c index d633c661..fc7704e5 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -960,21 +960,13 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) return NULL; } -char** _glfwPlatformGetRequiredInstanceExtensions(uint32_t* count) +void _glfwPlatformGetRequiredInstanceExtensions(char** extensions) { - char** extensions; + if (!_glfw.vk.KHR_surface || !_glfw.vk.KHR_wayland_surface) + return; - *count = 0; - - if (!_glfw.vk.KHR_wayland_surface) - return NULL; - - extensions = calloc(2, sizeof(char*)); - extensions[0] = strdup("VK_KHR_surface"); - extensions[1] = strdup("VK_KHR_wayland_surface"); - - *count = 2; - return extensions; + extensions[0] = "VK_KHR_surface"; + extensions[1] = "VK_KHR_wayland_surface"; } int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, diff --git a/src/x11_window.c b/src/x11_window.c index 7542321d..e98d9834 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2303,28 +2303,23 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) return _glfw.x11.clipboardString; } -char** _glfwPlatformGetRequiredInstanceExtensions(uint32_t* count) +void _glfwPlatformGetRequiredInstanceExtensions(char** extensions) { - char** extensions; - - *count = 0; + if (!_glfw.vk.KHR_surface) + return; if (!_glfw.vk.KHR_xcb_surface || !_glfw.x11.x11xcb.handle) { if (!_glfw.vk.KHR_xlib_surface) - return NULL; + return; } - extensions = calloc(2, sizeof(char*)); - extensions[0] = strdup("VK_KHR_surface"); + extensions[0] = "VK_KHR_surface"; if (_glfw.vk.KHR_xcb_surface && _glfw.x11.x11xcb.handle) - extensions[1] = strdup("VK_KHR_xcb_surface"); + extensions[1] = "VK_KHR_xcb_surface"; else - extensions[1] = strdup("VK_KHR_xlib_surface"); - - *count = 2; - return extensions; + extensions[1] = "VK_KHR_xlib_surface"; } int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,