SDL_vulkan_utils.c
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../SDL_internal.h"
#include "SDL_vulkan_internal.h"
#include "SDL_error.h"
#if SDL_VIDEO_VULKAN
const char *SDL_Vulkan_GetResultString(VkResult result)
{
switch((int)result)
{
case VK_SUCCESS:
return "VK_SUCCESS";
case VK_NOT_READY:
return "VK_NOT_READY";
case VK_TIMEOUT:
return "VK_TIMEOUT";
case VK_EVENT_SET:
return "VK_EVENT_SET";
case VK_EVENT_RESET:
return "VK_EVENT_RESET";
case VK_INCOMPLETE:
return "VK_INCOMPLETE";
case VK_ERROR_OUT_OF_HOST_MEMORY:
return "VK_ERROR_OUT_OF_HOST_MEMORY";
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
case VK_ERROR_INITIALIZATION_FAILED:
return "VK_ERROR_INITIALIZATION_FAILED";
case VK_ERROR_DEVICE_LOST:
return "VK_ERROR_DEVICE_LOST";
case VK_ERROR_MEMORY_MAP_FAILED:
return "VK_ERROR_MEMORY_MAP_FAILED";
case VK_ERROR_LAYER_NOT_PRESENT:
return "VK_ERROR_LAYER_NOT_PRESENT";
case VK_ERROR_EXTENSION_NOT_PRESENT:
return "VK_ERROR_EXTENSION_NOT_PRESENT";
case VK_ERROR_FEATURE_NOT_PRESENT:
return "VK_ERROR_FEATURE_NOT_PRESENT";
case VK_ERROR_INCOMPATIBLE_DRIVER:
return "VK_ERROR_INCOMPATIBLE_DRIVER";
case VK_ERROR_TOO_MANY_OBJECTS:
return "VK_ERROR_TOO_MANY_OBJECTS";
case VK_ERROR_FORMAT_NOT_SUPPORTED:
return "VK_ERROR_FORMAT_NOT_SUPPORTED";
case VK_ERROR_FRAGMENTED_POOL:
return "VK_ERROR_FRAGMENTED_POOL";
case VK_ERROR_SURFACE_LOST_KHR:
return "VK_ERROR_SURFACE_LOST_KHR";
case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:
return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
case VK_SUBOPTIMAL_KHR:
return "VK_SUBOPTIMAL_KHR";
case VK_ERROR_OUT_OF_DATE_KHR:
return "VK_ERROR_OUT_OF_DATE_KHR";
case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:
return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
case VK_ERROR_VALIDATION_FAILED_EXT:
return "VK_ERROR_VALIDATION_FAILED_EXT";
case VK_ERROR_OUT_OF_POOL_MEMORY_KHR:
return "VK_ERROR_OUT_OF_POOL_MEMORY_KHR";
case VK_ERROR_INVALID_SHADER_NV:
return "VK_ERROR_INVALID_SHADER_NV";
case VK_RESULT_MAX_ENUM:
case VK_RESULT_RANGE_SIZE:
break;
}
if(result < 0)
return "VK_ERROR_<Unknown>";
return "VK_<Unknown>";
}
VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties,
Uint32 *extensionCount)
{
Uint32 count = 0;
VkResult result = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL);
VkExtensionProperties *retval;
if(result == VK_ERROR_INCOMPATIBLE_DRIVER)
{
/* Avoid the ERR_MAX_STRLEN limit by passing part of the message
* as a string argument.
*/
SDL_SetError(
"You probably don't have a working Vulkan driver installed. %s %s %s(%d)",
"Getting Vulkan extensions failed:",
"vkEnumerateInstanceExtensionProperties returned",
SDL_Vulkan_GetResultString(result),
(int)result);
return NULL;
}
else if(result != VK_SUCCESS)
{
SDL_SetError(
"Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned "
"%s(%d)",
SDL_Vulkan_GetResultString(result),
(int)result);
return NULL;
}
if(count == 0)
{
retval = SDL_calloc(1, sizeof(VkExtensionProperties)); // so we can return non-null
}
else
{
retval = SDL_calloc(count, sizeof(VkExtensionProperties));
}
if(!retval)
{
SDL_OutOfMemory();
return NULL;
}
result = vkEnumerateInstanceExtensionProperties(NULL, &count, retval);
if(result != VK_SUCCESS)
{
SDL_SetError(
"Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned "
"%s(%d)",
SDL_Vulkan_GetResultString(result),
(int)result);
SDL_free(retval);
return NULL;
}
*extensionCount = count;
return retval;
}
SDL_bool SDL_Vulkan_GetInstanceExtensions_Helper(unsigned *userCount,
const char **userNames,
unsigned nameCount,
const char *const *names)
{
if (userNames) {
unsigned i;
if (*userCount < nameCount) {
SDL_SetError("Output array for SDL_Vulkan_GetInstanceExtensions needs to be at least %d big", nameCount);
return SDL_FALSE;
}
for (i = 0; i < nameCount; i++) {
userNames[i] = names[i];
}
}
*userCount = nameCount;
return SDL_TRUE;
}
#endif
/* vi: set ts=4 sw=4 expandtab: */
VK_ERROR_NATIVE_WINDOW_IN_USE_KHR
Definition: vulkan.h:142
SDL_TRUE
Definition: SDL_stdinc.h:142
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
VK_ERROR_EXTENSION_NOT_PRESENT
Definition: vulkan.h:135
VK_EVENT_SET
Definition: vulkan.h:126
names
GLuint GLuint * names
Definition: SDL_opengl_glext.h:4956
VK_INCOMPLETE
Definition: vulkan.h:128
count
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
VK_ERROR_OUT_OF_POOL_MEMORY_KHR
Definition: vulkan.h:148
SDL_FALSE
Definition: SDL_stdinc.h:141
VK_EVENT_RESET
Definition: vulkan.h:127
VkExtensionProperties
Definition: vulkan.h:1682
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:181
VK_ERROR_FORMAT_NOT_SUPPORTED
Definition: vulkan.h:139
VK_ERROR_INCOMPATIBLE_DISPLAY_KHR
Definition: vulkan.h:145
VkResult
VkResult
Definition: vulkan.h:122
VK_ERROR_SURFACE_LOST_KHR
Definition: vulkan.h:141
retval
SDL_bool retval
Definition: testgamecontroller.c:65
vkEnumerateInstanceExtensionProperties
VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties)
VK_NOT_READY
Definition: vulkan.h:124
VK_ERROR_VALIDATION_FAILED_EXT
Definition: vulkan.h:146
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
VK_ERROR_FRAGMENTED_POOL
Definition: vulkan.h:140
VK_SUCCESS
Definition: vulkan.h:123
VK_TIMEOUT
Definition: vulkan.h:125
VK_ERROR_INITIALIZATION_FAILED
Definition: vulkan.h:131
i
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
NULL
#define NULL
Definition: begin_code.h:164
VK_ERROR_OUT_OF_DATE_KHR
Definition: vulkan.h:144
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:139
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
VK_ERROR_INVALID_SHADER_NV
Definition: vulkan.h:147
SDL_calloc
#define SDL_calloc
Definition: SDL_dynapi_overrides.h:375
VK_SUBOPTIMAL_KHR
Definition: vulkan.h:143
VK_ERROR_TOO_MANY_OBJECTS
Definition: vulkan.h:138
VK_RESULT_MAX_ENUM
Definition: vulkan.h:153
VK_ERROR_LAYER_NOT_PRESENT
Definition: vulkan.h:134
VK_ERROR_OUT_OF_DEVICE_MEMORY
Definition: vulkan.h:130
SDL_vulkan_internal.h
PFN_vkEnumerateInstanceExtensionProperties
VkResult(VKAPI_PTR * PFN_vkEnumerateInstanceExtensionProperties)(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties)
Definition: vulkan.h:2488
VK_ERROR_DEVICE_LOST
Definition: vulkan.h:132
SDL_error.h
VK_ERROR_MEMORY_MAP_FAILED
Definition: vulkan.h:133
VK_ERROR_OUT_OF_HOST_MEMORY
Definition: vulkan.h:129
VK_ERROR_INCOMPATIBLE_DRIVER
Definition: vulkan.h:137
VK_RESULT_RANGE_SIZE
Definition: vulkan.h:152
VK_ERROR_FEATURE_NOT_PRESENT
Definition: vulkan.h:136