Simplifying VMA build integration.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dba9ea9..f8c27f9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -409,6 +409,7 @@
add_subdirectory(build_tools/third_party/pffft EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/renderdoc_api EXCLUDE_FROM_ALL)
add_subdirectory(build_tools/third_party/ruy EXCLUDE_FROM_ALL)
+add_subdirectory(build_tools/third_party/vulkan_memory_allocator EXCLUDE_FROM_ALL)
add_subdirectory(third_party/cpuinfo EXCLUDE_FROM_ALL)
add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
diff --git a/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py b/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
index 468ab6e..ca99267 100644
--- a/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
+++ b/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
@@ -74,6 +74,7 @@
"@sdl2//:SDL2": ["SDL2-static"],
"@com_github_pytorch_cpuinfo//:cpuinfo": ["cpuinfo"],
"@half//:half": ["half"],
+ "@vulkan_memory_allocator//:impl_header_only": ["vulkan_memory_allocator"],
}
diff --git a/build_tools/third_party/vulkan_memory_allocator/CMakeLists.txt b/build_tools/third_party/vulkan_memory_allocator/CMakeLists.txt
new file mode 100644
index 0000000..5e8a120
--- /dev/null
+++ b/build_tools/third_party/vulkan_memory_allocator/CMakeLists.txt
@@ -0,0 +1,28 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set(VMA_ROOT "${IREE_ROOT_DIR}/third_party/vulkan_memory_allocator/")
+
+external_cc_library(
+ PACKAGE
+ vulkan_memory_allocator
+ NAME
+ vulkan_memory_allocator
+ ROOT
+ ${VMA_ROOT}
+ HDRS
+ "src/vk_mem_alloc.h"
+ INCLUDES
+ "${VMA_ROOT}/src/"
+)
diff --git a/iree/hal/vulkan/BUILD b/iree/hal/vulkan/BUILD
index a00ccef..79956c6 100644
--- a/iree/hal/vulkan/BUILD
+++ b/iree/hal/vulkan/BUILD
@@ -411,21 +411,13 @@
"vma_allocator.h",
"vma_buffer.h",
],
- copts = [
- # Only needed in the implementation cc and not by external users.
- "-DVMA_STATIC_VULKAN_FUNCTIONS=0",
- ] + select({
- "//iree:iree_is_msvc": [],
- "//conditions:default": [
- "-Wno-thread-safety-attributes", # External code.
- ],
- }),
deps = [
":dynamic_symbols",
":handle_util",
":status_util",
"//iree/base:logging",
"//iree/base:status",
+ "//iree/base:target_platform",
"//iree/base:tracing",
"//iree/hal:allocator",
"//iree/hal:buffer",
diff --git a/iree/hal/vulkan/CMakeLists.txt b/iree/hal/vulkan/CMakeLists.txt
index 19e3685..11a7c9a 100644
--- a/iree/hal/vulkan/CMakeLists.txt
+++ b/iree/hal/vulkan/CMakeLists.txt
@@ -475,21 +475,13 @@
"vma_buffer.cc"
COPTS
"-DVK_NO_PROTOTYPES"
- # Only needed in the implementation cc and not by external users.
- "-DVMA_STATIC_VULKAN_FUNCTIONS=0"
- # Silence some warnings.
- "-Wno-nullability-completeness"
- # Note: IREE_DEFAULT_COPTS sets -Wthread-safety-analysis, so we can't
- # disable here without switching off of iree_cc_library or refactoring
- # "-Wno-thread-safety-analysis"
- INCLUDES
- ${VMA_SRC_ROOT}
DEPS
absl::flat_hash_map
absl::memory
absl::synchronization
iree::base::logging
iree::base::status
+ iree::base::target_platform
iree::base::tracing
iree::hal::allocator
iree::hal::buffer
@@ -497,6 +489,7 @@
iree::hal::vulkan::handle_util
iree::hal::vulkan::status_util
Vulkan::Headers
+ vulkan_memory_allocator
PUBLIC
)
diff --git a/iree/hal/vulkan/internal_vk_mem_alloc.cc b/iree/hal/vulkan/internal_vk_mem_alloc.cc
index 95747a7..b45f66a 100644
--- a/iree/hal/vulkan/internal_vk_mem_alloc.cc
+++ b/iree/hal/vulkan/internal_vk_mem_alloc.cc
@@ -71,6 +71,6 @@
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
#define VMA_IMPLEMENTATION
-#include "vk_mem_alloc.h"
+#include "iree/hal/vulkan/internal_vk_mem_alloc.h"
-#endif
+#endif // !VULKAN_MEMORY_ALLOCATOR_EXTERNAL_IMPL
diff --git a/iree/hal/vulkan/internal_vk_mem_alloc.h b/iree/hal/vulkan/internal_vk_mem_alloc.h
index 591ce7e..46bd63d 100644
--- a/iree/hal/vulkan/internal_vk_mem_alloc.h
+++ b/iree/hal/vulkan/internal_vk_mem_alloc.h
@@ -15,6 +15,16 @@
#ifndef IREE_HAL_VULKAN_INTERNAL_VK_MEM_ALLOC_H_
#define IREE_HAL_VULKAN_INTERNAL_VK_MEM_ALLOC_H_
-#include "vk_mem_alloc.h"
+// Force all Vulkan calls to go through an indirect pVulkanFunctions interface.
+// https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/configuration.html
+#define VMA_STATIC_VULKAN_FUNCTIONS 0
+
+// Allow VMA to query for dynamic functions we may not have provided.
+// TODO(benvanik): see if we can remove this for more predictable failures; we
+// want our code to be printing out nice symbol-not-found errors, not VMA
+// abort()ing.
+#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
+
+#include <vk_mem_alloc.h>
#endif // IREE_HAL_VULKAN_INTERNAL_VK_MEM_ALLOC_H_
diff --git a/iree/hal/vulkan/vma_buffer.h b/iree/hal/vulkan/vma_buffer.h
index b768f71..24352fa 100644
--- a/iree/hal/vulkan/vma_buffer.h
+++ b/iree/hal/vulkan/vma_buffer.h
@@ -18,7 +18,7 @@
#include <vulkan/vulkan.h>
#include "iree/hal/buffer.h"
-#include "vk_mem_alloc.h"
+#include "iree/hal/vulkan/internal_vk_mem_alloc.h"
namespace iree {
namespace hal {