2 * This file is part of FFmpeg.
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.
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.
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
19#ifndef AVUTIL_VULKAN_LOADER_H
20#define AVUTIL_VULKAN_LOADER_H
27/* Macro to turn a function name into a loader struct */
28 #define PFN_LOAD_INFO(req_inst, req_dev, ext_flag, name) \
32 offsetof(FFVulkanFunctions, name), \
39 static const struct ExtensionMap {
43 /* Instance extensions */
46 /* Device extensions */
47#ifdef VK_KHR_shader_relaxed_extended_instruction
64#ifdef VK_EXT_shader_long_vector
67#ifdef VK_EXT_shader_replicated_composites
70#ifdef VK_EXT_zero_initialize_device_memory
74#ifdef VK_KHR_video_maintenance2
88#ifdef VK_KHR_video_decode_vp9
93#ifdef VK_KHR_shader_expect_assume
96#ifdef VK_KHR_shader_maximal_reconvergence
99#ifdef VK_KHR_maintenance9
102#ifdef VK_KHR_unified_image_layouts
105#ifdef VK_KHR_video_encode_av1
108#ifdef VK_KHR_internally_synchronized_queues
115 for (
int i = 0;
i < nb_extensions;
i++) {
117 if (!strcmp(extensions[
i], extension_map[j].
name)) {
118 mask |= extension_map[j].flag;
129 * Vulkan function from scratch loading happens in 3 stages - the first one
130 * is before any initialization has happened, and you have neither an instance
131 * structure nor a device structure. At this stage, you can only get the bare
132 * minimals to initialize an instance.
133 * The second stage is when you have an instance. At this stage, you can
134 * initialize a VkDevice, and have an idea of what extensions each device
136 * Finally, in the third stage, you can proceed and load all core functions,
137 * plus you can be sure that any extensions you've enabled during device
138 * initialization will be available.
142 uint64_t extensions_mask,
143 int has_inst,
int has_dev)
147 static const struct FunctionLoadInfo {
150 uint16_t struct_offset;
158 // Concatenate the names to avoid relocations. The resulting string
159 // will end with 0円0円
160#define FUNC_NAME(req_inst, req_dev, ext_flag, name) "vk"#name"0円"
170 const struct FunctionLoadInfo *load = &vk_load_info[
i];
171 static const char extensions[][4] = {
"",
"EXT",
"KHR" };
172 PFN_vkVoidFunction
fn;
174 if (load->req_dev && !has_dev)
176 if (load->req_inst && !has_inst)
183 n =
snprintf(ext_name,
sizeof(ext_name),
"%s%s",
name, extensions[j]);
187 fn = vk->GetDeviceProcAddr(hwctx->
act_dev, ext_name);
188 else if (load->req_inst)
199 "as supported, but got NULL function pointer!\n",
name);
203 *(PFN_vkVoidFunction *)((uint8_t *)vk + load->struct_offset) =
fn;
210#endif /* AVUTIL_VULKAN_LOADER_H */
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define i(width, name, range_min, range_max)
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FUNC_NAME(rw, codec, name)
static const uint16_t mask[17]
#define FF_ARRAY_ELEMS(a)
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
VkDevice act_dev
Active device.
VkInstance inst
Vulkan instance.
PFN_vkGetInstanceProcAddr get_proc_addr
Pointer to a vkGetInstanceProcAddr loading function.
#define FF_VK_EXT_VIDEO_ENCODE_AV1
#define FF_VK_EXT_EXPLICIT_MEM_LAYOUT
#define FF_VK_EXT_VIDEO_DECODE_H265
#define FF_VK_EXT_RELAXED_EXTENDED_INSTR
#define FF_VK_EXT_EXTERNAL_FD_SEM
#define FF_VK_EXT_VIDEO_MAINTENANCE_1
#define FF_VK_EXT_DRM_MODIFIER_FLAGS
#define FF_VK_EXT_SHADER_OBJECT
#define FF_VK_EXT_VIDEO_QUEUE
#define FF_VK_EXT_UNIFIED_IMAGE_LAYOUTS
uint64_t FFVulkanExtensions
#define FF_VK_EXT_COOP_MATRIX
#define FF_VK_EXT_INTERNAL_QUEUE_SYNC
#define FF_VK_EXT_VIDEO_ENCODE_QUEUE
#define FF_VK_EXT_NO_FLAG
#define FF_VK_EXT_VIDEO_DECODE_AV1
#define FF_VK_EXT_OPTICAL_FLOW
#define FF_VK_EXT_EXTERNAL_DMABUF_MEMORY
#define FF_VK_EXT_SUBGROUP_ROTATE
#define FF_VK_EXT_PUSH_DESCRIPTOR
#define FF_VK_EXT_MAXIMAL_RECONVERGENCE
#define FF_VK_EXT_DEVICE_DRM
#define FF_VK_EXT_VIDEO_DECODE_H264
#define FF_VK_EXT_VIDEO_ENCODE_H264
#define FF_VK_EXT_VIDEO_DECODE_QUEUE
#define FF_VK_EXT_LONG_VECTOR
#define FF_VK_EXT_VIDEO_DECODE_VP9
#define FN_LIST_WIN32(MACRO)
#define FF_VK_EXT_EXTERNAL_WIN32_SEM
#define FF_VK_EXT_MAINTENANCE_9
#define FF_VK_EXT_EXPECT_ASSUME
#define FF_VK_EXT_HOST_IMAGE_COPY
#define FF_VK_EXT_EXTERNAL_FD_MEMORY
#define FF_VK_EXT_ZERO_INITIALIZE
#define FF_VK_EXT_REPLICATED_COMPOSITES
#define FF_VK_EXT_DEBUG_UTILS
#define FF_VK_EXT_VIDEO_ENCODE_H265
#define FF_VK_EXT_ATOMIC_FLOAT
#define FF_VK_EXT_EXTERNAL_HOST_MEMORY
#define FF_VK_EXT_EXTERNAL_WIN32_MEMORY
#define FF_VK_EXT_VIDEO_MAINTENANCE_2
static uint64_t ff_vk_extensions_to_mask(const char *const *extensions, int nb_extensions)
static int ff_vk_load_functions(AVHWDeviceContext *ctx, FFVulkanFunctions *vk, uint64_t extensions_mask, int has_inst, int has_dev)
Function loader.
#define PFN_LOAD_INFO(req_inst, req_dev, ext_flag, name)