removing unecessary SDL window creation in Vulkan Instance creation

This commit is contained in:
Kbz-8
2024-02-24 04:47:05 +01:00
parent dbe3bb3cb3
commit 80c0146ecd

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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<const char*> 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<const char*> 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<const char*> 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;
}