From fef25ea9346d5fa4cc37d3957f7db48c7bac708e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 31 Oct 2016 01:42:04 +0100 Subject: [PATCH] Emit all Vulkan init errors from init function --- src/internal.h | 2 +- src/vulkan.c | 32 ++++++++++++++------------------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/internal.h b/src/internal.h index a623262e..77af1d1c 100644 --- a/src/internal.h +++ b/src/internal.h @@ -1060,7 +1060,7 @@ GLFWbool _glfwIsPrintable(int key); /*! @ingroup utility */ -GLFWbool _glfwInitVulkan(void); +GLFWbool _glfwInitVulkan(int mode); /*! @ingroup utility */ diff --git a/src/vulkan.c b/src/vulkan.c index 2d3bfe6c..9908511f 100644 --- a/src/vulkan.c +++ b/src/vulkan.c @@ -31,12 +31,15 @@ #include #include +#define _GLFW_FIND_LOADER 1 +#define _GLFW_REQUIRE_LOADER 2 + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// -GLFWbool _glfwInitVulkan(void) +GLFWbool _glfwInitVulkan(int mode) { VkResult err; VkExtensionProperties* ep; @@ -54,7 +57,12 @@ GLFWbool _glfwInitVulkan(void) _glfw.vk.handle = _glfw_dlopen(name); if (!_glfw.vk.handle) + { + if (mode == _GLFW_REQUIRE_LOADER) + _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: Loader not found"); + return GLFW_FALSE; + } _glfw.vk.GetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) _glfw_dlsym(_glfw.vk.handle, "vkGetInstanceProcAddr"); @@ -205,7 +213,7 @@ const char* _glfwGetVulkanResultString(VkResult result) GLFWAPI int glfwVulkanSupported(void) { _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); - return _glfwInitVulkan(); + return _glfwInitVulkan(_GLFW_FIND_LOADER); } GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count) @@ -214,11 +222,8 @@ GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count) _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - if (!_glfwInitVulkan()) - { - _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: API not available"); + if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) return NULL; - } *count = 2; return (const char**) _glfw.vk.extensions; @@ -231,11 +236,8 @@ GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, _GLFW_REQUIRE_INIT_OR_RETURN(NULL); - if (!_glfwInitVulkan()) - { - _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: API not available"); + if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) return NULL; - } proc = (GLFWvkproc) vkGetInstanceProcAddr(instance, procname); #if !defined(_GLFW_VULKAN_STATIC) @@ -252,11 +254,8 @@ GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, { _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); - if (!_glfwInitVulkan()) - { - _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: API not available"); + if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) return GLFW_FALSE; - } if (!_glfw.vk.extensions[0]) { @@ -283,11 +282,8 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, _GLFW_REQUIRE_INIT_OR_RETURN(VK_ERROR_INITIALIZATION_FAILED); - if (!_glfwInitVulkan()) - { - _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: API not available"); + if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) return VK_ERROR_INITIALIZATION_FAILED; - } if (!_glfw.vk.extensions[0]) {