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