From 8c68564be26ec140c3d4dca091d853efc718a9c5 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 09:54:44 +0200 Subject: [PATCH] adding headless mode --- runtime/Sources/Renderer/RenderCore.cpp | 6 ++++-- runtime/Sources/Renderer/Vulkan/VulkanLoader.cpp | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/runtime/Sources/Renderer/RenderCore.cpp b/runtime/Sources/Renderer/RenderCore.cpp index 2445aa2..a7dc473 100644 --- a/runtime/Sources/Renderer/RenderCore.cpp +++ b/runtime/Sources/Renderer/RenderCore.cpp @@ -125,10 +125,12 @@ namespace mlx vkGetPhysicalDeviceProperties(m_physical_device, &props); DebugLog("Vulkan: physical device picked '%'", props.deviceName); - const char* device_extensions[] = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; + std::vector device_extensions; + if(!is_headless) + device_extensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); VkPhysicalDeviceFeatures features{}; vkGetPhysicalDeviceFeatures(m_physical_device, &features); - m_device = kvfCreateDevice(m_physical_device, device_extensions, sizeof(device_extensions) / sizeof(device_extensions[0]), &features); + m_device = kvfCreateDevice(m_physical_device, device_extensions.data(), device_extensions.size(), &features); DebugLog("Vulkan: logical device created"); loader->LoadDevice(m_device); diff --git a/runtime/Sources/Renderer/Vulkan/VulkanLoader.cpp b/runtime/Sources/Renderer/Vulkan/VulkanLoader.cpp index 4f63d54..7fc5483 100644 --- a/runtime/Sources/Renderer/Vulkan/VulkanLoader.cpp +++ b/runtime/Sources/Renderer/Vulkan/VulkanLoader.cpp @@ -28,6 +28,10 @@ namespace mlx { static inline PFN_vkVoidFunction vkGetInstanceProcAddrStub(Handle context, const char* name) { + bool is_headless = std::getenv("MLX_HEADLESS_MODE") != nullptr; + if(is_headless && std::string_view(name).find("KHR") != std::string_view::npos) + return nullptr; + PFN_vkVoidFunction function = RenderCore::Get().vkGetInstanceProcAddr(static_cast(context), name); if(!function) FatalError("Vulkan Loader: could not load '%'", name); @@ -37,6 +41,10 @@ namespace mlx static inline PFN_vkVoidFunction vkGetDeviceProcAddrStub(Handle context, const char* name) { + bool is_headless = std::getenv("MLX_HEADLESS_MODE") != nullptr; + if(is_headless && std::string_view(name).find("KHR") != std::string_view::npos) + return nullptr; + PFN_vkVoidFunction function = RenderCore::Get().vkGetDeviceProcAddr(static_cast(context), name); if(!function) FatalError("Vulkan Loader: could not load '%'", name);