1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #ifndef AVUTIL_VULKAN_LOADER_H
20 #define AVUTIL_VULKAN_LOADER_H
21
22 #include <stdio.h>
23
26
27 /* Macro to turn a function name into a loader struct */
28 #define PFN_LOAD_INFO(req_inst, req_dev, ext_flag, name) \
29 { \
30 req_inst, \
31 req_dev, \
32 offsetof(FFVulkanFunctions, name), \
33 ext_flag, \
34 },
35
37 int nb_extensions)
38 {
39 static const struct ExtensionMap {
42 } extension_map[] = {
43 /* Instance extensions */
45
46 /* Device extensions */
47 #ifdef VK_KHR_shader_relaxed_extended_instruction
49 #endif
63 #ifdef VK_EXT_zero_initialize_device_memory
65 #endif
67 #ifdef VK_KHR_video_maintenance2
69 #endif
70 #ifdef _WIN32
73 #endif
82 #ifdef VK_KHR_video_decode_vp9
84 #endif
87 #ifdef VK_KHR_shader_expect_assume
89 #endif
90 #ifdef VK_KHR_video_encode_av1
92 #endif
93 };
94
96
97 for (
int i = 0;
i < nb_extensions;
i++) {
99 if (!strcmp(extensions[
i], extension_map[j].
name)) {
100 mask |= extension_map[j].flag;
101 continue;
102 }
103 }
104 }
105
107 }
108
109 /**
110 * Function loader.
111 * Vulkan function from scratch loading happens in 3 stages - the first one
112 * is before any initialization has happened, and you have neither an instance
113 * structure nor a device structure. At this stage, you can only get the bare
114 * minimals to initialize an instance.
115 * The second stage is when you have an instance. At this stage, you can
116 * initialize a VkDevice, and have an idea of what extensions each device
117 * supports.
118 * Finally, in the third stage, you can proceed and load all core functions,
119 * plus you can be sure that any extensions you've enabled during device
120 * initialization will be available.
121 */
124 uint64_t extensions_mask,
125 int has_inst, int has_dev)
126 {
128
129 static const struct FunctionLoadInfo {
130 char req_inst;
131 char req_dev;
132 uint16_t struct_offset;
134 } vk_load_info[] = {
136 #ifdef _WIN32
138 #endif
139 };
140 // Concatenate the names to avoid relocations. The resulting string
141 // will end with 0円0円
142 #define FUNC_NAME(req_inst, req_dev, ext_flag, name) "vk"#name"0円"
145 #ifdef _WIN32
147 #endif
148 ;
149 #undef FUNC_NAME
150
152 const struct FunctionLoadInfo *load = &vk_load_info[
i];
153 static const char extensions[][4] = { "", "EXT", "KHR" };
154 PFN_vkVoidFunction
fn;
155
156 if (load->req_dev && !has_dev)
157 continue;
158 if (load->req_inst && !has_inst)
159 continue;
160
162 char ext_name[128];
164
165 n =
snprintf(ext_name,
sizeof(ext_name),
"%s%s",
name, extensions[j]);
167
168 if (load->req_dev)
169 fn = vk->GetDeviceProcAddr(hwctx->
act_dev, ext_name);
170 else if (load->req_inst)
172 else
174
176 break;
177 }
178
181 "as supported, but got NULL function pointer!\n",
name);
183 }
184
185 *(PFN_vkVoidFunction *)((uint8_t *)vk + load->struct_offset) =
fn;
186 }
188
189 return 0;
190 }
191
192 #endif /* AVUTIL_VULKAN_LOADER_H */