SDL  2.0
SDL_vulkan.h File Reference
#include "SDL_video.h"
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_vulkan.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define VK_DEFINE_HANDLE(object)   typedef struct object##_T* object;
 
#define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object)   typedef uint64_t object;
 

Typedefs

typedef VkInstance SDL_vulkanInstance
 
typedef VkSurfaceKHR SDL_vulkanSurface
 

Functions

Vulkan support functions
Note
SDL_Vulkan_GetInstanceExtensions & SDL_Vulkan_CreateSurface API is compatable with Tizen's implementation of Vulkan in SDL.
int SDL_Vulkan_LoadLibrary (const char *path)
 Dynamically load a Vulkan loader library. More...
 
voidSDL_Vulkan_GetVkGetInstanceProcAddr (void)
 Get the address of the vkGetInstanceProcAddr function. More...
 
void SDL_Vulkan_UnloadLibrary (void)
 Unload the Vulkan loader library previously loaded by SDL_Vulkan_LoadLibrary(). More...
 
SDL_bool SDL_Vulkan_GetInstanceExtensions (SDL_Window *window, unsigned int *pCount, const char **pNames)
 Get the names of the Vulkan instance extensions needed to create a surface with SDL_Vulkan_CreateSurface(). More...
 
SDL_bool SDL_Vulkan_CreateSurface (SDL_Window *window, VkInstance instance, VkSurfaceKHR *surface)
 Create a Vulkan rendering surface for a window. More...
 
void SDL_Vulkan_GetDrawableSize (SDL_Window *window, int *w, int *h)
 Get the size of a window's underlying drawable in pixels (for use with setting viewport, scissor & etc). More...
 

Detailed Description

Header file for functions to creating Vulkan surfaces on SDL windows.

Definition in file SDL_vulkan.h.

Macro Definition Documentation

#define VK_DEFINE_HANDLE (   object)    typedef struct object##_T* object;

Definition at line 44 of file SDL_vulkan.h.

#define VK_DEFINE_NON_DISPATCHABLE_HANDLE (   object)    typedef uint64_t object;

Definition at line 49 of file SDL_vulkan.h.

Typedef Documentation

typedef VkInstance SDL_vulkanInstance

Definition at line 57 of file SDL_vulkan.h.

typedef VkSurfaceKHR SDL_vulkanSurface

Definition at line 58 of file SDL_vulkan.h.

Function Documentation

SDL_bool SDL_Vulkan_CreateSurface ( SDL_Window window,
VkInstance  instance,
VkSurfaceKHR *  surface 
)

Create a Vulkan rendering surface for a window.

Parameters
[in]windowSDL_Window to which to attach the rendering surface.
[in]instancehandle to the Vulkan instance to use.
[out]surfacepointer to a VkSurfaceKHR handle to receive the handle of the newly created surface.
Returns
SDL_TRUE on success, SDL_FALSE on error.
VkInstance instance;
// create instance and window
// create the Vulkan surface
VkSurfaceKHR surface;
if(!SDL_Vulkan_CreateSurface(window, instance, &surface))
handle_error();
Note
window should have been created with the SDL_WINDOW_VULKAN flag.
instance should have been created with the extensions returned by SDL_Vulkan_CreateSurface() enabled.
See also
SDL_Vulkan_GetInstanceExtensions()

Definition at line 4041 of file SDL_video.c.

References CHECK_WINDOW_MAGIC, SDL_Window::flags, NOT_A_VULKAN_WINDOW, SDL_FALSE, SDL_InvalidParamError, SDL_SetError, SDL_WINDOW_VULKAN, and SDL_VideoDevice::Vulkan_CreateSurface.

4044 {
4045  CHECK_WINDOW_MAGIC(window, SDL_FALSE);
4046 
4047  if (!(window->flags & SDL_WINDOW_VULKAN)) {
4049  return SDL_FALSE;
4050  }
4051 
4052  if (!instance) {
4053  SDL_InvalidParamError("instance");
4054  return SDL_FALSE;
4055  }
4056 
4057  if (!surface) {
4058  SDL_InvalidParamError("surface");
4059  return SDL_FALSE;
4060  }
4061 
4062  return _this->Vulkan_CreateSurface(_this, window, instance, surface);
4063 }
#define NOT_A_VULKAN_WINDOW
Definition: SDL_video.c:3970
EGLSurface surface
Definition: eglext.h:248
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:54
SDL_bool(* Vulkan_CreateSurface)(_THIS, SDL_Window *window, VkInstance instance, VkSurfaceKHR *surface)
Definition: SDL_sysvideo.h:273
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
#define SDL_SetError
#define CHECK_WINDOW_MAGIC(window, retval)
Definition: SDL_video.c:123
Uint32 flags
Definition: SDL_sysvideo.h:83
void SDL_Vulkan_GetDrawableSize ( SDL_Window window,
int *  w,
int *  h 
)

