SDL  2.0
SDL_vulkan_utils.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../SDL_internal.h"
22 
23 #include "SDL_vulkan_internal.h"
24 #include "SDL_error.h"
25 
26 #if SDL_VIDEO_VULKAN
27 
28 const char *SDL_Vulkan_GetResultString(VkResult result)
29 {
30  switch((int)result)
31  {
32  case VK_SUCCESS:
33  return "VK_SUCCESS";
34  case VK_NOT_READY:
35  return "VK_NOT_READY";
36  case VK_TIMEOUT:
37  return "VK_TIMEOUT";
38  case VK_EVENT_SET:
39  return "VK_EVENT_SET";
40  case VK_EVENT_RESET:
41  return "VK_EVENT_RESET";
42  case VK_INCOMPLETE:
43  return "VK_INCOMPLETE";
45  return "VK_ERROR_OUT_OF_HOST_MEMORY";
47  return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
49  return "VK_ERROR_INITIALIZATION_FAILED";
51  return "VK_ERROR_DEVICE_LOST";
53  return "VK_ERROR_MEMORY_MAP_FAILED";
55  return "VK_ERROR_LAYER_NOT_PRESENT";
57  return "VK_ERROR_EXTENSION_NOT_PRESENT";
59  return "VK_ERROR_FEATURE_NOT_PRESENT";
61  return "VK_ERROR_INCOMPATIBLE_DRIVER";
63  return "VK_ERROR_TOO_MANY_OBJECTS";
65  return "VK_ERROR_FORMAT_NOT_SUPPORTED";
67  return "VK_ERROR_FRAGMENTED_POOL";
69  return "VK_ERROR_SURFACE_LOST_KHR";
71  return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
72  case VK_SUBOPTIMAL_KHR:
73  return "VK_SUBOPTIMAL_KHR";
75  return "VK_ERROR_OUT_OF_DATE_KHR";
77  return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
79  return "VK_ERROR_VALIDATION_FAILED_EXT";
81  return "VK_ERROR_OUT_OF_POOL_MEMORY_KHR";
83  return "VK_ERROR_INVALID_SHADER_NV";
84  case VK_RESULT_MAX_ENUM:
86  break;
87  }
88  if(result < 0)
89  return "VK_ERROR_<Unknown>";
90  return "VK_<Unknown>";
91 }
92 
93 VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
95  Uint32 *extensionCount)
96 {
97  Uint32 count = 0;
100  if(result == VK_ERROR_INCOMPATIBLE_DRIVER)
101  {
102  /* Avoid the ERR_MAX_STRLEN limit by passing part of the message
103  * as a string argument.
104  */
105  SDL_SetError(
106  "You probably don't have a working Vulkan driver installed. %s %s %s(%d)",
107  "Getting Vulkan extensions failed:",
108  "vkEnumerateInstanceExtensionProperties returned",
109  SDL_Vulkan_GetResultString(result),
110  (int)result);
111  return NULL;
112  }
113  else if(result != VK_SUCCESS)
114  {
115  SDL_SetError(
116  "Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned "
117  "%s(%d)",
118  SDL_Vulkan_GetResultString(result),
119  (int)result);
120  return NULL;
121  }
122  if(count == 0)
123  {
124  retval = SDL_calloc(1, sizeof(VkExtensionProperties)); // so we can return non-null
125  }
126  else
127  {
128  retval = SDL_calloc(count, sizeof(VkExtensionProperties));
129  }
130  if(!retval)
131  {
132  SDL_OutOfMemory();
133  return NULL;
134  }
135  result = vkEnumerateInstanceExtensionProperties(NULL, &count, retval);
136  if(result != VK_SUCCESS)
137  {
138  SDL_SetError(
139  "Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned "
140  "%s(%d)",
141  SDL_Vulkan_GetResultString(result),
142  (int)result);
143  SDL_free(retval);
144  return NULL;
145  }
146  *extensionCount = count;
147  return retval;
148 }
149 
150 SDL_bool SDL_Vulkan_GetInstanceExtensions_Helper(unsigned *userCount,
151  const char **userNames,
152  unsigned nameCount,
153  const char *const *names)
154 {
155  if (userNames) {
156  unsigned i;
157 
158  if (*userCount < nameCount) {
159  SDL_SetError("Output array for SDL_Vulkan_GetInstanceExtensions needs to be at least %d big", nameCount);
160  return SDL_FALSE;
161  }
162  for (i = 0; i < nameCount; i++) {
163  userNames[i] = names[i];
164  }
165  }
166  *userCount = nameCount;
167  return SDL_TRUE;
168 }
169 
170 #endif
171 
172 /* vi: set ts=4 sw=4 expandtab: */
GLuint64EXT * result
GLuint GLuint * names
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
uint32_t Uint32
Definition: SDL_stdinc.h:181
VkResult
Definition: vulkan.h:122
SDL_bool retval
VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties)
#define SDL_free
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:164
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_bool
Definition: SDL_stdinc.h:139
#define SDL_SetError
#define SDL_calloc
VkResult(VKAPI_PTR * PFN_vkEnumerateInstanceExtensionProperties)(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties)
Definition: vulkan.h:2488