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

◆ VK_DEFINE_HANDLE

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

Definition at line 44 of file SDL_vulkan.h.

◆ VK_DEFINE_NON_DISPATCHABLE_HANDLE

#define VK_DEFINE_NON_DISPATCHABLE_HANDLE (   object)    typedef uint64_t object;

Definition at line 49 of file SDL_vulkan.h.

Typedef Documentation

◆ SDL_vulkanInstance

typedef VkInstance SDL_vulkanInstance

Definition at line 57 of file SDL_vulkan.h.

◆ SDL_vulkanSurface

typedef VkSurfaceKHR SDL_vulkanSurface

Definition at line 58 of file SDL_vulkan.h.

Function Documentation

◆ SDL_Vulkan_CreateSurface()

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;
handle_error();
#define SDL_Vulkan_CreateSurface
EGLSurface surface
Definition: eglext.h:248
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
The type used to identify a window.
Definition: SDL_sysvideo.h:75
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 4298 of file SDL_video.c.

4301 {
4303 
4304  if (!(window->flags & SDL_WINDOW_VULKAN)) {
4306  return SDL_FALSE;
4307  }
4308 
4309  if (!instance) {
4310  SDL_InvalidParamError("instance");
4311  return SDL_FALSE;
4312  }
4313 
4314  if (!surface) {
4315  SDL_InvalidParamError("surface");
4316  return SDL_FALSE;
4317  }
4318 
4319  return _this->Vulkan_CreateSurface(_this, window, instance, surface);
4320 }
#define SDL_SetError
#define SDL_InvalidParamError(param)
Definition: SDL_error.h:90
@ SDL_FALSE
Definition: SDL_stdinc.h:169
#define NOT_A_VULKAN_WINDOW
Definition: SDL_video.c:4221
static SDL_VideoDevice * _this
Definition: SDL_video.c:126
#define CHECK_WINDOW_MAGIC(window, retval)
Definition: SDL_video.c:128
@ SDL_WINDOW_VULKAN
Definition: SDL_video.h:121
SDL_bool(* Vulkan_CreateSurface)(_THIS, SDL_Window *window, VkInstance instance, VkSurfaceKHR *surface)
Definition: SDL_sysvideo.h:275

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

◆ SDL_Vulkan_GetDrawableSize()

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.

Note
On macOS high-DPI support must be enabled for an application by setting NSHighResolutionCapable to true in its Info.plist.
See also
SDL_GetWindowSize()
SDL_CreateWindow()

Definition at line 4322 of file SDL_video.c.

4323 {
4325 
4328  } else {
4330  }
4331 }
GLfloat GLfloat GLfloat GLfloat h
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:2145
void(* Vulkan_GetDrawableSize)(_THIS, SDL_Window *window, int *w, int *h)
Definition: SDL_sysvideo.h:276

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

◆ SDL_Vulkan_GetInstanceExtensions()

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]

◆ SDL_Vulkan_GetVkGetInstanceProcAddr()

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 4249 of file SDL_video.c.

4250 {
4251  if (!_this) {
4253  return NULL;
4254  }
4256  SDL_SetError("No Vulkan loader has been loaded");
4257  return NULL;
4258  }
4260 }
static int SDL_UninitializedVideo()
Definition: SDL_video.c:445
#define NULL
Definition: begin_code.h:163
struct SDL_VideoDevice::@441 vulkan_config
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr
Definition: SDL_sysvideo.h:387

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

◆ SDL_Vulkan_LoadLibrary()

int SDL_Vulkan_LoadLibrary ( const char *  path)

Dynamically load a Vulkan loader library.

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

If path is NULL SDL will use the value of the environment variable SDL_VULKAN_LIBRARY, if set, otherwise it loads the default Vulkan loader library.

This should be called 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
It is fairly common for Vulkan applications to link with libvulkan instead of explicitly loading it at run time. This will work with SDL provided the application links to a dynamic library and both it and SDL use the same search path.
If you specify a non-NULL path, an application should retrieve all of the Vulkan functions it uses from the dynamic library using SDL_Vulkan_GetVkGetInstanceProcAddr() unless you can guarantee path points to the same vulkan loader library the application 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 it is fairly common for Vulkan applications to link with libvulkan (and historically MoltenVK was provided as a static library). If it is not found then, on macOS, SDL will attempt to load vulkan.framework/vulkan, libvulkan.1.dylib, followed by libvulkan.dylib, in that order. On iOS SDL will attempt to load libvulkan.dylib only. Applications using a dynamic framework or .dylib must ensure it is included in its application bundle.
On non-Apple devices, application linking with a static libvulkan is not supported. Either do not link to the Vulkan loader or link to a dynamic library version.
This function will fail if there are no working Vulkan drivers installed.
See also
SDL_Vulkan_GetVkGetInstanceProcAddr()
SDL_Vulkan_UnloadLibrary()

Definition at line 4223 of file SDL_video.c.

4224 {
4225  int retval;
4226  if (!_this) {
4228  return -1;
4229  }
4232  return SDL_SetError("Vulkan loader library already loaded");
4233  }
4234  retval = 0;
4235  } else {
4236  if (!_this->Vulkan_LoadLibrary) {
4237  return SDL_SetError("Vulkan support is either not configured in SDL "
4238  "or not available in current SDL video driver "
4239  "(%s) or platform", _this->name);
4240  }
4242  }
4243  if (retval == 0) {
4245  }
4246  return retval;
4247 }
#define SDL_strcmp
GLsizei const GLchar *const * path
const char * name
Definition: SDL_sysvideo.h:153
int(* Vulkan_LoadLibrary)(_THIS, const char *path)
Definition: SDL_sysvideo.h:272
char loader_path[256]
Definition: SDL_sysvideo.h:390
SDL_bool retval

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

Referenced by SDL_CreateWindow(), and SDL_RecreateWindow().

◆ SDL_Vulkan_UnloadLibrary()

void SDL_Vulkan_UnloadLibrary ( void  )