Get the size of a window's underlying drawable in pixels (for use with setting viewport, scissor & etc).

Parameters
windowSDL_Window from which the drawable size should be queried
wPointer to variable for storing the width in pixels, may be NULL
hPointer to variable for storing the height in pixels, may be NULL

This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI drawable, i.e. the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a platform with high-DPI support (Apple calls this "Retina"), and not disabled by the SDL_HINT_VIDEO_HIGHDPI_DISABLED hint.

See also
SDL_GetWindowSize()
SDL_CreateWindow()

Definition at line 4065 of file SDL_video.c.

References CHECK_WINDOW_MAGIC, SDL_GetWindowSize(), and SDL_VideoDevice::Vulkan_GetDrawableSize.

4066 {
4067  CHECK_WINDOW_MAGIC(window,);
4068 
4070  _this->Vulkan_GetDrawableSize(_this, window, w, h);
4071  } else {
4072  SDL_GetWindowSize(window, w, h);
4073  }
4074 }
GLfloat GLfloat GLfloat GLfloat h
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
GLubyte GLubyte GLubyte GLubyte w
void SDL_GetWindowSize(SDL_Window *window, int *w, int *h)
Get the size of a window's client area.
Definition: SDL_video.c:1954
void(* Vulkan_GetDrawableSize)(_THIS, SDL_Window *window, int *w, int *h)
Definition: SDL_sysvideo.h:274
#define CHECK_WINDOW_MAGIC(window, retval)
Definition: SDL_video.c:123
SDL_bool SDL_Vulkan_GetInstanceExtensions ( SDL_Window window,
unsigned int *  pCount,
const char **  pNames 
)

Get the names of the Vulkan instance extensions needed to create a surface with SDL_Vulkan_CreateSurface().

Parameters
[in]windowWindow for which the required Vulkan instance extensions should be retrieved
[in,out]countpointer to an unsigned related to the number of required Vulkan instance extensions
[out]namesNULL or a pointer to an array to be filled with the required Vulkan instance extensions
Returns
SDL_TRUE on success, SDL_FALSE on error.

If pNames is NULL, then the number of required Vulkan instance extensions is returned in pCount. Otherwise, pCount must point to a variable set to the number of elements in the pNames array, and on return the variable is overwritten with the number of names actually written to pNames. If pCount is less than the number of required extensions, at most pCount structures will be written. If pCount is smaller than the number of required extensions, SDL_FALSE will be returned instead of SDL_TRUE, to indicate that not all the required extensions were returned.

Note
The returned list of extensions will contain VK_KHR_surface and zero or more platform specific extensions
The extension names queried here must be enabled when calling VkCreateInstance, otherwise surface creation will fail.
window should have been created with the SDL_WINDOW_VULKAN flag.
unsigned int count;
// get count of required extensions
handle_error();
static const char *const additionalExtensions[] =
{
VK_EXT_DEBUG_REPORT_EXTENSION_NAME, // example additional extension
};
size_t additionalExtensionsCount = sizeof(additionalExtensions) / sizeof(additionalExtensions[0]);
size_t extensionCount = count + additionalExtensionsCount;
const char **names = malloc(sizeof(const char *) * extensionCount);
if(!names)
handle_error();
// get names of required extensions
if(!SDL_Vulkan_GetInstanceExtensions(window, &count, names))
handle_error();
// copy additional extensions after required extensions
for(size_t i = 0; i < additionalExtensionsCount; i++)
names[i + count] = additionalExtensions[i];
VkInstanceCreateInfo instanceCreateInfo = {};
instanceCreateInfo.enabledExtensionCount = extensionCount;
instanceCreateInfo.ppEnabledExtensionNames = names;
// fill in rest of instanceCreateInfo
VkInstance instance;
// create the Vulkan instance
VkResult result = vkCreateInstance(&instanceCreateInfo, NULL, &instance);
free(names);
See also
SDL_Vulkan_CreateSurface()
void* SDL_Vulkan_GetVkGetInstanceProcAddr ( void  )

Get the address of the vkGetInstanceProcAddr function.

Note
This should be called after either calling SDL_Vulkan_LoadLibrary or creating an SDL_Window with the SDL_WINDOW_VULKAN flag.

