From 26eab93f9fefa8e292fcfe55eb8448c5ca5a680b Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Tue, 24 Jun 2025 07:10:02 +0200 Subject: [PATCH 01/17] starting to work on headless support --- runtime/Includes/Core/UUID.h | 4 +-- runtime/Sources/Core/SDLManager.cpp | 2 +- runtime/Sources/Core/UUID.cpp | 11 +++++-- runtime/Sources/Renderer/RenderCore.cpp | 40 +++++++++++++++++-------- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/runtime/Includes/Core/UUID.h b/runtime/Includes/Core/UUID.h index 9911302..2caa3f7 100644 --- a/runtime/Includes/Core/UUID.h +++ b/runtime/Includes/Core/UUID.h @@ -7,9 +7,7 @@ namespace mlx { public: UUID(); - UUID(std::uint64_t uuid); - - inline operator std::uint64_t() const { return m_uuid; } + inline operator std::uint64_t() const noexcept { return m_uuid; } private: std::uint64_t m_uuid; diff --git a/runtime/Sources/Core/SDLManager.cpp b/runtime/Sources/Core/SDLManager.cpp index 5f3aa50..51aa85d 100644 --- a/runtime/Sources/Core/SDLManager.cpp +++ b/runtime/Sources/Core/SDLManager.cpp @@ -22,7 +22,7 @@ namespace mlx MLX_PROFILE_FUNCTION(); 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 return; SDL_SetMemoryFunctions(MemManager::Get().Malloc, MemManager::Get().Calloc, MemManager::Get().Realloc, MemManager::Get().Free); diff --git a/runtime/Sources/Core/UUID.cpp b/runtime/Sources/Core/UUID.cpp index cf2855a..5a370dd 100644 --- a/runtime/Sources/Core/UUID.cpp +++ b/runtime/Sources/Core/UUID.cpp @@ -7,7 +7,14 @@ namespace mlx static std::random_device random_device; static std::mt19937_64 engine(random_device()); static std::uniform_int_distribution uniform_distribution; + static std::unordered_set registry; - UUID::UUID() : m_uuid(uniform_distribution(engine)) {} - UUID::UUID(std::uint64_t uuid) : m_uuid(uuid) {} + UUID::UUID() + { + do + { + m_uuid = uniform_distribution(engine); + } while(registry.contains(m_uuid)); + registry.emplace(m_uuid); + } } diff --git a/runtime/Sources/Renderer/RenderCore.cpp b/runtime/Sources/Renderer/RenderCore.cpp index 4bddadc..2445aa2 100644 --- a/runtime/Sources/Renderer/RenderCore.cpp +++ b/runtime/Sources/Renderer/RenderCore.cpp @@ -87,15 +87,24 @@ namespace mlx kvfSetValidationErrorCallback(&ValidationErrorCallback); kvfSetValidationWarningCallback(&WarningCallback); - mlx_window_create_info info{}; - info.title = ""; - info.width = 1; - info.height = 1; - Window window(&info, true); - std::vector instance_extensions = window.GetRequiredVulkanInstanceExtentions(); - #ifdef MLX_PLAT_MACOS - instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); - #endif + std::vector instance_extensions; + VkSurfaceKHR surface = VK_NULL_HANDLE; + std::unique_ptr window; + + bool is_headless = std::getenv("MLX_HEADLESS_MODE") != nullptr; + + if(!is_headless) + { + mlx_window_create_info info{}; + info.title = ""; + info.width = 1; + info.height = 1; + window = std::make_unique(&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()); DebugLog("Vulkan: instance created"); @@ -103,9 +112,13 @@ namespace mlx loader->LoadInstance(m_instance); LoadKVFInstanceVulkanFunctionPointers(); - VkSurfaceKHR surface = window.CreateVulkanSurface(m_instance); - - m_physical_device = kvfPickGoodDefaultPhysicalDevice(m_instance, surface); + if(!is_headless) + { + 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 VkPhysicalDeviceProperties props; @@ -121,7 +134,8 @@ namespace mlx loader->LoadDevice(m_device); LoadKVFDeviceVulkanFunctionPointers(); - vkDestroySurfaceKHR(m_instance, surface, nullptr); + if(surface != VK_NULL_HANDLE) + vkDestroySurfaceKHR(m_instance, surface, nullptr); VkAllocationCallbacks callbacks; callbacks.pUserData = nullptr; From 8c68564be26ec140c3d4dca091d853efc718a9c5 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 09:54:44 +0200 Subject: [PATCH 02/17] 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); From bada4ea1933cebfcbfd2a73bfd6f8b47bc686775 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 10:15:54 +0200 Subject: [PATCH 03/17] adding unit test CI --- .github/workflows/tests.yml | 75 +++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..22fb65b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,75 @@ +name: Unit tests + +on: + pull_request: + push: + paths-ignore: + - '.gitignore' + - 'LICENSE' + - 'README.md' + +jobs: + build: + strategy: + fail-fast: false + matrix: + os: [ubuntu-24.04] + arch: [x86_64] + + runs-on: ${{ matrix.os }} + if: "!contains(github.event.head_commit.message, 'ci skip')" + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get -y install mesa-common-dev clang libsdl2-2.0-0 libsdl2-dev build-essential libvulkan-dev + + # Build the lib + - name: Build MacroLibX + run: make -j DEBUG=true + + # Force xmake to a specific folder (for cache) + - name: Set xmake env + run: echo "XMAKE_GLOBALDIR=${{ runner.workspace }}/xmake-global" >> $GITHUB_ENV + + # Install xmake + - name: Setup xmake + if: ${{ matrix.confs.plat != 'mingw' }} + uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: latest + actions-cache-folder: .xmake-cache-W${{ steps.cache_key.outputs.key }} + + # Update xmake repository (in order to have the file that will be cached) + - name: Update xmake repository + run: xmake repo --update + + # Fetch xmake dephash + - name: Retrieve dependencies hash + id: dep_hash + run: echo "hash=$(xmake l utils.ci.packageskey)" >> $GITHUB_OUTPUT + + # Setup compilation mode and install project dependencies + - name: Configure xmake and install dependencies + run: xmake config --ccache=n --yes + + # Save dependencies + - name: Save cached xmake dependencies + if: ${{ !steps.restore-depcache.outputs.cache-hit }} + uses: actions/cache/save@v4 + with: + path: ${{ env.XMAKE_GLOBALDIR }}/.xmake/packages + key: ${{ steps.restore-depcache.outputs.cache-primary-key }} + + - name: Install unit tester + run: git clone https://github.com/seekrs/MacroUnitTest.git + + - name: Build unit tester + run: cd MacroUnitTest && xmake + + - name: Run unit tests + run: cd MacroUnitTest && xmake run MacroUnitTest --headless --path="$PWD/../libmlx.so" From a2ba022c0152e1f76307277b9fd946b4176ae4e4 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 10:26:28 +0200 Subject: [PATCH 04/17] fixing unit tests CI --- .github/workflows/tests.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 22fb65b..5ce50e9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -53,9 +53,14 @@ jobs: id: dep_hash run: echo "hash=$(xmake l utils.ci.packageskey)" >> $GITHUB_OUTPUT + - name: Install unit tester + run: git clone https://github.com/seekrs/MacroUnitTest.git + # Setup compilation mode and install project dependencies - name: Configure xmake and install dependencies - run: xmake config --ccache=n --yes + run: | + cd MacroUnitTest + xmake config --ccache=n --yes # Save dependencies - name: Save cached xmake dependencies @@ -65,11 +70,7 @@ jobs: path: ${{ env.XMAKE_GLOBALDIR }}/.xmake/packages key: ${{ steps.restore-depcache.outputs.cache-primary-key }} - - name: Install unit tester - run: git clone https://github.com/seekrs/MacroUnitTest.git - - - name: Build unit tester - run: cd MacroUnitTest && xmake - - - name: Run unit tests - run: cd MacroUnitTest && xmake run MacroUnitTest --headless --path="$PWD/../libmlx.so" + - name: Build and run unit tester + run: | + cd MacroUnitTest + xmake run MacroUnitTest --headless --path=" ${GITHUB_WORKSPACE}/libmlx.so" From 5767be94f87298f2dd7e2cd7a10a85357637cb1d Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 10:37:03 +0200 Subject: [PATCH 05/17] fixing unit tests CI --- .github/workflows/tests.yml | 4 ++-- xmake.lua | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5ce50e9..e4a5fd7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -60,7 +60,7 @@ jobs: - name: Configure xmake and install dependencies run: | cd MacroUnitTest - xmake config --ccache=n --yes + xmake -P . config --ccache=n --yes # Save dependencies - name: Save cached xmake dependencies @@ -73,4 +73,4 @@ jobs: - name: Build and run unit tester run: | cd MacroUnitTest - xmake run MacroUnitTest --headless --path=" ${GITHUB_WORKSPACE}/libmlx.so" + xmake run -P . MacroUnitTest --headless --path="{{ runner.workspace }}/libmlx.so" diff --git a/xmake.lua b/xmake.lua index 074e4ce..f7445a4 100644 --- a/xmake.lua +++ b/xmake.lua @@ -1,6 +1,6 @@ -- Global settings -add_requires("libsdl", { configs = { sdlmain = false } }) +add_requires("libsdl2", { configs = { sdlmain = false } }) add_rules("mode.debug", "mode.release", "mode.releasedbg") set_languages("cxx20", "c11") @@ -63,7 +63,7 @@ target("mlx") add_files("runtime/Sources/**.cpp") - add_packages("libsdl") + add_packages("libsdl2") if is_mode("debug") then add_defines("DEBUG") @@ -98,5 +98,5 @@ target("Test") add_defines("SDL_MAIN_HANDLED") - add_packages("libsdl") + add_packages("libsdl2") target_end() From 36119a1643558d98c24e9cce547fa3be91c21a71 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 10:48:08 +0200 Subject: [PATCH 06/17] fixing unit tests CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e4a5fd7..9d43845 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -60,7 +60,7 @@ jobs: - name: Configure xmake and install dependencies run: | cd MacroUnitTest - xmake -P . config --ccache=n --yes + xmake config -P . --ccache=n --yes # Save dependencies - name: Save cached xmake dependencies From baf5a963f31a0387ac4d9a17a21bbc191802b820 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 10:55:06 +0200 Subject: [PATCH 07/17] fixing unit tests CI --- .github/workflows/tests.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9d43845..8cf23c5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,10 +23,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Install system dependencies - run: | - sudo apt-get update - sudo apt-get -y install mesa-common-dev clang libsdl2-2.0-0 libsdl2-dev build-essential libvulkan-dev + - uses: NcStudios/VulkanCI@v1.0 # Build the lib - name: Build MacroLibX From 6766777dca2359a13d1be0cd25c80f082d867deb Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 10:56:22 +0200 Subject: [PATCH 08/17] fixing unit tests CI --- .github/workflows/tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8cf23c5..fe28fd0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,6 +25,11 @@ jobs: - uses: NcStudios/VulkanCI@v1.0 + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get -y install mesa-common-dev build-essential libvulkan-dev + # Build the lib - name: Build MacroLibX run: make -j DEBUG=true From bae90e5603b8ab346bd226196763590a50f82b84 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 10:57:29 +0200 Subject: [PATCH 09/17] fixing unit tests CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fe28fd0..8192279 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,7 +28,7 @@ jobs: - name: Install system dependencies run: | sudo apt-get update - sudo apt-get -y install mesa-common-dev build-essential libvulkan-dev + sudo apt-get -y install mesa-common-dev libsdl2-2.0-0 libsdl2-dev build-essential libvulkan-dev # Build the lib - name: Build MacroLibX From 1704776df1558d894c0e14df462886c8c9c760ef Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 11:06:05 +0200 Subject: [PATCH 10/17] fixing unit tests CI --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8192279..141fd8a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,7 +28,7 @@ jobs: - name: Install system dependencies run: | sudo apt-get update - sudo apt-get -y install mesa-common-dev libsdl2-2.0-0 libsdl2-dev build-essential libvulkan-dev + sudo apt-get -y install mesa-common-dev clang libsdl2-2.0-0 libsdl2-dev build-essential libvulkan-dev # Build the lib - name: Build MacroLibX @@ -62,7 +62,7 @@ jobs: - name: Configure xmake and install dependencies run: | cd MacroUnitTest - xmake config -P . --ccache=n --yes + xmake config -P . --toolchain=clang --ccache=n --yes # Save dependencies - name: Save cached xmake dependencies From 083e3db9122af14e1695134f682912fc87ef96ab Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 15:48:08 +0200 Subject: [PATCH 11/17] fixing unit tests CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 141fd8a..6466d09 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -75,4 +75,4 @@ jobs: - name: Build and run unit tester run: | cd MacroUnitTest - xmake run -P . MacroUnitTest --headless --path="{{ runner.workspace }}/libmlx.so" + xmake run -P . -vD MacroUnitTest --headless --path="{{ runner.workspace }}/libmlx.so" From c24f1ade64c70757a5e4cfe1f35fef88cde75baf Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 16:24:06 +0200 Subject: [PATCH 12/17] fixing unit tests CI --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6466d09..98dd563 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -56,12 +56,12 @@ jobs: run: echo "hash=$(xmake l utils.ci.packageskey)" >> $GITHUB_OUTPUT - name: Install unit tester - run: git clone https://github.com/seekrs/MacroUnitTest.git + run: git clone https://github.com/seekrs/MacroUnitTest.git ../MacroUnitTest # Setup compilation mode and install project dependencies - name: Configure xmake and install dependencies run: | - cd MacroUnitTest + cd ../MacroUnitTest xmake config -P . --toolchain=clang --ccache=n --yes # Save dependencies @@ -74,5 +74,5 @@ jobs: - name: Build and run unit tester run: | - cd MacroUnitTest + cd ../MacroUnitTest xmake run -P . -vD MacroUnitTest --headless --path="{{ runner.workspace }}/libmlx.so" From 61d7c6ce9532e75ce20b7768186e620c4a410d86 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 16:27:59 +0200 Subject: [PATCH 13/17] fixing unit tests CI --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 98dd563..27baa51 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -62,7 +62,7 @@ jobs: - name: Configure xmake and install dependencies run: | cd ../MacroUnitTest - xmake config -P . --toolchain=clang --ccache=n --yes + xmake config --toolchain=clang --ccache=n --yes # Save dependencies - name: Save cached xmake dependencies @@ -75,4 +75,4 @@ jobs: - name: Build and run unit tester run: | cd ../MacroUnitTest - xmake run -P . -vD MacroUnitTest --headless --path="{{ runner.workspace }}/libmlx.so" + xmake run MacroUnitTest --headless --path="${{ runner.workspace }}/libmlx.so" From 7ebce77bb3ed591979c85b04e9883434bc87d6cf Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 16:32:55 +0200 Subject: [PATCH 14/17] fixing unit tests CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 27baa51..93615d0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -75,4 +75,4 @@ jobs: - name: Build and run unit tester run: | cd ../MacroUnitTest - xmake run MacroUnitTest --headless --path="${{ runner.workspace }}/libmlx.so" + xmake run MacroUnitTest --headless --path="${{ runner.workspace }}/MacroLibX/libmlx.so" From d6f472cf6c25001ee6f402891c435422050346af Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 19:11:53 +0200 Subject: [PATCH 15/17] fixing physical device selection under swiftshaders --- runtime/Sources/Renderer/RenderCore.cpp | 2 ++ third_party/kvf.h | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/runtime/Sources/Renderer/RenderCore.cpp b/runtime/Sources/Renderer/RenderCore.cpp index a7dc473..1bbe5f6 100644 --- a/runtime/Sources/Renderer/RenderCore.cpp +++ b/runtime/Sources/Renderer/RenderCore.cpp @@ -120,6 +120,8 @@ namespace mlx else m_physical_device = kvfPickGoodPhysicalDevice(m_instance, VK_NULL_HANDLE, nullptr, 0); + Verify(m_physical_device != VK_NULL_HANDLE, "Could not find a suitable physical device"); + // just for style VkPhysicalDeviceProperties props; vkGetPhysicalDeviceProperties(m_physical_device, &props); diff --git a/third_party/kvf.h b/third_party/kvf.h index eadc889..bd972e2 100755 --- a/third_party/kvf.h +++ b/third_party/kvf.h @@ -1474,9 +1474,6 @@ int32_t __kvfScorePhysicalDevice(VkPhysicalDevice device, VkSurfaceKHR surface, if(device_props.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) score += 1000; - if(!device_features.geometryShader) - return -1; - score += device_props.limits.maxImageDimension2D; score += device_props.limits.maxBoundDescriptorSets; From 7722e26095be484922afa6081531d560d922546a Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 19:22:45 +0200 Subject: [PATCH 16/17] updating readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index d2a2111..63f0097 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@
+
+ +
###### MacroLibX, a rewrite of 42 School's MiniLibX using SDL2 and Vulkan. From 5a0a2fccfe3d150a188aecf8b62c2c981d06d497 Mon Sep 17 00:00:00 2001 From: Kbz-8 Date: Wed, 24 Sep 2025 19:39:22 +0200 Subject: [PATCH 17/17] updating kvf --- runtime/Sources/Renderer/Buffer.cpp | 2 +- third_party/kvf.h | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/runtime/Sources/Renderer/Buffer.cpp b/runtime/Sources/Renderer/Buffer.cpp index c34f965..f8ef1b9 100644 --- a/runtime/Sources/Renderer/Buffer.cpp +++ b/runtime/Sources/Renderer/Buffer.cpp @@ -81,7 +81,7 @@ namespace mlx VkCommandBuffer cmd = kvfCreateCommandBuffer(RenderCore::Get().GetDevice()); kvfBeginCommandBuffer(cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT); - kvfCopyBufferToBuffer(cmd, m_buffer, buffer.Get(), m_size); + kvfCopyBufferToBuffer(cmd, m_buffer, buffer.Get(), m_size, 0, 0); kvfEndCommandBuffer(cmd); VkFence fence = kvfCreateFence(RenderCore::Get().GetDevice()); kvfSubmitSingleTimeCommandBuffer(RenderCore::Get().GetDevice(), cmd, KVF_GRAPHICS_QUEUE, fence); diff --git a/third_party/kvf.h b/third_party/kvf.h index bd972e2..bda9a57 100755 --- a/third_party/kvf.h +++ b/third_party/kvf.h @@ -51,7 +51,7 @@ #ifndef KBZ_8_VULKAN_FRAMEWORK_H #define KBZ_8_VULKAN_FRAMEWORK_H -#ifdef KVF_IMPL_VK_NO_PROTOTYPES +#if defined(KVF_IMPL_VK_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES) #define VK_NO_PROTOTYPES #endif @@ -159,7 +159,7 @@ VkSampler kvfCreateSampler(VkDevice device, VkFilter filters, VkSamplerAddressMo void kvfDestroySampler(VkDevice device, VkSampler sampler); VkBuffer kvfCreateBuffer(VkDevice device, VkBufferUsageFlags usage, VkDeviceSize size); -void kvfCopyBufferToBuffer(VkCommandBuffer cmd, VkBuffer dst, VkBuffer src, size_t size); +void kvfCopyBufferToBuffer(VkCommandBuffer cmd, VkBuffer dst, VkBuffer src, size_t size, size_t src_offset, size_t dst_offset); void kvfCopyBufferToImage(VkCommandBuffer cmd, VkImage dst, VkBuffer src, size_t buffer_offset, VkImageAspectFlagBits aspect, VkExtent3D extent); void kvfDestroyBuffer(VkDevice device, VkBuffer buffer); @@ -374,12 +374,12 @@ void kvfCheckVk(VkResult result); #ifdef KVF_DESCRIPTOR_POOL_CAPACITY #undef KVF_DESCRIPTOR_POOL_CAPACITY #endif -#define KVF_DESCRIPTOR_POOL_CAPACITY 512 +#define KVF_DESCRIPTOR_POOL_CAPACITY 1024 #ifdef KVF_COMMAND_POOL_CAPACITY #undef KVF_COMMAND_POOL_CAPACITY #endif -#define KVF_COMMAND_POOL_CAPACITY 512 +#define KVF_COMMAND_POOL_CAPACITY 1024 typedef struct { @@ -560,6 +560,7 @@ void __kvfCompleteDevice(VkPhysicalDevice physical, VkDevice device) kvf_device->device = device; kvf_device->cmd_pool = pool; + kvf_device->callbacks = NULL; kvf_device->sets_pools = NULL; kvf_device->sets_pools_size = 0; kvf_device->cmd_buffers_size = 0; @@ -2274,7 +2275,7 @@ VkBuffer kvfCreateBuffer(VkDevice device, VkBufferUsageFlags usage, VkDeviceSize return buffer; } -void kvfCopyBufferToBuffer(VkCommandBuffer cmd, VkBuffer dst, VkBuffer src, size_t size) +void kvfCopyBufferToBuffer(VkCommandBuffer cmd, VkBuffer dst, VkBuffer src, size_t size, size_t src_offset, size_t dst_offset) { KVF_ASSERT(cmd != VK_NULL_HANDLE); KVF_ASSERT(dst != VK_NULL_HANDLE); @@ -2285,6 +2286,8 @@ void kvfCopyBufferToBuffer(VkCommandBuffer cmd, VkBuffer dst, VkBuffer src, size #endif VkBufferCopy copy_region = {}; copy_region.size = size; + copy_region.srcOffset = src_offset; + copy_region.dstOffset = dst_offset; KVF_GET_DEVICE_FUNCTION(vkCmdCopyBuffer)(cmd, src, dst, 1, ©_region); } @@ -2540,7 +2543,7 @@ VkAttachmentDescription kvfBuildAttachmentDescription(KvfImageType type, VkForma __KvfSwapchain* kvf_swapchain = __kvfGetKvfSwapchainFromVkSwapchainKHR(swapchain); KVF_ASSERT(kvf_swapchain != NULL); KVF_ASSERT(kvf_swapchain->images_count != 0); - return kvfBuildAttachmentDescription(KVF_IMAGE_COLOR, kvf_swapchain->images_format, VK_IMAGE_LAYOUT_UNDEFINED,VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, clear, VK_SAMPLE_COUNT_1_BIT); + return kvfBuildAttachmentDescription(KVF_IMAGE_COLOR, kvf_swapchain->images_format, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, clear, VK_SAMPLE_COUNT_1_BIT); } #endif