FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
hwcontext_vulkan.c File Reference
#include <dlfcn.h>
#include <unistd.h>
#include "thread.h"
#include "config.h"
#include "pixdesc.h"
#include "avstring.h"
#include "imgutils.h"
#include "hwcontext.h"
#include "hwcontext_internal.h"
#include "hwcontext_vulkan.h"
#include "mem.h"
#include "vulkan.h"
#include "vulkan_loader.h"

Go to the source code of this file.

Data Structures

struct  VulkanDeviceFeatures
 
struct  VulkanDevicePriv
 
struct  VulkanFramesPriv
 
struct  AVVkFrameInternal
 
struct  FFVkFormatEntry
 
struct  VulkanOptExtension
 
struct  VulkanDeviceSelection
 

Macros

#define VK_NO_PROTOTYPES
 
#define VK_ENABLE_BETA_EXTENSIONS
 
#define OPT_CHAIN(STRUCT_P, EXT_FLAG, TYPE)
 
#define COPY_VAL(VAL)
 
#define ASPECT_2PLANE   (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT)
 
#define ASPECT_3PLANE   (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT | VK_IMAGE_ASPECT_PLANE_2_BIT)
 
#define FN_MAP_TO(dst_t, dst_name, src_t, src_name)
 
#define MAP_TO(flag1, flag2)   if (src & flag2) dst |= flag1;
 
#define MAP_TO(flag1, flag2)   if (src & flag1) dst |= flag2;
 
#define ADD_VAL_TO_LIST(list, count, val)
 
#define RELEASE_PROPS(props, count)
 
#define PICK_QF(type, vid_op)
 
#define SET_OLD_QF(field, nb_field, type)
 
#define CHECK_QUEUE(type, required, fidx, ctx_qf, qc)
 
#define ADD_QUEUE(ctx_qf, qc, flag)
 

Enumerations

enum  FFVulkanDebugMode {
  FF_VULKAN_DEBUG_NONE = 0, FF_VULKAN_DEBUG_VALIDATE = 1, FF_VULKAN_DEBUG_PRINTF = 2, FF_VULKAN_DEBUG_PRACTICES = 3,
  FF_VULKAN_DEBUG_PROFILE = 4, FF_VULKAN_DEBUG_NB
}
 
enum  PrepMode {
  PREP_MODE_GENERAL, PREP_MODE_WRITE, PREP_MODE_EXTERNAL_EXPORT, PREP_MODE_EXTERNAL_IMPORT,
  PREP_MODE_DECODING_DST, PREP_MODE_DECODING_DPB, PREP_MODE_ENCODING_DPB
}
 

Functions

static void device_features_init (AVHWDeviceContext *ctx, VulkanDeviceFeatures *feats)
 
static void device_features_copy_needed (VulkanDeviceFeatures *dst, VulkanDeviceFeatures *src)
 
const VkFormatav_vkfmt_from_pixfmt (enum AVPixelFormat p)
 Returns the optimal per-plane Vulkan format for a given sw_format, one for each plane. More...
 
static const struct FFVkFormatEntryvk_find_format_entry (enum AVPixelFormat p)
 
static int vkfmt_from_pixfmt2 (AVHWDeviceContext *dev_ctx, enum AVPixelFormat p, VkImageTiling tiling, VkFormat fmts[AV_NUM_DATA_POINTERS], int *nb_images, VkImageAspectFlags *aspect, VkImageUsageFlags *supported_usage, int disable_multiplane, int need_storage)
 
static int load_libvulkan (AVHWDeviceContext *ctx)
 
static VkBool32 VKAPI_CALL vk_dbg_callback (VkDebugUtilsMessageSeverityFlagBitsEXT severity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *data, void *priv)
 
static int check_extensions (AVHWDeviceContext *ctx, int dev, AVDictionary *opts, const char *const **dst, uint32_t *num, enum FFVulkanDebugMode debug_mode)
 
static int check_layers (AVHWDeviceContext *ctx, AVDictionary *opts, const char *const **dst, uint32_t *num, enum FFVulkanDebugMode *debug_mode)
 
static int create_instance (AVHWDeviceContext *ctx, AVDictionary *opts, enum FFVulkanDebugMode *debug_mode)
 
static const char * vk_dev_type (enum VkPhysicalDeviceType type)
 
static int find_device (AVHWDeviceContext *ctx, VulkanDeviceSelection *select)
 
static int pick_queue_family (VkQueueFamilyProperties2 *qf, uint32_t num_qf, VkQueueFlagBits flags)
 
static int pick_video_queue_family (VkQueueFamilyProperties2 *qf, VkQueueFamilyVideoPropertiesKHR *qf_vid, uint32_t num_qf, VkVideoCodecOperationFlagBitsKHR flags)
 
