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"
32 #include "libavutil/vulkan.h"
33 #include "avcodec.h"
34 #include "codec.h"
35 #include "codec_internal.h"
36 #include "encode.h"
37 #include "packet.h"
38 #include "put_bits.h"
39 #include "profiles.h"
40 #include "bytestream.h"
41 #include "proresdata.h"
43 #include "hwconfig.h"
44 
45 #define DCTSIZE 8
46 
47 typedef struct ProresDataTables {
48  int16_t qmat[128][64];
49  int16_t qmat_chroma[128][64];
51 
52 typedef struct SliceDataInfo {
53  int plane;
54  int line_add;
57 
58 typedef struct EncodeSliceInfo {
59  VkDeviceAddress bytestream;
60  VkDeviceAddress seek_table;
62 
63 typedef struct SliceData {
64  uint32_t mbs_per_slice;
65  int16_t rows[MAX_PLANES * MAX_MBS_PER_SLICE * 256];
66 } SliceData;
67 
68 typedef struct SliceScore {
69  int bits[MAX_STORED_Q][4];
73  int overquant;
74  int buf_start;
75  int quant;
76 } SliceScore;
77 
79  /* Intermediate buffers */
84 
85  /* Copied from the source */
88  void *frame_opaque;
93  int key_frame;
94  int flags;
96 
97 typedef struct ProresVulkanContext {
99 
100  /* Vulkan state */
110 
117 
121 
127 
128 extern const unsigned char ff_prores_ks_alpha_data_comp_spv_data[];
129 extern const unsigned int ff_prores_ks_alpha_data_comp_spv_len;
130 
131 extern const unsigned char ff_prores_ks_slice_data_comp_spv_data[];
132 extern const unsigned int ff_prores_ks_slice_data_comp_spv_len;
133 
134 extern const unsigned char ff_prores_ks_estimate_slice_comp_spv_data[];
135 extern const unsigned int ff_prores_ks_estimate_slice_comp_spv_len;
136 
137 extern const unsigned char ff_prores_ks_trellis_node_comp_spv_data[];
138 extern const unsigned int ff_prores_ks_trellis_node_comp_spv_len;
139 
140 extern const unsigned char ff_prores_ks_encode_slice_comp_spv_data[];
141 extern const unsigned int ff_prores_ks_encode_slice_comp_spv_len;
142 
143 static int init_slice_data_pipeline(ProresVulkanContext *pv, FFVulkanShader *shd, int blocks_per_mb)
144 {
145  int err = 0;
146  FFVulkanContext *vkctx = &pv->vkctx;
148 
149  SPEC_LIST_CREATE(sl, 5, 5 * sizeof(uint32_t))
150  SPEC_LIST_ADD(sl, 0, 32, pv->ctx.mbs_per_slice);
151  SPEC_LIST_ADD(sl, 1, 32, blocks_per_mb);
152  SPEC_LIST_ADD(sl, 2, 32, pv->ctx.mb_width);
153  SPEC_LIST_ADD(sl, 3, 32, pv->ctx.pictures_per_frame);
154  SPEC_LIST_ADD(sl, 16, 32, blocks_per_mb * pv->ctx.mbs_per_slice); /* nb_blocks */
155 
156  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
157  (uint32_t []) { DCTSIZE, blocks_per_mb, pv->ctx.mbs_per_slice }, 0);
158 
160  {
161  .name = "SliceBuffer",
162  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
163  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
164  },
165  {
166  .name = "planes",
167  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
168  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
169  .elems = av_pix_fmt_count_planes(vkctx->frames->sw_format),
170  },
171  };
172  ff_vk_shader_add_descriptor_set(vkctx, shd, desc, 2, 0);
173 
174  ff_vk_shader_add_push_const(shd, 0, sizeof(SliceDataInfo), VK_SHADER_STAGE_COMPUTE_BIT);
175 
176  RET(ff_vk_shader_link(vkctx, shd,
179 
180  RET(ff_vk_shader_register_exec(vkctx, &pv->e, shd));
181 
182 fail:
183  return err;
184 }
185 
187 {
188  int err = 0;
189  FFVulkanContext *vkctx = &pv->vkctx;
191 
192  SPEC_LIST_CREATE(sl, 4, 4 * sizeof(uint32_t))
193  SPEC_LIST_ADD(sl, 0, 32, pv->ctx.alpha_bits);
194  SPEC_LIST_ADD(sl, 1, 32, pv->ctx.slices_width);
195  SPEC_LIST_ADD(sl, 2, 32, pv->ctx.mb_width);
196  SPEC_LIST_ADD(sl, 3, 32, pv->ctx.mbs_per_slice);
197 
198  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
199  (uint32_t []) { 16, 16, 1 }, 0);
200 
202  {
203  .name = "SliceBuffer",
204  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
205  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
206  },
207  {
208  .name = "plane",
209  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
210  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
211  },
212  };
213  ff_vk_shader_add_descriptor_set(vkctx, shd, desc, 2, 0);
214 
215  RET(ff_vk_shader_link(vkctx, shd,
218 
219  RET(ff_vk_shader_register_exec(vkctx, &pv->e, shd));
220 
221 fail:
222  return err;
223 }
224 
226 {
227  int err = 0;
228  FFVulkanContext *vkctx = &pv->vkctx;
230  int subgroup_size = vkctx->subgroup_props.maxSubgroupSize;
231  int dim_x = pv->ctx.alpha_bits ? subgroup_size : (subgroup_size / 3) * 3;
232 
233  SPEC_LIST_CREATE(sl, 8, 8 * sizeof(uint32_t))
234  SPEC_LIST_ADD(sl, 0, 32, pv->ctx.mbs_per_slice);
235  SPEC_LIST_ADD(sl, 1, 32, pv->ctx.chroma_factor);
236  SPEC_LIST_ADD(sl, 2, 32, pv->ctx.alpha_bits);
237  SPEC_LIST_ADD(sl, 3, 32, pv->ctx.num_planes);
238  SPEC_LIST_ADD(sl, 4, 32, pv->ctx.slices_per_picture);
239  SPEC_LIST_ADD(sl, 5, 32, pv->ctx.force_quant ? 0 : pv->ctx.profile_info->min_quant);
240  SPEC_LIST_ADD(sl, 6, 32, pv->ctx.force_quant ? 0 : pv->ctx.profile_info->max_quant);
241  SPEC_LIST_ADD(sl, 7, 32, pv->ctx.bits_per_mb);
242 
243  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
244  (uint32_t []) { dim_x, 1, 1 }, 0);
245 
247  {
248  .name = "SliceBuffer",
249  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
250  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
251  },
252  {
253  .name = "SliceScores",
254  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
255  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
256  },
257  {
258  .name = "ProresDataTables",
259  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
260  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
261  },
262  };
263  ff_vk_shader_add_descriptor_set(vkctx, shd, desc, 3, 0);
264 
265  RET(ff_vk_shader_link(vkctx, shd,
268  RET(ff_vk_shader_register_exec(vkctx, &pv->e, shd));
269 
270 fail:
271  return err;
272 }
273 
275 {
276  int err = 0;
277  FFVulkanContext *vkctx = &pv->vkctx;
279  int subgroup_size = vkctx->subgroup_props.maxSubgroupSize;
280  int num_subgroups = FFALIGN(pv->ctx.mb_height, subgroup_size) / subgroup_size;
281 
282  SPEC_LIST_CREATE(sl, 8, 8 * sizeof(uint32_t))
283  SPEC_LIST_ADD(sl, 0, 32, pv->ctx.slices_width);
284  SPEC_LIST_ADD(sl, 1, 32, num_subgroups);
285  SPEC_LIST_ADD(sl, 2, 32, pv->ctx.num_planes);
286  SPEC_LIST_ADD(sl, 3, 32, pv->ctx.force_quant);
287  SPEC_LIST_ADD(sl, 4, 32, pv->ctx.profile_info->min_quant);
288  SPEC_LIST_ADD(sl, 5, 32, pv->ctx.profile_info->max_quant);
289  SPEC_LIST_ADD(sl, 6, 32, pv->ctx.mbs_per_slice);
290  SPEC_LIST_ADD(sl, 7, 32, pv->ctx.bits_per_mb);
291 
292  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
293  (uint32_t []) { pv->ctx.mb_height, 1, 1 }, 0);
294 
296  {
297  .name = "FrameSize",
298  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
299  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
300  },
301  {
302  .name = "SliceScores",
303  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
304  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
305  },
306  };
307  ff_vk_shader_add_descriptor_set(vkctx, shd, desc, 2, 0);
308 
309  RET(ff_vk_shader_link(vkctx, shd,
312 
313  RET(ff_vk_shader_register_exec(vkctx, &pv->e, shd));
314 
315 fail:
316  return err;
317 }
318 
320 {
321  int err = 0;
322  FFVulkanContext *vkctx = &pv->vkctx;
324 
325  SPEC_LIST_CREATE(sl, 6, 6 * sizeof(uint32_t))
326  SPEC_LIST_ADD(sl, 0, 32, pv->ctx.mbs_per_slice);
327  SPEC_LIST_ADD(sl, 1, 32, pv->ctx.chroma_factor);
328  SPEC_LIST_ADD(sl, 2, 32, pv->ctx.alpha_bits);
329  SPEC_LIST_ADD(sl, 3, 32, pv->ctx.num_planes);
330  SPEC_LIST_ADD(sl, 4, 32, pv->ctx.slices_per_picture);
331  SPEC_LIST_ADD(sl, 5, 32, pv->ctx.force_quant ? pv->ctx.force_quant : pv->ctx.profile_info->max_quant);
332 
333  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
334  (uint32_t []) { 64, 1, 1 }, 0);
335 
337  {
338  .name = "SliceBuffer",
339  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
340  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
341  },
342  {
343  .name = "SliceScores",
344  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
345  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
346  },
347  {
348  .name = "ProresDataTables",
349  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
350  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
351  },
352  };
353  ff_vk_shader_add_descriptor_set(vkctx, shd, desc, 3, 0);
354 
355  ff_vk_shader_add_push_const(shd, 0, sizeof(EncodeSliceInfo), VK_SHADER_STAGE_COMPUTE_BIT);
356 
357  RET(ff_vk_shader_link(vkctx, shd,
360 
361  RET(ff_vk_shader_register_exec(vkctx, &pv->e, shd));
362 
363 fail:
364  return err;
365 }
366 
368  AVFrame *frame, int picture_idx)
369 {
370  ProresVulkanContext *pv = avctx->priv_data;
371  ProresContext *ctx = &pv->ctx;
373  FFVulkanContext *vkctx = &pv->vkctx;
374  FFVulkanFunctions *vk = &vkctx->vkfn;
375  int err = 0, nb_img_bar = 0, i, is_chroma;
376  int min_quant = ctx->profile_info->min_quant;
377  int max_quant = ctx->profile_info->max_quant;
378  int subgroup_size = vkctx->subgroup_props.maxSubgroupSize;
379  int estimate_dim_x = ctx->alpha_bits ? subgroup_size : (subgroup_size / 3) * 3;
380  int transfer_slices = vkctx->extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY;
382  VkImageView views[AV_NUM_DATA_POINTERS];
383  VkImageMemoryBarrier2 img_bar[AV_NUM_DATA_POINTERS];
384  FFVkBuffer *pkt_vk_buf, *slice_data_buf, *slice_score_buf, *frame_size_buf;
385  SliceDataInfo slice_data_info;
386  EncodeSliceInfo encode_info;
387  FFVulkanShader *shd;
388 
389  /* Start recording */
390  ff_vk_exec_start(vkctx, exec);
391 
392  /* Get a pooled buffer for writing output data */
393  RET(ff_vk_get_pooled_buffer(vkctx, &pv->pkt_buf_pool, &pd->out_data_ref[picture_idx],
394  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
395  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
396  VK_BUFFER_USAGE_TRANSFER_SRC_BIT, NULL,
397  ctx->frame_size_upper_bound + FF_INPUT_BUFFER_MIN_SIZE,
398  transfer_slices ? VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
399  : (VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
400  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
401  VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)));
402  pkt_vk_buf = (FFVkBuffer*)pd->out_data_ref[picture_idx]->data;
403  ff_vk_exec_add_dep_buf(vkctx, exec, &pd->out_data_ref[picture_idx], 1, 1);
404 
405  /* Allocate buffer for writing slice data */
406  RET(ff_vk_get_pooled_buffer(vkctx, &pv->slice_data_buf_pool, &pd->slice_data_ref[picture_idx],
407  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
408  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, NULL,
409  ctx->slices_per_picture * sizeof(SliceData),
410  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT));
411  slice_data_buf = (FFVkBuffer*)pd->slice_data_ref[picture_idx]->data;
412  ff_vk_exec_add_dep_buf(vkctx, exec, &pd->slice_data_ref[picture_idx], 1, 1);
413 
414  /* Allocate buffer for writing slice scores */
415  RET(ff_vk_get_pooled_buffer(vkctx, &pv->slice_score_buf_pool, &pd->slice_score_ref[picture_idx],
416  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
417  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, NULL,
418  ctx->slices_per_picture * sizeof(SliceScore),
419  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT));
420  slice_score_buf = (FFVkBuffer*)pd->slice_score_ref[picture_idx]->data;
421  ff_vk_exec_add_dep_buf(vkctx, exec, &pd->slice_score_ref[picture_idx], 1, 1);
422 
423  /* Allocate buffer for writing frame size */
424  RET(ff_vk_get_pooled_buffer(vkctx, &pv->frame_size_buf_pool, &pd->frame_size_ref[picture_idx],
425  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
426  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, NULL,
427  sizeof(int),
428  VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
429  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
430  VK_MEMORY_PROPERTY_HOST_COHERENT_BIT));
431  frame_size_buf = (FFVkBuffer*)pd->frame_size_ref[picture_idx]->data;
432  ff_vk_exec_add_dep_buf(vkctx, exec, &pd->frame_size_ref[picture_idx], 1, 1);
433 
434  /* Generate barriers and image views for frame images. */
435  RET(ff_vk_exec_add_dep_frame(vkctx, exec, frame,
436  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
437  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
438  RET(ff_vk_create_imageviews(vkctx, exec, views, frame, FF_VK_REP_INT));
439  ff_vk_frame_barrier(vkctx, exec, frame, img_bar, &nb_img_bar,
440  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
441  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
442  VK_ACCESS_SHADER_READ_BIT,
443  VK_IMAGE_LAYOUT_GENERAL,
444  VK_QUEUE_FAMILY_IGNORED);
445 
446  /* Submit the image barriers. */
447  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
448  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
449  .pImageMemoryBarriers = img_bar,
450  .imageMemoryBarrierCount = nb_img_bar,
451  });
452 
453  /* Apply FDCT on input image data for future passes */
454  slice_data_info = (SliceDataInfo) {
455  .line_add = ctx->pictures_per_frame == 1 ? 0 : picture_idx ^ !(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST),
456  };
457  for (i = 0; i < ctx->num_planes; i++) {
458  is_chroma = (i == 1 || i == 2);
459  shd = &pv->slice_data_shd[!is_chroma || ctx->chroma_factor == CFACTOR_Y444];
460  if (i < 3) {
461  slice_data_info.plane = i;
462  slice_data_info.bits_per_sample = desc->comp[i].depth;
463  ff_vk_shader_update_desc_buffer(vkctx, exec, shd, 0, 0, 0,
464  slice_data_buf, 0, slice_data_buf->size,
465  VK_FORMAT_UNDEFINED);
466  ff_vk_shader_update_img_array(vkctx, exec, shd, frame, views, 0, 1,
467  VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
468  ff_vk_exec_bind_shader(vkctx, exec, shd);
469  ff_vk_shader_update_push_const(vkctx, exec, shd, VK_SHADER_STAGE_COMPUTE_BIT,
470  0, sizeof(SliceDataInfo), &slice_data_info);
471  vk->CmdDispatch(exec->buf, ctx->slices_width, ctx->mb_height, 1);
472  } else {
473  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->alpha_data_shd, 0, 0, 0,
474  slice_data_buf, 0, slice_data_buf->size,
475  VK_FORMAT_UNDEFINED);
476  ff_vk_shader_update_img(vkctx, exec, &pv->alpha_data_shd, 0, 1, 0, views[3],
477  VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
478  ff_vk_exec_bind_shader(vkctx, exec, &pv->alpha_data_shd);
479  vk->CmdDispatch(exec->buf, ctx->mb_width, ctx->mb_height, 1);
480  }
481  }
482 
483  /* Wait for writes to slice buffer. */
484  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
485  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
486  .pBufferMemoryBarriers = & (VkBufferMemoryBarrier2) {
487  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
488  .pNext = NULL,
489  .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
490  .srcAccessMask = VK_ACCESS_2_SHADER_WRITE_BIT,
491  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
492  .dstAccessMask = VK_ACCESS_2_SHADER_READ_BIT,
493  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
494  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
495  .buffer = slice_data_buf->buf,
496  .offset = 0,
497  .size = slice_data_buf->size,
498  },
499  .bufferMemoryBarrierCount = 1,
500  });
501 
502  /* Estimate slice bits and error for each quant */
503  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->estimate_slice_shd, 0, 0, 0,
504  slice_data_buf, 0, slice_data_buf->size,
505  VK_FORMAT_UNDEFINED);
506  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->estimate_slice_shd, 0, 1, 0,
507  slice_score_buf, 0, slice_score_buf->size,
508  VK_FORMAT_UNDEFINED);
509  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->estimate_slice_shd, 0, 2, 0,
510  &pv->prores_data_tables_buf, 0, pv->prores_data_tables_buf.size,
511  VK_FORMAT_UNDEFINED);
512  ff_vk_exec_bind_shader(vkctx, exec, &pv->estimate_slice_shd);
513  vk->CmdDispatch(exec->buf, (ctx->slices_per_picture * ctx->num_planes + estimate_dim_x - 1) / estimate_dim_x,
514  ctx->force_quant ? 1 : (max_quant - min_quant + 1), 1);
515 
516  /* Wait for writes to score buffer. */
517  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
518  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
519  .pBufferMemoryBarriers = & (VkBufferMemoryBarrier2) {
520  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
521  .pNext = NULL,
522  .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
523  .srcAccessMask = VK_ACCESS_2_SHADER_WRITE_BIT | VK_ACCESS_2_SHADER_READ_BIT,
524  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
525  .dstAccessMask = VK_ACCESS_2_SHADER_WRITE_BIT | VK_ACCESS_2_SHADER_READ_BIT,
526  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
527  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
528  .buffer = slice_score_buf->buf,
529  .offset = 0,
530  .size = slice_score_buf->size,
531  },
532  .bufferMemoryBarrierCount = 1,
533  });
534 
535  /* Compute optimal quant value for each slice */
536  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->trellis_node_shd, 0, 0, 0,
537  frame_size_buf, 0, frame_size_buf->size,
538  VK_FORMAT_UNDEFINED);
539  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->trellis_node_shd, 0, 1, 0,
540  slice_score_buf, 0, slice_score_buf->size,
541  VK_FORMAT_UNDEFINED);
542  ff_vk_exec_bind_shader(vkctx, exec, &pv->trellis_node_shd);
543  vk->CmdDispatch(exec->buf, 1, 1, 1);
544 
545  /* Wait for writes to quant buffer. */
546  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
547  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
548  .pBufferMemoryBarriers = & (VkBufferMemoryBarrier2) {
549  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
550  .pNext = NULL,
551  .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
552  .srcAccessMask = VK_ACCESS_2_SHADER_WRITE_BIT,
553  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
554  .dstAccessMask = VK_ACCESS_2_SHADER_WRITE_BIT | VK_ACCESS_2_SHADER_READ_BIT,
555  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
556  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
557  .buffer = frame_size_buf->buf,
558  .offset = 0,
559  .size = frame_size_buf->size,
560  },
561  .bufferMemoryBarrierCount = 1,
562  });
563 
564  /* Encode slices. */
565  encode_info = (EncodeSliceInfo) {
566  .seek_table = pkt_vk_buf->address,
567  .bytestream = pkt_vk_buf->address + ctx->slices_per_picture * 2,
568  };
569  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->encode_slice_shd, 0, 0, 0,
570  slice_data_buf, 0, slice_data_buf->size,
571  VK_FORMAT_UNDEFINED);
572  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->encode_slice_shd, 0, 1, 0,
573  slice_score_buf, 0, slice_score_buf->size,
574  VK_FORMAT_UNDEFINED);
575  ff_vk_shader_update_desc_buffer(vkctx, exec, &pv->encode_slice_shd, 0, 2, 0,
576  &pv->prores_data_tables_buf, 0, pv->prores_data_tables_buf.size,
577  VK_FORMAT_UNDEFINED);
578  ff_vk_exec_bind_shader(vkctx, exec, &pv->encode_slice_shd);
579  ff_vk_shader_update_push_const(vkctx, exec, &pv->encode_slice_shd,
580  VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(encode_info), &encode_info);
581  vk->CmdDispatch(exec->buf, FFALIGN(ctx->slices_per_picture, 64) / 64,
582  ctx->num_planes, 1);
583 
584 fail:
585  return err;
586 }
587 
589  uint8_t **orig_buf, int flags,
591  enum AVColorTransferCharacteristic color_trc,
592  enum AVColorSpace colorspace)
593 {
594  uint8_t *buf, *tmp;
595  uint8_t frame_flags;
596 
597  // frame atom
598  *orig_buf += 4; // frame size
599  bytestream_put_be32 (orig_buf, FRAME_ID); // frame container ID
600  buf = *orig_buf;
601 
602  // frame header
603  tmp = buf;
604  buf += 2; // frame header size will be stored here
605  bytestream_put_be16 (&buf, ctx->chroma_factor != CFACTOR_Y422 || ctx->alpha_bits ? 1 : 0);
606  bytestream_put_buffer(&buf, (uint8_t*)ctx->vendor, 4);
607  bytestream_put_be16 (&buf, avctx->width);
608  bytestream_put_be16 (&buf, avctx->height);
609 
610  frame_flags = ctx->chroma_factor << 6;
611  if (avctx->flags & AV_CODEC_FLAG_INTERLACED_DCT)
612  frame_flags |= (flags & AV_FRAME_FLAG_TOP_FIELD_FIRST) ? 0x04 : 0x08;
613  bytestream_put_byte (&buf, frame_flags);
614 
615  bytestream_put_byte (&buf, 0); // reserved
616  bytestream_put_byte (&buf, color_primaries);
617  bytestream_put_byte (&buf, color_trc);
618  bytestream_put_byte (&buf, colorspace);
619  bytestream_put_byte (&buf, ctx->alpha_bits >> 3);
620  bytestream_put_byte (&buf, 0); // reserved
621  if (ctx->quant_sel != QUANT_MAT_DEFAULT) {
622  bytestream_put_byte (&buf, 0x03); // matrix flags - both matrices are present
623  bytestream_put_buffer(&buf, ctx->quant_mat, 64); // luma quantisation matrix
624  bytestream_put_buffer(&buf, ctx->quant_chroma_mat, 64); // chroma quantisation matrix
625  } else {
626  bytestream_put_byte (&buf, 0x00); // matrix flags - default matrices are used
627  }
628  bytestream_put_be16 (&tmp, buf - *orig_buf); // write back frame header size
629  return buf;
630 }
631 
633 {
634  ProresVulkanContext *pv = avctx->priv_data;
635  ProresContext *ctx = &pv->ctx;
637  FFVulkanContext *vkctx = &pv->vkctx;
638  FFVulkanFunctions *vk = &vkctx->vkfn;
639  FFVkExecContext *transfer_exec;
640  uint8_t *orig_buf, *buf, *slice_sizes;
641  uint8_t *picture_size_pos;
642  int picture_idx, err = 0;
643  int frame_size, picture_size;
644  int pkt_size = ctx->frame_size_upper_bound;
645  int transfer_slices = vkctx->extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY;
646  FFVkBuffer *out_data_buf, *frame_size_buf;
647  VkMappedMemoryRange invalidate_data;
648  AVBufferRef *mapped_ref;
649  FFVkBuffer *mapped_buf;
650 
651  /* Allocate packet */
652  RET(ff_get_encode_buffer(avctx, pkt, pkt_size + FF_INPUT_BUFFER_MIN_SIZE, 0));
653 
654  /* Initialize packet. */
655  pkt->pts = pd->pts;
656  pkt->dts = pd->pts;
657  pkt->duration = pd->duration;
659 
660  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
661  pkt->opaque = pd->frame_opaque;
663  pd->frame_opaque_ref = NULL;
664  }
665 
666  /* Write frame atom */
667  orig_buf = pkt->data;
668  buf = write_frame_header(avctx, ctx, &orig_buf, pd->flags,
669  pd->color_primaries, pd->color_trc,
670  pd->colorspace);
671 
672  /* Make sure encoding's done */
673  ff_vk_exec_wait(vkctx, exec);
674 
675  /* Roll transfer execution context */
676  if (transfer_slices) {
677  RET(ff_vk_host_map_buffer(vkctx, &mapped_ref, pkt->data, pkt->buf,
678  VK_BUFFER_USAGE_TRANSFER_DST_BIT));
679  mapped_buf = (FFVkBuffer *)mapped_ref->data;
680  transfer_exec = ff_vk_exec_get(vkctx, &pv->transfer_exec_pool);
681  ff_vk_exec_start(vkctx, transfer_exec);
682  }
683 
684  for (picture_idx = 0; picture_idx < ctx->pictures_per_frame; picture_idx++) {
685  /* Fetch buffers for the current picture. */
686  out_data_buf = (FFVkBuffer *)pd->out_data_ref[picture_idx]->data;
687  frame_size_buf = (FFVkBuffer *)pd->frame_size_ref[picture_idx]->data;
688 
689  /* Invalidate slice/output data if needed */
690  invalidate_data = (VkMappedMemoryRange) {
691  .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
692  .offset = 0,
693  .size = VK_WHOLE_SIZE,
694  };
695  if (!(frame_size_buf->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
696  invalidate_data.memory = frame_size_buf->mem;
697  vk->InvalidateMappedMemoryRanges(vkctx->hwctx->act_dev, 1, &invalidate_data);
698  }
699 
700  /* Write picture header */
701  picture_size_pos = buf + 1;
702  bytestream_put_byte(&buf, 0x40); // picture header size (in bits)
703  buf += 4; // picture data size will be stored here
704  bytestream_put_be16(&buf, ctx->slices_per_picture);
705  bytestream_put_byte(&buf, av_log2(ctx->mbs_per_slice) << 4); // slice width and height in MBs
706 
707  /* Skip over seek table */
708  slice_sizes = buf;
709  buf += ctx->slices_per_picture * 2;
710 
711  /* Calculate final size */
712  buf += *(int*)frame_size_buf->mapped_mem;
713 
714  if (transfer_slices) {
715  /* Perform host mapped transfer of slice data */
716  ff_vk_exec_add_dep_buf(vkctx, transfer_exec, &pd->out_data_ref[picture_idx], 1, 0);
717  ff_vk_exec_add_dep_buf(vkctx, transfer_exec, &mapped_ref, 1, 0);
718  vk->CmdCopyBuffer(transfer_exec->buf, out_data_buf->buf, mapped_buf->buf, 1, & (VkBufferCopy) {
719  .srcOffset = 0,
720  .dstOffset = mapped_buf->virtual_offset + slice_sizes - pkt->data,
721  .size = buf - slice_sizes,
722  });
723  } else {
724  /* Fallback to regular memcpy if transfer is not available */
725  if (!(out_data_buf->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
726  invalidate_data.memory = out_data_buf->mem;
727  vk->InvalidateMappedMemoryRanges(vkctx->hwctx->act_dev, 1, &invalidate_data);
728  }
729  memcpy(slice_sizes, out_data_buf->mapped_mem, buf - slice_sizes);
730  av_buffer_unref(&pd->out_data_ref[picture_idx]);
731  }
732 
733  /* Write picture size with header */
734  picture_size = buf - (picture_size_pos - 1);
735  bytestream_put_be32(&picture_size_pos, picture_size);
736 
737  /* Slice output buffers no longer needed */
738  av_buffer_unref(&pd->slice_data_ref[picture_idx]);
739  av_buffer_unref(&pd->slice_score_ref[picture_idx]);
740  av_buffer_unref(&pd->frame_size_ref[picture_idx]);
741  }
742 
743  /* Write frame size in header */
744  orig_buf -= 8;
745  frame_size = buf - orig_buf;
746  bytestream_put_be32(&orig_buf, frame_size);
747 
749  av_log(avctx, AV_LOG_VERBOSE, "Encoded data: %iMiB\n", pkt->size / (1024*1024));
750 
751  /* Wait for slice transfer */
752  if (transfer_slices) {
753  RET(ff_vk_exec_submit(vkctx, transfer_exec));
754  ff_vk_exec_wait(vkctx, transfer_exec);
755  }
756 
757 fail:
758  return err;
759 }
760 
762 {
763  int err;
764  ProresVulkanContext *pv = avctx->priv_data;
765  ProresContext *ctx = &pv->ctx;
767  FFVkExecContext *exec;
768  AVFrame *frame;
769 
770  while (1) {
771  /* Roll an execution context */
772  exec = ff_vk_exec_get(&pv->vkctx, &pv->e);
773 
774  /* If it had a frame, immediately output it */
775  if (exec->had_submission) {
776  exec->had_submission = 0;
777  pv->in_flight--;
778  return get_packet(avctx, exec, pkt);
779  }
780 
781  /* Get next frame to encode */
782  frame = pv->frame;
783  err = ff_encode_get_frame(avctx, frame);
784  if (err < 0 && err != AVERROR_EOF) {
785  return err;
786  } else if (err == AVERROR_EOF) {
787  if (!pv->in_flight)
788  return err;
789  continue;
790  }
791 
792  /* Encode frame */
793  pd = exec->opaque;
794  pd->color_primaries = frame->color_primaries;
795  pd->color_trc = frame->color_trc;
796  pd->colorspace = frame->colorspace;
797  pd->pts = frame->pts;
798  pd->duration = frame->duration;
799  pd->flags = frame->flags;
800  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
801  pd->frame_opaque = frame->opaque;
802  pd->frame_opaque_ref = frame->opaque_ref;
803  frame->opaque_ref = NULL;
804  }
805 
806  err = vulkan_encode_prores_submit_frame(avctx, exec, frame, 0);
807  if (ctx->pictures_per_frame > 1)
808  vulkan_encode_prores_submit_frame(avctx, exec, frame, 1);
809 
810  /* Submit execution context */
811  ff_vk_exec_submit(&pv->vkctx, exec);
813  if (err < 0)
814  return err;
815 
816  pv->in_flight++;
817  if (pv->in_flight < pv->async_depth)
818  return AVERROR(EAGAIN);
819  }
820 
821  return 0;
822 }
823 
825 {
826  ProresVulkanContext *pv = avctx->priv_data;
827  ProresContext *ctx = &pv->ctx;
828  FFVulkanContext *vkctx = &pv->vkctx;
829 
830  ff_vk_exec_pool_free(vkctx, &pv->e);
832 
833  if (ctx->alpha_bits)
834  ff_vk_shader_free(vkctx, &pv->alpha_data_shd);
835 
836  ff_vk_shader_free(vkctx, &pv->slice_data_shd[0]);
837  ff_vk_shader_free(vkctx, &pv->slice_data_shd[1]);
839  ff_vk_shader_free(vkctx, &pv->encode_slice_shd);
840  ff_vk_shader_free(vkctx, &pv->trellis_node_shd);
841 
843 
848 
849  ff_vk_uninit(vkctx);
850 
851  return 0;
852 }
853 
855 {
856  ProresVulkanContext *pv = avctx->priv_data;
857  ProresContext *ctx = &pv->ctx;
858  int err = 0, i, q;
859  FFVulkanContext *vkctx = &pv->vkctx;
860 
861  /* Init vulkan */
862  RET(ff_vk_init(vkctx, avctx, NULL, avctx->hw_frames_ctx));
863 
864  pv->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
865  if (!pv->qf) {
866  av_log(avctx, AV_LOG_ERROR, "Device has no compute queues!\n");
867  return AVERROR(ENOTSUP);
868  }
869 
870  RET(ff_vk_exec_pool_init(vkctx, pv->qf, &pv->e, 1, 0, 0, 0, NULL));
871 
872  pv->transfer_qf = ff_vk_qf_find(vkctx, VK_QUEUE_TRANSFER_BIT, 0);
873  if (!pv->transfer_qf) {
874  av_log(avctx, AV_LOG_ERROR, "Device has no transfer queues!\n");
875  return err;
876  }
877 
879  pv->async_depth, 0, 0, 0, NULL));
880 
881  /* Init common prores structures */
882  err = ff_prores_kostya_encode_init(avctx, ctx, vkctx->frames->sw_format);
883  if (err < 0)
884  return err;
885 
886  /* Temporary frame */
887  pv->frame = av_frame_alloc();
888  if (!pv->frame)
889  return AVERROR(ENOMEM);
890 
891  /* Async data pool */
892  pv->async_depth = pv->e.pool_size;
893  pv->exec_ctx_info = av_calloc(pv->async_depth, sizeof(*pv->exec_ctx_info));
894  if (!pv->exec_ctx_info)
895  return AVERROR(ENOMEM);
896  for (int i = 0; i < pv->async_depth; i++)
897  pv->e.contexts[i].opaque = &pv->exec_ctx_info[i];
898 
899  /* Compile shaders used by encoder */
905 
906  if (ctx->alpha_bits)
908 
909  /* Create prores data tables uniform buffer. */
911  sizeof(ProresDataTables), NULL, NULL,
912  VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT |
913  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
914  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
915  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
916  RET(ff_vk_map_buffer(vkctx, &pv->prores_data_tables_buf, (void *)&pv->tables, 0));
917  for (q = 0; q < MAX_STORED_Q; ++q) {
918  for (i = 0; i < 64; i++) {
919  pv->tables->qmat[q][i] = ctx->quants[q][ctx->scantable[i]];
920  pv->tables->qmat_chroma[q][i] = ctx->quants_chroma[q][ctx->scantable[i]];
921  }
922  }
923  for (q = MAX_STORED_Q; q < 128; ++q) {
924  for (i = 0; i < 64; i++) {
925  pv->tables->qmat[q][i] = ctx->quant_mat[ctx->scantable[i]] * q;
926  pv->tables->qmat_chroma[q][i] = ctx->quant_chroma_mat[ctx->scantable[i]] * q;
927  }
928  }
929 
930 fail:
931  return err;
932 }
933 
934 #define OFFSET(x) offsetof(ProresVulkanContext, x)
935 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
936 
937 static const AVOption options[] = {
938  { "mbs_per_slice", "macroblocks per slice", OFFSET(ctx.mbs_per_slice),
939  AV_OPT_TYPE_INT, { .i64 = 8 }, 1, MAX_MBS_PER_SLICE, VE },
940  { "profile", NULL, OFFSET(ctx.profile), AV_OPT_TYPE_INT,
941  { .i64 = PRORES_PROFILE_AUTO },
942  PRORES_PROFILE_AUTO, PRORES_PROFILE_4444XQ, VE, .unit = "profile" },
943  { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_AUTO },
944  0, 0, VE, .unit = "profile" },
945  { "proxy", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_PROXY },
946  0, 0, VE, .unit = "profile" },
947  { "lt", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_LT },
948  0, 0, VE, .unit = "profile" },
949  { "standard", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_STANDARD },
950  0, 0, VE, .unit = "profile" },
951  { "hq", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_HQ },
952  0, 0, VE, .unit = "profile" },
953  { "4444", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_4444 },
954  0, 0, VE, .unit = "profile" },
955  { "4444xq", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PRORES_PROFILE_4444XQ },
956  0, 0, VE, .unit = "profile" },
957  { "vendor", "vendor ID", OFFSET(ctx.vendor),
958  AV_OPT_TYPE_STRING, { .str = "Lavc" }, 0, 0, VE },
959  { "bits_per_mb", "desired bits per macroblock", OFFSET(ctx.bits_per_mb),
960  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 8192, VE },
961  { "quant_mat", "quantiser matrix", OFFSET(ctx.quant_sel), AV_OPT_TYPE_INT,
962  { .i64 = -1 }, -1, QUANT_MAT_DEFAULT, VE, .unit = "quant_mat" },
963  { "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 },
964  0, 0, VE, .unit = "quant_mat" },
965  { "proxy", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_PROXY },
966  0, 0, VE, .unit = "quant_mat" },
967  { "lt", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_LT },
968  0, 0, VE, .unit = "quant_mat" },
969  { "standard", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_STANDARD },
970  0, 0, VE, .unit = "quant_mat" },
971  { "hq", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_HQ },
972  0, 0, VE, .unit = "quant_mat" },
973  { "default", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = QUANT_MAT_DEFAULT },
974  0, 0, VE, .unit = "quant_mat" },
975  { "alpha_bits", "bits for alpha plane", OFFSET(ctx.alpha_bits), AV_OPT_TYPE_INT,
976  { .i64 = 16 }, 0, 16, VE },
977  { "async_depth", "Internal parallelization depth", OFFSET(async_depth), AV_OPT_TYPE_INT,
978  { .i64 = 1 }, 1, INT_MAX, VE },
979  { NULL }
980 };
981 
982 static const AVClass proresenc_class = {
983  .class_name = "ProRes vulkan encoder",
984  .item_name = av_default_item_name,
985  .option = options,
986  .version = LIBAVUTIL_VERSION_INT,
987 };
988 
990  HW_CONFIG_ENCODER_FRAMES(VULKAN, VULKAN),
992  NULL,
993 };
994 
996  .p.name = "prores_ks_vulkan",
997  CODEC_LONG_NAME("Apple ProRes (iCodec Pro)"),
998  .p.type = AVMEDIA_TYPE_VIDEO,
999  .p.id = AV_CODEC_ID_PRORES,
1000  .priv_data_size = sizeof(ProresVulkanContext),
1001  .init = encode_init,
1002  .close = encode_close,
1004  .p.capabilities = AV_CODEC_CAP_DELAY |
1009  .hw_configs = prores_ks_hw_configs,
1010  .color_ranges = AVCOL_RANGE_MPEG,
1011  .p.priv_class = &proresenc_class,
1014 };
ProresContext::force_quant
int force_quant
Definition: proresenc_kostya_common.h:107
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:401
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:1050
VulkanEncodeProresFrameData::flags
int flags
Definition: proresenc_kostya_vulkan.c:94
ProresVulkanContext::ctx
ProresContext ctx
Definition: proresenc_kostya_vulkan.c:98
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:43
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
ProresVulkanContext::vkctx
FFVulkanContext vkctx
Definition: proresenc_kostya_vulkan.c:101
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:672
mem_internal.h
ff_vk_shader_free
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition: vulkan.c:2680
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:254
options
static const AVOption options[]
Definition: proresenc_kostya_vulkan.c:937
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3460
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:127
RET
#define RET(x)
Definition: vulkan.h:34
ProresVulkanContext::in_flight
int in_flight
Definition: proresenc_kostya_vulkan.c:122
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:87
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:90
av_cold
#define av_cold
Definition: attributes.h:119
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:854
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:472
pixdesc.h
ProresVulkanContext::slice_data_shd
FFVulkanShader slice_data_shd[2]
Definition: proresenc_kostya_vulkan.c:112
ff_vk_map_buffer
static int ff_vk_map_buffer(FFVulkanContext *s, FFVkBuffer *buf, uint8_t **mem, int invalidate)
Definition: vulkan.h:566
OFFSET
#define OFFSET(x)
Definition: proresenc_kostya_vulkan.c:934
AVPacket::data
uint8_t * data
Definition: packet.h:603
AVOption
AVOption.
Definition: opt.h:428
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:60
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:621
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:2716
SliceScore::bits
int bits[MAX_STORED_Q][4]
Definition: proresenc_kostya_vulkan.c:69
ff_vk_exec_get
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition: vulkan.c:568
ff_vk_uninit
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition: vulkan.c:2704
SliceScore::overquant
int overquant
Definition: proresenc_kostya_vulkan.c:73
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:642
SPEC_LIST_ADD
#define SPEC_LIST_ADD(name, idx, val_bits, val)
Definition: vulkan.h:52
EncodeSliceInfo
Definition: proresenc_kostya_vulkan.c:58
PRORES_PROFILE_PROXY
@ PRORES_PROFILE_PROXY
Definition: proresenc_kostya_common.h:50
FF_VK_REP_INT
@ FF_VK_REP_INT
Definition: vulkan.h:416
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:2583
VulkanEncodeProresFrameData::key_frame
int key_frame
Definition: proresenc_kostya_vulkan.c:93
NONE
#define NONE
Definition: vf_drawvg.c:262
ff_vk_exec_bind_shader
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition: vulkan.c:2657
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:650
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:800
FFVkBuffer::buf
VkBuffer buf
Definition: vulkan.h:92
VulkanEncodeProresFrameData
Definition: proresenc_kostya_vulkan.c:78
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:700
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:225
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:3500
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:86
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:639
macros.h
ff_prores_ks_vulkan_encoder
const FFCodec ff_prores_ks_vulkan_encoder
Definition: proresenc_kostya_vulkan.c:995
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_4444
@ PRORES_PROFILE_4444
Definition: proresenc_kostya_common.h:54
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:2608
PRORES_PROFILE_AUTO
@ PRORES_PROFILE_AUTO
Definition: proresenc_kostya_common.h:49
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
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:287
ProresVulkanContext::frame_size_buf_pool
AVBufferPool * frame_size_buf_pool
Definition: proresenc_kostya_vulkan.c:109
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:2473
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:500
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
AV_CODEC_CAP_ENCODER_FLUSH
#define AV_CODEC_CAP_ENCODER_FLUSH
This encoder can be flushed using avcodec_flush_buffers().
Definition: codec.h:148
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:105
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:104
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
QUANT_MAT_PROXY
@ QUANT_MAT_PROXY
Definition: proresenc_kostya_common.h:59
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:504
VulkanEncodeProresFrameData::color_primaries
enum AVColorPrimaries color_primaries
Definition: proresenc_kostya_vulkan.c:92
EncodeSliceInfo::bytestream
VkDeviceAddress bytestream
Definition: proresenc_kostya_vulkan.c:59
MAX_PLANES
#define MAX_PLANES
Definition: ffv1.h:44
ProresVulkanContext
Definition: proresenc_kostya_vulkan.c:97
proresenc_class
static const AVClass proresenc_class
Definition: proresenc_kostya_vulkan.c:982
frame_size
int frame_size
Definition: mxfenc.c:2489
VulkanEncodeProresFrameData::out_data_ref
AVBufferRef * out_data_ref[2]
Definition: proresenc_kostya_vulkan.c:80
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:573
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:141
ProresDataTables::qmat
int16_t qmat[128][64]
Definition: proresenc_kostya_vulkan.c:48
vulkan_encode_prores_receive_packet
static int vulkan_encode_prores_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: proresenc_kostya_vulkan.c:761
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
VE
#define VE
Definition: proresenc_kostya_vulkan.c:935
ProresContext::bits_per_mb
int bits_per_mb
Definition: proresenc_kostya_common.h:106
SliceScore
Definition: proresenc_kostya_vulkan.c:68
init_encode_slice_pipeline
static int init_encode_slice_pipeline(ProresVulkanContext *pv, FFVulkanShader *shd)
Definition: proresenc_kostya_vulkan.c:319
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
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
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:628
SliceData::mbs_per_slice
uint32_t mbs_per_slice
Definition: proresenc_kostya_vulkan.c:64
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:349
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:65
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:274
ProresContext::pictures_per_frame
int pictures_per_frame
Definition: proresenc_kostya_common.h:103
fail
#define fail
Definition: test.h:478
SliceDataInfo::plane
int plane
Definition: proresenc_kostya_vulkan.c:53
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:586
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
SliceData
Definition: proresenc_kostya_vulkan.c:63
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:71
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:588
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:89
VulkanEncodeProresFrameData::slice_score_ref
AVBufferRef * slice_score_ref[2]
Definition: proresenc_kostya_vulkan.c:82
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:384
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:50
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:2333
FFVkExecContext::had_submission
int had_submission
Definition: vulkan.h:114
FFVkBuffer::size
size_t size
Definition: vulkan.h:95
get_packet
static int get_packet(AVCodecContext *avctx, FFVkExecContext *exec, AVPacket *pkt)
Definition: proresenc_kostya_vulkan.c:632
SPEC_LIST_CREATE
#define SPEC_LIST_CREATE(name, max_length, max_size)
Definition: vulkan.h:42
init_slice_data_pipeline
static int init_slice_data_pipeline(ProresVulkanContext *pv, FFVulkanShader *shd, int blocks_per_mb)
Definition: proresenc_kostya_vulkan.c:143
FFVkBuffer::mapped_mem
uint8_t * mapped_mem
Definition: vulkan.h:100
FFVulkanContext
Definition: vulkan.h:275
encode_close
static av_cold int encode_close(AVCodecContext *avctx)
Definition: proresenc_kostya_vulkan.c:824
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:608
HW_CONFIG_ENCODER_DEVICE
#define HW_CONFIG_ENCODER_DEVICE(format, device_type_)
Definition: hwconfig.h:97
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:2647
AVPacket::size
int size
Definition: packet.h:604
FFVulkanDescriptorSetBinding
Definition: vulkan.h:78
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:88
SliceScore::buf_start
int buf_start
Definition: proresenc_kostya_vulkan.c:74
codec_internal.h
ProresVulkanContext::encode_slice_shd
FFVulkanShader encode_slice_shd
Definition: proresenc_kostya_vulkan.c:114
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:120
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:473
FFVulkanShader
Definition: vulkan.h:191
VulkanEncodeProresFrameData::slice_data_ref
AVBufferRef * slice_data_ref[2]
Definition: proresenc_kostya_vulkan.c:81
ProresVulkanContext::qf
AVVulkanDeviceQueueFamily * qf
Definition: proresenc_kostya_vulkan.c:102
proresdata.h
VulkanEncodeProresFrameData::frame_opaque
void * frame_opaque
Definition: proresenc_kostya_vulkan.c:88
AVCodecHWConfigInternal
Definition: hwconfig.h:25
FFVkBuffer::flags
VkMemoryPropertyFlagBits flags
Definition: vulkan.h:94
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:602
ProresVulkanContext::slice_score_buf_pool
AVBufferPool * slice_score_buf_pool
Definition: proresenc_kostya_vulkan.c:108
ProresVulkanContext::slice_quants
int * slice_quants
Definition: proresenc_kostya_vulkan.c:118
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
FFVkExecContext
Definition: vulkan.h:111
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:2621
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:609
init_alpha_data_pipeline
static int init_alpha_data_pipeline(ProresVulkanContext *pv, FFVulkanShader *shd)
Definition: proresenc_kostya_vulkan.c:186
VulkanEncodeProresFrameData::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: proresenc_kostya_vulkan.c:90
ProresVulkanContext::pkt_buf_pool
AVBufferPool * pkt_buf_pool
Definition: proresenc_kostya_vulkan.c:106
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:123
QUANT_MAT_STANDARD
@ QUANT_MAT_STANDARD
Definition: proresenc_kostya_common.h:62
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:100
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
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:124
ff_vk_exec_start
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition: vulkan.c:580
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:596
packet.h
SliceDataInfo::bits_per_sample
int bits_per_sample
Definition: proresenc_kostya_vulkan.c:55
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:706
ff_prores_ks_encode_slice_comp_spv_data
const unsigned char ff_prores_ks_encode_slice_comp_spv_data[]
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:93
PRORES_PROFILE_LT
@ PRORES_PROFILE_LT
Definition: proresenc_kostya_common.h:51
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:176
QUANT_MAT_DEFAULT
@ QUANT_MAT_DEFAULT
Definition: proresenc_kostya_common.h:65
FFVulkanContext::extensions
FFVulkanExtensions extensions
Definition: vulkan.h:280
SliceDataInfo::line_add
int line_add
Definition: proresenc_kostya_vulkan.c:54
ff_vk_free_buf
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
Definition: vulkan.c:1264
AVCodecContext::height
int height
Definition: avcodec.h:604
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:766
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:1471
avcodec.h
ff_vk_shader_add_descriptor_set
void ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, const FFVulkanDescriptorSetBinding *desc, int nb, int singular)
Add descriptor to a shader.
Definition: vulkan.c:2439
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:2010
FFVulkanContext::vkfn
FFVulkanFunctions vkfn
Definition: vulkan.h:279
ProresDataTables
Definition: proresenc_kostya_vulkan.c:47
FFVkExecContext::opaque
void * opaque
Definition: vulkan.h:128
PRORES_PROFILE_STANDARD
@ PRORES_PROFILE_STANDARD
Definition: proresenc_kostya_common.h:52
FFVkExecPool
Definition: vulkan.h:253
ProresDataTables::qmat_chroma
int16_t qmat_chroma[128][64]
Definition: proresenc_kostya_vulkan.c:49
SliceDataInfo
Definition: proresenc_kostya_vulkan.c:52
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
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:122
ProresVulkanContext::e
FFVkExecPool e
Definition: proresenc_kostya_vulkan.c:103
ProresVulkanContext::slice_data_buf_pool
AVBufferPool * slice_data_buf_pool
Definition: proresenc_kostya_vulkan.c:107
AVCodecContext
main external API structure.
Definition: avcodec.h:443
ProresVulkanContext::slice_scores
SliceScore * slice_scores
Definition: proresenc_kostya_vulkan.c:119
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:258
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:367
PRORES_PROFILE_4444XQ
@ PRORES_PROFILE_4444XQ
Definition: proresenc_kostya_common.h:55
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:75
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:73
VulkanEncodeProresFrameData::frame_size_ref
AVBufferRef * frame_size_ref[2]
Definition: proresenc_kostya_vulkan.c:83
QUANT_MAT_HQ
@ QUANT_MAT_HQ
Definition: proresenc_kostya_common.h:63
ProresVulkanContext::exec_ctx_info
VulkanEncodeProresFrameData * exec_ctx_info
Definition: proresenc_kostya_vulkan.c:125
desc
const char * desc
Definition: libsvtav1.c:83
ProresVulkanContext::trellis_node_shd
FFVulkanShader trellis_node_shd
Definition: proresenc_kostya_vulkan.c:115
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFVulkanContext::hwctx
AVVulkanDeviceContext * hwctx
Definition: vulkan.h:312
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:217
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:91
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:116
AVVulkanDeviceContext::act_dev
VkDevice act_dev
Active device.
Definition: hwcontext_vulkan.h:84
DCTSIZE
#define DCTSIZE
Definition: proresenc_kostya_vulkan.c:45
QUANT_MAT_LT
@ QUANT_MAT_LT
Definition: proresenc_kostya_common.h:61
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVPacket
This structure stores compressed data.
Definition: packet.h:580
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:470
FFVkBuffer
Definition: vulkan.h:91
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:604
bytestream.h
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:925
ProresVulkanContext::alpha_data_shd
FFVulkanShader alpha_data_shd
Definition: proresenc_kostya_vulkan.c:111
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVVulkanDeviceQueueFamily
Definition: hwcontext_vulkan.h:33
FFVulkanContext::frames
AVHWFramesContext * frames
Definition: vulkan.h:316
ProresVulkanContext::estimate_slice_shd
FFVulkanShader estimate_slice_shd
Definition: proresenc_kostya_vulkan.c:113
prores_ks_hw_configs
static const AVCodecHWConfigInternal *const prores_ks_hw_configs[]
Definition: proresenc_kostya_vulkan.c:989
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:275
put_bits.h
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:298
PRORES_PROFILE_HQ
@ PRORES_PROFILE_HQ
Definition: proresenc_kostya_common.h:53
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
FFVulkanFunctions
Definition: vulkan_functions.h:275
FFVkExecPool::pool_size
int pool_size
Definition: vulkan.h:259
SliceScore::total_error
int total_error[MAX_STORED_Q]
Definition: proresenc_kostya_vulkan.c:72
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
SliceScore::error
int error[MAX_STORED_Q][4]
Definition: proresenc_kostya_vulkan.c:70
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
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
proresenc_kostya_common.h