FFmpeg
hwcontext_vulkan.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_HWCONTEXT_VULKAN_H
20 #define AVUTIL_HWCONTEXT_VULKAN_H
21 
22 #include <vulkan/vulkan.h>
23 
24 /**
25  * @file
26  * API-specific header for AV_HWDEVICE_TYPE_VULKAN.
27  *
28  * For user-allocated pools, AVHWFramesContext.pool must return AVBufferRefs
29  * with the data pointer set to an AVVkFrame.
30  */
31 
32 /**
33  * Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
34  * All of these can be set before init to change what the context uses
35  */
36 typedef struct AVVulkanDeviceContext {
37  /**
38  * Custom memory allocator, else NULL
39  */
40  const VkAllocationCallbacks *alloc;
41  /**
42  * Vulkan instance. Must be at least version 1.1.
43  */
44  VkInstance inst;
45  /**
46  * Physical device
47  */
48  VkPhysicalDevice phys_dev;
49  /**
50  * Active device
51  */
52  VkDevice act_dev;
53  /**
54  * Queue family index for graphics
55  * @note av_hwdevice_create() will set all 3 queue indices if unset
56  * If there is no dedicated queue for compute or transfer operations,
57  * they will be set to the graphics queue index which can handle both.
58  * nb_graphics_queues indicates how many queues were enabled for the
59  * graphics queue (must be at least 1)
60  */
63  /**
64  * Queue family index to use for transfer operations, and the amount of queues
65  * enabled. In case there is no dedicated transfer queue, nb_tx_queues
66  * must be 0 and queue_family_tx_index must be the same as either the graphics
67  * queue or the compute queue, if available.
68  */
71  /**
72  * Queue family index for compute ops, and the amount of queues enabled.
73  * In case there are no dedicated compute queues, nb_comp_queues must be
74  * 0 and its queue family index must be set to the graphics queue.
75  */
78  /**
79  * Enabled instance extensions.
80  * If supplying your own device context, set this to an array of strings, with
81  * each entry containing the specified Vulkan extension string to enable.
82  * Duplicates are possible and accepted.
83  * If no extensions are enabled, set these fields to NULL, and 0 respectively.
84  */
85  const char * const *enabled_inst_extensions;
87  /**
88  * Enabled device extensions. By default, VK_KHR_external_memory_fd,
89  * VK_EXT_external_memory_dma_buf, VK_EXT_image_drm_format_modifier and
90  * VK_KHR_external_semaphore_fd are enabled if found.
91  * If supplying your own device context, these fields takes the same format as
92  * the above fields, with the same conditions that duplicates are possible
93  * and accepted, and that NULL and 0 respectively means no extensions are enabled.
94  */
95  const char * const *enabled_dev_extensions;
97  /**
98  * This structure should be set to the set of features that present and enabled
99  * during device creation. When a device is created by FFmpeg, it will default to
100  * enabling all that are present of the shaderImageGatherExtended,
101  * fragmentStoresAndAtomics, shaderInt64 and vertexPipelineStoresAndAtomics features.
102  */
103  VkPhysicalDeviceFeatures2 device_features;
105 
106 /**
107  * Allocated as AVHWFramesContext.hwctx, used to set pool-specific options
108  */
109 typedef struct AVVulkanFramesContext {
110  /**
111  * Controls the tiling of allocated frames.
112  */
113  VkImageTiling tiling;
114  /**
115  * Defines extra usage of output frames. If left as 0, the following bits
116  * are set: TRANSFER_SRC, TRANSFER_DST. SAMPLED and STORAGE.
117  */
118  VkImageUsageFlagBits usage;
119  /**
120  * Extension data for image creation.
121  */
123  /**
124  * Extension data for memory allocation. Must have as many entries as
125  * the number of planes of the sw_format.
126  * This will be chained to VkExportMemoryAllocateInfo, which is used
127  * to make all pool images exportable to other APIs if the necessary
128  * extensions are present in enabled_dev_extensions.
129  */
130  void *alloc_pnext[AV_NUM_DATA_POINTERS];
132 
133 /*
134  * Frame structure, the VkFormat of the image will always match
135  * the pool's sw_format.
136  * All frames, imported or allocated, will be created with the
137  * VK_IMAGE_CREATE_ALIAS_BIT flag set, so the memory may be aliased if needed.
138  *
139  * If all three queue family indices in the device context are the same,
140  * images will be created with the EXCLUSIVE sharing mode. Otherwise, all images
141  * will be created using the CONCURRENT sharing mode.
142  *
143  * @note the size of this structure is not part of the ABI, to allocate
144  * you must use @av_vk_frame_alloc().
145  */
146 typedef struct AVVkFrame {
147  /**
148  * Vulkan images to which the memory is bound to.
149  */
151 
152  /**
153  * The same tiling must be used for all images in the frame.
154  */
155  VkImageTiling tiling;
156 
157  /**
158  * Memory backing the images. Could be less than the amount of images
159  * if importing from a DRM or VAAPI frame.
160  */
161  VkDeviceMemory mem[AV_NUM_DATA_POINTERS];
163 
164  /**
165  * OR'd flags for all memory allocated
166  */
167  VkMemoryPropertyFlagBits flags;
168 
169  /**
170  * Updated after every barrier
171  */
172  VkAccessFlagBits access[AV_NUM_DATA_POINTERS];
173  VkImageLayout layout[AV_NUM_DATA_POINTERS];
174 
175  /**
176  * Synchronization semaphores. Must not be freed manually. Must be waited on
177  * and signalled at every queue submission.
178  * Could be less than the amount of images: either one per VkDeviceMemory
179  * or one for the entire frame. All others will be set to VK_NULL_HANDLE.
180  */
181  VkSemaphore sem[AV_NUM_DATA_POINTERS];
182 
183  /**
184  * Internal data.
185  */
186  struct AVVkFrameInternal *internal;
187 } AVVkFrame;
188 
189 /**
190  * Allocates a single AVVkFrame and initializes everything as 0.
191  * @note Must be freed via av_free()
192  */
194 
195 /**
196  * Returns the format of each image up to the number of planes for a given sw_format.
197  * Returns NULL on unsupported formats.
198  */
199 const VkFormat *av_vkfmt_from_pixfmt(enum AVPixelFormat p);
200 
201 #endif /* AVUTIL_HWCONTEXT_VULKAN_H */
#define AV_NUM_DATA_POINTERS
Definition: frame.h:301
VkDevice act_dev
Active device.
int queue_family_tx_index
Queue family index to use for transfer operations, and the amount of queues enabled.
const char *const * enabled_dev_extensions
Enabled device extensions.
VkMemoryPropertyFlagBits flags
OR&#39;d flags for all memory allocated.
void * create_pnext
Extension data for image creation.
VkPhysicalDeviceFeatures2 device_features
This structure should be set to the set of features that present and enabled during device creation...
#define img
int queue_family_index
Queue family index for graphics.
int queue_family_comp_index
Queue family index for compute ops, and the amount of queues enabled.
const VkFormat * av_vkfmt_from_pixfmt(enum AVPixelFormat p)
Returns the format of each image up to the number of planes for a given sw_format.
const char *const * enabled_inst_extensions
Enabled instance extensions.
ptrdiff_t size
Definition: opengl_enc.c:100
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
VkInstance inst
Vulkan instance.
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
VkImageUsageFlagBits usage
Defines extra usage of output frames.
VkImageTiling tiling
The same tiling must be used for all images in the frame.
VkPhysicalDevice phys_dev
Physical device.
VkImageTiling tiling
Controls the tiling of allocated frames.
AVVkFrame * av_vk_frame_alloc(void)
Allocates a single AVVkFrame and initializes everything as 0.
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
const VkAllocationCallbacks * alloc
Custom memory allocator, else NULL.