static int setup_queue_families (AVHWDeviceContext *ctx, VkDeviceCreateInfo *cd)
 
static void vulkan_device_free (AVHWDeviceContext *ctx)
 
static void vulkan_device_uninit (AVHWDeviceContext *ctx)
 
static int vulkan_device_create_internal (AVHWDeviceContext *ctx, VulkanDeviceSelection *dev_select, int disable_multiplane, AVDictionary *opts, int flags)
 
static void lock_queue (AVHWDeviceContext *ctx, uint32_t queue_family, uint32_t index)
 
static void unlock_queue (AVHWDeviceContext *ctx, uint32_t queue_family, uint32_t index)
 
static int vulkan_device_init (AVHWDeviceContext *ctx)
 
static int vulkan_device_create (AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
 
static int vulkan_device_derive (AVHWDeviceContext *ctx, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
 
static int vulkan_frames_get_constraints (AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
 
static int alloc_mem (AVHWDeviceContext *ctx, VkMemoryRequirements *req, VkMemoryPropertyFlagBits req_flags, const void *alloc_extension, VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem)
 
static void vulkan_free_internal (AVVkFrame *f)
 
static void vulkan_frame_free (AVHWFramesContext *hwfc, AVVkFrame *f)
 
static void vulkan_frame_free_cb (void *opaque, uint8_t *data)
 
static int alloc_bind_mem (AVHWFramesContext *hwfc, AVVkFrame *f, void *alloc_pnext, size_t alloc_pnext_stride)
 
static int prepare_frame (AVHWFramesContext *hwfc, FFVkExecPool *ectx, AVVkFrame *frame, enum PrepMode pmode)
 
static void get_plane_wh (uint32_t *w, uint32_t *h, enum AVPixelFormat format, int frame_w, int frame_h, int plane)
 
static int create_frame (AVHWFramesContext *hwfc, AVVkFrame **frame, VkImageTiling tiling, VkImageUsageFlagBits usage, VkImageCreateFlags flags, int nb_layers, void *create_pnext)
 
static void try_export_flags (AVHWFramesContext *hwfc, VkExternalMemoryHandleTypeFlags *comp_handle_types, VkExternalMemoryHandleTypeFlagBits *iexp, VkExternalMemoryHandleTypeFlagBits exp)
 
static AVBufferRefvulkan_pool_alloc (void *opaque, size_t size)
 
static void lock_frame (AVHWFramesContext *fc, AVVkFrame *vkf)
 
static void unlock_frame (AVHWFramesContext *fc, AVVkFrame *vkf)
 
static void vulkan_frames_uninit (AVHWFramesContext *hwfc)
 
static int vulkan_frames_init (AVHWFramesContext *hwfc)
 
static int vulkan_get_buffer (AVHWFramesContext *hwfc, AVFrame *frame)
 
static int vulkan_transfer_get_formats (AVHWFramesContext *hwfc, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
 
static int vulkan_map_to (AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
 
static int vulkan_map_from (AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
 
static int copy_buffer_data (AVHWFramesContext *hwfc, AVBufferRef *buf, AVFrame *swf, VkBufferImageCopy *region, int planes, int upload)
 
static int get_plane_buf (AVHWFramesContext *hwfc, AVBufferRef **dst, AVFrame *swf, VkBufferImageCopy *region, int upload)
 
static int create_mapped_buffer (AVHWFramesContext *hwfc, FFVkBuffer *vkb, VkBufferUsageFlags usage, size_t size, VkExternalMemoryBufferCreateInfo *create_desc, VkImportMemoryHostPointerInfoEXT *import_desc, VkMemoryHostPointerPropertiesEXT props)
 
static void destroy_avvkbuf (void *opaque, uint8_t *data)
 
static int host_map_frame (AVHWFramesContext *hwfc, AVBufferRef **dst, int *nb_bufs, AVFrame *swf, VkBufferImageCopy *region, int upload)
 
static int vulkan_transfer_frame (AVHWFramesContext *hwfc, AVFrame *swf, AVFrame *hwf, int upload)
 
static int vulkan_transfer_data_to (AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
 
static int vulkan_transfer_data_from (AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
 
static int vulkan_frames_derive_to (AVHWFramesContext *dst_fc, AVHWFramesContext *src_fc, int flags)
 
AVVkFrameav_vk_frame_alloc (void)
 Allocates a single AVVkFrame and initializes everything as 0. More...
 

Variables

static const struct FFVkFormatEntry vk_formats_list []
 
static const int nb_vk_formats_list = FF_ARRAY_ELEMS(vk_formats_list)
 
static const VulkanOptExtension optional_instance_exts []
 
static const VulkanOptExtension optional_device_exts []
 
const HWContextType ff_hwcontext_type_vulkan
 

Macro Definition Documentation

◆ VK_NO_PROTOTYPES

#define VK_NO_PROTOTYPES

Definition at line 21 of file hwcontext_vulkan.c.

◆ VK_ENABLE_BETA_EXTENSIONS

#define VK_ENABLE_BETA_EXTENSIONS

Definition at line 22 of file hwcontext_vulkan.c.

◆ OPT_CHAIN

#define OPT_CHAIN (   STRUCT_P,
  EXT_FLAG,
  TYPE 
)
Value:
do { \
if ((EXT_FLAG == FF_VK_EXT_NO_FLAG) || \
(p->vkctx.extensions & EXT_FLAG)) { \
(STRUCT_P)->sType = TYPE; \
ff_vk_link_struct(&feats->device, STRUCT_P); \
} \
} while (0)

◆ COPY_VAL

#define COPY_VAL (   VAL)
Value:
do { \
dst->VAL = src->VAL; \
} while (0) \

◆ ASPECT_2PLANE

#define ASPECT_2PLANE   (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT)

Definition at line 292 of file hwcontext_vulkan.c.

◆ ASPECT_3PLANE

#define ASPECT_3PLANE   (VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT | VK_IMAGE_ASPECT_PLANE_2_BIT)

Definition at line 293 of file hwcontext_vulkan.c.

◆ FN_MAP_TO

#define FN_MAP_TO (   dst_t,
  dst_name,
  src_t,
  src_name 
)
Value:
static av_unused dst_t map_ ##src_name## _to_ ##dst_name(src_t src) \
{ \
dst_t dst = 0x0; \
MAP_TO(VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT, \
VK_IMAGE_USAGE_SAMPLED_BIT); \
MAP_TO(VK_FORMAT_FEATURE_2_TRANSFER_SRC_BIT, \
VK_IMAGE_USAGE_TRANSFER_SRC_BIT); \
MAP_TO(VK_FORMAT_FEATURE_2_TRANSFER_DST_BIT, \
VK_IMAGE_USAGE_TRANSFER_DST_BIT); \
MAP_TO(VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT, \
VK_IMAGE_USAGE_STORAGE_BIT); \
MAP_TO(VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT, \
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT); \
MAP_TO(VK_FORMAT_FEATURE_2_VIDEO_DECODE_OUTPUT_BIT_KHR, \
VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR); \
MAP_TO(VK_FORMAT_FEATURE_2_VIDEO_DECODE_DPB_BIT_KHR, \
VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR); \
MAP_TO(VK_FORMAT_FEATURE_2_VIDEO_ENCODE_DPB_BIT_KHR, \
VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR); \
MAP_TO(VK_FORMAT_FEATURE_2_VIDEO_ENCODE_INPUT_BIT_KHR, \
VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR); \
return dst; \
}

Definition at line 387 of file hwcontext_vulkan.c.

◆ MAP_TO [1/2]

#define MAP_TO (   flag1,
  flag2 
)    if (src & flag2) dst |= flag1;

Definition at line 415 of file hwcontext_vulkan.c.

◆ MAP_TO [2/2]

#define MAP_TO (   flag1,
  flag2 
)    if (src & flag1) dst |= flag2;

Definition at line 415 of file hwcontext_vulkan.c.

◆ ADD_VAL_TO_LIST

#define ADD_VAL_TO_LIST (   list,
  count,
  val 
)
Value:
do { \
list = av_realloc_array(list, sizeof(*list), ++count); \
if (!list) { \
err = AVERROR(ENOMEM); \
goto fail; \
} \
list[count - 1] = av_strdup(val); \
if (!list[count - 1]) { \
err = AVERROR(ENOMEM); \
goto fail; \
} \
} while(0)

Definition at line 618 of file hwcontext_vulkan.c.

◆ RELEASE_PROPS

#define RELEASE_PROPS (   props,
  count 
)
Value:
if (props) { \
for (int i = 0; i < count; i++) \
av_free((void *)((props)[i])); \
av_free((void *)props); \
}

Definition at line 632 of file hwcontext_vulkan.c.

◆ PICK_QF

#define PICK_QF (   type,
  vid_op 
)
Value:
do { \
uint32_t i; \
uint32_t idx; \
if (vid_op) \
idx = pick_video_queue_family(qf, qf_vid, num, vid_op); \
else \
idx = pick_queue_family(qf, num, type); \
if (idx == -1) \
continue; \
for (i = 0; i < hwctx->nb_qf; i++) { \
if (hwctx->qf[i].idx == idx) { \
hwctx->qf[i].flags |= type; \
hwctx->qf[i].video_caps |= vid_op; \
break; \
} \
} \
if (i == hwctx->nb_qf) { \
hwctx->qf[i].idx = idx; \
hwctx->qf[i].num = qf[idx].queueFamilyProperties.queueCount; \
hwctx->qf[i].flags = type; \
hwctx->qf[i].video_caps = vid_op; \
hwctx->nb_qf++; \
} \
} while (0)

◆ SET_OLD_QF

#define SET_OLD_QF (   field,
  nb_field,
  type 
)
Value:
do { \
if (field < 0 && hwctx->qf[i].flags & type) { \
field = hwctx->qf[i].idx; \
nb_field = hwctx->qf[i].num; \
} \
} while (0)

