Wise&mystical  1.0
Project about Europe
Loading...
Searching...
No Matches
vulkan.c
Go to the documentation of this file.
1//========================================================================
2// GLFW 3.4 - www.glfw.org
3//------------------------------------------------------------------------
4// Copyright (c) 2002-2006 Marcus Geelnard
5// Copyright (c) 2006-2018 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// Please use C89 style variable declarations in this file because VS 2010
28//========================================================================
29
30#include "internal.h"
31
32#include <assert.h>
33#include <string.h>
34#include <stdlib.h>
35
36#define _GLFW_FIND_LOADER 1
37#define _GLFW_REQUIRE_LOADER 2
38
39
43
45{
46 VkResult err;
48 uint32_t i, count;
49
50 if (_glfw.vk.available)
51 return GLFW_TRUE;
52
53#if !defined(_GLFW_VULKAN_STATIC)
54#if defined(_GLFW_VULKAN_LIBRARY)
55 _glfw.vk.handle = _glfw_dlopen(_GLFW_VULKAN_LIBRARY);
56#elif defined(_GLFW_WIN32)
57 _glfw.vk.handle = _glfw_dlopen("vulkan-1.dll");
58#elif defined(_GLFW_COCOA)
59 _glfw.vk.handle = _glfw_dlopen("libvulkan.1.dylib");
60 if (!_glfw.vk.handle)
62#else
63 _glfw.vk.handle = _glfw_dlopen("libvulkan.so.1");
64#endif
65 if (!_glfw.vk.handle)
66 {
67 if (mode == _GLFW_REQUIRE_LOADER)
68 _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: Loader not found");
69
70 return GLFW_FALSE;
71 }
72
74 _glfw_dlsym(_glfw.vk.handle, "vkGetInstanceProcAddr");
76 {
78 "Vulkan: Loader does not export vkGetInstanceProcAddr");
79
81 return GLFW_FALSE;
82 }
83
85 vkGetInstanceProcAddr(NULL, "vkEnumerateInstanceExtensionProperties");
87 {
89 "Vulkan: Failed to retrieve vkEnumerateInstanceExtensionProperties");
90
92 return GLFW_FALSE;
93 }
94#endif // _GLFW_VULKAN_STATIC
95
97 if (err)
98 {
99 // NOTE: This happens on systems with a loader but without any Vulkan ICD
100 if (mode == _GLFW_REQUIRE_LOADER)
101 {
103 "Vulkan: Failed to query instance extension count: %s",
105 }
106
108 return GLFW_FALSE;
109 }
110
111 ep = calloc(count, sizeof(VkExtensionProperties));
112
114 if (err)
115 {
117 "Vulkan: Failed to query instance extensions: %s",
119
120 free(ep);
122 return GLFW_FALSE;
123 }
124
125 for (i = 0; i < count; i++)
126 {
127 if (strcmp(ep[i].extensionName, "VK_KHR_surface") == 0)
129#if defined(_GLFW_WIN32)
130 else if (strcmp(ep[i].extensionName, "VK_KHR_win32_surface") == 0)
131 _glfw.vk.KHR_win32_surface = GLFW_TRUE;
132#elif defined(_GLFW_COCOA)
133 else if (strcmp(ep[i].extensionName, "VK_MVK_macos_surface") == 0)
134 _glfw.vk.MVK_macos_surface = GLFW_TRUE;
135 else if (strcmp(ep[i].extensionName, "VK_EXT_metal_surface") == 0)
136 _glfw.vk.EXT_metal_surface = GLFW_TRUE;
137#elif defined(_GLFW_X11)
138 else if (strcmp(ep[i].extensionName, "VK_KHR_xlib_surface") == 0)
139 _glfw.vk.KHR_xlib_surface = GLFW_TRUE;
140 else if (strcmp(ep[i].extensionName, "VK_KHR_xcb_surface") == 0)
141 _glfw.vk.KHR_xcb_surface = GLFW_TRUE;
142#elif defined(_GLFW_WAYLAND)
143 else if (strcmp(ep[i].extensionName, "VK_KHR_wayland_surface") == 0)
144 _glfw.vk.KHR_wayland_surface = GLFW_TRUE;
145#endif
146 }
147
148 free(ep);
149
151
153
154 return GLFW_TRUE;
155}
156
158{
159#if !defined(_GLFW_VULKAN_STATIC)
160 if (_glfw.vk.handle)
162#endif
163}
164
166{
167 switch (result)
168 {
169 case VK_SUCCESS:
170 return "Success";
171 case VK_NOT_READY:
172 return "A fence or query has not yet completed";
173 case VK_TIMEOUT:
174 return "A wait operation has not completed in the specified time";
175 case VK_EVENT_SET:
176 return "An event is signaled";
177 case VK_EVENT_RESET:
178 return "An event is unsignaled";
179 case VK_INCOMPLETE:
180 return "A return array was too small for the result";
182 return "A host memory allocation has failed";
184 return "A device memory allocation has failed";
186 return "Initialization of an object could not be completed for implementation-specific reasons";
188 return "The logical or physical device has been lost";
190 return "Mapping of a memory object has failed";
192 return "A requested layer is not present or could not be loaded";
194 return "A requested extension is not supported";
196 return "A requested feature is not supported";
198 return "The requested version of Vulkan is not supported by the driver or is otherwise incompatible";
200 return "Too many objects of the type have already been created";
202 return "A requested format is not supported on this device";
204 return "A surface is no longer available";
206 return "A swapchain no longer matches the surface properties exactly, but can still be used";
208 return "A surface has changed in such a way that it is no longer compatible with the swapchain";
210 return "The display used by a swapchain does not use the same presentable image layout";
212 return "The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API";
214 return "A validation layer found an error";
215 default:
216 return "ERROR: UNKNOWN VULKAN ERROR";
217 }
218}
219
220
224
226{
229}
230
232{
233 assert(count != NULL);
234
235 *count = 0;
236
238
240 return NULL;
241
242 if (!_glfw.vk.extensions[0])
243 return NULL;
244
245 *count = 2;
246 return (const char**) _glfw.vk.extensions;
247}
248
250 const char* procname)
251{
252 GLFWvkproc proc;
253 assert(procname != NULL);
254
256
258 return NULL;
259
260 proc = (GLFWvkproc) vkGetInstanceProcAddr(instance, procname);
261#if defined(_GLFW_VULKAN_STATIC)
262 if (!proc)
263 {
264 if (strcmp(procname, "vkGetInstanceProcAddr") == 0)
266 }
267#else
268 if (!proc)
269 proc = (GLFWvkproc) _glfw_dlsym(_glfw.vk.handle, procname);
270#endif
271
272 return proc;
273}
274
276 VkPhysicalDevice device,
277 uint32_t queuefamily)
278{
279 assert(instance != VK_NULL_HANDLE);
280 assert(device != VK_NULL_HANDLE);
281
283
285 return GLFW_FALSE;
286
287 if (!_glfw.vk.extensions[0])
288 {
290 "Vulkan: Window surface creation extensions not found");
291 return GLFW_FALSE;
292 }
293
295 device,
296 queuefamily);
297}
298
300 GLFWwindow* handle,
301 const VkAllocationCallbacks* allocator,
302 VkSurfaceKHR* surface)
303{
304 _GLFWwindow* window = (_GLFWwindow*) handle;
305 assert(instance != VK_NULL_HANDLE);
306 assert(window != NULL);
307 assert(surface != NULL);
308
309 *surface = VK_NULL_HANDLE;
310
312
315
316 if (!_glfw.vk.extensions[0])
317 {
319 "Vulkan: Window surface creation extensions not found");
321 }
322
323 if (window->context.client != GLFW_NO_API)
324 {
326 "Vulkan: Window surface creation requires the window to have the client API set to GLFW_NO_API");
328 }
329
330 return _glfwPlatformCreateWindowSurface(instance, window, allocator, surface);
331}
332
void * _glfwLoadLocalVulkanLoaderNS(void)
Definition: cocoa_init.m:466
#define _glfw_dlopen(name)
#define _glfw_dlsym(handle, name)
#define _glfw_dlclose(handle)
void _glfwPlatformGetRequiredInstanceExtensions(char **extensions)
VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, _GLFWwindow *window, const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface)
int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily)
#define GLFWAPI
Definition: glfw3.h:269
#define GLFW_NO_API
Definition: glfw3.h:1086
#define GLFW_API_UNAVAILABLE
GLFW could not find support for the requested API on the system.
Definition: glfw3.h:730
#define GLFW_INVALID_VALUE
One of the arguments to the function was an invalid value.
Definition: glfw3.h:706
#define GLFW_TRUE
One.
Definition: glfw3.h:310
#define GLFW_FALSE
Zero.
Definition: glfw3.h:319
void(* GLFWvkproc)(void)
Vulkan API function pointer type.
Definition: glfw3.h:1295
GLFWAPI int glfwVulkanSupported(void)
Returns whether the Vulkan loader and an ICD have been found.
Definition: vulkan.c:225
GLFWAPI const char ** glfwGetRequiredInstanceExtensions(uint32_t *count)
Returns the Vulkan instance extensions required by GLFW.
Definition: vulkan.c:231
struct GLFWwindow GLFWwindow
Opaque window object.
Definition: glfw3.h:1319
_GLFWlibrary _glfw
Definition: init.c:46
void _glfwInputError(int code, const char *format,...)
Definition: init.c:160
uint64_t VkSurfaceKHR
Definition: internal.h:120
void * VkInstance
Definition: internal.h:118
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)
Definition: internal.h:214
void * VkPhysicalDevice
Definition: internal.h:119
@ VK_ERROR_INCOMPATIBLE_DISPLAY_KHR
Definition: internal.h:157
int GLFWbool
Definition: internal.h:61
#define NULL
Definition: miniaudio.h:3718
unsigned int uint32_t
Definition: stdint.h:80
struct _GLFWlibrary::@25 vk
PFN_vkGetInstanceProcAddr GetInstanceProcAddr
Definition: internal.h:567
GLFWbool KHR_surface
Definition: internal.h:569
void * handle
Definition: internal.h:563
GLFWbool available
Definition: internal.h:562
char * extensions[2]
Definition: internal.h:564
PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties
Definition: internal.h:566
_GLFWcontext context
Definition: internal.h:409
#define _GLFW_FIND_LOADER
Definition: vulkan.c:36
GLFWbool _glfwInitVulkan(int mode)
Definition: vulkan.c:44
GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow *handle, const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface)
Definition: vulkan.c:299
GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily)
Definition: vulkan.c:275
void _glfwTerminateVulkan(void)
Definition: vulkan.c:157
const char * _glfwGetVulkanResultString(VkResult result)
Definition: vulkan.c:165
GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char *procname)
Definition: vulkan.c:249
#define _GLFW_REQUIRE_LOADER
Definition: vulkan.c:37
PFN_vkVoidFunction(GLAD_API_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)
Definition: vulkan.h:3057
VkResult(GLAD_API_PTR * PFN_vkEnumerateInstanceExtensionProperties)(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties)
Definition: vulkan.h:3031
VkResult
Definition: vulkan.h:842
@ VK_ERROR_VALIDATION_FAILED_EXT
Definition: vulkan.h:867
@ VK_SUBOPTIMAL_KHR
Definition: vulkan.h:865
@ VK_ERROR_EXTENSION_NOT_PRESENT
Definition: vulkan.h:855
@ VK_INCOMPLETE
Definition: vulkan.h:848
@ VK_ERROR_DEVICE_LOST
Definition: vulkan.h:852
@ VK_SUCCESS
Definition: vulkan.h:843
@ VK_EVENT_SET
Definition: vulkan.h:846
@ VK_EVENT_RESET
Definition: vulkan.h:847
@ VK_ERROR_OUT_OF_HOST_MEMORY
Definition: vulkan.h:849
@ VK_ERROR_INITIALIZATION_FAILED
Definition: vulkan.h:851
@ VK_ERROR_OUT_OF_DEVICE_MEMORY
Definition: vulkan.h:850
@ VK_ERROR_NATIVE_WINDOW_IN_USE_KHR
Definition: vulkan.h:864
@ VK_ERROR_OUT_OF_DATE_KHR
Definition: vulkan.h:866
@ VK_TIMEOUT
Definition: vulkan.h:845
@ VK_ERROR_FORMAT_NOT_SUPPORTED
Definition: vulkan.h:859
@ VK_ERROR_SURFACE_LOST_KHR
Definition: vulkan.h:863
@ VK_NOT_READY
Definition: vulkan.h:844
@ VK_ERROR_FEATURE_NOT_PRESENT
Definition: vulkan.h:856
@ VK_ERROR_TOO_MANY_OBJECTS
Definition: vulkan.h:858
@ VK_ERROR_MEMORY_MAP_FAILED
Definition: vulkan.h:853
@ VK_ERROR_LAYER_NOT_PRESENT
Definition: vulkan.h:854
@ VK_ERROR_INCOMPATIBLE_DRIVER
Definition: vulkan.h:857
#define VK_NULL_HANDLE
Definition: vulkan.h:208
#define vkGetInstanceProcAddr
Definition: vulkan.h:3378
#define vkEnumerateInstanceExtensionProperties
Definition: vulkan.h:3326