FFmpeg
ffv1enc_vulkan.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 Lynne <dev@lynne.ee>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/mem.h"
22 #include "libavutil/vulkan.h"
23 
24 #include "avcodec.h"
25 #include "internal.h"
26 #include "hwconfig.h"
27 #include "encode.h"
28 #include "libavutil/opt.h"
29 #include "codec_internal.h"
30 
31 #include "ffv1.h"
32 #include "ffv1enc.h"
33 #include "ffv1_vulkan.h"
34 
35 /* Parallel Golomb alignment */
36 #define LG_ALIGN_W 32
37 #define LG_ALIGN_H 32
38 
39 /* Unlike the decoder, we need 4 lines (but really only 3) */
40 #define RGB_LINECACHE 4
41 
42 typedef struct VulkanEncodeFFv1FrameData {
43  /* Output data */
45 
46  /* Copied from the source */
49  void *frame_opaque;
51 
52  int key_frame;
53  int idx;
55 
56 typedef struct VulkanEncodeFFv1Context {
59 
63 
66 
67  VkBufferCopy *buf_regions;
69  int in_flight;
71  size_t max_heap_size;
72 
78 
79  /* Constant read-only buffers */
81 
82  /* Results buffer */
84 
85  /* Slice data buffer pool */
88 
89  /* Remap data pool */
91 
92  /* Output data buffer */
94 
95  /* Intermediate frame pool */
97 
102 
103  int is_rgb;
104  int ppi;
105  int chunks;
107 
108 extern const char *ff_source_common_comp;
109 extern const char *ff_source_rangecoder_comp;
110 extern const char *ff_source_ffv1_vlc_comp;
111 extern const char *ff_source_ffv1_common_comp;
112 extern const char *ff_source_ffv1_enc_comp;
113 
114 extern const unsigned char ff_ffv1_enc_setup_comp_spv_data[];
115 extern const unsigned int ff_ffv1_enc_setup_comp_spv_len;
116 
117 extern const unsigned char ff_ffv1_enc_reset_comp_spv_data[];
118 extern const unsigned int ff_ffv1_enc_reset_comp_spv_len;
119 
120 extern const unsigned char ff_ffv1_enc_reset_golomb_comp_spv_data[];
121 extern const unsigned int ff_ffv1_enc_reset_golomb_comp_spv_len;
122 
123 extern const unsigned char ff_ffv1_enc_comp_spv_data[];
124 extern const unsigned int ff_ffv1_enc_comp_spv_len;
125 
126 extern const unsigned char ff_ffv1_enc_rgb_comp_spv_data[];
127 extern const unsigned int ff_ffv1_enc_rgb_comp_spv_len;
128 
129 extern const unsigned char ff_ffv1_enc_golomb_comp_spv_data[];
130 extern const unsigned int ff_ffv1_enc_golomb_comp_spv_len;
131 
132 extern const unsigned char ff_ffv1_enc_rgb_golomb_comp_spv_data[];
133 extern const unsigned int ff_ffv1_enc_rgb_golomb_comp_spv_len;
134 
135 extern const unsigned char ff_ffv1_enc_rct_search_comp_spv_data[];
136 extern const unsigned int ff_ffv1_enc_rct_search_comp_spv_len;
137 
138 extern const unsigned char ff_ffv1_enc_remap_comp_spv_data[];
139 extern const unsigned int ff_ffv1_enc_remap_comp_spv_len;
140 
141 extern const unsigned char ff_ffv1_enc_rgb_float_comp_spv_data[];
142 extern const unsigned int ff_ffv1_enc_rgb_float_comp_spv_len;
143 
145  AVFrame *enc_in, VkImageView *enc_in_views,
146  FFVkBuffer *slice_data_buf, uint32_t slice_data_size,
147  FFv1ShaderParams *pd)
148 {
149  VulkanEncodeFFv1Context *fv = avctx->priv_data;
150  FFV1Context *f = &fv->ctx;
151  FFVulkanFunctions *vk = &fv->s.vkfn;
152 
153  /* Update descriptors */
155  1, 0, 0,
156  slice_data_buf,
157  0, slice_data_size*f->slice_count,
158  VK_FORMAT_UNDEFINED);
159  ff_vk_shader_update_img_array(&fv->s, exec, &fv->rct_search,
160  enc_in, enc_in_views,
161  1, 1,
162  VK_IMAGE_LAYOUT_GENERAL,
163  VK_NULL_HANDLE);
164 
165  ff_vk_exec_bind_shader(&fv->s, exec, &fv->rct_search);
167  VK_SHADER_STAGE_COMPUTE_BIT,
168  0, sizeof(FFv1ShaderParams), pd);
169 
170  vk->CmdDispatch(exec->buf, fv->ctx.num_h_slices, fv->ctx.num_v_slices, 1);
171 
172  return 0;
173 }
174 
175 static int run_remap(AVCodecContext *avctx, FFVkExecContext *exec,
176  AVFrame *enc_in, VkImageView *enc_in_views,
177  FFVkBuffer *fltmap_buf, uint32_t fltmap_size,
178  FFv1ShaderParams *pd)
179 {
180  VulkanEncodeFFv1Context *fv = avctx->priv_data;
181  FFV1Context *f = &fv->ctx;
182  FFVulkanFunctions *vk = &fv->s.vkfn;
183 
184  /* Update descriptors */
185  ff_vk_shader_update_img_array(&fv->s, exec, &fv->remap,
186  enc_in, enc_in_views,
187  1, 1,
188  VK_IMAGE_LAYOUT_GENERAL,
189  VK_NULL_HANDLE);
190  ff_vk_shader_update_desc_buffer(&fv->s, exec, &fv->remap,
191  1, 2, 0,
192  fltmap_buf,
193  0, fltmap_size*f->slice_count,
194  VK_FORMAT_UNDEFINED);
195 
196  ff_vk_exec_bind_shader(&fv->s, exec, &fv->remap);
197  ff_vk_shader_update_push_const(&fv->s, exec, &fv->remap,
198  VK_SHADER_STAGE_COMPUTE_BIT,
199  0, sizeof(FFv1ShaderParams), pd);
200 
201  vk->CmdDispatch(exec->buf, fv->ctx.num_h_slices, fv->ctx.num_v_slices, 1);
202 
203  return 0;
204 }
205 
207  FFVkExecContext *exec,
208  const AVFrame *pict)
209 {
210  int err;
211  VulkanEncodeFFv1Context *fv = avctx->priv_data;
212  FFV1Context *f = &fv->ctx;
213  FFVulkanFunctions *vk = &fv->s.vkfn;
214 
215  VulkanEncodeFFv1FrameData *fd = exec->opaque;
216 
217  /* Slice data */
218  AVBufferRef *slice_data_ref;
219  FFVkBuffer *slice_data_buf;
220  uint32_t plane_state_size;
221  uint32_t slice_state_size;
222  uint32_t slice_data_size;
223 
224  /* Remap data */
225  AVBufferRef *remap_data_ref = NULL;
226  FFVkBuffer *remap_data_buf = NULL;
227  uint32_t remap_data_size = 0;
228 
229  /* Output data */
230  size_t maxsize;
231  FFVkBuffer *out_data_buf;
232 
233  int has_inter = avctx->gop_size > 1;
234  uint32_t context_count = f->context_count[f->context_model];
235 
236  VkImageMemoryBarrier2 img_bar[37];
237  int nb_img_bar = 0;
238  VkBufferMemoryBarrier2 buf_bar[8];
239  int nb_buf_bar = 0;
240 
241  /* Frame state */
242  f->cur_enc_frame = pict;
243  if (avctx->gop_size == 0 || f->picture_number % avctx->gop_size == 0) {
245  f->key_frame = fd->key_frame = 1;
246  f->gob_count++;
247  } else {
248  f->key_frame = fd->key_frame = 0;
249  }
250 
251  f->slice_count = f->max_slice_count;
252 
253  /* Allocate slice buffer data */
254  if (f->ac == AC_GOLOMB_RICE)
255  plane_state_size = 8;
256  else
257  plane_state_size = CONTEXT_SIZE;
258 
259  plane_state_size *= context_count;
260  slice_state_size = plane_state_size*f->plane_count;
261 
262  slice_data_size = 256; /* Overestimation for the SliceContext struct */
263  slice_state_size += slice_data_size;
264  slice_state_size = FFALIGN(slice_state_size, 8);
265 
266  /* Allocate slice data buffer */
267  slice_data_ref = fv->keyframe_slice_data_ref;
268  if (!slice_data_ref) {
270  &slice_data_ref,
271  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
272  NULL, slice_state_size*f->slice_count,
273  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT));
274 
275  /* Only save it if we're going to use it again */
276  if (has_inter)
277  fv->keyframe_slice_data_ref = slice_data_ref;
278  }
279  slice_data_buf = (FFVkBuffer *)slice_data_ref->data;
280 
281  if (f->remap_mode) {
283  remap_data_size = 4*(1 << desc->comp[0].depth)*sizeof(uint32_t);
284 
286  &remap_data_ref,
287  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
288  NULL, remap_data_size*f->slice_count,
289  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT));
290 
291  remap_data_buf = (FFVkBuffer *)remap_data_ref->data;
292  }
293 
294  /* Output buffer size */
295  maxsize = ff_ffv1_encode_buffer_size(avctx);
296  maxsize = FFMIN(maxsize, fv->s.props_11.maxMemoryAllocationSize);
297 
298  /* Allocate output buffer */
299  VkMemoryPropertyFlagBits out_buf_flags;
300  if (maxsize < fv->max_heap_size) {
301  out_buf_flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
302  /* If we can't map host memory, we can't let the GPU copy its buffer. */
304  out_buf_flags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
305  } else {
306  out_buf_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
307  fv->s.host_cached_flag;
308  }
309 
311  &fd->out_data_ref,
312  VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
313  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
314  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
315  NULL, maxsize, out_buf_flags));
316  out_data_buf = (FFVkBuffer *)fd->out_data_ref->data;
317 
318  /* Image views */
319  AVFrame *src = (AVFrame *)pict;
320  VkImageView src_views[AV_NUM_DATA_POINTERS];
321 
322  AVFrame *tmp = NULL;
323  VkImageView tmp_views[AV_NUM_DATA_POINTERS];
324  if (fv->is_rgb) {
325  /* Create a temporaty frame */
326  tmp = av_frame_alloc();
327  if (!(tmp))
328  return AVERROR(ENOMEM);
329 
331  tmp, 0));
332  }
333 
334  /* With everything allocated, setup push data */
335  FFv1ShaderParams pd = {
336  .slice_data = out_data_buf->address,
337 
338  .img_size[0] = fv->s.frames->width,
339  .img_size[1] = fv->s.frames->height,
340 
341  .plane_state_size = plane_state_size,
342  .key_frame = f->key_frame,
343  .crcref = f->crcref,
344  .micro_version = f->micro_version,
345 
346  .sar[0] = pict->sample_aspect_ratio.num,
347  .sar[1] = pict->sample_aspect_ratio.den,
348  .pic_mode = !(pict->flags & AV_FRAME_FLAG_INTERLACED) ? 3 :
349  !(pict->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST) ? 2 : 1,
350  .slice_size_max = out_data_buf->size / f->slice_count,
351  };
352 
353  for (int i = 0; i < f->quant_table_count; i++) {
354  pd.context_count[i] = f->context_count[i];
355  pd.extend_lookup[i] = f->quant_tables[i][3][127] ||
356  f->quant_tables[i][4][127];
357  }
358 
359  /* For some reason the C FFv1 encoder/decoder treats these differently */
360  if (avctx->sw_pix_fmt == AV_PIX_FMT_GBRP10 ||
361  avctx->sw_pix_fmt == AV_PIX_FMT_GBRP12 ||
362  avctx->sw_pix_fmt == AV_PIX_FMT_GBRP14)
363  memcpy(pd.fmt_lut, (int [4]) { 2, 1, 0, 3 }, 4*sizeof(int));
364  else
365  ff_vk_set_perm(avctx->sw_pix_fmt, pd.fmt_lut, 1);
366 
367  /* Start recording */
368  ff_vk_exec_start(&fv->s, exec);
369  fd->idx = exec->idx;
370 
371  RET(ff_vk_create_imageviews(&fv->s, exec, src_views, src,
373 
374  ff_vk_exec_add_dep_buf(&fv->s, exec, &slice_data_ref, 1, has_inter);
375  ff_vk_exec_add_dep_buf(&fv->s, exec, &fd->out_data_ref, 1, 1);
376  if (f->remap_mode) {
377  ff_vk_exec_add_dep_buf(&fv->s, exec, &remap_data_ref, 1, 0);
378  remap_data_ref = NULL;
379  }
380 
381  RET(ff_vk_exec_add_dep_frame(&fv->s, exec, src,
382  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
383  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
384  if (fv->is_rgb)
385  RET(ff_vk_exec_add_dep_frame(&fv->s, exec, tmp,
386  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
387  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
388 
389  if (fv->optimize_rct || f->remap_mode) {
390  /* Prepare the frame for reading */
391  ff_vk_frame_barrier(&fv->s, exec, src, img_bar, &nb_img_bar,
392  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
393  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
394  VK_ACCESS_SHADER_READ_BIT,
395  VK_IMAGE_LAYOUT_GENERAL,
396  VK_QUEUE_FAMILY_IGNORED);
397 
398  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
399  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
400  .pImageMemoryBarriers = img_bar,
401  .imageMemoryBarrierCount = nb_img_bar,
402  });
403  nb_img_bar = 0;
404  }
405 
406  /* Run RCT search if needed */
407  if (fv->optimize_rct) {
408  RET(run_rct_search(avctx, exec, src, src_views,
409  slice_data_buf, slice_data_size, &pd));
410 
411  /* Make sure the writes are visible to the setup shader */
412  ff_vk_buf_barrier(buf_bar[nb_buf_bar++], slice_data_buf,
413  COMPUTE_SHADER_BIT, SHADER_READ_BIT, SHADER_WRITE_BIT,
414  COMPUTE_SHADER_BIT, SHADER_READ_BIT, SHADER_WRITE_BIT,
415  0, slice_data_size*f->slice_count);
416  }
417 
418  if (f->remap_mode) {
419  RET(run_remap(avctx, exec, src, src_views,
420  remap_data_buf, remap_data_size, &pd));
421 
422  /* Make sure the writes are visible to the setup shader */
423  ff_vk_buf_barrier(buf_bar[nb_buf_bar++], remap_data_buf,
424  COMPUTE_SHADER_BIT, SHADER_READ_BIT, SHADER_WRITE_BIT,
425  COMPUTE_SHADER_BIT, SHADER_READ_BIT, SHADER_WRITE_BIT,
426  0, remap_data_size*f->slice_count);
427  }
428 
429  if (fv->optimize_rct || f->remap_mode) {
430  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
431  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
432  .pBufferMemoryBarriers = buf_bar,
433  .bufferMemoryBarrierCount = nb_buf_bar,
434  });
435  nb_buf_bar = 0;
436  }
437 
438  /* Setup shader */
439  ff_vk_shader_update_desc_buffer(&fv->s, exec, &fv->setup,
440  1, 0, 0,
441  slice_data_buf,
442  0, slice_data_size*f->slice_count,
443  VK_FORMAT_UNDEFINED);
444  if (f->remap_mode)
446  &fv->setup, 1, 1, 0,
447  remap_data_buf,
448  0, remap_data_size*f->slice_count,
449  VK_FORMAT_UNDEFINED);
450 
451  ff_vk_exec_bind_shader(&fv->s, exec, &fv->setup);
452  ff_vk_shader_update_push_const(&fv->s, exec, &fv->setup,
453  VK_SHADER_STAGE_COMPUTE_BIT,
454  0, sizeof(FFv1ShaderParams), &pd);
455 
456  vk->CmdDispatch(exec->buf, fv->ctx.num_h_slices, fv->ctx.num_v_slices, 1);
457 
458  /* Clean up temporary image if needed */
459  if (fv->is_rgb) {
460  AVVkFrame *vkf = (AVVkFrame *)tmp->data[0];
461  vkf->layout[0] = VK_IMAGE_LAYOUT_UNDEFINED;
462  vkf->access[0] = VK_ACCESS_2_NONE;
463 
464  RET(ff_vk_create_imageviews(&fv->s, exec, tmp_views,
465  tmp,
467 
468  ff_vk_frame_barrier(&fv->s, exec, tmp, img_bar, &nb_img_bar,
469  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
470  VK_PIPELINE_STAGE_2_CLEAR_BIT,
471  VK_ACCESS_2_TRANSFER_WRITE_BIT,
472  VK_IMAGE_LAYOUT_GENERAL,
473  VK_QUEUE_FAMILY_IGNORED);
474  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
475  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
476  .pImageMemoryBarriers = img_bar,
477  .imageMemoryBarrierCount = nb_img_bar,
478  });
479  nb_img_bar = 0;
480 
481  vk->CmdClearColorImage(exec->buf, vkf->img[0], VK_IMAGE_LAYOUT_GENERAL,
482  &((VkClearColorValue) { 0 }),
483  1, &((VkImageSubresourceRange) {
484  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
485  .levelCount = 1,
486  .layerCount = 1,
487  }));
488  }
489 
490  /* Run reset shader */
491  if (f->key_frame || fv->force_pcm) {
492  ff_vk_shader_update_desc_buffer(&fv->s, exec, &fv->reset,
493  1, 0, 0,
494  slice_data_buf,
495  0, slice_data_size*f->slice_count,
496  VK_FORMAT_UNDEFINED);
497  ff_vk_shader_update_desc_buffer(&fv->s, exec, &fv->reset,
498  1, 1, 0,
499  slice_data_buf,
500  f->slice_count*256,
501  VK_WHOLE_SIZE,
502  VK_FORMAT_UNDEFINED);
503 
504  ff_vk_exec_bind_shader(&fv->s, exec, &fv->reset);
505  ff_vk_shader_update_push_const(&fv->s, exec, &fv->reset,
506  VK_SHADER_STAGE_COMPUTE_BIT,
507  0, sizeof(FFv1ShaderParams), &pd);
508 
509  vk->CmdDispatch(exec->buf, fv->ctx.num_h_slices, fv->ctx.num_v_slices,
510  f->plane_count);
511  }
512 
513  /* Sync between reset and encode shaders */
514  ff_vk_buf_barrier(buf_bar[nb_buf_bar++], slice_data_buf,
515  COMPUTE_SHADER_BIT, SHADER_WRITE_BIT, NONE_KHR,
516  COMPUTE_SHADER_BIT, SHADER_READ_BIT, SHADER_WRITE_BIT,
517  0, slice_data_size*f->slice_count);
518  if (f->key_frame || fv->force_pcm)
519  ff_vk_buf_barrier(buf_bar[nb_buf_bar++], slice_data_buf,
520  COMPUTE_SHADER_BIT, SHADER_WRITE_BIT, NONE_KHR,
521  COMPUTE_SHADER_BIT, SHADER_READ_BIT, SHADER_WRITE_BIT,
522  slice_data_size*f->slice_count, VK_WHOLE_SIZE);
523  else
524  ff_vk_buf_barrier(buf_bar[nb_buf_bar++], slice_data_buf,
525  COMPUTE_SHADER_BIT, SHADER_READ_BIT, SHADER_WRITE_BIT,
526  COMPUTE_SHADER_BIT, SHADER_READ_BIT, SHADER_WRITE_BIT,
527  slice_data_size*f->slice_count, VK_WHOLE_SIZE);
528 
529  ff_vk_frame_barrier(&fv->s, exec, src, img_bar, &nb_img_bar,
530  fv->optimize_rct ? VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT :
531  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
532  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
533  VK_ACCESS_SHADER_READ_BIT,
534  VK_IMAGE_LAYOUT_GENERAL,
535  VK_QUEUE_FAMILY_IGNORED);
536 
537  if (fv->is_rgb)
538  ff_vk_frame_barrier(&fv->s, exec, tmp, img_bar, &nb_img_bar,
539  VK_PIPELINE_STAGE_2_CLEAR_BIT,
540  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
541  VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
542  VK_IMAGE_LAYOUT_GENERAL,
543  VK_QUEUE_FAMILY_IGNORED);
544 
545  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
546  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
547  .pImageMemoryBarriers = img_bar,
548  .imageMemoryBarrierCount = nb_img_bar,
549  .pBufferMemoryBarriers = buf_bar,
550  .bufferMemoryBarrierCount = nb_buf_bar,
551  });
552  nb_img_bar = 0;
553  nb_buf_bar = 0;
554 
555  /* Main encode shader */
556  ff_vk_shader_update_desc_buffer(&fv->s, exec, &fv->enc,
557  1, 0, 0,
558  slice_data_buf,
559  0, slice_data_size*f->slice_count,
560  VK_FORMAT_UNDEFINED);
562  &fv->enc, 1, 1, 0,
563  &fv->results_buf,
564  fd->idx*f->max_slice_count*sizeof(uint32_t),
565  f->slice_count*sizeof(uint32_t),
566  VK_FORMAT_UNDEFINED);
567  ff_vk_shader_update_desc_buffer(&fv->s, exec, &fv->enc,
568  1, 2, 0,
569  slice_data_buf,
570  f->slice_count*256,
571  VK_WHOLE_SIZE,
572  VK_FORMAT_UNDEFINED);
573  ff_vk_shader_update_img_array(&fv->s, exec, &fv->enc,
574  src, src_views,
575  1, 3,
576  VK_IMAGE_LAYOUT_GENERAL,
577  VK_NULL_HANDLE);
578  if (fv->is_rgb)
579  ff_vk_shader_update_img_array(&fv->s, exec, &fv->enc,
580  tmp, tmp_views,
581  1, 4,
582  VK_IMAGE_LAYOUT_GENERAL,
583  VK_NULL_HANDLE);
584  if (f->remap_mode)
586  &fv->enc, 1, 5, 0,
587  remap_data_buf,
588  0, remap_data_size*f->slice_count,
589  VK_FORMAT_UNDEFINED);
590 
591  ff_vk_exec_bind_shader(&fv->s, exec, &fv->enc);
592  ff_vk_shader_update_push_const(&fv->s, exec, &fv->enc,
593  VK_SHADER_STAGE_COMPUTE_BIT,
594  0, sizeof(FFv1ShaderParams), &pd);
595  vk->CmdDispatch(exec->buf, fv->ctx.num_h_slices, fv->ctx.num_v_slices, 1);
596 
597  /* Submit */
598  err = ff_vk_exec_submit(&fv->s, exec);
599  if (err < 0)
600  return err;
601 
602  f->picture_number++;
603 
604  /* This, if needed, was referenced by the execution context
605  * as it was declared as a dependency. */
606  av_frame_free(&tmp);
607  return 0;
608 
609 fail:
610  av_frame_free(&tmp);
611  ff_vk_exec_discard_deps(&fv->s, exec);
612 
613  return err;
614 }
615 
616 static int transfer_slices(AVCodecContext *avctx,
617  VkBufferCopy *buf_regions, int nb_regions,
619  uint8_t *dst, AVBufferRef *dst_ref)
620 {
621  int err;
622  VulkanEncodeFFv1Context *fv = avctx->priv_data;
623  FFVulkanFunctions *vk = &fv->s.vkfn;
624  FFVkExecContext *exec;
625 
626  FFVkBuffer *out_data_buf = (FFVkBuffer *)fd->out_data_ref->data;
627 
628  AVBufferRef *mapped_ref;
629  FFVkBuffer *mapped_buf;
630 
631  VkBufferMemoryBarrier2 buf_bar[8];
632  int nb_buf_bar = 0;
633 
634  err = ff_vk_host_map_buffer(&fv->s, &mapped_ref, dst, dst_ref,
635  VK_BUFFER_USAGE_TRANSFER_DST_BIT);
636  if (err < 0)
637  return err;
638 
639  mapped_buf = (FFVkBuffer *)mapped_ref->data;
640 
641  /* Transfer the slices */
642  exec = ff_vk_exec_get(&fv->s, &fv->transfer_exec_pool);
643  ff_vk_exec_start(&fv->s, exec);
644 
645  ff_vk_exec_add_dep_buf(&fv->s, exec, &fd->out_data_ref, 1, 0);
646  fd->out_data_ref = NULL; /* Ownership passed */
647 
648  ff_vk_exec_add_dep_buf(&fv->s, exec, &mapped_ref, 1, 0);
649  mapped_ref = NULL; /* Ownership passed */
650 
651  /* Ensure the output buffer is finished */
652  ff_vk_buf_barrier(buf_bar[nb_buf_bar++], out_data_buf,
653  COMPUTE_SHADER_BIT, SHADER_WRITE_BIT, NONE_KHR,
654  TRANSFER_BIT, TRANSFER_READ_BIT, NONE_KHR,
655  0, VK_WHOLE_SIZE);
656  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
657  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
658  .pBufferMemoryBarriers = buf_bar,
659  .bufferMemoryBarrierCount = nb_buf_bar,
660  });
661  nb_buf_bar = 0;
662 
663  for (int i = 0; i < nb_regions; i++)
664  buf_regions[i].dstOffset += mapped_buf->virtual_offset;
665 
666  vk->CmdCopyBuffer(exec->buf,
667  out_data_buf->buf, mapped_buf->buf,
668  nb_regions, buf_regions);
669 
670  /* Submit */
671  err = ff_vk_exec_submit(&fv->s, exec);
672  if (err < 0)
673  return err;
674 
675  /* We need the encoded data immediately */
676  ff_vk_exec_wait(&fv->s, exec);
677 
678  return 0;
679 }
680 
681 static int get_packet(AVCodecContext *avctx, FFVkExecContext *exec,
682  AVPacket *pkt)
683 {
684  int err;
685  VulkanEncodeFFv1Context *fv = avctx->priv_data;
686  FFV1Context *f = &fv->ctx;
687  FFVulkanFunctions *vk = &fv->s.vkfn;
688  VulkanEncodeFFv1FrameData *fd = exec->opaque;
689 
690  FFVkBuffer *out_data_buf = (FFVkBuffer *)fd->out_data_ref->data;
691  uint32_t slice_size_max = out_data_buf->size / f->slice_count;
692 
693  /* Make sure encoding's done */
694  ff_vk_exec_wait(&fv->s, exec);
695 
696  /* Invalidate slice/output data if needed */
697  uint32_t rb_off = fd->idx*f->max_slice_count*sizeof(uint32_t);
698  if (!(fv->results_buf.flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
699  VkMappedMemoryRange invalidate_data = {
700  .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
701  .memory = fv->results_buf.mem,
702  .offset = rb_off,
703  .size = f->slice_count*sizeof(uint32_t),
704  };
705  vk->InvalidateMappedMemoryRanges(fv->s.hwctx->act_dev,
706  1, &invalidate_data);
707  }
708 
709  /* Calculate final size */
710  pkt->size = 0;
711  uint8_t *rb = fv->results_buf.mapped_mem + rb_off;
712  for (int i = 0; i < f->slice_count; i++) {
713  uint32_t sl_len = AV_RN32(rb + i*4);
714  av_log(avctx, AV_LOG_DEBUG, "Slice %i size = %u\n", i, sl_len);
715 
716  fv->buf_regions[i] = (VkBufferCopy) {
717  .srcOffset = i*slice_size_max,
718  .dstOffset = pkt->size,
719  .size = sl_len,
720  };
721  pkt->size += sl_len;
722  }
723  av_log(avctx, AV_LOG_VERBOSE, "Encoded data: %iMiB\n", pkt->size / (1024*1024));
724 
725  /* Allocate packet */
726  if ((err = ff_get_encode_buffer(avctx, pkt, pkt->size, 0)) < 0)
727  return err;
728 
729  pkt->pts = fd->pts;
730  pkt->dts = fd->pts;
731  pkt->duration = fd->duration;
733 
734  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
735  pkt->opaque = fd->frame_opaque;
737  fd->frame_opaque_ref = NULL;
738  }
739 
740  /* Try using host mapped memory transfers first */
742  err = transfer_slices(avctx, fv->buf_regions, f->slice_count, fd,
743  pkt->data, pkt->buf);
744  if (err >= 0)
745  return err;
746  }
747 
748  /* Invalidate slice/output data if needed */
749  if (!(out_data_buf->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
750  VkMappedMemoryRange invalidate_data = {
751  .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
752  .memory = out_data_buf->mem,
753  .offset = 0,
754  .size = VK_WHOLE_SIZE,
755  };
756  vk->InvalidateMappedMemoryRanges(fv->s.hwctx->act_dev,
757  1, &invalidate_data);
758  }
759 
760  /* Copy each slice */
761  for (int i = 0; i < f->slice_count; i++) {
762  VkBufferCopy *region = &fv->buf_regions[i];
763  memcpy(pkt->data + region->dstOffset,
764  out_data_buf->mapped_mem + region->srcOffset,
765  region->size);
766  }
767 
769 
770  return 0;
771 }
772 
774  AVPacket *pkt)
775 {
776  int err;
777  VulkanEncodeFFv1Context *fv = avctx->priv_data;
779  FFVkExecContext *exec;
780  AVFrame *frame;
781 
782  while (1) {
783  /* Roll an execution context */
784  exec = ff_vk_exec_get(&fv->s, &fv->exec_pool);
785 
786  /* If it had a frame, immediately output it */
787  if (exec->had_submission) {
788  exec->had_submission = 0;
789  fv->in_flight--;
790  return get_packet(avctx, exec, pkt);
791  }
792 
793  /* Get next frame to encode */
794  frame = fv->frame;
795  err = ff_encode_get_frame(avctx, frame);
796  if (err < 0 && err != AVERROR_EOF) {
797  return err;
798  } else if (err == AVERROR_EOF) {
799  if (!fv->in_flight)
800  return err;
801  continue;
802  }
803 
804  /* Encode frame */
805  fd = exec->opaque;
806  fd->pts = frame->pts;
807  fd->duration = frame->duration;
808  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
809  fd->frame_opaque = frame->opaque;
810  fd->frame_opaque_ref = frame->opaque_ref;
811  frame->opaque_ref = NULL;
812  }
813 
814  err = vulkan_encode_ffv1_submit_frame(avctx, exec, frame);
816  if (err < 0)
817  return err;
818 
819  fv->in_flight++;
820  if (fv->in_flight < fv->async_depth)
821  return AVERROR(EAGAIN);
822  }
823 
824  return 0;
825 }
826 
827 static int init_indirect(AVCodecContext *avctx, enum AVPixelFormat sw_format)
828 {
829  int err;
830  VulkanEncodeFFv1Context *fv = avctx->priv_data;
831  FFV1Context *f = &fv->ctx;
832  AVHWFramesContext *frames_ctx;
833  AVVulkanFramesContext *vk_frames;
834 
836  if (!fv->intermediate_frames_ref)
837  return AVERROR(ENOMEM);
838 
839  frames_ctx = (AVHWFramesContext *)fv->intermediate_frames_ref->data;
840  frames_ctx->format = AV_PIX_FMT_VULKAN;
841  frames_ctx->sw_format = sw_format;
842  frames_ctx->width = fv->s.frames->width;
843  frames_ctx->height = f->num_v_slices*RGB_LINECACHE;
844 
845  vk_frames = frames_ctx->hwctx;
846  vk_frames->tiling = VK_IMAGE_TILING_OPTIMAL;
847  vk_frames->usage = VK_IMAGE_USAGE_STORAGE_BIT |
848  VK_IMAGE_USAGE_TRANSFER_DST_BIT;
849  vk_frames->img_flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
850 
852  if (err < 0) {
853  av_log(avctx, AV_LOG_ERROR, "Unable to initialize frame pool with format %s: %s\n",
854  av_get_pix_fmt_name(sw_format), av_err2str(err));
856  return err;
857  }
858 
859  return 0;
860 }
861 
862 static int init_rct_search_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
863 {
864  int err;
865  VulkanEncodeFFv1Context *fv = avctx->priv_data;
866  FFVulkanShader *shd = &fv->rct_search;
867 
868  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
869  (uint32_t []) { 32, 32, 1 }, 0);
870 
872  VK_SHADER_STAGE_COMPUTE_BIT);
873 
874  const FFVulkanDescriptorSetBinding desc_set_const[] = {
875  { /* rangecoder_buf */
876  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
877  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
878  },
879  };
880  ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set_const, 1, 1, 0);
881 
882  const FFVulkanDescriptorSetBinding desc_set[] = {
883  { /* slice_data_buf */
884  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
885  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
886  },
887  { /* src */
888  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
889  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
890  .elems = av_pix_fmt_count_planes(fv->s.frames->sw_format),
891  },
892  };
893  ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 2, 0, 0);
894 
895  RET(ff_vk_shader_link(&fv->s, shd,
898 
899  RET(ff_vk_shader_register_exec(&fv->s, &fv->exec_pool, shd));
900 
901 fail:
902  return err;
903 }
904 
905 static int init_remap_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
906 {
907  int err;
908  VulkanEncodeFFv1Context *fv = avctx->priv_data;
909  FFVulkanShader *shd = &fv->remap;
910 
911  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
912  (uint32_t []) { 32, 32, 1 }, 0);
913 
915  VK_SHADER_STAGE_COMPUTE_BIT);
916 
917  const FFVulkanDescriptorSetBinding desc_set_const[] = {
918  { /* rangecoder_buf */
919  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
920  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
921  },
922  };
923  ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set_const, 1, 1, 0);
924 
925  const FFVulkanDescriptorSetBinding desc_set[] = {
926  { /* slice_data_buf */
927  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
928  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
929  },
930  { /* src */
931  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
932  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
933  .elems = av_pix_fmt_count_planes(fv->s.frames->sw_format),
934  },
935  { /* fltmap */
936  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
937  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
938  },
939  };
940  ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 3, 0, 0);
941 
942  RET(ff_vk_shader_link(&fv->s, shd,
945 
946  RET(ff_vk_shader_register_exec(&fv->s, &fv->exec_pool, shd));
947 
948 fail:
949  return err;
950 }
951 
952 static int init_setup_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
953 {
954  int err;
955  VulkanEncodeFFv1Context *fv = avctx->priv_data;
956  FFVulkanShader *shd = &fv->setup;
957 
958  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
959  (uint32_t []) { 1, 1, 1 }, 0);
960 
962  VK_SHADER_STAGE_COMPUTE_BIT);
963 
964  const FFVulkanDescriptorSetBinding desc_set_const[] = {
965  { /* rangecoder_buf */
966  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
967  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
968  },
969  };
970  ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set_const, 1, 1, 0);
971 
972  const FFVulkanDescriptorSetBinding desc_set[] = {
973  { /* slice_data_buf */
974  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
975  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
976  },
977  { /* fltmap */
978  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
979  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
980  },
981  };
982  ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 2, 0, 0);
983 
984  RET(ff_vk_shader_link(&fv->s, shd,
987 
988  RET(ff_vk_shader_register_exec(&fv->s, &fv->exec_pool, shd));
989 
990 fail:
991  return err;
992 }
993 
994 static int init_reset_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
995 {
996  int err;
997  VulkanEncodeFFv1Context *fv = avctx->priv_data;
998  FFVulkanShader *shd = &fv->reset;
999 
1000  int wg_dim = FFMIN(fv->s.props.properties.limits.maxComputeWorkGroupSize[0], 1024);
1001 
1002  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
1003  (uint32_t []) { wg_dim, 1, 1 }, 0);
1004 
1006  VK_SHADER_STAGE_COMPUTE_BIT);
1007 
1008  const FFVulkanDescriptorSetBinding desc_set_const[] = {
1009  { /* rangecoder_buf */
1010  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1011  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1012  },
1013  };
1014  ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set_const, 1, 1, 0);
1015 
1016  const FFVulkanDescriptorSetBinding desc_set[] = {
1017  { /* slice_data_buf */
1018  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1019  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1020  },
1021  { /* slice_state_buf */
1022  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1023  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1024  },
1025  };
1026  ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 2, 0, 0);
1027 
1028  if (fv->ctx.ac == AC_GOLOMB_RICE)
1029  RET(ff_vk_shader_link(&fv->s, shd,
1032  else
1033  RET(ff_vk_shader_link(&fv->s, shd,
1036 
1037  RET(ff_vk_shader_register_exec(&fv->s, &fv->exec_pool, shd));
1038 
1039 fail:
1040  return err;
1041 }
1042 
1043 static int init_encode_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
1044 {
1045  int err;
1046  VulkanEncodeFFv1Context *fv = avctx->priv_data;
1047  FFV1Context *f = &fv->ctx;
1048  FFVulkanShader *shd = &fv->enc;
1049 
1050  uint32_t wg_x = fv->ctx.ac != AC_GOLOMB_RICE ? CONTEXT_SIZE : 1;
1051  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
1052  (uint32_t []) { wg_x, 1, 1 }, 0);
1053 
1055  VK_SHADER_STAGE_COMPUTE_BIT);
1056 
1057  const FFVulkanDescriptorSetBinding desc_set_const[] = {
1058  { /* rangecoder_buf */
1059  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1060  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1061  },
1062  { /* quant_buf */
1063  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1064  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1065  },
1066  { /* crc_ieee_buf */
1067  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1068  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1069  },
1070  };
1071  ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set_const, 3, 1, 0);
1072 
1073  const FFVulkanDescriptorSetBinding desc_set[] = {
1074  { /* slice_data_buf */
1075  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1076  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1077  },
1078  { /* slice_results_buf */
1079  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1080  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1081  },
1082  { /* slice_state_buf */
1083  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1084  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1085  },
1086  { /* src */
1087  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
1088  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1089  .elems = av_pix_fmt_count_planes(fv->s.frames->sw_format),
1090  },
1091  { /* tmp */
1092  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
1093  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1094  },
1095  { /* fltmap */
1096  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1097  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1098  },
1099  };
1100  ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set,
1101  4 + fv->is_rgb + !!f->remap_mode, 0, 0);
1102 
1103  if (f->remap_mode) {
1104  ff_vk_shader_link(&fv->s, shd,
1107  } else if (fv->ctx.ac == AC_GOLOMB_RICE) {
1108  if (fv->is_rgb)
1109  ff_vk_shader_link(&fv->s, shd,
1112  else
1113  ff_vk_shader_link(&fv->s, shd,
1116  } else {
1117  if (fv->is_rgb)
1118  ff_vk_shader_link(&fv->s, shd,
1121  else
1122  ff_vk_shader_link(&fv->s, shd,
1124  ff_ffv1_enc_comp_spv_len, "main");
1125  }
1126 
1127  RET(ff_vk_shader_register_exec(&fv->s, &fv->exec_pool, shd));
1128 
1129 fail:
1130  return err;
1131 }
1132 
1134 {
1135  int err;
1136  size_t maxsize, max_heap_size, max_host_size;
1137  VulkanEncodeFFv1Context *fv = avctx->priv_data;
1138  FFV1Context *f = &fv->ctx;
1139 
1140  if ((err = ff_ffv1_common_init(avctx, f)) < 0)
1141  return err;
1142 
1143  if (f->ac == 1)
1144  f->ac = AC_RANGE_CUSTOM_TAB;
1145 
1146  err = ff_ffv1_encode_setup_plane_info(avctx, avctx->sw_pix_fmt);
1147  if (err < 0)
1148  return err;
1149 
1150  /* Target version 3 by default */
1151  f->version = 3;
1152 
1153  err = ff_ffv1_encode_init(avctx);
1154  if (err < 0)
1155  return err;
1156 
1157  /* Rice coding did not support high bit depths */
1158  if (f->bits_per_raw_sample > (f->version > 3 ? 16 : 8)) {
1159  if (f->ac == AC_GOLOMB_RICE) {
1160  av_log(avctx, AV_LOG_WARNING, "bits_per_raw_sample > 8, "
1161  "forcing range coder\n");
1162  f->ac = AC_RANGE_CUSTOM_TAB;
1163  }
1164  }
1165 
1166  if (f->version < 4 && avctx->gop_size > 1) {
1167  av_log(avctx, AV_LOG_ERROR, "Using inter frames requires version 4 (-level 4)\n");
1168  return AVERROR_INVALIDDATA;
1169  }
1170 
1171  if (f->version == 4 && avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
1172  av_log(avctx, AV_LOG_ERROR, "Version 4 is experimental and requires -strict -2\n");
1173  return AVERROR_INVALIDDATA;
1174  }
1175 
1176  /* We target version 4.3 */
1177  if (f->version == 4)
1178  f->micro_version = f->remap_mode ? 9 : 3;
1179 
1180  f->num_h_slices = fv->num_h_slices;
1181  f->num_v_slices = fv->num_v_slices;
1182 
1183  if (f->num_h_slices <= 0 && f->num_v_slices <= 0) {
1184  if (avctx->slices) {
1185  err = ff_ffv1_encode_determine_slices(avctx);
1186  if (err < 0)
1187  return err;
1188  } else {
1189  f->num_h_slices = 32;
1190  f->num_v_slices = 32;
1191  }
1192  } else if (f->num_h_slices && f->num_v_slices <= 0) {
1193  f->num_v_slices = MAX_SLICES / f->num_h_slices;
1194  } else if (f->num_v_slices && f->num_h_slices <= 0) {
1195  f->num_h_slices = MAX_SLICES / f->num_v_slices;
1196  }
1197 
1198  f->num_h_slices = FFMIN(f->num_h_slices, avctx->width);
1199  f->num_v_slices = FFMIN(f->num_v_slices, avctx->height);
1200 
1201  if (f->num_h_slices * f->num_v_slices > MAX_SLICES) {
1202  av_log(avctx, AV_LOG_ERROR, "Too many slices (%i), maximum supported "
1203  "by the standard is %i\n",
1204  f->num_h_slices * f->num_v_slices, MAX_SLICES);
1205  return AVERROR_PATCHWELCOME;
1206  }
1207 
1208  f->max_slice_count = f->num_h_slices * f->num_v_slices;
1209 
1210  if ((err = ff_ffv1_write_extradata(avctx)) < 0)
1211  return err;
1212 
1213  if (f->version < 4) {
1214  if (((f->chroma_h_shift > 0) && (avctx->width % (64 << f->chroma_h_shift))) ||
1215  ((f->chroma_v_shift > 0) && (avctx->height % (64 << f->chroma_v_shift)))) {
1216  av_log(avctx, AV_LOG_ERROR, "Encoding frames with subsampling and unaligned "
1217  "dimensions is only supported in version 4 (-level 4)\n");
1218  return AVERROR_PATCHWELCOME;
1219  }
1220  }
1221 
1222  if (fv->force_pcm) {
1223  if (f->version < 4) {
1224  av_log(avctx, AV_LOG_ERROR, "PCM coding only supported by version 4 (-level 4)\n");
1225  return AVERROR_INVALIDDATA;
1226  } else if (f->ac == AC_GOLOMB_RICE) {
1227  av_log(avctx, AV_LOG_ERROR, "PCM coding requires range coding\n");
1228  return AVERROR_INVALIDDATA;
1229  }
1230  }
1231 
1232  /* Init Vulkan */
1233  err = ff_vk_init(&fv->s, avctx, NULL, avctx->hw_frames_ctx);
1234  if (err < 0)
1235  return err;
1236 
1237  fv->qf = ff_vk_qf_find(&fv->s, VK_QUEUE_COMPUTE_BIT, 0);
1238  if (!fv->qf) {
1239  av_log(avctx, AV_LOG_ERROR, "Device has no compute queues!\n");
1240  return err;
1241  }
1242 
1243  /* Try to measure VRAM size */
1244  max_heap_size = 0;
1245  max_host_size = 0;
1246  for (int i = 0; i < fv->s.mprops.memoryHeapCount; i++) {
1247  if (fv->s.mprops.memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT)
1248  max_heap_size = FFMAX(fv->max_heap_size,
1249  fv->s.mprops.memoryHeaps[i].size);
1250  if (!(fv->s.mprops.memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT))
1251  max_host_size = FFMAX(max_host_size,
1252  fv->s.mprops.memoryHeaps[i].size);
1253  }
1254  fv->max_heap_size = max_heap_size;
1255 
1256  maxsize = ff_ffv1_encode_buffer_size(avctx);
1257  if (maxsize > fv->s.props_11.maxMemoryAllocationSize) {
1258  av_log(avctx, AV_LOG_WARNING, "Encoding buffer size (%zu) larger "
1259  "than maximum device allocation (%zu), clipping\n",
1260  maxsize, fv->s.props_11.maxMemoryAllocationSize);
1261  maxsize = fv->s.props_11.maxMemoryAllocationSize;
1262  }
1263 
1264  if (max_heap_size < maxsize) {
1265  av_log(avctx, AV_LOG_WARNING, "Encoding buffer (%zu) larger than VRAM (%zu), "
1266  "using host memory (slower)\n",
1267  maxsize, fv->max_heap_size);
1268 
1269  /* Keep 1/2th of RAM as headroom */
1270  max_heap_size = max_host_size - (max_host_size >> 1);
1271  } else {
1272  /* Keep 1/8th of VRAM as headroom */
1273  max_heap_size = max_heap_size - (max_heap_size >> 3);
1274  }
1275 
1276  av_log(avctx, AV_LOG_INFO, "Async buffers: %zuMiB per context, %zuMiB total, depth: %i\n",
1277  maxsize / (1024*1024),
1278  (fv->async_depth * maxsize) / (1024*1024),
1279  fv->async_depth);
1280 
1281  err = ff_vk_exec_pool_init(&fv->s, fv->qf, &fv->exec_pool,
1282  fv->async_depth,
1283  0, 0, 0, NULL);
1284  if (err < 0)
1285  return err;
1286 
1287  fv->transfer_qf = ff_vk_qf_find(&fv->s, VK_QUEUE_TRANSFER_BIT, 0);
1288  if (!fv->transfer_qf) {
1289  av_log(avctx, AV_LOG_ERROR, "Device has no transfer queues!\n");
1290  return err;
1291  }
1292 
1293  err = ff_vk_exec_pool_init(&fv->s, fv->transfer_qf, &fv->transfer_exec_pool,
1294  1,
1295  0, 0, 0, NULL);
1296  if (err < 0)
1297  return err;
1298 
1299  /* Detect the special RGB coding mode */
1300  fv->is_rgb = !(f->colorspace == 0 && avctx->sw_pix_fmt != AV_PIX_FMT_YA8) &&
1301  !(avctx->sw_pix_fmt == AV_PIX_FMT_YA8);
1302 
1303  /* Init rct search shader */
1304  fv->optimize_rct = fv->is_rgb && f->version >= 4 &&
1305  !fv->force_pcm && fv->optimize_rct;
1306 
1307  /* Init shader specialization consts */
1308  SPEC_LIST_CREATE(sl, 19, 19*sizeof(uint32_t))
1309  SPEC_LIST_ADD(sl, 0, 32, RGB_LINECACHE);
1310  SPEC_LIST_ADD(sl, 1, 32, f->ec);
1311  ff_ffv1_vk_set_common_sl(avctx, f, sl, fv->s.frames->sw_format);
1312  SPEC_LIST_ADD(sl, 15, 32, fv->force_pcm);
1313  SPEC_LIST_ADD(sl, 16, 32, fv->optimize_rct);
1314  SPEC_LIST_ADD(sl, 17, 32, f->context_model);
1315  SPEC_LIST_ADD(sl, 18, 32, f->remap_mode);
1316 
1317  if (fv->optimize_rct) {
1318  err = init_rct_search_shader(avctx, sl);
1319  if (err < 0)
1320  return err;
1321  }
1322 
1323  if (f->remap_mode) {
1324  err = init_remap_shader(avctx, sl);
1325  if (err < 0)
1326  return err;
1327  }
1328 
1329  /* Init setup shader */
1330  err = init_setup_shader(avctx, sl);
1331  if (err < 0)
1332  return err;
1333 
1334  /* Init reset shader */
1335  err = init_reset_shader(avctx, sl);
1336  if (err < 0)
1337  return err;
1338 
1339  if (fv->is_rgb)
1340  RET(init_indirect(avctx, fv->ctx.use32bit ?
1342 
1343  /* Encode shader */
1344  err = init_encode_shader(avctx, sl);
1345  if (err < 0)
1346  return err;
1347 
1348  /* Constant data */
1349  err = ff_ffv1_vk_init_consts(&fv->s, &fv->consts_buf, f);
1350  if (err < 0)
1351  return err;
1352 
1353  /* Update setup global descriptors */
1355  &fv->setup, 0, 0, 0,
1356  &fv->consts_buf,
1357  256*sizeof(uint32_t), 512*sizeof(uint8_t),
1358  VK_FORMAT_UNDEFINED));
1359 
1360  /* Update encode global descriptors */
1362  &fv->enc, 0, 0, 0,
1363  &fv->consts_buf,
1364  256*sizeof(uint32_t), 512*sizeof(uint8_t),
1365  VK_FORMAT_UNDEFINED));
1367  &fv->enc, 0, 1, 0,
1368  &fv->consts_buf,
1369  256*sizeof(uint32_t) + 512*sizeof(uint8_t),
1370  VK_WHOLE_SIZE,
1371  VK_FORMAT_UNDEFINED));
1373  &fv->enc, 0, 2, 0,
1374  &fv->consts_buf,
1375  0, 256*sizeof(uint32_t),
1376  VK_FORMAT_UNDEFINED));
1377 
1378  /* Temporary frame */
1379  fv->frame = av_frame_alloc();
1380  if (!fv->frame)
1381  return AVERROR(ENOMEM);
1382 
1383  /* Async data pool */
1384  fv->async_depth = fv->exec_pool.pool_size;
1385  fv->exec_ctx_info = av_calloc(fv->async_depth, sizeof(*fv->exec_ctx_info));
1386  if (!fv->exec_ctx_info)
1387  return AVERROR(ENOMEM);
1388  for (int i = 0; i < fv->async_depth; i++)
1389  fv->exec_pool.contexts[i].opaque = &fv->exec_ctx_info[i];
1390 
1391  fv->buf_regions = av_malloc_array(f->max_slice_count, sizeof(*fv->buf_regions));
1392  if (!fv->buf_regions)
1393  return AVERROR(ENOMEM);
1394 
1395  /* Buffers */
1396  RET(ff_vk_create_buf(&fv->s, &fv->results_buf,
1397  fv->async_depth*f->max_slice_count*sizeof(uint32_t),
1398  NULL, NULL,
1399  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
1400  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
1401  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
1402  RET(ff_vk_map_buffer(&fv->s, &fv->results_buf, NULL, 0));
1403 
1404 fail:
1405  return err;
1406 }
1407 
1409 {
1410  VulkanEncodeFFv1Context *fv = avctx->priv_data;
1411 
1412  ff_vk_exec_pool_free(&fv->s, &fv->exec_pool);
1414 
1415  ff_vk_shader_free(&fv->s, &fv->enc);
1416  ff_vk_shader_free(&fv->s, &fv->reset);
1417  ff_vk_shader_free(&fv->s, &fv->setup);
1418  ff_vk_shader_free(&fv->s, &fv->remap);
1419  ff_vk_shader_free(&fv->s, &fv->rct_search);
1420 
1421  if (fv->exec_ctx_info) {
1422  for (int i = 0; i < fv->async_depth; i++) {
1426  }
1427  }
1428  av_free(fv->exec_ctx_info);
1429 
1431 
1433 
1437 
1438  ff_vk_free_buf(&fv->s, &fv->results_buf);
1439 
1440  ff_vk_free_buf(&fv->s, &fv->consts_buf);
1441 
1442  av_free(fv->buf_regions);
1443  av_frame_free(&fv->frame);
1444  ff_vk_uninit(&fv->s);
1445 
1446  return 0;
1447 }
1448 
1449 #define OFFSET(x) offsetof(VulkanEncodeFFv1Context, x)
1450 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1452  { "slicecrc", "Protect slices with CRCs", OFFSET(ctx.ec), AV_OPT_TYPE_INT,
1453  { .i64 = -1 }, -1, 2, VE },
1454  { "context", "Context model", OFFSET(ctx.context_model), AV_OPT_TYPE_INT,
1455  { .i64 = 0 }, 0, 1, VE },
1456  { "coder", "Coder type", OFFSET(ctx.ac), AV_OPT_TYPE_INT,
1457  { .i64 = AC_RANGE_CUSTOM_TAB }, -2, 2, VE, .unit = "coder" },
1458  { "rice", "Golomb rice", 0, AV_OPT_TYPE_CONST,
1459  { .i64 = AC_GOLOMB_RICE }, INT_MIN, INT_MAX, VE, .unit = "coder" },
1460  { "range_def", "Range with default table", 0, AV_OPT_TYPE_CONST,
1461  { .i64 = AC_RANGE_DEFAULT_TAB_FORCE }, INT_MIN, INT_MAX, VE, .unit = "coder" },
1462  { "range_tab", "Range with custom table", 0, AV_OPT_TYPE_CONST,
1463  { .i64 = AC_RANGE_CUSTOM_TAB }, INT_MIN, INT_MAX, VE, .unit = "coder" },
1464  { "qtable", "Quantization table", OFFSET(ctx.qtable), AV_OPT_TYPE_INT,
1465  { .i64 = -1 }, -1, 2, VE , .unit = "qtable"},
1466  { "default", NULL, 0, AV_OPT_TYPE_CONST,
1467  { .i64 = QTABLE_DEFAULT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },
1468  { "8bit", NULL, 0, AV_OPT_TYPE_CONST,
1469  { .i64 = QTABLE_8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },
1470  { "greater8bit", NULL, 0, AV_OPT_TYPE_CONST,
1471  { .i64 = QTABLE_GT8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },
1472 
1473  { "slices_h", "Number of horizontal slices", OFFSET(num_h_slices), AV_OPT_TYPE_INT,
1474  { .i64 = -1 }, -1, MAX_SLICES, VE },
1475  { "slices_v", "Number of vertical slices", OFFSET(num_v_slices), AV_OPT_TYPE_INT,
1476  { .i64 = -1 }, -1, MAX_SLICES, VE },
1477 
1478  { "force_pcm", "Code all slices with no prediction", OFFSET(force_pcm), AV_OPT_TYPE_BOOL,
1479  { .i64 = 0 }, 0, 1, VE },
1480 
1481  { "rct_search", "Run a search for RCT parameters (level 4 only)", OFFSET(optimize_rct), AV_OPT_TYPE_BOOL,
1482  { .i64 = 1 }, 0, 1, VE },
1483 
1484  { "async_depth", "Internal parallelization depth", OFFSET(async_depth), AV_OPT_TYPE_INT,
1485  { .i64 = 1 }, 1, INT_MAX, VE },
1486 
1487  { "remap_mode", "Remap Mode", OFFSET(ctx.remap_mode), AV_OPT_TYPE_INT,
1488  { .i64 = -1 }, -1, 2, VE, .unit = "remap_mode" },
1489  { "auto", "Automatic", 0, AV_OPT_TYPE_CONST,
1490  { .i64 = -1 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
1491  { "off", "Disabled", 0, AV_OPT_TYPE_CONST,
1492  { .i64 = 0 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
1493  { "dualrle", "Dual RLE", 0, AV_OPT_TYPE_CONST,
1494  { .i64 = 1 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
1495  { "flipdualrle", "Dual RLE", 0, AV_OPT_TYPE_CONST,
1496  { .i64 = 2 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
1497 
1498  { NULL }
1499 };
1500 
1502  { "g", "1" },
1503  { NULL },
1504 };
1505 
1507  .class_name = "ffv1_vulkan",
1508  .item_name = av_default_item_name,
1509  .option = vulkan_encode_ffv1_options,
1510  .version = LIBAVUTIL_VERSION_INT,
1511 };
1512 
1514  HW_CONFIG_ENCODER_FRAMES(VULKAN, VULKAN),
1515  NULL,
1516 };
1517 
1519  .p.name = "ffv1_vulkan",
1520  CODEC_LONG_NAME("FFmpeg video codec #1 (Vulkan)"),
1521  .p.type = AVMEDIA_TYPE_VIDEO,
1522  .p.id = AV_CODEC_ID_FFV1,
1523  .priv_data_size = sizeof(VulkanEncodeFFv1Context),
1526  .close = &vulkan_encode_ffv1_close,
1527  .p.priv_class = &vulkan_encode_ffv1_class,
1528  .p.capabilities = AV_CODEC_CAP_DELAY |
1534  .defaults = vulkan_encode_ffv1_defaults,
1536  .hw_configs = vulkan_encode_ffv1_hw_configs,
1537  .p.wrapper_name = "vulkan",
1538 };
hwconfig.h
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:1030
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
ff_ffv1_enc_golomb_comp_spv_len
const unsigned int ff_ffv1_enc_golomb_comp_spv_len
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
ff_ffv1_encode_determine_slices
int ff_ffv1_encode_determine_slices(AVCodecContext *avctx)
Definition: ffv1enc.c:566
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
ff_ffv1_enc_comp_spv_len
const unsigned int ff_ffv1_enc_comp_spv_len
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
AV_PIX_FMT_YA8
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:140
FFVulkanContext::props_11
VkPhysicalDeviceVulkan11Properties props_11
Definition: vulkan.h:319
ff_vk_shader_free
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition: vulkan.c:2810
AVBufferPool
The buffer pool.
Definition: buffer_internal.h:88
FFVulkanContext::device_ref
AVBufferRef * device_ref
Definition: vulkan.h:347
FFVkExecPool::contexts
FFVkExecContext * contexts
Definition: vulkan.h:291
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
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
FFv1ShaderParams::fmt_lut
int fmt_lut[4]
Definition: ffv1_vulkan.h:39
VulkanEncodeFFv1Context::is_rgb
int is_rgb
Definition: ffv1enc_vulkan.c:103
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:200
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
VulkanEncodeFFv1Context::in_flight
int in_flight
Definition: ffv1enc_vulkan.c:69
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:337
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
ff_vk_map_buffer
static int ff_vk_map_buffer(FFVulkanContext *s, FFVkBuffer *buf, uint8_t **mem, int invalidate)
Definition: vulkan.h:603
QTABLE_DEFAULT
@ QTABLE_DEFAULT
Definition: ffv1enc.h:29
VulkanEncodeFFv1Context::chunks
int chunks
Definition: ffv1enc_vulkan.c:105
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:263
internal.h
AC_RANGE_DEFAULT_TAB_FORCE
#define AC_RANGE_DEFAULT_TAB_FORCE
Definition: ffv1.h:55
AVPacket::data
uint8_t * data
Definition: packet.h:588
run_remap
static int run_remap(AVCodecContext *avctx, FFVkExecContext *exec, AVFrame *enc_in, VkImageView *enc_in_views, FFVkBuffer *fltmap_buf, uint32_t fltmap_size, FFv1ShaderParams *pd)
Definition: ffv1enc_vulkan.c:175
AVOption
AVOption.
Definition: opt.h:429
encode.h
VulkanEncodeFFv1Context::rct_search
FFVulkanShader rct_search
Definition: ffv1enc_vulkan.c:73
ff_source_ffv1_vlc_comp
const char * ff_source_ffv1_vlc_comp
AV_PIX_FMT_RGBA128
#define AV_PIX_FMT_RGBA128
Definition: pixfmt.h:630
ff_ffv1_write_extradata
av_cold int ff_ffv1_write_extradata(AVCodecContext *avctx)
Definition: ffv1enc.c:447
FFCodec
Definition: codec_internal.h:127
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
FFV1Context::num_h_slices
int num_h_slices
Definition: ffv1.h:175
FFVkBuffer::address
VkDeviceAddress address
Definition: vulkan.h:130
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:2848
ff_vk_exec_get
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition: vulkan.c:548
FF_VK_REP_NATIVE
@ FF_VK_REP_NATIVE
Definition: vulkan.h:449
ff_vk_uninit
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition: vulkan.c:2836
FF_COMPLIANCE_EXPERIMENTAL
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: defs.h:62
ff_ffv1_enc_rgb_float_comp_spv_len
const unsigned int ff_ffv1_enc_rgb_float_comp_spv_len
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:671
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
SPEC_LIST_ADD
#define SPEC_LIST_ADD(name, idx, val_bits, val)
Definition: vulkan.h:86
init_remap_shader
static int init_remap_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
Definition: ffv1enc_vulkan.c:905
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:220
AC_RANGE_CUSTOM_TAB
#define AC_RANGE_CUSTOM_TAB
Definition: ffv1.h:54
ff_vk_exec_bind_shader
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition: vulkan.c:2787
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:643
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
ff_ffv1_enc_remap_comp_spv_len
const unsigned int ff_ffv1_enc_remap_comp_spv_len
VulkanEncodeFFv1Context::results_buf
FFVkBuffer results_buf
Definition: ffv1enc_vulkan.c:83
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
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
vulkan_encode_ffv1_class
static const AVClass vulkan_encode_ffv1_class
Definition: ffv1enc_vulkan.c:1506
FFCodecDefault
Definition: codec_internal.h:96
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:560
AVVkFrame::img
VkImage img[AV_NUM_DATA_POINTERS]
Vulkan images to which the memory is bound to.
Definition: hwcontext_vulkan.h:315
VulkanEncodeFFv1FrameData::key_frame
int key_frame
Definition: ffv1enc_vulkan.c:52
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:624
VulkanEncodeFFv1Context::num_v_slices
int num_v_slices
Definition: ffv1enc_vulkan.c:99
fail
#define fail()
Definition: checkasm.h:223
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:558
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:2738
AVVulkanFramesContext
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
Definition: hwcontext_vulkan.h:220
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:2050
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:2603
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:496
VulkanEncodeFFv1Context::ppi
int ppi
Definition: ffv1enc_vulkan.c:104
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:1391
MAX_SLICES
#define MAX_SLICES
Definition: d3d12va_hevc.c:33
CONTEXT_SIZE
#define CONTEXT_SIZE
Definition: ffv1.h:45
AV_CODEC_CAP_ENCODER_FLUSH
#define AV_CODEC_CAP_ENCODER_FLUSH
This encoder can be flushed using avcodec_flush_buffers().
Definition: codec.h:151
ff_ffv1_enc_setup_comp_spv_len
const unsigned int ff_ffv1_enc_setup_comp_spv_len
VulkanEncodeFFv1Context::keyframe_slice_data_ref
AVBufferRef * keyframe_slice_data_ref
Definition: ffv1enc_vulkan.c:87
VulkanEncodeFFv1FrameData::frame_opaque_ref
AVBufferRef * frame_opaque_ref
Definition: ffv1enc_vulkan.c:50
AVRational::num
int num
Numerator.
Definition: rational.h:59
ff_ffv1_vulkan_encoder
const FFCodec ff_ffv1_vulkan_encoder
Definition: ffv1enc_vulkan.c:1518
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
FFVulkanDescriptorSetBinding::type
VkDescriptorType type
Definition: vulkan.h:114
VulkanEncodeFFv1Context::s
FFVulkanContext s
Definition: ffv1enc_vulkan.c:60
VulkanEncodeFFv1FrameData
Definition: ffv1enc_vulkan.c:42
vulkan_encode_ffv1_hw_configs
const AVCodecHWConfigInternal *const vulkan_encode_ffv1_hw_configs[]
Definition: ffv1enc_vulkan.c:1513
get_packet
static int get_packet(AVCodecContext *avctx, FFVkExecContext *exec, AVPacket *pkt)
Definition: ffv1enc_vulkan.c:681
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
VulkanEncodeFFv1Context::exec_ctx_info
VulkanEncodeFFv1FrameData * exec_ctx_info
Definition: ffv1enc_vulkan.c:68
av_cold
#define av_cold
Definition: attributes.h:111
VulkanEncodeFFv1Context::setup
FFVulkanShader setup
Definition: ffv1enc_vulkan.c:75
AVHWFramesContext::height
int height
Definition: hwcontext.h:220
FFV1Context::use32bit
int use32bit
Definition: ffv1.h:158
ff_ffv1_enc_reset_comp_spv_data
const unsigned char ff_ffv1_enc_reset_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
ff_vk_set_perm
void ff_vk_set_perm(enum AVPixelFormat pix_fmt, int lut[4], int inv)
Since storage images may not be swizzled, we have to do this in the shader itself.
Definition: vulkan.c:1572
VulkanEncodeFFv1Context::max_heap_size
size_t max_heap_size
Definition: ffv1enc_vulkan.c:71
FFVulkanContext::host_cached_flag
VkMemoryPropertyFlagBits host_cached_flag
Definition: vulkan.h:345
AVVulkanFramesContext::img_flags
VkImageCreateFlags img_flags
Flags to set during image creation.
Definition: hwcontext_vulkan.h:273
vulkan_encode_ffv1_receive_packet
static int vulkan_encode_ffv1_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: ffv1enc_vulkan.c:773
ff_source_ffv1_common_comp
const char * ff_source_ffv1_common_comp
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
VulkanEncodeFFv1Context::transfer_qf
AVVulkanDeviceQueueFamily * transfer_qf
Definition: ffv1enc_vulkan.c:64
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
FFV1Context::ac
int ac
1=range coder <-> 0=golomb rice
Definition: ffv1.h:147
ff_ffv1_encode_setup_plane_info
av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx, enum AVPixelFormat pix_fmt)
Definition: ffv1enc.c:801
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
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:332
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
if
if(ret)
Definition: filter_design.txt:179
ff_ffv1_enc_rct_search_comp_spv_len
const unsigned int ff_ffv1_enc_rct_search_comp_spv_len
FFv1ShaderParams::extend_lookup
uint32_t extend_lookup[8]
Definition: ffv1_vulkan.h:36
VulkanEncodeFFv1Context::frame
AVFrame * frame
Definition: ffv1enc_vulkan.c:58
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:571
ff_ffv1_vk_init_consts
int ff_ffv1_vk_init_consts(FFVulkanContext *s, FFVkBuffer *vkb, FFV1Context *f)
Definition: ffv1_vulkan.c:76
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:529
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
ff_ffv1_enc_rgb_comp_spv_len
const unsigned int ff_ffv1_enc_rgb_comp_spv_len
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
run_rct_search
static int run_rct_search(AVCodecContext *avctx, FFVkExecContext *exec, AVFrame *enc_in, VkImageView *enc_in_views, FFVkBuffer *slice_data_buf, uint32_t slice_data_size, FFv1ShaderParams *pd)
Definition: ffv1enc_vulkan.c:144
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:213
AC_GOLOMB_RICE
#define AC_GOLOMB_RICE
Definition: ffv1.h:52
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
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
init_encode_shader
static int init_encode_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
Definition: ffv1enc_vulkan.c:1043
FFV1Context::num_v_slices
int num_v_slices
Definition: ffv1.h:174
VulkanEncodeFFv1Context::force_pcm
int force_pcm
Definition: ffv1enc_vulkan.c:100
VulkanEncodeFFv1Context::consts_buf
FFVkBuffer consts_buf
Definition: ffv1enc_vulkan.c:80
VulkanEncodeFFv1FrameData::idx
int idx
Definition: ffv1enc_vulkan.c:53
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:367
ff_ffv1_enc_rgb_comp_spv_data
const unsigned char ff_ffv1_enc_rgb_comp_spv_data[]
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:360
av_buffer_pool_uninit
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:328
ff_vk_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:2376
FFVkExecContext::had_submission
int had_submission
Definition: vulkan.h:148
FFVkBuffer::size
size_t size
Definition: vulkan.h:129
AVVulkanFramesContext::usage
VkImageUsageFlagBits usage
Defines extra usage of output frames.
Definition: hwcontext_vulkan.h:240
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:616
ff_ffv1_enc_rgb_golomb_comp_spv_data
const unsigned char ff_ffv1_enc_rgb_golomb_comp_spv_data[]
ffv1_vulkan.h
VulkanEncodeFFv1Context::num_h_slices
int num_h_slices
Definition: ffv1enc_vulkan.c:98
FFVkBuffer::mapped_mem
uint8_t * mapped_mem
Definition: vulkan.h:134
FFVulkanContext
Definition: vulkan.h:312
VulkanEncodeFFv1FrameData::duration
int64_t duration
Definition: ffv1enc_vulkan.c:48
VulkanEncodeFFv1Context
Definition: ffv1enc_vulkan.c:56
AV_CODEC_ID_FFV1
@ AV_CODEC_ID_FFV1
Definition: codec_id.h:85
f
f
Definition: af_crystalizer.c:122
VulkanEncodeFFv1Context::slice_data_pool
AVBufferPool * slice_data_pool
Definition: ffv1enc_vulkan.c:86
ff_vk_buf_barrier
#define ff_vk_buf_barrier(dst, vkb, s_stage, s_access, s_access2, d_stage, d_access, d_access2, offs, bsz)
Definition: vulkan.h:551
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:550
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
VulkanEncodeFFv1Context::ctx
FFV1Context ctx
Definition: ffv1enc_vulkan.c:57
AVVkFrame::access
VkAccessFlagBits access[AV_NUM_DATA_POINTERS]
Updated after every barrier.
Definition: hwcontext_vulkan.h:339
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:2777
AVPacket::size
int size
Definition: packet.h:589
FFVulkanDescriptorSetBinding
Definition: vulkan.h:112
VulkanEncodeFFv1FrameData::pts
int64_t pts
Definition: ffv1enc_vulkan.c:47
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1017
codec_internal.h
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
AVVkFrame
Definition: hwcontext_vulkan.h:310
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
vulkan.h
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
QTABLE_GT8BIT
@ QTABLE_GT8BIT
Definition: ffv1enc.h:31
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:428
init_indirect
static int init_indirect(AVCodecContext *avctx, enum AVPixelFormat sw_format)
Definition: ffv1enc_vulkan.c:827
FFVulkanShader
Definition: vulkan.h:225
VulkanEncodeFFv1Context::optimize_rct
int optimize_rct
Definition: ffv1enc_vulkan.c:101
AVCodecHWConfigInternal
Definition: hwconfig.h:25
QTABLE_8BIT
@ QTABLE_8BIT
Definition: ffv1enc.h:30
FFVkBuffer::flags
VkMemoryPropertyFlagBits flags
Definition: vulkan.h:128
ff_ffv1_enc_remap_comp_spv_data
const unsigned char ff_ffv1_enc_remap_comp_spv_data[]
ff_ffv1_enc_reset_comp_spv_len
const unsigned int ff_ffv1_enc_reset_comp_spv_len
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:587
ff_source_common_comp
const char * ff_source_common_comp
VulkanEncodeFFv1FrameData::out_data_ref
AVBufferRef * out_data_ref
Definition: ffv1enc_vulkan.c:44
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:2751
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:594
ff_ffv1_enc_rct_search_comp_spv_data
const unsigned char ff_ffv1_enc_rct_search_comp_spv_data[]
VulkanEncodeFFv1Context::enc
FFVulkanShader enc
Definition: ffv1enc_vulkan.c:77
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
ff_ffv1_enc_golomb_comp_spv_data
const unsigned char ff_ffv1_enc_golomb_comp_spv_data[]
ff_ffv1_vk_set_common_sl
void ff_ffv1_vk_set_common_sl(AVCodecContext *avctx, FFV1Context *f, VkSpecializationInfo *sl, enum AVPixelFormat sw_format)
Definition: ffv1_vulkan.c:24
VE
#define VE
Definition: ffv1enc_vulkan.c:1450
HW_CONFIG_ENCODER_FRAMES
#define HW_CONFIG_ENCODER_FRAMES(format, device_type_)
Definition: hwconfig.h:98
FF_VK_EXT_EXTERNAL_HOST_MEMORY
#define FF_VK_EXT_EXTERNAL_HOST_MEMORY
Definition: vulkan_functions.h:36
ff_source_ffv1_enc_comp
const char * ff_source_ffv1_enc_comp
VulkanEncodeFFv1Context::remap_data_pool
AVBufferPool * remap_data_pool
Definition: ffv1enc_vulkan.c:90
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
ff_ffv1_enc_reset_golomb_comp_spv_data
const unsigned char ff_ffv1_enc_reset_golomb_comp_spv_data[]
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:559
ff_ffv1_common_init
av_cold int ff_ffv1_common_init(AVCodecContext *avctx, FFV1Context *s)
Definition: ffv1.c:36
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ffv1.h
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_encode_ffv1_close
static av_cold int vulkan_encode_ffv1_close(AVCodecContext *avctx)
Definition: ffv1enc_vulkan.c:1408
FFVulkanContext::props
VkPhysicalDeviceProperties2 props
Definition: vulkan.h:318
FFVulkanContext::extensions
FFVulkanExtensions extensions
Definition: vulkan.h:317
ff_vk_free_buf
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
Definition: vulkan.c:1244
AVCodecContext::height
int height
Definition: avcodec.h:600
init_setup_shader
static int init_setup_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
Definition: ffv1enc_vulkan.c:952
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:650
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
FFVulkanContext::mprops
VkPhysicalDeviceMemoryProperties mprops
Definition: vulkan.h:321
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:1465
avcodec.h
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:118
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
ff_ffv1_encode_buffer_size
size_t ff_ffv1_encode_buffer_size(AVCodecContext *avctx)
Definition: ffv1enc.c:1686
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:1967
FFVulkanContext::vkfn
FFVulkanFunctions vkfn
Definition: vulkan.h:316
AVHWFramesContext::hwctx
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:153
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1369
VulkanEncodeFFv1Context::exec_pool
FFVkExecPool exec_pool
Definition: ffv1enc_vulkan.c:62
FFVkExecContext::opaque
void * opaque
Definition: vulkan.h:162
FFVkExecPool
Definition: vulkan.h:290
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:1489
VulkanEncodeFFv1Context::intermediate_frames_ref
AVBufferRef * intermediate_frames_ref
Definition: ffv1enc_vulkan.c:96
VulkanEncodeFFv1FrameData::frame_opaque
void * frame_opaque
Definition: ffv1enc_vulkan.c:49
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:524
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
vulkan_encode_ffv1_options
static const AVOption vulkan_encode_ffv1_options[]
Definition: ffv1enc_vulkan.c:1451
FFVkExecContext::buf
VkCommandBuffer buf
Definition: vulkan.h:156
AVCodecContext
main external API structure.
Definition: avcodec.h:439
ff_ffv1_enc_comp_spv_data
const unsigned char ff_ffv1_enc_comp_spv_data[]
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:2503
VulkanEncodeFFv1Context::transfer_exec_pool
FFVkExecPool transfer_exec_pool
Definition: ffv1enc_vulkan.c:65
init_reset_shader
static int init_reset_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
Definition: ffv1enc_vulkan.c:994
RGB_LINECACHE
#define RGB_LINECACHE
Definition: ffv1enc_vulkan.c:40
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
VulkanEncodeFFv1Context::reset
FFVulkanShader reset
Definition: ffv1enc_vulkan.c:76
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
VulkanEncodeFFv1Context::async_depth
int async_depth
Definition: ffv1enc_vulkan.c:70
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
ffv1enc.h
vulkan_encode_ffv1_submit_frame
static int vulkan_encode_ffv1_submit_frame(AVCodecContext *avctx, FFVkExecContext *exec, const AVFrame *pict)
Definition: ffv1enc_vulkan.c:206
AVVulkanFramesContext::tiling
VkImageTiling tiling
Controls the tiling of allocated frames.
Definition: hwcontext_vulkan.h:229
VulkanEncodeFFv1Context::qf
AVVulkanDeviceQueueFamily * qf
Definition: ffv1enc_vulkan.c:61
vulkan_encode_ffv1_defaults
static const FFCodecDefault vulkan_encode_ffv1_defaults[]
Definition: ffv1enc_vulkan.c:1501
desc
const char * desc
Definition: libsvtav1.c:82
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFVulkanContext::hwctx
AVVulkanDeviceContext * hwctx
Definition: vulkan.h:349
VulkanEncodeFFv1Context::buf_regions
VkBufferCopy * buf_regions
Definition: ffv1enc_vulkan.c:67
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
AVVkFrame::layout
VkImageLayout layout[AV_NUM_DATA_POINTERS]
Definition: hwcontext_vulkan.h:340
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
ff_ffv1_encode_init
av_cold int ff_ffv1_encode_init(AVCodecContext *avctx)
Definition: ffv1enc.c:601
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AVVulkanDeviceContext::act_dev
VkDevice act_dev
Active device.
Definition: hwcontext_vulkan.h:84
FFV1Context
Definition: ffv1.h:122
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
FFv1ShaderParams
Definition: ffv1_vulkan.h:33
ff_vk_exec_discard_deps
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:592
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVCodecContext::slices
int slices
Number of slices.
Definition: avcodec.h:1033
AVPacket
This structure stores compressed data.
Definition: packet.h:565
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:466
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
FFVkBuffer
Definition: vulkan.h:125
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:600
vulkan_encode_ffv1_init
static av_cold int vulkan_encode_ffv1_init(AVCodecContext *avctx)
Definition: ffv1enc_vulkan.c:1133
FFv1ShaderParams::context_count
uint16_t context_count[8]
Definition: ffv1_vulkan.h:37
ff_ffv1_enc_reset_golomb_comp_spv_len
const unsigned int ff_ffv1_enc_reset_golomb_comp_spv_len
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:905
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVVulkanDeviceQueueFamily
Definition: hwcontext_vulkan.h:33
ff_ffv1_enc_setup_comp_spv_data
const unsigned char ff_ffv1_enc_setup_comp_spv_data[]
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
FFVulkanContext::frames
AVHWFramesContext * frames
Definition: vulkan.h:353
ff_ffv1_enc_rgb_float_comp_spv_data
const unsigned char ff_ffv1_enc_rgb_float_comp_spv_data[]
OFFSET
#define OFFSET(x)
Definition: ffv1enc_vulkan.c:1449
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:646
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
VulkanEncodeFFv1Context::remap
FFVulkanShader remap
Definition: ffv1enc_vulkan.c:74
FFv1ShaderParams::slice_data
VkDeviceAddress slice_data
Definition: ffv1_vulkan.h:34
ff_ffv1_enc_rgb_golomb_comp_spv_len
const unsigned int ff_ffv1_enc_rgb_golomb_comp_spv_len
av_hwframe_get_buffer
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:506
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
FFVulkanFunctions
Definition: vulkan_functions.h:274
FFVkExecPool::pool_size
int pool_size
Definition: vulkan.h:296
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:2093
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:1286
FFVkExecContext::idx
uint32_t idx
Definition: vulkan.h:146
src
#define src
Definition: vp8dsp.c:248
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:3376
init_rct_search_shader
static int init_rct_search_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
Definition: ffv1enc_vulkan.c:862
VulkanEncodeFFv1Context::out_data_pool
AVBufferPool * out_data_pool
Definition: ffv1enc_vulkan.c:93
ff_source_rangecoder_comp
const char * ff_source_rangecoder_comp