From b5bae50f55716e8104d728dfd80e250ed778f07b Mon Sep 17 00:00:00 2001 From: Alexandre Date: Fri, 9 Oct 2026 20:50:02 +0200 Subject: [PATCH] Switched to Volk --- CMakeLists.txt | 28 ++++++++++++++-------------- src/Common/Types.h | 4 ++-- src/Engine/engine/engine.h | 5 +++++ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bdd7ce1..83a1ae3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,13 @@ endif() # --------------------------------------------------------------------------- # Dependencies # --------------------------------------------------------------------------- -set(ENGINE_EXTRA_DEFINITIONS "") +# Same in every mode: no link-time dependency on libvulkan, all Vulkan +# functions come from volk (otherwise vk*KHR aliases are undefined at link). +set(ENGINE_EXTRA_DEFINITIONS + VK_NO_PROTOTYPES + VMA_STATIC_VULKAN_FUNCTIONS=0 + VMA_DYNAMIC_VULKAN_FUNCTIONS=1 +) if(VULKANENGINE_FETCH_DEPS) # Portable = static libs, bundle = shared libs (in lib/) @@ -118,7 +124,7 @@ if(VULKANENGINE_FETCH_DEPS) GIT_REPOSITORY https://github.com/zeux/volk.git GIT_TAG 1.4.304) FetchContent_Declare(VMA - GIT_REPOSITORY https://github.com/GPUOpen-LibrariesAndPatches/VulkanMemoryAllocator.git + GIT_REPOSITORY https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git GIT_TAG v3.2.1) FetchContent_Declare(glfw GIT_REPOSITORY https://github.com/glfw/glfw.git @@ -145,14 +151,9 @@ if(VULKANENGINE_FETCH_DEPS) target_link_libraries(volk PUBLIC Vulkan::Headers) - # No link-time dependency on libvulkan: functions come from volk - list(APPEND ENGINE_EXTRA_DEFINITIONS - VK_NO_PROTOTYPES - VMA_STATIC_VULKAN_FUNCTIONS=0 - VMA_DYNAMIC_VULKAN_FUNCTIONS=1 - ) else() - # Nix path (unchanged) + # Nix path + find_package( volk CONFIG REQUIRED ) find_package( glfw3 REQUIRED ) find_package( glm REQUIRED ) find_package( VulkanMemoryAllocator CONFIG REQUIRED ) @@ -297,10 +298,8 @@ function ( addBinary BINARY_NAME ) ${CMAKE_SOURCE_DIR}/include/imgui/backends/imgui_impl_vulkan.cpp ) - # imgui's Vulkan backend must use volk when there is no linked loader - if(VULKANENGINE_FETCH_DEPS) - target_compile_definitions(${BINARY_NAME} PRIVATE IMGUI_IMPL_VULKAN_USE_VOLK) - endif() + # imgui's Vulkan backend must use volk since there is no linked loader + target_compile_definitions(${BINARY_NAME} PRIVATE IMGUI_IMPL_VULKAN_USE_VOLK) endif() @@ -410,7 +409,8 @@ if(VULKANENGINE_FETCH_DEPS) simdjson::simdjson ) else() - list(APPEND lib_list vulkan) + # Nix: volk comes from nixpkgs (vulkan-volk); libvulkan is NOT linked + list(APPEND lib_list volk::volk) endif() addBinary ( diff --git a/src/Common/Types.h b/src/Common/Types.h index a00d716..8037c46 100644 --- a/src/Common/Types.h +++ b/src/Common/Types.h @@ -15,12 +15,12 @@ #include #include -#include +#include #include #include #include -#define GLFW_INCLUDE_VULKAN +#define GLFW_INCLUDE_NONE #include #define GLM_ENABLE_EXPERIMENTAL diff --git a/src/Engine/engine/engine.h b/src/Engine/engine/engine.h index 92eb399..d66a4f3 100644 --- a/src/Engine/engine/engine.h +++ b/src/Engine/engine/engine.h @@ -624,6 +624,7 @@ void Engine::initVulkan() { #ifdef DEBUG _logger.logRAM(ENGINE, EINIT, "Initializing Vulkan..."); #endif + volkInitialize(); vkb::InstanceBuilder builder; // Create a basic VK instance, with debuging features if compiled in debug mode @@ -639,6 +640,8 @@ void Engine::initVulkan() { _instance = vkbInst.instance; _debugMessenger = vkbInst.debug_messenger; + volkLoadInstance(_instance); + // Create the surface if (glfwCreateWindowSurface(_instance, window, nullptr, & _surface) != VK_SUCCESS) { _logger.logFatal(ENGINE, "Failed to create window surface !\nAborting..."); @@ -769,6 +772,8 @@ void Engine::initVulkan() { vkGetDeviceQueue(_device, _graphicsQueueFamily, 0, &_graphicsQueue); } + volkLoadDevice(_device); + VmaAllocatorCreateInfo allocatorInfo = { .flags = VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT, .physicalDevice = _choosenGPU,