From 80c0146ecdbd22525e20c91a9dda832f81e12383 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Sat, 24 Feb 2024 04:47:05 +0100 Subject: [PATCH] removing unecessary SDL window creation in Vulkan Instance creation --- src/renderer/core/vk_instance.cpp | 37 +++++++++++++++++++------------ 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/renderer/core/vk_instance.cpp b/src/renderer/core/vk_instance.cpp index bd9582b..013e387 100644 --- a/src/renderer/core/vk_instance.cpp +++ b/src/renderer/core/vk_instance.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 19:04:21 by maldavid #+# #+# */ -/* Updated: 2024/01/10 21:54:06 by maldavid ### ########.fr */ +/* Updated: 2024/02/24 04:31:00 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,25 +58,34 @@ namespace mlx std::vector Instance::getRequiredExtensions() { - unsigned int count = 0; - SDL_Window* window = SDL_CreateWindow("", 0, 0, 1, 1, SDL_WINDOW_VULKAN | SDL_WINDOW_HIDDEN); - if(!window) - core::error::report(e_kind::fatal_error, "Vulkan : cannot get instance extentions from window : %s", SDL_GetError()); + std::vector extensions; + extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); + + #ifdef VK_USE_PLATFORM_XCB_KHR + extensions.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); + #endif - if(!SDL_Vulkan_GetInstanceExtensions(window, &count, nullptr)) - core::error::report(e_kind::fatal_error, "Vulkan : cannot get instance extentions from window : %s", SDL_GetError()); + #ifdef VK_USE_PLATFORM_XLIB_KHR + extensions.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); + #endif - std::vector extensions = { VK_EXT_DEBUG_REPORT_EXTENSION_NAME }; - size_t additional_extension_count = extensions.size(); - extensions.resize(additional_extension_count + count); + #ifdef VK_USE_PLATFORM_WAYLAND_KHR + extensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); + #endif - if(!SDL_Vulkan_GetInstanceExtensions(window, &count, extensions.data() + additional_extension_count)) - core::error::report(e_kind::error, "Vulkan : cannot get instance extentions from window : %s", SDL_GetError()); + #ifdef VK_USE_PLATFORM_WIN32_KHR + extensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); + #endif + + #ifdef VK_USE_PLATFORM_METAL_EXT + extensions.push_back(VK_EXT_METAL_SURFACE_EXTENSION_NAME); + #endif if constexpr(enableValidationLayers) + { + extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); - - SDL_DestroyWindow(window); + } return extensions; }