FFmpeg
vulkan_functions.h
Go to the documentation of this file.
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_FUNCTIONS_H
20 #define AVUTIL_VULKAN_FUNCTIONS_H
21 
22 #define VK_NO_PROTOTYPES
23 #define VK_ENABLE_BETA_EXTENSIONS
24 
25 #include "hwcontext.h"
26 #include "hwcontext_vulkan.h"
27 
28 /* An enum of bitflags for every optional extension we need */
29 typedef enum FFVulkanExtensions {
30  FF_VK_EXT_EXTERNAL_DMABUF_MEMORY = 1ULL << 0, /* VK_EXT_external_memory_dma_buf */
31  FF_VK_EXT_DRM_MODIFIER_FLAGS = 1ULL << 1, /* VK_EXT_image_drm_format_modifier */
32  FF_VK_EXT_EXTERNAL_FD_MEMORY = 1ULL << 2, /* VK_KHR_external_memory_fd */
33  FF_VK_EXT_EXTERNAL_FD_SEM = 1ULL << 3, /* VK_KHR_external_semaphore_fd */
34  FF_VK_EXT_EXTERNAL_HOST_MEMORY = 1ULL << 4, /* VK_EXT_external_memory_host */
35  FF_VK_EXT_DEBUG_UTILS = 1ULL << 5, /* VK_EXT_debug_utils */
36 #ifdef _WIN32
37  FF_VK_EXT_EXTERNAL_WIN32_MEMORY = 1ULL << 6, /* VK_KHR_external_memory_win32 */
38  FF_VK_EXT_EXTERNAL_WIN32_SEM = 1ULL << 7, /* VK_KHR_external_semaphore_win32 */
39 #endif
40  FF_VK_EXT_DESCRIPTOR_BUFFER = 1ULL << 8, /* VK_EXT_descriptor_buffer */
41  FF_VK_EXT_DEVICE_DRM = 1ULL << 9, /* VK_EXT_physical_device_drm */
42  FF_VK_EXT_VIDEO_QUEUE = 1ULL << 10, /* VK_KHR_video_queue */
43  FF_VK_EXT_VIDEO_DECODE_QUEUE = 1ULL << 11, /* VK_KHR_video_decode_queue */
44  FF_VK_EXT_VIDEO_DECODE_H264 = 1ULL << 12, /* VK_EXT_video_decode_h264 */
45  FF_VK_EXT_VIDEO_DECODE_H265 = 1ULL << 13, /* VK_EXT_video_decode_h265 */
46  FF_VK_EXT_VIDEO_DECODE_AV1 = 1ULL << 14, /* VK_KHR_video_decode_av1 */
47  FF_VK_EXT_ATOMIC_FLOAT = 1ULL << 15, /* VK_EXT_shader_atomic_float */
48  FF_VK_EXT_COOP_MATRIX = 1ULL << 16, /* VK_KHR_cooperative_matrix */
49  FF_VK_EXT_OPTICAL_FLOW = 1ULL << 17, /* VK_NV_optical_flow */
50  FF_VK_EXT_SHADER_OBJECT = 1ULL << 18, /* VK_EXT_shader_object */
51 
52  FF_VK_EXT_VIDEO_MAINTENANCE_1 = 1ULL << 27, /* VK_KHR_video_maintenance1 */
53  FF_VK_EXT_VIDEO_ENCODE_QUEUE = 1ULL << 28, /* VK_KHR_video_encode_queue */
54  FF_VK_EXT_VIDEO_ENCODE_H264 = 1ULL << 29, /* VK_KHR_video_encode_h264 */
55  FF_VK_EXT_VIDEO_ENCODE_H265 = 1ULL << 30, /* VK_KHR_video_encode_h265 */
56 
57  FF_VK_EXT_NO_FLAG = 1ULL << 31,
59 
60 /* Macro containing every function that we utilize in our codebase */
61 #define FN_LIST(MACRO) \
62  /* Instance */ \
63  MACRO(0, 0, FF_VK_EXT_NO_FLAG, EnumerateInstanceExtensionProperties) \
64  MACRO(0, 0, FF_VK_EXT_NO_FLAG, EnumerateInstanceLayerProperties) \
65  MACRO(0, 0, FF_VK_EXT_NO_FLAG, CreateInstance) \
66  MACRO(1, 0, FF_VK_EXT_NO_FLAG, DestroyInstance) \
67  \
68  /* Debug */ \
69  MACRO(1, 0, FF_VK_EXT_NO_FLAG, CreateDebugUtilsMessengerEXT) \
70  MACRO(1, 0, FF_VK_EXT_NO_FLAG, DestroyDebugUtilsMessengerEXT) \
71  \
72  /* Device */ \
73  MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetDeviceProcAddr) \
74  MACRO(1, 0, FF_VK_EXT_NO_FLAG, CreateDevice) \
75  MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceFeatures2) \
76  MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceProperties) \
77  MACRO(1, 0, FF_VK_EXT_VIDEO_QUEUE, GetPhysicalDeviceVideoCapabilitiesKHR) \
78  MACRO(1, 0, FF_VK_EXT_VIDEO_QUEUE, GetPhysicalDeviceVideoFormatPropertiesKHR) \
79  MACRO(1, 0, FF_VK_EXT_NO_FLAG, DeviceWaitIdle) \
80  MACRO(1, 0, FF_VK_EXT_NO_FLAG, DestroyDevice) \
81  \
82  MACRO(1, 0, FF_VK_EXT_NO_FLAG, EnumeratePhysicalDevices) \
83  MACRO(1, 0, FF_VK_EXT_NO_FLAG, EnumerateDeviceExtensionProperties) \
84  \
85  MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceProperties2) \
86  MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceMemoryProperties) \
87  MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceFormatProperties2) \
88  MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceImageFormatProperties2) \
89  MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceQueueFamilyProperties) \
90  MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceQueueFamilyProperties2) \
91  MACRO(1, 0, FF_VK_EXT_COOP_MATRIX, GetPhysicalDeviceCooperativeMatrixPropertiesKHR) \
92  \
93  /* Command pool */ \
94  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateCommandPool) \
95  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyCommandPool) \
96  \
97  /* Command buffer */ \
98  MACRO(1, 1, FF_VK_EXT_NO_FLAG, AllocateCommandBuffers) \
99  MACRO(1, 1, FF_VK_EXT_NO_FLAG, BeginCommandBuffer) \
100  MACRO(1, 1, FF_VK_EXT_NO_FLAG, EndCommandBuffer) \
101  MACRO(1, 1, FF_VK_EXT_NO_FLAG, FreeCommandBuffers) \
102  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CmdDispatch) \
103  \
104  /* Queue */ \
105  MACRO(1, 1, FF_VK_EXT_NO_FLAG, GetDeviceQueue) \
106  MACRO(1, 1, FF_VK_EXT_NO_FLAG, QueueSubmit) \
107  MACRO(1, 1, FF_VK_EXT_NO_FLAG, QueueSubmit2) \
108  \
109  /* Fences */ \
110  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateFence) \
111  MACRO(1, 1, FF_VK_EXT_NO_FLAG, WaitForFences) \
112  MACRO(1, 1, FF_VK_EXT_NO_FLAG, ResetFences) \
113  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyFence) \
114  \
115  /* Semaphores */ \
116  MACRO(1, 1, FF_VK_EXT_EXTERNAL_FD_SEM, GetSemaphoreFdKHR) \
117  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateSemaphore) \
118  MACRO(1, 1, FF_VK_EXT_NO_FLAG, WaitSemaphores) \
119  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroySemaphore) \
120  \
121  /* Memory */ \
122  MACRO(1, 1, FF_VK_EXT_EXTERNAL_FD_MEMORY, GetMemoryFdKHR) \
123  MACRO(1, 1, FF_VK_EXT_NO_FLAG, GetMemoryFdPropertiesKHR) \
124  MACRO(1, 1, FF_VK_EXT_EXTERNAL_HOST_MEMORY, GetMemoryHostPointerPropertiesEXT) \
125  MACRO(1, 1, FF_VK_EXT_NO_FLAG, AllocateMemory) \
126  MACRO(1, 1, FF_VK_EXT_NO_FLAG, MapMemory) \
127  MACRO(1, 1, FF_VK_EXT_NO_FLAG, FlushMappedMemoryRanges) \
128  MACRO(1, 1, FF_VK_EXT_NO_FLAG, InvalidateMappedMemoryRanges) \
129  MACRO(1, 1, FF_VK_EXT_NO_FLAG, UnmapMemory) \
130  MACRO(1, 1, FF_VK_EXT_NO_FLAG, FreeMemory) \
131  \
132  /* Commands */ \
133  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CmdBindDescriptorSets) \
134  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CmdPushConstants) \
135  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CmdBindPipeline) \
136  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CmdPipelineBarrier) \
137  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CmdCopyBufferToImage) \
138  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CmdCopyImageToBuffer) \
139  \
140  /* Buffer */ \
141  MACRO(1, 1, FF_VK_EXT_NO_FLAG, GetBufferMemoryRequirements2) \
142  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateBuffer) \
143  MACRO(1, 1, FF_VK_EXT_NO_FLAG, BindBufferMemory) \
144  MACRO(1, 1, FF_VK_EXT_NO_FLAG, GetBufferDeviceAddress) \
145  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CmdFillBuffer) \
146  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyBuffer) \
147  \
148  /* Image */ \
149  MACRO(1, 1, FF_VK_EXT_DRM_MODIFIER_FLAGS, GetImageDrmFormatModifierPropertiesEXT) \
150  MACRO(1, 1, FF_VK_EXT_NO_FLAG, GetImageMemoryRequirements2) \
151  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateImage) \
152  MACRO(1, 1, FF_VK_EXT_NO_FLAG, BindImageMemory2) \
153  MACRO(1, 1, FF_VK_EXT_NO_FLAG, GetImageSubresourceLayout) \
154  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyImage) \
155  \
156  /* ImageView */ \
157  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateImageView) \
158  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyImageView) \
159  \
160  /* DescriptorSet */ \
161  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateDescriptorSetLayout) \
162  MACRO(1, 1, FF_VK_EXT_NO_FLAG, AllocateDescriptorSets) \
163  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateDescriptorPool) \
164  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyDescriptorPool) \
165  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyDescriptorSetLayout) \
166  \
167  /* Descriptor buffers */ \
168  MACRO(1, 1, FF_VK_EXT_DESCRIPTOR_BUFFER, GetDescriptorSetLayoutSizeEXT) \
169  MACRO(1, 1, FF_VK_EXT_DESCRIPTOR_BUFFER, GetDescriptorSetLayoutBindingOffsetEXT) \
170  MACRO(1, 1, FF_VK_EXT_DESCRIPTOR_BUFFER, GetDescriptorEXT) \
171  MACRO(1, 1, FF_VK_EXT_DESCRIPTOR_BUFFER, CmdBindDescriptorBuffersEXT) \
172  MACRO(1, 1, FF_VK_EXT_DESCRIPTOR_BUFFER, CmdSetDescriptorBufferOffsetsEXT) \
173  \
174  /* DescriptorUpdateTemplate */ \
175  MACRO(1, 1, FF_VK_EXT_NO_FLAG, UpdateDescriptorSetWithTemplate) \
176  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateDescriptorUpdateTemplate) \
177  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyDescriptorUpdateTemplate) \
178  \
179  /* Queries */ \
180  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateQueryPool) \
181  MACRO(1, 1, FF_VK_EXT_NO_FLAG, GetQueryPoolResults) \
182  MACRO(1, 1, FF_VK_EXT_NO_FLAG, ResetQueryPool) \
183  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CmdBeginQuery) \
184  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CmdEndQuery) \
185  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CmdResetQueryPool) \
186  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyQueryPool) \
187  \
188  /* sync2 */ \
189  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CmdPipelineBarrier2) \
190  \
191  /* Video queue */ \
192  MACRO(1, 1, FF_VK_EXT_VIDEO_QUEUE, CreateVideoSessionKHR) \
193  MACRO(1, 1, FF_VK_EXT_VIDEO_QUEUE, CreateVideoSessionParametersKHR) \
194  MACRO(1, 1, FF_VK_EXT_VIDEO_QUEUE, GetVideoSessionMemoryRequirementsKHR) \
195  MACRO(1, 1, FF_VK_EXT_VIDEO_QUEUE, BindVideoSessionMemoryKHR) \
196  MACRO(1, 1, FF_VK_EXT_VIDEO_QUEUE, CmdBeginVideoCodingKHR) \
197  MACRO(1, 1, FF_VK_EXT_VIDEO_QUEUE, CmdControlVideoCodingKHR) \
198  MACRO(1, 1, FF_VK_EXT_VIDEO_QUEUE, CmdEndVideoCodingKHR) \
199  MACRO(1, 1, FF_VK_EXT_VIDEO_QUEUE, DestroyVideoSessionParametersKHR) \
200  MACRO(1, 1, FF_VK_EXT_VIDEO_QUEUE, DestroyVideoSessionKHR) \
201  \
202  /* Video decoding */ \
203  MACRO(1, 1, FF_VK_EXT_VIDEO_DECODE_QUEUE, CmdDecodeVideoKHR) \
204  \
205  /* Video encoding */ \
206  MACRO(1, 1, FF_VK_EXT_VIDEO_ENCODE_QUEUE, CmdEncodeVideoKHR) \
207  MACRO(1, 1, FF_VK_EXT_VIDEO_ENCODE_QUEUE, GetEncodedVideoSessionParametersKHR) \
208  MACRO(1, 0, FF_VK_EXT_VIDEO_ENCODE_QUEUE, GetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR) \
209  \
210  /* Pipeline */ \
211  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreatePipelineLayout) \
212  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyPipelineLayout) \
213  \
214  /* PipelineLayout */ \
215  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateComputePipelines) \
216  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyPipeline) \
217  \
218  /* Sampler */ \
219  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateSamplerYcbcrConversion) \
220  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroySamplerYcbcrConversion) \
221  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateSampler) \
222  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroySampler) \
223  \
224  /* Optical flow */ \
225  MACRO(1, 1, FF_VK_EXT_OPTICAL_FLOW, BindOpticalFlowSessionImageNV) \
226  MACRO(1, 1, FF_VK_EXT_OPTICAL_FLOW, CmdOpticalFlowExecuteNV) \
227  MACRO(1, 1, FF_VK_EXT_OPTICAL_FLOW, CreateOpticalFlowSessionNV) \
228  MACRO(1, 1, FF_VK_EXT_OPTICAL_FLOW, DestroyOpticalFlowSessionNV) \
229  MACRO(1, 0, FF_VK_EXT_OPTICAL_FLOW, GetPhysicalDeviceOpticalFlowImageFormatsNV)\
230  \
231  /* Shaders */ \
232  MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateShaderModule) \
233  MACRO(1, 1, FF_VK_EXT_NO_FLAG, DestroyShaderModule) \
234  MACRO(1, 1, FF_VK_EXT_SHADER_OBJECT, CmdBindShadersEXT) \
235  MACRO(1, 1, FF_VK_EXT_SHADER_OBJECT, CreateShadersEXT) \
236  MACRO(1, 1, FF_VK_EXT_SHADER_OBJECT, DestroyShaderEXT) \
237  MACRO(1, 1, FF_VK_EXT_SHADER_OBJECT, GetShaderBinaryDataEXT)
238 
239 /* Macro containing every win32 specific function that we utilize in our codebase */
240 #define FN_LIST_WIN32(MACRO) \
241  MACRO(1, 1, FF_VK_EXT_EXTERNAL_WIN32_SEM, GetSemaphoreWin32HandleKHR) \
242  MACRO(1, 1, FF_VK_EXT_EXTERNAL_WIN32_MEMORY, GetMemoryWin32HandleKHR)
243 
244 /* Macro to turn a function name into a definition */
245 #define PFN_DEF(req_inst, req_dev, ext_flag, name) \
246  PFN_vk##name name;
247 
248 /* Structure with the definition of all listed functions */
249 typedef struct FFVulkanFunctions {
251 #ifdef _WIN32
253 #endif
255 
256 #endif /* AVUTIL_VULKAN_FUNCTIONS_H */
FF_VK_EXT_NO_FLAG
@ FF_VK_EXT_NO_FLAG
Definition: vulkan_functions.h:57
FF_VK_EXT_VIDEO_ENCODE_QUEUE
@ FF_VK_EXT_VIDEO_ENCODE_QUEUE
Definition: vulkan_functions.h:53
FF_VK_EXT_VIDEO_DECODE_H264
@ FF_VK_EXT_VIDEO_DECODE_H264
Definition: vulkan_functions.h:44
FF_VK_EXT_VIDEO_DECODE_AV1
@ FF_VK_EXT_VIDEO_DECODE_AV1
Definition: vulkan_functions.h:46
FF_VK_EXT_DESCRIPTOR_BUFFER
@ FF_VK_EXT_DESCRIPTOR_BUFFER
Definition: vulkan_functions.h:40
FF_VK_EXT_VIDEO_DECODE_H265
@ FF_VK_EXT_VIDEO_DECODE_H265
Definition: vulkan_functions.h:45
FF_VK_EXT_VIDEO_ENCODE_H264
@ FF_VK_EXT_VIDEO_ENCODE_H264
Definition: vulkan_functions.h:54
FF_VK_EXT_VIDEO_DECODE_QUEUE
@ FF_VK_EXT_VIDEO_DECODE_QUEUE
Definition: vulkan_functions.h:43
FF_VK_EXT_COOP_MATRIX
@ FF_VK_EXT_COOP_MATRIX
Definition: vulkan_functions.h:48
FN_LIST_WIN32
#define FN_LIST_WIN32(MACRO)
Definition: vulkan_functions.h:240
FF_VK_EXT_VIDEO_QUEUE
@ FF_VK_EXT_VIDEO_QUEUE
Definition: vulkan_functions.h:42
FF_VK_EXT_VIDEO_MAINTENANCE_1
@ FF_VK_EXT_VIDEO_MAINTENANCE_1
Definition: vulkan_functions.h:52
FN_LIST
#define FN_LIST(MACRO)
Definition: vulkan_functions.h:61
FF_VK_EXT_EXTERNAL_HOST_MEMORY
@ FF_VK_EXT_EXTERNAL_HOST_MEMORY
Definition: vulkan_functions.h:34
hwcontext_vulkan.h
FF_VK_EXT_DRM_MODIFIER_FLAGS
@ FF_VK_EXT_DRM_MODIFIER_FLAGS
Definition: vulkan_functions.h:31
FF_VK_EXT_EXTERNAL_DMABUF_MEMORY
@ FF_VK_EXT_EXTERNAL_DMABUF_MEMORY
Definition: vulkan_functions.h:30
FF_VK_EXT_EXTERNAL_FD_MEMORY
@ FF_VK_EXT_EXTERNAL_FD_MEMORY
Definition: vulkan_functions.h:32
FF_VK_EXT_SHADER_OBJECT
@ FF_VK_EXT_SHADER_OBJECT
Definition: vulkan_functions.h:50
FF_VK_EXT_OPTICAL_FLOW
@ FF_VK_EXT_OPTICAL_FLOW
Definition: vulkan_functions.h:49
PFN_DEF
#define PFN_DEF(req_inst, req_dev, ext_flag, name)
Definition: vulkan_functions.h:245
FF_VK_EXT_DEBUG_UTILS
@ FF_VK_EXT_DEBUG_UTILS
Definition: vulkan_functions.h:35
FFVulkanExtensions
FFVulkanExtensions
Definition: vulkan_functions.h:29
FF_VK_EXT_EXTERNAL_FD_SEM
@ FF_VK_EXT_EXTERNAL_FD_SEM
Definition: vulkan_functions.h:33
FF_VK_EXT_VIDEO_ENCODE_H265
@ FF_VK_EXT_VIDEO_ENCODE_H265
Definition: vulkan_functions.h:55
FF_VK_EXT_DEVICE_DRM
@ FF_VK_EXT_DEVICE_DRM
Definition: vulkan_functions.h:41
FF_VK_EXT_ATOMIC_FLOAT
@ FF_VK_EXT_ATOMIC_FLOAT
Definition: vulkan_functions.h:47
hwcontext.h
FFVulkanFunctions
Definition: vulkan_functions.h:249