Definition at line 3996 of file SDL_video.c.

References SDL_VideoDevice::loader_loaded, NULL, SDL_SetError, SDL_UninitializedVideo(), SDL_VideoDevice::vkGetInstanceProcAddr, and SDL_VideoDevice::vulkan_config.

3997 {
3998  if (!_this) {
4000  return NULL;
4001  }
4003  SDL_SetError("No Vulkan loader has been loaded");
4004  }
4006 }
struct SDL_VideoDevice::@32 vulkan_config
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
void * vkGetInstanceProcAddr
Definition: SDL_sysvideo.h:368
#define NULL
Definition: begin_code.h:164
#define SDL_SetError
static int SDL_UninitializedVideo()
Definition: SDL_video.c:440
int SDL_Vulkan_LoadLibrary ( const char *  path)

Dynamically load a Vulkan loader library.

Parameters
[in]pathThe platform dependent Vulkan loader library name, or NULL to open the default Vulkan loader library.
Returns
0 on success, or -1 if the library couldn't be loaded.

This should be done after initializing the video driver, but before creating any Vulkan windows. If no Vulkan loader library is loaded, the default library will be loaded upon creation of the first Vulkan window.

Note
If you specify a non-NULL path, you should retrieve all of the Vulkan functions used in your program from the dynamic library using SDL_Vulkan_GetVkGetInstanceProcAddr() unless you can guarantee path points to the same vulkan loader library that you linked to.
On Apple devices, if path is NULL, SDL will attempt to find the vkGetInstanceProcAddr address within all the mach-o images of the current process. This is because the currently (v0.17.0) recommended MoltenVK (Vulkan on Metal) usage is as a static library. If it is not found then SDL will attempt to load libMoltenVK.dylib. Applications using the dylib alternative therefore do not need to do anything special when calling SDL.
On non-Apple devices, SDL requires you to either not link to the Vulkan loader or link to a dynamic library version. This limitation may be removed in a future version of SDL.
This function will fail if there are no working Vulkan drivers installed.
See also
SDL_Vulkan_GetVkGetInstanceProcAddr()
SDL_Vulkan_UnloadLibrary()

Definition at line 3972 of file SDL_video.c.

References SDL_VideoDevice::loader_loaded, SDL_VideoDevice::loader_path, retval, SDL_SetError, SDL_strcmp, SDL_UninitializedVideo(), SDL_VideoDevice::vulkan_config, and SDL_VideoDevice::Vulkan_LoadLibrary.

Referenced by SDL_CreateWindow().

3973 {
3974  int retval;
3975  if (!_this) {
3977  return -1;
3978  }
3981  return SDL_SetError("Vulkan loader library already loaded");
3982  }
3983  retval = 0;
3984  } else {
3985  if (!_this->Vulkan_LoadLibrary) {
3986  return SDL_SetError("No Vulkan support in video driver");
3987  }
3988  retval = _this->Vulkan_LoadLibrary(_this, path);
3989  }
3990  if (retval == 0) {
3992  }
3993  return retval;
3994 }
int(* Vulkan_LoadLibrary)(_THIS, const char *path)
Definition: SDL_sysvideo.h:270
struct SDL_VideoDevice::@32 vulkan_config
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
char loader_path[256]
Definition: SDL_sysvideo.h:371
SDL_bool retval
#define SDL_SetError
static int SDL_UninitializedVideo()
Definition: SDL_video.c:440
GLsizei const GLchar *const * path
#define SDL_strcmp
void SDL_Vulkan_UnloadLibrary ( void  )

Unload the Vulkan loader library previously loaded by SDL_Vulkan_LoadLibrary().

See also
SDL_Vulkan_LoadLibrary()

Definition at line 4008 of file SDL_video.c.

References SDL_VideoDevice::loader_loaded, SDL_UninitializedVideo(), SDL_VideoDevice::vulkan_config, and SDL_VideoDevice::Vulkan_UnloadLibrary.

Referenced by SDL_DestroyWindow().

4009 {
4010  if (!_this) {
4012  return;
4013  }
4014  if (_this->vulkan_config.loader_loaded > 0) {
4015  if (--_this->vulkan_config.loader_loaded > 0) {
4016  return;
4017  }
4018  if (_this->Vulkan_UnloadLibrary) {
4020  }
4021  }
4022 }
struct SDL_VideoDevice::@32 vulkan_config
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
void(* Vulkan_UnloadLibrary)(_THIS)
Definition: SDL_sysvideo.h:271
static int SDL_UninitializedVideo()
Definition: SDL_video.c:440