mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
starting to work on headless support
This commit is contained in:
@@ -7,9 +7,7 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UUID();
|
UUID();
|
||||||
UUID(std::uint64_t uuid);
|
inline operator std::uint64_t() const noexcept { return m_uuid; }
|
||||||
|
|
||||||
inline operator std::uint64_t() const { return m_uuid; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::uint64_t m_uuid;
|
std::uint64_t m_uuid;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace mlx
|
|||||||
MLX_PROFILE_FUNCTION();
|
MLX_PROFILE_FUNCTION();
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
|
|
||||||
m_drop_sdl_responsability = SDL_WasInit(SDL_INIT_VIDEO);
|
m_drop_sdl_responsability = SDL_WasInit(SDL_INIT_VIDEO) || std::getenv("MLX_HEADLESS_MODE") != nullptr;
|
||||||
if(m_drop_sdl_responsability) // is case the mlx is running in a sandbox like MacroUnitTester where SDL is already init
|
if(m_drop_sdl_responsability) // is case the mlx is running in a sandbox like MacroUnitTester where SDL is already init
|
||||||
return;
|
return;
|
||||||
SDL_SetMemoryFunctions(MemManager::Get().Malloc, MemManager::Get().Calloc, MemManager::Get().Realloc, MemManager::Get().Free);
|
SDL_SetMemoryFunctions(MemManager::Get().Malloc, MemManager::Get().Calloc, MemManager::Get().Realloc, MemManager::Get().Free);
|
||||||
|
|||||||
@@ -7,7 +7,14 @@ namespace mlx
|
|||||||
static std::random_device random_device;
|
static std::random_device random_device;
|
||||||
static std::mt19937_64 engine(random_device());
|
static std::mt19937_64 engine(random_device());
|
||||||
static std::uniform_int_distribution<std::uint64_t> uniform_distribution;
|
static std::uniform_int_distribution<std::uint64_t> uniform_distribution;
|
||||||
|
static std::unordered_set<std::uint64_t> registry;
|
||||||
|
|
||||||
UUID::UUID() : m_uuid(uniform_distribution(engine)) {}
|
UUID::UUID()
|
||||||
UUID::UUID(std::uint64_t uuid) : m_uuid(uuid) {}
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
m_uuid = uniform_distribution(engine);
|
||||||
|
} while(registry.contains(m_uuid));
|
||||||
|
registry.emplace(m_uuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,15 +87,24 @@ namespace mlx
|
|||||||
kvfSetValidationErrorCallback(&ValidationErrorCallback);
|
kvfSetValidationErrorCallback(&ValidationErrorCallback);
|
||||||
kvfSetValidationWarningCallback(&WarningCallback);
|
kvfSetValidationWarningCallback(&WarningCallback);
|
||||||
|
|
||||||
mlx_window_create_info info{};
|
std::vector<const char*> instance_extensions;
|
||||||
info.title = "";
|
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
||||||
info.width = 1;
|
std::unique_ptr<Window> window;
|
||||||
info.height = 1;
|
|
||||||
Window window(&info, true);
|
bool is_headless = std::getenv("MLX_HEADLESS_MODE") != nullptr;
|
||||||
std::vector<const char*> instance_extensions = window.GetRequiredVulkanInstanceExtentions();
|
|
||||||
#ifdef MLX_PLAT_MACOS
|
if(!is_headless)
|
||||||
instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
|
{
|
||||||
#endif
|
mlx_window_create_info info{};
|
||||||
|
info.title = "";
|
||||||
|
info.width = 1;
|
||||||
|
info.height = 1;
|
||||||
|
window = std::make_unique<Window>(&info, true);
|
||||||
|
instance_extensions = window->GetRequiredVulkanInstanceExtentions();
|
||||||
|
#ifdef MLX_PLAT_MACOS
|
||||||
|
instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
m_instance = kvfCreateInstance(instance_extensions.data(), instance_extensions.size());
|
m_instance = kvfCreateInstance(instance_extensions.data(), instance_extensions.size());
|
||||||
DebugLog("Vulkan: instance created");
|
DebugLog("Vulkan: instance created");
|
||||||
@@ -103,9 +112,13 @@ namespace mlx
|
|||||||
loader->LoadInstance(m_instance);
|
loader->LoadInstance(m_instance);
|
||||||
LoadKVFInstanceVulkanFunctionPointers();
|
LoadKVFInstanceVulkanFunctionPointers();
|
||||||
|
|
||||||
VkSurfaceKHR surface = window.CreateVulkanSurface(m_instance);
|
if(!is_headless)
|
||||||
|
{
|
||||||
m_physical_device = kvfPickGoodDefaultPhysicalDevice(m_instance, surface);
|
surface = window->CreateVulkanSurface(m_instance);
|
||||||
|
m_physical_device = kvfPickGoodDefaultPhysicalDevice(m_instance, surface);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_physical_device = kvfPickGoodPhysicalDevice(m_instance, VK_NULL_HANDLE, nullptr, 0);
|
||||||
|
|
||||||
// just for style
|
// just for style
|
||||||
VkPhysicalDeviceProperties props;
|
VkPhysicalDeviceProperties props;
|
||||||
@@ -121,7 +134,8 @@ namespace mlx
|
|||||||
loader->LoadDevice(m_device);
|
loader->LoadDevice(m_device);
|
||||||
LoadKVFDeviceVulkanFunctionPointers();
|
LoadKVFDeviceVulkanFunctionPointers();
|
||||||
|
|
||||||
vkDestroySurfaceKHR(m_instance, surface, nullptr);
|
if(surface != VK_NULL_HANDLE)
|
||||||
|
vkDestroySurfaceKHR(m_instance, surface, nullptr);
|
||||||
|
|
||||||
VkAllocationCallbacks callbacks;
|
VkAllocationCallbacks callbacks;
|
||||||
callbacks.pUserData = nullptr;
|
callbacks.pUserData = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user