From f7ea6cd1d912c35d41dc51c344be751d52c02872 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Tue, 17 Feb 2026 12:47:01 +0800 Subject: [PATCH] [Feat] (MG_Backend/DirectVulkan): dynamically load vulkan functions for vma --- CMakeLists.txt | 18 ++++++++++++++++++ .../DirectVulkan/Renderer/VulkanRenderer.cpp | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 091d5f30..5ba2cbd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,6 +255,14 @@ set(MOBILEGL_LINK_LIBRARIES GPUOpen::VulkanMemoryAllocator ) +set(MOBILEGL_COMPILE_DEF + -DVMA_STATIC_VULKAN_FUNCTIONS=0 + -DVMA_DYNAMIC_VULKAN_FUNCTIONS=1 + -DVMA_VULKAN_VERSION=1001000 +) + +message(STATUS "MOBILEGL_COMPILE_DEF=${MOBILEGL_COMPILE_DEF}") + set(MOBILEGL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/MobileGL @@ -291,6 +299,11 @@ target_link_libraries(${CMAKE_PROJECT_NAME} ${MOBILEGL_LINK_LIBRARIES} ) +target_compile_definitions(${CMAKE_PROJECT_NAME} + PUBLIC + ${MOBILEGL_COMPILE_DEF} +) + if(NOT ANDROID) add_library(${CMAKE_PROJECT_NAME}_s STATIC ${SOURCE_FILES} @@ -318,6 +331,11 @@ if(NOT ANDROID) PUBLIC ${MOBILEGL_LINK_LIBRARIES} ) + + target_compile_definitions(${CMAKE_PROJECT_NAME}_s + PUBLIC + ${MOBILEGL_COMPILE_DEF} + ) endif() if (TRACY_ENABLE) diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp index 2940c4f6..3599e370 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp @@ -1020,9 +1020,13 @@ namespace MobileGL::MG_Backend::DirectVulkan { } VmaAllocatorCreateInfo allocatorInfo{}; + VmaVulkanFunctions vulkanFunctions{}; + vulkanFunctions.vkGetInstanceProcAddr = vkGetInstanceProcAddr; + vulkanFunctions.vkGetDeviceProcAddr = vkGetDeviceProcAddr; allocatorInfo.instance = m_instance; allocatorInfo.physicalDevice = m_physicalDevice.handle; allocatorInfo.device = m_device; + allocatorInfo.pVulkanFunctions = &vulkanFunctions; allocatorInfo.vulkanApiVersion = VK_API_VERSION_1_0; VK_VERIFY(vmaCreateAllocator(&allocatorInfo, &m_allocator), "vmaCreateAllocator");