src/vulkan.c
Go to the documentation of this file.
1 //========================================================================
2 // GLFW 3.3 - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2002-2006 Marcus Geelnard
5 // Copyright (c) 2006-2016 Camilla Löwy <elmindreda@glfw.org>
6 //
7 // This software is provided 'as-is', without any express or implied
8 // warranty. In no event will the authors be held liable for any damages
9 // arising from the use of this software.
10 //
11 // Permission is granted to anyone to use this software for any purpose,
12 // including commercial applications, and to alter it and redistribute it
13 // freely, subject to the following restrictions:
14 //
15 // 1. The origin of this software must not be misrepresented; you must not
16 // claim that you wrote the original software. If you use this software
17 // in a product, an acknowledgment in the product documentation would
18 // be appreciated but is not required.
19 //
20 // 2. Altered source versions must be plainly marked as such, and must not
21 // be misrepresented as being the original software.
22 //
23 // 3. This notice may not be removed or altered from any source
24 // distribution.
25 //
26 //========================================================================
27 
28 #include "internal.h"
29 
30 #include <assert.h>
31 #include <string.h>
32 #include <stdlib.h>
33 
34 #define _GLFW_FIND_LOADER 1
35 #define _GLFW_REQUIRE_LOADER 2
36 
37 
41 
43 {
44  VkResult err;
46  uint32_t i, count;
47 
48  if (_glfw.vk.available)
49  return GLFW_TRUE;
50 
51 #if !defined(_GLFW_VULKAN_STATIC)
52 #if defined(_GLFW_VULKAN_LIBRARY)
53  _glfw.vk.handle = _glfw_dlopen(_GLFW_VULKAN_LIBRARY);
54 #elif defined(_GLFW_WIN32)
55  _glfw.vk.handle = _glfw_dlopen("vulkan-1.dll");
56 #elif defined(_GLFW_COCOA)
57  _glfw.vk.handle = _glfw_dlopen("libvulkan.1.dylib");
58 #else
59  _glfw.vk.handle = _glfw_dlopen("libvulkan.so.1");
60 #endif
61  if (!_glfw.vk.handle)
62  {
63  if (mode == _GLFW_REQUIRE_LOADER)
64  _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: Loader not found");
65 
66  return GLFW_FALSE;
67  }
68 
70  _glfw_dlsym(_glfw.vk.handle, "vkGetInstanceProcAddr");
72  {
74  "Vulkan: Loader does not export vkGetInstanceProcAddr");
75 
77  return GLFW_FALSE;
78  }
79 
81  vkGetInstanceProcAddr(NULL, "vkEnumerateInstanceExtensionProperties");
83  {
85  "Vulkan: Failed to retrieve vkEnumerateInstanceExtensionProperties");
86 
88  return GLFW_FALSE;
89  }
90 #endif // _GLFW_VULKAN_STATIC
91 
93  if (err)
94  {
95  // NOTE: This happens on systems with a loader but without any Vulkan ICD
96  if (mode == _GLFW_REQUIRE_LOADER)
97  {
99  "Vulkan: Failed to query instance extension count: %s",
101  }
102 
104  return GLFW_FALSE;
105  }
106 
107  ep = calloc(count, sizeof(VkExtensionProperties));
108 
109  err = vkEnumerateInstanceExtensionProperties(NULL, &count, ep);
110  if (err)
111  {
113  "Vulkan: Failed to query instance extensions: %s",
115 
116  free(ep);
118  return GLFW_FALSE;
119  }
120 
121  for (i = 0; i < count; i++)
122  {
123  if (strcmp(ep[i].extensionName, "VK_KHR_surface") == 0)
125 #if defined(_GLFW_WIN32)
126  else if (strcmp(ep[i].extensionName, "VK_KHR_win32_surface") == 0)
127  _glfw.vk.KHR_win32_surface = GLFW_TRUE;
128 #elif defined(_GLFW_COCOA)
129  else if (strcmp(ep[i].extensionName, "VK_MVK_macos_surface") == 0)
130  _glfw.vk.MVK_macos_surface = GLFW_TRUE;
131 #elif defined(_GLFW_X11)
132  else if (strcmp(ep[i].extensionName, "VK_KHR_xlib_surface") == 0)
133  _glfw.vk.KHR_xlib_surface = GLFW_TRUE;
134  else if (strcmp(ep[i].extensionName, "VK_KHR_xcb_surface") == 0)
135  _glfw.vk.KHR_xcb_surface = GLFW_TRUE;
136 #elif defined(_GLFW_WAYLAND)
137  else if (strcmp(ep[i].extensionName, "VK_KHR_wayland_surface") == 0)
138  _glfw.vk.KHR_wayland_surface = GLFW_TRUE;
139 #endif
140  }
141 
142  free(ep);
143 
145 
147 
148  return GLFW_TRUE;
149 }
150 
152 {
153 #if !defined(_GLFW_VULKAN_STATIC)
154  if (_glfw.vk.handle)
156 #endif
157 }
158 
160 {
161  switch (result)
162  {
163  case VK_SUCCESS:
164  return "Success";
165  case VK_NOT_READY:
166  return "A fence or query has not yet completed";
167  case VK_TIMEOUT:
168  return "A wait operation has not completed in the specified time";
169  case VK_EVENT_SET:
170  return "An event is signaled";
171  case VK_EVENT_RESET:
172  return "An event is unsignaled";
173  case VK_INCOMPLETE:
174  return "A return array was too small for the result";
176  return "A host memory allocation has failed";
178  return "A device memory allocation has failed";
180  return "Initialization of an object could not be completed for implementation-specific reasons";
182  return "The logical or physical device has been lost";
184  return "Mapping of a memory object has failed";
186  return "A requested layer is not present or could not be loaded";
188  return "A requested extension is not supported";
190  return "A requested feature is not supported";
192  return "The requested version of Vulkan is not supported by the driver or is otherwise incompatible";
194  return "Too many objects of the type have already been created";
196  return "A requested format is not supported on this device";
198  return "A surface is no longer available";
199  case VK_SUBOPTIMAL_KHR:
200  return "A swapchain no longer matches the surface properties exactly, but can still be used";
202  return "A surface has changed in such a way that it is no longer compatible with the swapchain";
204  return "The display used by a swapchain does not use the same presentable image layout";
206  return "The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API";
208  return "A validation layer found an error";
209  default:
210  return "ERROR: UNKNOWN VULKAN ERROR";
211  }
212 }
213 
214 
218 
220 {
223 }
224 
226 {
227  assert(count != NULL);
228 
229  *count = 0;
230 
232 
234  return NULL;
235 
236  if (!_glfw.vk.extensions[0])
237  return NULL;
238 
239  *count = 2;
240  return (const char**) _glfw.vk.extensions;
241 }
242 
244  const char* procname)
245 {
246  GLFWvkproc proc;
247  assert(procname != NULL);
248 
250 
252  return NULL;
253 
254  proc = (GLFWvkproc) vkGetInstanceProcAddr(instance, procname);
255 #if defined(_GLFW_VULKAN_STATIC)
256  if (!proc)
257  {
258  if (strcmp(procname, "vkGetInstanceProcAddr") == 0)
260  }
261 #else
262  if (!proc)
263  proc = (GLFWvkproc) _glfw_dlsym(_glfw.vk.handle, procname);
264 #endif
265 
266  return proc;
267 }
268 
271  uint32_t queuefamily)
272 {
273  assert(instance != VK_NULL_HANDLE);
274  assert(device != VK_NULL_HANDLE);
275 
277 
279  return GLFW_FALSE;
280 
281  if (!_glfw.vk.extensions[0])
282  {
284  "Vulkan: Window surface creation extensions not found");
285  return GLFW_FALSE;
286  }
287 
289  device,
290  queuefamily);
291 }
292 
295  const VkAllocationCallbacks* allocator,
296  VkSurfaceKHR* surface)
297 {
298  _GLFWwindow* window = (_GLFWwindow*) handle;
299  assert(instance != VK_NULL_HANDLE);
300  assert(window != NULL);
301  assert(surface != NULL);
302 
303  *surface = VK_NULL_HANDLE;
304 
306 
309 
310  if (!_glfw.vk.extensions[0])
311  {
313  "Vulkan: Window surface creation extensions not found");
315  }
316 
317  if (window->context.client != GLFW_NO_API)
318  {
320  "Vulkan: Window surface creation requires the window to have the client API set to GLFW_NO_API");
322  }
323 
324  return _glfwPlatformCreateWindowSurface(instance, window, allocator, surface);
325 }
326 
#define VK_NULL_HANDLE
Definition: vulkan_core.h:49
VkResult
Definition: vulkan_core.h:122
GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char *procname)
Definition: src/vulkan.c:243
#define GLFWAPI
Definition: glfw3.h:240
PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties
Definition: internal.h:550
GLuint64 GLenum void * handle
Definition: glext.h:7785
GLFWAPI int glfwVulkanSupported(void)
Returns whether the Vulkan loader and an ICD have been found.
Definition: src/vulkan.c:219
GLFWbool _glfwInitVulkan(int mode)
Definition: src/vulkan.c:42
#define GLFW_FALSE
Zero.
Definition: glfw3.h:287
#define _glfw_dlopen(name)
struct _GLFWlibrary::@29 vk
#define GLFW_API_UNAVAILABLE
GLFW could not find support for the requested API on the system.
Definition: glfw3.h:698
_GLFWcontext context
Definition: internal.h:394
int GLFWbool
Definition: internal.h:61
void * handle
Definition: internal.h:547
void(* GLFWvkproc)(void)
Vulkan API function pointer type.
Definition: glfw3.h:1113
GLFWbool KHR_surface
Definition: internal.h:553
GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily)
Definition: src/vulkan.c:269
#define _glfw_dlclose(handle)
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)
Definition: internal.h:210
VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties)
GLenum mode
_GLFWlibrary _glfw
Definition: init.c:44
void * VkInstance
Definition: internal.h:118
unsigned int uint32_t
Definition: stdint.h:80
void * VkPhysicalDevice
Definition: internal.h:119
PFN_vkGetInstanceProcAddr GetInstanceProcAddr
Definition: internal.h:551
GLFWbool available
Definition: internal.h:546
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *pName)
uint64_t VkSurfaceKHR
Definition: internal.h:120
void _glfwInputError(int code, const char *format,...)
Definition: init.c:129
const char * _glfwGetVulkanResultString(VkResult result)
Definition: src/vulkan.c:159
#define GLFW_TRUE
One.
Definition: glfw3.h:279
#define GLFW_INVALID_VALUE
One of the arguments to the function was an invalid value.
Definition: glfw3.h:674
VkResult(VKAPI_PTR * PFN_vkEnumerateInstanceExtensionProperties)(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties)
Definition: vulkan_core.h:2717
char * extensions[2]
Definition: internal.h:548
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)
Definition: vulkan_core.h:2713
GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow *handle, const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface)
Definition: src/vulkan.c:293
void _glfwPlatformGetRequiredInstanceExtensions(char **extensions)
Definition: null_window.c:302
GLint GLsizei count
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily)
Definition: null_window.c:306
#define _GLFW_FIND_LOADER
Definition: src/vulkan.c:34
#define NULL
Definition: tinycthread.c:47
int i
GLFWAPI const char ** glfwGetRequiredInstanceExtensions(uint32_t *count)
Returns the Vulkan instance extensions required by GLFW.
Definition: src/vulkan.c:225
void _glfwTerminateVulkan(void)
Definition: src/vulkan.c:151
#define _GLFW_REQUIRE_LOADER
Definition: src/vulkan.c:35
#define _glfw_dlsym(handle, name)
VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, _GLFWwindow *window, const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface)
Definition: null_window.c:313
GLuint64EXT * result
Definition: glext.h:10921
auto device
Definition: pyrs_net.cpp:17
struct GLFWwindow GLFWwindow
#define GLFW_NO_API
Definition: glfw3.h:989


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:14