Skip to content

Commit 8656f5d

Browse files
authored
vulkan : make the vulkan.hpp dynamic dispatcher instance private (#16224)
* don't use VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE which can cause conflicts if application or other libraries do the same
1 parent 4807e8f commit 8656f5d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ggml/src/ggml-vulkan/ggml-vulkan.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
// See https://github.com/KhronosGroup/Vulkan-Hpp?tab=readme-ov-file#extensions--per-device-function-pointers-
99
#define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1
10+
// We use VULKAN_HPP_DEFAULT_DISPATCHER, but not VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE
11+
// to avoid conflicts with applications or other libraries who might use it.
12+
namespace vk::detail { class DispatchLoaderDynamic; }
13+
vk::detail::DispatchLoaderDynamic & ggml_vk_default_dispatcher();
14+
#define VULKAN_HPP_DEFAULT_DISPATCHER ggml_vk_default_dispatcher()
1015

1116
#include <vulkan/vulkan.hpp>
1217

13-
// See https://github.com/KhronosGroup/Vulkan-Hpp?tab=readme-ov-file#extensions--per-device-function-pointers-
14-
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE
15-
1618
#include <algorithm>
1719
#include <cmath>
1820
#include <iomanip>
@@ -4508,14 +4510,20 @@ static bool ggml_vk_instance_portability_enumeration_ext_available(const std::ve
45084510
static bool ggml_vk_instance_debug_utils_ext_available(const std::vector<vk::ExtensionProperties> & instance_extensions);
45094511
static bool ggml_vk_device_is_supported(const vk::PhysicalDevice & vkdev);
45104512

4513+
static vk::detail::DispatchLoaderDynamic ggml_vk_default_dispatcher_instance;
4514+
4515+
vk::detail::DispatchLoaderDynamic & ggml_vk_default_dispatcher() {
4516+
return ggml_vk_default_dispatcher_instance;
4517+
}
4518+
45114519
static void ggml_vk_instance_init() {
45124520
if (vk_instance_initialized) {
45134521
return;
45144522
}
45154523
VK_LOG_DEBUG("ggml_vk_instance_init()");
45164524

45174525
// See https://github.com/KhronosGroup/Vulkan-Hpp?tab=readme-ov-file#extensions--per-device-function-pointers-
4518-
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
4526+
ggml_vk_default_dispatcher_instance.init(vkGetInstanceProcAddr);
45194527

45204528
uint32_t api_version = vk::enumerateInstanceVersion();
45214529

0 commit comments

Comments
 (0)