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 #include "libavutil/vulkan_spirv.h"
24 
25 #include "avcodec.h"
26 #include "internal.h"
27 #include "hwconfig.h"
28 #include "encode.h"
29 #include "libavutil/opt.h"
30 #include "codec_internal.h"
31 
32 #include "ffv1.h"
33 #include "ffv1enc.h"
34 #include "ffv1_vulkan.h"
35 
36 /* Parallel Golomb alignment */
37 #define LG_ALIGN_W 32
38 #define LG_ALIGN_H 32
39 
40 /* Unlike the decoder, we need 4 lines (but really only 3) */
41 #define RGB_LINECACHE 4
42 
43 typedef struct VulkanEncodeFFv1FrameData {
44  /* Output data */
46 
47  /* Results data */
49 
50  /* Copied from the source */
53  void *frame_opaque;
55 
56  int key_frame;
58 
59 typedef struct VulkanEncodeFFv1Context {
62 
66 
69 
70  VkBufferCopy *buf_regions;
72  int in_flight;
74  size_t max_heap_size;
75 
80 
81  /* Constant read-only buffers */
85 
86  /* Slice data buffer pool */
89 
90  /* Output data buffer */
92 
93  /* Slice results buffer */
95 
96  /* Intermediate frame pool */
98 
103 
104  int is_rgb;
105  int ppi;
106  int chunks;
108 
109 extern const char *ff_source_common_comp;
110 extern const char *ff_source_rangecoder_comp;
111 extern const char *ff_source_ffv1_vlc_comp;
112 extern const char *ff_source_ffv1_common_comp;
113 extern const char *ff_source_ffv1_reset_comp;
114 extern const char *ff_source_ffv1_rct_search_comp;
115 extern const char *ff_source_ffv1_enc_setup_comp;
116 extern const char *ff_source_ffv1_enc_comp;
117 
118 typedef struct FFv1VkParameters {
119  VkDeviceAddress slice_state;
120  VkDeviceAddress scratch_data;
121  VkDeviceAddress out_data;
122 
125  uint32_t chroma_shift[2];
126 
128  uint32_t context_count;
129  uint32_t crcref;
130  uint32_t slice_size_max;
132 
133  uint8_t extend_lookup[8];
135  uint8_t context_model;
136  uint8_t version;
137  uint8_t micro_version;
138  uint8_t force_pcm;
139  uint8_t key_frame;
140  uint8_t components;
141  uint8_t planes;
142  uint8_t codec_planes;
143  uint8_t planar_rgb;
144  uint8_t transparency;
145  uint8_t colorspace;
146  uint8_t pic_mode;
147  uint8_t ec;
148  uint8_t ppi;
149  uint8_t chunks;
150  uint8_t rct_search;
151  uint8_t padding[3];
153 
154 static void add_push_data(FFVulkanShader *shd)
155 {
156  GLSLC(0, layout(push_constant, scalar) uniform pushConstants { );
157  GLSLC(1, u8buf slice_state; );
158  GLSLC(1, u8buf scratch_data; );
159  GLSLC(1, u8buf out_data; );
160  GLSLC(0, );
161  GLSLC(1, ivec4 fmt_lut; );
162  GLSLC(1, ivec2 sar; );
163  GLSLC(1, uvec2 chroma_shift; );
164  GLSLC(0, );
165  GLSLC(1, uint plane_state_size; );
166  GLSLC(1, uint context_count; );
167  GLSLC(1, uint32_t crcref; );
168  GLSLC(1, uint32_t slice_size_max; );
169  GLSLC(1, int rct_offset; );
170  GLSLC(0, );
171  GLSLC(1, uint8_t extend_lookup[8]; );
172  GLSLC(1, uint8_t bits_per_raw_sample; );
173  GLSLC(1, uint8_t context_model; );
174  GLSLC(1, uint8_t version; );
175  GLSLC(1, uint8_t micro_version; );
176  GLSLC(1, uint8_t force_pcm; );
177  GLSLC(1, uint8_t key_frame; );
178  GLSLC(1, uint8_t components; );
179  GLSLC(1, uint8_t planes; );
180  GLSLC(1, uint8_t codec_planes; );
181  GLSLC(1, uint8_t planar_rgb; );
182  GLSLC(1, uint8_t transparency; );
183  GLSLC(1, uint8_t colorspace; );
184  GLSLC(1, uint8_t pic_mode; );
185  GLSLC(1, uint8_t ec; );
186  GLSLC(1, uint8_t ppi; );
187  GLSLC(1, uint8_t chunks; );
188  GLSLC(1, uint8_t rct_search; );
189  GLSLC(1, uint8_t padding[3]; );
190  GLSLC(0, }; );
192  VK_SHADER_STAGE_COMPUTE_BIT);
193 }
194 
196  int fmt_lut[4];
198  uint8_t planar_rgb;
199  uint8_t transparency;
200  uint8_t key_frame;
201  uint8_t force_pcm;
202  uint8_t version;
203  uint8_t micro_version;
204  uint8_t padding[2];
206 
208  AVFrame *enc_in, VkImageView *enc_in_views,
209  FFVkBuffer *slice_data_buf, uint32_t slice_data_size)
210 {
211  VulkanEncodeFFv1Context *fv = avctx->priv_data;
212  FFV1Context *f = &fv->ctx;
213  FFVulkanFunctions *vk = &fv->s.vkfn;
214  AVHWFramesContext *src_hwfc = (AVHWFramesContext *)enc_in->hw_frames_ctx->data;
216 
217  /* Update descriptors */
219  0, 0, 0,
220  slice_data_buf,
221  0, slice_data_size*f->slice_count,
222  VK_FORMAT_UNDEFINED);
223  ff_vk_shader_update_img_array(&fv->s, exec, &fv->rct_search,
224  enc_in, enc_in_views,
225  0, 1,
226  VK_IMAGE_LAYOUT_GENERAL,
227  VK_NULL_HANDLE);
228 
229  ff_vk_exec_bind_shader(&fv->s, exec, &fv->rct_search);
230 
232  .rct_offset = 1 << f->bits_per_raw_sample,
233  .planar_rgb = ff_vk_mt_is_np_rgb(src_hwfc->sw_format) &&
234  (ff_vk_count_images((AVVkFrame *)enc_in->data[0]) > 1),
235  .transparency = f->transparency,
236  .key_frame = f->key_frame,
237  .force_pcm = fv->force_pcm,
238  .version = f->version,
239  .micro_version = f->micro_version,
240  };
241 
242  if (avctx->sw_pix_fmt == AV_PIX_FMT_GBRP10 ||
243  avctx->sw_pix_fmt == AV_PIX_FMT_GBRP12 ||
244  avctx->sw_pix_fmt == AV_PIX_FMT_GBRP14)
245  memcpy(pd.fmt_lut, (int [4]) { 2, 1, 0, 3 }, 4*sizeof(int));
246  else
247  ff_vk_set_perm(avctx->sw_pix_fmt, pd.fmt_lut, 1);
248 
250  VK_SHADER_STAGE_COMPUTE_BIT,
251  0, sizeof(pd), &pd);
252 
253  vk->CmdDispatch(exec->buf, fv->ctx.num_h_slices, fv->ctx.num_v_slices, 1);
254 
255  return 0;
256 }
257 
259  FFVkExecContext *exec,
260  const AVFrame *pict)
261 {
262  int err;
263  VulkanEncodeFFv1Context *fv = avctx->priv_data;
264  FFV1Context *f = &fv->ctx;
265  FFVulkanFunctions *vk = &fv->s.vkfn;
266 
267  VulkanEncodeFFv1FrameData *fd = exec->opaque;
268  FFv1VkParameters pd;
269 
270  /* Slice data */
271  AVBufferRef *slice_data_ref;
272  FFVkBuffer *slice_data_buf;
273  uint32_t plane_state_size;
274  uint32_t slice_state_size;
275  uint32_t slice_data_size;
276 
277  /* Output data */
278  size_t maxsize;
279  FFVkBuffer *out_data_buf;
280 
281  /* Results data */
282  FFVkBuffer *results_data_buf;
283 
284  int has_inter = avctx->gop_size > 1;
285  uint32_t context_count = f->context_count[f->context_model];
286  const AVPixFmtDescriptor *fmt_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
287 
288  AVFrame *src = (AVFrame *)pict;
289  VkImageView src_views[AV_NUM_DATA_POINTERS];
290 
291  AVFrame *tmp = NULL;
292  VkImageView tmp_views[AV_NUM_DATA_POINTERS];
293 
294  VkImageMemoryBarrier2 img_bar[37];
295  int nb_img_bar = 0;
296  VkBufferMemoryBarrier2 buf_bar[8];
297  int nb_buf_bar = 0;
298 
299  /* Start recording */
300  ff_vk_exec_start(&fv->s, exec);
301 
302  /* Frame state */
303  f->cur_enc_frame = pict;
304  if (avctx->gop_size == 0 || f->picture_number % avctx->gop_size == 0) {
306  f->key_frame = fd->key_frame = 1;
307  f->gob_count++;
308  } else {
309  f->key_frame = fd->key_frame = 0;
310  }
311 
312  f->slice_count = f->max_slice_count;
313 
314  /* Allocate slice buffer data */
315  if (f->ac == AC_GOLOMB_RICE)
316  plane_state_size = 8;
317  else
318  plane_state_size = CONTEXT_SIZE;
319 
320  plane_state_size *= context_count;
321  slice_state_size = plane_state_size*f->plane_count;
322 
323  slice_data_size = 256; /* Overestimation for the SliceContext struct */
324  slice_state_size += slice_data_size;
325  slice_state_size = FFALIGN(slice_state_size, 8);
326 
327  /* Allocate slice data buffer */
328  slice_data_ref = fv->keyframe_slice_data_ref;
329  if (!slice_data_ref) {
331  &slice_data_ref,
332  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
333  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
334  NULL, slice_state_size*f->slice_count,
335  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT));
336 
337  /* Only save it if we're going to use it again */
338  if (has_inter)
339  fv->keyframe_slice_data_ref = slice_data_ref;
340  }
341  slice_data_buf = (FFVkBuffer *)slice_data_ref->data;
342  ff_vk_exec_add_dep_buf(&fv->s, exec, &slice_data_ref, 1, has_inter);
343 
344  /* Allocate results buffer */
346  &fd->results_data_ref,
347  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
348  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
349  NULL, 2*f->slice_count*sizeof(uint64_t),
350  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
351  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
352  results_data_buf = (FFVkBuffer *)fd->results_data_ref->data;
353  ff_vk_exec_add_dep_buf(&fv->s, exec, &fd->results_data_ref, 1, 1);
354 
355  /* Output buffer size */
356  maxsize = ff_ffv1_encode_buffer_size(avctx);
357  maxsize = FFMIN(maxsize, fv->s.props_11.maxMemoryAllocationSize);
358 
359  /* Allocate output buffer */
361  &fd->out_data_ref,
362  VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
363  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
364  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
365  NULL, maxsize,
366  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
367  (maxsize < fv->max_heap_size ?
368  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT : 0x0) |
370  VK_MEMORY_PROPERTY_HOST_CACHED_BIT : 0x0)));
371  out_data_buf = (FFVkBuffer *)fd->out_data_ref->data;
372  ff_vk_exec_add_dep_buf(&fv->s, exec, &fd->out_data_ref, 1, 1);
373 
374  /* Prepare input frame */
375  RET(ff_vk_exec_add_dep_frame(&fv->s, exec, src,
376  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
377  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
378 
379  RET(ff_vk_create_imageviews(&fv->s, exec, src_views, src,
381  ff_vk_frame_barrier(&fv->s, exec, src, img_bar, &nb_img_bar,
382  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
383  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
384  VK_ACCESS_SHADER_READ_BIT,
385  VK_IMAGE_LAYOUT_GENERAL,
386  VK_QUEUE_FAMILY_IGNORED);
387 
388  if (fv->is_rgb) {
389  /* Create a temporaty frame */
390  tmp = av_frame_alloc();
391  if (!(tmp))
392  return AVERROR(ENOMEM);
393 
395  tmp, 0));
396 
397  RET(ff_vk_exec_add_dep_frame(&fv->s, exec, tmp,
398  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
399  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
400  RET(ff_vk_create_imageviews(&fv->s, exec, tmp_views,
401  tmp,
403  }
404 
405  /* Setup shader */
406  ff_vk_shader_update_desc_buffer(&fv->s, exec, &fv->setup,
407  1, 0, 0,
408  slice_data_buf,
409  0, slice_data_size*f->slice_count,
410  VK_FORMAT_UNDEFINED);
411  ff_vk_shader_update_img_array(&fv->s, exec, &fv->setup,
412  src, src_views,
413  1, 1,
414  VK_IMAGE_LAYOUT_GENERAL,
415  VK_NULL_HANDLE);
416 
417  /* Add a buffer barrier between previous and current frame */
418  if (!f->key_frame) {
419  buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
420  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
421  .srcStageMask = slice_data_buf->stage,
422  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
423  .srcAccessMask = slice_data_buf->access,
424  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
425  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
426  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
427  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
428  .buffer = slice_data_buf->buf,
429  .size = VK_WHOLE_SIZE,
430  .offset = 0,
431  };
432  }
433 
434  if (fv->optimize_rct) {
435  RET(run_rct_search(avctx, exec,
436  src, src_views,
437  slice_data_buf, slice_data_size));
438 
439  buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
440  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
441  .srcStageMask = slice_data_buf->stage,
442  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
443  .srcAccessMask = slice_data_buf->access,
444  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
445  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
446  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
447  .buffer = slice_data_buf->buf,
448  .size = slice_data_size*f->slice_count,
449  .offset = 0,
450  };
451  }
452 
453  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
454  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
455  .pImageMemoryBarriers = img_bar,
456  .imageMemoryBarrierCount = nb_img_bar,
457  .pBufferMemoryBarriers = buf_bar,
458  .bufferMemoryBarrierCount = nb_buf_bar,
459  });
460  nb_img_bar = 0;
461  if (nb_buf_bar) {
462  slice_data_buf->stage = buf_bar[0].dstStageMask;
463  slice_data_buf->access = buf_bar[0].dstAccessMask;
464  nb_buf_bar = 0;
465  }
466 
467  /* Run setup shader */
468  ff_vk_exec_bind_shader(&fv->s, exec, &fv->setup);
469  pd = (FFv1VkParameters) {
470  .slice_state = slice_data_buf->address + f->slice_count*256,
471  .out_data = out_data_buf->address,
472  .bits_per_raw_sample = f->bits_per_raw_sample,
473  .sar[0] = pict->sample_aspect_ratio.num,
474  .sar[1] = pict->sample_aspect_ratio.den,
475  .chroma_shift[0] = f->chroma_h_shift,
476  .chroma_shift[1] = f->chroma_v_shift,
477  .plane_state_size = plane_state_size,
478  .context_count = context_count,
479  .crcref = f->crcref,
480  .rct_offset = 1 << f->bits_per_raw_sample,
481  .slice_size_max = out_data_buf->size / f->slice_count,
482  .context_model = fv->ctx.context_model,
483  .version = f->version,
484  .micro_version = f->micro_version,
485  .force_pcm = fv->force_pcm,
486  .key_frame = f->key_frame,
487  .components = fmt_desc->nb_components,
488  .planes = av_pix_fmt_count_planes(avctx->sw_pix_fmt),
489  .codec_planes = f->plane_count,
490  .planar_rgb = ff_vk_mt_is_np_rgb(avctx->sw_pix_fmt) &&
491  (ff_vk_count_images((AVVkFrame *)src->data[0]) > 1),
492  .transparency = f->transparency,
493  .colorspace = f->colorspace,
494  .pic_mode = !(pict->flags & AV_FRAME_FLAG_INTERLACED) ? 3 :
495  !(pict->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST) ? 2 : 1,
496  .ec = f->ec,
497  .ppi = fv->ppi,
498  .chunks = fv->chunks,
499  .rct_search = fv->optimize_rct,
500  };
501 
502  /* For some reason the C FFv1 encoder/decoder treats these differently */
503  if (avctx->sw_pix_fmt == AV_PIX_FMT_GBRP10 ||
504  avctx->sw_pix_fmt == AV_PIX_FMT_GBRP12 ||
505  avctx->sw_pix_fmt == AV_PIX_FMT_GBRP14)
506  memcpy(pd.fmt_lut, (int [4]) { 2, 1, 0, 3 }, 4*sizeof(int));
507  else
508  ff_vk_set_perm(avctx->sw_pix_fmt, pd.fmt_lut, 1);
509 
510  for (int i = 0; i < f->quant_table_count; i++)
511  pd.extend_lookup[i] = (f->quant_tables[i][3][127] != 0) ||
512  (f->quant_tables[i][4][127] != 0);
513  ff_vk_shader_update_push_const(&fv->s, exec, &fv->setup,
514  VK_SHADER_STAGE_COMPUTE_BIT,
515  0, sizeof(pd), &pd);
516  vk->CmdDispatch(exec->buf, fv->ctx.num_h_slices, fv->ctx.num_v_slices, 1);
517 
518  /* Clean up temporary image */
519  if (fv->is_rgb) {
520  AVVkFrame *vkf = (AVVkFrame *)tmp->data[0];
521  vk->CmdClearColorImage(exec->buf, vkf->img[0], VK_IMAGE_LAYOUT_GENERAL,
522  &((VkClearColorValue) { 0 }),
523  1, &((VkImageSubresourceRange) {
524  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
525  .levelCount = 1,
526  .layerCount = 1,
527  }));
528  }
529 
530  /* Setup shader modified the slice data buffer */
531  buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
532  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
533  .srcStageMask = slice_data_buf->stage,
534  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
535  .srcAccessMask = slice_data_buf->access,
536  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
537  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
538  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
539  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
540  .buffer = slice_data_buf->buf,
541  .size = slice_data_size*f->slice_count,
542  .offset = 0,
543  };
544 
545  if (f->key_frame || f->version > 3) {
546  FFv1VkResetParameters pd_reset;
547 
548  ff_vk_shader_update_desc_buffer(&fv->s, exec, &fv->reset,
549  1, 0, 0,
550  slice_data_buf,
551  0, slice_data_size*f->slice_count,
552  VK_FORMAT_UNDEFINED);
553 
554  /* Run setup shader */
555  ff_vk_exec_bind_shader(&fv->s, exec, &fv->reset);
556  pd_reset = (FFv1VkResetParameters) {
557  .slice_state = slice_data_buf->address + f->slice_count*256,
558  .plane_state_size = plane_state_size,
559  .codec_planes = f->plane_count,
560  .key_frame = f->key_frame,
561  };
562  for (int i = 0; i < f->quant_table_count; i++)
563  pd_reset.context_count[i] = f->context_count[i];
564 
565  ff_vk_shader_update_push_const(&fv->s, exec, &fv->reset,
566  VK_SHADER_STAGE_COMPUTE_BIT,
567  0, sizeof(pd_reset), &pd_reset);
568 
569  /* Sync between setup and reset shaders */
570  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
571  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
572  .pBufferMemoryBarriers = buf_bar,
573  .bufferMemoryBarrierCount = nb_buf_bar,
574  });
575  slice_data_buf->stage = buf_bar[0].dstStageMask;
576  slice_data_buf->access = buf_bar[0].dstAccessMask;
577  nb_buf_bar = 0;
578 
579  vk->CmdDispatch(exec->buf, fv->ctx.num_h_slices, fv->ctx.num_v_slices,
580  f->plane_count);
581  }
582 
583  /* If the reset shader ran, insert a barrier now. */
584  if (f->key_frame || f->version > 3) {
585  /* Reset shader modified the slice data buffer */
586  buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
587  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
588  .srcStageMask = slice_data_buf->stage,
589  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
590  .srcAccessMask = slice_data_buf->access,
591  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
592  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
593  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
594  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
595  .buffer = slice_data_buf->buf,
596  .size = slice_data_buf->size - slice_data_size*f->slice_count,
597  .offset = slice_data_size*f->slice_count,
598  };
599  }
600 
601  if (fv->is_rgb) {
602  ff_vk_frame_barrier(&fv->s, exec, tmp, img_bar, &nb_img_bar,
603  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
604  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
605  VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
606  VK_IMAGE_LAYOUT_GENERAL,
607  VK_QUEUE_FAMILY_IGNORED);
608  }
609 
610  /* Final barrier before encoding */
611  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
612  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
613  .pImageMemoryBarriers = img_bar,
614  .imageMemoryBarrierCount = nb_img_bar,
615  .pBufferMemoryBarriers = buf_bar,
616  .bufferMemoryBarrierCount = nb_buf_bar,
617  });
618  nb_img_bar = 0;
619  if (nb_buf_bar) {
620  slice_data_buf->stage = buf_bar[0].dstStageMask;
621  slice_data_buf->access = buf_bar[0].dstAccessMask;
622  nb_buf_bar = 0;
623  }
624 
625  /* Main encode shader */
626  ff_vk_shader_update_desc_buffer(&fv->s, exec, &fv->enc,
627  1, 0, 0,
628  slice_data_buf,
629  0, slice_data_size*f->slice_count,
630  VK_FORMAT_UNDEFINED);
631  ff_vk_shader_update_img_array(&fv->s, exec, &fv->enc,
632  src, src_views,
633  1, 1,
634  VK_IMAGE_LAYOUT_GENERAL,
635  VK_NULL_HANDLE);
637  &fv->enc, 1, 2, 0,
638  results_data_buf,
639  0, results_data_buf->size,
640  VK_FORMAT_UNDEFINED);
641  if (fv->is_rgb)
642  ff_vk_shader_update_img_array(&fv->s, exec, &fv->enc,
643  tmp, tmp_views,
644  1, 3,
645  VK_IMAGE_LAYOUT_GENERAL,
646  VK_NULL_HANDLE);
647 
648  ff_vk_exec_bind_shader(&fv->s, exec, &fv->enc);
649  ff_vk_shader_update_push_const(&fv->s, exec, &fv->enc,
650  VK_SHADER_STAGE_COMPUTE_BIT,
651  0, sizeof(pd), &pd);
652  vk->CmdDispatch(exec->buf, fv->ctx.num_h_slices, fv->ctx.num_v_slices, 1);
653 
654  /* Submit */
655  err = ff_vk_exec_submit(&fv->s, exec);
656  if (err < 0)
657  return err;
658 
659  f->picture_number++;
660 
661  /* This, if needed, was referenced by the execution context
662  * as it was declared as a dependency. */
663  av_frame_free(&tmp);
664  return 0;
665 
666 fail:
667  av_frame_free(&tmp);
668  ff_vk_exec_discard_deps(&fv->s, exec);
669 
670  return err;
671 }
672 
673 static int transfer_slices(AVCodecContext *avctx,
674  VkBufferCopy *buf_regions, int nb_regions,
676  uint8_t *dst, AVBufferRef *dst_ref)
677 {
678  int err;
679  VulkanEncodeFFv1Context *fv = avctx->priv_data;
680  FFVulkanFunctions *vk = &fv->s.vkfn;
681  FFVkExecContext *exec;
682 
683  FFVkBuffer *out_data_buf = (FFVkBuffer *)fd->out_data_ref->data;
684 
685  AVBufferRef *mapped_ref;
686  FFVkBuffer *mapped_buf;
687 
688  VkBufferMemoryBarrier2 buf_bar[8];
689  int nb_buf_bar = 0;
690 
691  err = ff_vk_host_map_buffer(&fv->s, &mapped_ref, dst, dst_ref,
692  VK_BUFFER_USAGE_TRANSFER_DST_BIT);
693  if (err < 0)
694  return err;
695 
696  mapped_buf = (FFVkBuffer *)mapped_ref->data;
697 
698  /* Transfer the slices */
699  exec = ff_vk_exec_get(&fv->s, &fv->transfer_exec_pool);
700  ff_vk_exec_start(&fv->s, exec);
701 
702  ff_vk_exec_add_dep_buf(&fv->s, exec, &fd->out_data_ref, 1, 0);
703  fd->out_data_ref = NULL; /* Ownership passed */
704 
705  ff_vk_exec_add_dep_buf(&fv->s, exec, &mapped_ref, 1, 0);
706  mapped_ref = NULL; /* Ownership passed */
707 
708  /* Ensure the output buffer is finished */
709  buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
710  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
711  .srcStageMask = out_data_buf->stage,
712  .dstStageMask = VK_PIPELINE_STAGE_2_TRANSFER_BIT,
713  .srcAccessMask = out_data_buf->access,
714  .dstAccessMask = VK_ACCESS_2_TRANSFER_READ_BIT,
715  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
716  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
717  .buffer = out_data_buf->buf,
718  .size = VK_WHOLE_SIZE,
719  .offset = 0,
720  };
721  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
722  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
723  .pBufferMemoryBarriers = buf_bar,
724  .bufferMemoryBarrierCount = nb_buf_bar,
725  });
726  out_data_buf->stage = buf_bar[0].dstStageMask;
727  out_data_buf->access = buf_bar[0].dstAccessMask;
728  nb_buf_bar = 0;
729 
730  for (int i = 0; i < nb_regions; i++)
731  buf_regions[i].dstOffset += mapped_buf->virtual_offset;
732 
733  vk->CmdCopyBuffer(exec->buf,
734  out_data_buf->buf, mapped_buf->buf,
735  nb_regions, buf_regions);
736 
737  /* Submit */
738  err = ff_vk_exec_submit(&fv->s, exec);
739  if (err < 0)
740  return err;
741 
742  /* We need the encoded data immediately */
743  ff_vk_exec_wait(&fv->s, exec);
744 
745  return 0;
746 }
747 
748 static int get_packet(AVCodecContext *avctx, FFVkExecContext *exec,
749  AVPacket *pkt)
750 {
751  int err;
752  VulkanEncodeFFv1Context *fv = avctx->priv_data;
753  FFV1Context *f = &fv->ctx;
754  FFVulkanFunctions *vk = &fv->s.vkfn;
755  VulkanEncodeFFv1FrameData *fd = exec->opaque;
756 
757  FFVkBuffer *out_data_buf = (FFVkBuffer *)fd->out_data_ref->data;
758  FFVkBuffer *results_data_buf = (FFVkBuffer *)fd->results_data_ref->data;
759  uint64_t *sc;
760 
761  /* Make sure encoding's done */
762  ff_vk_exec_wait(&fv->s, exec);
763 
764  /* Invalidate slice/output data if needed */
765  if (!(results_data_buf->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
766  VkMappedMemoryRange invalidate_data = {
767  .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
768  .memory = results_data_buf->mem,
769  .offset = 0,
770  .size = VK_WHOLE_SIZE,
771  };
772  vk->InvalidateMappedMemoryRanges(fv->s.hwctx->act_dev,
773  1, &invalidate_data);
774  }
775 
776  /* Calculate final size */
777  pkt->size = 0;
778  for (int i = 0; i < f->slice_count; i++) {
779  sc = &((uint64_t *)results_data_buf->mapped_mem)[i*2];
780  av_log(avctx, AV_LOG_DEBUG, "Slice %i size = %"PRIu64", "
781  "src offset = %"PRIu64"\n",
782  i, sc[0], sc[1]);
783 
784  fv->buf_regions[i] = (VkBufferCopy) {
785  .srcOffset = sc[1],
786  .dstOffset = pkt->size,
787  .size = sc[0],
788  };
789  pkt->size += sc[0];
790  }
791  av_log(avctx, AV_LOG_VERBOSE, "Encoded data: %iMiB\n", pkt->size / (1024*1024));
792  av_buffer_unref(&fd->results_data_ref); /* No need for this buffer anymore */
793 
794  /* Allocate packet */
795  if ((err = ff_get_encode_buffer(avctx, pkt, pkt->size, 0)) < 0)
796  return err;
797 
798  pkt->pts = fd->pts;
799  pkt->dts = fd->pts;
800  pkt->duration = fd->duration;
802 
803  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
804  pkt->opaque = fd->frame_opaque;
806  fd->frame_opaque_ref = NULL;
807  }
808 
809  /* Try using host mapped memory transfers first */
811  err = transfer_slices(avctx, fv->buf_regions, f->slice_count, fd,
812  pkt->data, pkt->buf);
813  if (err >= 0)
814  return err;
815  }
816 
817  /* Invalidate slice/output data if needed */
818  if (!(out_data_buf->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
819  VkMappedMemoryRange invalidate_data = {
820  .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
821  .memory = out_data_buf->mem,
822  .offset = 0,
823  .size = VK_WHOLE_SIZE,
824  };
825  vk->InvalidateMappedMemoryRanges(fv->s.hwctx->act_dev,
826  1, &invalidate_data);
827  }
828 
829  /* Copy each slice */
830  for (int i = 0; i < f->slice_count; i++) {
831  VkBufferCopy *region = &fv->buf_regions[i];
832  memcpy(pkt->data + region->dstOffset,
833  out_data_buf->mapped_mem + region->srcOffset,
834  region->size);
835  }
836 
838 
839  return 0;
840 }
841 
843  AVPacket *pkt)
844 {
845  int err;
846  VulkanEncodeFFv1Context *fv = avctx->priv_data;
848  FFVkExecContext *exec;
849  AVFrame *frame;
850 
851  while (1) {
852  /* Roll an execution context */
853  exec = ff_vk_exec_get(&fv->s, &fv->exec_pool);
854 
855  /* If it had a frame, immediately output it */
856  if (exec->had_submission) {
857  exec->had_submission = 0;
858  fv->in_flight--;
859  return get_packet(avctx, exec, pkt);
860  }
861 
862  /* Get next frame to encode */
863  frame = fv->frame;
864  err = ff_encode_get_frame(avctx, frame);
865  if (err < 0 && err != AVERROR_EOF) {
866  return err;
867  } else if (err == AVERROR_EOF) {
868  if (!fv->in_flight)
869  return err;
870  continue;
871  }
872 
873  /* Encode frame */
874  fd = exec->opaque;
875  fd->pts = frame->pts;
876  fd->duration = frame->duration;
877  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
878  fd->frame_opaque = frame->opaque;
879  fd->frame_opaque_ref = frame->opaque_ref;
880  frame->opaque_ref = NULL;
881  }
882 
883  err = vulkan_encode_ffv1_submit_frame(avctx, exec, frame);
885  if (err < 0)
886  return err;
887 
888  fv->in_flight++;
889  if (fv->in_flight < fv->async_depth)
890  return AVERROR(EAGAIN);
891  }
892 
893  return 0;
894 }
895 
896 static int init_indirect(AVCodecContext *avctx, enum AVPixelFormat sw_format)
897 {
898  int err;
899  VulkanEncodeFFv1Context *fv = avctx->priv_data;
900  FFV1Context *f = &fv->ctx;
901  AVHWFramesContext *frames_ctx;
902  AVVulkanFramesContext *vk_frames;
903 
905  if (!fv->intermediate_frames_ref)
906  return AVERROR(ENOMEM);
907 
908  frames_ctx = (AVHWFramesContext *)fv->intermediate_frames_ref->data;
909  frames_ctx->format = AV_PIX_FMT_VULKAN;
910  frames_ctx->sw_format = sw_format;
911  frames_ctx->width = fv->s.frames->width;
912  frames_ctx->height = f->num_v_slices*RGB_LINECACHE;
913 
914  vk_frames = frames_ctx->hwctx;
915  vk_frames->tiling = VK_IMAGE_TILING_OPTIMAL;
916  vk_frames->usage = VK_IMAGE_USAGE_STORAGE_BIT |
917  VK_IMAGE_USAGE_TRANSFER_DST_BIT;
918  vk_frames->img_flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
919 
921  if (err < 0) {
922  av_log(avctx, AV_LOG_ERROR, "Unable to initialize frame pool with format %s: %s\n",
923  av_get_pix_fmt_name(sw_format), av_err2str(err));
925  return err;
926  }
927 
928  return 0;
929 }
930 
931 static int check_support(AVHWFramesConstraints *constraints,
932  enum AVPixelFormat fmt)
933 {
934  for (int i = 0; constraints->valid_sw_formats[i]; i++) {
935  if (constraints->valid_sw_formats[i] == fmt)
936  return 1;
937  }
938  return 0;
939 }
940 
942 {
943  VulkanEncodeFFv1Context *fv = avctx->priv_data;
944 
945  enum AVPixelFormat fmt;
946  AVHWFramesConstraints *constraints;
948  NULL);
949 
950  /* What we'd like to optimally have */
951  fmt = fv->ctx.use32bit ?
954  if (check_support(constraints, fmt))
955  goto end;
956 
957  if (fv->ctx.use32bit) {
958  if (check_support(constraints, (fmt = AV_PIX_FMT_RGBA128)))
959  goto end;
960  } else {
961  if (check_support(constraints, (fmt = AV_PIX_FMT_RGBA64)))
962  goto end;
963 
964  if (!fv->ctx.transparency &&
965  check_support(constraints, (fmt = AV_PIX_FMT_RGB96)))
966  goto end;
967 
968  if (check_support(constraints, (fmt = AV_PIX_FMT_RGBA128)))
969  goto end;
970  }
971 
972  fmt = AV_PIX_FMT_NONE;
973 
974 end:
975  av_hwframe_constraints_free(&constraints);
976  return fmt;
977 }
978 
980 {
981  VulkanEncodeFFv1Context *fv = avctx->priv_data;
982  FFV1Context *f = &fv->ctx;
983  int smp_bits = fv->ctx.use32bit ? 32 : 16;
984 
985  av_bprintf(&shd->src, "#define RGB_LINECACHE %i\n" ,RGB_LINECACHE);
986  av_bprintf(&shd->src, "#define CONTEXT_SIZE %i\n" ,CONTEXT_SIZE);
987  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_MASK 0x%x\n" ,MAX_QUANT_TABLE_MASK);
988 
989  if (f->ac == AC_GOLOMB_RICE) {
990  av_bprintf(&shd->src, "#define PB_UNALIGNED\n" );
991  av_bprintf(&shd->src, "#define GOLOMB\n" );
992  }
993 
994  if (fv->is_rgb)
995  av_bprintf(&shd->src, "#define RGB\n");
996 
997  GLSLF(0, #define TYPE int%i_t ,smp_bits);
998  GLSLF(0, #define VTYPE2 i%ivec2 ,smp_bits);
999  GLSLF(0, #define VTYPE3 i%ivec3 ,smp_bits);
1001 
1002  if (f->ac == AC_GOLOMB_RICE)
1004 
1006 }
1007 
1009 {
1010  int err;
1011  VulkanEncodeFFv1Context *fv = avctx->priv_data;
1012  FFV1Context *f = &fv->ctx;
1013  FFVulkanShader *shd = &fv->rct_search;
1014  FFVulkanDescriptorSetBinding *desc_set;
1015 
1016  uint8_t *spv_data;
1017  size_t spv_len;
1018  void *spv_opaque = NULL;
1019 
1020  RET(ff_vk_shader_init(&fv->s, shd, "ffv1_rct_search",
1021  VK_SHADER_STAGE_COMPUTE_BIT,
1022  (const char *[]) { "GL_EXT_buffer_reference",
1023  "GL_EXT_buffer_reference2",
1024  "GL_EXT_null_initializer" }, 3,
1025  32, 32, 1,
1026  0));
1027 
1028  /* Common codec header */
1030 
1031  GLSLC(0, layout(push_constant, scalar) uniform pushConstants { );
1032  GLSLC(1, ivec4 fmt_lut; );
1033  GLSLC(1, int rct_offset; );
1034  GLSLC(1, uint8_t planar_rgb; );
1035  GLSLC(1, uint8_t transparency; );
1036  GLSLC(1, uint8_t key_frame; );
1037  GLSLC(1, uint8_t force_pcm; );
1038  GLSLC(1, uint8_t version; );
1039  GLSLC(1, uint8_t micro_version; );
1040  GLSLC(1, uint8_t padding[3]; );
1041  GLSLC(0, }; );
1043  VK_SHADER_STAGE_COMPUTE_BIT);
1044 
1045  av_bprintf(&shd->src, "#define MAX_QUANT_TABLES %i\n", MAX_QUANT_TABLES);
1046  av_bprintf(&shd->src, "#define MAX_CONTEXT_INPUTS %i\n", MAX_CONTEXT_INPUTS);
1047  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_SIZE %i\n", MAX_QUANT_TABLE_SIZE);
1048 
1049  /* Never used */
1050  desc_set = (FFVulkanDescriptorSetBinding []) {
1051  {
1052  .name = "rangecoder_static_buf",
1053  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1054  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1055  .mem_layout = "scalar",
1056  .buf_content = "uint8_t zero_one_state[512];",
1057  },
1058  {
1059  .name = "quant_buf",
1060  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1061  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1062  .mem_layout = "scalar",
1063  .buf_content = "int16_t quant_table[MAX_QUANT_TABLES]"
1064  "[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];",
1065  },
1066  };
1067  RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 2, 1, 1));
1068 
1069  define_shared_code(avctx, shd);
1070 
1071  desc_set = (FFVulkanDescriptorSetBinding []) {
1072  {
1073  .name = "slice_data_buf",
1074  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1075  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1076  .buf_content = "SliceContext slice_ctx",
1077  .buf_elems = f->max_slice_count,
1078  },
1079  {
1080  .name = "src",
1081  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
1082  .dimensions = 2,
1083  .mem_layout = ff_vk_shader_rep_fmt(fv->s.frames->sw_format,
1085  .elems = av_pix_fmt_count_planes(fv->s.frames->sw_format),
1086  .mem_quali = "readonly",
1087  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1088  },
1089  };
1090  RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 2, 0, 0));
1091 
1093 
1094  RET(spv->compile_shader(&fv->s, spv, shd, &spv_data, &spv_len, "main",
1095  &spv_opaque));
1096  RET(ff_vk_shader_link(&fv->s, shd, spv_data, spv_len, "main"));
1097 
1098  RET(ff_vk_shader_register_exec(&fv->s, &fv->exec_pool, shd));
1099 
1100 fail:
1101  if (spv_opaque)
1102  spv->free_shader(spv, &spv_opaque);
1103 
1104  return err;
1105 }
1106 
1108 {
1109  int err;
1110  VulkanEncodeFFv1Context *fv = avctx->priv_data;
1111  FFV1Context *f = &fv->ctx;
1112  FFVulkanShader *shd = &fv->setup;
1113  FFVulkanDescriptorSetBinding *desc_set;
1114 
1115  uint8_t *spv_data;
1116  size_t spv_len;
1117  void *spv_opaque = NULL;
1118 
1119  RET(ff_vk_shader_init(&fv->s, shd, "ffv1_setup",
1120  VK_SHADER_STAGE_COMPUTE_BIT,
1121  (const char *[]) { "GL_EXT_buffer_reference",
1122  "GL_EXT_buffer_reference2" }, 2,
1123  1, 1, 1,
1124  0));
1125 
1126  /* Common codec header */
1128  add_push_data(shd);
1129 
1130  av_bprintf(&shd->src, "#define MAX_QUANT_TABLES %i\n", MAX_QUANT_TABLES);
1131  av_bprintf(&shd->src, "#define MAX_CONTEXT_INPUTS %i\n", MAX_CONTEXT_INPUTS);
1132  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_SIZE %i\n", MAX_QUANT_TABLE_SIZE);
1133  av_bprintf(&shd->src, "#define FULL_RENORM\n");
1134 
1135  desc_set = (FFVulkanDescriptorSetBinding []) {
1136  {
1137  .name = "rangecoder_static_buf",
1138  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1139  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1140  .mem_layout = "scalar",
1141  .buf_content = "uint8_t zero_one_state[512];",
1142  },
1143  { /* This descriptor is never used */
1144  .name = "quant_buf",
1145  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1146  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1147  .mem_layout = "scalar",
1148  .buf_content = "int16_t quant_table[MAX_QUANT_TABLES]"
1149  "[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];",
1150  },
1151  };
1152  RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 2, 1, 0));
1153 
1154  define_shared_code(avctx, shd);
1155 
1156  desc_set = (FFVulkanDescriptorSetBinding []) {
1157  {
1158  .name = "slice_data_buf",
1159  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1160  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1161  .buf_content = "SliceContext slice_ctx",
1162  .buf_elems = f->max_slice_count,
1163  },
1164  {
1165  .name = "src",
1166  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
1167  .dimensions = 2,
1168  .mem_layout = ff_vk_shader_rep_fmt(fv->s.frames->sw_format,
1170  .elems = av_pix_fmt_count_planes(fv->s.frames->sw_format),
1171  .mem_quali = "readonly",
1172  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1173  },
1174  };
1175  RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 2, 0, 0));
1176 
1178 
1179  RET(spv->compile_shader(&fv->s, spv, shd, &spv_data, &spv_len, "main",
1180  &spv_opaque));
1181  RET(ff_vk_shader_link(&fv->s, shd, spv_data, spv_len, "main"));
1182 
1183  RET(ff_vk_shader_register_exec(&fv->s, &fv->exec_pool, shd));
1184 
1185 fail:
1186  if (spv_opaque)
1187  spv->free_shader(spv, &spv_opaque);
1188 
1189  return err;
1190 }
1191 
1193 {
1194  int err;
1195  VulkanEncodeFFv1Context *fv = avctx->priv_data;
1196  FFV1Context *f = &fv->ctx;
1197  FFVulkanShader *shd = &fv->reset;
1198  FFVulkanDescriptorSetBinding *desc_set;
1199 
1200  uint8_t *spv_data;
1201  size_t spv_len;
1202  void *spv_opaque = NULL;
1203  int wg_dim = FFMIN(fv->s.props.properties.limits.maxComputeWorkGroupSize[0], 1024);
1204 
1205  RET(ff_vk_shader_init(&fv->s, shd, "ffv1_reset",
1206  VK_SHADER_STAGE_COMPUTE_BIT,
1207  (const char *[]) { "GL_EXT_buffer_reference",
1208  "GL_EXT_buffer_reference2" }, 2,
1209  wg_dim, 1, 1,
1210  0));
1211 
1212  /* Common codec header */
1214 
1215  GLSLC(0, layout(push_constant, scalar) uniform pushConstants { );
1216  GLSLF(1, uint context_count[%i]; ,MAX_QUANT_TABLES);
1217  GLSLC(1, u8buf slice_state; );
1218  GLSLC(1, uint plane_state_size; );
1219  GLSLC(1, uint8_t codec_planes; );
1220  GLSLC(1, uint8_t key_frame; );
1221  GLSLC(1, uint8_t version; );
1222  GLSLC(1, uint8_t micro_version; );
1223  GLSLC(1, uint8_t padding[1]; );
1224  GLSLC(0, }; );
1226  VK_SHADER_STAGE_COMPUTE_BIT);
1227 
1228  av_bprintf(&shd->src, "#define MAX_QUANT_TABLES %i\n", MAX_QUANT_TABLES);
1229  av_bprintf(&shd->src, "#define MAX_CONTEXT_INPUTS %i\n", MAX_CONTEXT_INPUTS);
1230  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_SIZE %i\n", MAX_QUANT_TABLE_SIZE);
1231 
1232  desc_set = (FFVulkanDescriptorSetBinding []) {
1233  {
1234  .name = "rangecoder_static_buf",
1235  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1236  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1237  .mem_layout = "scalar",
1238  .buf_content = "uint8_t zero_one_state[512];",
1239  },
1240  {
1241  .name = "quant_buf",
1242  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1243  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1244  .mem_layout = "scalar",
1245  .buf_content = "int16_t quant_table[MAX_QUANT_TABLES]"
1246  "[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];",
1247  },
1248  };
1249  RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 2, 1, 0));
1250 
1251  define_shared_code(avctx, shd);
1252 
1253  desc_set = (FFVulkanDescriptorSetBinding []) {
1254  {
1255  .name = "slice_data_buf",
1256  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1257  .mem_quali = "readonly",
1258  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1259  .buf_content = "SliceContext slice_ctx",
1260  .buf_elems = f->max_slice_count,
1261  },
1262  };
1263  RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 1, 0, 0));
1264 
1266 
1267  RET(spv->compile_shader(&fv->s, spv, shd, &spv_data, &spv_len, "main",
1268  &spv_opaque));
1269  RET(ff_vk_shader_link(&fv->s, shd, spv_data, spv_len, "main"));
1270 
1271  RET(ff_vk_shader_register_exec(&fv->s, &fv->exec_pool, shd));
1272 
1273 fail:
1274  if (spv_opaque)
1275  spv->free_shader(spv, &spv_opaque);
1276 
1277  return err;
1278 }
1279 
1281 {
1282  int err;
1283  VulkanEncodeFFv1Context *fv = avctx->priv_data;
1284  FFV1Context *f = &fv->ctx;
1285  FFVulkanShader *shd = &fv->enc;
1286  FFVulkanDescriptorSetBinding *desc_set;
1287 
1288  uint8_t *spv_data;
1289  size_t spv_len;
1290  void *spv_opaque = NULL;
1291  int use_cached_reader = fv->ctx.ac != AC_GOLOMB_RICE &&
1292  fv->s.driver_props.driverID == VK_DRIVER_ID_MESA_RADV;
1293 
1294  RET(ff_vk_shader_init(&fv->s, shd, "ffv1_enc",
1295  VK_SHADER_STAGE_COMPUTE_BIT,
1296  (const char *[]) { "GL_EXT_buffer_reference",
1297  "GL_EXT_buffer_reference2" }, 2,
1298  use_cached_reader ? CONTEXT_SIZE : 1, 1, 1,
1299  0));
1300 
1301  /* Common codec header */
1303 
1304  add_push_data(shd);
1305 
1306  av_bprintf(&shd->src, "#define MAX_QUANT_TABLES %i\n", MAX_QUANT_TABLES);
1307  av_bprintf(&shd->src, "#define MAX_CONTEXT_INPUTS %i\n", MAX_CONTEXT_INPUTS);
1308  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_SIZE %i\n", MAX_QUANT_TABLE_SIZE);
1309 
1310  if (use_cached_reader)
1311  av_bprintf(&shd->src, "#define CACHED_SYMBOL_READER 1\n");
1312 
1313  desc_set = (FFVulkanDescriptorSetBinding []) {
1314  {
1315  .name = "rangecoder_static_buf",
1316  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1317  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1318  .mem_layout = "scalar",
1319  .buf_content = "uint8_t zero_one_state[512];",
1320  },
1321  {
1322  .name = "quant_buf",
1323  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1324  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1325  .mem_layout = "scalar",
1326  .buf_content = "int16_t quant_table[MAX_QUANT_TABLES]"
1327  "[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];",
1328  },
1329  {
1330  .name = "crc_ieee_buf",
1331  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1332  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1333  .mem_layout = "scalar",
1334  .buf_content = "uint32_t crc_ieee[256];",
1335  },
1336  };
1337 
1338  RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 3, 1, 0));
1339 
1340  define_shared_code(avctx, shd);
1341 
1342  desc_set = (FFVulkanDescriptorSetBinding []) {
1343  {
1344  .name = "slice_data_buf",
1345  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1346  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1347  .buf_content = "SliceContext slice_ctx",
1348  .buf_elems = f->max_slice_count,
1349  },
1350  {
1351  .name = "src",
1352  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
1353  .dimensions = 2,
1354  .mem_layout = ff_vk_shader_rep_fmt(fv->s.frames->sw_format,
1356  .elems = av_pix_fmt_count_planes(fv->s.frames->sw_format),
1357  .mem_quali = "readonly",
1358  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1359  },
1360  {
1361  .name = "results_data_buf",
1362  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1363  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1364  .mem_quali = "writeonly",
1365  .buf_content = "uint64_t slice_results[2048];",
1366  },
1367  { /* place holder for desc_set[3] */
1368  .name = "placeholder",
1369  },
1370  };
1371  if (fv->is_rgb) {
1372  AVHWFramesContext *intermediate_frames_ctx;
1373  intermediate_frames_ctx = (AVHWFramesContext *)fv->intermediate_frames_ref->data;
1374  desc_set[3] = (FFVulkanDescriptorSetBinding) {
1375  .name = "tmp",
1376  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
1377  .dimensions = 2,
1378  .mem_layout = ff_vk_shader_rep_fmt(intermediate_frames_ctx->sw_format,
1380  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1381  };
1382  }
1383  RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 3 + fv->is_rgb, 0, 0));
1384 
1386 
1387  RET(spv->compile_shader(&fv->s, spv, shd, &spv_data, &spv_len, "main",
1388  &spv_opaque));
1389  RET(ff_vk_shader_link(&fv->s, shd, spv_data, spv_len, "main"));
1390 
1391  RET(ff_vk_shader_register_exec(&fv->s, &fv->exec_pool, shd));
1392 
1393 fail:
1394  if (spv_opaque)
1395  spv->free_shader(spv, &spv_opaque);
1396 
1397  return err;
1398 }
1399 
1401 {
1402  int err;
1403  size_t maxsize, max_heap_size, max_host_size;
1404  VulkanEncodeFFv1Context *fv = avctx->priv_data;
1405  FFV1Context *f = &fv->ctx;
1406  FFVkSPIRVCompiler *spv;
1407 
1408  if ((err = ff_ffv1_common_init(avctx, f)) < 0)
1409  return err;
1410 
1411  if (f->ac == 1)
1412  f->ac = AC_RANGE_CUSTOM_TAB;
1413 
1414  err = ff_ffv1_encode_setup_plane_info(avctx, avctx->sw_pix_fmt);
1415  if (err < 0)
1416  return err;
1417 
1418  /* Target version 3 by default */
1419  f->version = 3;
1420 
1421  err = ff_ffv1_encode_init(avctx);
1422  if (err < 0)
1423  return err;
1424 
1425  /* Rice coding did not support high bit depths */
1426  if (f->bits_per_raw_sample > (f->version > 3 ? 16 : 8)) {
1427  if (f->ac == AC_GOLOMB_RICE) {
1428  av_log(avctx, AV_LOG_WARNING, "bits_per_raw_sample > 8, "
1429  "forcing range coder\n");
1430  f->ac = AC_RANGE_CUSTOM_TAB;
1431  }
1432  }
1433 
1434  if (f->version < 4 && avctx->gop_size > 1) {
1435  av_log(avctx, AV_LOG_ERROR, "Using inter frames requires version 4 (-level 4)\n");
1436  return AVERROR_INVALIDDATA;
1437  }
1438 
1439  if (f->version == 4 && avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
1440  av_log(avctx, AV_LOG_ERROR, "Version 4 is experimental and requires -strict -2\n");
1441  return AVERROR_INVALIDDATA;
1442  }
1443 
1444  /* We target version 4.3 */
1445  if (f->version == 4 && f->micro_version > 4)
1446  f->micro_version = 3;
1447 
1448  //if (fv->ctx.ac == AC_GOLOMB_RICE) {
1449  if (0) {
1450  int w_a = FFALIGN(avctx->width, LG_ALIGN_W);
1451  int h_a = FFALIGN(avctx->height, LG_ALIGN_H);
1452  int w_sl, h_sl;
1453 
1454  /* Pixels per line an invocation handles */
1455  int ppi = 0;
1456  /* Chunk size */
1457  int chunks = 0;
1458 
1459  do {
1460  if (ppi < 2)
1461  ppi++;
1462  chunks++;
1463  w_sl = w_a / (LG_ALIGN_W*ppi);
1464  h_sl = h_a / (LG_ALIGN_H*chunks);
1465  } while (w_sl > MAX_SLICES / h_sl);
1466 
1467  av_log(avctx, AV_LOG_VERBOSE, "Slice config: %ix%i, %i total\n",
1468  LG_ALIGN_W*ppi, LG_ALIGN_H*chunks, w_sl*h_sl);
1469  av_log(avctx, AV_LOG_VERBOSE, "Horizontal slices: %i (%i pixels per invoc)\n",
1470  w_sl, ppi);
1471  av_log(avctx, AV_LOG_VERBOSE, "Vertical slices: %i (%i chunks)\n",
1472  h_sl, chunks);
1473 
1474  f->num_h_slices = w_sl;
1475  f->num_v_slices = h_sl;
1476 
1477  fv->ppi = ppi;
1478  fv->chunks = chunks;
1479  } else {
1480  f->num_h_slices = fv->num_h_slices;
1481  f->num_v_slices = fv->num_v_slices;
1482 
1483  if (f->num_h_slices <= 0 && f->num_v_slices <= 0) {
1484  if (avctx->slices) {
1485  err = ff_ffv1_encode_determine_slices(avctx);
1486  if (err < 0)
1487  return err;
1488  } else {
1489  f->num_h_slices = 32;
1490  f->num_v_slices = 32;
1491  }
1492  } else if (f->num_h_slices && f->num_v_slices <= 0) {
1493  f->num_v_slices = MAX_SLICES / f->num_h_slices;
1494  } else if (f->num_v_slices && f->num_h_slices <= 0) {
1495  f->num_h_slices = MAX_SLICES / f->num_v_slices;
1496  }
1497 
1498  f->num_h_slices = FFMIN(f->num_h_slices, avctx->width);
1499  f->num_v_slices = FFMIN(f->num_v_slices, avctx->height);
1500 
1501  if (f->num_h_slices * f->num_v_slices > MAX_SLICES) {
1502  av_log(avctx, AV_LOG_ERROR, "Too many slices (%i), maximum supported "
1503  "by the standard is %i\n",
1504  f->num_h_slices * f->num_v_slices, MAX_SLICES);
1505  return AVERROR_PATCHWELCOME;
1506  }
1507  }
1508 
1509  f->max_slice_count = f->num_h_slices * f->num_v_slices;
1510 
1511  if ((err = ff_ffv1_write_extradata(avctx)) < 0)
1512  return err;
1513 
1514  if (f->version < 4) {
1515  if (((f->chroma_h_shift > 0) && (avctx->width % (64 << f->chroma_h_shift))) ||
1516  ((f->chroma_v_shift > 0) && (avctx->height % (64 << f->chroma_v_shift)))) {
1517  av_log(avctx, AV_LOG_ERROR, "Encoding frames with subsampling and unaligned "
1518  "dimensions is only supported in version 4 (-level 4)\n");
1519  return AVERROR_PATCHWELCOME;
1520  }
1521  }
1522 
1523  if (fv->force_pcm) {
1524  if (f->version < 4) {
1525  av_log(avctx, AV_LOG_ERROR, "PCM coding only supported by version 4 (-level 4)\n");
1526  return AVERROR_INVALIDDATA;
1527  } else if (f->ac == AC_GOLOMB_RICE) {
1528  av_log(avctx, AV_LOG_ERROR, "PCM coding requires range coding\n");
1529  return AVERROR_INVALIDDATA;
1530  }
1531  }
1532 
1533  /* Init Vulkan */
1534  err = ff_vk_init(&fv->s, avctx, NULL, avctx->hw_frames_ctx);
1535  if (err < 0)
1536  return err;
1537 
1538  fv->qf = ff_vk_qf_find(&fv->s, VK_QUEUE_COMPUTE_BIT, 0);
1539  if (!fv->qf) {
1540  av_log(avctx, AV_LOG_ERROR, "Device has no compute queues!\n");
1541  return err;
1542  }
1543 
1544  /* Try to measure VRAM size */
1545  max_heap_size = 0;
1546  max_host_size = 0;
1547  for (int i = 0; i < fv->s.mprops.memoryHeapCount; i++) {
1548  if (fv->s.mprops.memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT)
1549  max_heap_size = FFMAX(fv->max_heap_size,
1550  fv->s.mprops.memoryHeaps[i].size);
1551  if (!(fv->s.mprops.memoryHeaps[i].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT))
1552  max_host_size = FFMAX(max_host_size,
1553  fv->s.mprops.memoryHeaps[i].size);
1554  }
1555  fv->max_heap_size = max_heap_size;
1556 
1557  maxsize = ff_ffv1_encode_buffer_size(avctx);
1558  if (maxsize > fv->s.props_11.maxMemoryAllocationSize) {
1559  av_log(avctx, AV_LOG_WARNING, "Encoding buffer size (%zu) larger "
1560  "than maximum device allocation (%zu), clipping\n",
1561  maxsize, fv->s.props_11.maxMemoryAllocationSize);
1562  maxsize = fv->s.props_11.maxMemoryAllocationSize;
1563  }
1564 
1565  if (max_heap_size < maxsize) {
1566  av_log(avctx, AV_LOG_WARNING, "Encoding buffer (%zu) larger than VRAM (%zu), "
1567  "using host memory (slower)\n",
1568  maxsize, fv->max_heap_size);
1569 
1570  /* Keep 1/2th of RAM as headroom */
1571  max_heap_size = max_host_size - (max_host_size >> 1);
1572  } else {
1573  /* Keep 1/8th of VRAM as headroom */
1574  max_heap_size = max_heap_size - (max_heap_size >> 3);
1575  }
1576 
1577  av_log(avctx, AV_LOG_INFO, "Async buffers: %zuMiB per context, %zuMiB total, depth: %i\n",
1578  maxsize / (1024*1024),
1579  (fv->async_depth * maxsize) / (1024*1024),
1580  fv->async_depth);
1581 
1582  err = ff_vk_exec_pool_init(&fv->s, fv->qf, &fv->exec_pool,
1583  fv->async_depth,
1584  0, 0, 0, NULL);
1585  if (err < 0)
1586  return err;
1587 
1588  fv->transfer_qf = ff_vk_qf_find(&fv->s, VK_QUEUE_TRANSFER_BIT, 0);
1589  if (!fv->transfer_qf) {
1590  av_log(avctx, AV_LOG_ERROR, "Device has no transfer queues!\n");
1591  return err;
1592  }
1593 
1594  err = ff_vk_exec_pool_init(&fv->s, fv->transfer_qf, &fv->transfer_exec_pool,
1595  1,
1596  0, 0, 0, NULL);
1597  if (err < 0)
1598  return err;
1599 
1600  spv = ff_vk_spirv_init();
1601  if (!spv) {
1602  av_log(avctx, AV_LOG_ERROR, "Unable to initialize SPIR-V compiler!\n");
1603  return AVERROR_EXTERNAL;
1604  }
1605 
1606  /* Detect the special RGB coding mode */
1607  fv->is_rgb = !(f->colorspace == 0 && avctx->sw_pix_fmt != AV_PIX_FMT_YA8) &&
1608  !(avctx->sw_pix_fmt == AV_PIX_FMT_YA8);
1609 
1610  /* Init rct search shader */
1611  fv->optimize_rct = fv->is_rgb && f->version >= 4 &&
1612  !fv->force_pcm && fv->optimize_rct;
1613  if (fv->optimize_rct) {
1614  err = init_rct_search_shader(avctx, spv);
1615  if (err < 0) {
1616  spv->uninit(&spv);
1617  return err;
1618  }
1619  }
1620 
1621  /* Init setup shader */
1622  err = init_setup_shader(avctx, spv);
1623  if (err < 0) {
1624  spv->uninit(&spv);
1625  return err;
1626  }
1627 
1628  /* Init reset shader */
1629  err = init_reset_shader(avctx, spv);
1630  if (err < 0) {
1631  spv->uninit(&spv);
1632  return err;
1633  }
1634 
1635  if (fv->is_rgb) {
1636  enum AVPixelFormat intermediate_fmt = get_supported_rgb_buffer_fmt(avctx);
1637  if (intermediate_fmt == AV_PIX_FMT_NONE) {
1638  av_log(avctx, AV_LOG_ERROR, "Unable to find a supported compatible "
1639  "pixel format for RCT buffer!\n");
1640  return AVERROR(ENOTSUP);
1641  }
1642 
1643  RET(init_indirect(avctx, intermediate_fmt));
1644  }
1645 
1646  /* Encode shader */
1647  err = init_encode_shader(avctx, spv);
1648  if (err < 0) {
1649  spv->uninit(&spv);
1650  return err;
1651  }
1652 
1653  spv->uninit(&spv);
1654 
1655  /* Range coder data */
1657  &fv->rangecoder_static_buf,
1658  f);
1659  if (err < 0)
1660  return err;
1661 
1662  /* Quantization table data */
1664  &fv->quant_buf,
1665  f);
1666  if (err < 0)
1667  return err;
1668 
1669  /* CRC table buffer */
1670  err = ff_ffv1_vk_init_crc_table_data(&fv->s,
1671  &fv->crc_tab_buf,
1672  f);
1673  if (err < 0)
1674  return err;
1675 
1676  /* Update setup global descriptors */
1678  &fv->setup, 0, 0, 0,
1679  &fv->rangecoder_static_buf,
1680  0, fv->rangecoder_static_buf.size,
1681  VK_FORMAT_UNDEFINED));
1682 
1683  /* Update encode global descriptors */
1685  &fv->enc, 0, 0, 0,
1686  &fv->rangecoder_static_buf,
1687  0, fv->rangecoder_static_buf.size,
1688  VK_FORMAT_UNDEFINED));
1690  &fv->enc, 0, 1, 0,
1691  &fv->quant_buf,
1692  0, fv->quant_buf.size,
1693  VK_FORMAT_UNDEFINED));
1695  &fv->enc, 0, 2, 0,
1696  &fv->crc_tab_buf,
1697  0, fv->crc_tab_buf.size,
1698  VK_FORMAT_UNDEFINED));
1699 
1700  /* Temporary frame */
1701  fv->frame = av_frame_alloc();
1702  if (!fv->frame)
1703  return AVERROR(ENOMEM);
1704 
1705  /* Async data pool */
1706  fv->async_depth = fv->exec_pool.pool_size;
1707  fv->exec_ctx_info = av_calloc(fv->async_depth, sizeof(*fv->exec_ctx_info));
1708  if (!fv->exec_ctx_info)
1709  return AVERROR(ENOMEM);
1710  for (int i = 0; i < fv->async_depth; i++)
1711  fv->exec_pool.contexts[i].opaque = &fv->exec_ctx_info[i];
1712 
1713  fv->buf_regions = av_malloc_array(f->max_slice_count, sizeof(*fv->buf_regions));
1714  if (!fv->buf_regions)
1715  return AVERROR(ENOMEM);
1716 
1717 fail:
1718  return err;
1719 }
1720 
1722 {
1723  VulkanEncodeFFv1Context *fv = avctx->priv_data;
1724 
1725  ff_vk_exec_pool_free(&fv->s, &fv->exec_pool);
1727 
1728  ff_vk_shader_free(&fv->s, &fv->enc);
1729  ff_vk_shader_free(&fv->s, &fv->reset);
1730  ff_vk_shader_free(&fv->s, &fv->setup);
1731  ff_vk_shader_free(&fv->s, &fv->rct_search);
1732 
1733  if (fv->exec_ctx_info) {
1734  for (int i = 0; i < fv->async_depth; i++) {
1739  }
1740  }
1741  av_free(fv->exec_ctx_info);
1742 
1744 
1746 
1748 
1751 
1752  ff_vk_free_buf(&fv->s, &fv->quant_buf);
1754  ff_vk_free_buf(&fv->s, &fv->crc_tab_buf);
1755 
1756  av_free(fv->buf_regions);
1757  av_frame_free(&fv->frame);
1758  ff_vk_uninit(&fv->s);
1759 
1760  return 0;
1761 }
1762 
1763 #define OFFSET(x) offsetof(VulkanEncodeFFv1Context, x)
1764 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1766  { "slicecrc", "Protect slices with CRCs", OFFSET(ctx.ec), AV_OPT_TYPE_INT,
1767  { .i64 = -1 }, -1, 2, VE },
1768  { "context", "Context model", OFFSET(ctx.context_model), AV_OPT_TYPE_INT,
1769  { .i64 = 0 }, 0, 1, VE },
1770  { "coder", "Coder type", OFFSET(ctx.ac), AV_OPT_TYPE_INT,
1771  { .i64 = AC_RANGE_CUSTOM_TAB }, -2, 2, VE, .unit = "coder" },
1772  { "rice", "Golomb rice", 0, AV_OPT_TYPE_CONST,
1773  { .i64 = AC_GOLOMB_RICE }, INT_MIN, INT_MAX, VE, .unit = "coder" },
1774  { "range_def", "Range with default table", 0, AV_OPT_TYPE_CONST,
1775  { .i64 = AC_RANGE_DEFAULT_TAB_FORCE }, INT_MIN, INT_MAX, VE, .unit = "coder" },
1776  { "range_tab", "Range with custom table", 0, AV_OPT_TYPE_CONST,
1777  { .i64 = AC_RANGE_CUSTOM_TAB }, INT_MIN, INT_MAX, VE, .unit = "coder" },
1778  { "qtable", "Quantization table", OFFSET(ctx.qtable), AV_OPT_TYPE_INT,
1779  { .i64 = -1 }, -1, 2, VE , .unit = "qtable"},
1780  { "default", NULL, 0, AV_OPT_TYPE_CONST,
1781  { .i64 = QTABLE_DEFAULT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },
1782  { "8bit", NULL, 0, AV_OPT_TYPE_CONST,
1783  { .i64 = QTABLE_8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },
1784  { "greater8bit", NULL, 0, AV_OPT_TYPE_CONST,
1785  { .i64 = QTABLE_GT8BIT }, INT_MIN, INT_MAX, VE, .unit = "qtable" },
1786 
1787  { "slices_h", "Number of horizontal slices", OFFSET(num_h_slices), AV_OPT_TYPE_INT,
1788  { .i64 = -1 }, -1, MAX_SLICES, VE },
1789  { "slices_v", "Number of vertical slices", OFFSET(num_v_slices), AV_OPT_TYPE_INT,
1790  { .i64 = -1 }, -1, MAX_SLICES, VE },
1791 
1792  { "force_pcm", "Code all slices with no prediction", OFFSET(force_pcm), AV_OPT_TYPE_BOOL,
1793  { .i64 = 0 }, 0, 1, VE },
1794 
1795  { "rct_search", "Run a search for RCT parameters (level 4 only)", OFFSET(optimize_rct), AV_OPT_TYPE_BOOL,
1796  { .i64 = 1 }, 0, 1, VE },
1797 
1798  { "async_depth", "Internal parallelization depth", OFFSET(async_depth), AV_OPT_TYPE_INT,
1799  { .i64 = 1 }, 1, INT_MAX, VE },
1800 
1801  { NULL }
1802 };
1803 
1805  { "g", "1" },
1806  { NULL },
1807 };
1808 
1810  .class_name = "ffv1_vulkan",
1811  .item_name = av_default_item_name,
1812  .option = vulkan_encode_ffv1_options,
1813  .version = LIBAVUTIL_VERSION_INT,
1814 };
1815 
1817  HW_CONFIG_ENCODER_FRAMES(VULKAN, VULKAN),
1818  NULL,
1819 };
1820 
1822  .p.name = "ffv1_vulkan",
1823  CODEC_LONG_NAME("FFmpeg video codec #1 (Vulkan)"),
1824  .p.type = AVMEDIA_TYPE_VIDEO,
1825  .p.id = AV_CODEC_ID_FFV1,
1826  .priv_data_size = sizeof(VulkanEncodeFFv1Context),
1829  .close = &vulkan_encode_ffv1_close,
1830  .p.priv_class = &vulkan_encode_ffv1_class,
1831  .p.capabilities = AV_CODEC_CAP_DELAY |
1837  .defaults = vulkan_encode_ffv1_defaults,
1839  .hw_configs = vulkan_encode_ffv1_hw_configs,
1840  .p.wrapper_name = "vulkan",
1841 };
hwconfig.h
init_rct_search_shader
static int init_rct_search_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv)
Definition: ffv1enc_vulkan.c:1008
VulkanEncodeFFv1Context::rangecoder_static_buf
FFVkBuffer rangecoder_static_buf
Definition: ffv1enc_vulkan.c:83
CODEC_PIXFMTS
#define CODEC_PIXFMTS(...)
Definition: codec_internal.h:392
FFv1VkResetParameters::context_count
uint32_t context_count[MAX_QUANT_TABLES]
Definition: ffv1_vulkan.h:52
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
FFv1VkParameters::planes
uint8_t planes
Definition: ffv1enc_vulkan.c:141
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
FFv1VkParameters::extend_lookup
uint8_t extend_lookup[8]
Definition: ffv1enc_vulkan.c:133
add_push_data
static void add_push_data(FFVulkanShader *shd)
Definition: ffv1enc_vulkan.c:154
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:281
FFv1VkRCTSearchParameters::force_pcm
uint8_t force_pcm
Definition: ffv1enc_vulkan.c:201
ff_vk_shader_free
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition: vulkan.c:2961
ff_vk_shader_init
int ff_vk_shader_init(FFVulkanContext *s, FFVulkanShader *shd, const char *name, VkPipelineStageFlags stage, const char *extensions[], int nb_extensions, int lg_x, int lg_y, int lg_z, uint32_t required_subgroup_size)
Initialize a shader object, with a specific set of extensions, type+bind, local group size,...
Definition: vulkan.c:2093
QTABLE_8BIT
@ QTABLE_8BIT
Definition: ffv1enc.h:30
AVBufferPool
The buffer pool.
Definition: buffer_internal.h:88
FFVulkanContext::device_ref
AVBufferRef * device_ref
Definition: vulkan.h:304
FFVkExecPool::contexts
FFVkExecContext * contexts
Definition: vulkan.h:253
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
FFv1VkParameters::scratch_data
VkDeviceAddress scratch_data
Definition: ffv1enc_vulkan.c:120
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:66
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:356
VulkanEncodeFFv1Context::is_rgb
int is_rgb
Definition: ffv1enc_vulkan.c:104
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
FFVkBuffer::access
VkAccessFlags2 access
Definition: vulkan.h:96
int64_t
long long int64_t
Definition: coverity.c:34
VulkanEncodeFFv1Context::in_flight
int in_flight
Definition: ffv1enc_vulkan.c:72
FFVkBuffer::stage
VkPipelineStageFlags2 stage
Definition: vulkan.h:95
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
FFv1VkParameters::key_frame
uint8_t key_frame
Definition: ffv1enc_vulkan.c:139
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:337
ff_ffv1_vk_init_quant_table_data
int ff_ffv1_vk_init_quant_table_data(FFVulkanContext *s, FFVkBuffer *vkb, FFV1Context *f)
Definition: ffv1_vulkan.c:72
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
FFv1VkParameters::slice_state
VkDeviceAddress slice_state
Definition: ffv1enc_vulkan.c:119
VulkanEncodeFFv1Context::chunks
int chunks
Definition: ffv1enc_vulkan.c:106
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
FFv1VkRCTSearchParameters::planar_rgb
uint8_t planar_rgb
Definition: ffv1enc_vulkan.c:198
AVOption
AVOption.
Definition: opt.h:429
encode.h
FFVulkanShader::src
AVBPrint src
Definition: vulkan.h:195
MAX_QUANT_TABLE_SIZE
#define MAX_QUANT_TABLE_SIZE
Definition: ffv1.h:48
VulkanEncodeFFv1Context::rct_search
FFVulkanShader rct_search
Definition: ffv1enc_vulkan.c:77
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
FFv1VkResetParameters::slice_state
VkDeviceAddress slice_state
Definition: ffv1_vulkan.h:53
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:92
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:3014
ff_vk_exec_get
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition: vulkan.c:547
FF_VK_REP_NATIVE
@ FF_VK_REP_NATIVE
Definition: vulkan.h:406
ff_vk_uninit
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition: vulkan.c:3002
FF_COMPLIANCE_EXPERIMENTAL
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
Definition: defs.h:62
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
FFVkSPIRVCompiler::uninit
void(* uninit)(struct FFVkSPIRVCompiler **ctx)
Definition: vulkan_spirv.h:32
define_shared_code
static void define_shared_code(AVCodecContext *avctx, FFVulkanShader *shd)
Definition: ffv1enc_vulkan.c:979
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:220
av_hwdevice_get_hwframe_constraints
AVHWFramesConstraints * av_hwdevice_get_hwframe_constraints(AVBufferRef *ref, const void *hwconfig)
Get the constraints on HW frames given a device and the HW-specific configuration to be used with tha...
Definition: hwcontext.c:581
AC_RANGE_CUSTOM_TAB
#define AC_RANGE_CUSTOM_TAB
Definition: ffv1.h:54
FFv1VkParameters::micro_version
uint8_t micro_version
Definition: ffv1enc_vulkan.c:137
ff_source_ffv1_reset_comp
const char * ff_source_ffv1_reset_comp
FFv1VkParameters::padding
uint8_t padding[3]
Definition: ffv1enc_vulkan.c:151
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:779
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:448
FFVkBuffer::buf
VkBuffer buf
Definition: vulkan.h:88
AVHWFramesConstraints
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition: hwcontext.h:444
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
FFv1VkRCTSearchParameters::rct_offset
int rct_offset
Definition: ffv1enc_vulkan.c:197
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3496
AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition: avcodec.h:279
vulkan_encode_ffv1_class
static const AVClass vulkan_encode_ffv1_class
Definition: ffv1enc_vulkan.c:1809
MAX_QUANT_TABLE_MASK
#define MAX_QUANT_TABLE_MASK
Definition: ffv1.h:49
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:303
VulkanEncodeFFv1FrameData::key_frame
int key_frame
Definition: ffv1enc_vulkan.c:56
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:100
FFv1VkParameters::sar
int32_t sar[2]
Definition: ffv1enc_vulkan.c:124
fail
#define fail()
Definition: checkasm.h:208
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:558
FFv1VkParameters::out_data
VkDeviceAddress out_data
Definition: ffv1enc_vulkan.c:121
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:2838
AVVulkanFramesContext
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
Definition: hwcontext_vulkan.h:208
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
FFv1VkParameters::transparency
uint8_t transparency
Definition: ffv1enc_vulkan.c:144
VulkanEncodeFFv1Context::crc_tab_buf
FFVkBuffer crc_tab_buf
Definition: ffv1enc_vulkan.c:84
FFv1VkParameters::force_pcm
uint8_t force_pcm
Definition: ffv1enc_vulkan.c:138
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:2601
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:488
VulkanEncodeFFv1Context::ppi
int ppi
Definition: ffv1enc_vulkan.c:105
FFv1VkParameters::plane_state_size
uint32_t plane_state_size
Definition: ffv1enc_vulkan.c:127
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:1392
MAX_SLICES
#define MAX_SLICES
Definition: d3d12va_hevc.c:33
ff_vk_shader_add_descriptor_set
int ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a shader.
Definition: vulkan.c:2465
CONTEXT_SIZE
#define CONTEXT_SIZE
Definition: ffv1.h:45
FFv1VkParameters::pic_mode
uint8_t pic_mode
Definition: ffv1enc_vulkan.c:146
AV_CODEC_CAP_ENCODER_FLUSH
#define AV_CODEC_CAP_ENCODER_FLUSH
This encoder can be flushed using avcodec_flush_buffers().
Definition: codec.h:151
VulkanEncodeFFv1Context::keyframe_slice_data_ref
AVBufferRef * keyframe_slice_data_ref
Definition: ffv1enc_vulkan.c:88
ff_source_ffv1_enc_setup_comp
const char * ff_source_ffv1_enc_setup_comp
VulkanEncodeFFv1FrameData::frame_opaque_ref
AVBufferRef * frame_opaque_ref
Definition: ffv1enc_vulkan.c:54
AVRational::num
int num
Numerator.
Definition: rational.h:59
ff_ffv1_vulkan_encoder
const FFCodec ff_ffv1_vulkan_encoder
Definition: ffv1enc_vulkan.c:1821
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
VulkanEncodeFFv1Context::s
FFVulkanContext s
Definition: ffv1enc_vulkan.c:63
GLSLC
#define GLSLC(N, S)
Definition: vulkan.h:43
VulkanEncodeFFv1FrameData
Definition: ffv1enc_vulkan.c:43
FFv1VkRCTSearchParameters::micro_version
uint8_t micro_version
Definition: ffv1enc_vulkan.c:203
vulkan_encode_ffv1_hw_configs
const AVCodecHWConfigInternal *const vulkan_encode_ffv1_hw_configs[]
Definition: ffv1enc_vulkan.c:1816
get_packet
static int get_packet(AVCodecContext *avctx, FFVkExecContext *exec, AVPacket *pkt)
Definition: ffv1enc_vulkan.c:748
pkt
AVPacket * pkt
Definition: movenc.c:60
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:71
VulkanEncodeFFv1Context::results_data_pool
AVBufferPool * results_data_pool
Definition: ffv1enc_vulkan.c:94
av_cold
#define av_cold
Definition: attributes.h:106
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)
Definition: ffv1enc_vulkan.c:207
VulkanEncodeFFv1Context::setup
FFVulkanShader setup
Definition: ffv1enc_vulkan.c:76
AVHWFramesContext::height
int height
Definition: hwcontext.h:220
FFv1VkParameters::codec_planes
uint8_t codec_planes
Definition: ffv1enc_vulkan.c:142
AVHWFramesConstraints::valid_sw_formats
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
Definition: hwcontext.h:456
FFV1Context::use32bit
int use32bit
Definition: ffv1.h:158
LG_ALIGN_W
#define LG_ALIGN_W
Definition: ffv1enc_vulkan.c:37
av_hwframe_constraints_free
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
Definition: hwcontext.c:606
AV_PIX_FMT_RGB96
#define AV_PIX_FMT_RGB96
Definition: pixfmt.h:629
FFVulkanContext::driver_props
VkPhysicalDeviceDriverProperties driver_props
Definition: vulkan.h:282
FFv1VkParameters::bits_per_raw_sample
uint8_t bits_per_raw_sample
Definition: ffv1enc_vulkan.c:134
ff_vk_exec_wait
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:552
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:1582
VulkanEncodeFFv1Context::max_heap_size
size_t max_heap_size
Definition: ffv1enc_vulkan.c:74
AVVulkanFramesContext::img_flags
VkImageCreateFlags img_flags
Flags to set during image creation.
Definition: hwcontext_vulkan.h:261
vulkan_encode_ffv1_receive_packet
static int vulkan_encode_ffv1_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: ffv1enc_vulkan.c:842
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
AVFormatContext * ctx
Definition: movenc.c:49
VulkanEncodeFFv1Context::transfer_qf
AVVulkanDeviceQueueFamily * transfer_qf
Definition: ffv1enc_vulkan.c:67
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:619
FFV1Context::ac
int ac
1=range coder <-> 0=golomb rice
Definition: ffv1.h:147
GLSLD
#define GLSLD(D)
Definition: vulkan.h:58
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
FFv1VkParameters::crcref
uint32_t crcref
Definition: ffv1enc_vulkan.c:129
ff_vk_exec_pool_free
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
Definition: vulkan.c:287
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
FFv1VkRCTSearchParameters::transparency
uint8_t transparency
Definition: ffv1enc_vulkan.c:199
FFv1VkParameters::chroma_shift
uint32_t chroma_shift[2]
Definition: ffv1enc_vulkan.c:125
VulkanEncodeFFv1Context::frame
AVFrame * frame
Definition: ffv1enc_vulkan.c:61
TYPE
#define TYPE
Definition: ffv1dec.c:96
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:571
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_vk_shader_rep_fmt
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt, enum FFVkShaderRepFormat rep_fmt)
Definition: vulkan.c:1626
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:213
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
FFv1VkParameters::ppi
uint8_t ppi
Definition: ffv1enc_vulkan.c:148
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
AVPixFmtDescriptor::nb_components
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
FFV1Context::num_v_slices
int num_v_slices
Definition: ffv1.h:174
VulkanEncodeFFv1Context::force_pcm
int force_pcm
Definition: ffv1enc_vulkan.c:101
FFv1VkParameters::version
uint8_t version
Definition: ffv1enc_vulkan.c:136
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:367
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:241
av_buffer_pool_uninit
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:328
FFVkExecContext::had_submission
int had_submission
Definition: vulkan.h:114
FFVkBuffer::size
size_t size
Definition: vulkan.h:91
AVVulkanFramesContext::usage
VkImageUsageFlagBits usage
Defines extra usage of output frames.
Definition: hwcontext_vulkan.h:228
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:673
ffv1_vulkan.h
VulkanEncodeFFv1Context::num_h_slices
int num_h_slices
Definition: ffv1enc_vulkan.c:99
FFVkBuffer::mapped_mem
uint8_t * mapped_mem
Definition: vulkan.h:100
FFVulkanContext
Definition: vulkan.h:274
FFv1VkParameters::planar_rgb
uint8_t planar_rgb
Definition: ffv1enc_vulkan.c:143
VulkanEncodeFFv1FrameData::duration
int64_t duration
Definition: ffv1enc_vulkan.c:52
VulkanEncodeFFv1Context
Definition: ffv1enc_vulkan.c:59
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:87
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:550
FFv1VkParameters::fmt_lut
int32_t fmt_lut[4]
Definition: ffv1enc_vulkan.c:123
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:60
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:2917
AVPacket::size
int size
Definition: packet.h:589
FFVulkanDescriptorSetBinding
Definition: vulkan.h:74
VulkanEncodeFFv1FrameData::pts
int64_t pts
Definition: ffv1enc_vulkan.c:51
AVCodecContext::gop_size
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1005
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:298
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
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:525
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:896
FFVulkanShader
Definition: vulkan.h:190
FFv1VkRCTSearchParameters::version
uint8_t version
Definition: ffv1enc_vulkan.c:202
ff_ffv1_vk_init_crc_table_data
int ff_ffv1_vk_init_crc_table_data(FFVulkanContext *s, FFVkBuffer *vkb, FFV1Context *f)
Definition: ffv1_vulkan.c:100
VulkanEncodeFFv1Context::optimize_rct
int optimize_rct
Definition: ffv1enc_vulkan.c:102
AVCodecHWConfigInternal
Definition: hwconfig.h:25
FFVkBuffer::flags
VkMemoryPropertyFlagBits flags
Definition: vulkan.h:90
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
FFVkSPIRVCompiler::compile_shader
int(* compile_shader)(FFVulkanContext *s, struct FFVkSPIRVCompiler *ctx, FFVulkanShader *shd, uint8_t **data, size_t *size, const char *entrypoint, void **opaque)
Definition: vulkan_spirv.h:28
VulkanEncodeFFv1FrameData::out_data_ref
AVBufferRef * out_data_ref
Definition: ffv1enc_vulkan.c:45
init_setup_shader
static int init_setup_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv)
Definition: ffv1enc_vulkan.c:1107
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
FFVkExecContext
Definition: vulkan.h:111
init_reset_shader
static int init_reset_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv)
Definition: ffv1enc_vulkan.c:1192
FFv1VkRCTSearchParameters::fmt_lut
int fmt_lut[4]
Definition: ffv1enc_vulkan.c:196
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:2851
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:594
FFVulkanDescriptorSetBinding::name
const char * name
Definition: vulkan.h:75
version
version
Definition: libkvazaar.c:313
VulkanEncodeFFv1Context::enc
FFVulkanShader enc
Definition: ffv1enc_vulkan.c:79
ff_vk_mt_is_np_rgb
int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
Returns 1 if pixfmt is a usable RGB format.
Definition: vulkan.c:1560
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
VulkanEncodeFFv1Context::quant_buf
FFVkBuffer quant_buf
Definition: ffv1enc_vulkan.c:82
FFVkSPIRVCompiler
Definition: vulkan_spirv.h:26
VE
#define VE
Definition: ffv1enc_vulkan.c:1764
layout
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 layout
Definition: filter_design.txt:18
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
ff_vk_exec_start
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition: vulkan.c:559
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
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
VulkanEncodeFFv1FrameData::results_data_ref
AVBufferRef * results_data_ref
Definition: ffv1enc_vulkan.c:48
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
init_encode_shader
static int init_encode_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv)
Definition: ffv1enc_vulkan.c:1280
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
ff_vk_shader_link
int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, uint8_t *spirv, size_t spirv_len, const char *entrypoint)
Link a shader into an executable.
Definition: vulkan.c:2390
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:89
planes
static const struct @546 planes[]
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
vulkan_spirv.h
vulkan_encode_ffv1_close
static av_cold int vulkan_encode_ffv1_close(AVCodecContext *avctx)
Definition: ffv1enc_vulkan.c:1721
FFVulkanContext::props
VkPhysicalDeviceProperties2 props
Definition: vulkan.h:280
FFVulkanContext::extensions
FFVulkanExtensions extensions
Definition: vulkan.h:279
ff_vk_free_buf
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
Definition: vulkan.c:1243
AVCodecContext::height
int height
Definition: avcodec.h:592
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
MAX_CONTEXT_INPUTS
#define MAX_CONTEXT_INPUTS
Definition: ffv1.h:50
FFVkSPIRVCompiler::free_shader
void(* free_shader)(struct FFVkSPIRVCompiler *ctx, void **opaque)
Definition: vulkan_spirv.h:31
FFVulkanContext::mprops
VkPhysicalDeviceMemoryProperties mprops
Definition: vulkan.h:283
ff_vk_exec_bind_shader
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd)
Bind a shader.
Definition: vulkan.c:2927
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:1453
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:1685
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:278
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:1357
VulkanEncodeFFv1Context::exec_pool
FFVkExecPool exec_pool
Definition: ffv1enc_vulkan.c:65
FFVkExecContext::opaque
void * opaque
Definition: vulkan.h:128
FFv1VkRCTSearchParameters::padding
uint8_t padding[2]
Definition: ffv1enc_vulkan.c:204
FFVkExecPool
Definition: vulkan.h:252
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:122
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:1490
VulkanEncodeFFv1Context::intermediate_frames_ref
AVBufferRef * intermediate_frames_ref
Definition: ffv1enc_vulkan.c:97
VulkanEncodeFFv1FrameData::frame_opaque
void * frame_opaque
Definition: ffv1enc_vulkan.c:53
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:274
vulkan_encode_ffv1_options
static const AVOption vulkan_encode_ffv1_options[]
Definition: ffv1enc_vulkan.c:1765
FFVkExecContext::buf
VkCommandBuffer buf
Definition: vulkan.h:122
AVFrame::hw_frames_ctx
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
Definition: frame.h:724
FFv1VkRCTSearchParameters
Definition: ffv1enc_vulkan.c:195
AVCodecContext
main external API structure.
Definition: avcodec.h:431
VulkanEncodeFFv1Context::transfer_exec_pool
FFVkExecPool transfer_exec_pool
Definition: ffv1enc_vulkan.c:68
check_support
static int check_support(AVHWFramesConstraints *constraints, enum AVPixelFormat fmt)
Definition: ffv1enc_vulkan.c:931
ff_ffv1_vk_init_state_transition_data
int ff_ffv1_vk_init_state_transition_data(FFVulkanContext *s, FFVkBuffer *vkb, FFV1Context *f)
Definition: ffv1_vulkan.c:65
FFV1Context::context_model
int context_model
Definition: ffv1.h:163
RGB_LINECACHE
#define RGB_LINECACHE
Definition: ffv1enc_vulkan.c:41
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:78
FFv1VkParameters::rct_offset
int rct_offset
Definition: ffv1enc_vulkan.c:131
GLSLF
#define GLSLF(N, S,...)
Definition: vulkan.h:53
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
QTABLE_GT8BIT
@ QTABLE_GT8BIT
Definition: ffv1enc.h:31
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:73
FFv1VkParameters::context_model
uint8_t context_model
Definition: ffv1enc_vulkan.c:135
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:258
AVVulkanFramesContext::tiling
VkImageTiling tiling
Controls the tiling of allocated frames.
Definition: hwcontext_vulkan.h:217
FFv1VkResetParameters
Definition: ffv1_vulkan.h:51
FFv1VkParameters::colorspace
uint8_t colorspace
Definition: ffv1enc_vulkan.c:145
VulkanEncodeFFv1Context::qf
AVVulkanDeviceQueueFamily * qf
Definition: ffv1enc_vulkan.c:64
vulkan_encode_ffv1_defaults
static const FFCodecDefault vulkan_encode_ffv1_defaults[]
Definition: ffv1enc_vulkan.c:1804
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFVulkanContext::hwctx
AVVulkanDeviceContext * hwctx
Definition: vulkan.h:306
VulkanEncodeFFv1Context::buf_regions
VkBufferCopy * buf_regions
Definition: ffv1enc_vulkan.c:70
mem.h
ff_encode_get_frame
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:204
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
MAX_QUANT_TABLES
#define MAX_QUANT_TABLES
Definition: ffv1.h:47
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
LG_ALIGN_H
#define LG_ALIGN_H
Definition: ffv1enc_vulkan.c:38
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
FFV1Context::transparency
int transparency
Definition: ffv1.h:133
ff_vk_count_images
static int ff_vk_count_images(AVVkFrame *f)
Definition: vulkan.h:323
ff_vk_exec_discard_deps
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:591
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVCodecContext::slices
int slices
Number of slices.
Definition: avcodec.h:1021
AVPacket
This structure stores compressed data.
Definition: packet.h:565
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
FFVkBuffer
Definition: vulkan.h:87
FFv1VkParameters::components
uint8_t components
Definition: ffv1enc_vulkan.c:140
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:592
vulkan_encode_ffv1_init
static av_cold int vulkan_encode_ffv1_init(AVCodecContext *avctx)
Definition: ffv1enc_vulkan.c:1400
int32_t
int32_t
Definition: audioconvert.c:56
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:904
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVVulkanDeviceQueueFamily
Definition: hwcontext_vulkan.h:33
QTABLE_DEFAULT
@ QTABLE_DEFAULT
Definition: ffv1enc.h:29
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
FFVulkanContext::frames
AVHWFramesContext * frames
Definition: vulkan.h:310
FFv1VkParameters
Definition: ffv1enc_vulkan.c:118
get_supported_rgb_buffer_fmt
static enum AVPixelFormat get_supported_rgb_buffer_fmt(AVCodecContext *avctx)
Definition: ffv1enc_vulkan.c:941
OFFSET
#define OFFSET(x)
Definition: ffv1enc_vulkan.c:1763
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:638
FFv1VkRCTSearchParameters::key_frame
uint8_t key_frame
Definition: ffv1enc_vulkan.c:200
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
FFv1VkParameters::chunks
uint8_t chunks
Definition: ffv1enc_vulkan.c:149
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
FFv1VkParameters::context_count
uint32_t context_count
Definition: ffv1enc_vulkan.c:128
FFVulkanFunctions
Definition: vulkan_functions.h:277
FFVkExecPool::pool_size
int pool_size
Definition: vulkan.h:258
FFv1VkParameters::slice_size_max
uint32_t slice_size_max
Definition: ffv1enc_vulkan.c:130
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:1285
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
FFv1VkParameters::rct_search
uint8_t rct_search
Definition: ffv1enc_vulkan.c:150
ff_source_ffv1_rct_search_comp
const char * ff_source_ffv1_rct_search_comp
FFv1VkParameters::ec
uint8_t ec
Definition: ffv1enc_vulkan.c:147
VulkanEncodeFFv1Context::out_data_pool
AVBufferPool * out_data_pool
Definition: ffv1enc_vulkan.c:91
ff_source_rangecoder_comp
const char * ff_source_rangecoder_comp