FFmpeg
Loading...
Searching...
No Matches
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_VULKAN_H
20#define AVUTIL_VULKAN_H
21
22#define VK_NO_PROTOTYPES
23
24#include <stdatomic.h>
25
26#include "refstruct.h"
27
28#include "thread.h"
29#include "pixdesc.h"
30#include "hwcontext.h"
31#include "vulkan_functions.h"
32#include "hwcontext_vulkan.h"
33#include "avassert.h"
34#include "intreadwrite.h"
35
36/* Helper, pretty much every Vulkan return value needs to be checked */
37#define RET(x) \
38 do { \
39 if ((err = (x)) < 0) \
40 goto fail; \
41 } while (0)
42
43/* Convenience macros for specialization lists */
44#define SPEC_LIST_MAX 256
45#define SPEC_LIST_CREATE(name, max_length, max_size) \
46 av_assert1((max_length) < (SPEC_LIST_MAX - 3)); \
47 uint8_t name##_data[(max_size) + 3*sizeof(uint32_t)]; \
48 VkSpecializationMapEntry name##_entries[(max_length) + 3]; \
49 VkSpecializationInfo name##_info = { \
50 .pMapEntries = name##_entries, \
51 .pData = name##_data, \
52 }; \
53 VkSpecializationInfo *name = &name##_info;
54
55#define SPEC_LIST_ADD(name, idx, val_bits, val) \
56do { \
57 unsigned int name##_cnt = name->mapEntryCount; \
58 size_t name##_off = name->dataSize; \
59 uint8_t *name##_dp = (uint8_t *)name->pData; \
60 void *name##_ep = (void *)&name->pMapEntries[name##_cnt]; \
61 AV_WN(val_bits, name##_dp + name##_off, (val)); \
62 VkSpecializationMapEntry name##_new_entry = { \
63 .constantID = (idx), \
64 .offset = name##_off, \
65 .size = val_bits >> 3, \
66 }; \
67 memcpy(name##_ep, &name##_new_entry, \
68 sizeof(VkSpecializationMapEntry)); \
69 name->dataSize = name##_off + (val_bits >> 3); \
70 name->mapEntryCount = name##_cnt + 1; \
71} while (0)
72
73#define DUP_SAMPLER(x) { x, x, x, x }
74
75#define FF_VK_MAX_DESCRIPTOR_SETS 4
76#define FF_VK_MAX_DESCRIPTOR_BINDINGS 16
77#define FF_VK_MAX_DESCRIPTOR_TYPES 16
78#define FF_VK_MAX_PUSH_CONSTS 4
79#define FF_VK_MAX_SHADERS 16
80
82 const char *name;
83 VkDescriptorType type;
84 const char *mem_layout; /* Storage images (rgba8, etc.) and buffers (std430, etc.) */
85 const char *mem_quali; /* readonly, writeonly, etc. */
86 const char *buf_content; /* For buffers */
87 uint32_t dimensions; /* Needed for e.g. sampler%iD */
88 uint32_t elems; /* 0 - scalar, 1 or more - vector */
89 VkShaderStageFlags stages;
90 uint32_t buf_elems; /* Appends [buf_elems] to the contents. Avoids manually printing to a string. */
91 VkSampler samplers[4]; /* Sampler to use for all elems */
93
94typedef struct FFVkBuffer {
95 VkBuffer buf;
96 VkDeviceMemory mem;
97 VkMemoryPropertyFlagBits flags;
98 size_t size;
99 VkDeviceAddress address;
100
101 /* Only valid when allocated via ff_vk_get_pooled_buffer with HOST_VISIBLE or
102 * via ff_vk_host_map_buffer */
103 uint8_t *mapped_mem;
104
105 /* Set by ff_vk_host_map_buffer. This is the offset at which the buffer data
106 * actually begins at.
107 * The address and mapped_mem fields will be offset by this amount. */
109
110 /* If host mapping, reference to the backing host memory buffer */
112} FFVkBuffer;
113
114/* Fixed dependency limits per exec context (with room to spare) */
115#define FF_VK_EXEC_MAX_FRAME_DEPS 64
116#define FF_VK_EXEC_MAX_BUF_DEPS 256
117#define FF_VK_EXEC_MAX_SW_FRAME_DEPS 16
118#define FF_VK_EXEC_MAX_SEM_OPS (FF_VK_EXEC_MAX_FRAME_DEPS*AV_NUM_DATA_POINTERS)
119
120/* Default number of in-flight execution contexts per pool */
121#define FF_VK_DEFAULT_EXEC_CONTEXTS 4
122
123typedef struct FFVkExecObjDep {
124 uint64_t obj;
125 VkObjectType type;
127
128typedef struct FFVkExecContext {
129 uint32_t idx;
130 const struct FFVkExecPool *parent;
131
132 /* Set on submission; pool-rolling users check and clear it to tell
133 * contexts with uncollected results apart from fresh ones */
135
136 /* Queue for the execution context */
137 VkQueue queue;
138 int qf;
139 int qi;
140
141 /* Command buffer for the context */
142 VkCommandBuffer buf;
143
144 /* Busy (claimed or executing) while the counter is below sem_value;
145 * signalled by the submission, or by ff_vk_exec_discard() */
146 VkSemaphore sem;
147 uint64_t sem_value;
148
149 /* Briefly guards the dependency lists; the busy state is carried by the
150 * semaphore above */
152
153 /* Opaque data, untouched, free to use by users */
154 void *opaque;
155
158
159 /* Buffer dependencies */
162
163 /* AVRefStruct object dependencies */
166
167 /* Raw Vulkan object dependencies, destroyed on release */
170
171 /* Frame dependencies */
174
175 /* Software frame dependencies */
178
179 VkSemaphoreSubmitInfo sem_wait[FF_VK_EXEC_MAX_SEM_OPS];
181
182 VkSemaphoreSubmitInfo sem_sig[FF_VK_EXEC_MAX_SEM_OPS];
184
187
194
195typedef struct FFVulkanDescriptorSet {
196 /* Descriptor buffer */
197 VkDeviceSize layout_size;
198 VkDeviceSize aligned_size; /* descriptorBufferOffsetAlignment */
199 VkBufferUsageFlags usage;
200
201 VkDescriptorSetLayoutBinding binding[FF_VK_MAX_DESCRIPTOR_BINDINGS];
203
205
206 /* Descriptor set is shared between all submissions */
209
210typedef struct FFVulkanShader {
211 /* Name for id/debugging purposes */
212 const char *name;
213
214 /* Whether shader is precompiled or not */
216 VkSpecializationInfo *specialization_info;
217
218 /* Compute shader local group sizes */
219 uint32_t lg_size[3];
220
221 /* Shader bind point/type */
222 VkPipelineStageFlags stage;
223 VkPipelineBindPoint bind_point;
224
225 /* Creation info */
226 VkPipelineShaderStageRequiredSubgroupSizeCreateInfo subgroup_info;
227
228 /* Base shader object */
229 VkShaderEXT object;
230 VkPipeline pipeline;
231
232 /* Pipeline layout */
233 VkPipelineLayout pipeline_layout;
234
235 /* Push consts */
236 VkPushConstantRange push_consts[FF_VK_MAX_PUSH_CONSTS];
238
239 /* Descriptor sets */
242
243 /* Descriptors */
245
246 /* Descriptor pool */
251
253 /* Descriptor buffer */
255 uint8_t *desc_mem;
257
258typedef struct FFVulkanShaderData {
259 /* Shader to which this data belongs to */
262
263 /* Descriptor buffer */
265 VkDescriptorBufferBindingInfoEXT desc_bind[FF_VK_MAX_DESCRIPTOR_SETS];
266
267 /* Descriptor pools */
268 VkDescriptorSet *desc_sets;
269 VkDescriptorPool desc_pool;
271
293
294typedef struct FFVulkanContext {
295 const AVClass *class;
297
300 VkPhysicalDeviceProperties2 props;
301 VkPhysicalDeviceVulkan11Properties props_11;
302 VkPhysicalDeviceDriverProperties driver_props;
303 VkPhysicalDeviceMemoryProperties mprops;
304 VkPhysicalDeviceExternalMemoryHostPropertiesEXT hprops;
305 VkPhysicalDeviceDescriptorBufferPropertiesEXT desc_buf_props;
306 VkPhysicalDeviceSubgroupSizeControlProperties subgroup_props;
307 VkPhysicalDeviceCooperativeMatrixPropertiesKHR coop_matrix_props;
308 VkPhysicalDevicePushDescriptorPropertiesKHR push_desc_props;
309 VkPhysicalDeviceOpticalFlowPropertiesNV optical_flow_props;
310#ifdef VK_EXT_shader_long_vector
311 VkPhysicalDeviceShaderLongVectorPropertiesEXT long_vector_props;
312#endif
313 VkQueueFamilyQueryResultStatusPropertiesKHR *query_props;
314 VkQueueFamilyVideoPropertiesKHR *video_props;
315#ifdef VK_KHR_maintenance9
316 VkQueueFamilyOwnershipTransferPropertiesKHR *ownership_props;
317#endif
318 VkQueueFamilyProperties2 *qf_props;
320 VkPhysicalDeviceHostImageCopyPropertiesEXT host_image_props;
322
323 VkCooperativeMatrixPropertiesKHR *coop_mat_props;
325
326 VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomic_float_feats;
328
329 VkPhysicalDeviceVulkan12Features feats_12;
330#ifdef VK_KHR_unified_image_layouts
331 VkPhysicalDeviceUnifiedImageLayoutsFeaturesKHR unified_layout_feats;
332#endif
333 VkPhysicalDeviceFeatures2 feats;
334
335 VkMemoryPropertyFlagBits host_cached_flag;
336
340
345
346 uint32_t qfs[64];
348
349 /* Properties */
355
356static inline int ff_vk_count_images(AVVkFrame *f)
357{
358 int cnt = 0;
359 while (cnt < FF_ARRAY_ELEMS(f->img) && f->img[cnt])
360 cnt++;
361
362 return cnt;
363}
364
365static inline const void *ff_vk_find_struct(const void *chain, VkStructureType stype)
366{
367 const VkBaseInStructure *in = chain;
368 while (in) {
369 if (in->sType == stype)
370 return in;
371
372 in = in->pNext;
373 }
374
375 return NULL;
376}
377
378static inline void ff_vk_link_struct(void *chain, const void *in)
379{
380 VkBaseOutStructure *out = chain;
381 while (out->pNext)
382 out = out->pNext;
383
384 out->pNext = (void *)in;
385}
386
387#define FF_VK_STRUCT_EXT(CTX, BASE, STRUCT_P, EXT_FLAG, TYPE) \
388 do { \
389 if ((EXT_FLAG == FF_VK_EXT_NO_FLAG) || \
390 ((CTX)->extensions & EXT_FLAG)) { \
391 (STRUCT_P)->sType = TYPE; \
392 ff_vk_link_struct(BASE, STRUCT_P); \
393 } \
394 } while (0)
395
396/* Identity mapping - r = r, b = b, g = g, a = a */
397extern const VkComponentMapping ff_comp_identity_map;
398
399/**
400 * Initializes the AVClass, in case this context is not used
401 * as the main user's context.
402 * May use either a frames context reference, or a device context reference.
403 */
404int ff_vk_init(FFVulkanContext *s, void *log_parent,
405 AVBufferRef *device_ref, AVBufferRef *frames_ref);
406
407/**
408 * Converts Vulkan return values to strings
409 */
410const char *ff_vk_ret2str(VkResult res);
411
412/**
413 * Map between usage and features.
414 */
415VkImageUsageFlags ff_vk_map_feats_to_usage(VkFormatFeatureFlagBits2 feats);
416VkFormatFeatureFlagBits2 ff_vk_map_usage_to_feats(VkImageUsageFlags usage);
417
418/**
419 * Returns 1 if pixfmt is a usable RGB format.
420 */
422
423/**
424 * Since storage images may not be swizzled, we have to do this in the
425 * shader itself. This fills in a lookup table to do it.
426 */
427void ff_vk_set_perm(enum AVPixelFormat pix_fmt, int lut[4], int inv);
428
429/**
430 * Get the aspect flag for a plane from an image.
431 */
432VkImageAspectFlags ff_vk_aspect_flag(AVFrame *f, int p);
433
434/**
435 * Returns the format to use for images in shaders.
436 */
438 /* Native format with no conversion. May require casting. */
440 /* Float conversion of the native format. */
442 /* Signed integer version of the native format */
444 /* Unsigned integer version of the native format */
446};
448 enum FFVkShaderRepFormat rep_fmt);
449
450/**
451 * Loads props/mprops/driver_props
452 */
454
455/**
456 * Chooses an appropriate QF.
457 */
459 VkQueueFlagBits dev_family,
460 VkVideoCodecOperationFlagBitsKHR vid_ops);
461
462/**
463 * Allocates/frees an execution pool.
464 * If used in a multi-threaded context, there must be at least as many contexts
465 * as there are threads.
466 * ff_vk_exec_pool_init_desc() MUST be called if ff_vk_exec_descriptor_set_add()
467 * has been called.
468 */
470 FFVkExecPool *pool, int nb_contexts,
471 int nb_queries, VkQueryType query_type, int query_64bit,
472 const void *query_create_pnext);
474
475/**
476 * Retrieve an execution pool. Threadsafe.
477 */
479
480/**
481 * Performs nb_queries queries and returns their results and statuses.
482 * 64_BIT and WITH_STATUS flags are ignored as 64_BIT must be specified via
483 * query_64bit in ff_vk_exec_pool_init() and WITH_STATUS is always enabled.
484 */
486 void **data, VkQueryResultFlagBits flags);
487
488/**
489 * Start/submit/wait an execution.
490 * ff_vk_exec_start() always waits on a submission, so using ff_vk_exec_wait()
491 * is not necessary (unless using it is just better).
492 */
496
497/**
498 * Execution dependency management.
499 * Can attach buffers to executions that will only be unref'd once the
500 * buffer has finished executing.
501 * Adding a frame dep will *lock the frame*, until either the dependencies
502 * are discarded, the execution is submitted, or a failure happens.
503 * update_frame will update the frame's properties before it is unlocked,
504 * only if submission was successful.
505 * ff_vk_exec_discard() abandons a started, unsubmitted recording: call it
506 * exactly once, from the claiming thread. ff_vk_exec_submit() cleans up
507 * after its own failures.
508 */
509
510/* Takes a new reference to an AVRefStruct-managed object, held until the
511 * execution's dependencies are released. */
513 void *obj);
514
515/* Moves the caller's reference into the execution's dependencies, given a
516 * pointer to it; a duplicate of an already-tracked object is released. */
518 void *obj);
519
520/* Takes ownership of a raw Vulkan object, destroyed when the execution's
521 * dependencies are released. */
523 VkObjectType type, uint64_t obj);
524
526 VkSemaphore sem, uint64_t val,
527 VkPipelineStageFlagBits2 stage);
529 VkSemaphore *sem, int nb,
530 VkPipelineStageFlagBits2 stage,
531 int wait); /* Ownership transferred if !wait */
533 VkPipelineStageFlagBits2 wait_stage,
534 VkPipelineStageFlagBits2 signal_stage);
536 AVFrame *f);
538 VkImageMemoryBarrier2 *bar, uint32_t *nb_img_bar);
540 VkSemaphore *dst, uint64_t *dst_val,
541 AVFrame *f);
543
544/**
545 * Create a single imageview for a given plane.
546 */
548 VkImageView *img_view, VkImageAspectFlags *aspect,
549 AVFrame *f, int plane, enum FFVkShaderRepFormat rep_fmt);
550
551/* Refcounted set of image views; stashes destruction handles to be context-free */
552typedef struct FFVkImageViews {
554
555 VkDevice dev;
556 const VkAllocationCallbacks *alloc;
557 PFN_vkDestroyImageView destroy_image_view;
558
561
562/**
563 * Allocate a reference-counted set of image views, zero-initialized for the
564 * caller to create.
565 */
567
568/**
569 * Create an imageview and add it as a dependency to an execution.
570 */
572 VkImageView views[AV_NUM_DATA_POINTERS],
573 AVFrame *f, enum FFVkShaderRepFormat rep_fmt);
574
575#define ff_vk_buf_barrier(dst, vkb, s_stage, s_access, s_access2, \
576 d_stage, d_access, d_access2, offs, bsz) \
577 do { \
578 dst = (VkBufferMemoryBarrier2) { \
579 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2, \
580 .srcStageMask = VK_PIPELINE_STAGE_2_ ##s_stage, \
581 .srcAccessMask = VK_ACCESS_2_ ##s_access | \
582 VK_ACCESS_2_ ##s_access2, \
583 .dstStageMask = VK_PIPELINE_STAGE_2_ ##d_stage, \
584 .dstAccessMask = VK_ACCESS_2_ ##d_access | \
585 VK_ACCESS_2_ ##d_access2, \
586 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, \
587 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, \
588 .buffer = vkb->buf, \
589 .offset = offs, \
590 .size = bsz \
591 }; \
592 } while(0)
593
595 AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar,
596 VkPipelineStageFlags2 src_stage,
597 VkPipelineStageFlags2 dst_stage,
598 VkAccessFlagBits2 new_access,
599 VkImageLayout new_layout,
600 uint32_t new_qf);
601
602/**
603 * Memory/buffer/image allocation helpers.
604 */
605/**
606 * Create a standalone internal-use image: exclusive sharing, dedicated
607 * memory. Not for interop or mapping.
608 */
609int ff_vk_image_create(FFVulkanContext *s, VkImage *img, VkDeviceMemory *mem,
610 int width, int height, VkFormat format, int nb_layers,
611 VkImageTiling tiling, VkImageUsageFlags usage,
612 VkImageCreateFlags flags, void *create_pnext);
613
614/**
615 * Free an image created by ff_vk_image_create(); all GPU use must have
616 * completed.
617 */
618void ff_vk_image_free(FFVulkanContext *s, VkImage *img, VkDeviceMemory *mem);
619
620int ff_vk_alloc_mem(FFVulkanContext *s, VkMemoryRequirements *req,
621 VkMemoryPropertyFlagBits req_flags, void *alloc_extension,
622 VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem);
624 void *pNext, void *alloc_pNext,
625 VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags);
626
627/**
628 * Flush or invalidate a single buffer, with a given size and offset.
629 */
631 VkDeviceSize offset, VkDeviceSize mem_size,
632 int flush);
633
634/**
635 * Buffer management code.
636 */
637int ff_vk_map_buffers(FFVulkanContext *s, FFVkBuffer **buf, uint8_t *mem[],
638 int nb_buffers, int invalidate);
639int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer **buf, int nb_buffers,
640 int flush);
641
642static inline int ff_vk_map_buffer(FFVulkanContext *s, FFVkBuffer *buf, uint8_t **mem,
643 int invalidate)
644{
645 return ff_vk_map_buffers(s, (FFVkBuffer *[]){ buf }, mem,
646 1, invalidate);
647}
648
650{
651 return ff_vk_unmap_buffers(s, (FFVkBuffer *[]){ buf }, 1, flush);
652}
653
655
656/** Initialize a pool and create AVBufferRefs containing FFVkBuffer.
657 * Threadsafe to use. Buffers are automatically mapped on creation if
658 * VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT is set in mem_props. Users should
659 * synchronize access themselvesd. Mainly meant for device-local buffers. */
661 FFVkBuffer **buf, VkBufferUsageFlags usage,
662 void *create_pNext, size_t size,
663 VkMemoryPropertyFlagBits mem_props);
664
665/** Maps a system RAM buffer into a Vulkan buffer.
666 * References the source buffer. Imports size bytes starting at src_data,
667 * rounded up to the host-pointer import alignment and clamped to the end
668 * of src_buf. */
670 uint8_t *src_data, VkDeviceSize size,
671 const AVBufferRef *src_buf,
672 VkBufferUsageFlags usage);
673
674/**
675 * Create a sampler.
676 */
677int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler,
678 int unnorm_coords, VkFilter filt);
679
680/**
681 * Initialize a shader object.
682 * If spec is non-null, it must have been created with SPEC_LIST_CREATE().
683 * The IDs for the workgroup size must be 253, 254, 255.
684 */
686 VkPipelineStageFlags stage, VkSpecializationInfo *spec,
687 uint32_t wg_size[3], uint32_t required_subgroup_size);
688
689/**
690 * Link a shader into an executable.
691 */
693 const char *spirv, size_t spirv_len,
694 const char *entrypoint);
695
696/**
697 * Add/update push constants for execution.
698 */
700 VkShaderStageFlagBits stage);
701
702/**
703 * Add descriptor to a shader. Must be called before shader init.
704 */
706 const FFVulkanDescriptorSetBinding *desc, int nb,
707 int singular);
708
709/**
710 * Register a shader with an exec pool.
711 * Pool may be NULL if all descriptor sets are read-only.
712 */
714 FFVulkanShader *shd);
715
716/**
717 * Bind a shader.
718 */
720 const FFVulkanShader *shd);
721
722/**
723 * Update push constant in a shader.
724 * Must be called before binding the shader.
725 */
727 FFVulkanShader *shd,
728 VkShaderStageFlagBits stage,
729 int offset, size_t size, void *src);
730
731/**
732 * Update a descriptor in a buffer with a buffer.
733 * Must be called before binding the shader.
734 */
736 FFVulkanShader *shd,
737 int set, int bind, int elem,
738 FFVkBuffer *buf, VkDeviceSize offset, VkDeviceSize len,
739 VkFormat fmt);
740
741/**
742 * Sets an image descriptor for specified shader and binding.
743 */
745 FFVulkanShader *shd, int set, int bind, int offs,
746 VkImageView view, VkImageLayout layout,
747 VkSampler sampler);
748
749/**
750 * Update a descriptor in a buffer with an image array..
751 * Must be called before binding the shader.
752 */
754 FFVulkanShader *shd, AVFrame *f,
755 VkImageView *views, int set, int binding,
756 VkImageLayout layout, VkSampler sampler);
757
758/**
759 * Free a shader.
760 */
762
763/**
764 * Frees main context.
765 */
767
768#endif /* AVUTIL_VULKAN_H */
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static double val(void *priv, double ch)
Definition aeval.c:77
static const char *const format[]
Definition af_aiir.c:444
static const int8_t filt[NUMTAPS *2]
Definition af_earwax.c:40
simple assert() macros that are a bit more flexible than ISO C assert().
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define f(width, name)
Definition cbs_vp8.c:236
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
static enum AVPixelFormat pix_fmt
void(* flush)(AVBSFContext *ctx)
Definition dts2pts.c:610
intptr_t atomic_uint_least64_t
Definition stdatomic.h:69
const char * usage
#define AV_NUM_DATA_POINTERS
Definition frame.h:473
cl_device_type type
enum VkFormat VkFormat
API-specific header for AV_HWDEVICE_TYPE_VULKAN.
unsigned offset
Definition libaomenc.c:763
const VkComponentMapping ff_comp_identity_map
Definition vulkan.c:34
const char * desc
Definition libsvtav1.c:83
uint64_t layout
const char data[16]
Definition mxf.c:149
_fmutex pthread_mutex_t
Definition os2threads.h:53
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Definition buffer.h:82
Describe the class of an AVClass context structure.
Definition log.h:76
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition refstruct.c:183
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
VkBuffer buf
Definition vulkan.h:95
VkDeviceAddress address
Definition vulkan.h:99
size_t size
Definition vulkan.h:98
VkMemoryPropertyFlagBits flags
Definition vulkan.h:97
AVBufferRef * host_ref
Definition vulkan.h:111
size_t virtual_offset
Definition vulkan.h:108
VkDeviceMemory mem
Definition vulkan.h:96
uint8_t * mapped_mem
Definition vulkan.h:103
VkAccessFlagBits access_dst[FF_VK_EXEC_MAX_FRAME_DEPS]
Definition vulkan.h:189
AVBufferRef * buf_deps[FF_VK_EXEC_MAX_BUF_DEPS]
Definition vulkan.h:160
uint32_t idx
Definition vulkan.h:129
uint8_t frame_update[FF_VK_EXEC_MAX_FRAME_DEPS]
Definition vulkan.h:192
void * opaque
Definition vulkan.h:154
void * query_data
Definition vulkan.h:156
uint64_t sem_value
Definition vulkan.h:147
VkSemaphoreSubmitInfo sem_wait[FF_VK_EXEC_MAX_SEM_OPS]
Definition vulkan.h:179
FFVkExecObjDep obj_deps[FF_VK_EXEC_MAX_BUF_DEPS]
Definition vulkan.h:168
VkQueue queue
Definition vulkan.h:137
AVFrame * sw_frame_deps[FF_VK_EXEC_MAX_SW_FRAME_DEPS]
Definition vulkan.h:176
pthread_mutex_t lock
Definition vulkan.h:151
uint32_t queue_family_dst[FF_VK_EXEC_MAX_FRAME_DEPS]
Definition vulkan.h:191
uint64_t * sem_sig_val_dst[FF_VK_EXEC_MAX_SEM_OPS]
Definition vulkan.h:185
VkSemaphoreSubmitInfo sem_sig[FF_VK_EXEC_MAX_SEM_OPS]
Definition vulkan.h:182
const struct FFVkExecPool * parent
Definition vulkan.h:130
int had_submission
Definition vulkan.h:134
int sem_sig_val_dst_cnt
Definition vulkan.h:186
int nb_sw_frame_deps
Definition vulkan.h:177
VkSemaphore sem
Definition vulkan.h:146
uint8_t frame_locked[FF_VK_EXEC_MAX_FRAME_DEPS]
Definition vulkan.h:188
void * refstruct_deps[FF_VK_EXEC_MAX_BUF_DEPS]
Definition vulkan.h:164
VkImageLayout layout_dst[FF_VK_EXEC_MAX_FRAME_DEPS]
Definition vulkan.h:190
AVFrame * frame_deps[FF_VK_EXEC_MAX_FRAME_DEPS]
Definition vulkan.h:172
int nb_frame_deps
Definition vulkan.h:173
int nb_refstruct_deps
Definition vulkan.h:165
VkCommandBuffer buf
Definition vulkan.h:142
VkObjectType type
Definition vulkan.h:125
uint64_t obj
Definition vulkan.h:124
FFVulkanShaderData reg_shd[FF_VK_MAX_SHADERS]
Definition vulkan.h:290
int query_results
Definition vulkan.h:282
atomic_uint_least64_t idx
Definition vulkan.h:274
VkQueryPool query_pool
Definition vulkan.h:280
FFVkExecContext * contexts
Definition vulkan.h:273
VkCommandBuffer * cmd_bufs
Definition vulkan.h:277
int pool_size
Definition vulkan.h:278
int nb_queries
Definition vulkan.h:286
VkCommandPool * cmd_buf_pools
Definition vulkan.h:276
int nb_reg_shd
Definition vulkan.h:291
void * query_data
Definition vulkan.h:281
size_t qd_size
Definition vulkan.h:287
int query_status_stride
Definition vulkan.h:285
int query_statuses
Definition vulkan.h:283
int query_64bit
Definition vulkan.h:284
PFN_vkDestroyImageView destroy_image_view
Definition vulkan.h:557
const VkAllocationCallbacks * alloc
Definition vulkan.h:556
VkImageView views[AV_NUM_DATA_POINTERS]
Definition vulkan.h:559
VkDevice dev
Definition vulkan.h:555
uint32_t qfs[64]
Definition vulkan.h:346
AVHWFramesContext * frames
Definition vulkan.h:343
VkPhysicalDeviceMemoryProperties mprops
Definition vulkan.h:303
VkPhysicalDeviceVulkan12Features feats_12
Definition vulkan.h:329
FFVulkanExtensions extensions
Definition vulkan.h:299
int output_height
Definition vulkan.h:351
VkPhysicalDeviceOpticalFlowPropertiesNV optical_flow_props
Definition vulkan.h:309
VkImageLayout * host_image_copy_layouts
Definition vulkan.h:321
VkQueueFamilyVideoPropertiesKHR * video_props
Definition vulkan.h:314
AVVulkanDeviceContext * hwctx
Definition vulkan.h:339
VkPhysicalDeviceHostImageCopyPropertiesEXT host_image_props
Definition vulkan.h:320
VkPhysicalDeviceCooperativeMatrixPropertiesKHR coop_matrix_props
Definition vulkan.h:307
VkMemoryPropertyFlagBits host_cached_flag
Definition vulkan.h:335
void * log_parent
Definition vulkan.h:296
AVBufferRef * input_frames_ref
Definition vulkan.h:341
VkCooperativeMatrixPropertiesKHR * coop_mat_props
Definition vulkan.h:323
VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomic_float_feats
Definition vulkan.h:326
enum AVPixelFormat input_format
Definition vulkan.h:353
AVRefStructPool * imageviews_pool
Definition vulkan.h:327
VkPhysicalDeviceExternalMemoryHostPropertiesEXT hprops
Definition vulkan.h:304
VkPhysicalDevicePushDescriptorPropertiesKHR push_desc_props
Definition vulkan.h:308
VkPhysicalDeviceSubgroupSizeControlProperties subgroup_props
Definition vulkan.h:306
uint32_t coop_mat_props_nb
Definition vulkan.h:324
VkPhysicalDeviceVulkan11Properties props_11
Definition vulkan.h:301
FFVulkanFunctions vkfn
Definition vulkan.h:298
VkPhysicalDeviceDriverProperties driver_props
Definition vulkan.h:302
AVBufferRef * frames_ref
Definition vulkan.h:342
AVHWDeviceContext * device
Definition vulkan.h:338
VkPhysicalDeviceProperties2 props
Definition vulkan.h:300
VkQueueFamilyProperties2 * qf_props
Definition vulkan.h:318
VkPhysicalDeviceFeatures2 feats
Definition vulkan.h:333
enum AVPixelFormat output_format
Definition vulkan.h:352
VkPhysicalDeviceDescriptorBufferPropertiesEXT desc_buf_props
Definition vulkan.h:305
AVVulkanFramesContext * hwfc
Definition vulkan.h:344
VkQueueFamilyQueryResultStatusPropertiesKHR * query_props
Definition vulkan.h:313
AVBufferRef * device_ref
Definition vulkan.h:337
const char * buf_content
Definition vulkan.h:86
VkDescriptorType type
Definition vulkan.h:83
const char * mem_layout
Definition vulkan.h:84
VkShaderStageFlags stages
Definition vulkan.h:89
VkDeviceSize aligned_size
Definition vulkan.h:198
VkDeviceSize binding_offset[FF_VK_MAX_DESCRIPTOR_BINDINGS]
Definition vulkan.h:202
VkDescriptorSetLayoutBinding binding[FF_VK_MAX_DESCRIPTOR_BINDINGS]
Definition vulkan.h:201
VkBufferUsageFlags usage
Definition vulkan.h:199
VkDeviceSize layout_size
Definition vulkan.h:197
VkDescriptorSet * desc_sets
Definition vulkan.h:268
FFVulkanDescriptorSetData desc_set_buf[FF_VK_MAX_DESCRIPTOR_SETS]
Definition vulkan.h:264
VkDescriptorBufferBindingInfoEXT desc_bind[FF_VK_MAX_DESCRIPTOR_SETS]
Definition vulkan.h:265
FFVulkanShader * shd
Definition vulkan.h:260
VkDescriptorPool desc_pool
Definition vulkan.h:269
VkPipelineLayout pipeline_layout
Definition vulkan.h:233
FFVulkanDescriptorSet desc_set[FF_VK_MAX_DESCRIPTOR_SETS]
Definition vulkan.h:240
VkPipeline pipeline
Definition vulkan.h:230
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo subgroup_info
Definition vulkan.h:226
VkPipelineStageFlags stage
Definition vulkan.h:222
int push_consts_num
Definition vulkan.h:237
VkSpecializationInfo * specialization_info
Definition vulkan.h:216
int nb_descriptor_sets
Definition vulkan.h:241
int precompiled
Definition vulkan.h:215
VkPushConstantRange push_consts[FF_VK_MAX_PUSH_CONSTS]
Definition vulkan.h:236
uint32_t lg_size[3]
Definition vulkan.h:219
const char * name
Definition vulkan.h:212
VkDescriptorSetLayout desc_layout[FF_VK_MAX_DESCRIPTOR_SETS]
Definition vulkan.h:244
VkPipelineBindPoint bind_point
Definition vulkan.h:223
VkDescriptorPoolSize desc_pool_size[FF_VK_MAX_DESCRIPTOR_TYPES]
Definition vulkan.h:248
int nb_desc_pool_size
Definition vulkan.h:249
VkShaderEXT object
Definition vulkan.h:229
#define src
Definition vp8dsp.c:248
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
Definition swresample.c:55
int size
#define img
int len
void ff_vk_set_perm(enum AVPixelFormat pix_fmt, int lut[4], int inv)
Since storage images may not be swizzled, we have to do this in the shader itself.
Definition vulkan.c:1696
void ff_vk_shader_update_img_array(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, AVFrame *f, VkImageView *views, int set, int binding, VkImageLayout layout, VkSampler sampler)
Update a descriptor in a buffer with an image array.
Definition vulkan.c:2712
int ff_vk_shader_load(FFVulkanShader *shd, VkPipelineStageFlags stage, VkSpecializationInfo *spec, uint32_t wg_size[3], uint32_t required_subgroup_size)
Initialize a shader object.
Definition vulkan.c:2240
void ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, const FFVulkanDescriptorSetBinding *desc, int nb, int singular)
Add descriptor to a shader.
Definition vulkan.c:2543
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
Definition vulkan.c:331
FFVkShaderRepFormat
Returns the format to use for images in shaders.
Definition vulkan.h:437
@ FF_VK_REP_UINT
Definition vulkan.h:445
@ FF_VK_REP_INT
Definition vulkan.h:443
@ FF_VK_REP_NATIVE
Definition vulkan.h:439
@ FF_VK_REP_FLOAT
Definition vulkan.h:441
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt, enum FFVkShaderRepFormat rep_fmt)
Definition vulkan.c:1750
int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer **buf, int nb_buffers, int flush)
Definition vulkan.c:1358
VkImageAspectFlags ff_vk_aspect_flag(AVFrame *f, int p)
Get the aspect flag for a plane from an image.
Definition vulkan.c:1656
int ff_vk_create_buf(FFVulkanContext *s, FFVkBuffer *buf, size_t size, void *pNext, void *alloc_pNext, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags)
Definition vulkan.c:1186
int ff_vk_exec_pool_init(FFVulkanContext *s, AVVulkanDeviceQueueFamily *qf, FFVkExecPool *pool, int nb_contexts, int nb_queries, VkQueryType query_type, int query_64bit, const void *query_create_pnext)
Allocates/frees an execution pool.
Definition vulkan.c:395
void ff_vk_image_free(FFVulkanContext *s, VkImage *img, VkDeviceMemory *mem)
Free an image created by ff_vk_image_create(); all GPU use must have completed.
Definition vulkan.c:1172
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
Definition vulkan.c:645
int ff_vk_alloc_mem(FFVulkanContext *s, VkMemoryRequirements *req, VkMemoryPropertyFlagBits req_flags, void *alloc_extension, VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem)
Definition vulkan.c:1044
int ff_vk_image_create(FFVulkanContext *s, VkImage *img, VkDeviceMemory *mem, int width, int height, VkFormat format, int nb_layers, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, void *create_pnext)
Memory/buffer/image allocation helpers.
Definition vulkan.c:1095
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
Definition vulkan.c:1613
int ff_vk_shader_update_img(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, int set, int bind, int offs, VkImageView view, VkImageLayout layout, VkSampler sampler)
Sets an image descriptor for specified shader and binding.
Definition vulkan.c:2687
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition vulkan.c:2808
int ff_vk_load_props(FFVulkanContext *s)
Loads props/mprops/driver_props.
Definition vulkan.c:151
int ff_vk_map_buffers(FFVulkanContext *s, FFVkBuffer **buf, uint8_t *mem[], int nb_buffers, int invalidate)
Buffer management code.
Definition vulkan.c:1278
const char * ff_vk_ret2str(VkResult res)
Converts Vulkan return values to strings.
Definition vulkan.c:42
#define FF_VK_EXEC_MAX_SEM_OPS
Definition vulkan.h:118
int ff_vk_init(FFVulkanContext *s, void *log_parent, AVBufferRef *device_ref, AVBufferRef *frames_ref)
Initializes the AVClass, in case this context is not used as the main user's context.
Definition vulkan.c:2824
static const void * ff_vk_find_struct(const void *chain, VkStructureType stype)
Definition vulkan.h:365
int ff_vk_exec_add_dep_sw_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f)
Definition vulkan.c:811
void ff_vk_exec_add_dep_obj(FFVulkanContext *s, FFVkExecContext *e, VkObjectType type, uint64_t obj)
Definition vulkan.c:804
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
Definition vulkan.c:1400
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e, AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar, VkPipelineStageFlags2 src_stage, VkPipelineStageFlags2 dst_stage, VkAccessFlagBits2 new_access, VkImageLayout new_layout, uint32_t new_qf)
Definition vulkan.c:2197
VkFormatFeatureFlagBits2 ff_vk_map_usage_to_feats(VkImageUsageFlags usage)
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition vulkan.c:660
int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e, VkImageView views[AV_NUM_DATA_POINTERS], AVFrame *f, enum FFVkShaderRepFormat rep_fmt)
Create an imageview and add it as a dependency to an execution.
Definition vulkan.c:2128
#define FF_VK_MAX_SHADERS
Definition vulkan.h:79
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition vulkan.c:2784
FFVkImageViews * ff_vk_imageviews_alloc(FFVulkanContext *s, int nb_views)
Allocate a reference-counted set of image views, zero-initialized for the caller to create.
Definition vulkan.c:1959
static int ff_vk_unmap_buffer(FFVulkanContext *s, FFVkBuffer *buf, int flush)
Definition vulkan.h:649
VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e, void **data, VkQueryResultFlagBits flags)
Performs nb_queries queries and returns their results and statuses.
Definition vulkan.c:594
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
Definition vulkan.c:2577
int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler, int unnorm_coords, VkFilter filt)
Create a sampler.
Definition vulkan.c:1624
#define FF_VK_EXEC_MAX_FRAME_DEPS
Definition vulkan.h:115
static int ff_vk_count_images(AVVkFrame *f)
Definition vulkan.h:356
void ff_vk_exec_update_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkImageMemoryBarrier2 *bar, uint32_t *nb_img_bar)
Definition vulkan.c:925
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition vulkan.c:622
int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
Returns 1 if pixfmt is a usable RGB format.
Definition vulkan.c:1673
#define FF_VK_MAX_PUSH_CONSTS
Definition vulkan.h:78
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition vulkan.c:969
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition vulkan.c:2761
#define FF_VK_MAX_DESCRIPTOR_BINDINGS
Definition vulkan.h:76
void ff_vk_exec_move_dep_refstruct(FFVulkanContext *s, FFVkExecContext *e, void *obj)
Definition vulkan.c:786
int ff_vk_shader_update_desc_buffer(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, int set, int bind, int elem, FFVkBuffer *buf, VkDeviceSize offset, VkDeviceSize len, VkFormat fmt)
Update a descriptor in a buffer with a buffer.
Definition vulkan.c:2725
#define FF_VK_EXEC_MAX_BUF_DEPS
Definition vulkan.h:116
VkImageUsageFlags ff_vk_map_feats_to_usage(VkFormatFeatureFlagBits2 feats)
Map between usage and features.
AVVulkanDeviceQueueFamily * ff_vk_qf_find(FFVulkanContext *s, VkQueueFlagBits dev_family, VkVideoCodecOperationFlagBitsKHR vid_ops)
Chooses an appropriate QF.
Definition vulkan.c:316
int ff_vk_host_map_buffer(FFVulkanContext *s, FFVkBuffer **dst, uint8_t *src_data, VkDeviceSize size, const AVBufferRef *src_buf, VkBufferUsageFlags usage)
Maps a system RAM buffer into a Vulkan buffer.
Definition vulkan.c:1522
void ff_vk_exec_add_dep_refstruct(FFVulkanContext *s, FFVkExecContext *e, void *obj)
Execution dependency management.
Definition vulkan.c:779
int ff_vk_create_imageview(FFVulkanContext *s, VkImageView *img_view, VkImageAspectFlags *aspect, AVFrame *f, int plane, enum FFVkShaderRepFormat rep_fmt)
Create a single imageview for a given plane.
Definition vulkan.c:2077
int ff_vk_get_pooled_buffer(FFVulkanContext *ctx, AVRefStructPool **buf_pool, FFVkBuffer **buf, VkBufferUsageFlags usage, void *create_pNext, size_t size, VkMemoryPropertyFlagBits mem_props)
Initialize a pool and create AVBufferRefs containing FFVkBuffer.
Definition vulkan.c:1426
#define FF_VK_EXEC_MAX_SW_FRAME_DEPS
Definition vulkan.h:117
int ff_vk_flush_buffer(FFVulkanContext *s, FFVkBuffer *buf, VkDeviceSize offset, VkDeviceSize mem_size, int flush)
Flush or invalidate a single buffer, with a given size and offset.
Definition vulkan.c:1327
int ff_vk_exec_mirror_sem_value(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore *dst, uint64_t *dst_val, AVFrame *f)
Definition vulkan.c:944
static void ff_vk_link_struct(void *chain, const void *in)
Definition vulkan.h:378
void ff_vk_exec_discard(FFVulkanContext *s, FFVkExecContext *e)
Definition vulkan.c:763
#define FF_VK_MAX_DESCRIPTOR_SETS
Definition vulkan.h:75
void ff_vk_exec_add_dep_bool_sem(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore *sem, int nb, VkPipelineStageFlagBits2 stage, int wait)
Definition vulkan.c:839
int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, const char *spirv, size_t spirv_len, const char *entrypoint)
Link a shader into an executable.
Definition vulkan.c:2437
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
Definition vulkan.c:867
static int ff_vk_map_buffer(FFVulkanContext *s, FFVkBuffer *buf, uint8_t **mem, int invalidate)
Definition vulkan.h:642
#define FF_VK_MAX_DESCRIPTOR_TYPES
Definition vulkan.h:77
void ff_vk_shader_update_push_const(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, VkShaderStageFlagBits stage, int offset, size_t size, void *src)
Update push constant in a shader.
Definition vulkan.c:2751
void ff_vk_exec_add_dep_wait_sem(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore sem, uint64_t val, VkPipelineStageFlagBits2 stage)
Definition vulkan.c:825
uint64_t FFVulkanExtensions