◆ CHECK_QUEUE

#define CHECK_QUEUE (   type,
  required,
  fidx,
  ctx_qf,
  qc 
)
Value:
do { \
if (ctx_qf < 0 && required) { \
av_log(ctx, AV_LOG_ERROR, "%s queue family is required, but marked as missing" \
" in the context!\n", type); \
err = AVERROR(EINVAL); \
goto end; \
} else if (fidx < 0 || ctx_qf < 0) { \
break; \
} else if (ctx_qf >= qf_num) { \
av_log(ctx, AV_LOG_ERROR, "Invalid %s family index %i (device has %i families)!\n", \
type, ctx_qf, qf_num); \
err = AVERROR(EINVAL); \
goto end; \
} \
av_log(ctx, AV_LOG_VERBOSE, "Using queue family %i (queues: %i)" \
" for%s%s%s%s%s\n", \
ctx_qf, qc, \
ctx_qf == graph_index ? " graphics" : "", \
ctx_qf == comp_index ? " compute" : "", \
ctx_qf == tx_index ? " transfers" : "", \
ctx_qf == enc_index ? " encode" : "", \
ctx_qf == dec_index ? " decode" : ""); \
graph_index = (ctx_qf == graph_index) ? -1 : graph_index; \
comp_index = (ctx_qf == comp_index) ? -1 : comp_index; \
tx_index = (ctx_qf == tx_index) ? -1 : tx_index; \
enc_index = (ctx_qf == enc_index) ? -1 : enc_index; \
dec_index = (ctx_qf == dec_index) ? -1 : dec_index; \
} while (0)

