summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/video/vivante/SDL_vivantevulkan.c
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
committer3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
commit5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch)
tree8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/video/vivante/SDL_vivantevulkan.c
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/video/vivante/SDL_vivantevulkan.c')
-rw-r--r--contrib/SDL-3.2.8/src/video/vivante/SDL_vivantevulkan.c154
1 files changed, 154 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/video/vivante/SDL_vivantevulkan.c b/contrib/SDL-3.2.8/src/video/vivante/SDL_vivantevulkan.c
new file mode 100644
index 0000000..a021a99
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/video/vivante/SDL_vivantevulkan.c
@@ -0,0 +1,154 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 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/*
24 * @author Wladimir J. van der Laan. Based on Jacob Lifshay's
25 * SDL_x11vulkan.c, Mark Callow's SDL_androidvulkan.c, and
26 * the FSL demo framework.
27 */
28
29#if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_VIVANTE)
30
31#include "../SDL_vulkan_internal.h"
32
33#include "SDL_vivantevideo.h"
34
35#include "SDL_vivantevulkan.h"
36
37bool VIVANTE_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
38{
39 VkExtensionProperties *extensions = NULL;
40 Uint32 i, extensionCount = 0;
41 bool hasSurfaceExtension = false;
42 bool hasDisplayExtension = false;
43 PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = NULL;
44 if (_this->vulkan_config.loader_handle) {
45 return SDL_SetError("Vulkan already loaded");
46 }
47
48 // Load the Vulkan loader library
49 if (!path) {
50 path = SDL_GetHint(SDL_HINT_VULKAN_LIBRARY);
51 }
52 if (!path) {
53 // If no path set, try Vivante fb vulkan driver explicitly
54 path = "libvulkan-fb.so";
55 _this->vulkan_config.loader_handle = SDL_LoadObject(path);
56 if (!_this->vulkan_config.loader_handle) {
57 // If that couldn't be loaded, fall back to default name
58 path = "libvulkan.so";
59 _this->vulkan_config.loader_handle = SDL_LoadObject(path);
60 }
61 } else {
62 _this->vulkan_config.loader_handle = SDL_LoadObject(path);
63 }
64 if (!_this->vulkan_config.loader_handle) {
65 return false;
66 }
67 SDL_strlcpy(_this->vulkan_config.loader_path, path,
68 SDL_arraysize(_this->vulkan_config.loader_path));
69 SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vivante: Loaded vulkan driver %s", path);
70 vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction(
71 _this->vulkan_config.loader_handle, "vkGetInstanceProcAddr");
72 if (!vkGetInstanceProcAddr) {
73 goto fail;
74 }
75 _this->vulkan_config.vkGetInstanceProcAddr = (void *)vkGetInstanceProcAddr;
76 _this->vulkan_config.vkEnumerateInstanceExtensionProperties =
77 (void *)((PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr)(
78 VK_NULL_HANDLE, "vkEnumerateInstanceExtensionProperties");
79 if (!_this->vulkan_config.vkEnumerateInstanceExtensionProperties) {
80 goto fail;
81 }
82 extensions = SDL_Vulkan_CreateInstanceExtensionsList(
83 (PFN_vkEnumerateInstanceExtensionProperties)
84 _this->vulkan_config.vkEnumerateInstanceExtensionProperties,
85 &extensionCount);
86 if (!extensions) {
87 goto fail;
88 }
89 for (i = 0; i < extensionCount; i++) {
90 if (SDL_strcmp(VK_KHR_SURFACE_EXTENSION_NAME, extensions[i].extensionName) == 0) {
91 hasSurfaceExtension = true;
92 } else if (SDL_strcmp(VK_KHR_DISPLAY_EXTENSION_NAME, extensions[i].extensionName) == 0) {
93 hasDisplayExtension = true;
94 }
95 }
96 SDL_free(extensions);
97 if (!hasSurfaceExtension) {
98 SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_SURFACE_EXTENSION_NAME " extension");
99 goto fail;
100 } else if (!hasDisplayExtension) {
101 SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_DISPLAY_EXTENSION_NAME "extension");
102 goto fail;
103 }
104 return true;
105
106fail:
107 SDL_UnloadObject(_this->vulkan_config.loader_handle);
108 _this->vulkan_config.loader_handle = NULL;
109 return false;
110}
111
112void VIVANTE_Vulkan_UnloadLibrary(SDL_VideoDevice *_this)
113{
114 if (_this->vulkan_config.loader_handle) {
115 SDL_UnloadObject(_this->vulkan_config.loader_handle);
116 _this->vulkan_config.loader_handle = NULL;
117 }
118}
119
120char const* const* VIVANTE_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
121 Uint32 *count)
122{
123 static const char *const extensionsForVivante[] = {
124 VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_DISPLAY_EXTENSION_NAME
125 };
126 if (count) {
127 *count = SDL_arraysize(extensionsForVivante);
128 }
129 return extensionsForVivante;
130}
131
132bool VIVANTE_Vulkan_CreateSurface(SDL_VideoDevice *_this,
133 SDL_Window *window,
134 VkInstance instance,
135 const struct VkAllocationCallbacks *allocator,
136 VkSurfaceKHR *surface)
137{
138 if (!_this->vulkan_config.loader_handle) {
139 return SDL_SetError("Vulkan is not loaded");
140 }
141 return SDL_Vulkan_Display_CreateSurface(_this->vulkan_config.vkGetInstanceProcAddr, instance, allocator, surface);
142}
143
144void VIVANTE_Vulkan_DestroySurface(SDL_VideoDevice *_this,
145 VkInstance instance,
146 VkSurfaceKHR surface,
147 const struct VkAllocationCallbacks *allocator)
148{
149 if (_this->vulkan_config.loader_handle) {
150 SDL_Vulkan_DestroySurface_Internal(_this->vulkan_config.vkGetInstanceProcAddr, instance, surface, allocator);
151 }
152}
153
154#endif