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 VkPipeline pipeline;
229
230 /* Pipeline layout */
231 VkPipelineLayout pipeline_layout;
232
233 /* Push consts */
234 VkPushConstantRange push_consts[FF_VK_MAX_PUSH_CONSTS];
236
237 /* Descriptor sets */
240
241 /* Descriptors */
243
244 /* Descriptor pool */
249
251 /* Descriptor buffer */
253 uint8_t *desc_mem;
255
256typedef struct FFVulkanShaderData {
257 /* Shader to which this data belongs to */
260
261 /* Descriptor buffer */
263 VkDescriptorBufferBindingInfoEXT desc_bind[FF_VK_MAX_DESCRIPTOR_SETS];
264
265 /* Descriptor pools */
266 VkDescriptorSet *desc_sets;
267 VkDescriptorPool desc_pool;
269
291
292typedef struct FFVulkanContext {
293 const AVClass *class;
295
298 VkPhysicalDeviceProperties2 props;
299 VkPhysicalDeviceVulkan11Properties props_11;
300 VkPhysicalDeviceDriverProperties driver_props;
301 VkPhysicalDeviceMemoryProperties mprops;
302 VkPhysicalDeviceExternalMemoryHostPropertiesEXT hprops;
303 VkPhysicalDeviceDescriptorBufferPropertiesEXT desc_buf_props;
304 VkPhysicalDeviceSubgroupSizeControlProperties subgroup_props;
305 VkPhysicalDeviceCooperativeMatrixPropertiesKHR coop_matrix_props;
306 VkPhysicalDevicePushDescriptorPropertiesKHR push_desc_props;
307 VkPhysicalDeviceOpticalFlowPropertiesNV optical_flow_props;
308#ifdef VK_EXT_shader_long_vector
309 VkPhysicalDeviceShaderLongVectorPropertiesEXT long_vector_props;
310#endif
311 VkQueueFamilyQueryResultStatusPropertiesKHR *query_props;
312 VkQueueFamilyVideoPropertiesKHR *video_props;
313#ifdef VK_KHR_maintenance9
314 VkQueueFamilyOwnershipTransferPropertiesKHR *ownership_props;
315#endif
316 VkQueueFamilyProperties2 *qf_props;
318 VkPhysicalDeviceHostImageCopyPropertiesEXT host_image_props;
320
321 VkCooperativeMatrixPropertiesKHR *coop_mat_props;
323
324 VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomic_float_feats;
326
327 VkPhysicalDeviceVulkan12Features feats_12;
328#ifdef VK_KHR_unified_image_layouts
329 VkPhysicalDeviceUnifiedImageLayoutsFeaturesKHR unified_layout_feats;
330#endif
331#ifdef VK_KHR_maintenance11
332 VkPhysicalDeviceMaintenance11FeaturesKHR maintenance_11_feats;
333#endif
334 VkPhysicalDeviceFeatures2 feats;
335
336 VkMemoryPropertyFlagBits host_cached_flag;
337
341
346
347 uint32_t qfs[64];
349
350 /* Properties */
356
357static inline int ff_vk_count_images(AVVkFrame *f)
358{
359 int cnt = 0;
360 while (cnt < FF_ARRAY_ELEMS(f->img) && f->img[cnt])
361 cnt++;
362
363 return cnt;
364}
365
366static inline const void *ff_vk_find_struct(const void *chain, VkStructureType stype)
367{
368 const VkBaseInStructure *in = chain;
369 while (in) {
370 if (in->sType == stype)
371 return in;
372
373 in = in->pNext;
374 }
375
376 return NULL;
377}
378
379static inline void ff_vk_link_struct(void *chain, const void *in)
380{
381 VkBaseOutStructure *out = chain;
382 while (out->pNext)
383 out = out->pNext;
384
385 out->pNext = (void *)in;
386}
387
388#define FF_VK_STRUCT_EXT(CTX, BASE, STRUCT_P, EXT_FLAG, TYPE) \
389 do { \
390 if ((EXT_FLAG == FF_VK_EXT_NO_FLAG) || \
391 ((CTX)->extensions & EXT_FLAG)) { \
392 (STRUCT_P)->sType = TYPE; \
393 ff_vk_link_struct(BASE, STRUCT_P); \
394 } \
395 } while (0)
396
397/* Identity mapping - r = r, b = b, g = g, a = a */
398extern const VkComponentMapping ff_comp_identity_map;
399
400/**
401 * Initializes the AVClass, in case this context is not used
402 * as the main user's context.
403 * May use either a frames context reference, or a device context reference.
404 */
405int ff_vk_init(FFVulkanContext *s, void *log_parent,
406 AVBufferRef *device_ref, AVBufferRef *frames_ref);
407
408/**
409 * Converts Vulkan return values to strings
410 */
411const char *ff_vk_ret2str(VkResult res);
412
413/**
414 * Map between usage and features.
415 */
416VkImageUsageFlags ff_vk_map_feats_to_usage(VkFormatFeatureFlagBits2 feats);
417VkFormatFeatureFlagBits2 ff_vk_map_usage_to_feats(VkImageUsageFlags usage);
418
419/**
420 * Returns 1 if pixfmt is a usable RGB format.
421 */
423
424/**
425 * Since storage images may not be swizzled, we have to do this in the
426 * shader itself. This fills in a lookup table to do it.
427 */
428void ff_vk_set_perm(enum AVPixelFormat pix_fmt, int lut[4], int inv);
429
430/**
431 * Get the aspect flag for a plane from an image.
432 */
433VkImageAspectFlags ff_vk_aspect_flag(AVFrame *f, int p);
434
435/**
436 * Returns the format to use for images in shaders.
437 */
439 /* Native format with no conversion. May require casting. */
441 /* Float conversion of the native format. */
443 /* Signed integer version of the native format */
445 /* Unsigned integer version of the native format */
447};
449 enum FFVkShaderRepFormat rep_fmt);
450
451/**
452 * Loads props/mprops/driver_props
453 */
455
456/**
457 * Chooses an appropriate QF.
458 */
460 VkQueueFlagBits dev_family,
461 VkVideoCodecOperationFlagBitsKHR vid_ops);
462
463/**
464 * Allocates/frees an execution pool.
465 * If used in a multi-threaded context, there must be at least as many contexts
466 * as there are threads.
467 * ff_vk_exec_pool_init_desc() MUST be called if ff_vk_exec_descriptor_set_add()
468 * has been called.
469 */
471 FFVkExecPool *pool, int nb_contexts,
472 int nb_queries, VkQueryType query_type, int query_64bit,
473 const void *query_create_pnext);
475
476/**
477 * Retrieve an execution pool. Threadsafe.
478 */
480
481/**
482 * Performs nb_queries queries and returns their results and statuses.
483 * 64_BIT and WITH_STATUS flags are ignored as 64_BIT must be specified via
484 * query_64bit in ff_vk_exec_pool_init() and WITH_STATUS is always enabled.
485 */
487 void **data, VkQueryResultFlagBits flags);
488
489/**
490 * Start/submit/wait an execution.
491 * ff_vk_exec_start() always waits on a submission, so using ff_vk_exec_wait()
492 * is not necessary (unless using it is just better).
493 */
497
498/**
499 * Execution dependency management.
500 * Can attach buffers to executions that will only be unref'd once the
501 * buffer has finished executing.
502 * Adding a frame dep will *lock the frame*, until either the dependencies
503 * are discarded, the execution is submitted, or a failure happens.
504 * update_frame will update the frame's properties before it is unlocked,
505 * only if submission was successful.
506 * ff_vk_exec_discard() abandons a started, unsubmitted recording: call it
507 * exactly once, from the claiming thread. ff_vk_exec_submit() cleans up
508 * after its own failures.
509 */
510
511/* Takes a new reference to an AVRefStruct-managed object, held until the
512 * execution's dependencies are released. */
514 void *obj);
515
516/* Moves the caller's reference into the execution's dependencies, given a
517 * pointer to it; a duplicate of an already-tracked object is released. */
519 void *obj);
520
521/* Takes ownership of a raw Vulkan object, destroyed when the execution's
522 * dependencies are released. */
524 VkObjectType type, uint64_t obj);
525
527 VkSemaphore sem, uint64_t val,
528 VkPipelineStageFlagBits2 stage);
530 VkSemaphore sem, uint64_t val,
531 VkPipelineStageFlagBits2 stage);
533 VkSemaphore *sem, int nb,
534 VkPipelineStageFlagBits2 stage,
535 int wait); /* Ownership transferred if !wait */
537 VkPipelineStageFlagBits2 wait_stage,
538 VkPipelineStageFlagBits2 signal_stage);
540 AVFrame *f);
542 VkImageMemoryBarrier2 *bar, uint32_t *nb_img_bar);
544 VkSemaphore *dst, uint64_t *dst_val,
545 AVFrame *f);
547
548/**
549 * Create a single imageview for a given plane.
550 */
552 VkImageView *img_view, VkImageAspectFlags *aspect,
553 AVFrame *f, int plane, enum FFVkShaderRepFormat rep_fmt);
554
555/* Refcounted set of image views; stashes destruction handles to be context-free */
556typedef struct FFVkImageViews {
558
559 VkDevice dev;
560 const VkAllocationCallbacks *alloc;
561 PFN_vkDestroyImageView destroy_image_view;
562
565
566/**
567 * Allocate a reference-counted set of image views, zero-initialized for the
568 * caller to create.
569 */
571
572/**
573 * Create an imageview and add it as a dependency to an execution.
574 */
576 VkImageView views[AV_NUM_DATA_POINTERS],
577 AVFrame *f, enum FFVkShaderRepFormat rep_fmt);
578
579#define ff_vk_buf_barrier(dst, vkb, s_stage, s_access, s_access2, \
580 d_stage, d_access, d_access2, offs, bsz) \
581 do { \
582 dst = (VkBufferMemoryBarrier2) { \
583 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2, \
584 .srcStageMask = VK_PIPELINE_STAGE_2_ ##s_stage, \
585 .srcAccessMask = VK_ACCESS_2_ ##s_access | \
586 VK_ACCESS_2_ ##s_access2, \
587 .dstStageMask = VK_PIPELINE_STAGE_2_ ##d_stage, \
588 .dstAccessMask = VK_ACCESS_2_ ##d_access | \
589 VK_ACCESS_2_ ##d_access2, \
590 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, \
591 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, \
592 .buffer = vkb->buf, \
593 .offset = offs, \
594 .size = bsz \
595 }; \
596 } while(0)
597
599 AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar,
600 VkPipelineStageFlags2 src_stage,
601 VkPipelineStageFlags2 dst_stage,
602 VkAccessFlagBits2 new_access,
603 VkImageLayout new_layout,
604 uint32_t new_qf);
605
606/**
607 * Memory/buffer/image allocation helpers.
608 */
609/**
610 * Create a standalone internal-use image: exclusive sharing, dedicated
611 * memory. Not for interop or mapping.
612 */
613int ff_vk_image_create(FFVulkanContext *s, VkImage *img, VkDeviceMemory *mem,
614 int width, int height, VkFormat format, int nb_layers,
615 VkImageTiling tiling, VkImageUsageFlags usage,
616 VkImageCreateFlags flags, void *create_pnext);
617
618/**
619 * Free an image created by ff_vk_image_create(); all GPU use must have
620 * completed.
621 */
622void ff_vk_image_free(FFVulkanContext *s, VkImage *img, VkDeviceMemory *mem);
623
624int ff_vk_alloc_mem(FFVulkanContext *s, VkMemoryRequirements *req,
625 VkMemoryPropertyFlagBits req_flags, void *alloc_extension,
626 VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem);
628 void *pNext, void *alloc_pNext,
629 VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags);
630
631/**
632 * Flush or invalidate a single buffer, with a given size and offset.
633 */
635 VkDeviceSize offset, VkDeviceSize mem_size,
636 int flush);
637
638/**
639 * Buffer management code.
640 */
641int ff_vk_map_buffers(FFVulkanContext *s, FFVkBuffer **buf, uint8_t *mem[],
642 int nb_buffers, int invalidate);
643int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer **buf, int nb_buffers,
644 int flush);
645
646static inline int ff_vk_map_buffer(FFVulkanContext *s, FFVkBuffer *buf, uint8_t **mem,
647 int invalidate)
648{
649 return ff_vk_map_buffers(s, (FFVkBuffer *[]){ buf }, mem,
650 1, invalidate);
651}
652
654{
655 return ff_vk_unmap_buffers(s, (FFVkBuffer *[]){ buf }, 1, flush);
656}
657
659
660/** Initialize a pool and create AVBufferRefs containing FFVkBuffer.
661 * Threadsafe to use. Buffers are automatically mapped on creation if
662 * VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT is set in mem_props. Users should
663 * synchronize access themselvesd. Mainly meant for device-local buffers. */
665 FFVkBuffer **buf, VkBufferUsageFlags usage,
666 void *create_pNext, size_t size,
667 VkMemoryPropertyFlagBits mem_props);
668
669/** Maps a system RAM buffer into a Vulkan buffer.
670 * References the source buffer. Imports size bytes starting at src_data,
671 * rounded up to the host-pointer import alignment and clamped to the end
672 * of src_buf. */
674 uint8_t *src_data, VkDeviceSize size,
675 const AVBufferRef *src_buf,
676 VkBufferUsageFlags usage);
677
678/**
679 * Create a sampler.
680 */
681int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler,
682 int unnorm_coords, VkFilter filt);
683
684/**
685 * Initialize a shader object.
686 * If spec is non-null, it must have been created with SPEC_LIST_CREATE().
687 * The IDs for the workgroup size must be 253, 254, 255.
688 */
690 VkPipelineStageFlags stage, VkSpecializationInfo *spec,
691 uint32_t wg_size[3], uint32_t required_subgroup_size);
692
693/**
694 * Link a shader into an executable.
695 */
697 const char *spirv, size_t spirv_len,
698 const char *entrypoint);
699
700/**
701 * Add/update push constants for execution.
702 */
704 VkShaderStageFlagBits stage);
705
706/**
707 * Add descriptor to a shader. Must be called before shader init.
708 */
710 const FFVulkanDescriptorSetBinding *desc, int nb,
711 int singular);
712
713/**
714 * Register a shader with an exec pool.
715 * Pool may be NULL if all descriptor sets are read-only.
716 */
718 FFVulkanShader *shd);
719
720/**
721 * Bind a shader.
722 */
724 const FFVulkanShader *shd);
725
726/**
727 * Update push constant in a shader.
728 * Must be called before binding the shader.
729 */
731 FFVulkanShader *shd,
732 VkShaderStageFlagBits stage,
733 int offset, size_t size, void *src);
734
735/**
736 * Update a descriptor in a buffer with a buffer.
737 * Must be called before binding the shader.
738 */
740 FFVulkanShader *shd,
741 int set, int bind, int elem,
742 FFVkBuffer *buf, VkDeviceSize offset, VkDeviceSize len,
743 VkFormat fmt);
744
745/**
746 * Sets an image descriptor for specified shader and binding.
747 */
749 FFVulkanShader *shd, int set, int bind, int offs,
750 VkImageView view, VkImageLayout layout,
751 VkSampler sampler);
752
753/**
754 * Update a descriptor in a buffer with an image array..
755 * Must be called before binding the shader.
756 */
758 FFVulkanShader *shd, AVFrame *f,
759 VkImageView *views, int set, int binding,
760 VkImageLayout layout, VkSampler sampler);
761
762/**
763 * Free a shader.
764 */
766
767/**
768 * Frees main context.
769 */
771
772#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:445
static const int8_t filt[NUMTAPS *2]
Definition af_earwax.c:40
static FILE * out
static AVFormatContext * ctx
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
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
static const char * obj
Definition mscl.c:57
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)
FF_ATOMIC_ALIGN64 uint_least64_t atomic_uint_least64_t
Definition stdatomic.h:80
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:184
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:288
int query_results
Definition vulkan.h:280
atomic_uint_least64_t idx
Definition vulkan.h:272
VkQueryPool query_pool
Definition vulkan.h:278
FFVkExecContext * contexts
Definition vulkan.h:271
VkCommandBuffer * cmd_bufs
Definition vulkan.h:275
int pool_size
Definition vulkan.h:276
int nb_queries
Definition vulkan.h:284
VkCommandPool * cmd_buf_pools
Definition vulkan.h:274
int nb_reg_shd
Definition vulkan.h:289
void * query_data
Definition vulkan.h:279
size_t qd_size
Definition vulkan.h:285
int query_status_stride
Definition vulkan.h:283
int query_statuses
Definition vulkan.h:281
int query_64bit
Definition vulkan.h:282
PFN_vkDestroyImageView destroy_image_view
Definition vulkan.h:561
const VkAllocationCallbacks * alloc
Definition vulkan.h:560
VkImageView views[AV_NUM_DATA_POINTERS]
Definition vulkan.h:563
VkDevice dev
Definition vulkan.h:559
uint32_t qfs[64]
Definition vulkan.h:347
AVHWFramesContext * frames
Definition vulkan.h:344
VkPhysicalDeviceMemoryProperties mprops
Definition vulkan.h:301
VkPhysicalDeviceVulkan12Features feats_12
Definition vulkan.h:327
FFVulkanExtensions extensions
Definition vulkan.h:297
int output_height
Definition vulkan.h:352
VkPhysicalDeviceOpticalFlowPropertiesNV optical_flow_props
Definition vulkan.h:307
VkImageLayout * host_image_copy_layouts
Definition vulkan.h:319
VkQueueFamilyVideoPropertiesKHR * video_props
Definition vulkan.h:312
AVVulkanDeviceContext * hwctx
Definition vulkan.h:340
VkPhysicalDeviceHostImageCopyPropertiesEXT host_image_props
Definition vulkan.h:318
VkPhysicalDeviceCooperativeMatrixPropertiesKHR coop_matrix_props
Definition vulkan.h:305
VkMemoryPropertyFlagBits host_cached_flag
Definition vulkan.h:336
void * log_parent
Definition vulkan.h:294
AVBufferRef * input_frames_ref
Definition vulkan.h:342
VkCooperativeMatrixPropertiesKHR * coop_mat_props
Definition vulkan.h:321
VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomic_float_feats
Definition vulkan.h:324
enum AVPixelFormat input_format
Definition vulkan.h:354
AVRefStructPool * imageviews_pool
Definition vulkan.h:325
VkPhysicalDeviceExternalMemoryHostPropertiesEXT hprops
Definition vulkan.h:302
VkPhysicalDevicePushDescriptorPropertiesKHR push_desc_props
Definition vulkan.h:306
VkPhysicalDeviceSubgroupSizeControlProperties subgroup_props
Definition vulkan.h:304
uint32_t coop_mat_props_nb
Definition vulkan.h:322
VkPhysicalDeviceVulkan11Properties props_11
Definition vulkan.h:299
FFVulkanFunctions vkfn
Definition vulkan.h:296
VkPhysicalDeviceDriverProperties driver_props
Definition vulkan.h:300
AVBufferRef * frames_ref
Definition vulkan.h:343
AVHWDeviceContext * device
Definition vulkan.h:339
VkPhysicalDeviceProperties2 props
Definition vulkan.h:298
VkQueueFamilyProperties2 * qf_props
Definition vulkan.h:316
VkPhysicalDeviceFeatures2 feats
Definition vulkan.h:334
enum AVPixelFormat output_format
Definition vulkan.h:353
VkPhysicalDeviceDescriptorBufferPropertiesEXT desc_buf_props
Definition vulkan.h:303
AVVulkanFramesContext * hwfc
Definition vulkan.h:345
VkQueueFamilyQueryResultStatusPropertiesKHR * query_props
Definition vulkan.h:311
AVBufferRef * device_ref
Definition vulkan.h:338
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:266
FFVulkanDescriptorSetData desc_set_buf[FF_VK_MAX_DESCRIPTOR_SETS]
Definition vulkan.h:262
VkDescriptorBufferBindingInfoEXT desc_bind[FF_VK_MAX_DESCRIPTOR_SETS]
Definition vulkan.h:263
FFVulkanShader * shd
Definition vulkan.h:258
VkDescriptorPool desc_pool
Definition vulkan.h:267
VkPipelineLayout pipeline_layout
Definition vulkan.h:231
FFVulkanDescriptorSet desc_set[FF_VK_MAX_DESCRIPTOR_SETS]
Definition vulkan.h:238
VkPipeline pipeline
Definition vulkan.h:228
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo subgroup_info
Definition vulkan.h:226
VkPipelineStageFlags stage
Definition vulkan.h:222
int push_consts_num
Definition vulkan.h:235
VkSpecializationInfo * specialization_info
Definition vulkan.h:216
int nb_descriptor_sets
Definition vulkan.h:239
int precompiled
Definition vulkan.h:215
VkPushConstantRange push_consts[FF_VK_MAX_PUSH_CONSTS]
Definition vulkan.h:234
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:242
VkPipelineBindPoint bind_point
Definition vulkan.h:223
VkDescriptorPoolSize desc_pool_size[FF_VK_MAX_DESCRIPTOR_TYPES]
Definition vulkan.h:246
int nb_desc_pool_size
Definition vulkan.h:247
#define src
Definition vp8dsp.c:248
#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:1715
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:2690
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:2262
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:2521
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
Definition vulkan.c:335
FFVkShaderRepFormat
Returns the format to use for images in shaders.
Definition vulkan.h:438
@ FF_VK_REP_UINT
Definition vulkan.h:446
@ FF_VK_REP_INT
Definition vulkan.h:444
@ FF_VK_REP_NATIVE
Definition vulkan.h:440
@ FF_VK_REP_FLOAT
Definition vulkan.h:442
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt, enum FFVkShaderRepFormat rep_fmt)
Definition vulkan.c:1769
int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer **buf, int nb_buffers, int flush)
Definition vulkan.c:1376
VkImageAspectFlags ff_vk_aspect_flag(AVFrame *f, int p)
Get the aspect flag for a plane from an image.
Definition vulkan.c:1675
int ff_vk_create_buf(FFVulkanContext *s, FFVkBuffer *buf, size_t size, void *pNext, void *alloc_pNext, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags)
Definition vulkan.c:1204
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:399
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:1190
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
Definition vulkan.c:649
int ff_vk_alloc_mem(FFVulkanContext *s, VkMemoryRequirements *req, VkMemoryPropertyFlagBits req_flags, void *alloc_extension, VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem)
Definition vulkan.c:1062
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:1113
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
Definition vulkan.c:1631
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:2665
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition vulkan.c:2779
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:1296
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:2795
static const void * ff_vk_find_struct(const void *chain, VkStructureType stype)
Definition vulkan.h:366
int ff_vk_exec_add_dep_sw_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f)
Definition vulkan.c:815
void ff_vk_exec_add_dep_obj(FFVulkanContext *s, FFVkExecContext *e, VkObjectType type, uint64_t obj)
Definition vulkan.c:808
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
Definition vulkan.c:1418
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:2216
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:664
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:2147
#define FF_VK_MAX_SHADERS
Definition vulkan.h:79
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition vulkan.c:2757
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:1978
static int ff_vk_unmap_buffer(FFVulkanContext *s, FFVkBuffer *buf, int flush)
Definition vulkan.h:653
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:598
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
Definition vulkan.c:2555
int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler, int unnorm_coords, VkFilter filt)
Create a sampler.
Definition vulkan.c:1642
#define FF_VK_EXEC_MAX_FRAME_DEPS
Definition vulkan.h:115
static int ff_vk_count_images(AVVkFrame *f)
Definition vulkan.h:357
void ff_vk_exec_update_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkImageMemoryBarrier2 *bar, uint32_t *nb_img_bar)
Definition vulkan.c:943
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition vulkan.c:626
int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
Returns 1 if pixfmt is a usable RGB format.
Definition vulkan.c:1692
#define FF_VK_MAX_PUSH_CONSTS
Definition vulkan.h:78
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition vulkan.c:987
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition vulkan.c:2739
#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:790
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:2703
#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:320
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:1540
void ff_vk_exec_add_dep_refstruct(FFVulkanContext *s, FFVkExecContext *e, void *obj)
Execution dependency management.
Definition vulkan.c:783
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:2096
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:1444
#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:1345
int ff_vk_exec_mirror_sem_value(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore *dst, uint64_t *dst_val, AVFrame *f)
Definition vulkan.c:962
static void ff_vk_link_struct(void *chain, const void *in)
Definition vulkan.h:379
void ff_vk_exec_add_dep_signal_sem(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore sem, uint64_t val, VkPipelineStageFlagBits2 stage)
Definition vulkan.c:843
void ff_vk_exec_discard(FFVulkanContext *s, FFVkExecContext *e)
Definition vulkan.c:767
#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:857
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:2425
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
Definition vulkan.c:885
static int ff_vk_map_buffer(FFVulkanContext *s, FFVkBuffer *buf, uint8_t **mem, int invalidate)
Definition vulkan.h:646
#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:2729
void ff_vk_exec_add_dep_wait_sem(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore sem, uint64_t val, VkPipelineStageFlagBits2 stage)
Definition vulkan.c:829
uint64_t FFVulkanExtensions