FFmpeg
vulkan_prores.c
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 #include "proresdec.h"
20 #include "vulkan_decode.h"
21 #include "hwaccel_internal.h"
22 #include "libavutil/mem.h"
23 #include "libavutil/vulkan.h"
24 
25 extern const unsigned char ff_prores_vld_comp_spv_data[];
26 extern const unsigned int ff_prores_vld_comp_spv_len;
27 
28 extern const unsigned char ff_prores_idct_comp_spv_data[];
29 extern const unsigned int ff_prores_idct_comp_spv_len;
30 
33  .queue_flags = VK_QUEUE_COMPUTE_BIT,
34 };
35 
36 typedef struct ProresVulkanDecodePicture {
38 
40 
41  uint32_t bitstream_start;
42  uint32_t bitstream_size;
43  uint32_t slice_num;
44 
48 
49 typedef struct ProresVulkanDecodeContext {
52 
55 
56 typedef struct ProresVkParameters {
57  VkDeviceAddress slice_data;
58  uint32_t bitstream_size;
59 
60  uint16_t width;
61  uint16_t height;
62  uint16_t mb_width;
63  uint16_t mb_height;
64  uint16_t slice_width;
65  uint16_t slice_height;
67  uint8_t log2_chroma_w;
68  uint8_t depth;
69  uint8_t alpha_info;
70  uint8_t bottom_field;
72 
74  const AVBufferRef *buffer_ref,
75  av_unused const uint8_t *buffer,
76  av_unused uint32_t size)
77 {
78  ProresContext *pr = avctx->priv_data;
81  ProresVulkanDecodeContext *pv = ctx->sd_ctx;
83  FFVulkanDecodePicture *vp = &pp->vp;
84 
85  int err;
86 
87  pp->slice_offsets_sz = (pr->slice_count + 1) * sizeof(uint32_t);
88  pp->qmat_sz = sizeof(pr->qmat_luma) + sizeof(pr->qmat_chroma);
89  pp->mb_params_sz = pr->mb_width * pr->mb_height * sizeof(uint8_t);
90 
91  pp->slice_offsets_off = 0;
93  ctx->s.props.properties.limits.minStorageBufferOffsetAlignment);
94  pp->mb_params_off = FFALIGN(pp->qmat_off + pp->qmat_sz,
95  ctx->s.props.properties.limits.minStorageBufferOffsetAlignment);
96 
97  /* Host map the input slices data if supported */
98  if (!vp->slices_buf && ctx->s.extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY)
99  RET(ff_vk_host_map_buffer(&ctx->s, &vp->slices_buf, buffer_ref->data,
100  buffer_ref,
101  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
102  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT));
103 
104  /* Allocate metadata buffer */
106  &pp->metadata_buf,
107  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
108  NULL, pp->mb_params_off + pp->mb_params_sz,
109  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
110  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
111 
112  pp->slice_num = 0;
113  pp->bitstream_start = pp->bitstream_size = 0;
114 
115 fail:
116  return err;
117 }
118 
120  const uint8_t *data,
121  uint32_t size)
122 {
123  ProresContext *pr = avctx->priv_data;
125  FFVulkanDecodePicture *vp = &pp->vp;
126 
127  FFVkBuffer *slice_offset = (FFVkBuffer *)pp->metadata_buf->data;
128  FFVkBuffer *slices_buf = vp->slices_buf ? (FFVkBuffer *)vp->slices_buf->data : NULL;
129 
130  /* Skip picture header */
131  if (slices_buf && slices_buf->host_ref && !pp->slice_num)
132  pp->bitstream_size = data - slices_buf->mapped_mem;
133 
134  AV_WN32(slice_offset->mapped_mem + (pp->slice_num + 0) * sizeof(uint32_t),
135  pp->bitstream_size);
136  AV_WN32(slice_offset->mapped_mem + (pp->slice_num + 1) * sizeof(uint32_t),
137  pp->bitstream_size += size);
138 
139  if (!slices_buf || !slices_buf->host_ref) {
140  int err = ff_vk_decode_add_slice(avctx, vp, data, size, 0,
141  &pp->slice_num, NULL);
142  if (err < 0)
143  return err;
144  } else {
145  pp->slice_num++;
146  }
147 
148  return 0;
149 }
150 
152 {
153  ProresContext *pr = avctx->priv_data;
156  FFVulkanFunctions *vk = &ctx->s.vkfn;
157  ProresVulkanDecodeContext *pv = ctx->sd_ctx;
159  FFVulkanDecodePicture *vp = &pp->vp;
160  AVFrame *f = pr->frame;
161  AVVkFrame *vkf = (AVVkFrame *)f->data[0];
162 
164  FFVkBuffer *slice_data, *metadata;
165  VkImageMemoryBarrier2 img_bar[AV_NUM_DATA_POINTERS];
166  VkBufferMemoryBarrier2 buf_bar[2];
167  int nb_img_bar = 0, nb_buf_bar = 0, nb_imgs, i, err;
168  const AVPixFmtDescriptor *pix_desc;
169 
170  if (!pp->slice_num)
171  return 0;
172 
173  pix_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
174  if (!pix_desc)
175  return AVERROR(EINVAL);
176 
177  slice_data = (FFVkBuffer *)vp->slices_buf->data;
179 
180  pd = (ProresVkParameters) {
181  .slice_data = slice_data->address,
182  .bitstream_size = pp->bitstream_size,
183 
184  .width = avctx->width,
185  .height = avctx->height,
186  .mb_width = pr->mb_width,
187  .mb_height = pr->mb_height,
188  .slice_width = pr->slice_count / pr->mb_height,
189  .slice_height = pr->mb_height,
190  .log2_slice_width = av_log2(pr->slice_mb_width),
191  .log2_chroma_w = pix_desc->log2_chroma_w,
192  .depth = avctx->bits_per_raw_sample,
193  .alpha_info = pr->alpha_info,
194  .bottom_field = pr->first_field ^ (pr->frame_type == 1),
195  };
196 
197  memcpy(metadata->mapped_mem + pp->qmat_off,
198  pr->qmat_luma, sizeof(pr->qmat_luma));
199  memcpy(metadata->mapped_mem + pp->qmat_off + sizeof(pr->qmat_luma),
200  pr->qmat_chroma, sizeof(pr->qmat_chroma));
201 
202  FFVkExecContext *exec = ff_vk_exec_get(&ctx->s, &ctx->exec_pool);
203  RET(ff_vk_exec_start(&ctx->s, exec));
204 
205  /* Prepare deps */
206  RET(ff_vk_exec_add_dep_frame(&ctx->s, exec, f,
207  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
208  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
209 
210  /* Exec-owned output views: freed on exec recycle, so releasing a picture
211  * needs no blocking wait. No mirror_sem: nothing consumes vp->sem here. */
212  VkImageView views[AV_NUM_DATA_POINTERS];
213  RET(ff_vk_create_imageviews(&ctx->s, exec, views, f, FF_VK_REP_NATIVE));
214 
215  /* Transfer ownership to the exec context */
216  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &vp->slices_buf, 1, 0));
217  vp->slices_buf = NULL;
218  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &pp->metadata_buf, 1, 0));
219  pp->metadata_buf = NULL;
220 
221  vkf->layout[0] = VK_IMAGE_LAYOUT_UNDEFINED;
222  vkf->access[0] = VK_ACCESS_2_NONE;
223 
224  nb_imgs = ff_vk_count_images(vkf);
225 
226  if (pr->first_field) {
227  /* Input barrier */
228  ff_vk_frame_barrier(&ctx->s, exec, f, img_bar, &nb_img_bar,
229  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
230  VK_PIPELINE_STAGE_2_CLEAR_BIT,
231  VK_ACCESS_2_TRANSFER_WRITE_BIT,
232  VK_IMAGE_LAYOUT_GENERAL,
233  VK_QUEUE_FAMILY_IGNORED);
234  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
235  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
236  .pBufferMemoryBarriers = buf_bar,
237  .bufferMemoryBarrierCount = nb_buf_bar,
238  .pImageMemoryBarriers = img_bar,
239  .imageMemoryBarrierCount = nb_img_bar,
240  });
241  nb_img_bar = nb_buf_bar = 0;
242 
243  /* Clear the input image since the vld shader does sparse writes, except for alpha */
244  for (i = 0; i < FFMIN(nb_imgs, 3); ++i) {
245  vk->CmdClearColorImage(exec->buf, vkf->img[i],
246  VK_IMAGE_LAYOUT_GENERAL,
247  &((VkClearColorValue) { 0 }),
248  1, &((VkImageSubresourceRange) {
249  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
250  .levelCount = 1,
251  .layerCount = 1,
252  }));
253  }
254  }
255 
256  /* Input barrier, or synchronization between clear and vld shader */
257  ff_vk_frame_barrier(&ctx->s, exec, f, img_bar, &nb_img_bar,
258  pr->first_field ? VK_PIPELINE_STAGE_2_CLEAR_BIT :
259  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
260  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
261  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
262  VK_IMAGE_LAYOUT_GENERAL,
263  VK_QUEUE_FAMILY_IGNORED);
264  ff_vk_buf_barrier(buf_bar[nb_buf_bar++], metadata,
265  ALL_COMMANDS_BIT, NONE_KHR, NONE_KHR,
266  COMPUTE_SHADER_BIT, SHADER_WRITE_BIT, NONE_KHR,
267  pp->slice_offsets_sz, pp->mb_params_sz);
268  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
269  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
270  .pBufferMemoryBarriers = buf_bar,
271  .bufferMemoryBarrierCount = nb_buf_bar,
272  .pImageMemoryBarriers = img_bar,
273  .imageMemoryBarrierCount = nb_img_bar,
274  });
275  nb_img_bar = nb_buf_bar = 0;
276 
277  /* Entropy decode */
278  ff_vk_shader_update_desc_buffer(&ctx->s, exec, &pv->vld,
279  0, 0, 0,
280  metadata,
281  pp->slice_offsets_off,
282  pp->slice_offsets_sz,
283  VK_FORMAT_UNDEFINED);
284  ff_vk_shader_update_desc_buffer(&ctx->s, exec, &pv->vld,
285  0, 1, 0,
286  metadata,
287  pp->mb_params_off,
288  pp->mb_params_sz,
289  VK_FORMAT_UNDEFINED);
290  ff_vk_shader_update_img_array(&ctx->s, exec, &pv->vld,
291  f, views,
292  0, 2,
293  VK_IMAGE_LAYOUT_GENERAL,
294  VK_NULL_HANDLE);
295 
296  ff_vk_exec_bind_shader(&ctx->s, exec, &pv->vld);
297  ff_vk_shader_update_push_const(&ctx->s, exec, &pv->vld,
298  VK_SHADER_STAGE_COMPUTE_BIT,
299  0, sizeof(pd), &pd);
300 
301  vk->CmdDispatch(exec->buf, AV_CEIL_RSHIFT(pr->slice_count / pr->mb_height, 3),
302  AV_CEIL_RSHIFT(pr->mb_height, 3),
303  3 + !!pr->alpha_info);
304 
305  /* Synchronize vld and idct shaders */
306  ff_vk_frame_barrier(&ctx->s, exec, f, img_bar, &nb_img_bar,
307  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
308  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
309  VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
310  VK_IMAGE_LAYOUT_GENERAL,
311  VK_QUEUE_FAMILY_IGNORED);
312  ff_vk_buf_barrier(buf_bar[nb_buf_bar++], metadata,
313  COMPUTE_SHADER_BIT, SHADER_WRITE_BIT, NONE_KHR,
314  COMPUTE_SHADER_BIT, SHADER_READ_BIT, NONE_KHR,
315  pp->slice_offsets_sz, pp->mb_params_sz);
316  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
317  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
318  .pBufferMemoryBarriers = buf_bar,
319  .bufferMemoryBarrierCount = nb_buf_bar,
320  .pImageMemoryBarriers = img_bar,
321  .imageMemoryBarrierCount = nb_img_bar,
322  });
323  nb_img_bar = nb_buf_bar = 0;
324 
325  /* Inverse transform */
326  ff_vk_shader_update_desc_buffer(&ctx->s, exec, &pv->idct,
327  0, 0, 0,
328  metadata,
329  pp->mb_params_off,
330  pp->mb_params_sz,
331  VK_FORMAT_UNDEFINED);
332  ff_vk_shader_update_desc_buffer(&ctx->s, exec, &pv->idct,
333  0, 1, 0,
334  metadata,
335  pp->qmat_off,
336  pp->qmat_sz,
337  VK_FORMAT_UNDEFINED);
338  ff_vk_shader_update_img_array(&ctx->s, exec, &pv->idct,
339  f, views,
340  0, 2,
341  VK_IMAGE_LAYOUT_GENERAL,
342  VK_NULL_HANDLE);
343 
344  ff_vk_exec_bind_shader(&ctx->s, exec, &pv->idct);
345  ff_vk_shader_update_push_const(&ctx->s, exec, &pv->idct,
346  VK_SHADER_STAGE_COMPUTE_BIT,
347  0, sizeof(pd), &pd);
348 
349  vk->CmdDispatch(exec->buf, AV_CEIL_RSHIFT(pr->mb_width, 1), pr->mb_height, 3);
350 
351  RET(ff_vk_exec_submit(&ctx->s, exec));
352 
353 fail:
354  return err;
355 }
356 
358  FFVkExecPool *pool, FFVulkanShader *shd,
359  int max_num_mbs, int interlaced)
360 {
361  int err;
362  AVHWFramesContext *dec_frames_ctx;
363  dec_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
364 
365  SPEC_LIST_CREATE(sl, 1, 1*sizeof(uint32_t))
366  SPEC_LIST_ADD(sl, 0, 32, interlaced);
367 
368  ff_vk_shader_load(shd,
369  VK_SHADER_STAGE_COMPUTE_BIT, sl,
370  (uint32_t []) { 8, 8, 1 }, 0);
371 
373  VK_SHADER_STAGE_COMPUTE_BIT);
374 
375  const FFVulkanDescriptorSetBinding desc_set[] = {
376  { /* slice_offsets_buf */
377  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
378  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
379  },
380  { /* quant_idx_buf */
381  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
382  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
383  },
384  { /* dst */
385  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
386  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
387  .elems = av_pix_fmt_count_planes(dec_frames_ctx->sw_format),
388  },
389  };
390  ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3, 0, 0);
391 
392  RET(ff_vk_shader_link(s, shd,
394  ff_prores_vld_comp_spv_len, "main"));
395 
396  RET(ff_vk_shader_register_exec(s, pool, shd));
397 
398 fail:
399  return 0;
400 }
401 
403  FFVkExecPool *pool, FFVulkanShader *shd,
404  int max_num_mbs, int interlaced)
405 {
406  int err;
407  AVHWFramesContext *dec_frames_ctx;
408  dec_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
409 
410  SPEC_LIST_CREATE(sl, 2 + 64, (2 + 64)*sizeof(uint32_t))
411  SPEC_LIST_ADD(sl, 0, 32, interlaced);
412  SPEC_LIST_ADD(sl, 16, 32, 4*2); /* nb_blocks */
413 
414  const double idct_8_scales[8] = {
415  cos(4.0*M_PI/16.0) / 2.0, cos(1.0*M_PI/16.0) / 2.0,
416  cos(2.0*M_PI/16.0) / 2.0, cos(3.0*M_PI/16.0) / 2.0,
417  cos(4.0*M_PI/16.0) / 2.0, cos(5.0*M_PI/16.0) / 2.0,
418  cos(6.0*M_PI/16.0) / 2.0, cos(7.0*M_PI/16.0) / 2.0,
419  };
420  for (int i = 0; i < 64; i++)
421  SPEC_LIST_ADD(sl, 18 + i, 32,
422  av_float2int(idct_8_scales[i >> 3]*idct_8_scales[i & 7]));
423 
424  ff_vk_shader_load(shd,
425  VK_SHADER_STAGE_COMPUTE_BIT, sl,
426  (uint32_t []) { 32, 2, 1 }, 0);
427 
429  VK_SHADER_STAGE_COMPUTE_BIT);
430 
431  const FFVulkanDescriptorSetBinding desc_set[] = {
432  { /* quant_idx_buf */
433  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
434  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
435  },
436  { /* qmat_buf */
437  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
438  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
439  },
440  { /* dst */
441  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
442  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
443  .elems = av_pix_fmt_count_planes(dec_frames_ctx->sw_format),
444  },
445  };
446  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3, 0, 0));
447 
448  RET(ff_vk_shader_link(s, shd,
450  ff_prores_idct_comp_spv_len, "main"));
451 
452  RET(ff_vk_shader_register_exec(s, pool, shd));
453 
454 fail:
455  return 0;
456 }
457 
459 {
460  ProresVulkanDecodeContext *pv = ctx->sd_ctx;
461 
462  ff_vk_shader_free(&ctx->s, &pv->vld);
463  ff_vk_shader_free(&ctx->s, &pv->idct);
464 
466 
467  av_freep(&pv);
468 }
469 
471 {
474  ProresContext *pr = avctx->priv_data;
475 
477  int max_num_mbs, err;
478 
479  max_num_mbs = (avctx->coded_width >> 4) * (avctx->coded_height >> 4);
480 
481  err = ff_vk_decode_init(avctx);
482  if (err < 0)
483  return err;
484  ctx = dec->shared_ctx;
485 
486  pv = ctx->sd_ctx = av_mallocz(sizeof(*pv));
487  if (!pv) {
488  err = AVERROR(ENOMEM);
489  goto fail;
490  }
491 
492  ctx->sd_ctx_free = vk_decode_prores_uninit;
493 
494  RET(init_decode_shader(avctx, &ctx->s, &ctx->exec_pool,
495  &pv->vld, max_num_mbs, pr->frame_type != 0));
496  RET(init_idct_shader(avctx, &ctx->s, &ctx->exec_pool,
497  &pv->idct, max_num_mbs, pr->frame_type != 0));
498 
499 fail:
500  return err;
501 }
502 
504 {
505  AVHWDeviceContext *dev_ctx = _hwctx.nc;
507 
508  ff_vk_decode_free_frame(dev_ctx, &pp->vp);
509 
511 }
512 
514  .p.name = "prores_vulkan",
515  .p.type = AVMEDIA_TYPE_VIDEO,
516  .p.id = AV_CODEC_ID_PRORES,
517  .p.pix_fmt = AV_PIX_FMT_VULKAN,
518  .start_frame = &vk_prores_start_frame,
519  .decode_slice = &vk_prores_decode_slice,
520  .end_frame = &vk_prores_end_frame,
521  .free_frame_priv = &vk_prores_free_frame_priv,
522  .frame_priv_data_size = sizeof(ProresVulkanDecodePicture),
526  .frame_params = &ff_vk_frame_params,
527  .priv_data_size = sizeof(FFVulkanDecodeContext),
529 };
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
ProresVkParameters::bottom_field
uint8_t bottom_field
Definition: vulkan_prores.c:70
ff_vk_shader_free
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition: vulkan.c:2853
AVBufferPool
The buffer pool.
Definition: buffer_internal.h:88
ProresContext::hwaccel_picture_private
void * hwaccel_picture_private
Definition: proresdec.h:47
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
FFVulkanDecodeContext::shared_ctx
FFVulkanDecodeShared * shared_ctx
Definition: vulkan_decode.h:55
RET
#define RET(x)
Definition: vulkan.h:68
ProresVulkanDecodePicture::slice_num
uint32_t slice_num
Definition: vulkan_prores.c:43
AVRefStructOpaque
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition: refstruct.h:58
ff_prores_idct_comp_spv_len
const unsigned int ff_prores_idct_comp_spv_len
ProresVkParameters::bitstream_size
uint32_t bitstream_size
Definition: vulkan_prores.c:58
AVRefStructOpaque::nc
void * nc
Definition: refstruct.h:59
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
vk_prores_free_frame_priv
static void vk_prores_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
Definition: vulkan_prores.c:503
ProresVkParameters::log2_slice_width
uint8_t log2_slice_width
Definition: vulkan_prores.c:66
data
const char data[16]
Definition: mxf.c:149
FFVulkanDecodeDescriptor::codec_id
enum AVCodecID codec_id
Definition: vulkan_decode.h:30
ProresContext
Definition: proresdec.h:43
vk_prores_end_frame
static int vk_prores_end_frame(AVCodecContext *avctx)
Definition: vulkan_prores.c:151
ProresVkParameters
Definition: vulkan_prores.c:56
ProresVulkanDecodeContext::vld
FFVulkanShader vld
Definition: vulkan_prores.c:50
ff_vk_exec_get
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition: vulkan.c:568
FF_VK_REP_NATIVE
@ FF_VK_REP_NATIVE
Definition: vulkan.h:449
SPEC_LIST_ADD
#define SPEC_LIST_ADD(name, idx, val_bits, val)
Definition: vulkan.h:86
av_float2int
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
Definition: intfloat.h:50
ff_vk_exec_bind_shader
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition: vulkan.c:2830
FFVulkanDecodeContext
Definition: vulkan_decode.h:54
ProresContext::slice_count
int slice_count
number of slices in the current picture
Definition: proresdec.h:52
ProresVulkanDecodePicture::mb_params_off
uint32_t mb_params_off
Definition: vulkan_prores.c:46
ProresVkParameters::alpha_info
uint8_t alpha_info
Definition: vulkan_prores.c:69
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
ff_vk_exec_add_dep_frame
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
Definition: vulkan.c:800
ProresContext::slice_mb_width
unsigned slice_mb_width
maximum width of a slice in mb
Definition: proresdec.h:55
ProresVkParameters::slice_height
uint16_t slice_height
Definition: vulkan_prores.c:65
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3496
FFHWAccel
Definition: hwaccel_internal.h:34
AVVkFrame::img
VkImage img[AV_NUM_DATA_POINTERS]
Vulkan images to which the memory is bound to.
Definition: hwcontext_vulkan.h:266
ff_prores_vld_comp_spv_data
const unsigned char ff_prores_vld_comp_spv_data[]
ff_vk_shader_update_img_array
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:2781
ProresVulkanDecodePicture::bitstream_start
uint32_t bitstream_start
Definition: vulkan_prores.c:41
ff_vk_frame_barrier
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:2093
HWACCEL_CAP_THREAD_SAFE
#define HWACCEL_CAP_THREAD_SAFE
Definition: hwaccel_internal.h:32
ff_vk_shader_register_exec
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
Definition: vulkan.c:2646
proresdec.h
ff_vk_host_map_buffer
int ff_vk_host_map_buffer(FFVulkanContext *s, AVBufferRef **dst, uint8_t *src_data, const AVBufferRef *src_buf, VkBufferUsageFlags usage)
Maps a system RAM buffer into a Vulkan buffer.
Definition: vulkan.c:1411
ProresVulkanDecodePicture
Definition: vulkan_prores.c:36
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:619
FFVulkanDecodeShared
Definition: vulkan_decode.h:38
ProresVulkanDecodeContext
Definition: vulkan_prores.c:49
av_unused
#define av_unused
Definition: attributes.h:164
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:63
FFVulkanDescriptorSetBinding::type
VkDescriptorType type
Definition: vulkan.h:114
ProresContext::first_field
int first_field
Definition: proresdec.h:60
vk_prores_start_frame
static int vk_prores_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition: vulkan_prores.c:73
FFVulkanDecodePicture
Definition: vulkan_decode.h:73
init_idct_shader
static int init_idct_shader(AVCodecContext *avctx, FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd, int max_num_mbs, int interlaced)
Definition: vulkan_prores.c:402
ProresVulkanDecodeContext::idct
FFVulkanShader idct
Definition: vulkan_prores.c:51
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
ProresContext::qmat_luma
uint8_t qmat_luma[64]
Definition: proresdec.h:49
ProresVkParameters::width
uint16_t width
Definition: vulkan_prores.c:60
ProresVkParameters::height
uint16_t height
Definition: vulkan_prores.c:61
vk_prores_decode_slice
static int vk_prores_decode_slice(AVCodecContext *avctx, const uint8_t *data, uint32_t size)
Definition: vulkan_prores.c:119
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1571
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
ff_vk_exec_add_dep_buf
int ff_vk_exec_add_dep_buf(FFVulkanContext *s, FFVkExecContext *e, AVBufferRef **deps, int nb_deps, int ref)
Execution dependency management.
Definition: vulkan.c:640
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
ProresVulkanDecodePicture::qmat_off
uint32_t qmat_off
Definition: vulkan_prores.c:46
if
if(ret)
Definition: filter_design.txt:179
fail
#define fail
Definition: test.h:478
vk_decode_prores_init
static int vk_decode_prores_init(AVCodecContext *avctx)
Definition: vulkan_prores.c:470
HWACCEL_CAP_ASYNC_SAFE
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
Definition: hwaccel_internal.h:31
ProresVulkanDecodePicture::mb_params_sz
uint32_t mb_params_sz
Definition: vulkan_prores.c:45
metadata
Stream codec metadata
Definition: ogg-flac-chained-meta.txt:2
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:213
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
hwaccel_internal.h
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:647
ProresVkParameters::mb_width
uint16_t mb_width
Definition: vulkan_prores.c:62
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:478
av_buffer_pool_uninit
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:328
ff_vk_decode_uninit
int ff_vk_decode_uninit(AVCodecContext *avctx)
Free decoder.
Definition: vulkan_decode.c:1253
ProresVulkanDecodePicture::bitstream_size
uint32_t bitstream_size
Definition: vulkan_prores.c:42
ff_vk_shader_link
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:2419
SPEC_LIST_CREATE
#define SPEC_LIST_CREATE(name, max_length, max_size)
Definition: vulkan.h:76
ff_prores_idct_comp_spv_data
const unsigned char ff_prores_idct_comp_spv_data[]
AVVkFrame::access
VkAccessFlagBits2 access[AV_NUM_DATA_POINTERS]
Updated after every barrier.
Definition: hwcontext_vulkan.h:290
FFVkBuffer::mapped_mem
uint8_t * mapped_mem
Definition: vulkan.h:134
FFVulkanContext
Definition: vulkan.h:312
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:1112
f
f
Definition: af_crystalizer.c:122
ff_vk_buf_barrier
#define ff_vk_buf_barrier(dst, vkb, s_stage, s_access, s_access2, d_stage, d_access, d_access2, offs, bsz)
Definition: vulkan.h:551
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:579
ff_vk_shader_update_push_const
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:2820
FFVulkanDescriptorSetBinding
Definition: vulkan.h:112
ProresVulkanDecodePicture::slice_offsets_sz
uint32_t slice_offsets_sz
Definition: vulkan_prores.c:45
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:372
AVCodecInternal::hwaccel_priv_data
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:130
AVVkFrame
Definition: hwcontext_vulkan.h:261
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
vulkan.h
size
int size
Definition: twinvq_data.h:10344
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:467
FFVulkanShader
Definition: vulkan.h:225
ProresVulkanDecodePicture::qmat_sz
uint32_t qmat_sz
Definition: vulkan_prores.c:45
FFVkExecContext
Definition: vulkan.h:145
ff_vk_shader_update_desc_buffer
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:2794
M_PI
#define M_PI
Definition: mathematics.h:67
ProresVkParameters::log2_chroma_w
uint8_t log2_chroma_w
Definition: vulkan_prores.c:67
ff_prores_vulkan_hwaccel
const FFHWAccel ff_prores_vulkan_hwaccel
Definition: vulkan_prores.c:513
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:1954
ProresContext::mb_width
unsigned mb_width
width of the current picture in mb
Definition: proresdec.h:53
FF_VK_EXT_EXTERNAL_HOST_MEMORY
#define FF_VK_EXT_EXTERNAL_HOST_MEMORY
Definition: vulkan_functions.h:36
interlaced
uint8_t interlaced
Definition: mxfenc.c:2336
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
ProresVkParameters::depth
uint8_t depth
Definition: vulkan_prores.c:68
ff_vk_exec_start
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition: vulkan.c:580
ff_prores_vld_comp_spv_len
const unsigned int ff_prores_vld_comp_spv_len
s
uint8_t s
Definition: llvidencdsp.c:39
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVCodecContext::height
int height
Definition: avcodec.h:604
AVCodecContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition: avcodec.h:1471
ProresVulkanDecodePicture::slice_offsets_off
uint32_t slice_offsets_off
Definition: vulkan_prores.c:46
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:118
ff_vk_dec_prores_desc
const FFVulkanDecodeDescriptor ff_vk_dec_prores_desc
Definition: vulkan_prores.c:31
ff_vk_create_imageviews
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:2010
FFVkExecPool
Definition: vulkan.h:290
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:258
ff_vk_shader_add_push_const
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
Definition: vulkan.c:1509
FFVkExecContext::buf
VkCommandBuffer buf
Definition: vulkan.h:156
ProresContext::frame_type
int frame_type
0 = progressive, 1 = tff, 2 = bff
Definition: proresdec.h:48
AVCodecContext
main external API structure.
Definition: avcodec.h:443
ff_vk_shader_add_descriptor_set
int ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, const FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a shader.
Definition: vulkan.c:2546
ProresContext::qmat_chroma
uint8_t qmat_chroma[64]
Definition: proresdec.h:50
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
update_thread_context
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have update_thread_context() run it in the next thread. Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little speed gain at this point but it should work. Use ff_thread_get_buffer()(or ff_progress_frame_get_buffer() in case you have inter-frame dependencies and use the ProgressFrame API) to allocate frame buffers. Call ff_progress_frame_report() after some part of the current picture has decoded. A good place to put this is where draw_horiz_band() is called - add this if it isn 't called anywhere
ProresVkParameters::slice_width
uint16_t slice_width
Definition: vulkan_prores.c:64
FFVulkanDecodeDescriptor
Definition: vulkan_decode.h:29
ProresVulkanDecodePicture::metadata_buf
AVBufferRef * metadata_buf
Definition: vulkan_prores.c:39
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:142
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:619
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
ProresVkParameters::mb_height
uint16_t mb_height
Definition: vulkan_prores.c:63
FFVulkanDecodePicture::slices_buf
AVBufferRef * slices_buf
Definition: vulkan_decode.h:99
mem.h
AVVkFrame::layout
VkImageLayout layout[AV_NUM_DATA_POINTERS]
Definition: hwcontext_vulkan.h:291
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
ProresVulkanDecodePicture::vp
FFVulkanDecodePicture vp
Definition: vulkan_prores.c:37
ProresVulkanDecodeContext::metadata_pool
AVBufferPool * metadata_pool
Definition: vulkan_prores.c:53
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
vulkan_decode.h
ff_vk_count_images
static int ff_vk_count_images(AVVkFrame *f)
Definition: vulkan.h:366
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:470
ProresVkParameters::slice_data
VkDeviceAddress slice_data
Definition: vulkan_prores.c:57
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
FFVkBuffer
Definition: vulkan.h:125
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:604
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:925
init_decode_shader
static int init_decode_shader(AVCodecContext *avctx, FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd, int max_num_mbs, int interlaced)
Definition: vulkan_prores.c:357
ff_vk_decode_init
int ff_vk_decode_init(AVCodecContext *avctx)
Initialize decoder.
Definition: vulkan_decode.c:1264
ProresContext::frame
AVFrame * frame
Definition: proresdec.h:46
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:650
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
FFVulkanFunctions
Definition: vulkan_functions.h:275
vk_decode_prores_uninit
static void vk_decode_prores_uninit(FFVulkanDecodeShared *ctx)
Definition: vulkan_prores.c:458
ff_vk_shader_load
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:2136
ff_vk_get_pooled_buffer
int ff_vk_get_pooled_buffer(FFVulkanContext *ctx, AVBufferPool **buf_pool, AVBufferRef **buf, VkBufferUsageFlags usage, void *create_pNext, size_t size, VkMemoryPropertyFlagBits mem_props)
Initialize a pool and create AVBufferRefs containing FFVkBuffer.
Definition: vulkan.c:1306
ProresContext::alpha_info
int alpha_info
Definition: proresdec.h:61
AV_CODEC_ID_PRORES
@ AV_CODEC_ID_PRORES
Definition: codec_id.h:198
ProresContext::mb_height
unsigned mb_height
height of the current picture in mb
Definition: proresdec.h:54