◆ ADD_QUEUE

#define ADD_QUEUE (   ctx_qf,
  qc,
  flag 
)
Value:
do { \
if (ctx_qf != -1) { \
hwctx->qf[hwctx->nb_qf++] = (AVVulkanDeviceQueueFamily) { \
.idx = ctx_qf, \
.num = qc, \
.flags = flag, \
}; \
} \
} while (0)

Enumeration Type Documentation

◆ FFVulkanDebugMode

Enumerator
FF_VULKAN_DEBUG_NONE 
FF_VULKAN_DEBUG_VALIDATE 
FF_VULKAN_DEBUG_PRINTF 
FF_VULKAN_DEBUG_PRACTICES 
FF_VULKAN_DEBUG_PROFILE 
FF_VULKAN_DEBUG_NB 

Definition at line 639 of file hwcontext_vulkan.c.

◆ PrepMode

enum PrepMode
Enumerator
PREP_MODE_GENERAL 
PREP_MODE_WRITE 
PREP_MODE_EXTERNAL_EXPORT 
PREP_MODE_EXTERNAL_IMPORT 
PREP_MODE_DECODING_DST 
PREP_MODE_DECODING_DPB 
PREP_MODE_ENCODING_DPB 

Definition at line 2251 of file hwcontext_vulkan.c.

Function Documentation

◆ device_features_init()

static void device_features_init ( AVHWDeviceContext ctx,
VulkanDeviceFeatures feats 
)
static

Definition at line 179 of file hwcontext_vulkan.c.

Referenced by vulkan_device_create_internal().

◆ device_features_copy_needed()

static void device_features_copy_needed ( VulkanDeviceFeatures dst,
VulkanDeviceFeatures src 
)
static

Definition at line 229 of file hwcontext_vulkan.c.

Referenced by vulkan_device_create_internal().

◆ av_vkfmt_from_pixfmt()

const VkFormat* av_vkfmt_from_pixfmt ( enum AVPixelFormat  p)

Returns the optimal per-plane Vulkan format for a given sw_format, one for each plane.

Returns NULL on unsupported formats.

Definition at line 370 of file hwcontext_vulkan.c.

Referenced by try_export_flags(), and vulkan_transfer_frame().

◆ vk_find_format_entry()

static const struct FFVkFormatEntry* vk_find_format_entry ( enum AVPixelFormat  p)
static

Definition at line 378 of file hwcontext_vulkan.c.

Referenced by vulkan_frames_init().

◆ vkfmt_from_pixfmt2()

