FFmpeg
proresenc_kostya_vulkan.c
Go to the documentation of this file.
1 /*
2  * Apple ProRes encoder
3  *
4  * Copyright (c) 2011 Anatoliy Wasserman
5  * Copyright (c) 2012 Konstantin Shishkov
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "libavutil/buffer.h"
25 #include "libavutil/macros.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/mem_internal.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/vulkan_spirv.h"
33 #include "libavutil/vulkan.h"
34 #include "avcodec.h"
35 #include "codec.h"
36 #include "codec_internal.h"
37 #include "encode.h"
38 #include "packet.h"
39 #include "put_bits.h"
40 #include "profiles.h"
41 #include "bytestream.h"
42 #include "proresdata.h"
44 #include "hwconfig.h"
45 
46 #define DCTSIZE 8
47 
48 typedef struct ProresDataTables {
49  int16_t qmat[128][64];
50  int16_t qmat_chroma[128][64];
52 
53 typedef struct SliceDataInfo {
54  int plane;
55  int line_add;
58 
59 typedef struct EncodeSliceInfo {
60  VkDeviceAddress bytestream;
61  VkDeviceAddress seek_table;
63 
64 typedef struct SliceData {
65  uint32_t mbs_per_slice;
66  int16_t rows[MAX_PLANES * MAX_MBS_PER_SLICE * 256];
67 } SliceData;
68 
69 typedef struct SliceScore {
70  int bits[MAX_STORED_Q][4];
74  int overquant;
75  int buf_start;
76  int quant;
77 } SliceScore;
78 
80  /* Intermediate buffers */
85 
86  /* Copied from the source */
89  void *frame_opaque;
94  int key_frame;
95  int flags;
97 
98 typedef struct ProresVulkanContext {
100 
101  /* Vulkan state */
111 
118 
122 
128 
129 extern const unsigned char ff_prores_ks_alpha_data_comp_spv_data[];
130 extern const unsigned int ff_prores_ks_alpha_data_comp_spv_len;
131 
132 extern const unsigned char ff_prores_ks_slice_data_comp_spv_data[];
133 extern const unsigned int ff_prores_ks_slice_data_comp_spv_len;
134 
135 extern const unsigned char ff_prores_ks_estimate_slice_comp_spv_data[];
136 extern const unsigned int ff_prores_ks_estimate_slice_comp_spv_len;
137 
138 extern const unsigned char ff_prores_ks_trellis_node_comp_spv_data[];
139 extern const unsigned int ff_prores_ks_trellis_node_comp_spv_len;
140 
141 extern const unsigned char ff_prores_ks_encode_slice_comp_spv_data[];
142 extern const unsigned int ff_prores_ks_encode_slice_comp_spv_len;
143 
144 static int init_slice_data_pipeline(ProresVulkanContext *pv, FFVulkanShader *shd, int blocks_per_mb)
145 {
146  int err = 0;
147  FFVulkanContext *vkctx = &pv->vkctx;
149 
150  SPEC_LIST_CREATE(sl, 5, 5 * sizeof(uint32_t))
151  SPEC_LIST_ADD(sl, 0, 32, pv->ctx.mbs_per_slice);
152  SPEC_LIST_ADD(sl, 1, 32, blocks_per_mb);
153  SPEC_LIST_ADD(sl, 2, 32, pv->ctx.mb_width);
154  SPEC_LIST_ADD(sl, 3, 32, pv->ctx.pictures_per_frame);
155  SPEC_LIST_ADD(sl, 16, 32, blocks_per_mb * pv->ctx.mbs_per_slice); /* nb_blocks */
156 
157  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
158  (uint32_t []) { DCTSIZE, blocks_per_mb, pv->ctx.mbs_per_slice }, 0);
159 
161  {
162  .name = "SliceBuffer",
163  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
164  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
165  },
166  {
167  .name = "planes",
168  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
169  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
170  .elems = av_pix_fmt_count_planes(vkctx->frames->sw_format),
171  },
172  };
173  RET(ff_vk_shader_add_descriptor_set(vkctx, shd, desc, 2, 0, 0));
174 
175  ff_vk_shader_add_push_const(shd, 0, sizeof(SliceDataInfo), VK_SHADER_STAGE_COMPUTE_BIT);
176 
177  RET(ff_vk_shader_link(vkctx, shd,
180 
181  RET(ff_vk_shader_register_exec(vkctx, &pv->e, shd));
182 
183 fail:
184  return err;
185 }
186 
188 {
189  int err = 0;
190  FFVulkanContext *vkctx = &pv->vkctx;
192 
193  SPEC_LIST_CREATE(sl, 4, 4 * sizeof(uint32_t))
194  SPEC_LIST_ADD(sl, 0, 32, pv->ctx.alpha_bits);
195  SPEC_LIST_ADD(sl, 1, 32, pv->ctx.slices_width);
196  SPEC_LIST_ADD(sl, 2, 32, pv->ctx.mb_width);
197  SPEC_LIST_ADD(sl, 3, 32, pv->ctx.mbs_per_slice);
198 
199  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
200  (uint32_t []) { 16, 16, 1 }, 0);
201 
203  {
204  .name = "SliceBuffer",
205  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
206  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
207  },
208  {
209  .name = "plane",
210  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
211  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
212  },
213  };
214  RET(ff_vk_shader_add_descriptor_set(vkctx, shd, desc, 2, 0, 0));
215 
216  RET(ff_vk_shader_link(vkctx, shd,
219 
220  RET(ff_vk_shader_register_exec(vkctx, &pv->e, shd));
221 
222 fail:
223  return err;
224 }
225 
227 {
228  int err = 0;
229  FFVulkanContext *vkctx = &pv->vkctx;
231  int subgroup_size = vkctx->subgroup_props.maxSubgroupSize;
232  int dim_x = pv->ctx.alpha_bits ? subgroup_size : (subgroup_size / 3) * 3;
233 
234  SPEC_LIST_CREATE(sl, 8, 8 * sizeof(uint32_t))
235  SPEC_LIST_ADD(sl, 0, 32, pv->ctx.mbs_per_slice);
236  SPEC_LIST_ADD(sl, 1, 32, pv->ctx.chroma_factor);
237  SPEC_LIST_ADD(sl, 2, 32, pv->ctx.alpha_bits);
238  SPEC_LIST_ADD(sl, 3, 32, pv->ctx.num_planes);
239  SPEC_LIST_ADD(sl, 4, 32, pv->ctx.slices_per_picture);
240  SPEC_LIST_ADD(sl, 5, 32, pv->ctx.force_quant ? 0 : pv->ctx.profile_info->min_quant);
241  SPEC_LIST_ADD(sl, 6, 32, pv->ctx.force_quant ? 0 : pv->ctx.profile_info->max_quant);
242  SPEC_LIST_ADD(sl, 7, 32, pv->ctx.bits_per_mb);
243 
244  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
245  (uint32_t []) { dim_x, 1, 1 }, 0);
246 
248  {
249  .name = "SliceBuffer",
250  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
251  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
252  },
253  {
254  .name = "SliceScores",
255  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
256  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
257  },
258  {
259  .name = "ProresDataTables",
260  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
261  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
262  },
263  };
264  RET(ff_vk_shader_add_descriptor_set(vkctx, shd, desc, 3, 0, 0));
265 
266  RET(ff_vk_shader_link(vkctx, shd,
269  RET(ff_vk_shader_register_exec(vkctx, &pv->e, shd));
270 
271 fail:
272  return err;
273 }
274 
276 {
277  int err = 0;
278  FFVulkanContext *vkctx = &pv->vkctx;
280  int subgroup_size = vkctx->subgroup_props.maxSubgroupSize;
281  int num_subgroups = FFALIGN(pv->ctx.mb_height, subgroup_size) / subgroup_size;
282 
283  SPEC_LIST_CREATE(sl, 8, 8 * sizeof(uint32_t))
284  SPEC_LIST_ADD(sl, 0, 32, pv->ctx.slices_width);
285  SPEC_LIST_ADD(sl, 1, 32, num_subgroups);
286  SPEC_LIST_ADD(sl, 2, 32, pv->ctx.num_planes);
287  SPEC_LIST_ADD(sl, 3, 32, pv->ctx.force_quant);
288  SPEC_LIST_ADD(sl, 4, 32, pv->ctx.profile_info->min_quant);
289  SPEC_LIST_ADD(sl, 5, 32, pv->ctx.profile_info->max_quant);
290  SPEC_LIST_ADD(sl, 6, 32, pv->ctx.mbs_per_slice);
291  SPEC_LIST_ADD(sl, 7, 32, pv->ctx.bits_per_mb);
292 
293  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
294  (uint32_t []) { pv->ctx.mb_height, 1, 1 }, 0);
295 
297  {
298  .name = "FrameSize",
299  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
300  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
301  },
302  {
303  .name = "SliceScores",
304  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
305  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
306  },
307  };
308  RET(ff_vk_shader_add_descriptor_set(vkctx, shd, desc, 2, 0, 0));
309 
310  RET(ff_vk_shader_link(vkctx, shd,
313 
314  RET(ff_vk_shader_register_exec(vkctx, &pv->e, shd));
315 
316 fail:
317  return err;
318 }
319 
321 {
322  int err = 0;
323  FFVulkanContext *vkctx = &pv->vkctx;
325 
326  SPEC_LIST_CREATE(sl, 6, 6 * sizeof(uint32_t))
327  SPEC_LIST_ADD(sl, 0, 32, pv->ctx.mbs_per_slice);
328  SPEC_LIST_ADD(sl, 1, 32, pv->ctx.chroma_factor);
329  SPEC_LIST_ADD(sl, 2, 32, pv->ctx.alpha_bits);
330  SPEC_LIST_ADD(sl, 3, 32, pv->ctx.num_planes);
331  SPEC_LIST_ADD(sl, 4, 32, pv->ctx.slices_per_picture);
332  SPEC_LIST_ADD(sl, 5, 32, pv->ctx.force_quant ? pv->ctx.force_quant : pv->ctx.profile_info->max_quant);
333 
334  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
335  (uint32_t []) { 64, 1, 1 }, 0);
336 
338  {
339  .name = "SliceBuffer",
340  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
341  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
342  },
343  {
344  .name = "SliceScores",
345  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
346  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
347  },
348  {
349  .name = "ProresDataTables",
350  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
351  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
352  },
353  };
354  RET(ff_vk_shader_add_descriptor_set(vkctx, shd, desc, 3, 0, 0));
355 
356  ff_vk_shader_add_push_const(shd, 0, sizeof(EncodeSliceInfo), VK_SHADER_STAGE_COMPUTE_BIT);
357 
358  RET(ff_vk_shader_link(vkctx, shd,
361 
362  RET(ff_vk_shader_register_exec(vkctx, &pv->e, shd));
363 
364 fail:
365  return err;
366 }
367 
369  AVFrame *frame, int picture_idx)
370 {
371  ProresVulkanContext *pv = avctx->priv_data;
372  ProresContext *ctx = &pv->ctx;
374  FFVulkanContext *vkctx = &pv->vkctx;
375  FFVulkanFunctions *vk = &vkctx->vkfn;
376  int err = 0, nb_img_bar = 0, i, is_chroma;
377  int min_quant = ctx->profile_info->min_quant;
378  int max_quant = ctx->profile_info->max_quant;
379  int subgroup_size = vkctx->subgroup_props.maxSubgroupSize;
380  int estimate_dim_x = ctx->alpha_bits ? subgroup_size : (subgroup_size / 3) * 3;
383  VkImageView views[AV_NUM_DATA_POINTERS];
384  VkImageMemoryBarrier2 img_bar[AV_NUM_DATA_POINTERS];
385  FFVkBuffer *pkt_vk_buf, *slice_data_buf, *slice_score_buf, *frame_size_buf;
386  SliceDataInfo slice_data_info;
387  EncodeSliceInfo encode_info;
388  FFVulkanShader *shd;
389 
390  /* Start recording */
391  ff_vk_exec_start(vkctx, exec);
392 
393  /* Get a pooled buffer for writing output data */
394  RET(ff_vk_get_pooled_buffer(vkctx, &pv->pkt_buf_pool, &pd->out_data_ref[picture_idx],
395  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
396  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
397  VK_BUFFER_USAGE_TRANSFER_SRC_BIT, NULL,
398  ctx->frame_size_upper_bound + FF_INPUT_BUFFER_MIN_SIZE,
399  transfer_slices ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
400  : (VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
401  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
402  VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)));
403  pkt_vk_buf = (FFVkBuffer*)pd->out_data_ref[picture_idx]->data;
404  ff_vk_exec_add_dep_buf(vkctx, exec, &pd->out_data_ref[picture_idx], 1, 1);
405 
406  /* Allocate buffer for writing slice data */
407  RET(ff_vk_get_pooled_buffer(vkctx, &pv->slice_data_buf_pool, &pd->slice_data_ref[picture_idx],
408  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
409  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, NULL,
410  ctx->slices_per_picture * sizeof(SliceData),
411  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT));
412  slice_data_buf = (FFVkBuffer*)pd->slice_data_ref[picture_idx]->data;
413  ff_vk_exec_add_dep_buf(vkctx, exec, &pd->slice_data_ref[picture_idx], 1, 1);
414 
415  /* Allocate buffer for writing slice scores */
416  RET(ff_vk_get_pooled_buffer(vkctx, &pv->slice_score_buf_pool, &pd->slice_score_ref[picture_idx],
417  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
418  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, NULL,
419  ctx->slices_per_picture * sizeof(SliceScore),
420  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT));
421  slice_score_buf = (FFVkBuffer*)pd->slice_score_ref[picture_idx]->data;
422  ff_vk_exec_add_dep_buf(vkctx, exec, &pd->slice_score_ref[picture_idx], 1, 1);
423 
424  /* Allocate buffer for writing frame size */
425  RET(ff_vk_get_pooled_buffer(vkctx, &pv->frame_size_buf_pool, &pd->frame_size_ref[picture_idx],
426  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
427  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, NULL,
428  sizeof(int),
429  VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
430  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
431  VK_MEMORY_PROPERTY_HOST_COHERENT_BIT));
432  frame_size_buf = (FFVkBuffer*)pd->frame_size_ref[picture_idx]->data;
433  ff_vk_exec_add_dep_buf(vkctx, exec, &pd->frame_size_ref[picture_idx], 1, 1);
434 
435  /* Generate barriers and image views for frame images. */
436  RET(ff_vk_exec_add_dep_frame(vkctx, exec, frame,
437  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
438  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
439  RET(ff_vk_create_imageviews(vkctx, exec, views, frame, FF_VK_REP_INT));
440  ff_vk_frame_barrier(vkctx, exec, frame, img_bar, &nb_img_bar,
441  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
442  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
443  VK_ACCESS_SHADER_READ_BIT,
444  VK_IMAGE_LAYOUT_GENERAL,
445  VK_QUEUE_FAMILY_IGNORED);
446 
447  /* Submit the image barriers. */
448  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
449  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
450  .pImageMemoryBarriers = img_bar,
451  .imageMemoryBarrierCount = nb_img_bar,
452  });
453 
454  /* Apply FDCT on input image data for future passes */
455  slice_data_info = (SliceDataInfo) {
456  .line_add = ctx->pictures_per_frame == 1 ? 0 : picture_idx ^ !(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST),
457  };
458  for (i = 0; i < ctx->num_planes; i++) {
459  is_chroma = (i == 1 || i == 2);
460  shd = &pv->slice_data_shd[!is_chroma || ctx->chroma_factor == CFACTOR_Y444];
461  if (i < 3) {
462  slice_data_info.plane = i;
463  slice_data_info.bits_per_sample = desc->comp[i].depth;
464  ff_vk_shader_update_desc_buffer(vkctx, exec, shd, 0, 0, 0,
465  slice_data_buf, 0, slice_data_buf->size,
466  VK_FORMAT_UNDEFINED);
467  ff_vk_shader_update_img_array(vkctx, exec, shd, frame, views, 0, 1,
468  VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
469  ff_vk_exec_bind_shader(vkctx, exec, shd);
470  ff_vk_shader_update_push_const(vkctx, exec, shd, VK_SHADER_STAGE_COMPUTE_BIT,
471  0, sizeof(SliceDataInfo), &slice_data_info);
472  vk->CmdDispatch(exec->buf, ctx->slices_width, ctx->mb_height, 1);
473  } else {
474  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->alpha_data_shd, 0, 0, 0,
475  slice_data_buf, 0, slice_data_buf->size,
476  VK_FORMAT_UNDEFINED);
477  ff_vk_shader_update_img(vkctx, exec, &pv->alpha_data_shd, 0, 1, 0, views[3],
478  VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
479  ff_vk_exec_bind_shader(vkctx, exec, &pv->alpha_data_shd);
480  vk->CmdDispatch(exec->buf, ctx->mb_width, ctx->mb_height, 1);
481  }
482  }
483 
484  /* Wait for writes to slice buffer. */
485  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
486  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
487  .pBufferMemoryBarriers = & (VkBufferMemoryBarrier2) {
488  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
489  .pNext = NULL,
490  .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
491  .srcAccessMask = VK_ACCESS_2_SHADER_WRITE_BIT,
492  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
493  .dstAccessMask = VK_ACCESS_2_SHADER_READ_BIT,
494  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
495  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
496  .buffer = slice_data_buf->buf,
497  .offset = 0,
498  .size = slice_data_buf->size,
499  },
500  .bufferMemoryBarrierCount = 1,
501  });
502 
503  /* Estimate slice bits and error for each quant */
504  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->estimate_slice_shd, 0, 0, 0,
505  slice_data_buf, 0, slice_data_buf->size,
506  VK_FORMAT_UNDEFINED);
507  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->estimate_slice_shd, 0, 1, 0,
508  slice_score_buf, 0, slice_score_buf->size,
509  VK_FORMAT_UNDEFINED);
510  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->estimate_slice_shd, 0, 2, 0,
511  &pv->prores_data_tables_buf, 0, pv->prores_data_tables_buf.size,
512  VK_FORMAT_UNDEFINED);
513  ff_vk_exec_bind_shader(vkctx, exec, &pv->estimate_slice_shd);
514  vk->CmdDispatch(exec->buf, (ctx->slices_per_picture * ctx->num_planes + estimate_dim_x - 1) / estimate_dim_x,
515  ctx->force_quant ? 1 : (max_quant - min_quant + 1), 1);
516 
517  /* Wait for writes to score buffer. */
518  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
519  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
520  .pBufferMemoryBarriers = & (VkBufferMemoryBarrier2) {
521  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
522  .pNext = NULL,
523  .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
524  .srcAccessMask = VK_ACCESS_2_SHADER_WRITE_BIT | VK_ACCESS_2_SHADER_READ_BIT,
525  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
526  .dstAccessMask = VK_ACCESS_2_SHADER_WRITE_BIT | VK_ACCESS_2_SHADER_READ_BIT,
527  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
528  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
529  .buffer = slice_score_buf->buf,
530  .offset = 0,
531  .size = slice_score_buf->size,
532  },
533  .bufferMemoryBarrierCount = 1,
534  });
535 
536  /* Compute optimal quant value for each slice */
537  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->trellis_node_shd, 0, 0, 0,
538  frame_size_buf, 0, frame_size_buf->size,
539  VK_FORMAT_UNDEFINED);
540  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->trellis_node_shd, 0, 1, 0,
541  slice_score_buf, 0, slice_score_buf->size,
542  VK_FORMAT_UNDEFINED);
543  ff_vk_exec_bind_shader(vkctx, exec, &pv->trellis_node_shd);
544  vk->CmdDispatch(exec->buf, 1, 1, 1);
545 
546  /* Wait for writes to quant buffer. */
547  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
548  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
549  .pBufferMemoryBarriers = & (VkBufferMemoryBarrier2) {
550  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
551  .pNext = NULL,
552  .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
553  .srcAccessMask = VK_ACCESS_2_SHADER_WRITE_BIT,
554  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
555  .dstAccessMask = VK_ACCESS_2_SHADER_WRITE_BIT | VK_ACCESS_2_SHADER_READ_BIT,
556  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
557  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
558  .buffer = frame_size_buf->buf,
559  .offset = 0,
560  .size = frame_size_buf->size,
561  },
562  .bufferMemoryBarrierCount = 1,
563  });
564 
565  /* Encode slices. */
566  encode_info = (EncodeSliceInfo) {
567  .seek_table = pkt_vk_buf->address,
568  .bytestream = pkt_vk_buf->address + ctx->slices_per_picture * 2,
569  };
570  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->encode_slice_shd, 0, 0, 0,
571  slice_data_buf, 0, slice_data_buf->size,
572  VK_FORMAT_UNDEFINED);
573  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->encode_slice_shd, 0, 1, 0,
574  slice_score_buf, 0, slice_score_buf->size,
575  VK_FORMAT_UNDEFINED);
576  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->encode_slice_shd, 0, 2, 0,
577  &pv->prores_data_tables_buf, 0, pv->prores_data_tables_buf.size,
578  VK_FORMAT_UNDEFINED);
579  ff_vk_exec_bind_shader(vkctx, exec, &pv->encode_slice_shd);
580  ff_vk_shader_update_push_const(vkctx, exec, &pv->encode_slice_shd,
581  VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(encode_info), &encode_info);
582  vk->CmdDispatch(exec->buf, FFALIGN(ctx->slices_per_picture, 64) / 64,
583  ctx->num_planes, 1);
584 
585 fail:
586  return err;
587 }
588 
590  uint8_t **orig_buf, int flags,
592  enum AVColorTransferCharacteristic color_trc,
593  enum AVColorSpace colorspace)
594 {
595  uint8_t *buf, *tmp;
596  uint8_t frame_flags;
597 
598  // frame atom
599  *orig_buf += 4; // frame size
600  bytestream_put_be32 (orig_buf, FRAME_ID); // frame container ID
601  buf = *orig_buf;
602 
603  // frame header
604  tmp = buf;
605  buf += 2; // frame header size will be stored here
606  bytestream_put_be16 (&buf, ctx->chroma_factor != CFACTOR_Y422 || ctx->alpha_bits ? 1 : 0);
607  bytestream_put_buffer(&buf, (uint8_t*)ctx->vendor, 4);
608  bytestream_put_be16 (&buf, avctx->width);
609  bytestream_put_be16 (&buf, avctx->height);
610 
611  frame_flags = ctx->chroma_factor << 6;
612  if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT)
613  frame_flags |= (flags & AV_FRAME_FLAG_TOP_FIELD_FIRST) ? 0x04 : 0x08;
614  bytestream_put_byte (&buf, frame_flags);
615 
616  bytestream_put_byte (&buf, 0); // reserved
617  bytestream_put_byte (&buf, color_primaries);
618  bytestream_put_byte (&buf, color_trc);
619  bytestream_put_byte (&buf, colorspace);
620  bytestream_put_byte (&buf, ctx->alpha_bits >> 3);
621  bytestream_put_byte (&buf, 0); // reserved
622  if (ctx->quant_sel != QUANT_MAT_DEFAULT) {
623  bytestream_put_byte (&buf, 0x03); // matrix flags - both matrices are present
624  bytestream_put_buffer(&buf, ctx->quant_mat, 64); // luma quantisation matrix
625  bytestream_put_buffer(&buf, ctx->quant_chroma_mat, 64); // chroma quantisation matrix
626  } else {
627  bytestream_put_byte (&buf, 0x00); // matrix flags - default matrices are used
628  }
629  bytestream_put_be16 (&tmp, buf - *orig_buf); // write back frame header size
630  return buf;
631 }
632 
634 {
635  ProresVulkanContext *pv = avctx->priv_data;
636  ProresContext *ctx = &pv->ctx;
638  FFVulkanContext *vkctx = &pv->vkctx;
639  FFVulkanFunctions *vk = &vkctx->vkfn;
640  FFVkExecContext *transfer_exec;
641  uint8_t *orig_buf, *buf, *slice_sizes;
642  uint8_t *picture_size_pos;
643  int picture_idx, err = 0;
644  int frame_size, picture_size;
645  int pkt_size = ctx->frame_size_upper_bound;
647  FFVkBuffer *out_data_buf, *frame_size_buf;
648  VkMappedMemoryRange invalidate_data;
649  AVBufferRef *mapped_ref;
650  FFVkBuffer *mapped_buf;
651 
652  /* Allocate packet */
653  RET(ff_get_encode_buffer(avctx, pkt, pkt_size + FF_INPUT_BUFFER_MIN_SIZE, 0));
654 
655  /* Initialize packet. */
656  pkt->pts = pd->pts;
657  pkt->dts = pd->pts;
658  pkt->duration = pd->duration;
660 
661  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
662  pkt->opaque = pd->frame_opaque;
664  pd->frame_opaque_ref = NULL;
665  }
666 
667  /* Write frame atom */
668  orig_buf = pkt->data;
669  buf = write_frame_header(avctx, ctx, &orig_buf, pd->flags,
670  pd->color_primaries, pd->color_trc,
671  pd->colorspace);
672 
673  /* Make sure encoding's done */
674  ff_vk_exec_wait(vkctx, exec);
675 
676  /* Roll transfer execution context */
677  if (transfer_slices) {
678  RET(ff_vk_host_map_buffer(vkctx, &mapped_ref, pkt->data, pkt->buf,
679  VK_BUFFER_USAGE_TRANSFER_DST_BIT));
680  mapped_buf = (FFVkBuffer *)mapped_ref->data;
681  transfer_exec = ff_vk_exec_get(vkctx, &pv->transfer_exec_pool);
682  ff_vk_exec_start(vkctx, transfer_exec);
683  }
684 
685  for (picture_idx = 0; picture_idx < ctx->pictures_per_frame; picture_idx++) {
686  /* Fetch buffers for the current picture. */
687  out_data_buf = (FFVkBuffer *)pd->out_data_ref[picture_idx]->data;
688  frame_size_buf = (FFVkBuffer *)pd->frame_size_ref[picture_idx]->data;
689 
690  /* Invalidate slice/output data if needed */
691  invalidate_data = (VkMappedMemoryRange) {
692  .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
693  .offset = 0,
694  .size = VK_WHOLE_SIZE,
695  };
696  if (!(frame_size_buf->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
697  invalidate_data.memory = frame_size_buf->mem;
698  vk->InvalidateMappedMemoryRanges(vkctx->hwctx->act_dev, 1, &invalidate_data);
699  }
700 
701  /* Write picture header */
702  picture_size_pos = buf + 1;
703  bytestream_put_byte(&buf, 0x40); // picture header size (in bits)
704  buf += 4; // picture data size will be stored here
705  bytestream_put_be16(&buf, ctx->slices_per_picture);
706  bytestream_put_byte(&buf, av_log2(ctx->mbs_per_slice) << 4); // slice width and height in MBs
707 
708  /* Skip over seek table */
709  slice_sizes = buf;
710  buf += ctx->slices_per_picture * 2;
711 
712  /* Calculate final size */
713  buf += *(int*)frame_size_buf->mapped_mem;
714 
715  if (transfer_slices) {
716  /* Perform host mapped transfer of slice data */
717  ff_vk_exec_add_dep_buf(vkctx, transfer_exec, &pd->out_data_ref[picture_idx], 1, 0);
718  ff_vk_exec_add_dep_buf(vkctx, transfer_exec, &mapped_ref, 1, 0);
719  vk->CmdCopyBuffer(transfer_exec->buf, out_data_buf->buf, mapped_buf->buf, 1, & (VkBufferCopy) {
720  .srcOffset = 0,
721  .dstOffset = mapped_buf->virtual_offset + slice_sizes - pkt->data,
722  .size = buf - slice_sizes,
723  });
724  } else {
725  /* Fallback to regular memcpy if transfer is not available */
726  if (!(out_data_buf->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
727  invalidate_data.memory = out_data_buf->mem;
728  vk->InvalidateMappedMemoryRanges(vkctx->hwctx->act_dev, 1, &invalidate_data);
729  }
730  memcpy(slice_sizes, out_data_buf->mapped_mem, buf - slice_sizes);
731  av_buffer_unref(&pd->out_data_ref[picture_idx]);
732  }
733 
734  /* Write picture size with header */
735  picture_size = buf - (picture_size_pos - 1);
736  bytestream_put_be32(&picture_size_pos, picture_size);
737 
738  /* Slice output buffers no longer needed */
739  av_buffer_unref(&pd->slice_data_ref[picture_idx]);
740  av_buffer_unref(&pd->slice_score_ref[picture_idx]);
741  av_buffer_unref(&pd->frame_size_ref[picture_idx]);
742  }
743 
744  /* Write frame size in header */
745  orig_buf -= 8;
746  frame_size = buf - orig_buf;
747  bytestream_put_be32(&orig_buf, frame_size);
748 
750  av_log(avctx, AV_LOG_VERBOSE, "Encoded data: %iMiB\n", pkt->size / (1024*1024));
751 
752  /* Wait for slice transfer */
753  if (transfer_slices) {
754  RET(ff_vk_exec_submit(vkctx, transfer_exec));
755  ff_vk_exec_wait(vkctx, transfer_exec);
756  }
757 
758 fail:
759  return err;
760 }
761 
763 {
764  int err;
765  ProresVulkanContext *pv = avctx->priv_data;
766  ProresContext *ctx = &pv->ctx;
768  FFVkExecContext *exec;
769  AVFrame *frame;
770 
771  while (1) {
772  /* Roll an execution context */
773  exec = ff_vk_exec_get(&pv->vkctx, &pv->e);
774 
775  /* If it had a frame, immediately output it */
776  if (exec->had_submission) {
777  exec->had_submission = 0;
778  pv->in_flight--;
779  return get_packet(avctx, exec, pkt);
780  }
781 
782  /* Get next frame to encode */
783  frame = pv->frame;
784  err = ff_encode_get_frame(avctx, frame);
785  if (err < 0 && err != AVERROR_EOF) {
786  return err;
787  } else if (err == AVERROR_EOF) {
788  if (!pv->in_flight)
789  return err;
790  continue;
791  }
792 
793  /* Encode frame */
794  pd = exec->opaque;
795  pd->color_primaries = frame->color_primaries;
796  pd->color_trc = frame->color_trc;
797  pd->colorspace = frame->colorspace;
798  pd->pts = frame->pts;
799  pd->duration = frame->duration;
800  pd->flags = frame->flags;
801  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
802  pd->frame_opaque = frame->opaque;
803  pd->frame_opaque_ref = frame->opaque_ref;
804  frame->opaque_ref = NULL;
805  }
806 
807  err = vulkan_encode_prores_submit_frame(avctx, exec, frame, 0);
808  if (ctx->pictures_per_frame > 1)
809  vulkan_encode_prores_submit_frame(avctx, exec, frame, 1);
810 
811  /* Submit execution context */
812  ff_vk_exec_submit(&pv->vkctx, exec);
814  if (err < 0)
815  return err;
816 
817  pv->in_flight++;
818  if (pv->in_flight < pv->async_depth)
819  return AVERROR(EAGAIN);
820  }
821 
822  return 0;
823 }
824 
826 {
827  ProresVulkanContext *pv = avctx->priv_data;
828  ProresContext *ctx = &pv->ctx;
829  FFVulkanContext *vkctx = &pv->vkctx;
830 
831  ff_vk_exec_pool_free(vkctx, &pv->e);
833 
834  if (ctx->alpha_bits)
835  ff_vk_shader_free(vkctx, &pv->alpha_data_shd);
836 
837  ff_vk_shader_free(vkctx, &pv->slice_data_shd[0]);
838  ff_vk_shader_free(vkctx, &pv->slice_data_shd[1]);
840  ff_vk_shader_free(vkctx, &pv->encode_slice_shd);
841  ff_vk_shader_free(vkctx, &pv->trellis_node_shd);
842 
844 
849 
850  ff_vk_uninit(vkctx);
851 
852  return 0;
853 }
854 
856 {
857  ProresVulkanContext *pv = avctx->priv_data;
858  ProresContext *ctx = &pv->ctx;
859  int err = 0, i, q;
860  FFVulkanContext *vkctx = &pv->vkctx;
861 
862  /* Init vulkan */
863  RET(ff_vk_init(vkctx, avctx, NULL, avctx->hw_frames_ctx));
864 
865  pv->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
866  if (!pv->qf) {
867  av_log(avctx, AV_LOG_ERROR, "Device has no compute queues!\n");
868  return AVERROR(ENOTSUP);
869  }
870 
871  RET(ff_vk_exec_pool_init(vkctx, pv->qf, &pv->e, 1, 0, 0, 0, NULL));
872 
873  pv->transfer_qf = ff_vk_qf_find(vkctx, VK_QUEUE_TRANSFER_BIT, 0);
874  if (!pv->transfer_qf) {
875  av_log(avctx, AV_LOG_ERROR, "Device has no transfer queues!\n");
876  return err;
877  }
878 
880  pv->async_depth, 0, 0, 0, NULL));
881 
882  /* Init common prores structures */
883  err = ff_prores_kostya_encode_init(avctx, ctx, vkctx->frames->sw_format);
884  if (err < 0)
885  return err;
886 
887  /* Temporary frame */
888  pv->frame = av_frame_alloc();
889  if (!pv->frame)
890  return AVERROR(ENOMEM);
891 
892  /* Async data pool */
893  pv->async_depth = pv->e.pool_size;
894  pv->exec_ctx_info = av_calloc(pv->async_depth, sizeof(*pv->exec_ctx_info));
895  if (!pv->exec_ctx_info)
896  return AVERROR(ENOMEM);
897  for (int i = 0; i < pv->async_depth; i++)
898  pv->e.contexts[i].opaque = &pv->exec_ctx_info[i];
899 
900  /* Compile shaders used by encoder */
906 
907  if (ctx->alpha_bits)
909 
910  /* Create prores data tables uniform buffer. */
912  sizeof(ProresDataTables), NULL, NULL,
913  VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT |
914  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
915  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
916  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
917  RET(ff_vk_map_buffer(vkctx, &pv->prores_data_tables_buf, (void *)&pv->tables, 0));
918  for (q = 0; q < MAX_STORED_Q; ++q) {
919  for (i = 0; i < 64; i++) {
920  pv->tables->qmat[q][i] = ctx->quants[q][ctx->scantable[i]];
921  pv->tables->qmat_chroma[q][i] = ctx->quants_chroma[q][ctx->scantable[i]];
922  }
923  }
924  for (q = MAX_STORED_Q; q < 128; ++q) {
925  for (i = 0; i < 64; i++) {
926  pv->tables->qmat[q][i] = ctx->quant_mat[ctx->scantable[i]] * q;
927  pv->tables->qmat_chroma[q][i] = ctx->quant_chroma_mat[ctx->scantable[i]] * q;
928  }
929  }
930 
931 fail:
932  return err;
933 }
934 
935 #define OFFSET(x) offsetof(ProresVulkanContext, x)
936 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
937 
938 static const AVOption options[] = {
939  { "mbs_per_slice", "macroblocks per slice", OFFSET(ctx.mbs_per_slice),
940  AV_OPT_TYPE_INT, { .i64 = 8 }, 1, MAX_MBS_PER_SLICE, VE },
941  { "profile", NULL, OFFSET(ctx.profile), AV_OPT_TYPE_INT,
942  { .i64 = PRORES_PROFILE_AUTO },
943  PRORES_PROFILE_AUTO, PRORES_PROFILE_4444XQ, VE, .unit = "profile" },
944  { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_AUTO },
945  0, 0, VE, .unit = "profile" },
946  { "proxy", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_PROXY },
947  0, 0, VE, .unit = "profile" },
948  { "lt", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_LT },
949  0, 0, VE, .unit = "profile" },
950  { "standard", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_STANDARD },
951  0, 0, VE, .unit = "profile" },
952  { "hq", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_HQ },
953  0, 0, VE, .unit = "profile" },
954  { "4444", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_4444 },
955  0, 0, VE, .unit = "profile" },
956  { "4444xq", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_4444XQ },
957  0, 0, VE, .unit = "profile" },
958  { "vendor", "vendor ID", OFFSET(ctx.vendor),
959  AV_OPT_TYPE_STRING, { .str = "Lavc" }, 0, 0, VE },
960  { "bits_per_mb", "desired bits per macroblock", OFFSET(ctx.bits_per_mb),
961  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 8192, VE },
962  { "quant_mat", "quantiser matrix", OFFSET(ctx.quant_sel), AV_OPT_TYPE_INT,
963  { .i64 = -1 }, -1, QUANT_MAT_DEFAULT, VE, .unit = "quant_mat" },
964  { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 },
965  0, 0, VE, .unit = "quant_mat" },
966  { "proxy", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_PROXY },
967  0, 0, VE, .unit = "quant_mat" },
968  { "lt", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_LT },
969  0, 0, VE, .unit = "quant_mat" },
970  { "standard", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_STANDARD },
971  0, 0, VE, .unit = "quant_mat" },
972  { "hq", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_HQ },
973  0, 0, VE, .unit = "quant_mat" },
974  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_DEFAULT },
975  0, 0, VE, .unit = "quant_mat" },
976  { "alpha_bits", "bits for alpha plane", OFFSET(ctx.alpha_bits), AV_OPT_TYPE_INT,
977  { .i64 = 16 }, 0, 16, VE },
978  { "async_depth", "Internal parallelization depth", OFFSET(async_depth), AV_OPT_TYPE_INT,
979  { .i64 = 1 }, 1, INT_MAX, VE },
980  { NULL }
981 };
982 
983 static const AVClass proresenc_class = {
984  .class_name = "ProRes vulkan encoder",
985  .item_name = av_default_item_name,
986  .option = options,
987  .version = LIBAVUTIL_VERSION_INT,
988 };
989 
991  HW_CONFIG_ENCODER_FRAMES(VULKAN, VULKAN),
993  NULL,
994 };
995 
997  .p.name = "prores_ks_vulkan",
998  CODEC_LONG_NAME("Apple ProRes (iCodec Pro)"),
999  .p.type = AVMEDIA_TYPE_VIDEO,
1000  .p.id = AV_CODEC_ID_PRORES,
1001  .priv_data_size = sizeof(ProresVulkanContext),
1002  .init = encode_init,
1003  .close = encode_close,
1005  .p.capabilities = AV_CODEC_CAP_DELAY |
1010  .hw_configs = prores_ks_hw_configs,
1011  .color_ranges = AVCOL_RANGE_MPEG,
1012  .p.priv_class = &proresenc_class,
1015 };
ProresContext::force_quant
int force_quant
Definition: proresenc_kostya_common.h:107
flags
const SwsFlags flags[]
Definition: swscale.c:61
vulkan_loader.h
hwconfig.h
CFACTOR_Y422
#define CFACTOR_Y422
Definition: proresenc_kostya_common.h:37
CODEC_PIXFMTS
#define CODEC_PIXFMTS(...)
Definition: codec_internal.h:392
ff_vk_create_buf
int ff_vk_create_buf(FFVulkanContext *s, FFVkBuffer *buf, size_t size, void *pNext, void *alloc_pNext, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags)
Definition: vulkan.c:1022
VulkanEncodeProresFrameData::flags
int flags
Definition: proresenc_kostya_vulkan.c:95
ProresVulkanContext::ctx
ProresContext ctx
Definition: proresenc_kostya_vulkan.c:99
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
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
opt.h
QUANT_MAT_LT
@ QUANT_MAT_LT
Definition: proresenc_kostya_common.h:61
ProresVulkanContext::vkctx
FFVulkanContext vkctx
Definition: proresenc_kostya_vulkan.c:102
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:666
mem_internal.h
ff_vk_shader_free
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition: vulkan.c:2791
AVBufferPool
The buffer pool.
Definition: buffer_internal.h:88
ff_prores_profiles
const AVProfile ff_prores_profiles[]
Definition: profiles.c:175
FFVkExecPool::contexts
FFVkExecContext * contexts
Definition: vulkan.h:291
options
static const AVOption options[]
Definition: proresenc_kostya_vulkan.c:938
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AV_CODEC_CAP_HARDWARE
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition: codec.h:130
RET
#define RET(x)
Definition: vulkan.h:68
ProresVulkanContext::in_flight
int in_flight
Definition: proresenc_kostya_vulkan.c:123
ff_vk_exec_pool_init
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:357
VulkanEncodeProresFrameData::duration
int64_t duration
Definition: proresenc_kostya_vulkan.c:88
FF_CODEC_CAP_EOF_FLUSH
#define FF_CODEC_CAP_EOF_FLUSH
The encoder has AV_CODEC_CAP_DELAY set, but does not actually have delay - it only wants to be flushe...
Definition: codec_internal.h:89
int64_t
long long int64_t
Definition: coverity.c:34
encode_init
static av_cold int encode_init(AVCodecContext *avctx)
Definition: proresenc_kostya_vulkan.c:855
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
pixdesc.h
ProresVulkanContext::slice_data_shd
FFVulkanShader slice_data_shd[2]
Definition: proresenc_kostya_vulkan.c:113
ff_vk_map_buffer
static int ff_vk_map_buffer(FFVulkanContext *s, FFVkBuffer *buf, uint8_t **mem, int invalidate)
Definition: vulkan.h:603
OFFSET
#define OFFSET(x)
Definition: proresenc_kostya_vulkan.c:935
AVPacket::data
uint8_t * data
Definition: packet.h:588
AVOption
AVOption.
Definition: opt.h:429
ProresContext::slices_width
int slices_width
Definition: proresenc_kostya_common.h:101
encode.h
ProresContext::alpha_bits
int alpha_bits
Definition: proresenc_kostya_common.h:108
ProresContext
Definition: proresdec.h:43
ff_prores_kostya_encode_init
av_cold int ff_prores_kostya_encode_init(AVCodecContext *avctx, ProresContext *ctx, enum AVPixelFormat pix_fmt)
Definition: proresenc_kostya_common.c:168
FFCodec
Definition: codec_internal.h:127
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
ProresContext::num_planes
int num_planes
Definition: proresenc_kostya_common.h:105
EncodeSliceInfo::seek_table
VkDeviceAddress seek_table
Definition: proresenc_kostya_vulkan.c:61
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:606
ff_vk_init
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:2829
SliceScore::bits
int bits[MAX_STORED_Q][4]
Definition: proresenc_kostya_vulkan.c:70
ff_vk_exec_get
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition: vulkan.c:548
ff_vk_uninit
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition: vulkan.c:2817
SliceScore::overquant
int overquant
Definition: proresenc_kostya_vulkan.c:74
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:636
SPEC_LIST_ADD
#define SPEC_LIST_ADD(name, idx, val_bits, val)
Definition: vulkan.h:86
EncodeSliceInfo
Definition: proresenc_kostya_vulkan.c:59
FF_VK_REP_INT
@ FF_VK_REP_INT
Definition: vulkan.h:453
ff_vk_shader_update_img
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:2694
VulkanEncodeProresFrameData::key_frame
int key_frame
Definition: proresenc_kostya_vulkan.c:94
NONE
#define NONE
Definition: vf_drawvg.c:261
ff_vk_exec_bind_shader
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition: vulkan.c:2768
ff_prores_ks_slice_data_comp_spv_len
const unsigned int ff_prores_ks_slice_data_comp_spv_len
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:643
FF_INPUT_BUFFER_MIN_SIZE
#define FF_INPUT_BUFFER_MIN_SIZE
Used by some encoders as upper bound for the length of headers.
Definition: encode.h:33
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:780
FFVkBuffer::buf
VkBuffer buf
Definition: vulkan.h:126
VulkanEncodeProresFrameData
Definition: proresenc_kostya_vulkan.c:79
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:655
MAX_MBS_PER_SLICE
#define MAX_MBS_PER_SLICE
Definition: proresenc_kostya_common.h:40
init_estimate_slice_pipeline
static int init_estimate_slice_pipeline(ProresVulkanContext *pv, FFVulkanShader *shd)
Definition: proresenc_kostya_vulkan.c:226
ProresContext::profile_info
const struct prores_profile * profile_info
Definition: proresenc_kostya_common.h:117
close
static av_cold void close(AVCodecParserContext *s)
Definition: apv_parser.c:197
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3496
AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition: avcodec.h:279
VulkanEncodeProresFrameData::pts
int64_t pts
Definition: proresenc_kostya_vulkan.c:87
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
PRORES_PROFILE_4444
@ PRORES_PROFILE_4444
Definition: proresenc_kostya_common.h:54
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:624
macros.h
fail
#define fail()
Definition: checkasm.h:219
ff_prores_ks_vulkan_encoder
const FFCodec ff_prores_ks_vulkan_encoder
Definition: proresenc_kostya_vulkan.c:996
ProresContext::mbs_per_slice
int mbs_per_slice
Definition: proresenc_kostya_common.h:99
av_shrink_packet
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: packet.c:113
PRORES_PROFILE_HQ
@ PRORES_PROFILE_HQ
Definition: proresenc_kostya_common.h:53
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:2719
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:2031
ff_prores_ks_trellis_node_comp_spv_data
const unsigned char ff_prores_ks_trellis_node_comp_spv_data[]
FFVulkanContext::subgroup_props
VkPhysicalDeviceSubgroupSizeControlProperties subgroup_props
Definition: vulkan.h:324
ProresVulkanContext::frame_size_buf_pool
AVBufferPool * frame_size_buf_pool
Definition: proresenc_kostya_vulkan.c:110
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:2584
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:496
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:1383
AV_CODEC_CAP_ENCODER_FLUSH
#define AV_CODEC_CAP_ENCODER_FLUSH
This encoder can be flushed using avcodec_flush_buffers().
Definition: codec.h:151
codec.h
AV_CODEC_FLAG_INTERLACED_DCT
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
Definition: avcodec.h:310
ProresVulkanContext::transfer_exec_pool
FFVkExecPool transfer_exec_pool
Definition: proresenc_kostya_vulkan.c:106
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
ProresVulkanContext::transfer_qf
AVVulkanDeviceQueueFamily * transfer_qf
Definition: proresenc_kostya_vulkan.c:105
prores_profile::max_quant
int max_quant
Definition: proresenc_kostya_common.h:75
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
av_cold
#define av_cold
Definition: attributes.h:106
QUANT_MAT_DEFAULT
@ QUANT_MAT_DEFAULT
Definition: proresenc_kostya_common.h:65
VulkanEncodeProresFrameData::color_primaries
enum AVColorPrimaries color_primaries
Definition: proresenc_kostya_vulkan.c:93
EncodeSliceInfo::bytestream
VkDeviceAddress bytestream
Definition: proresenc_kostya_vulkan.c:60
MAX_PLANES
#define MAX_PLANES
Definition: ffv1.h:44
ProresVulkanContext
Definition: proresenc_kostya_vulkan.c:98
QUANT_MAT_STANDARD
@ QUANT_MAT_STANDARD
Definition: proresenc_kostya_common.h:62
proresenc_class
static const AVClass proresenc_class
Definition: proresenc_kostya_vulkan.c:983
frame_size
int frame_size
Definition: mxfenc.c:2487
VulkanEncodeProresFrameData::out_data_ref
AVBufferRef * out_data_ref[2]
Definition: proresenc_kostya_vulkan.c:81
ff_prores_ks_alpha_data_comp_spv_data
const unsigned char ff_prores_ks_alpha_data_comp_spv_data[]
ff_vk_exec_wait
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:553
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:144
ProresDataTables::qmat
int16_t qmat[128][64]
Definition: proresenc_kostya_vulkan.c:49
vulkan_encode_prores_receive_packet
static int vulkan_encode_prores_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: proresenc_kostya_vulkan.c:762
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
VE
#define VE
Definition: proresenc_kostya_vulkan.c:936
ProresContext::bits_per_mb
int bits_per_mb
Definition: proresenc_kostya_common.h:106
SliceScore
Definition: proresenc_kostya_vulkan.c:69
init_encode_slice_pipeline
static int init_encode_slice_pipeline(ProresVulkanContext *pv, FFVulkanShader *shd)
Definition: proresenc_kostya_vulkan.c:320
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:620
MAX_STORED_Q
#define MAX_STORED_Q
Definition: proresenc_kostya_common.h:46
prores_profile::min_quant
int min_quant
Definition: proresenc_kostya_common.h:74
PRORES_PROFILE_AUTO
@ PRORES_PROFILE_AUTO
Definition: proresenc_kostya_common.h:49
ff_vk_exec_pool_free
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
Definition: vulkan.c:299
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:613
SliceData::mbs_per_slice
uint32_t mbs_per_slice
Definition: proresenc_kostya_vulkan.c:65
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:332
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
SliceData::rows
int16_t rows[MAX_PLANES *MAX_MBS_PER_SLICE *256]
Definition: proresenc_kostya_vulkan.c:66
if
if(ret)
Definition: filter_design.txt:179
init_trellis_node_pipeline
static int init_trellis_node_pipeline(ProresVulkanContext *pv, FFVulkanShader *shd)
Definition: proresenc_kostya_vulkan.c:275
ProresContext::pictures_per_frame
int pictures_per_frame
Definition: proresenc_kostya_common.h:103
SliceDataInfo::plane
int plane
Definition: proresenc_kostya_vulkan.c:54
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:571
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
SliceData
Definition: proresenc_kostya_vulkan.c:64
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
SliceScore::total_bits
int total_bits[MAX_STORED_Q]
Definition: proresenc_kostya_vulkan.c:72
NULL
#define NULL
Definition: coverity.c:32
write_frame_header
static uint8_t * write_frame_header(AVCodecContext *avctx, ProresContext *ctx, uint8_t **orig_buf, int flags, enum AVColorPrimaries color_primaries, enum AVColorTransferCharacteristic color_trc, enum AVColorSpace colorspace)
Definition: proresenc_kostya_vulkan.c:589
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
VulkanEncodeProresFrameData::frame_opaque_ref
AVBufferRef * frame_opaque_ref
Definition: proresenc_kostya_vulkan.c:90
VulkanEncodeProresFrameData::slice_score_ref
AVBufferRef * slice_score_ref[2]
Definition: proresenc_kostya_vulkan.c:83
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:367
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
profiles.h
av_buffer_pool_uninit
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:328
hwcontext_vulkan.h
options
Definition: swscale.c:43
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:2357
FFVkExecContext::had_submission
int had_submission
Definition: vulkan.h:148
FFVkBuffer::size
size_t size
Definition: vulkan.h:129
get_packet
static int get_packet(AVCodecContext *avctx, FFVkExecContext *exec, AVPacket *pkt)
Definition: proresenc_kostya_vulkan.c:633
SPEC_LIST_CREATE
#define SPEC_LIST_CREATE(name, max_length, max_size)
Definition: vulkan.h:76
transfer_slices
static int transfer_slices(AVCodecContext *avctx, VkBufferCopy *buf_regions, int nb_regions, VulkanEncodeFFv1FrameData *fd, uint8_t *dst, AVBufferRef *dst_ref)
Definition: ffv1enc_vulkan.c:526
init_slice_data_pipeline
static int init_slice_data_pipeline(ProresVulkanContext *pv, FFVulkanShader *shd, int blocks_per_mb)
Definition: proresenc_kostya_vulkan.c:144
FFVkBuffer::mapped_mem
uint8_t * mapped_mem
Definition: vulkan.h:134
FFVulkanContext
Definition: vulkan.h:312
encode_close
static av_cold int encode_close(AVCodecContext *avctx)
Definition: proresenc_kostya_vulkan.c:825
ff_prores_ks_slice_data_comp_spv_data
const unsigned char ff_prores_ks_slice_data_comp_spv_data[]
color_primaries
static const AVColorPrimariesDesc color_primaries[AVCOL_PRI_NB]
Definition: csp.c:76
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:550
HW_CONFIG_ENCODER_DEVICE
#define HW_CONFIG_ENCODER_DEVICE(format, device_type_)
Definition: hwconfig.h:95
ProresContext::chroma_factor
int chroma_factor
Definition: proresenc_kostya_common.h:100
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:2758
AVPacket::size
int size
Definition: packet.h:589
FFVulkanDescriptorSetBinding
Definition: vulkan.h:112
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
SliceScore::buf_start
int buf_start
Definition: proresenc_kostya_vulkan.c:75
codec_internal.h
ProresVulkanContext::encode_slice_shd
FFVulkanShader encode_slice_shd
Definition: proresenc_kostya_vulkan.c:115
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
vulkan.h
ProresVulkanContext::tables
ProresDataTables * tables
Definition: proresenc_kostya_vulkan.c:121
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:428
FFVulkanShader
Definition: vulkan.h:225
VulkanEncodeProresFrameData::slice_data_ref
AVBufferRef * slice_data_ref[2]
Definition: proresenc_kostya_vulkan.c:82
ProresVulkanContext::qf
AVVulkanDeviceQueueFamily * qf
Definition: proresenc_kostya_vulkan.c:103
proresdata.h
VulkanEncodeProresFrameData::frame_opaque
void * frame_opaque
Definition: proresenc_kostya_vulkan.c:89
AVCodecHWConfigInternal
Definition: hwconfig.h:25
FFVkBuffer::flags
VkMemoryPropertyFlagBits flags
Definition: vulkan.h:128
buffer.h
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:587
ProresVulkanContext::slice_score_buf_pool
AVBufferPool * slice_score_buf_pool
Definition: proresenc_kostya_vulkan.c:109
ProresVulkanContext::slice_quants
int * slice_quants
Definition: proresenc_kostya_vulkan.c:119
ff_prores_ks_estimate_slice_comp_spv_len
const unsigned int ff_prores_ks_estimate_slice_comp_spv_len
ff_prores_ks_alpha_data_comp_spv_len
const unsigned int ff_prores_ks_alpha_data_comp_spv_len
PRORES_PROFILE_STANDARD
@ PRORES_PROFILE_STANDARD
Definition: proresenc_kostya_common.h:52
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:2732
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:594
init_alpha_data_pipeline
static int init_alpha_data_pipeline(ProresVulkanContext *pv, FFVulkanShader *shd)
Definition: proresenc_kostya_vulkan.c:187
VulkanEncodeProresFrameData::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: proresenc_kostya_vulkan.c:91
ProresVulkanContext::pkt_buf_pool
AVBufferPool * pkt_buf_pool
Definition: proresenc_kostya_vulkan.c:107
ff_prores_ks_encode_slice_comp_spv_len
const unsigned int ff_prores_ks_encode_slice_comp_spv_len
ProresVulkanContext::async_depth
int async_depth
Definition: proresenc_kostya_vulkan.c:124
ProresContext::mb_width
unsigned mb_width
width of the current picture in mb
Definition: proresdec.h:53
HW_CONFIG_ENCODER_FRAMES
#define HW_CONFIG_ENCODER_FRAMES(format, device_type_)
Definition: hwconfig.h:98
QUANT_MAT_HQ
@ QUANT_MAT_HQ
Definition: proresenc_kostya_common.h:63
FF_VK_EXT_EXTERNAL_HOST_MEMORY
#define FF_VK_EXT_EXTERNAL_HOST_MEMORY
Definition: vulkan_functions.h:36
ff_prores_ks_trellis_node_comp_spv_len
const unsigned int ff_prores_ks_trellis_node_comp_spv_len
PRORES_PROFILE_4444XQ
@ PRORES_PROFILE_4444XQ
Definition: proresenc_kostya_common.h:55
bytestream_put_buffer
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:372
ProresVulkanContext::frame
AVFrame * frame
Definition: proresenc_kostya_vulkan.c:125
ff_vk_exec_start
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition: vulkan.c:560
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:581
packet.h
SliceDataInfo::bits_per_sample
int bits_per_sample
Definition: proresenc_kostya_vulkan.c:56
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:700
ff_prores_ks_encode_slice_comp_spv_data
const unsigned char ff_prores_ks_encode_slice_comp_spv_data[]
QUANT_MAT_PROXY
@ QUANT_MAT_PROXY
Definition: proresenc_kostya_common.h:59
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:496
FFVkBuffer::mem
VkDeviceMemory mem
Definition: vulkan.h:127
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
vulkan_spirv.h
FFVulkanContext::extensions
FFVulkanExtensions extensions
Definition: vulkan.h:317
SliceDataInfo::line_add
int line_add
Definition: proresenc_kostya_vulkan.c:55
ff_vk_free_buf
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
Definition: vulkan.c:1236
AVCodecContext::height
int height
Definition: avcodec.h:600
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:760
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
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:1461
avcodec.h
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
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:1948
FFVulkanContext::vkfn
FFVulkanFunctions vkfn
Definition: vulkan.h:316
ProresDataTables
Definition: proresenc_kostya_vulkan.c:48
FFVkExecContext::opaque
void * opaque
Definition: vulkan.h:162
FFVkExecPool
Definition: vulkan.h:290
ProresDataTables::qmat_chroma
int16_t qmat_chroma[128][64]
Definition: proresenc_kostya_vulkan.c:50
SliceDataInfo
Definition: proresenc_kostya_vulkan.c:53
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:1481
ff_vk_qf_find
AVVulkanDeviceQueueFamily * ff_vk_qf_find(FFVulkanContext *s, VkQueueFlagBits dev_family, VkVideoCodecOperationFlagBitsKHR vid_ops)
Chooses an appropriate QF.
Definition: vulkan.c:286
FFVkExecContext::buf
VkCommandBuffer buf
Definition: vulkan.h:156
ProresVulkanContext::e
FFVkExecPool e
Definition: proresenc_kostya_vulkan.c:104
ProresVulkanContext::slice_data_buf_pool
AVBufferPool * slice_data_buf_pool
Definition: proresenc_kostya_vulkan.c:108
AVCodecContext
main external API structure.
Definition: avcodec.h:439
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:2484
ProresVulkanContext::slice_scores
SliceScore * slice_scores
Definition: proresenc_kostya_vulkan.c:120
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:105
ProresContext::slices_per_picture
int slices_per_picture
Definition: proresenc_kostya_common.h:102
CFACTOR_Y444
#define CFACTOR_Y444
Definition: proresenc_kostya_common.h:38
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
vulkan_encode_prores_submit_frame
static int vulkan_encode_prores_submit_frame(AVCodecContext *avctx, FFVkExecContext *exec, AVFrame *frame, int picture_idx)
Definition: proresenc_kostya_vulkan.c:368
ff_prores_ks_estimate_slice_comp_spv_data
const unsigned char ff_prores_ks_estimate_slice_comp_spv_data[]
SliceScore::quant
int quant
Definition: proresenc_kostya_vulkan.c:76
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
PRORES_PROFILE_PROXY
@ PRORES_PROFILE_PROXY
Definition: proresenc_kostya_common.h:50
VulkanEncodeProresFrameData::frame_size_ref
AVBufferRef * frame_size_ref[2]
Definition: proresenc_kostya_vulkan.c:84
ProresVulkanContext::exec_ctx_info
VulkanEncodeProresFrameData * exec_ctx_info
Definition: proresenc_kostya_vulkan.c:126
PRORES_PROFILE_LT
@ PRORES_PROFILE_LT
Definition: proresenc_kostya_common.h:51
desc
const char * desc
Definition: libsvtav1.c:82
ProresVulkanContext::trellis_node_shd
FFVulkanShader trellis_node_shd
Definition: proresenc_kostya_vulkan.c:116
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFVulkanContext::hwctx
AVVulkanDeviceContext * hwctx
Definition: vulkan.h:349
mem.h
ff_encode_get_frame
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:204
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
FRAME_ID
#define FRAME_ID
Definition: proresdata.h:28
VulkanEncodeProresFrameData::colorspace
enum AVColorSpace colorspace
Definition: proresenc_kostya_vulkan.c:92
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
ProresVulkanContext::prores_data_tables_buf
FFVkBuffer prores_data_tables_buf
Definition: proresenc_kostya_vulkan.c:117
AVVulkanDeviceContext::act_dev
VkDevice act_dev
Active device.
Definition: hwcontext_vulkan.h:84
DCTSIZE
#define DCTSIZE
Definition: proresenc_kostya_vulkan.c:46
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:565
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:466
FFVkBuffer
Definition: vulkan.h:125
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:600
bytestream.h
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:905
ProresVulkanContext::alpha_data_shd
FFVulkanShader alpha_data_shd
Definition: proresenc_kostya_vulkan.c:112
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVVulkanDeviceQueueFamily
Definition: hwcontext_vulkan.h:33
FFVulkanContext::frames
AVHWFramesContext * frames
Definition: vulkan.h:353
ProresVulkanContext::estimate_slice_shd
FFVulkanShader estimate_slice_shd
Definition: proresenc_kostya_vulkan.c:114
prores_ks_hw_configs
static const AVCodecHWConfigInternal *const prores_ks_hw_configs[]
Definition: proresenc_kostya_vulkan.c:990
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
put_bits.h
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
FFVulkanFunctions
Definition: vulkan_functions.h:274
FFVkExecPool::pool_size
int pool_size
Definition: vulkan.h:296
SliceScore::total_error
int total_error[MAX_STORED_Q]
Definition: proresenc_kostya_vulkan.c:73
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:2074
SliceScore::error
int error[MAX_STORED_Q][4]
Definition: proresenc_kostya_vulkan.c:71
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:1278
AV_CODEC_ID_PRORES
@ AV_CODEC_ID_PRORES
Definition: codec_id.h:200
ProresContext::mb_height
unsigned mb_height
height of the current picture in mb
Definition: proresdec.h:54
proresenc_kostya_common.h