FFmpeg
Loading...
Searching...
No Matches
vulkan_video.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 AVCODEC_VULKAN_VIDEO_H
20#define AVCODEC_VULKAN_VIDEO_H
21
22#include "avcodec.h"
23#include "libavutil/refstruct.h"
24#include "libavutil/vulkan.h"
25
26#include <vk_video/vulkan_video_codecs_common.h>
27
28#define CODEC_VER_MAJ(ver) (ver >> 22)
29#define CODEC_VER_MIN(ver) ((ver >> 12) & ((1 << 10) - 1))
30#define CODEC_VER_PAT(ver) (ver & ((1 << 12) - 1))
31#define CODEC_VER(ver) CODEC_VER_MAJ(ver), CODEC_VER_MIN(ver), CODEC_VER_PAT(ver)
32
33/* DEDICATED-mode queue-exclusive DPB image */
34typedef struct FFVkVideoDPBImage {
35 VkImage img;
36 VkDeviceMemory mem;
37 VkImageView view;
38 VkImageAspectFlags aspect;
39 VkImageLayout layout;
41
42/* Internal DPB image pool; av_refstruct_pool_get()/av_refstruct_unref() */
43typedef struct FFVkVideoDPB {
44 /* Creation only; destruction uses the stashed handles below, as the
45 * pool may outlive the context */
47
48 AVRefStructPool *img_pool; /* FFVkVideoDPBImage entries */
49
50 VkDevice dev;
51 const VkAllocationCallbacks *alloc;
52 PFN_vkDestroyImageView destroy_image_view;
53 PFN_vkDestroyImage destroy_image;
54 PFN_vkFreeMemory free_memory;
55
57 VkImageUsageFlags usage;
58 VkImageTiling tiling;
62
63typedef struct FFVkVideoSession {
64 VkVideoSessionKHR session;
65 VkDeviceMemory *mem;
66 uint32_t nb_mem;
67
71 VkImageView layered_view;
72 VkImageAspectFlags layered_aspect;
74
75/**
76 * Get pixfmt from a Vulkan format.
77 */
79
80/**
81 * Get aspect bits which include all planes from a VkFormat.
82 */
83VkImageAspectFlags ff_vk_aspect_bits_from_vkfmt(VkFormat vkf);
84
85/**
86 * Get Vulkan's chroma subsampling from a pixfmt descriptor.
87 */
88VkVideoChromaSubsamplingFlagBitsKHR ff_vk_subsampling_from_av_desc(const AVPixFmtDescriptor *desc);
89
90/**
91 * Get Vulkan's bit depth from an [8:12] integer.
92 */
93VkVideoComponentBitDepthFlagBitsKHR ff_vk_depth_from_av_depth(int depth);
94
95/**
96 * Convert level from Vulkan to AV.
97 */
98int ff_vk_h264_level_to_av(StdVideoH264LevelIdc level);
99int ff_vk_h265_level_to_av(StdVideoH265LevelIdc level);
100
101StdVideoH264LevelIdc ff_vk_h264_level_to_vk(int level_idc);
102StdVideoH265LevelIdc ff_vk_h265_level_to_vk(int level_idc);
103StdVideoAV1Level ff_vk_av1_level_to_vk(int level);
104
105/**
106 * Convert profile from/to AV to Vulkan
107 */
108StdVideoH264ProfileIdc ff_vk_h264_profile_to_vk(int profile);
109StdVideoH265ProfileIdc ff_vk_h265_profile_to_vk(int profile);
110StdVideoAV1Profile ff_vk_av1_profile_to_vk(int profile);
111
112/**
113 * Creates image views for video frames.
114 */
115int ff_vk_create_view(FFVulkanContext *s, VkImageView *view,
116 VkImageAspectFlags *aspect, VkImage img,
117 VkFormat vkf, VkImageUsageFlags usage, int layered);
118
119/**
120 * Initialize the internal DPB image pool.
121 */
123 VkFormat format, VkImageUsageFlags usage,
124 VkImageTiling tiling, void *create_pnext,
125 int width, int height, int nb_layers);
126
127/**
128 * Initialize video session, allocating and binding necessary memory.
129 */
131 FFVkVideoCommon *common,
132 VkVideoSessionCreateInfoKHR *session_create);
133
134/**
135 * Free video session and required resources.
136 */
138
139/**
140 * Packs fixed-stride segment slots back to back into a contiguous buffer.
141 */
143 FFVulkanShader *shd);
144
145/**
146 * Gathers nb_segs slots of slot_size bytes from sparse into compacted, with
147 * the segment sizes given as nb_segs uint32_t in sizes at sizes_offset,
148 * followed by one more that receives the packed size. Both are made visible
149 * to the host. If offset_addr is non-zero, the uint32_t it points to is added
150 * to compacted_offset.
151 */
153 FFVkBuffer *sizes, size_t sizes_offset, uint32_t nb_segs,
154 FFVkBuffer *sparse, uint32_t slot_size,
155 FFVkBuffer *compacted, size_t compacted_offset,
156 VkDeviceAddress offset_addr);
157
158/**
159 * Frame loop for compute encoders. Keeps up to pool_size frames in flight,
160 * submitting each into its own execution context, and returns their packets
161 * in order as soon as they complete, or once the pool is full.
162 */
180
183 int (*get_packet)(AVCodecContext *avctx, FFVkExecContext *exec, AVPacket *pkt));
184
185/**
186 * Call from FFCodec.cb.receive_packet; the packet metadata is carried from
187 * the submitted frame to its packet.
188 */
190 AVPacket *pkt);
191
192/**
193 * Waits for and discards every frame in flight.
194 */
196
198
199#endif /* AVCODEC_VULKAN_VIDEO_H */
static const char *const format[]
Definition af_aiir.c:445
static int frames
static int submit_frame(AVCodecContext *avctx, FFVkExecContext *exec, AVFrame *frame)
Libavcodec external API header.
#define s(width, name)
Definition cbs_vp9.c:198
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
static AVFrame * frame
static int get_packet(AVCodecContext *avctx, FFVkExecContext *exec, AVPacket *pkt)
const char * usage
enum VkFormat VkFormat
static const int sizes[][2]
Definition img2dec.c:62
const char * desc
Definition libsvtav1.c:83
int profile
Definition mxfenc.c:2299
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
A reference to a data buffer.
Definition buffer.h:82
main external API structure.
Definition avcodec.h:443
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
This structure stores compressed data.
Definition packet.h:580
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition refstruct.c:184
Frame loop for compute encoders.
int(* get_packet)(AVCodecContext *avctx, FFVkExecContext *exec, AVPacket *pkt)
AVBufferRef * opaque_ref
FFVkExecPool * pool
int(* submit_frame)(AVCodecContext *avctx, FFVkExecContext *exec, AVFrame *frame)
AVFrame * frame
FFVulkanContext * s
AVPacket * pkt
VkImageAspectFlags layered_aspect
VkDeviceMemory * mem
VkVideoSessionKHR session
FFVkVideoDPBImage * layered_img
FFVkVideoDPB * dpb
VkImageView layered_view
VkDeviceMemory mem
VkImageLayout layout
VkImageAspectFlags aspect
VkImageView view
AVRefStructPool * img_pool
FFVulkanContext * s
PFN_vkDestroyImage destroy_image
VkDevice dev
VkImageTiling tiling
VkFormat format
PFN_vkFreeMemory free_memory
const VkAllocationCallbacks * alloc
void * create_pnext
PFN_vkDestroyImageView destroy_image_view
VkImageUsageFlags usage
uint8_t level
Definition svq3.c:208
int level_idc
Definition h264_levels.c:29
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
#define img
void ff_vk_video_common_uninit(FFVulkanContext *s, FFVkVideoCommon *common)
Free video session and required resources.
VkVideoComponentBitDepthFlagBitsKHR ff_vk_depth_from_av_depth(int depth)
Get Vulkan's bit depth from an [8:12] integer.
int ff_vk_encode_loop_receive_packet(AVCodecContext *avctx, FFVkEncodeLoop *l, AVPacket *pkt)
Call from FFCodec.cb.receive_packet; the packet metadata is carried from the submitted frame to its p...
VkVideoChromaSubsamplingFlagBitsKHR ff_vk_subsampling_from_av_desc(const AVPixFmtDescriptor *desc)
Get Vulkan's chroma subsampling from a pixfmt descriptor.
int ff_vk_seg_gather_init(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Packs fixed-stride segment slots back to back into a contiguous buffer.
int ff_vk_h265_level_to_av(StdVideoH265LevelIdc level)
int ff_vk_create_view(FFVulkanContext *s, VkImageView *view, VkImageAspectFlags *aspect, VkImage img, VkFormat vkf, VkImageUsageFlags usage, int layered)
Creates image views for video frames.
StdVideoH265ProfileIdc ff_vk_h265_profile_to_vk(int profile)
int ff_vk_h264_level_to_av(StdVideoH264LevelIdc level)
Convert level from Vulkan to AV.
StdVideoH265LevelIdc ff_vk_h265_level_to_vk(int level_idc)
StdVideoAV1Profile ff_vk_av1_profile_to_vk(int profile)
void ff_vk_encode_loop_uninit(FFVkEncodeLoop *l)
enum AVPixelFormat ff_vk_pix_fmt_from_vkfmt(VkFormat vkf)
Get pixfmt from a Vulkan format.
int ff_vk_video_common_init(AVCodecContext *avctx, FFVulkanContext *s, FFVkVideoCommon *common, VkVideoSessionCreateInfoKHR *session_create)
Initialize video session, allocating and binding necessary memory.
int ff_vk_seg_gather(FFVulkanContext *s, FFVkExecContext *exec, FFVulkanShader *shd, FFVkBuffer *sizes, size_t sizes_offset, uint32_t nb_segs, FFVkBuffer *sparse, uint32_t slot_size, FFVkBuffer *compacted, size_t compacted_offset, VkDeviceAddress offset_addr)
Gathers nb_segs slots of slot_size bytes from sparse into compacted, with the segment sizes given as ...
StdVideoH264LevelIdc ff_vk_h264_level_to_vk(int level_idc)
void ff_vk_encode_loop_flush(AVCodecContext *avctx, FFVkEncodeLoop *l)
Waits for and discards every frame in flight.
StdVideoH264ProfileIdc ff_vk_h264_profile_to_vk(int profile)
Convert profile from/to AV to Vulkan.
VkImageAspectFlags ff_vk_aspect_bits_from_vkfmt(VkFormat vkf)
Get aspect bits which include all planes from a VkFormat.
int ff_vk_encode_loop_init(FFVulkanContext *s, FFVkExecPool *pool, FFVkEncodeLoop *l, int(*submit_frame)(AVCodecContext *avctx, FFVkExecContext *exec, AVFrame *frame), int(*get_packet)(AVCodecContext *avctx, FFVkExecContext *exec, AVPacket *pkt))
StdVideoAV1Level ff_vk_av1_level_to_vk(int level)
int ff_vk_video_dpb_init(FFVulkanContext *s, FFVkVideoCommon *common, VkFormat format, VkImageUsageFlags usage, VkImageTiling tiling, void *create_pnext, int width, int height, int nb_layers)
Initialize the internal DPB image pool.