static int vkfmt_from_pixfmt2 ( AVHWDeviceContext dev_ctx,
enum AVPixelFormat  p,
VkImageTiling  tiling,
VkFormat  fmts[AV_NUM_DATA_POINTERS],
int *  nb_images,
VkImageAspectFlags *  aspect,
VkImageUsageFlags *  supported_usage,
int  disable_multiplane,
int  need_storage 
)
static

Definition at line 420 of file hwcontext_vulkan.c.

Referenced by vulkan_frames_get_constraints(), and vulkan_frames_init().

◆ load_libvulkan()

static int load_libvulkan ( AVHWDeviceContext ctx)
static

Definition at line 507 of file hwcontext_vulkan.c.

Referenced by create_instance().

◆ vk_dbg_callback()

static VkBool32 VKAPI_CALL vk_dbg_callback ( VkDebugUtilsMessageSeverityFlagBitsEXT  severity,
VkDebugUtilsMessageTypeFlagsEXT  messageType,
const VkDebugUtilsMessengerCallbackDataEXT *  data,
void *  priv 
)
static

Definition at line 584 of file hwcontext_vulkan.c.

Referenced by create_instance().

◆ check_extensions()

static int check_extensions ( AVHWDeviceContext ctx,
int  dev,
AVDictionary opts,
const char *const **  dst,
uint32_t *  num,
enum FFVulkanDebugMode  debug_mode 
)
static

Definition at line 653 of file hwcontext_vulkan.c.

Referenced by create_instance(), and vulkan_device_create_internal().

◆ check_layers()

static int check_layers ( AVHWDeviceContext ctx,
AVDictionary opts,
const char *const **  dst,
uint32_t *  num,
enum FFVulkanDebugMode debug_mode 
)
static

Definition at line 817 of file hwcontext_vulkan.c.

Referenced by create_instance().

◆ create_instance()

static int create_instance ( AVHWDeviceContext ctx,
AVDictionary opts,
enum FFVulkanDebugMode debug_mode 
)
static

Definition at line 968 of file hwcontext_vulkan.c.

Referenced by vulkan_device_create_internal().

◆ vk_dev_type()

static const char* vk_dev_type ( enum VkPhysicalDeviceType  type)
static

Definition at line 1117 of file hwcontext_vulkan.c.

Referenced by find_device().

◆ find_device()

static int find_device ( AVHWDeviceContext ctx,
VulkanDeviceSelection select 
)
static

Definition at line 1129 of file hwcontext_vulkan.c.

Referenced by vulkan_device_create_internal().

◆ pick_queue_family()

static int pick_queue_family ( VkQueueFamilyProperties2 *  qf,
uint32_t  num_qf,
VkQueueFlagBits  flags 
)
inlinestatic

Definition at line 1286 of file hwcontext_vulkan.c.

◆ pick_video_queue_family()

static int pick_video_queue_family ( VkQueueFamilyProperties2 *  qf,
VkQueueFamilyVideoPropertiesKHR *  qf_vid,
uint32_t  num_qf,
VkVideoCodecOperationFlagBitsKHR  flags 
)
inlinestatic

Definition at line 1315 of file hwcontext_vulkan.c.

◆ setup_queue_families()

static int setup_queue_families ( AVHWDeviceContext ctx,
VkDeviceCreateInfo *  cd 
)
static

Definition at line 1344 of file hwcontext_vulkan.c.

Referenced by vulkan_device_create_internal().

◆ vulkan_device_free()

static void vulkan_device_free ( AVHWDeviceContext ctx)
static

Definition at line 1526 of file hwcontext_vulkan.c.

Referenced by vulkan_device_create_internal().

◆ vulkan_device_uninit()

static void vulkan_device_uninit ( AVHWDeviceContext ctx)
static

Definition at line 1549 of file hwcontext_vulkan.c.

◆ vulkan_device_create_internal()

static int vulkan_device_create_internal ( AVHWDeviceContext ctx,
VulkanDeviceSelection dev_select,
int  disable_multiplane,
AVDictionary opts,
int  flags 
)
static

Definition at line 1562 of file hwcontext_vulkan.c.

Referenced by vulkan_device_create(), and vulkan_device_derive().

◆ lock_queue()

static void lock_queue ( AVHWDeviceContext ctx,
uint32_t  queue_family,
uint32_t  index 
)
static

Definition at line 1655 of file hwcontext_vulkan.c.

Referenced by init_vulkan(), and vulkan_device_init().

◆ unlock_queue()

static void unlock_queue ( AVHWDeviceContext ctx,
uint32_t  queue_family,
uint32_t  index 
)
static

Definition at line 1661 of file hwcontext_vulkan.c.

Referenced by init_vulkan(), and vulkan_device_init().

◆ vulkan_device_init()

