FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
vulkan_decode.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_DECODE_H
20 #define AVCODEC_VULKAN_DECODE_H
21 
22 #include "codec_id.h"
23 #include "decode.h"
24 #include "hwaccel_internal.h"
25 #include "internal.h"
26 
27 #include "vulkan_video.h"
28 
29 typedef struct FFVulkanDecodeDescriptor {
32  VkQueueFlagBits queue_flags;
33  VkVideoCodecOperationFlagBitsKHR decode_op;
34 
35  VkExtensionProperties ext_props;
37 
38 typedef struct FFVulkanDecodeShared {
40  FFVkVideoCommon common;
43 
45 
46  VkVideoCapabilitiesKHR caps;
47  VkVideoDecodeCapabilitiesKHR dec_caps;
48 
49  VkVideoSessionParametersKHR empty_session_params;
50 
51  /* Software-defined decoder context */
52  void *sd_ctx;
55 
56 typedef struct FFVulkanDecodeContext {
59 
60  int dedicated_dpb; /* Oddity #1 - separate DPB images */
61  int external_fg; /* Oddity #2 - hardware can't apply film grain */
62 
63  /* Workaround for NVIDIA drivers tested with CTS version 1.3.8 for AV1.
64  * The tests were incorrect as the OrderHints were offset by 1. */
66 
67  /* Thread-local state below */
70 
71  uint32_t *slice_off;
72  unsigned int slice_off_max;
74 
75 typedef struct FFVulkanDecodePicture {
76  AVFrame *dpb_frame; /* Only used for out-of-place decoding. */
77 
78  struct {
79  VkImageView ref[AV_NUM_DATA_POINTERS]; /* Image representation view (reference) */
80  VkImageView out[AV_NUM_DATA_POINTERS]; /* Image representation view (output-only) */
81  VkImageView dst[AV_NUM_DATA_POINTERS]; /* Set to img_view_out if no layered refs are used */
82  VkImageAspectFlags aspect[AV_NUM_DATA_POINTERS]; /* Image plane mask bits */
83  VkImageAspectFlags aspect_ref[AV_NUM_DATA_POINTERS]; /* Only used for out-of-place decoding */
84  } view;
85 
86  VkSemaphore sem;
87  uint64_t sem_value;
88 
89  /* Current picture */
90  VkVideoPictureResourceInfoKHR ref;
91  VkVideoReferenceSlotInfoKHR ref_slot;
92 
93  /* Picture refs. H264 has the maximum number of refs (36) of any supported codec. */
94  VkVideoPictureResourceInfoKHR refs [36];
95  VkVideoReferenceSlotInfoKHR ref_slots[36];
96 
97  /* Main decoding struct */
98  VkVideoDecodeInfoKHR decode_info;
99 
100  /* Slice data */
102  size_t slices_size;
103 
104  /* Vulkan functions needed for destruction, as no other context is guaranteed to exist */
105  PFN_vkWaitSemaphores wait_semaphores;
106  PFN_vkDestroyImageView destroy_image_view;
107  PFN_vkInvalidateMappedMemoryRanges invalidate_memory_ranges;
109 
110 /**
111  * Initialize decoder.
112  */
114 
115 /**
116  * Synchronize the contexts between 2 threads.
117  */
119 
120 /**
121  * Initialize hw_frames_ctx with the parameters needed to decode the stream
122  * using the parameters from avctx.
123  *
124  * NOTE: if avctx->internal->hwaccel_priv_data exists, will partially initialize
125  * the context.
126  */
127 int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx);
128 
129 /**
130  * Removes current session parameters to recreate them
131  */
132 int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s);
133 
134 /**
135  * Prepare a frame, creates the image view, and sets up the dpb fields.
136  */
138  FFVulkanDecodePicture *vkpic, int is_current,
139  int alloc_dpb);
140 
141 /**
142  * Software-defined decoder version of ff_vk_decode_prepare_frame.
143  */
145  FFVulkanDecodePicture *vkpic, int is_current,
146  enum FFVkShaderRepFormat rep_fmt, int alloc_dpb);
147 
148 /**
149  * Add slice data to frame.
150  */
152  const uint8_t *data, size_t size, int add_startcode,
153  uint32_t *nb_slices, const uint32_t **offsets);
154 
155 /**
156  * Decode a frame.
157  */
159  AVFrame *pic, FFVulkanDecodePicture *vp,
160  AVFrame *rpic[], FFVulkanDecodePicture *rvkp[]);
161 
162 /**
163  * Free a frame and its state.
164  */
166 
167 /**
168  * Get an FFVkBuffer suitable for decoding from.
169  */
171  void *create_pNext, size_t size);
172 
173 /**
174  * Create VkVideoSessionParametersKHR wrapped in an AVBufferRef.
175  */
176 int ff_vk_decode_create_params(AVBufferRef **par_ref, void *logctx, FFVulkanDecodeShared *ctx,
177  const VkVideoSessionParametersCreateInfoKHR *session_params_create);
178 
179 /**
180  * Flush decoder.
181  */
183 
184 /**
185  * Free decoder.
186  */
188 
189 #endif /* AVCODEC_VULKAN_DECODE_H */
FFVulkanDecodePicture::slices_size
size_t slices_size
Definition: vulkan_decode.h:102
FFVulkanDecodeShared::s
FFVulkanContext s
Definition: vulkan_decode.h:39
FFVulkanExtensions
uint64_t FFVulkanExtensions
Definition: vulkan_functions.h:29
AVBufferPool
The buffer pool.
Definition: buffer_internal.h:88
FFVulkanDecodeContext::shared_ctx
FFVulkanDecodeShared * shared_ctx
Definition: vulkan_decode.h:57
ff_vk_decode_uninit
int ff_vk_decode_uninit(AVCodecContext *avctx)
Free decoder.
Definition: vulkan_decode.c:1191
FFVulkanDecodeShared::sd_ctx_free
void(* sd_ctx_free)(struct FFVulkanDecodeShared *ctx)
Definition: vulkan_decode.h:53
FFVulkanDecodeContext::hevc_headers_size
size_t hevc_headers_size
Definition: vulkan_decode.h:69
FFVulkanDecodeShared::common
FFVkVideoCommon common
Definition: vulkan_decode.h:40
FFVulkanDecodePicture::invalidate_memory_ranges
PFN_vkInvalidateMappedMemoryRanges invalidate_memory_ranges
Definition: vulkan_decode.h:107
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:421
internal.h
FFVulkanDecodeShared::buf_pool
AVBufferPool * buf_pool
Definition: vulkan_decode.h:44
b
#define b
Definition: input.c:42
data
const char data[16]
Definition: mxf.c:149
FFVulkanDecodeDescriptor::codec_id
enum AVCodecID codec_id
Definition: vulkan_decode.h:30
FFVulkanDecodePicture::view
struct FFVulkanDecodePicture::@319 view
FFVulkanDecodePicture::dst
VkImageView dst[AV_NUM_DATA_POINTERS]
Definition: vulkan_decode.h:81
ff_vk_get_decode_buffer
int ff_vk_get_decode_buffer(FFVulkanDecodeContext *ctx, AVBufferRef **buf, void *create_pNext, size_t size)
Get an FFVkBuffer suitable for decoding from.
ff_vk_decode_add_slice
int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp, const uint8_t *data, size_t size, int add_startcode, uint32_t *nb_slices, const uint32_t **offsets)
Add slice data to frame.
Definition: vulkan_decode.c:280
FFVulkanDecodeContext
Definition: vulkan_decode.h:56
FFVulkanDecodePicture::ref
VkVideoPictureResourceInfoKHR ref
Definition: vulkan_decode.h:90
FFVkShaderRepFormat
FFVkShaderRepFormat
Returns the format to use for images in shaders.
Definition: vulkan.h:404
FFVulkanDecodeContext::session_params
AVBufferRef * session_params
Definition: vulkan_decode.h:58
ff_vk_decode_create_params
int ff_vk_decode_create_params(AVBufferRef **par_ref, void *logctx, FFVulkanDecodeShared *ctx, const VkVideoSessionParametersCreateInfoKHR *session_params_create)
Create VkVideoSessionParametersKHR wrapped in an AVBufferRef.
Definition: vulkan_decode.c:1162
FFVulkanDecodeDescriptor::decode_op
VkVideoCodecOperationFlagBitsKHR decode_op
Definition: vulkan_decode.h:33
FFVulkanDecodePicture::sem_value
uint64_t sem_value
Definition: vulkan_decode.h:87
FFVulkanDecodeShared
Definition: vulkan_decode.h:38
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:63
FFVulkanDecodeContext::slice_off
uint32_t * slice_off
Definition: vulkan_decode.h:71
codec_id.h
FFVulkanDecodePicture::refs
VkVideoPictureResourceInfoKHR refs[36]
Definition: vulkan_decode.h:94
FFVulkanDecodePicture::wait_semaphores
PFN_vkWaitSemaphores wait_semaphores
Definition: vulkan_decode.h:105
s
#define s(width, name)
Definition: cbs_vp9.c:198
FFVulkanDecodePicture
Definition: vulkan_decode.h:75
offsets
static const int offsets[]
Definition: hevc_pel.c:34
ctx
AVFormatContext * ctx
Definition: movenc.c:49
decode.h
ff_vk_params_invalidate
int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s)
Removes current session parameters to recreate them.
Definition: vulkan_decode.c:138
ff_vk_update_thread_context
int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Synchronize the contexts between 2 threads.
Definition: vulkan_decode.c:120
hwaccel_internal.h
FFVulkanDecodeDescriptor::decode_extension
FFVulkanExtensions decode_extension
Definition: vulkan_decode.h:31
ff_vk_decode_free_frame
void ff_vk_decode_free_frame(AVHWDeviceContext *dev_ctx, FFVulkanDecodePicture *vp)
Free a frame and its state.
Definition: vulkan_decode.c:603
FFVulkanDecodePicture::aspect
VkImageAspectFlags aspect[AV_NUM_DATA_POINTERS]
Definition: vulkan_decode.h:82
FFVulkanDecodePicture::aspect_ref
VkImageAspectFlags aspect_ref[AV_NUM_DATA_POINTERS]
Definition: vulkan_decode.h:83
ff_vk_decode_frame
int ff_vk_decode_frame(AVCodecContext *avctx, AVFrame *pic, FFVulkanDecodePicture *vp, AVFrame *rpic[], FFVulkanDecodePicture *rvkp[])
Decode a frame.
Definition: vulkan_decode.c:397
FFVulkanContext
Definition: vulkan.h:274
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
FFVulkanDecodeShared::caps
VkVideoCapabilitiesKHR caps
Definition: vulkan_decode.h:46
FFVulkanDecodePicture::ref
VkImageView ref[AV_NUM_DATA_POINTERS]
Definition: vulkan_decode.h:79
size
int size
Definition: twinvq_data.h:10344
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:422
FFVulkanDecodeShared::sd_ctx
void * sd_ctx
Definition: vulkan_decode.h:52
FFVulkanDecodeShared::empty_session_params
VkVideoSessionParametersKHR empty_session_params
Definition: vulkan_decode.h:49
FFVulkanDecodeShared::qf
AVVulkanDeviceQueueFamily * qf
Definition: vulkan_decode.h:41
FFVulkanDecodeContext::slice_off_max
unsigned int slice_off_max
Definition: vulkan_decode.h:72
HEVCHeaderSet
Definition: vulkan_hevc.c:67
ff_vk_frame_params
int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Initialize hw_frames_ctx with the parameters needed to decode the stream using the parameters from av...
Definition: vulkan_decode.c:1075
FFVulkanDecodePicture::out
VkImageView out[AV_NUM_DATA_POINTERS]
Definition: vulkan_decode.h:80
FFVulkanDecodeDescriptor::ext_props
VkExtensionProperties ext_props
Definition: vulkan_decode.h:35
FFVulkanDecodePicture::ref_slot
VkVideoReferenceSlotInfoKHR ref_slot
Definition: vulkan_decode.h:91
FFVulkanDecodePicture::sem
VkSemaphore sem
Definition: vulkan_decode.h:86
FFVulkanDecodeContext::external_fg
int external_fg
Definition: vulkan_decode.h:61
FFVulkanDecodePicture::ref_slots
VkVideoReferenceSlotInfoKHR ref_slots[36]
Definition: vulkan_decode.h:95
FFVkExecPool
Definition: vulkan.h:252
FFVulkanDecodeContext::hevc_headers
struct HEVCHeaderSet * hevc_headers
Definition: vulkan_decode.h:68
ff_vk_decode_prepare_frame
int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic, FFVulkanDecodePicture *vkpic, int is_current, int alloc_dpb)
Prepare a frame, creates the image view, and sets up the dpb fields.
Definition: vulkan_decode.c:176
AVCodecContext
main external API structure.
Definition: avcodec.h:431
FFVulkanDecodeContext::dedicated_dpb
int dedicated_dpb
Definition: vulkan_decode.h:60
FFVulkanDecodeDescriptor
Definition: vulkan_decode.h:29
ff_vk_decode_prepare_frame_sdr
int ff_vk_decode_prepare_frame_sdr(FFVulkanDecodeContext *dec, AVFrame *pic, FFVulkanDecodePicture *vkpic, int is_current, enum FFVkShaderRepFormat rep_fmt, int alloc_dpb)
Software-defined decoder version of ff_vk_decode_prepare_frame.
Definition: vulkan_decode.c:233
FFVulkanDecodePicture::dpb_frame
AVFrame * dpb_frame
Definition: vulkan_decode.h:76
vulkan_video.h
FFVulkanDecodePicture::slices_buf
AVBufferRef * slices_buf
Definition: vulkan_decode.h:101
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
FFVulkanDecodeDescriptor::queue_flags
VkQueueFlagBits queue_flags
Definition: vulkan_decode.h:32
ff_vk_decode_init
int ff_vk_decode_init(AVCodecContext *avctx)
Initialize decoder.
Definition: vulkan_decode.c:1243
ff_vk_decode_flush
void ff_vk_decode_flush(AVCodecContext *avctx)
Flush decoder.
Definition: vulkan_decode.c:361
FFVulkanDecodePicture::destroy_image_view
PFN_vkDestroyImageView destroy_image_view
Definition: vulkan_decode.h:106
AVVulkanDeviceQueueFamily
Definition: hwcontext_vulkan.h:33
FFVulkanDecodePicture::decode_info
VkVideoDecodeInfoKHR decode_info
Definition: vulkan_decode.h:98
FFVulkanDecodeContext::quirk_av1_offset
int quirk_av1_offset
Definition: vulkan_decode.h:65
src
#define src
Definition: vp8dsp.c:248
FFVulkanDecodeShared::dec_caps
VkVideoDecodeCapabilitiesKHR dec_caps
Definition: vulkan_decode.h:47
FFVulkanDecodeShared::exec_pool
FFVkExecPool exec_pool
Definition: vulkan_decode.h:42