Atlas - SDL_vivantevulkan.c
Home / ext / SDL / src / video / vivante Lines: 1 | Size: 5827 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 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, Uint32 *count) 121{ 122 static const char *const extensionsForVivante[] = { 123 VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_DISPLAY_EXTENSION_NAME 124 }; 125 if (count) { 126 *count = SDL_arraysize(extensionsForVivante); 127 } 128 return extensionsForVivante; 129} 130 131bool VIVANTE_Vulkan_CreateSurface(SDL_VideoDevice *_this, 132 SDL_Window *window, 133 VkInstance instance, 134 const struct VkAllocationCallbacks *allocator, 135 VkSurfaceKHR *surface) 136{ 137 if (!_this->vulkan_config.loader_handle) { 138 return SDL_SetError("Vulkan is not loaded"); 139 } 140 return SDL_Vulkan_Display_CreateSurface(_this->vulkan_config.vkGetInstanceProcAddr, instance, allocator, surface); 141} 142 143void VIVANTE_Vulkan_DestroySurface(SDL_VideoDevice *_this, 144 VkInstance instance, 145 VkSurfaceKHR surface, 146 const struct VkAllocationCallbacks *allocator) 147{ 148 if (_this->vulkan_config.loader_handle) { 149 SDL_Vulkan_DestroySurface_Internal(_this->vulkan_config.vkGetInstanceProcAddr, instance, surface, allocator); 150 } 151} 152 153#endif 154[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.