static int vulkan_device_init ( AVHWDeviceContext ctx)
static

Definition at line 1667 of file hwcontext_vulkan.c.

◆ vulkan_device_create()

static int vulkan_device_create ( AVHWDeviceContext ctx,
const char *  device,
AVDictionary opts,
int  flags 
)
static

Definition at line 1884 of file hwcontext_vulkan.c.

◆ vulkan_device_derive()

static int vulkan_device_derive ( AVHWDeviceContext ctx,
AVHWDeviceContext src_ctx,
AVDictionary opts,
int  flags 
)
static

Definition at line 1900 of file hwcontext_vulkan.c.

◆ vulkan_frames_get_constraints()

static int vulkan_frames_get_constraints ( AVHWDeviceContext ctx,
const void *  hwconfig,
AVHWFramesConstraints constraints 
)
static

Definition at line 2003 of file hwcontext_vulkan.c.

◆ alloc_mem()

static int alloc_mem ( AVHWDeviceContext ctx,
VkMemoryRequirements *  req,
VkMemoryPropertyFlagBits  req_flags,
const void *  alloc_extension,
VkMemoryPropertyFlagBits *  mem_flags,
VkDeviceMemory *  mem 
)
static

Definition at line 2049 of file hwcontext_vulkan.c.

Referenced by alloc_bind_mem().

◆ vulkan_free_internal()

static void vulkan_free_internal ( AVVkFrame f)
static

Definition at line 2107 of file hwcontext_vulkan.c.

Referenced by vulkan_frame_free().

◆ vulkan_frame_free()

static void vulkan_frame_free ( AVHWFramesContext hwfc,
AVVkFrame f 
)
static

◆ vulkan_frame_free_cb()

static void vulkan_frame_free_cb ( void *  opaque,
uint8_t *  data 
)
static

Definition at line 2177 of file hwcontext_vulkan.c.

Referenced by vulkan_pool_alloc().

◆ alloc_bind_mem()

static int alloc_bind_mem ( AVHWFramesContext hwfc,
AVVkFrame f,
void *  alloc_pnext,
size_t  alloc_pnext_stride 
)
static

Definition at line 2182 of file hwcontext_vulkan.c.

Referenced by vulkan_pool_alloc().

◆ prepare_frame()

static int prepare_frame ( AVHWFramesContext hwfc,
FFVkExecPool ectx,
AVVkFrame frame,
enum PrepMode  pmode 
)
static

Definition at line 2261 of file hwcontext_vulkan.c.

Referenced by vulkan_pool_alloc().

◆ get_plane_wh()

static void get_plane_wh ( uint32_t *  w,
uint32_t *  h,
enum AVPixelFormat  format,
int  frame_w,
int  frame_h,
int  plane 
)
inlinestatic

Definition at line 2351 of file hwcontext_vulkan.c.

Referenced by create_frame(), get_plane_buf(), and host_map_frame().

◆ create_frame()

static int create_frame ( AVHWFramesContext hwfc,
AVVkFrame **  frame,
VkImageTiling  tiling,
VkImageUsageFlagBits  usage,
VkImageCreateFlags  flags,
int  nb_layers,
void *  create_pnext 
)
static

Definition at line 2368 of file hwcontext_vulkan.c.

Referenced by vulkan_frames_init(), and vulkan_pool_alloc().

◆ try_export_flags()

static void try_export_flags ( AVHWFramesContext hwfc,
VkExternalMemoryHandleTypeFlags *  comp_handle_types,
VkExternalMemoryHandleTypeFlagBits *  iexp,
VkExternalMemoryHandleTypeFlagBits  exp 
)
static

Definition at line 2477 of file hwcontext_vulkan.c.

Referenced by vulkan_pool_alloc().

◆ vulkan_pool_alloc()

static AVBufferRef* vulkan_pool_alloc ( void *  opaque,
size_t  size 
)
static

Definition at line 2539 of file hwcontext_vulkan.c.

Referenced by vulkan_frames_init().

◆ lock_frame()

static void lock_frame ( AVHWFramesContext fc,
AVVkFrame vkf 
)
static

Definition at line 2609 of file hwcontext_vulkan.c.

Referenced by vulkan_frames_init().

◆ unlock_frame()

static void unlock_frame ( AVHWFramesContext fc,
AVVkFrame vkf 
)
static

Definition at line 2614 of file hwcontext_vulkan.c.

Referenced by vulkan_frames_init().

◆ vulkan_frames_uninit()

static void vulkan_frames_uninit ( AVHWFramesContext hwfc)
static

Definition at line 2619 of file hwcontext_vulkan.c.

◆ vulkan_frames_init()

static int vulkan_frames_init ( AVHWFramesContext hwfc)
static

