Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
vulkan_interface.h
Go to the documentation of this file.
1#ifndef HALIDE_RUNTIME_VULKAN_INTERFACE_H
2#define HALIDE_RUNTIME_VULKAN_INTERFACE_H
3
4#include "runtime_internal.h"
5
6// --------------------------------------------------------------------------
7// Vulkan Specific Definitions
8// --------------------------------------------------------------------------
9
10// Vulkan API version identifier macro
11#define VK_MAKE_API_VERSION(variant, major, minor, patch) \
12 ((((uint32_t)(variant)) << 29) | (((uint32_t)(major)) << 22) | (((uint32_t)(minor)) << 12) | ((uint32_t)(patch)))
13
14// Vulkan API version 1.0.0
15#define VK_API_VERSION_1_0 VK_MAKE_API_VERSION(0, 1, 0, 0) // Patch version should always be set to 0
16
17// Environment variable string delimiter
18#ifdef WINDOWS
19#define HL_VK_ENV_DELIM ";"
20#else
21#define HL_VK_ENV_DELIM ":"
22#endif
23
24// Prototypes for the subset of the Vulkan API we need
25#define VK_NO_PROTOTYPES
26// NOLINTNEXTLINE
27#include "mini_vulkan.h"
28
29// --------------------------------------------------------------------------
30// Vulkan API Definition
31// --------------------------------------------------------------------------
32
33namespace Halide {
34namespace Runtime {
35namespace Internal {
36namespace Vulkan {
37
38// --------------------------------------------------------------------------
39
40// Halide device interface struct for runtime specific function table
42
43// --------------------------------------------------------------------------
44
45// The default implementation of halide_vulkan_get_symbol attempts to load
46// the Vulkan loader shared library/DLL, and then get the symbol from it.
47WEAK void *lib_vulkan = nullptr;
49extern "C" WEAK void *halide_vulkan_get_symbol(void *user_context, const char *name) {
50 // Only try to load the library if the library isn't already
51 // loaded, or we can't load the symbol from the process already.
52 void *symbol = halide_get_library_symbol(lib_vulkan, name);
53 if (symbol) {
54 return symbol;
55 }
56
57 const char *lib_names[] = {
58#ifdef WINDOWS
59 "vulkan-1.dll",
60#else
61 "libvulkan.so.1",
62 "libvulkan.1.dylib",
63#endif
64 };
65 for (auto &lib_name : lib_names) {
67 if (lib_vulkan) {
68 debug(user_context) << " Loaded Vulkan loader library: " << lib_name << "\n";
69 break;
70 } else {
71 debug(user_context) << " Missing Vulkan loader library: " << lib_name << "\n";
72 }
73 }
74
76}
77
78// Declare all the function pointers for the Vulkan API methods that will be resolved dynamically
79// clang-format off
80#define VULKAN_FN(fn) WEAK PFN_##fn fn;
83#include "vulkan_functions.h"
84#undef VULKAN_FN
85// clang-format on
86
87// Get the function pointers from the Vulkan loader to create an Instance (to find all available driver implementations)
88void WEAK vk_load_vulkan_loader_functions(void *user_context) {
89 debug(user_context) << " vk_load_vulkan_loader_functions (user_context: " << user_context << ")\n";
90#define VULKAN_FN(fn) fn = (PFN_##fn)halide_vulkan_get_symbol(user_context, #fn);
93#undef VULKAN_FN
94}
95
96// Get the function pointers from the Vulkan instance for the resolved driver API methods.
97void WEAK vk_load_vulkan_functions(void *user_context, VkInstance instance) {
98 debug(user_context) << " vk_load_vulkan_functions (user_context: " << user_context << ")\n";
99#define VULKAN_FN(fn) fn = (PFN_##fn)vkGetInstanceProcAddr(instance, #fn);
100#include "vulkan_functions.h"
101#undef VULKAN_FN
102}
103
104// --------------------------------------------------------------------------
105
106} // namespace Vulkan
107} // namespace Internal
108} // namespace Runtime
109} // namespace Halide
110
111#endif // HALIDE_RUNTIME_VULKAN_INTERFACE_H
void * halide_get_library_symbol(void *lib, const char *name)
void * halide_load_library(const char *name)
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *pName)
VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkInstance *pInstance)
WEAK void * halide_vulkan_get_symbol(void *user_context, const char *name)
void WEAK vk_load_vulkan_functions(void *user_context, VkInstance instance)
WEAK halide_device_interface_t vulkan_device_interface
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
#define WEAK
Each GPU API provides a halide_device_interface_t struct pointing to the code that manages device all...
#define VULKAN_FN(fn)