Skip to content

Commit ecd97d5

Browse files
ssjiaSS-JIA
authored andcommitted
[ET-VK] Add etvk.use_existing_vma config to avoid duplicate VMA symbols
Pull Request resolved: #18522 Apps that already link VulkanMemoryAllocatorInstantiated (e.g. Stella, via IGL or Diamond/Skia) get duplicate symbol errors when also linking ExecuTorch's Vulkan backend, because vma_api.cpp defines VMA_IMPLEMENTATION independently. Add a Buck config flag `etvk.use_existing_vma=1` that: - Defines ETVK_USE_META_VMA, which makes vma_api.h match the third-party VulkanMemoryAllocatorInstantiated config (Vulkan 1.2, dynamic function loading) so struct layouts agree - Skips VMA_IMPLEMENTATION in vma_api.cpp so no duplicate definitions are emitted - Swaps the Buck dep from VulkanMemoryAllocator_xplat (header-only) to VulkanMemoryAllocatorInstantiated (pre-compiled) Off by default — no behavior change for existing builds or OSS. ghstack-source-id: 364855830 @exported-using-ghexport Differential Revision: [D98250268](https://our.internmc.facebook.com/intern/diff/D98250268/)
1 parent 6b63d3d commit ecd97d5

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

backends/vulkan/runtime/vk_api/memory/vma_api.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
#ifndef ETVK_USE_META_VMA
910
#define VMA_IMPLEMENTATION
11+
#endif
1012
#include <executorch/backends/vulkan/runtime/vk_api/memory/vma_api.h>

backends/vulkan/runtime/vk_api/memory/vma_api.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,32 @@
1313
// Always include this file (vma_api.h) instead.
1414
//
1515

16+
#ifdef ETVK_USE_META_VMA
17+
18+
// Match the config from the shared third-party
19+
// VulkanMemoryAllocatorInstantiated library so that struct layouts agree.
20+
// We do NOT define VMA_IMPLEMENTATION here; the third-party static lib
21+
// provides it.
22+
#undef VMA_STATIC_VULKAN_FUNCTIONS
23+
#undef VMA_DYNAMIC_VULKAN_FUNCTIONS
24+
#define VMA_STATIC_VULKAN_FUNCTIONS 0
25+
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
26+
#define VMA_VULKAN_VERSION 1002000
27+
28+
#ifdef __clang__
29+
#pragma clang diagnostic push
30+
#pragma clang diagnostic ignored "-Wnullability-completeness"
31+
#pragma clang diagnostic ignored "-Wunused-variable"
32+
#endif /* __clang__ */
33+
34+
#include <vk_mem_alloc.h>
35+
36+
#ifdef __clang__
37+
#pragma clang diagnostic pop
38+
#endif /* __clang__ */
39+
40+
#else // !ETVK_USE_META_VMA
41+
1642
#define VMA_VULKAN_VERSION 1000000
1743

1844
#ifdef USE_VULKAN_WRAPPER
@@ -56,3 +82,5 @@
5682
#ifdef __clang__
5783
#pragma clang diagnostic pop
5884
#endif /* __clang__ */
85+
86+
#endif // ETVK_USE_META_VMA

backends/vulkan/targets.bzl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ def get_vulkan_preprocessor_flags(no_volk, is_fbcode):
6969
if debug_mode:
7070
VK_API_PREPROCESSOR_FLAGS += ["-DVULKAN_DEBUG"]
7171

72+
vma_dep = read_config("etvk", "vma_dep", "xplat")
73+
if vma_dep == "instantiated":
74+
VK_API_PREPROCESSOR_FLAGS += ["-DETVK_USE_META_VMA"]
75+
7276
if force_no_extensions:
7377
VK_API_PREPROCESSOR_FLAGS += ["-DETVK_FORCE_NO_EXTENSIONS"]
7478

@@ -152,6 +156,7 @@ def vulkan_spv_shader_lib(name, spv_filegroups, is_fbcode = False, no_volk = Fal
152156

153157
def define_common_targets(is_fbcode = False):
154158
debug_mode = read_config("etvk", "debug", "0") == "1"
159+
vma_dep = read_config("etvk", "vma_dep", "xplat")
155160

156161
runtime.python_library(
157162
name = "gen_vulkan_spv_lib",
@@ -185,9 +190,14 @@ def define_common_targets(is_fbcode = False):
185190

186191
suffix = "_no_volk" if no_volk else ""
187192

188-
VK_API_DEPS = [
189-
"fbsource//third-party/VulkanMemoryAllocator/3.2.0:VulkanMemoryAllocator_xplat",
190-
]
193+
if vma_dep == "instantiated":
194+
VK_API_DEPS = [
195+
"fbsource//third-party/VulkanMemoryAllocator/3.0.1:VulkanMemoryAllocatorInstantiated",
196+
]
197+
else:
198+
VK_API_DEPS = [
199+
"fbsource//third-party/VulkanMemoryAllocator/3.2.0:VulkanMemoryAllocator_xplat",
200+
]
191201

192202
default_deps = []
193203
android_deps = ["fbsource//third-party/toolchains:android"]

0 commit comments

Comments
 (0)