Definition at line 2637 of file hwcontext_vulkan.c.

Referenced by vulkan_frames_derive_to().

◆ vulkan_get_buffer()

static int vulkan_get_buffer ( AVHWFramesContext hwfc,
AVFrame frame 
)
static

Definition at line 2796 of file hwcontext_vulkan.c.

◆ vulkan_transfer_get_formats()

static int vulkan_transfer_get_formats ( AVHWFramesContext hwfc,
enum AVHWFrameTransferDirection  dir,
enum AVPixelFormat **  formats 
)
static

Definition at line 2810 of file hwcontext_vulkan.c.

◆ vulkan_map_to()

static int vulkan_map_to ( AVHWFramesContext hwfc,
AVFrame dst,
const AVFrame src,
int  flags 
)
static

Definition at line 3607 of file hwcontext_vulkan.c.

◆ vulkan_map_from()

static int vulkan_map_from ( AVHWFramesContext hwfc,
AVFrame dst,
const AVFrame src,
int  flags 
)
static

Definition at line 3794 of file hwcontext_vulkan.c.

◆ copy_buffer_data()

static int copy_buffer_data ( AVHWFramesContext hwfc,
AVBufferRef buf,
AVFrame swf,
VkBufferImageCopy *  region,
int  planes,
int  upload 
)
static

Definition at line 3820 of file hwcontext_vulkan.c.

Referenced by vulkan_transfer_frame().

◆ get_plane_buf()

static int get_plane_buf ( AVHWFramesContext hwfc,
AVBufferRef **  dst,
AVFrame swf,
VkBufferImageCopy *  region,
int  upload 
)
static

Definition at line 3868 of file hwcontext_vulkan.c.

Referenced by vulkan_transfer_frame().

◆ create_mapped_buffer()

static int create_mapped_buffer ( AVHWFramesContext hwfc,
FFVkBuffer vkb,
VkBufferUsageFlags  usage,
size_t  size,
VkExternalMemoryBufferCreateInfo *  create_desc,
VkImportMemoryHostPointerInfoEXT *  import_desc,
VkMemoryHostPointerPropertiesEXT  props 
)
static

Definition at line 3913 of file hwcontext_vulkan.c.

Referenced by host_map_frame().

◆ destroy_avvkbuf()

static void destroy_avvkbuf ( void *  opaque,
uint8_t *  data 
)
static

Definition at line 3961 of file hwcontext_vulkan.c.

Referenced by host_map_frame().

◆ host_map_frame()

static int host_map_frame ( AVHWFramesContext hwfc,
AVBufferRef **  dst,
int *  nb_bufs,
AVFrame swf,
VkBufferImageCopy *  region,
int  upload 
)
static

Definition at line 3969 of file hwcontext_vulkan.c.

Referenced by vulkan_transfer_frame().

◆ vulkan_transfer_frame()

static int vulkan_transfer_frame ( AVHWFramesContext hwfc,
AVFrame swf,
AVFrame hwf,
int  upload 
)
static

Definition at line 4072 of file hwcontext_vulkan.c.

Referenced by vulkan_transfer_data_from(), and vulkan_transfer_data_to().

◆ vulkan_transfer_data_to()

static int vulkan_transfer_data_to ( AVHWFramesContext hwfc,
AVFrame dst,
const AVFrame src 
)
static

Definition at line 4208 of file hwcontext_vulkan.c.

◆ vulkan_transfer_data_from()

static int vulkan_transfer_data_from ( AVHWFramesContext hwfc,
AVFrame dst,
const AVFrame src 
)
static

Definition at line 4325 of file hwcontext_vulkan.c.

◆ vulkan_frames_derive_to()

static int vulkan_frames_derive_to ( AVHWFramesContext dst_fc,
AVHWFramesContext src_fc,
int  flags 
)
static

Definition at line 4350 of file hwcontext_vulkan.c.

◆ av_vk_frame_alloc()

AVVkFrame* av_vk_frame_alloc ( void  )

Allocates a single AVVkFrame and initializes everything as 0.

Note
Must be freed via av_free()

Definition at line 4356 of file hwcontext_vulkan.c.

Referenced by create_frame().

Variable Documentation

◆ vk_formats_list

const struct FFVkFormatEntry vk_formats_list[]
static

◆ nb_vk_formats_list

const int nb_vk_formats_list = FF_ARRAY_ELEMS(vk_formats_list)
static

◆ optional_instance_exts

const VulkanOptExtension optional_instance_exts[]
static
Initial value:
= {
{ VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, FF_VK_EXT_NO_FLAG },
}

Definition at line 546 of file hwcontext_vulkan.c.

Referenced by check_extensions().

◆ optional_device_exts

const VulkanOptExtension optional_device_exts[]
static

