FFmpeg
vulkan_apv.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2025 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 "vulkan_decode.h"
22 #include "hwaccel_internal.h"
23 
24 #include "apv_decode.h"
25 #include "libavutil/mem.h"
26 
27 extern const unsigned char ff_apv_decode_comp_spv_data[];
28 extern const unsigned int ff_apv_decode_comp_spv_len;
29 
30 extern const unsigned char ff_apv_idct_comp_spv_data[];
31 extern const unsigned int ff_apv_idct_comp_spv_len;
32 
35  .queue_flags = VK_QUEUE_COMPUTE_BIT,
36 };
37 
38 typedef struct APVVulkanDecodePicture {
40 
42  uint32_t *frame_data;
43  int tile_num;
45 
46 typedef struct APVVulkanDecodeContext {
49 
52 
53 typedef struct DecodePushData {
54  VkDeviceAddress tile_data;
55  int tile_count[2];
58  int bit_depth;
60 
62  const AVBufferRef *buffer_ref,
63  av_unused const uint8_t *buffer,
64  av_unused uint32_t size)
65 {
66  int err;
67  APVDecodeContext *apv = avctx->priv_data;
70  APVVulkanDecodeContext *apvvk = ctx->sd_ctx;
71 
73  FFVulkanDecodePicture *vp = &apvvp->vp;
74 
75  /* Host map the input tile data if supported */
76  if (ctx->s.extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY)
77  ff_vk_host_map_buffer(&ctx->s, &vp->slices_buf, buffer_ref->data,
78  buffer_ref,
79  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
80  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
81 
82  /* Allocate frame data buffer */
83  int fd_size = (2*4*APV_MAX_TILE_COUNT)*APV_MAX_NUM_COMP +
86 
87  err = ff_vk_get_pooled_buffer(&ctx->s, &apvvk->frame_data_pool,
88  &apvvp->frame_data_buf,
89  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
90  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
91  NULL, fd_size,
92  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
93  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
94  if (err < 0)
95  return err;
96 
97  /* Frame data */
99  uint8_t *fd = frame_data->mapped_mem;
100 
101  fd += 2*4*APV_MAX_TILE_COUNT*APV_MAX_NUM_COMP; /* Tile offsets go first */
102 
103  /* per-component qmatrix and QPs */
104  for (int i = 0; i < APV_MAX_NUM_COMP; i++)
105  memcpy(fd + 64*i,
107  64);
108  fd += 64*APV_MAX_NUM_COMP;
109 
110  for (int i = 0; i < APV_MAX_NUM_COMP; i++) {
111  for (int j = 0; j < APV_MAX_TILE_COUNT; j++)
112  fd[j] = apv->cur_raw_frame->tile[j].tile_header.tile_qp[i];
113  fd += APV_MAX_TILE_COUNT;
114  }
115 
116  /* tile col/row offset */
117  memcpy(fd, apv->tile_info.col_starts, (APV_MAX_TILE_COLS+1)*2);
118  fd += (APV_MAX_TILE_COLS+1)*2;
119  memcpy(fd, apv->tile_info.row_starts, (APV_MAX_TILE_ROWS+1)*2);
120 
121  /* Prepare frame to be used */
122  err = ff_vk_decode_prepare_frame_sdr(dec, apv->output_frame, vp, 1,
123  FF_VK_REP_NATIVE, 0);
124  if (err < 0)
125  return err;
126 
127  return 0;
128 }
129 
131  const uint8_t *data,
132  uint32_t size)
133 {
134  APVDecodeContext *apv = avctx->priv_data;
135 
137  FFVulkanDecodePicture *vp = &apvvp->vp;
138 
140  FFVkBuffer *slices_buf = vp->slices_buf ? (FFVkBuffer *)vp->slices_buf->data : NULL;
141 
142  if (slices_buf && slices_buf->host_ref) {
143  AV_WN32(frame_data->mapped_mem + (2*apvvp->tile_num + 0)*sizeof(uint32_t),
144  data - slices_buf->mapped_mem);
145  AV_WN32(frame_data->mapped_mem + (2*apvvp->tile_num + 1)*sizeof(uint32_t),
146  size);
147 
148  apvvp->tile_num++;
149  } else {
150  int err = ff_vk_decode_add_slice(avctx, vp, data, size, 0,
151  &apvvp->tile_num,
152  (const uint32_t **)&apvvp->frame_data);
153  if (err < 0)
154  return err;
155 
156  AV_WN32(frame_data->mapped_mem + (2*(apvvp->tile_num - 1) + 0)*sizeof(uint32_t),
157  apvvp->frame_data[apvvp->tile_num - 1]);
158  AV_WN32(frame_data->mapped_mem + (2*(apvvp->tile_num - 1) + 1)*sizeof(uint32_t),
159  size);
160  }
161 
162  return 0;
163 }
164 
166 {
167  int err;
168  APVDecodeContext *apv = avctx->priv_data;
169  const CodedBitstreamAPVContext *apv_cbc = apv->cbc->priv_data;
172  APVVulkanDecodeContext *apvvk = ctx->sd_ctx;
173  FFVulkanFunctions *vk = &ctx->s.vkfn;
174 
176  FFVulkanDecodePicture *vp = &apvvp->vp;
177 
178  FFVkBuffer *slices_buf = (FFVkBuffer *)vp->slices_buf->data;
179  FFVkBuffer *frame_data_buf = (FFVkBuffer *)apvvp->frame_data_buf->data;
180 
182  enum AVPixelFormat sw_format = hwfc->sw_format;
183  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(sw_format);
184 
185  VkImageMemoryBarrier2 img_bar[8];
186  int nb_img_bar = 0;
187 
188  FFVkExecContext *exec = ff_vk_exec_get(&ctx->s, &ctx->exec_pool);
189  ff_vk_exec_start(&ctx->s, exec);
190 
191  /* Make sure the buffer is flushed */
192  RET(ff_vk_flush_buffer(&ctx->s, frame_data_buf, 0, frame_data_buf->size, 1));
193 
194  /* Prepare deps */
196  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
197  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
198 
199  err = ff_vk_exec_mirror_sem_value(&ctx->s, exec, &vp->sem, &vp->sem_value,
200  apv->output_frame);
201  if (err < 0)
202  return err;
203 
204  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &vp->slices_buf, 1, 0));
205  vp->slices_buf = NULL;
206  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &apvvp->frame_data_buf, 1, 0));
207  apvvp->frame_data_buf = NULL;
208 
209  AVVkFrame *vkf = (AVVkFrame *)apv->output_frame->data[0];
210  vkf->layout[0] = VK_IMAGE_LAYOUT_UNDEFINED;
211  vkf->access[0] = VK_ACCESS_2_NONE;
212 
213  ff_vk_frame_barrier(&ctx->s, exec, apv->output_frame,
214  img_bar, &nb_img_bar,
215  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
216  VK_PIPELINE_STAGE_2_CLEAR_BIT,
217  VK_ACCESS_2_TRANSFER_WRITE_BIT,
218  VK_IMAGE_LAYOUT_GENERAL,
219  VK_QUEUE_FAMILY_IGNORED);
220  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
221  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
222  .pImageMemoryBarriers = img_bar,
223  .imageMemoryBarrierCount = nb_img_bar,
224  });
225  nb_img_bar = 0;
226 
227  /* Zero frame */
228  for (int i = 0; i < ff_vk_count_images(vkf); i++)
229  vk->CmdClearColorImage(exec->buf, vkf->img[i],
230  VK_IMAGE_LAYOUT_GENERAL,
231  &((VkClearColorValue) { 0 }),
232  1, &((VkImageSubresourceRange) {
233  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
234  .levelCount = 1,
235  .layerCount = 1,
236  }));
237 
238  /* Wait for the frame to get zeroed out before continuing */
239  ff_vk_frame_barrier(&ctx->s, exec, apv->output_frame, img_bar, &nb_img_bar,
240  VK_PIPELINE_STAGE_2_CLEAR_BIT,
241  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
242  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
243  VK_IMAGE_LAYOUT_GENERAL,
244  VK_QUEUE_FAMILY_IGNORED);
245  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
246  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
247  .pImageMemoryBarriers = img_bar,
248  .imageMemoryBarrierCount = nb_img_bar,
249  });
250  nb_img_bar = 0;
251 
252  /* Setup push data */
254  .tile_data = slices_buf->address,
255  .tile_count = { apv->tile_info.tile_cols, apv->tile_info.tile_rows },
256  .log2_chroma_sub = { desc->log2_chroma_w, desc->log2_chroma_h },
257  .components = desc->nb_components,
258  .bit_depth = apv_cbc->bit_depth,
259  };
260 
261  /* Decoding */
262  ff_vk_shader_update_img_array(&ctx->s, exec, &apvvk->decode,
263  apv->output_frame, vp->view.out,
264  0, 0,
265  VK_IMAGE_LAYOUT_GENERAL,
266  VK_NULL_HANDLE);
267  ff_vk_shader_update_desc_buffer(&ctx->s, exec, &apvvk->decode,
268  0, 1, 0,
269  frame_data_buf,
270  0, frame_data_buf->size,
271  VK_FORMAT_UNDEFINED);
272 
273  ff_vk_exec_bind_shader(&ctx->s, exec, &apvvk->decode);
274  ff_vk_shader_update_push_const(&ctx->s, exec, &apvvk->decode,
275  VK_SHADER_STAGE_COMPUTE_BIT,
276  0, sizeof(pd), &pd);
277 
278  vk->CmdDispatch(exec->buf,
280  desc->nb_components);
281 
282  /* Wait for all decoding to finish */
283  ff_vk_frame_barrier(&ctx->s, exec, apv->output_frame, img_bar, &nb_img_bar,
284  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
285  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
286  VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
287  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
288  VK_IMAGE_LAYOUT_GENERAL,
289  VK_QUEUE_FAMILY_IGNORED);
290  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
291  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
292  .pImageMemoryBarriers = img_bar,
293  .imageMemoryBarrierCount = nb_img_bar,
294  });
295  nb_img_bar = 0;
296 
297  /* iDCT */
298  ff_vk_shader_update_img_array(&ctx->s, exec, &apvvk->idct,
299  apv->output_frame, vp->view.out,
300  0, 0,
301  VK_IMAGE_LAYOUT_GENERAL,
302  VK_NULL_HANDLE);
303  ff_vk_shader_update_desc_buffer(&ctx->s, exec, &apvvk->idct,
304  0, 1, 0,
305  frame_data_buf,
306  0, frame_data_buf->size,
307  VK_FORMAT_UNDEFINED);
308 
309  ff_vk_exec_bind_shader(&ctx->s, exec, &apvvk->idct);
310  ff_vk_shader_update_push_const(&ctx->s, exec, &apvvk->idct,
311  VK_SHADER_STAGE_COMPUTE_BIT,
312  0, sizeof(pd), &pd);
313 
314  /* one workgroup per group of 8 horizontally adjacent transform blocks,
315  * in the luma basis coords, in case a block is OOB writes/reads are ignored */
316  int idct_cx = 0, idct_by = 0;
317  for (int comp = 0; comp < desc->nb_components; comp++) {
318  int sw = (comp == 0) ? 0 : desc->log2_chroma_w;
319  int sh = (comp == 0) ? 0 : desc->log2_chroma_h;
320  int bx = (avctx->coded_width + (1 << (3 + sw)) - 1) >> (3 + sw);
321  int by = (avctx->coded_height + (1 << (3 + sh)) - 1) >> (3 + sh);
322  idct_cx = FFMAX(idct_cx, (bx + 7) >> 3);
323  idct_by = FFMAX(idct_by, by);
324  }
325  vk->CmdDispatch(exec->buf, idct_cx, idct_by, desc->nb_components);
326 
327  err = ff_vk_exec_submit(&ctx->s, exec);
328  if (err < 0)
329  return err;
330 
331 fail:
332  return 0;
333 }
334 
336  FFVkExecPool *pool, FFVulkanShader *shd)
337 {
338  int err;
339  AVHWFramesContext *dec_frames_ctx;
340  dec_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
341 
342  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, NULL,
343  (uint32_t []) { 1, 1, 1 }, 0);
345  VK_SHADER_STAGE_COMPUTE_BIT);
346 
347  const FFVulkanDescriptorSetBinding desc_set[] = {
348  {
349  .name = "dst",
350  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
351  .elems = av_pix_fmt_count_planes(dec_frames_ctx->sw_format),
352  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
353  },
354  {
355  .name = "frame_data_buf",
356  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
357  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
358  }
359  };
360  ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 0, 0);
361 
362  RET(ff_vk_shader_link(s, shd,
364  ff_apv_decode_comp_spv_len, "main"));
365 
366  RET(ff_vk_shader_register_exec(s, pool, shd));
367 
368 fail:
369  return err;
370 }
371 
373  FFVkExecPool *pool, FFVulkanShader *shd)
374 {
375  int err;
376  AVHWFramesContext *dec_frames_ctx;
377  dec_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
378 
379  SPEC_LIST_CREATE(sl, 1 + 64, (1 + 64)*sizeof(uint32_t))
380  SPEC_LIST_ADD(sl, 16, 32, 8); /* nb_blocks per workgroup */
381 
382  const double idct_8_scales[8] = {
383  cos(4.0*M_PI/16.0) / 2.0, cos(1.0*M_PI/16.0) / 2.0,
384  cos(2.0*M_PI/16.0) / 2.0, cos(3.0*M_PI/16.0) / 2.0,
385  cos(4.0*M_PI/16.0) / 2.0, cos(5.0*M_PI/16.0) / 2.0,
386  cos(6.0*M_PI/16.0) / 2.0, cos(7.0*M_PI/16.0) / 2.0,
387  };
388  for (int i = 0; i < 64; i++)
389  SPEC_LIST_ADD(sl, 18 + i, 32,
390  av_float2int(idct_8_scales[i >> 3]*idct_8_scales[i & 7]));
391 
392  ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
393  (uint32_t []) { 32, 2, 1 }, 0);
395  VK_SHADER_STAGE_COMPUTE_BIT);
396 
397  FFVulkanDescriptorSetBinding desc_set[] = {
398  {
399  .name = "dst",
400  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
401  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
402  .elems = av_pix_fmt_count_planes(dec_frames_ctx->sw_format),
403  },
404  {
405  .name = "frame_data_buf",
406  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
407  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
408  },
409  };
410  ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 0, 0);
411 
412  RET(ff_vk_shader_link(s, shd,
414  ff_apv_idct_comp_spv_len, "main"));
415 
416  RET(ff_vk_shader_register_exec(s, pool, shd));
417 
418 fail:
419  return err;
420 }
421 
423 {
424  APVVulkanDecodeContext *apvvk = ctx->sd_ctx;
425 
426  ff_vk_shader_free(&ctx->s, &apvvk->decode);
427  ff_vk_shader_free(&ctx->s, &apvvk->idct);
428 
430 
431  av_freep(&apvvk);
432 }
433 
435 {
436  int err;
438 
439  err = ff_vk_decode_init(avctx);
440  if (err < 0)
441  return err;
442 
444  APVVulkanDecodeContext *apvvk = ctx->sd_ctx = av_mallocz(sizeof(*apvvk));
445  if (!apvvk) {
446  err = AVERROR(ENOMEM);
447  goto fail;
448  }
449 
450  ctx->sd_ctx_free = &vk_decode_apv_uninit;
451 
452  RET(init_decode_shader(avctx, &ctx->s, &ctx->exec_pool,
453  &apvvk->decode));
454 
455  RET(init_idct_shader(avctx, &ctx->s, &ctx->exec_pool,
456  &apvvk->idct));
457 
458 fail:
459  return err;
460 }
461 
463 {
464  AVHWDeviceContext *dev_ctx = _hwctx.nc;
465 
466  APVVulkanDecodePicture *apvvp = data;
467  FFVulkanDecodePicture *vp = &apvvp->vp;
468 
469  ff_vk_decode_free_frame(dev_ctx, vp);
470 
472 }
473 
475  .p.name = "apv_vulkan",
476  .p.type = AVMEDIA_TYPE_VIDEO,
477  .p.id = AV_CODEC_ID_APV,
478  .p.pix_fmt = AV_PIX_FMT_VULKAN,
479  .start_frame = &vk_apv_start_frame,
480  .decode_slice = &vk_apv_decode_slice,
481  .end_frame = &vk_apv_end_frame,
482  .free_frame_priv = &vk_apv_free_frame_priv,
483  .frame_priv_data_size = sizeof(APVVulkanDecodePicture),
487  .frame_params = &ff_vk_frame_params,
488  .priv_data_size = sizeof(FFVulkanDecodeContext),
490 };
APV_MAX_TILE_COLS
@ APV_MAX_TILE_COLS
Definition: apv.h:75
ff_vk_dec_apv_desc
const FFVulkanDecodeDescriptor ff_vk_dec_apv_desc
Definition: vulkan_apv.c:33
DecodePushData::log2_chroma_sub
int log2_chroma_sub[2]
Definition: vulkan_apv.c:56
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
APVDerivedTileInfo::tile_cols
uint8_t tile_cols
Definition: apv_decode.h:89
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
CodedBitstreamContext::priv_data
void * priv_data
Internal codec-specific data.
Definition: cbs.h:247
ff_vk_shader_free
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition: vulkan.c:2835
APVDecodeContext::output_frame
AVFrame * output_frame
Definition: apv_decode.h:107
comp
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:79
AVBufferPool
The buffer pool.
Definition: buffer_internal.h:88
ff_vk_decode_prepare_frame_sdr
int ff_vk_decode_prepare_frame_sdr(FFVulkanDecodeContext *dec, AVFrame *pic, FFVulkanDecodePicture *vkpic, int is_current, enum FFVkShaderRepFormat rep_fmt, int alloc_dpb)
Software-defined decoder version of ff_vk_decode_prepare_frame.
Definition: vulkan_decode.c:258
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
FFVulkanDecodeContext::shared_ctx
FFVulkanDecodeShared * shared_ctx
Definition: vulkan_decode.h:55
RET
#define RET(x)
Definition: vulkan.h:68
AVRefStructOpaque
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition: refstruct.h:58
APVDecodeContext
Definition: apv_decode.h:98
vk_apv_decode_slice
static int vk_apv_decode_slice(AVCodecContext *avctx, const uint8_t *data, uint32_t size)
Definition: vulkan_apv.c:130
AVRefStructOpaque::nc
void * nc
Definition: refstruct.h:59
av_unused
#define av_unused
Definition: attributes.h:164
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
apv_decode.h
APVRawFrame::tile
APVRawTile tile[APV_MAX_TILE_COUNT]
Definition: cbs_apv.h:105
APV_MAX_TILE_COUNT
@ APV_MAX_TILE_COUNT
Definition: apv.h:77
data
const char data[16]
Definition: mxf.c:149
FFVulkanDecodeDescriptor::codec_id
enum AVCodecID codec_id
Definition: vulkan_decode.h:30
ff_vk_flush_buffer
int ff_vk_flush_buffer(FFVulkanContext *s, FFVkBuffer *buf, VkDeviceSize offset, VkDeviceSize mem_size, int flush)
Flush or invalidate a single buffer, with a given size and offset.
Definition: vulkan.c:1181
FFVkBuffer::address
VkDeviceAddress address
Definition: vulkan.h:130
ff_vk_exec_get
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition: vulkan.c:558
FF_VK_REP_NATIVE
@ FF_VK_REP_NATIVE
Definition: vulkan.h:449
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
SPEC_LIST_ADD
#define SPEC_LIST_ADD(name, idx, val_bits, val)
Definition: vulkan.h:86
av_float2int
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
Definition: intfloat.h:50
ff_vk_exec_bind_shader
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition: vulkan.c:2812
FFVulkanDecodeContext
Definition: vulkan_decode.h:54
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:790
APVDecodeContext::tile_info
APVDerivedTileInfo tile_info
Definition: apv_decode.h:103
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:480
APV_MAX_NUM_COMP
@ APV_MAX_NUM_COMP
Definition: apv.h:39
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3496
FFHWAccel
Definition: hwaccel_internal.h:34
AVVkFrame::img
VkImage img[AV_NUM_DATA_POINTERS]
Vulkan images to which the memory is bound to.
Definition: hwcontext_vulkan.h:315
fail
#define fail()
Definition: checkasm.h:225
FFVulkanDecodePicture::sem_value
uint64_t sem_value
Definition: vulkan_decode.h:85
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:2763
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:2075
HWACCEL_CAP_THREAD_SAFE
#define HWACCEL_CAP_THREAD_SAFE
Definition: hwaccel_internal.h:32
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:2628
ff_vk_host_map_buffer
int ff_vk_host_map_buffer(FFVulkanContext *s, AVBufferRef **dst, uint8_t *src_data, const AVBufferRef *src_buf, VkBufferUsageFlags usage)
Maps a system RAM buffer into a Vulkan buffer.
Definition: vulkan.c:1401
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:619
FFVulkanDecodeShared
Definition: vulkan_decode.h:38
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:63
DecodePushData::bit_depth
int bit_depth
Definition: vulkan_apv.c:58
ff_apv_decode_comp_spv_len
const unsigned int ff_apv_decode_comp_spv_len
vk_apv_free_frame_priv
static void vk_apv_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
Definition: vulkan_apv.c:462
APVRawFrame::frame_header
APVRawFrameHeader frame_header
Definition: cbs_apv.h:103
s
#define s(width, name)
Definition: cbs_vp9.c:198
FFVulkanDecodePicture
Definition: vulkan_decode.h:73
init_idct_shader
static int init_idct_shader(AVCodecContext *avctx, FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Definition: vulkan_apv.c:372
ff_vk_exec_mirror_sem_value
int ff_vk_exec_mirror_sem_value(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore *dst, uint64_t *dst_val, AVFrame *f)
Definition: vulkan.c:889
APVVulkanDecodeContext::idct
FFVulkanShader idct
Definition: vulkan_apv.c:48
init_decode_shader
static int init_decode_shader(AVCodecContext *avctx, FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Definition: vulkan_apv.c:335
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
DecodePushData
Definition: vulkan_apv.c:53
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:630
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
APVDecodeContext::cur_raw_frame
APVRawFrame * cur_raw_frame
Definition: apv_decode.h:104
APVVulkanDecodeContext::frame_data_pool
AVBufferPool * frame_data_pool
Definition: vulkan_apv.c:50
ff_apv_decode_comp_spv_data
const unsigned char ff_apv_decode_comp_spv_data[]
HWACCEL_CAP_ASYNC_SAFE
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
Definition: hwaccel_internal.h:31
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:213
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
hwaccel_internal.h
ff_vk_decode_free_frame
void ff_vk_decode_free_frame(AVHWDeviceContext *dev_ctx, FFVulkanDecodePicture *vp)
Free a frame and its state.
Definition: vulkan_decode.c:694
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:478
CodedBitstreamAPVContext::bit_depth
int bit_depth
Definition: cbs_apv.h:191
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
ff_vk_decode_uninit
int ff_vk_decode_uninit(AVCodecContext *avctx)
Free decoder.
Definition: vulkan_decode.c:1300
APVVulkanDecodePicture::frame_data_buf
AVBufferRef * frame_data_buf
Definition: vulkan_apv.c:41
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:2401
SPEC_LIST_CREATE
#define SPEC_LIST_CREATE(name, max_length, max_size)
Definition: vulkan.h:76
FFVulkanContext
Definition: vulkan.h:312
ff_vk_frame_params
int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Initialize hw_frames_ctx with the parameters needed to decode the stream using the parameters from av...
Definition: vulkan_decode.c:1159
DecodePushData::tile_count
int tile_count[2]
Definition: vulkan_apv.c:55
APVRawTile::tile_header
APVRawTileHeader tile_header
Definition: cbs_apv.h:94
vk_decode_apv_init
static int vk_decode_apv_init(AVCodecContext *avctx)
Definition: vulkan_apv.c:434
vk_apv_end_frame
static int vk_apv_end_frame(AVCodecContext *avctx)
Definition: vulkan_apv.c:165
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:551
ff_apv_vulkan_hwaccel
const FFHWAccel ff_apv_vulkan_hwaccel
Definition: vulkan_apv.c:474
AVVkFrame::access
VkAccessFlagBits access[AV_NUM_DATA_POINTERS]
Updated after every barrier.
Definition: hwcontext_vulkan.h:339
APVVulkanDecodeContext::decode
FFVulkanShader decode
Definition: vulkan_apv.c:47
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:2802
FFVulkanDescriptorSetBinding
Definition: vulkan.h:112
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:372
AVCodecInternal::hwaccel_priv_data
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:130
AVVkFrame
Definition: hwcontext_vulkan.h:310
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
size
int size
Definition: twinvq_data.h:10344
FFVulkanShader
Definition: vulkan.h:225
APVVulkanDecodeContext
Definition: vulkan_apv.c:46
APVRawFrameHeader::quantization_matrix
APVRawQuantizationMatrix quantization_matrix
Definition: cbs_apv.h:78
frame_data
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
Definition: ffmpeg.c:477
CodedBitstreamAPVContext
Definition: cbs_apv.h:190
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:2776
FFVulkanDescriptorSetBinding::name
const char * name
Definition: vulkan.h:113
M_PI
#define M_PI
Definition: mathematics.h:67
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:1967
DecodePushData::tile_data
VkDeviceAddress tile_data
Definition: vulkan_apv.c:54
FF_VK_EXT_EXTERNAL_HOST_MEMORY
#define FF_VK_EXT_EXTERNAL_HOST_MEMORY
Definition: vulkan_functions.h:36
APVDerivedTileInfo::row_starts
uint16_t row_starts[APV_MAX_TILE_ROWS+1]
Definition: apv_decode.h:95
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
vk_decode_apv_uninit
static void vk_decode_apv_uninit(FFVulkanDecodeShared *ctx)
Definition: vulkan_apv.c:422
FFVulkanDecodePicture::out
VkImageView out[AV_NUM_DATA_POINTERS]
Definition: vulkan_decode.h:78
ff_vk_exec_start
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition: vulkan.c:570
FFVulkanDecodePicture::view
struct FFVulkanDecodePicture::@340 view
FFVulkanDecodePicture::sem
VkSemaphore sem
Definition: vulkan_decode.h:84
vk_apv_start_frame
static int vk_apv_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition: vulkan_apv.c:61
ff_apv_idct_comp_spv_data
const unsigned char ff_apv_idct_comp_spv_data[]
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
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:332
APVVulkanDecodePicture::tile_num
int tile_num
Definition: vulkan_apv.c:43
FFVkExecPool
Definition: vulkan.h:290
ff_vk_decode_add_slice
int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp, const uint8_t *data, size_t size, int add_startcode, uint32_t *nb_slices, const uint32_t **offsets)
Add slice data to frame.
Definition: vulkan_decode.c:305
APVRawTileHeader::tile_qp
uint8_t tile_qp[APV_MAX_NUM_COMP]
Definition: cbs_apv.h:89
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:1499
APVDerivedTileInfo::tile_rows
uint8_t tile_rows
Definition: apv_decode.h:90
ff_apv_idct_comp_spv_len
const unsigned int ff_apv_idct_comp_spv_len
FFVkExecContext::buf
VkCommandBuffer buf
Definition: vulkan.h:156
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:2528
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
update_thread_context
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have update_thread_context() run it in the next thread. Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little speed gain at this point but it should work. Use ff_thread_get_buffer()(or ff_progress_frame_get_buffer() in case you have inter-frame dependencies and use the ProgressFrame API) to allocate frame buffers. Call ff_progress_frame_report() after some part of the current picture has decoded. A good place to put this is where draw_horiz_band() is called - add this if it isn 't called anywhere
APVDerivedTileInfo::col_starts
uint16_t col_starts[APV_MAX_TILE_COLS+1]
Definition: apv_decode.h:94
FFVulkanDecodeDescriptor
Definition: vulkan_decode.h:29
APVVulkanDecodePicture
Definition: vulkan_apv.c:38
APV_MAX_TILE_ROWS
@ APV_MAX_TILE_ROWS
Definition: apv.h:76
APVVulkanDecodePicture::vp
FFVulkanDecodePicture vp
Definition: vulkan_apv.c:39
ff_vk_update_thread_context
int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Synchronize the contexts between 2 threads.
Definition: vulkan_decode.c:142
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:619
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFVulkanDecodePicture::slices_buf
AVBufferRef * slices_buf
Definition: vulkan_decode.h:99
mem.h
AVVkFrame::layout
VkImageLayout layout[AV_NUM_DATA_POINTERS]
Definition: hwcontext_vulkan.h:340
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
vulkan_decode.h
DecodePushData::components
int components
Definition: vulkan_apv.c:57
APVDecodeContext::cbc
CodedBitstreamContext * cbc
Definition: apv_decode.h:99
ff_vk_count_images
static int ff_vk_count_images(AVVkFrame *f)
Definition: vulkan.h:366
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:470
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
FFVkBuffer
Definition: vulkan.h:125
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:915
APVDecodeContext::hwaccel_picture_private
void * hwaccel_picture_private
Definition: apv_decode.h:108
ff_vk_decode_init
int ff_vk_decode_init(AVCodecContext *avctx)
Initialize decoder.
Definition: vulkan_decode.c:1311
APVVulkanDecodePicture::frame_data
uint32_t * frame_data
Definition: vulkan_apv.c:42
FFVulkanFunctions
Definition: vulkan_functions.h:275
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:2118
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:1296