SDL  2.0
SDL_vivantevulkan.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2017 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 
22 /*
23  * @author Wladimir J. van der Laan. Based on Jacob Lifshay's
24  * SDL_x11vulkan.c, Mark Callow's SDL_androidvulkan.c, and
25  * the FSL demo framework.
26  */
27 
28 #include "../../SDL_internal.h"
29 
30 #if SDL_VIDEO_VULKAN && SDL_VIDEO_DRIVER_VIVANTE
31 
32 #include "SDL_vivantevideo.h"
33 #include "SDL_assert.h"
34 
35 #include "SDL_loadso.h"
36 #include "SDL_vivantevulkan.h"
37 #include "SDL_syswm.h"
38 #include "SDL_log.h"
39 
40 int VIVANTE_Vulkan_LoadLibrary(_THIS, const char *path)
41 {
42  VkExtensionProperties *extensions = NULL;
43  Uint32 i, extensionCount = 0;
44  SDL_bool hasSurfaceExtension = SDL_FALSE;
45  SDL_bool hasDisplayExtension = SDL_FALSE;
48  return SDL_SetError("Vulkan already loaded");
49 
50  /* Load the Vulkan loader library */
51  if(!path)
52  path = SDL_getenv("SDL_VULKAN_LIBRARY");
53  if(!path)
54  {
55  /* If no path set, try Vivante fb vulkan driver explicitly */
56  path = "libvulkan-fb.so";
59  {
60  /* If that couldn't be loaded, fall back to default name */
61  path = "libvulkan.so";
63  }
64  } else {
66  }
68  return -1;
71  SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vivante: Loaded vulkan driver %s", path);
72  vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
73  _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
74  if(!vkGetInstanceProcAddr)
75  goto fail;
76  _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
79  VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
81  goto fail;
82  extensions = SDL_Vulkan_CreateInstanceExtensionsList(
85  &extensionCount);
86  if(!extensions)
87  goto fail;
88  for(i = 0; i < extensionCount; i++)
89  {
90  if(SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0)
91  hasSurfaceExtension = SDL_TRUE;
92  else if(SDL_strcmp(VK_KHR_DISPLAY_EXTENSION_NAME, extensions[i].extensionName) == 0)
93  hasDisplayExtension = SDL_TRUE;
94  }
95  SDL_free(extensions);
96  if(!hasSurfaceExtension)
97  {
98  SDL_SetError("Installed Vulkan doesn't implement the "
99  VK_KHR_SURFACE_EXTENSION_NAME " extension");
100  goto fail;
101  }
102  else if(!hasDisplayExtension)
103  {
104  SDL_SetError("Installed Vulkan doesn't implement the "
105  VK_KHR_DISPLAY_EXTENSION_NAME "extension");
106  goto fail;
107  }
108  return 0;
109 
110 fail:
113  return -1;
114 }
115 
116 void VIVANTE_Vulkan_UnloadLibrary(_THIS)
117 {
119  {
122  }
123 }
124 
125 SDL_bool VIVANTE_Vulkan_GetInstanceExtensions(_THIS,
127  unsigned *count,
128  const char **names)
129 {
130  static const char *const extensionsForVivante[] = {
132  };
134  {
135  SDL_SetError("Vulkan is not loaded");
136  return SDL_FALSE;
137  }
138  return SDL_Vulkan_GetInstanceExtensions_Helper(
139  count, names, SDL_arraysize(extensionsForVivante),
140  extensionsForVivante);
141 }
142 
143 SDL_bool VIVANTE_Vulkan_CreateSurface(_THIS,
144  SDL_Window *window,
145  VkInstance instance,
146  VkSurfaceKHR *surface)
147 {
149  {
150  SDL_SetError("Vulkan is not loaded");
151  return SDL_FALSE;
152  }
153  return SDL_Vulkan_Display_CreateSurface(_this->vulkan_config.vkGetInstanceProcAddr, instance, surface);
154 }
155 
156 #endif
157 
158 /* vi: set ts=4 sw=4 expandtab: */
159 
#define SDL_strlcpy
#define VK_NULL_HANDLE
Definition: vulkan_core.h:49
GLuint GLuint * names
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
EGLSurface surface
Definition: eglext.h:248
#define SDL_LoadObject
#define SDL_UnloadObject
struct SDL_VideoDevice::@263 vulkan_config
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
char loader_path[256]
Definition: SDL_sysvideo.h:375
#define SDL_LogDebug
#define _THIS
#define SDL_free
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *pName)
#define VK_KHR_DISPLAY_EXTENSION_NAME
Definition: vulkan_core.h:4953
#define SDL_getenv
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 VK_KHR_SURFACE_EXTENSION_NAME
Definition: vulkan_core.h:4669
#define NULL
Definition: begin_code.h:167
SDL_bool
Definition: SDL_stdinc.h:161
#define SDL_SetError
VkResult(VKAPI_PTR * PFN_vkEnumerateInstanceExtensionProperties)(const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties)
Definition: vulkan_core.h:2863
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)
Definition: vulkan_core.h:2859
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties
Definition: SDL_sysvideo.h:373
The type used to identify a window.
Definition: SDL_sysvideo.h:73
uint32_t Uint32
Definition: SDL_stdinc.h:203
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr
Definition: SDL_sysvideo.h:372
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
GLsizei const GLchar *const * path
#define SDL_strcmp
void * SDL_LoadFunction(void *handle, const char *name)
void * loader_handle
Definition: SDL_sysvideo.h:376