Definition at line 550 of file hwcontext_vulkan.c.

Referenced by check_extensions(), and vulkan_device_init().

◆ ff_hwcontext_type_vulkan

const HWContextType ff_hwcontext_type_vulkan
Initial value:
= {
.name = "Vulkan",
.device_hwctx_size = sizeof(VulkanDevicePriv),
.frames_hwctx_size = sizeof(VulkanFramesPriv),
.device_init = &vulkan_device_init,
.device_uninit = &vulkan_device_uninit,
.device_create = &vulkan_device_create,
.device_derive = &vulkan_device_derive,
.frames_get_constraints = &vulkan_frames_get_constraints,
.frames_init = vulkan_frames_init,
.frames_get_buffer = vulkan_get_buffer,
.frames_uninit = vulkan_frames_uninit,
.transfer_get_formats = vulkan_transfer_get_formats,
.transfer_data_to = vulkan_transfer_data_to,
.transfer_data_from = vulkan_transfer_data_from,
.map_to = vulkan_map_to,
.map_from = vulkan_map_from,
.frames_derive_to = &vulkan_frames_derive_to,
.pix_fmts = (const enum AVPixelFormat []) {
},
}

Definition at line 4379 of file hwcontext_vulkan.c.

vulkan_device_init
static int vulkan_device_init(AVHWDeviceContext *ctx)
Definition: hwcontext_vulkan.c:1667
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AVERROR
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 sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
vulkan_transfer_data_to
static int vulkan_transfer_data_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_vulkan.c:4208
vulkan_frames_get_constraints
static int vulkan_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
Definition: hwcontext_vulkan.c:2003
av_unused
#define av_unused
Definition: attributes.h:131
vulkan_frames_derive_to
static int vulkan_frames_derive_to(AVHWFramesContext *dst_fc, AVHWFramesContext *src_fc, int flags)
Definition: hwcontext_vulkan.c:4350
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
vulkan_map_from
static int vulkan_map_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_vulkan.c:3794
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
AV_HWDEVICE_TYPE_VULKAN
@ AV_HWDEVICE_TYPE_VULKAN
Definition: hwcontext.h:39
vulkan_device_derive
static int vulkan_device_derive(AVHWDeviceContext *ctx, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
Definition: hwcontext_vulkan.c:1900
fail
#define fail()
Definition: checkasm.h:188
VulkanDevicePriv
Definition: hwcontext_vulkan.c:97
val
static double val(void *priv, double ch)
Definition: aeval.c:77
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
vulkan_map_to
static int vulkan_map_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_vulkan.c:3607
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
vulkan_device_uninit
static void vulkan_device_uninit(AVHWDeviceContext *ctx)
Definition: hwcontext_vulkan.c:1549
vulkan_frames_uninit
static void vulkan_frames_uninit(AVHWFramesContext *hwfc)
Definition: hwcontext_vulkan.c:2619
ctx
AVFormatContext * ctx
Definition: movenc.c:49
vulkan_transfer_get_formats
static int vulkan_transfer_get_formats(AVHWFramesContext *hwfc, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
Definition: hwcontext_vulkan.c:2810
if
if(ret)
Definition: filter_design.txt:179
TYPE
#define TYPE
Definition: ffv1dec.c:116
pick_video_queue_family
static int pick_video_queue_family(VkQueueFamilyProperties2 *qf, VkQueueFamilyVideoPropertiesKHR *qf_vid, uint32_t num_qf, VkVideoCodecOperationFlagBitsKHR flags)
Definition: hwcontext_vulkan.c:1315
list
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 sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
Definition: filter_design.txt:25
VulkanFramesPriv
Definition: hwcontext_vulkan.c:140
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
FF_VK_EXT_NO_FLAG
#define FF_VK_EXT_NO_FLAG
Definition: vulkan_functions.h:66
vulkan_transfer_data_from
static int vulkan_transfer_data_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_vulkan.c:4325
flag
#define flag(name)
Definition: cbs_av1.c:474
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
vulkan_frames_init
static int vulkan_frames_init(AVHWFramesContext *hwfc)
Definition: hwcontext_vulkan.c:2637
vulkan_get_buffer
static int vulkan_get_buffer(AVHWFramesContext *hwfc, AVFrame *frame)
Definition: hwcontext_vulkan.c:2796
pick_queue_family
static int pick_queue_family(VkQueueFamilyProperties2 *qf, uint32_t num_qf, VkQueueFlagBits flags)
Definition: hwcontext_vulkan.c:1286
vulkan_device_create
static int vulkan_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
Definition: hwcontext_vulkan.c:1884
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVVulkanDeviceQueueFamily
Definition: hwcontext_vulkan.h:33
src
#define src
Definition: vp8dsp.c:248