FFmpeg
apv_encode_vulkan.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2026 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 <math.h>
22 #include <stdlib.h>
23 
24 #include "libavutil/mem.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/pixdesc.h"
27 #include "libavutil/vulkan.h"
28 #include "libavutil/vulkan_spirv.h"
29 
30 #include "avcodec.h"
31 #include "codec_internal.h"
32 #include "encode.h"
33 #include "hwconfig.h"
34 #include "internal.h"
35 
36 #include "apv.h"
37 #include "cbs.h"
38 #include "cbs_apv.h"
39 
40 extern const unsigned char ff_apv_encode_dct_comp_spv_data[];
41 extern const unsigned int ff_apv_encode_dct_comp_spv_len;
42 
43 extern const unsigned char ff_apv_encode_tiles_comp_spv_data[];
44 extern const unsigned int ff_apv_encode_tiles_comp_spv_len;
45 
46 extern const unsigned char ff_seg_gather_comp_spv_data[];
47 extern const unsigned int ff_seg_gather_comp_spv_len;
48 
49 #define APV_DEFAULT_QMAT 16
50 #define APV_MAX_NUM_COMP 4
51 
52 typedef struct DCTPushData {
53  int frame_dim[2];
54  int tile_count[2];
55  int tile_mb_dim[2];
57  int num_comp;
58  int bit_depth;
59  float qf[APV_MAX_NUM_COMP]; /* per-component fact/(level_scale*2^qp_shift) */
60  uint8_t qmat[64]; /* quantisation matrix, raster order */
61 } DCTPushData;
62 
63 typedef struct EntropyPushData {
64  VkDeviceAddress bytestream;
65  int tile_count[2];
66  int num_comp;
67  uint32_t slot_size;
68  uint32_t comp_base; /* component index this dispatch's z=0 maps to */
69  uint32_t blocks_per_tile; /* uniform coeff stride, in blocks */
70  int frame_mb[2]; /* frame size in MBs (luma basis) */
71  int tile_mb_dim[2]; /* full-tile size in MBs */
72  uint32_t blocks_per_mb; /* blocks per MB of this dispatch's components */
74 
75 typedef struct CompactPushData {
76  VkDeviceAddress sparse;
77  VkDeviceAddress compacted;
78  uint32_t slot_size;
80 
81 typedef struct VulkanEncodeAPVFrameData {
86 
89  void *frame_opaque;
91  int flags;
93 
94 typedef struct VulkanEncodeAPVContext {
95  const AVClass *class;
96 
100 
102  FFVulkanShader shd_entropy[2]; /* [0] luma-sized, [1] chroma-sized */
104 
105  /* Per-frame buffer pools */
110 
111  /* DCT/quantize push constants -- encoder-constant, built once at init. */
113 
114  /* CBS used to assemble the output packet */
117 
119 
120  /* Async machinery */
124 
125  /* Derived per-encoder state */
126  int frame_mb_x, frame_mb_y; /* MBs in the frame (luma basis) */
128  int tile_mb_w, tile_mb_h; /* MBs per tile (luma basis) */
130  int blocks_per_mb; /* luma; always 4 */
131  int chroma_blocks_per_mb; /* 4 for 4:4:4, 2 for 4:2:2 */
132  int num_comp;
135 
138  int band_idc;
140 
141  size_t coeffs_size; /* total size of coeffs buffer */
142  size_t bytestream_size; /* total size of bytestream buffer */
143  size_t slot_size; /* per-tile-component bytestream slot size */
144  size_t sizes_size; /* total size of sizes buffer */
145 
146  /* User options */
149  int qp_y;
150  int qp_c;
151  int qmatrix; /* APV_QMATRIX_*: quantisation matrix select */
152 
153  /* Benchmark knob (env APV_VULKAN_HEADERS_ONLY): the GPU still encodes,
154  * but the tiles are never downloaded and packets carry headers only. */
156 
157  /* Benchmark knob (env APV_VULKAN_SKIP_ENTROPY): skip the entropy
158  * dispatch to isolate the DCT pass. Implies headers_only. */
161 
162 /*
163  * HEVC default 8x8 intra scaling list (ITU-T H.265, Table 7-6): flat through
164  * the low-frequency core, a gentle ramp toward the high-frequency corner.
165  * Raster order; the matrix is symmetric, so APV's [y][x]/[x][y] indexing is
166  * immaterial. APV and HEVC share the "16 = neutral" convention, so the list
167  * transfers without rescaling.
168  */
169 static const uint8_t apv_qmat_hevc_intra[64] = {
170  16, 16, 16, 16, 17, 18, 21, 24,
171  16, 16, 16, 16, 17, 19, 22, 25,
172  16, 16, 17, 18, 20, 22, 25, 29,
173  16, 16, 18, 21, 24, 27, 31, 36,
174  17, 17, 20, 24, 30, 35, 41, 47,
175  18, 19, 22, 27, 35, 44, 54, 65,
176  21, 22, 25, 31, 41, 54, 70, 88,
177  24, 25, 29, 36, 47, 65, 88, 115,
178 };
179 
180 enum {
181  APV_QMATRIX_FLAT = 0, /* uniform 16 (the spec default) */
182  APV_QMATRIX_HEVC = 1, /* HEVC default intra scaling list */
183 };
184 
185 /*
186  * The active quantisation-matrix value at raster index i. Both the q_matrix
187  * signalled in the frame header and the encoder's pf table are derived from
188  * this single accessor, so they cannot disagree -- a mismatch would quantise
189  * against a different matrix than the decoder dequantises with.
190  */
191 static int apv_qmatrix_value(int qmatrix, int i)
192 {
193  return qmatrix == APV_QMATRIX_HEVC ? apv_qmat_hevc_intra[i]
195 }
196 
197 static const uint8_t apv_level_scale[6] = { 40, 45, 51, 57, 64, 71 };
198 
200 {
201  switch (sw_fmt) {
204  return APV_CHROMA_FORMAT_422;
207  return APV_CHROMA_FORMAT_444;
208  case AV_PIX_FMT_GRAY10:
209  case AV_PIX_FMT_GRAY12:
210  return APV_CHROMA_FORMAT_400;
213  return APV_CHROMA_FORMAT_4444;
214  default:
215  return -1;
216  }
217 }
218 
220 {
221  switch (sw_fmt) {
229  default: return -1;
230  }
231 }
232 
233 static int init_dct_shader(AVCodecContext *avctx)
234 {
235  int err;
236  VulkanEncodeAPVContext *ev = avctx->priv_data;
237  FFVulkanShader *shd = &ev->shd_dct;
238 
239  SPEC_LIST_CREATE(sl, 1, sizeof(uint32_t))
240  SPEC_LIST_ADD(sl, 16, 32, 4); /* nb_blocks: blocks_per_mb per workgroup */
241 
242  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
243  (uint32_t []) { 8, 4, 1 }, 0);
244 
246  VK_SHADER_STAGE_COMPUTE_BIT);
247 
248  const FFVulkanDescriptorSetBinding desc_set[] = {
249  {
250  .name = "coeffs_buf",
251  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
252  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
253  },
254  {
255  .name = "src",
256  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
257  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
258  .elems = av_pix_fmt_count_planes(ev->sw_format),
259  },
260  };
261  RET(ff_vk_shader_add_descriptor_set(&ev->s, shd, desc_set, 2, 0, 0));
262 
263  RET(ff_vk_shader_link(&ev->s, shd,
266 
267  RET(ff_vk_shader_register_exec(&ev->s, &ev->exec_pool, shd));
268 
269 fail:
270  return err;
271 }
272 
273 static int init_entropy_shader(AVCodecContext *avctx, int blocks_per_mb,
274  FFVulkanShader *shd)
275 {
276  int err;
277  VulkanEncodeAPVContext *ev = avctx->priv_data;
278 
279  /* One workgroup per tile-component, one invocation per transform block.
280  * Luma and chroma tile-components hold different block counts under
281  * chroma sub-sampling, so each gets a pipeline with its own size. */
282  uint32_t wg = ev->tile_mb_w * ev->tile_mb_h * blocks_per_mb;
283 
284  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, NULL,
285  (uint32_t []) { wg, 1, 1 }, 0);
286 
288  VK_SHADER_STAGE_COMPUTE_BIT);
289 
290  const FFVulkanDescriptorSetBinding desc_set[] = {
291  {
292  .name = "coeffs_buf",
293  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
294  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
295  },
296  {
297  .name = "sizes_buf",
298  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
299  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
300  },
301  };
302  RET(ff_vk_shader_add_descriptor_set(&ev->s, shd, desc_set, 2, 0, 0));
303 
304  RET(ff_vk_shader_link(&ev->s, shd,
307 
308  RET(ff_vk_shader_register_exec(&ev->s, &ev->exec_pool, shd));
309 
310 fail:
311  return err;
312 }
313 
315 {
316  int err;
317  VulkanEncodeAPVContext *ev = avctx->priv_data;
318  FFVulkanShader *shd = &ev->shd_compact;
319 
320  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, NULL,
321  (uint32_t []) { 256, 1, 1 }, 0);
322 
324  VK_SHADER_STAGE_COMPUTE_BIT);
325 
326  const FFVulkanDescriptorSetBinding desc_set[] = {
327  {
328  .name = "sizes_buf",
329  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
330  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
331  },
332  };
333  RET(ff_vk_shader_add_descriptor_set(&ev->s, shd, desc_set, 1, 0, 0));
334 
335  RET(ff_vk_shader_link(&ev->s, shd,
337  ff_seg_gather_comp_spv_len, "main"));
338 
339  RET(ff_vk_shader_register_exec(&ev->s, &ev->exec_pool, shd));
340 
341 fail:
342  return err;
343 }
344 
345 /*
346  * The DCT/quantize shader's push constants are entirely encoder-constant:
347  * frame geometry, the per-component quant scale qf, and the quantisation
348  * matrix. Build them once -- nothing here changes between frames.
349  */
351 {
352  VulkanEncodeAPVContext *ev = avctx->priv_data;
354  DCTPushData *pd = &ev->dct_push;
355  const double fact = (double)(1 << (ev->bit_depth - 1));
356 
357  pd->frame_dim[0] = avctx->width;
358  pd->frame_dim[1] = avctx->height;
359  pd->tile_count[0] = ev->tile_cols;
360  pd->tile_count[1] = ev->tile_rows;
361  pd->tile_mb_dim[0] = ev->tile_mb_w;
362  pd->tile_mb_dim[1] = ev->tile_mb_h;
363  pd->log2_chroma_sub[0] = desc->log2_chroma_w;
364  pd->log2_chroma_sub[1] = desc->log2_chroma_h;
365  pd->num_comp = ev->num_comp;
366  pd->bit_depth = ev->bit_depth;
367 
368  /*
369  * qf[c] = fact / (level_scale * 2^qp_shift). The encoder uses one QP per
370  * component, so this never varies by tile. Component 3 is alpha
371  * (4:4:4:4): full-resolution, so it takes the luma QP.
372  */
373  for (int c = 0; c < APV_MAX_NUM_COMP; c++) {
374  int qp = (c == 0 || c == 3) ? ev->qp_y : ev->qp_c;
375  int level_scale = apv_level_scale[qp % 6];
376  int qp_shift = qp / 6;
377  pd->qf[c] =
378  (float)(fact / ((double)level_scale * (double)(1 << qp_shift)));
379  }
380 
381  /*
382  * The 8-bit quantisation matrix. The shader stages it to shared memory
383  * and quantises with 1024 / qmat[i], the reciprocal partner of the
384  * decoder's per-coefficient dequant -- the same matrix that gets
385  * signalled in the frame header.
386  */
387  for (int i = 0; i < 64; i++)
388  pd->qmat[i] = apv_qmatrix_value(ev->qmatrix, i);
389 }
390 
391 static int submit_frame(AVCodecContext *avctx, FFVkExecContext *exec,
392  AVFrame *frame)
393 {
394  int err = 0;
395  VulkanEncodeAPVContext *ev = avctx->priv_data;
396  FFVulkanFunctions *vk = &ev->s.vkfn;
397  VulkanEncodeAPVFrameData *fd = exec->opaque;
398  VkImageView views[AV_NUM_DATA_POINTERS];
399 
400  VkImageMemoryBarrier2 img_bar[AV_NUM_DATA_POINTERS];
401  int nb_img_bar = 0;
402  VkBufferMemoryBarrier2 buf_bar[4];
403  int nb_buf_bar = 0;
404 
405  FFVkBuffer *coeffs_buf;
406  FFVkBuffer *bytestream_buf;
407  FFVkBuffer *compacted_buf;
408  FFVkBuffer *sizes_buf;
409 
410  /* Allocate per-frame buffers */
412  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
413  NULL, ev->coeffs_size,
414  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT));
415  coeffs_buf = (FFVkBuffer *)fd->coeffs_ref->data;
416 
417  /* The entropy shader writes the bitstream here, sparsely -- one
418  * worst-case-sized slot per tile-component. Device-local, so those GPU
419  * writes stay in VRAM and never cross PCIe. */
421  &fd->bytestream_ref,
422  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
423  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
424  NULL, ev->bytestream_size,
425  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT));
426  bytestream_buf = (FFVkBuffer *)fd->bytestream_ref->data;
427 
428  /* The compaction shader gathers the sparse slots into here, contiguous.
429  * Host-visible + host-cached so the CPU readback is a fast cached copy,
430  * and the GPU writes it as one coalesced sequential stream. */
432  &fd->compacted_ref,
433  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
434  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
435  NULL, ev->bytestream_size,
436  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
437  VK_MEMORY_PROPERTY_HOST_CACHED_BIT));
438  compacted_buf = (FFVkBuffer *)fd->compacted_ref->data;
439 
441  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
442  NULL, ev->sizes_size,
443  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
444  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
445  VK_MEMORY_PROPERTY_HOST_COHERENT_BIT));
446  sizes_buf = (FFVkBuffer *)fd->sizes_ref->data;
447 
448  ff_vk_exec_start(&ev->s, exec);
449 
450  ff_vk_exec_add_dep_buf(&ev->s, exec, &fd->coeffs_ref, 1, 1);
451  ff_vk_exec_add_dep_buf(&ev->s, exec, &fd->bytestream_ref, 1, 1);
452  ff_vk_exec_add_dep_buf(&ev->s, exec, &fd->compacted_ref, 1, 1);
453  ff_vk_exec_add_dep_buf(&ev->s, exec, &fd->sizes_ref, 1, 1);
454 
455  RET(ff_vk_exec_add_dep_frame(&ev->s, exec, frame,
456  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
457  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
458 
459  RET(ff_vk_create_imageviews(&ev->s, exec, views, frame, FF_VK_REP_INT));
460 
461  ff_vk_frame_barrier(&ev->s, exec, frame,
462  img_bar, &nb_img_bar,
463  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
464  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
465  VK_ACCESS_SHADER_READ_BIT,
466  VK_IMAGE_LAYOUT_GENERAL,
467  VK_QUEUE_FAMILY_IGNORED);
468 
469  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
470  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
471  .pImageMemoryBarriers = img_bar,
472  .imageMemoryBarrierCount = nb_img_bar,
473  });
474  nb_img_bar = 0;
475 
476  /* DCT + Quantize pass */
477  {
478  ff_vk_shader_update_desc_buffer(&ev->s, exec, &ev->shd_dct,
479  0, 0, 0,
480  coeffs_buf, 0, coeffs_buf->size,
481  VK_FORMAT_UNDEFINED);
482  ff_vk_shader_update_img_array(&ev->s, exec, &ev->shd_dct,
483  frame, views,
484  0, 1,
485  VK_IMAGE_LAYOUT_GENERAL,
486  VK_NULL_HANDLE);
487 
488  ff_vk_exec_bind_shader(&ev->s, exec, &ev->shd_dct);
489  ff_vk_shader_update_push_const(&ev->s, exec, &ev->shd_dct,
490  VK_SHADER_STAGE_COMPUTE_BIT,
491  0, sizeof(ev->dct_push), &ev->dct_push);
492 
493  vk->CmdDispatch(exec->buf,
494  ev->frame_mb_x, ev->frame_mb_y, ev->num_comp);
495  }
496 
497  /* Barrier: wait for coeff writes before entropy */
498  ff_vk_buf_barrier(buf_bar[nb_buf_bar++], coeffs_buf,
499  COMPUTE_SHADER_BIT, SHADER_WRITE_BIT, NONE,
500  COMPUTE_SHADER_BIT, SHADER_READ_BIT, NONE,
501  0, coeffs_buf->size);
502 
503  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
504  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
505  .pBufferMemoryBarriers = buf_bar,
506  .bufferMemoryBarrierCount = nb_buf_bar,
507  });
508  nb_buf_bar = 0;
509 
510  /*
511  * Entropy encoding pass. Luma (component 0) and chroma (components
512  * 1..num_comp-1) run as two dispatches: under chroma sub-sampling their
513  * tile-components hold different block counts, hence different workgroup
514  * sizes -- one pipeline each. The two write disjoint memory and need no
515  * barrier between them, so the GPU is free to overlap them.
516  */
517  for (int p = 0; !ev->skip_entropy && p < 2; p++) {
518  FFVulkanShader *shd = &ev->shd_entropy[p];
519  uint32_t z_comps = (p == 0) ? 1 : ev->num_comp - 1;
520 
521  if (z_comps == 0)
522  continue; /* 4:0:0 (monochrome) has no chroma components */
523 
524  EntropyPushData pd = {
525  .bytestream = bytestream_buf->address,
526  .tile_count = { ev->tile_cols, ev->tile_rows },
527  .num_comp = ev->num_comp,
528  .slot_size = (uint32_t)ev->slot_size,
529  .comp_base = (uint32_t)p,
530  .blocks_per_tile = (uint32_t)ev->tile_mb_w * ev->tile_mb_h *
531  ev->blocks_per_mb,
532  .frame_mb = { ev->frame_mb_x, ev->frame_mb_y },
533  .tile_mb_dim = { ev->tile_mb_w, ev->tile_mb_h },
534  .blocks_per_mb = (uint32_t)(p == 0 ? ev->blocks_per_mb
535  : ev->chroma_blocks_per_mb),
536  };
537 
538  ff_vk_shader_update_desc_buffer(&ev->s, exec, shd, 0, 0, 0,
539  coeffs_buf, 0, coeffs_buf->size,
540  VK_FORMAT_UNDEFINED);
541  ff_vk_shader_update_desc_buffer(&ev->s, exec, shd, 0, 1, 0,
542  sizes_buf, 0, sizes_buf->size,
543  VK_FORMAT_UNDEFINED);
544 
545  ff_vk_exec_bind_shader(&ev->s, exec, shd);
546  ff_vk_shader_update_push_const(&ev->s, exec, shd,
547  VK_SHADER_STAGE_COMPUTE_BIT,
548  0, sizeof(pd), &pd);
549 
550  vk->CmdDispatch(exec->buf, ev->tile_cols, ev->tile_rows, z_comps);
551  }
552 
553  /* Compaction pass: gather the sparse per-tile-component slots into one
554  * contiguous, host-visible buffer. Reads VRAM, writes the host buffer as
555  * a coalesced stream -- the device->host transfer the CPU then reads. */
556  if (!ev->headers_only) {
557  ff_vk_buf_barrier(buf_bar[nb_buf_bar++], bytestream_buf,
558  COMPUTE_SHADER_BIT, SHADER_WRITE_BIT, NONE,
559  COMPUTE_SHADER_BIT, SHADER_READ_BIT, NONE,
560  0, bytestream_buf->size);
561  ff_vk_buf_barrier(buf_bar[nb_buf_bar++], sizes_buf,
562  COMPUTE_SHADER_BIT, SHADER_WRITE_BIT, NONE,
563  COMPUTE_SHADER_BIT, SHADER_READ_BIT, NONE,
564  0, sizes_buf->size);
565  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
566  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
567  .pBufferMemoryBarriers = buf_bar,
568  .bufferMemoryBarrierCount = nb_buf_bar,
569  });
570  nb_buf_bar = 0;
571 
572  CompactPushData pd = {
573  .sparse = bytestream_buf->address,
574  .compacted = compacted_buf->address,
575  .slot_size = (uint32_t)ev->slot_size,
576  };
577 
578  ff_vk_shader_update_desc_buffer(&ev->s, exec, &ev->shd_compact,
579  0, 0, 0,
580  sizes_buf, 0, sizes_buf->size,
581  VK_FORMAT_UNDEFINED);
582  ff_vk_exec_bind_shader(&ev->s, exec, &ev->shd_compact);
583  ff_vk_shader_update_push_const(&ev->s, exec, &ev->shd_compact,
584  VK_SHADER_STAGE_COMPUTE_BIT,
585  0, sizeof(pd), &pd);
586 
587  vk->CmdDispatch(exec->buf, ev->tile_count * ev->num_comp, 1, 1);
588  }
589 
590  err = ff_vk_exec_submit(&ev->s, exec);
591  if (err < 0)
592  return err;
593 
594  return 0;
595 
596 fail:
597  ff_vk_exec_discard_deps(&ev->s, exec);
598  return err;
599 }
600 
601 static int build_packet(AVCodecContext *avctx, FFVkExecContext *exec,
602  AVPacket *pkt)
603 {
604  int err = 0;
605  VulkanEncodeAPVContext *ev = avctx->priv_data;
606  FFVulkanFunctions *vk = &ev->s.vkfn;
607  VulkanEncodeAPVFrameData *fd = exec->opaque;
608  FFVkBuffer *compacted_buf = (FFVkBuffer *)fd->compacted_ref->data;
609  FFVkBuffer *sizes_buf = (FFVkBuffer *)fd->sizes_ref->data;
610  APVRawFrame *raw_frame = NULL;
611 
612  /* Wait for the GPU encode to finish */
613  ff_vk_exec_wait(&ev->s, exec);
614 
615  const uint32_t *sizes = NULL;
616  static uint8_t headers_only_tile; /* 1-byte token tile data */
617 
618  /* Headers-only benchmark mode never touches the GPU output. */
619  if (!ev->headers_only) {
620  /* Invalidate mapped memory if needed */
621  if (!(compacted_buf->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
622  VkMappedMemoryRange r = {
623  .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
624  .memory = compacted_buf->mem,
625  .offset = 0,
626  .size = VK_WHOLE_SIZE,
627  };
628  vk->InvalidateMappedMemoryRanges(ev->s.hwctx->act_dev, 1, &r);
629  }
630  if (!(sizes_buf->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
631  VkMappedMemoryRange r = {
632  .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
633  .memory = sizes_buf->mem,
634  .offset = 0,
635  .size = VK_WHOLE_SIZE,
636  };
637  vk->InvalidateMappedMemoryRanges(ev->s.hwctx->act_dev, 1, &r);
638  }
639  sizes = (const uint32_t *)sizes_buf->mapped_mem;
640  }
641 
642  /* Allocate the cbs frame structure */
643  raw_frame = av_mallocz(sizeof(*raw_frame));
644  if (!raw_frame)
645  return AVERROR(ENOMEM);
646 
648  raw_frame->pbu_header.group_id = 1;
649 
650  APVRawFrameHeader *fh = &raw_frame->frame_header;
652  fh->frame_info.level_idc = ev->level_idc;
653  fh->frame_info.band_idc = ev->band_idc;
654  fh->frame_info.frame_width = avctx->width;
655  fh->frame_info.frame_height = avctx->height;
657  fh->frame_info.bit_depth_minus8 = ev->bit_depth - 8;
659 
661  /* Inferred values when the flag is 0, per the spec. */
662  fh->color_primaries = 2;
663  fh->transfer_characteristics = 2;
664  fh->matrix_coefficients = 2;
665  fh->full_range_flag = 0;
666 
667  /* compute_pf_table() builds the encoder's pf scale from the same matrix;
668  * the two must stay in sync. use_q_matrix is only signalled when the
669  * matrix is non-uniform (a flat 16 matrix is the inferred default). */
671  for (int c = 0; c < ev->num_comp; c++)
672  for (int y = 0; y < 8; y++)
673  for (int x = 0; x < 8; x++)
674  fh->quantization_matrix.q_matrix[c][y][x] =
675  apv_qmatrix_value(ev->qmatrix, y * 8 + x);
676 
680 
681  /* Populate each tile. The compacted buffer holds each tile-component's
682  * data back to back, in (tile, component) order -- the same layout the
683  * gather shader produced. */
684  uint32_t comp_off = 0;
685  for (int t = 0; t < ev->tile_count; t++) {
686  APVRawTile *tile = &raw_frame->tile[t];
687  uint32_t total_tile_data = 0;
688 
689  tile->tile_header.tile_header_size =
690  4 + ev->num_comp * (4 + 1) + 1;
691  tile->tile_header.tile_index = t;
692 
693  for (int c = 0; c < ev->num_comp; c++) {
694  uint32_t sz;
695  if (ev->headers_only) {
696  /* No readback: one token byte (CBS requires size >= 1). */
697  sz = 1;
698  tile->tile_data[c] = &headers_only_tile;
699  } else {
700  sz = sizes[t * ev->num_comp + c];
701  tile->tile_data[c] = compacted_buf->mapped_mem + comp_off;
702  comp_off += sz;
703  }
704  tile->tile_header.tile_data_size[c] = sz;
705  tile->tile_header.tile_qp[c] =
706  (c == 0 || c == 3) ? ev->qp_y : ev->qp_c;
707  total_tile_data += sz;
708  }
709  tile->tile_header.reserved_zero_8bits = 0;
710  tile->tile_dummy_byte_size = 0;
711  tile->tile_dummy_byte = NULL;
712 
713  raw_frame->tile_size[t] =
714  tile->tile_header.tile_header_size + total_tile_data;
715  }
716 
717  /* Assemble fragment using cbs_apv */
718  ff_cbs_fragment_reset(&ev->au);
719 
720  err = ff_cbs_insert_unit_content(&ev->au, -1, APV_PBU_PRIMARY_FRAME,
721  raw_frame, NULL);
722  if (err < 0) {
723  av_freep(&raw_frame);
724  return err;
725  }
726  /* raw_frame is now owned by the fragment unit */
727  raw_frame = NULL;
728 
729  /* Assemble straight into the packet: ff_cbs_write_packet() hands pkt a
730  * reference to CBS's own assembled buffer -- no copy. */
731  err = ff_cbs_write_packet(ev->cbc, pkt, &ev->au);
732  if (err < 0)
733  return err;
734 
735  pkt->pts = fd->pts;
736  pkt->dts = fd->pts;
737  pkt->duration = fd->duration;
738  pkt->flags |= AV_PKT_FLAG_KEY; /* APV is all intra */
739 
740  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
741  pkt->opaque = fd->frame_opaque;
743  fd->frame_opaque_ref = NULL;
744  }
745 
746  av_log(avctx, AV_LOG_VERBOSE, "Encoded APV frame: %i bytes (%.2f MiB)\n",
747  pkt->size, pkt->size / (1024.0 * 1024.0));
748 
753 
754  return 0;
755 }
756 
758  AVPacket *pkt)
759 {
760  int err;
761  VulkanEncodeAPVContext *ev = avctx->priv_data;
763  FFVkExecContext *exec;
764  AVFrame *frame;
765 
766  while (1) {
767  exec = ff_vk_exec_get(&ev->s, &ev->exec_pool);
768 
769  if (exec->had_submission) {
770  exec->had_submission = 0;
771  ev->in_flight--;
772  return build_packet(avctx, exec, pkt);
773  }
774 
775  frame = ev->frame;
776  err = ff_encode_get_frame(avctx, frame);
777  if (err < 0 && err != AVERROR_EOF)
778  return err;
779  else if (err == AVERROR_EOF) {
780  if (!ev->in_flight)
781  return err;
782  continue;
783  }
784 
785  fd = exec->opaque;
786  fd->pts = frame->pts;
787  fd->duration = frame->duration;
788  fd->flags = frame->flags;
789  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
790  fd->frame_opaque = frame->opaque;
791  fd->frame_opaque_ref = frame->opaque_ref;
792  frame->opaque_ref = NULL;
793  }
794 
795  err = submit_frame(avctx, exec, frame);
797  if (err < 0)
798  return err;
799 
800  ev->in_flight++;
801  if (ev->in_flight < ev->async_depth)
802  return AVERROR(EAGAIN);
803  }
804  return 0;
805 }
806 
808 {
809  VulkanEncodeAPVContext *ev = avctx->priv_data;
810 
811  ff_vk_exec_pool_free(&ev->s, &ev->exec_pool);
812 
813  ff_vk_shader_free(&ev->s, &ev->shd_dct);
814  ff_vk_shader_free(&ev->s, &ev->shd_entropy[0]);
815  ff_vk_shader_free(&ev->s, &ev->shd_entropy[1]);
816  ff_vk_shader_free(&ev->s, &ev->shd_compact);
817 
818  if (ev->exec_ctx_info) {
819  for (int i = 0; i < ev->async_depth; i++) {
826  }
827  av_freep(&ev->exec_ctx_info);
828  }
829 
834 
835  ff_cbs_fragment_free(&ev->au);
836  ff_cbs_close(&ev->cbc);
837 
838  av_frame_free(&ev->frame);
839  ff_vk_uninit(&ev->s);
840 
841  return 0;
842 }
843 
845 {
846  int err;
847  VulkanEncodeAPVContext *ev = avctx->priv_data;
848  AVHWFramesContext *hwfc;
849 
850  if (!avctx->hw_frames_ctx) {
851  av_log(avctx, AV_LOG_ERROR, "An AVHWFramesContext is required.\n");
852  return AVERROR(EINVAL);
853  }
854  hwfc = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
855  ev->sw_format = hwfc->sw_format;
856 
859  if (ev->profile_idc < 0 || ev->chroma_format_idc < 0) {
860  av_log(avctx, AV_LOG_ERROR, "Unsupported sw_format %s for APV.\n",
862  return AVERROR(EINVAL);
863  }
864 
865  /* All four APV chroma formats are supported -- 4:0:0, 4:2:2, 4:4:4 and
866  * 4:4:4:4. The profile_idc / chroma_format_idc checks above already
867  * reject any pixel format that is not one of them. */
869  ev->bit_depth = desc->comp[0].depth;
870  ev->num_comp = desc->nb_components;
871  ev->blocks_per_mb = 4; /* luma: 16x16 MB -> 4 8x8 blocks */
872  ev->chroma_blocks_per_mb = 4 >> (desc->log2_chroma_w + desc->log2_chroma_h);
873  ev->level_idc = 33; /* placeholder, real value depends on resolution and bitrate */
874  ev->band_idc = 0;
875 
876  /* Frame dimensions in macroblocks */
877  ev->frame_mb_x = (avctx->width + APV_MB_WIDTH - 1) / APV_MB_WIDTH;
878  ev->frame_mb_y = (avctx->height + APV_MB_HEIGHT - 1) / APV_MB_HEIGHT;
879 
880  /* The 20x20 tile grid cap is structural (fixed-size arrays everywhere);
881  * the spec additionally demands tiles of at least 16x8 MBs. Each
882  * tile-component maps to one entropy workgroup, one invocation per
883  * transform block. */
884  int grid_tw = (ev->frame_mb_x + APV_MAX_TILE_COLS - 1) / APV_MAX_TILE_COLS;
885  int grid_th = (ev->frame_mb_y + APV_MAX_TILE_ROWS - 1) / APV_MAX_TILE_ROWS;
886  int min_tw = FFMAX(APV_MIN_TILE_WIDTH_IN_MBS, grid_tw);
887  int min_th = FFMAX(APV_MIN_TILE_HEIGHT_IN_MBS, grid_th);
888 
889  /* tile_w/tile_h pick the tile size in MBs; 0 selects the spec minimum.
890  * An explicit request below the spec minimum is honoured down to the
891  * grid cap -- non-conformant, but more tiles mean shorter (serial)
892  * entropy streams, which is the decode speed lever. */
893  ev->tile_mb_w = ev->tile_w_mbs_opt > 0 ? ev->tile_w_mbs_opt : min_tw;
894  ev->tile_mb_h = ev->tile_h_mbs_opt > 0 ? ev->tile_h_mbs_opt : min_th;
895  ev->tile_mb_w = FFMIN(FFMAX(ev->tile_mb_w, grid_tw), ev->frame_mb_x);
896  ev->tile_mb_h = FFMIN(FFMAX(ev->tile_mb_h, grid_th), ev->frame_mb_y);
899  av_log(avctx, AV_LOG_WARNING,
900  "Tile size %dx%d MBs is below the spec minimum of %dx%d: "
901  "NON-CONFORMANT bitstream, most decoders will reject it.\n",
902  ev->tile_mb_w, ev->tile_mb_h,
904 
905  /* Left to default, grow the tile toward 1024 transform blocks (the
906  * entropy workgroup ceiling) while it still divides the frame. Bigger
907  * tiles mean fewer tile-components, which the compaction pass strongly
908  * prefers -- it is the dominant win for throughput. */
909  if (!ev->tile_w_mbs_opt && !ev->tile_h_mbs_opt) {
910  while (ev->tile_mb_w * 2 <= ev->frame_mb_x &&
911  ev->frame_mb_x % (ev->tile_mb_w * 2) == 0 &&
912  (ev->tile_mb_w * 2) * ev->tile_mb_h * ev->blocks_per_mb <= 1024)
913  ev->tile_mb_w *= 2;
914  while (ev->tile_mb_h * 2 <= ev->frame_mb_y &&
915  ev->frame_mb_y % (ev->tile_mb_h * 2) == 0 &&
916  ev->tile_mb_w * (ev->tile_mb_h * 2) * ev->blocks_per_mb <= 1024)
917  ev->tile_mb_h *= 2;
918  }
919 
920  /* Ceil division: the rightmost column / bottom row of tiles take the
921  * remainder MBs (spec-legal; the tile grid is closed at the frame edge,
922  * so those tiles may be smaller than the signalled tile size). */
923  ev->tile_cols = (ev->frame_mb_x + ev->tile_mb_w - 1) / ev->tile_mb_w;
924  ev->tile_rows = (ev->frame_mb_y + ev->tile_mb_h - 1) / ev->tile_mb_h;
925  ev->tile_count = ev->tile_cols * ev->tile_rows;
926 
927  if (ev->tile_count > APV_MAX_TILE_COUNT) {
928  av_log(avctx, AV_LOG_ERROR, "Too many tiles (%d).\n", ev->tile_count);
929  return AVERROR(EINVAL);
930  }
931 
932  /* The entropy shader runs one invocation per block in a tile-component
933  * and its shared buffers are sized for 1024. */
934  if (ev->tile_mb_w * ev->tile_mb_h * ev->blocks_per_mb > 1024) {
935  av_log(avctx, AV_LOG_ERROR,
936  "Tile-component has too many transform blocks (%d > 1024).\n",
937  ev->tile_mb_w * ev->tile_mb_h * ev->blocks_per_mb);
938  return AVERROR_PATCHWELCOME;
939  }
940 
941  /* qp_chroma left at 0 means "use the luma QP". */
942  if (ev->qp_c == 0)
943  ev->qp_c = ev->qp_y;
944 
945  /* Validate QP range */
946  int max_qp = 3 + ev->bit_depth * 6;
947  if (ev->qp_y < 0 || ev->qp_y > max_qp || ev->qp_c < 0 || ev->qp_c > max_qp) {
948  av_log(avctx, AV_LOG_ERROR,
949  "QP out of range [0, %d]: qp_y=%d, qp_c=%d.\n",
950  max_qp, ev->qp_y, ev->qp_c);
951  return AVERROR(EINVAL);
952  }
953 
954  /* Buffer sizing */
955  size_t blocks_per_tile = (size_t)ev->tile_mb_w * ev->tile_mb_h * ev->blocks_per_mb;
956  ev->coeffs_size = (size_t)ev->tile_count * ev->num_comp *
957  blocks_per_tile * APV_BLK_COEFFS * sizeof(int16_t);
958 
959  /* Worst-case per-tile-component bytestream: each coefficient at most ~32 bits.
960  * Round up generously. */
961  ev->slot_size = blocks_per_tile * APV_BLK_COEFFS * 8;
962  ev->slot_size = FFALIGN(ev->slot_size, 64);
963  ev->bytestream_size = (size_t)ev->tile_count * ev->num_comp * ev->slot_size;
964  ev->sizes_size = (size_t)ev->tile_count * ev->num_comp * sizeof(uint32_t);
965 
966  av_log(avctx, AV_LOG_VERBOSE,
967  "APV Vulkan encoder: %dx%d, %d tiles (%dx%d MBs each), "
968  "qp_y=%d qp_c=%d, coeffs=%zu KiB, bytestream=%zu KiB\n",
969  avctx->width, avctx->height, ev->tile_count,
970  ev->tile_mb_w, ev->tile_mb_h, ev->qp_y, ev->qp_c,
971  ev->coeffs_size / 1024, ev->bytestream_size / 1024);
972 
973  ev->headers_only = !!getenv("APV_VULKAN_HEADERS_ONLY");
974  ev->skip_entropy = !!getenv("APV_VULKAN_SKIP_ENTROPY");
975  if (ev->skip_entropy)
976  ev->headers_only = 1; /* the bitstream is never produced */
977  if (ev->headers_only)
978  av_log(avctx, AV_LOG_WARNING,
979  "APV_VULKAN_HEADERS_ONLY set: tiles will not be downloaded "
980  "or assembled; output packets contain headers only.\n");
981  if (ev->skip_entropy)
982  av_log(avctx, AV_LOG_WARNING,
983  "APV_VULKAN_SKIP_ENTROPY set: entropy dispatch skipped "
984  "(DCT-only benchmark mode).\n");
985 
986  /* Init Vulkan */
987  err = ff_vk_init(&ev->s, avctx, NULL, avctx->hw_frames_ctx);
988  if (err < 0)
989  return err;
990 
991  ev->qf = ff_vk_qf_find(&ev->s, VK_QUEUE_COMPUTE_BIT, 0);
992  if (!ev->qf) {
993  av_log(avctx, AV_LOG_ERROR, "Device has no compute queues!\n");
994  return AVERROR(ENOTSUP);
995  }
996 
997  err = ff_vk_exec_pool_init(&ev->s, ev->qf, &ev->exec_pool,
998  ev->async_depth, 0, 0, 0, NULL);
999  if (err < 0)
1000  return err;
1001 
1002  /* Init CBS for assembling output */
1003  err = ff_cbs_init(&ev->cbc, AV_CODEC_ID_APV, avctx);
1004  if (err < 0)
1005  return err;
1006 
1007  /* Shaders */
1008  err = init_dct_shader(avctx);
1009  if (err < 0)
1010  return err;
1011  err = init_entropy_shader(avctx, ev->blocks_per_mb, &ev->shd_entropy[0]);
1012  if (err < 0)
1013  return err;
1014  err = init_entropy_shader(avctx, ev->chroma_blocks_per_mb,
1015  &ev->shd_entropy[1]);
1016  if (err < 0)
1017  return err;
1018  err = init_compact_shader(avctx);
1019  if (err < 0)
1020  return err;
1021 
1022  /* The DCT/quantize shader's push constants never change frame to frame;
1023  * build them once. */
1024  build_dct_push_const(avctx);
1025 
1026  ev->frame = av_frame_alloc();
1027  if (!ev->frame)
1028  return AVERROR(ENOMEM);
1029 
1030  /* Async data pool */
1031  ev->async_depth = ev->exec_pool.pool_size;
1032  ev->exec_ctx_info = av_calloc(ev->async_depth, sizeof(*ev->exec_ctx_info));
1033  if (!ev->exec_ctx_info)
1034  return AVERROR(ENOMEM);
1035  for (int i = 0; i < ev->async_depth; i++)
1036  ev->exec_pool.contexts[i].opaque = &ev->exec_ctx_info[i];
1037 
1038  return 0;
1039 }
1040 
1041 #define OFFSET(x) offsetof(VulkanEncodeAPVContext, x)
1042 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1044  { "qp", "Quantization parameter (luma)", OFFSET(qp_y),
1045  AV_OPT_TYPE_INT, { .i64 = 22 }, 0, 255, VE },
1046  { "qp_chroma", "Chroma quantization parameter (0 = same as luma qp)", OFFSET(qp_c),
1047  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 255, VE },
1048  { "qmatrix", "Quantization matrix", OFFSET(qmatrix),
1049  AV_OPT_TYPE_INT, { .i64 = APV_QMATRIX_HEVC }, 0, 1, VE, "qmatrix" },
1050  { "flat", "Uniform matrix, all 16 (APV spec default)", 0,
1051  AV_OPT_TYPE_CONST, { .i64 = APV_QMATRIX_FLAT }, 0, 0, VE, "qmatrix" },
1052  { "hevc", "HEVC default intra scaling list (mild perceptual shaping)", 0,
1053  AV_OPT_TYPE_CONST, { .i64 = APV_QMATRIX_HEVC }, 0, 0, VE, "qmatrix" },
1054  /* The minimum legal tile is 16x8 MBs; the maxima are this encoder's
1055  * ceiling of 1024 transform blocks per tile-component (256 MBs): with
1056  * the other dimension at its minimum, width <= 32 and height <= 16. A
1057  * value of 0 is the sentinel for the adaptive per-frame default. */
1058  { "tile_width", "Tile width in macroblocks (0 = adaptive, auto-sized per frame)", OFFSET(tile_w_mbs_opt),
1059  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 32, VE },
1060  { "tile_height", "Tile height in macroblocks (0 = adaptive, auto-sized per frame)", OFFSET(tile_h_mbs_opt),
1061  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 16, VE },
1062  { "async_depth", "Internal parallelization depth", OFFSET(async_depth),
1063  AV_OPT_TYPE_INT, { .i64 = 1 }, 1, INT_MAX, VE },
1064  { NULL }
1065 };
1066 
1068  { "g", "1" },
1069  { NULL },
1070 };
1071 
1073  .class_name = "apv_vulkan",
1074  .item_name = av_default_item_name,
1075  .option = vulkan_encode_apv_options,
1076  .version = LIBAVUTIL_VERSION_INT,
1077 };
1078 
1080  HW_CONFIG_ENCODER_FRAMES(VULKAN, VULKAN),
1081  NULL,
1082 };
1083 
1085  .p.name = "apv_vulkan",
1086  CODEC_LONG_NAME("Advanced Professional Video (Vulkan)"),
1087  .p.type = AVMEDIA_TYPE_VIDEO,
1088  .p.id = AV_CODEC_ID_APV,
1089  .priv_data_size = sizeof(VulkanEncodeAPVContext),
1092  .close = &vulkan_encode_apv_close,
1093  .p.priv_class = &vulkan_encode_apv_class,
1094  .p.capabilities = AV_CODEC_CAP_DELAY |
1100  .defaults = vulkan_encode_apv_defaults,
1102  .hw_configs = vulkan_encode_apv_hw_configs,
1103  .p.wrapper_name = "vulkan",
1104 };
VulkanEncodeAPVContext::frame_mb_y
int frame_mb_y
Definition: apv_encode_vulkan.c:126
APVRawFrameInfo::capture_time_distance
uint8_t capture_time_distance
Definition: cbs_apv.h:52
EntropyPushData::num_comp
int num_comp
Definition: apv_encode_vulkan.c:66
hwconfig.h
cbs.h
CODEC_PIXFMTS
#define CODEC_PIXFMTS(...)
Definition: codec_internal.h:401
ff_seg_gather_comp_spv_data
const unsigned char ff_seg_gather_comp_spv_data[]
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
ff_apv_vulkan_encoder
const FFCodec ff_apv_vulkan_encoder
Definition: apv_encode_vulkan.c:1084
VulkanEncodeAPVContext::headers_only
int headers_only
Definition: apv_encode_vulkan.c:155
VulkanEncodeAPVFrameData::compacted_ref
AVBufferRef * compacted_ref
Definition: apv_encode_vulkan.c:84
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
VulkanEncodeAPVContext::shd_dct
FFVulkanShader shd_dct
Definition: apv_encode_vulkan.c:101
r
const char * r
Definition: vf_curves.c:127
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
init_compact_shader
static int init_compact_shader(AVCodecContext *avctx)
Definition: apv_encode_vulkan.c:314
VulkanEncodeAPVFrameData::flags
int flags
Definition: apv_encode_vulkan.c:91
VulkanEncodeAPVContext::sw_format
enum AVPixelFormat sw_format
Definition: apv_encode_vulkan.c:134
vulkan_encode_apv_options
static const AVOption vulkan_encode_apv_options[]
Definition: apv_encode_vulkan.c:1043
ff_vk_shader_free
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition: vulkan.c:2853
ff_apv_encode_dct_comp_spv_data
const unsigned char ff_apv_encode_dct_comp_spv_data[]
VulkanEncodeAPVContext::level_idc
int level_idc
Definition: apv_encode_vulkan.c:137
AVBufferPool
The buffer pool.
Definition: buffer_internal.h:88
FFVkExecPool::contexts
FFVkExecContext * contexts
Definition: vulkan.h:291
vulkan_encode_apv_hw_configs
static const AVCodecHWConfigInternal *const vulkan_encode_apv_hw_configs[]
Definition: apv_encode_vulkan.c:1079
VulkanEncodeAPVFrameData::frame_opaque
void * frame_opaque
Definition: apv_encode_vulkan.c:89
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AV_CODEC_CAP_HARDWARE
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition: codec.h:127
RET
#define RET(x)
Definition: vulkan.h:68
ff_vk_exec_pool_init
int ff_vk_exec_pool_init(FFVulkanContext *s, AVVulkanDeviceQueueFamily *qf, FFVkExecPool *pool, int nb_contexts, int nb_queries, VkQueryType query_type, int query_64bit, const void *query_create_pnext)
Allocates/frees an execution pool.
Definition: vulkan.c:357
VulkanEncodeAPVContext::skip_entropy
int skip_entropy
Definition: apv_encode_vulkan.c:159
APV_MAX_NUM_COMP
#define APV_MAX_NUM_COMP
Definition: apv_encode_vulkan.c:50
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
VulkanEncodeAPVContext::blocks_per_mb
int blocks_per_mb
Definition: apv_encode_vulkan.c:130
APVRawFrameInfo::level_idc
uint8_t level_idc
Definition: cbs_apv.h:45
av_cold
#define av_cold
Definition: attributes.h:119
int64_t
long long int64_t
Definition: coverity.c:34
VulkanEncodeAPVContext::cbc
CodedBitstreamContext * cbc
Definition: apv_encode_vulkan.c:115
DCTPushData::qmat
uint8_t qmat[64]
Definition: apv_encode_vulkan.c:60
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
VulkanEncodeAPVFrameData::coeffs_ref
AVBufferRef * coeffs_ref
Definition: apv_encode_vulkan.c:82
vulkan_encode_apv_receive_packet
static int vulkan_encode_apv_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: apv_encode_vulkan.c:757
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:466
VulkanEncodeAPVContext::num_comp
int num_comp
Definition: apv_encode_vulkan.c:132
pixdesc.h
VulkanEncodeAPVContext::qf
AVVulkanDeviceQueueFamily * qf
Definition: apv_encode_vulkan.c:98
APV_MIN_TILE_HEIGHT_IN_MBS
@ APV_MIN_TILE_HEIGHT_IN_MBS
Definition: apv.h:74
level_scale
const static int level_scale[2][6]
Definition: intra.c:336
APVRawFrameHeader::color_primaries
uint8_t color_primaries
Definition: cbs_apv.h:72
internal.h
APVRawFrameInfo::profile_idc
uint8_t profile_idc
Definition: cbs_apv.h:44
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:226
APVRawFrame::tile
APVRawTile tile[APV_MAX_TILE_COUNT]
Definition: cbs_apv.h:105
APVRawFrameInfo::frame_width
uint32_t frame_width
Definition: cbs_apv.h:48
AVOption
AVOption.
Definition: opt.h:428
encode.h
VulkanEncodeAPVContext::tile_cols
int tile_cols
Definition: apv_encode_vulkan.c:127
VulkanEncodeAPVContext::compacted_pool
AVBufferPool * compacted_pool
Definition: apv_encode_vulkan.c:108
profile_idc_from_pix_fmt
static int profile_idc_from_pix_fmt(enum AVPixelFormat sw_fmt)
Definition: apv_encode_vulkan.c:219
FFCodec
Definition: codec_internal.h:127
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
APV_MB_WIDTH
@ APV_MB_WIDTH
Definition: apv.h:40
APV_QMATRIX_HEVC
@ APV_QMATRIX_HEVC
Definition: apv_encode_vulkan.c:182
FFVkBuffer::address
VkDeviceAddress address
Definition: vulkan.h:130
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:621
ff_vk_init
int ff_vk_init(FFVulkanContext *s, void *log_parent, AVBufferRef *device_ref, AVBufferRef *frames_ref)
Initializes the AVClass, in case this context is not used as the main user's context.
Definition: vulkan.c:2891
ff_vk_exec_get
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition: vulkan.c:568
VulkanEncodeAPVContext::frame_mb_x
int frame_mb_x
Definition: apv_encode_vulkan.c:126
ff_vk_uninit
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition: vulkan.c:2879
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
APVRawTileInfo::tile_width_in_mbs
uint32_t tile_width_in_mbs
Definition: cbs_apv.h:61
SPEC_LIST_ADD
#define SPEC_LIST_ADD(name, idx, val_bits, val)
Definition: vulkan.h:86
apv_level_scale
static const uint8_t apv_level_scale[6]
Definition: apv_encode_vulkan.c:197
APVRawTileInfo::tile_size_present_in_fh_flag
uint8_t tile_size_present_in_fh_flag
Definition: cbs_apv.h:63
FF_VK_REP_INT
@ FF_VK_REP_INT
Definition: vulkan.h:453
EntropyPushData::tile_count
int tile_count[2]
Definition: apv_encode_vulkan.c:65
NONE
#define NONE
Definition: vf_drawvg.c:262
init_entropy_shader
static int init_entropy_shader(AVCodecContext *avctx, int blocks_per_mb, FFVulkanShader *shd)
Definition: apv_encode_vulkan.c:273
ff_vk_exec_bind_shader
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition: vulkan.c:2830
VulkanEncodeAPVFrameData
Definition: apv_encode_vulkan.c:81
APV_QMATRIX_FLAT
@ APV_QMATRIX_FLAT
Definition: apv_encode_vulkan.c:181
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:650
VulkanEncodeAPVContext::chroma_format_idc
int chroma_format_idc
Definition: apv_encode_vulkan.c:139
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
VulkanEncodeAPVContext::bytestream_size
size_t bytestream_size
Definition: apv_encode_vulkan.c:142
ff_vk_exec_add_dep_frame
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
Definition: vulkan.c:800
APV_PROFILE_4444_12
@ APV_PROFILE_4444_12
Definition: apv.h:67
build_packet
static int build_packet(AVCodecContext *avctx, FFVkExecContext *exec, AVPacket *pkt)
Definition: apv_encode_vulkan.c:601
DCTPushData::bit_depth
int bit_depth
Definition: apv_encode_vulkan.c:58
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3496
AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition: avcodec.h:279
FFCodecDefault
Definition: codec_internal.h:97
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
ff_apv_encode_tiles_comp_spv_data
const unsigned char ff_apv_encode_tiles_comp_spv_data[]
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:639
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:2781
APVRawFrame::pbu_header
APVRawPBUHeader pbu_header
Definition: cbs_apv.h:102
ff_vk_frame_barrier
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e, AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar, VkPipelineStageFlags2 src_stage, VkPipelineStageFlags2 dst_stage, VkAccessFlagBits2 new_access, VkImageLayout new_layout, uint32_t new_qf)
Definition: vulkan.c:2093
VulkanEncodeAPVFrameData::pts
int64_t pts
Definition: apv_encode_vulkan.c:87
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:2646
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:500
APVRawFrameHeader::frame_info
APVRawFrameInfo frame_info
Definition: cbs_apv.h:68
AV_CODEC_CAP_ENCODER_FLUSH
#define AV_CODEC_CAP_ENCODER_FLUSH
This encoder can be flushed using avcodec_flush_buffers().
Definition: codec.h:148
VulkanEncodeAPVContext
Definition: apv_encode_vulkan.c:94
EntropyPushData::blocks_per_mb
uint32_t blocks_per_mb
Definition: apv_encode_vulkan.c:72
APVRawFrameHeader::transfer_characteristics
uint8_t transfer_characteristics
Definition: cbs_apv.h:73
APVRawFrameInfo::band_idc
uint8_t band_idc
Definition: cbs_apv.h:46
ff_apv_encode_tiles_comp_spv_len
const unsigned int ff_apv_encode_tiles_comp_spv_len
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:52
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:542
APVRawPBUHeader::group_id
uint16_t group_id
Definition: cbs_apv.h:35
VulkanEncodeAPVContext::in_flight
int in_flight
Definition: apv_encode_vulkan.c:122
VulkanEncodeAPVFrameData::sizes_ref
AVBufferRef * sizes_ref
Definition: apv_encode_vulkan.c:85
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
EntropyPushData::slot_size
uint32_t slot_size
Definition: apv_encode_vulkan.c:67
VulkanEncodeAPVContext::bit_depth
int bit_depth
Definition: apv_encode_vulkan.c:133
VulkanEncodeAPVContext::slot_size
size_t slot_size
Definition: apv_encode_vulkan.c:143
APVRawFrame::frame_header
APVRawFrameHeader frame_header
Definition: cbs_apv.h:103
VulkanEncodeAPVContext::sizes_size
size_t sizes_size
Definition: apv_encode_vulkan.c:144
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:129
submit_frame
static int submit_frame(AVCodecContext *avctx, FFVkExecContext *exec, AVFrame *frame)
Definition: apv_encode_vulkan.c:391
APVRawFrameHeader::full_range_flag
uint8_t full_range_flag
Definition: cbs_apv.h:75
ff_vk_exec_wait
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:573
VulkanEncodeAPVContext::tile_mb_h
int tile_mb_h
Definition: apv_encode_vulkan.c:128
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:141
VulkanEncodeAPVContext::chroma_blocks_per_mb
int chroma_blocks_per_mb
Definition: apv_encode_vulkan.c:131
APVRawFrameHeader::use_q_matrix
uint8_t use_q_matrix
Definition: cbs_apv.h:77
APVRawTileInfo::tile_height_in_mbs
uint32_t tile_height_in_mbs
Definition: cbs_apv.h:62
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:594
VulkanEncodeAPVContext::frame
AVFrame * frame
Definition: apv_encode_vulkan.c:118
CompactPushData::compacted
VkDeviceAddress compacted
Definition: apv_encode_vulkan.c:77
ff_vk_exec_add_dep_buf
int ff_vk_exec_add_dep_buf(FFVulkanContext *s, FFVkExecContext *e, AVBufferRef **deps, int nb_deps, int ref)
Execution dependency management.
Definition: vulkan.c:640
VulkanEncodeAPVContext::dct_push
DCTPushData dct_push
Definition: apv_encode_vulkan.c:112
APVRawFrameHeader::matrix_coefficients
uint8_t matrix_coefficients
Definition: cbs_apv.h:74
ff_vk_exec_pool_free
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
Definition: vulkan.c:299
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:628
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:349
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:519
if
if(ret)
Definition: filter_design.txt:179
VulkanEncodeAPVContext::qp_y
int qp_y
Definition: apv_encode_vulkan.c:149
fail
#define fail
Definition: test.h:478
DCTPushData::qf
float qf[APV_MAX_NUM_COMP]
Definition: apv_encode_vulkan.c:59
DCTPushData::frame_dim
int frame_dim[2]
Definition: apv_encode_vulkan.c:53
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
sizes
static const int sizes[][2]
Definition: img2dec.c:62
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:213
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
APV_CHROMA_FORMAT_4444
@ APV_CHROMA_FORMAT_4444
Definition: apv.h:50
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:384
ff_seg_gather_comp_spv_len
const unsigned int ff_seg_gather_comp_spv_len
apv.h
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
APV_BLK_COEFFS
@ APV_BLK_COEFFS
Definition: apv.h:55
vulkan_encode_apv_close
static av_cold int vulkan_encode_apv_close(AVCodecContext *avctx)
Definition: apv_encode_vulkan.c:807
av_buffer_pool_uninit
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:328
APVRawQuantizationMatrix::q_matrix
uint8_t q_matrix[APV_MAX_NUM_COMP][APV_TR_SIZE][APV_TR_SIZE]
Definition: cbs_apv.h:57
APV_PROFILE_444_12
@ APV_PROFILE_444_12
Definition: apv.h:65
CompactPushData
Definition: apv_encode_vulkan.c:75
APV_PROFILE_422_12
@ APV_PROFILE_422_12
Definition: apv.h:63
ff_vk_shader_link
int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, const char *spirv, size_t spirv_len, const char *entrypoint)
Link a shader into an executable.
Definition: vulkan.c:2419
FFVkExecContext::had_submission
int had_submission
Definition: vulkan.h:148
FFVkBuffer::size
size_t size
Definition: vulkan.h:129
SPEC_LIST_CREATE
#define SPEC_LIST_CREATE(name, max_length, max_size)
Definition: vulkan.h:76
double
double
Definition: af_crystalizer.c:132
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:540
DCTPushData::log2_chroma_sub
int log2_chroma_sub[2]
Definition: apv_encode_vulkan.c:56
FFVkBuffer::mapped_mem
uint8_t * mapped_mem
Definition: vulkan.h:134
FFVulkanContext
Definition: vulkan.h:312
APVRawFrame
Definition: cbs_apv.h:101
apv_qmat_hevc_intra
static const uint8_t apv_qmat_hevc_intra[64]
Definition: apv_encode_vulkan.c:169
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
VulkanEncodeAPVContext::qp_c
int qp_c
Definition: apv_encode_vulkan.c:150
APV_PROFILE_444_10
@ APV_PROFILE_444_10
Definition: apv.h:64
VulkanEncodeAPVContext::shd_entropy
FFVulkanShader shd_entropy[2]
Definition: apv_encode_vulkan.c:102
APV_MB_HEIGHT
@ APV_MB_HEIGHT
Definition: apv.h:41
APVRawFrameInfo::frame_height
uint32_t frame_height
Definition: cbs_apv.h:49
ff_vk_buf_barrier
#define ff_vk_buf_barrier(dst, vkb, s_stage, s_access, s_access2, d_stage, d_access, d_access2, offs, bsz)
Definition: vulkan.h:551
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:579
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:49
EntropyPushData::frame_mb
int frame_mb[2]
Definition: apv_encode_vulkan.c:70
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:2820
AVPacket::size
int size
Definition: packet.h:604
FFVulkanDescriptorSetBinding
Definition: vulkan.h:112
APV_PBU_PRIMARY_FRAME
@ APV_PBU_PRIMARY_FRAME
Definition: apv.h:27
codec_internal.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
vulkan.h
APVRawFrameHeader
Definition: cbs_apv.h:67
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:544
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:467
DCTPushData::tile_count
int tile_count[2]
Definition: apv_encode_vulkan.c:54
EntropyPushData::comp_base
uint32_t comp_base
Definition: apv_encode_vulkan.c:68
vulkan_encode_apv_class
static const AVClass vulkan_encode_apv_class
Definition: apv_encode_vulkan.c:1072
FFVulkanShader
Definition: vulkan.h:225
VulkanEncodeAPVContext::s
FFVulkanContext s
Definition: apv_encode_vulkan.c:97
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:546
CompactPushData::sparse
VkDeviceAddress sparse
Definition: apv_encode_vulkan.c:76
apv_qmatrix_value
static int apv_qmatrix_value(int qmatrix, int i)
Definition: apv_encode_vulkan.c:191
APVRawFrameInfo::chroma_format_idc
uint8_t chroma_format_idc
Definition: cbs_apv.h:50
APV_MAX_TILE_COUNT
@ APV_MAX_TILE_COUNT
Definition: apv.h:77
build_dct_push_const
static void build_dct_push_const(AVCodecContext *avctx)
Definition: apv_encode_vulkan.c:350
AVCodecHWConfigInternal
Definition: hwconfig.h:25
APVRawFrameHeader::quantization_matrix
APVRawQuantizationMatrix quantization_matrix
Definition: cbs_apv.h:78
VulkanEncodeAPVContext::bytestream_pool
AVBufferPool * bytestream_pool
Definition: apv_encode_vulkan.c:107
FFVkBuffer::flags
VkMemoryPropertyFlagBits flags
Definition: vulkan.h:128
VulkanEncodeAPVFrameData::frame_opaque_ref
AVBufferRef * frame_opaque_ref
Definition: apv_encode_vulkan.c:90
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:602
VulkanEncodeAPVContext::tile_w_mbs_opt
int tile_w_mbs_opt
Definition: apv_encode_vulkan.c:147
APVRawFrameHeader::tile_info
APVRawTileInfo tile_info
Definition: cbs_apv.h:80
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:592
init_dct_shader
static int init_dct_shader(AVCodecContext *avctx)
Definition: apv_encode_vulkan.c:233
FFVkExecContext
Definition: vulkan.h:145
ff_vk_shader_update_desc_buffer
int ff_vk_shader_update_desc_buffer(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, int set, int bind, int elem, FFVkBuffer *buf, VkDeviceSize offset, VkDeviceSize len, VkFormat fmt)
Update a descriptor in a buffer with a buffer.
Definition: vulkan.c:2794
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:609
FFVulkanDescriptorSetBinding::name
const char * name
Definition: vulkan.h:113
fact
static double fact(double i)
Definition: af_aiir.c:935
HW_CONFIG_ENCODER_FRAMES
#define HW_CONFIG_ENCODER_FRAMES(format, device_type_)
Definition: hwconfig.h:98
APV_CHROMA_FORMAT_422
@ APV_CHROMA_FORMAT_422
Definition: apv.h:48
VulkanEncodeAPVContext::tile_count
int tile_count
Definition: apv_encode_vulkan.c:129
vulkan_encode_apv_defaults
static const FFCodecDefault vulkan_encode_apv_defaults[]
Definition: apv_encode_vulkan.c:1067
APV_DEFAULT_QMAT
#define APV_DEFAULT_QMAT
Definition: apv_encode_vulkan.c:49
ff_vk_exec_start
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition: vulkan.c:580
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:596
APVRawPBUHeader::pbu_type
uint8_t pbu_type
Definition: cbs_apv.h:34
VulkanEncodeAPVContext::exec_pool
FFVkExecPool exec_pool
Definition: apv_encode_vulkan.c:99
VulkanEncodeAPVContext::sizes_pool
AVBufferPool * sizes_pool
Definition: apv_encode_vulkan.c:109
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:496
FFVkBuffer::mem
VkDeviceMemory mem
Definition: vulkan.h:127
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:176
vulkan_spirv.h
EntropyPushData::blocks_per_tile
uint32_t blocks_per_tile
Definition: apv_encode_vulkan.c:69
AVCodecContext::height
int height
Definition: avcodec.h:604
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
APV_MAX_TILE_COLS
@ APV_MAX_TILE_COLS
Definition: apv.h:75
VulkanEncodeAPVContext::coeffs_pool
AVBufferPool * coeffs_pool
Definition: apv_encode_vulkan.c:106
AVCodecContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition: avcodec.h:1471
avcodec.h
APV_PROFILE_400_10
@ APV_PROFILE_400_10
Definition: apv.h:68
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:118
AV_CODEC_ID_APV
@ AV_CODEC_ID_APV
Definition: codec_id.h:323
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
ff_vk_create_imageviews
int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e, VkImageView views[AV_NUM_DATA_POINTERS], AVFrame *f, enum FFVkShaderRepFormat rep_fmt)
Create an imageview and add it as a dependency to an execution.
Definition: vulkan.c:2010
FFVulkanContext::vkfn
FFVulkanFunctions vkfn
Definition: vulkan.h:316
tile
static int FUNC() tile(CodedBitstreamContext *ctx, RWContext *rw, APVRawTile *current, int tile_idx, uint32_t tile_size)
Definition: cbs_apv_syntax_template.c:226
FFVkExecContext::opaque
void * opaque
Definition: vulkan.h:162
FFVkExecPool
Definition: vulkan.h:290
ff_vk_shader_add_push_const
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
Definition: vulkan.c:1509
ff_vk_qf_find
AVVulkanDeviceQueueFamily * ff_vk_qf_find(FFVulkanContext *s, VkQueueFlagBits dev_family, VkVideoCodecOperationFlagBitsKHR vid_ops)
Chooses an appropriate QF.
Definition: vulkan.c:286
FFVkExecContext::buf
VkCommandBuffer buf
Definition: vulkan.h:156
APVRawFrameHeader::color_description_present_flag
uint8_t color_description_present_flag
Definition: cbs_apv.h:71
AVCodecContext
main external API structure.
Definition: avcodec.h:443
ff_vk_shader_add_descriptor_set
int ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, const FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a shader.
Definition: vulkan.c:2546
APV_PROFILE_422_10
@ APV_PROFILE_422_10
Definition: apv.h:62
APV_MAX_TILE_ROWS
@ APV_MAX_TILE_ROWS
Definition: apv.h:76
VulkanEncodeAPVFrameData::bytestream_ref
AVBufferRef * bytestream_ref
Definition: apv_encode_vulkan.c:83
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:258
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:73
VulkanEncodeAPVContext::tile_rows
int tile_rows
Definition: apv_encode_vulkan.c:127
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
CompactPushData::slot_size
uint32_t slot_size
Definition: apv_encode_vulkan.c:78
VulkanEncodeAPVContext::profile_idc
int profile_idc
Definition: apv_encode_vulkan.c:136
VulkanEncodeAPVContext::au
CodedBitstreamFragment au
Definition: apv_encode_vulkan.c:116
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFVulkanContext::hwctx
AVVulkanDeviceContext * hwctx
Definition: vulkan.h:349
mem.h
ff_encode_get_frame
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:217
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
vulkan_encode_apv_init
static av_cold int vulkan_encode_apv_init(AVCodecContext *avctx)
Definition: apv_encode_vulkan.c:844
VulkanEncodeAPVContext::tile_h_mbs_opt
int tile_h_mbs_opt
Definition: apv_encode_vulkan.c:148
APV_CHROMA_FORMAT_444
@ APV_CHROMA_FORMAT_444
Definition: apv.h:49
VulkanEncodeAPVContext::qmatrix
int qmatrix
Definition: apv_encode_vulkan.c:151
APVRawFrame::tile_size
uint32_t tile_size[APV_MAX_TILE_COUNT]
Definition: cbs_apv.h:104
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AVVulkanDeviceContext::act_dev
VkDevice act_dev
Active device.
Definition: hwcontext_vulkan.h:84
ff_vk_exec_discard_deps
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:612
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
DCTPushData
Definition: apv_encode_vulkan.c:52
AVPacket
This structure stores compressed data.
Definition: packet.h:580
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:470
ff_apv_encode_dct_comp_spv_len
const unsigned int ff_apv_encode_dct_comp_spv_len
VulkanEncodeAPVContext::band_idc
int band_idc
Definition: apv_encode_vulkan.c:138
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
DCTPushData::num_comp
int num_comp
Definition: apv_encode_vulkan.c:57
VulkanEncodeAPVContext::async_depth
int async_depth
Definition: apv_encode_vulkan.c:121
APV_PROFILE_4444_10
@ APV_PROFILE_4444_10
Definition: apv.h:66
FFVkBuffer
Definition: vulkan.h:125
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:604
VE
#define VE
Definition: apv_encode_vulkan.c:1042
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:925
APV_CHROMA_FORMAT_400
@ APV_CHROMA_FORMAT_400
Definition: apv.h:47
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVVulkanDeviceQueueFamily
Definition: hwcontext_vulkan.h:33
APVRawFrameInfo::bit_depth_minus8
uint8_t bit_depth_minus8
Definition: cbs_apv.h:51
EntropyPushData::bytestream
VkDeviceAddress bytestream
Definition: apv_encode_vulkan.c:64
APV_MIN_TILE_WIDTH_IN_MBS
@ APV_MIN_TILE_WIDTH_IN_MBS
Definition: apv.h:73
DCTPushData::tile_mb_dim
int tile_mb_dim[2]
Definition: apv_encode_vulkan.c:55
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:520
VulkanEncodeAPVContext::exec_ctx_info
VulkanEncodeAPVFrameData * exec_ctx_info
Definition: apv_encode_vulkan.c:123
VulkanEncodeAPVContext::tile_mb_w
int tile_mb_w
Definition: apv_encode_vulkan.c:128
EntropyPushData::tile_mb_dim
int tile_mb_dim[2]
Definition: apv_encode_vulkan.c:71
VulkanEncodeAPVFrameData::duration
int64_t duration
Definition: apv_encode_vulkan.c:88
APVRawTile
Definition: cbs_apv.h:93
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:298
cbs_apv.h
OFFSET
#define OFFSET(x)
Definition: apv_encode_vulkan.c:1041
FFVulkanFunctions
Definition: vulkan_functions.h:275
FFVkExecPool::pool_size
int pool_size
Definition: vulkan.h:296
VulkanEncodeAPVContext::coeffs_size
size_t coeffs_size
Definition: apv_encode_vulkan.c:141
ff_vk_shader_load
int ff_vk_shader_load(FFVulkanShader *shd, VkPipelineStageFlags stage, VkSpecializationInfo *spec, uint32_t wg_size[3], uint32_t required_subgroup_size)
Initialize a shader object.
Definition: vulkan.c:2136
ff_vk_get_pooled_buffer
int ff_vk_get_pooled_buffer(FFVulkanContext *ctx, AVBufferPool **buf_pool, AVBufferRef **buf, VkBufferUsageFlags usage, void *create_pNext, size_t size, VkMemoryPropertyFlagBits mem_props)
Initialize a pool and create AVBufferRefs containing FFVkBuffer.
Definition: vulkan.c:1306
VulkanEncodeAPVContext::shd_compact
FFVulkanShader shd_compact
Definition: apv_encode_vulkan.c:103
chroma_format_from_pix_fmt
static int chroma_format_from_pix_fmt(enum AVPixelFormat sw_fmt)
Definition: apv_encode_vulkan.c:199
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:3376
EntropyPushData
Definition: apv_encode_vulkan.c:63