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