FFmpeg
vulkan_ffv1.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 Lynne <dev@lynne.ee>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "vulkan_decode.h"
22 #include "hwaccel_internal.h"
23 
24 #include "ffv1.h"
25 #include "ffv1_vulkan.h"
26 #include "libavutil/vulkan_spirv.h"
27 #include "libavutil/mem.h"
28 
29 #define RGB_LINECACHE 2
30 
31 extern const char *ff_source_common_comp;
32 extern const char *ff_source_rangecoder_comp;
33 extern const char *ff_source_ffv1_vlc_comp;
34 extern const char *ff_source_ffv1_common_comp;
35 extern const char *ff_source_ffv1_dec_setup_comp;
36 extern const char *ff_source_ffv1_reset_comp;
37 extern const char *ff_source_ffv1_dec_comp;
38 
41  .decode_extension = FF_VK_EXT_PUSH_DESCRIPTOR,
42  .queue_flags = VK_QUEUE_COMPUTE_BIT,
43 };
44 
45 typedef struct FFv1VulkanDecodePicture {
47 
49  uint32_t plane_state_size;
50  uint32_t slice_state_size;
51  uint32_t slice_data_size;
52 
54  uint32_t *slice_offset;
55  int slice_num;
56 
60 
61 typedef struct FFv1VulkanDecodeContext {
62  AVBufferRef *intermediate_frames_ref[2]; /* 16/32 bit */
63 
65  FFVulkanShader reset[2]; /* AC/Golomb */
66  FFVulkanShader decode[2][2][2]; /* 16/32 bit, AC/Golomb, Normal/RGB */
67 
71 
76 
77 typedef struct FFv1VkParameters {
78  VkDeviceAddress slice_data;
79  VkDeviceAddress slice_state;
80 
81  int fmt_lut[4];
82  uint32_t img_size[2];
83  uint32_t chroma_shift[2];
84 
85  uint32_t plane_state_size;
86  uint32_t crcref;
87  int rct_offset;
88 
89  uint8_t extend_lookup[8];
90  uint8_t bits_per_raw_sample;
92  uint8_t version;
93  uint8_t micro_version;
94  uint8_t key_frame;
95  uint8_t planes;
96  uint8_t codec_planes;
97  uint8_t color_planes;
98  uint8_t transparency;
99  uint8_t planar_rgb;
100  uint8_t colorspace;
101  uint8_t ec;
102  uint8_t golomb;
103  uint8_t check_crc;
104  uint8_t padding[3];
106 
107 static void add_push_data(FFVulkanShader *shd)
108 {
109  GLSLC(0, layout(push_constant, scalar) uniform pushConstants { );
110  GLSLC(1, u8buf slice_data; );
111  GLSLC(1, u8buf slice_state; );
112  GLSLC(0, );
113  GLSLC(1, ivec4 fmt_lut; );
114  GLSLC(1, uvec2 img_size; );
115  GLSLC(1, uvec2 chroma_shift; );
116  GLSLC(0, );
117  GLSLC(1, uint plane_state_size; );
118  GLSLC(1, uint32_t crcref; );
119  GLSLC(1, int rct_offset; );
120  GLSLC(0, );
121  GLSLC(1, uint8_t extend_lookup[8]; );
122  GLSLC(1, uint8_t bits_per_raw_sample; );
123  GLSLC(1, uint8_t quant_table_count; );
124  GLSLC(1, uint8_t version; );
125  GLSLC(1, uint8_t micro_version; );
126  GLSLC(1, uint8_t key_frame; );
127  GLSLC(1, uint8_t planes; );
128  GLSLC(1, uint8_t codec_planes; );
129  GLSLC(1, uint8_t color_planes; );
130  GLSLC(1, uint8_t transparency; );
131  GLSLC(1, uint8_t planar_rgb; );
132  GLSLC(1, uint8_t colorspace; );
133  GLSLC(1, uint8_t ec; );
134  GLSLC(1, uint8_t golomb; );
135  GLSLC(1, uint8_t check_crc; );
136  GLSLC(1, uint8_t padding[3]; );
137  GLSLC(0, }; );
139  VK_SHADER_STAGE_COMPUTE_BIT);
140 }
141 
143  const AVBufferRef *buffer_ref,
144  av_unused const uint8_t *buffer,
145  av_unused uint32_t size)
146 {
147  int err;
150  FFv1VulkanDecodeContext *fv = ctx->sd_ctx;
151  FFV1Context *f = avctx->priv_data;
152 
153  FFv1VulkanDecodePicture *fp = f->hwaccel_picture_private;
154  FFVulkanDecodePicture *vp = &fp->vp;
155 
157  enum AVPixelFormat sw_format = hwfc->sw_format;
158 
159  int max_contexts;
160  int is_rgb = !(f->colorspace == 0 && sw_format != AV_PIX_FMT_YA8) &&
161  !(sw_format == AV_PIX_FMT_YA8);
162 
163  fp->slice_num = 0;
164 
165  max_contexts = 0;
166  for (int i = 0; i < f->quant_table_count; i++)
167  max_contexts = FFMAX(f->context_count[i], max_contexts);
168 
169  /* Allocate slice buffer data */
170  if (f->ac == AC_GOLOMB_RICE)
171  fp->plane_state_size = 8;
172  else
174 
175  fp->plane_state_size *= max_contexts;
176  fp->slice_state_size = fp->plane_state_size*f->plane_count;
177 
178  fp->slice_data_size = 256; /* Overestimation for the SliceContext struct */
181 
182  fp->crc_checked = f->ec && (avctx->err_recognition & AV_EF_CRCCHECK);
183 
184  /* Host map the input slices data if supported */
185  if (ctx->s.extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY)
186  ff_vk_host_map_buffer(&ctx->s, &vp->slices_buf, buffer_ref->data,
187  buffer_ref,
188  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
189  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
190 
191  /* Allocate slice state data */
192  if (f->picture.f->flags & AV_FRAME_FLAG_KEY) {
194  &fp->slice_state,
195  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
196  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
197  NULL, f->slice_count*fp->slice_state_size,
198  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
199  if (err < 0)
200  return err;
201  } else {
202  FFv1VulkanDecodePicture *fpl = f->hwaccel_last_picture_private;
204  if (!fp->slice_state)
205  return AVERROR(ENOMEM);
206  }
207 
208  /* Allocate slice offsets buffer */
210  &fp->slice_offset_buf,
211  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
212  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
213  NULL, 2*f->slice_count*sizeof(uint32_t),
214  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
215  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
216  if (err < 0)
217  return err;
218 
219  /* Allocate slice status buffer */
221  &fp->slice_status_buf,
222  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
223  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
224  NULL, 2*f->slice_count*sizeof(uint32_t),
225  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
226  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
227  if (err < 0)
228  return err;
229 
230  /* Prepare frame to be used */
231  err = ff_vk_decode_prepare_frame_sdr(dec, f->picture.f, vp, 1,
232  FF_VK_REP_NATIVE, 0);
233  if (err < 0)
234  return err;
235 
236  /* Create a temporaty frame for RGB */
237  if (is_rgb) {
238  vp->dpb_frame = av_frame_alloc();
239  if (!vp->dpb_frame)
240  return AVERROR(ENOMEM);
241 
242  err = av_hwframe_get_buffer(fv->intermediate_frames_ref[f->use32bit],
243  vp->dpb_frame, 0);
244  if (err < 0)
245  return err;
246  }
247 
248  return 0;
249 }
250 
252  const uint8_t *data,
253  uint32_t size)
254 {
255  FFV1Context *f = avctx->priv_data;
256 
257  FFv1VulkanDecodePicture *fp = f->hwaccel_picture_private;
258  FFVulkanDecodePicture *vp = &fp->vp;
259 
260  FFVkBuffer *slice_offset = (FFVkBuffer *)fp->slice_offset_buf->data;
261  FFVkBuffer *slices_buf = vp->slices_buf ? (FFVkBuffer *)vp->slices_buf->data : NULL;
262 
263  if (slices_buf && slices_buf->host_ref) {
264  AV_WN32(slice_offset->mapped_mem + (2*fp->slice_num + 0)*sizeof(uint32_t),
265  data - slices_buf->mapped_mem);
266  AV_WN32(slice_offset->mapped_mem + (2*fp->slice_num + 1)*sizeof(uint32_t),
267  size);
268 
269  fp->slice_num++;
270  } else {
271  int err = ff_vk_decode_add_slice(avctx, vp, data, size, 0,
272  &fp->slice_num,
273  (const uint32_t **)&fp->slice_offset);
274  if (err < 0)
275  return err;
276 
277  AV_WN32(slice_offset->mapped_mem + (2*(fp->slice_num - 1) + 0)*sizeof(uint32_t),
278  fp->slice_offset[fp->slice_num - 1]);
279  AV_WN32(slice_offset->mapped_mem + (2*(fp->slice_num - 1) + 1)*sizeof(uint32_t),
280  size);
281  }
282 
283  return 0;
284 }
285 
287 {
288  int err;
291  FFVulkanFunctions *vk = &ctx->s.vkfn;
292 
293  FFV1Context *f = avctx->priv_data;
294  FFv1VulkanDecodeContext *fv = ctx->sd_ctx;
295  FFv1VkParameters pd;
296  FFv1VkResetParameters pd_reset;
297 
299  enum AVPixelFormat sw_format = hwfc->sw_format;
300 
301  int bits = f->avctx->bits_per_raw_sample > 0 ? f->avctx->bits_per_raw_sample : 8;
302  int is_rgb = !(f->colorspace == 0 && sw_format != AV_PIX_FMT_YA8) &&
303  !(sw_format == AV_PIX_FMT_YA8);
304  int color_planes = av_pix_fmt_desc_get(avctx->sw_pix_fmt)->nb_components;
305 
306  FFVulkanShader *reset_shader;
307  FFVulkanShader *decode_shader;
308 
309  FFv1VulkanDecodePicture *fp = f->hwaccel_picture_private;
310  FFVulkanDecodePicture *vp = &fp->vp;
311 
312  FFVkBuffer *slices_buf = (FFVkBuffer *)vp->slices_buf->data;
313  FFVkBuffer *slice_state = (FFVkBuffer *)fp->slice_state->data;
314  FFVkBuffer *slice_offset = (FFVkBuffer *)fp->slice_offset_buf->data;
315  FFVkBuffer *slice_status = (FFVkBuffer *)fp->slice_status_buf->data;
316 
317  VkImageView rct_image_views[AV_NUM_DATA_POINTERS];
318 
319  AVFrame *decode_dst = is_rgb ? vp->dpb_frame : f->picture.f;
320  VkImageView *decode_dst_view = is_rgb ? rct_image_views : vp->view.out;
321 
322  VkImageMemoryBarrier2 img_bar[37];
323  int nb_img_bar = 0;
324  VkBufferMemoryBarrier2 buf_bar[8];
325  int nb_buf_bar = 0;
326 
327  FFVkExecContext *exec = ff_vk_exec_get(&ctx->s, &ctx->exec_pool);
328  ff_vk_exec_start(&ctx->s, exec);
329 
330  /* Prepare deps */
331  RET(ff_vk_exec_add_dep_frame(&ctx->s, exec, f->picture.f,
332  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
333  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
334 
335  err = ff_vk_exec_mirror_sem_value(&ctx->s, exec, &vp->sem, &vp->sem_value,
336  f->picture.f);
337  if (err < 0)
338  return err;
339 
340  if (is_rgb) {
341  RET(ff_vk_create_imageviews(&ctx->s, exec, rct_image_views,
343  RET(ff_vk_exec_add_dep_frame(&ctx->s, exec, vp->dpb_frame,
344  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
345  VK_PIPELINE_STAGE_2_CLEAR_BIT));
346  ff_vk_frame_barrier(&ctx->s, exec, decode_dst, img_bar, &nb_img_bar,
347  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
348  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
349  VK_ACCESS_2_TRANSFER_WRITE_BIT,
350  VK_IMAGE_LAYOUT_GENERAL,
351  VK_QUEUE_FAMILY_IGNORED);
352  }
353 
354  if (!(f->picture.f->flags & AV_FRAME_FLAG_KEY)) {
355  FFv1VulkanDecodePicture *fpl = f->hwaccel_last_picture_private;
356  FFVulkanDecodePicture *vpl = &fpl->vp;
357 
358  /* Wait on the previous frame */
359  RET(ff_vk_exec_add_dep_wait_sem(&ctx->s, exec, vpl->sem, vpl->sem_value,
360  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT));
361  }
362 
363  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &fp->slice_state, 1, 1));
364  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &fp->slice_status_buf, 1, 1));
365  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &vp->slices_buf, 1, 0));
366  vp->slices_buf = NULL;
367  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &fp->slice_offset_buf, 1, 0));
368  fp->slice_offset_buf = NULL;
369 
370  /* Entry barrier for the slice state */
371  buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
372  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
373  .srcStageMask = slice_state->stage,
374  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
375  .srcAccessMask = slice_state->access,
376  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
377  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
378  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
379  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
380  .buffer = slice_state->buf,
381  .offset = 0,
382  .size = fp->slice_data_size*f->slice_count,
383  };
384 
385  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
386  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
387  .pImageMemoryBarriers = img_bar,
388  .imageMemoryBarrierCount = nb_img_bar,
389  .pBufferMemoryBarriers = buf_bar,
390  .bufferMemoryBarrierCount = nb_buf_bar,
391  });
392  slice_state->stage = buf_bar[0].dstStageMask;
393  slice_state->access = buf_bar[0].dstAccessMask;
394  nb_buf_bar = 0;
395  nb_img_bar = 0;
396 
397  /* Setup shader */
398  ff_vk_shader_update_desc_buffer(&ctx->s, exec, &fv->setup,
399  1, 0, 0,
400  slice_state,
401  0, fp->slice_data_size*f->slice_count,
402  VK_FORMAT_UNDEFINED);
403  ff_vk_shader_update_desc_buffer(&ctx->s, exec, &fv->setup,
404  1, 1, 0,
405  slice_offset,
406  0, 2*f->slice_count*sizeof(uint32_t),
407  VK_FORMAT_UNDEFINED);
408  ff_vk_shader_update_desc_buffer(&ctx->s, exec, &fv->setup,
409  1, 2, 0,
410  slice_status,
411  0, 2*f->slice_count*sizeof(uint32_t),
412  VK_FORMAT_UNDEFINED);
413 
414  ff_vk_exec_bind_shader(&ctx->s, exec, &fv->setup);
415  pd = (FFv1VkParameters) {
416  .slice_data = slices_buf->address,
417  .slice_state = slice_state->address + f->slice_count*fp->slice_data_size,
418 
419  .img_size[0] = f->picture.f->width,
420  .img_size[1] = f->picture.f->height,
421  .chroma_shift[0] = f->chroma_h_shift,
422  .chroma_shift[1] = f->chroma_v_shift,
423 
424  .plane_state_size = fp->plane_state_size,
425  .crcref = f->crcref,
426  .rct_offset = 1 << bits,
427 
428  .bits_per_raw_sample = bits,
429  .quant_table_count = f->quant_table_count,
430  .version = f->version,
431  .micro_version = f->micro_version,
432  .key_frame = f->picture.f->flags & AV_FRAME_FLAG_KEY,
433  .planes = av_pix_fmt_count_planes(sw_format),
434  .codec_planes = f->plane_count,
435  .color_planes = color_planes,
436  .transparency = f->transparency,
437  .planar_rgb = ff_vk_mt_is_np_rgb(sw_format) &&
438  (ff_vk_count_images((AVVkFrame *)f->picture.f->data[0]) > 1),
439  .colorspace = f->colorspace,
440  .ec = f->ec,
441  .golomb = f->ac == AC_GOLOMB_RICE,
442  .check_crc = !!(avctx->err_recognition & AV_EF_CRCCHECK),
443  };
444  for (int i = 0; i < f->quant_table_count; i++)
445  pd.extend_lookup[i] = (f->quant_tables[i][3][127] != 0) ||
446  (f->quant_tables[i][4][127] != 0);
447 
448 
449  /* For some reason the C FFv1 encoder/decoder treats these differently */
450  if (sw_format == AV_PIX_FMT_GBRP10 || sw_format == AV_PIX_FMT_GBRP12 ||
451  sw_format == AV_PIX_FMT_GBRP14)
452  memcpy(pd.fmt_lut, (int [4]) { 2, 1, 0, 3 }, 4*sizeof(int));
453  else if (sw_format == AV_PIX_FMT_X2BGR10)
454  memcpy(pd.fmt_lut, (int [4]) { 0, 2, 1, 3 }, 4*sizeof(int));
455  else
456  ff_vk_set_perm(sw_format, pd.fmt_lut, 0);
457 
458  ff_vk_shader_update_push_const(&ctx->s, exec, &fv->setup,
459  VK_SHADER_STAGE_COMPUTE_BIT,
460  0, sizeof(pd), &pd);
461 
462  vk->CmdDispatch(exec->buf, f->num_h_slices, f->num_v_slices, 1);
463 
464  if (is_rgb) {
465  AVVkFrame *vkf = (AVVkFrame *)vp->dpb_frame->data[0];
466  for (int i = 0; i < color_planes; i++)
467  vk->CmdClearColorImage(exec->buf, vkf->img[i], VK_IMAGE_LAYOUT_GENERAL,
468  &((VkClearColorValue) { 0 }),
469  1, &((VkImageSubresourceRange) {
470  .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
471  .levelCount = 1,
472  .layerCount = 1,
473  }));
474  }
475 
476  /* Reset shader */
477  reset_shader = &fv->reset[f->ac == AC_GOLOMB_RICE];
478  ff_vk_shader_update_desc_buffer(&ctx->s, exec, reset_shader,
479  1, 0, 0,
480  slice_state,
481  0, fp->slice_data_size*f->slice_count,
482  VK_FORMAT_UNDEFINED);
483 
484  ff_vk_exec_bind_shader(&ctx->s, exec, reset_shader);
485 
486  pd_reset = (FFv1VkResetParameters) {
487  .slice_state = slice_state->address + f->slice_count*fp->slice_data_size,
488  .plane_state_size = fp->plane_state_size,
489  .codec_planes = f->plane_count,
490  .key_frame = f->picture.f->flags & AV_FRAME_FLAG_KEY,
491  .version = f->version,
492  .micro_version = f->micro_version,
493  };
494  for (int i = 0; i < f->quant_table_count; i++)
495  pd_reset.context_count[i] = f->context_count[i];
496 
497  ff_vk_shader_update_push_const(&ctx->s, exec, reset_shader,
498  VK_SHADER_STAGE_COMPUTE_BIT,
499  0, sizeof(pd_reset), &pd_reset);
500 
501  /* Sync between setup and reset shaders */
502  buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
503  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
504  .srcStageMask = slice_state->stage,
505  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
506  .srcAccessMask = slice_state->access,
507  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT,
508  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
509  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
510  .buffer = slice_state->buf,
511  .offset = 0,
512  .size = fp->slice_data_size*f->slice_count,
513  };
514  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
515  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
516  .pImageMemoryBarriers = img_bar,
517  .imageMemoryBarrierCount = nb_img_bar,
518  .pBufferMemoryBarriers = buf_bar,
519  .bufferMemoryBarrierCount = nb_buf_bar,
520  });
521  slice_state->stage = buf_bar[0].dstStageMask;
522  slice_state->access = buf_bar[0].dstAccessMask;
523  nb_buf_bar = 0;
524  nb_img_bar = 0;
525 
526  vk->CmdDispatch(exec->buf, f->num_h_slices, f->num_v_slices,
527  f->plane_count);
528 
529  /* Decode */
530  decode_shader = &fv->decode[f->use32bit][f->ac == AC_GOLOMB_RICE][is_rgb];
531  ff_vk_shader_update_desc_buffer(&ctx->s, exec, decode_shader,
532  1, 0, 0,
533  slice_state,
534  0, fp->slice_data_size*f->slice_count,
535  VK_FORMAT_UNDEFINED);
536  ff_vk_shader_update_img_array(&ctx->s, exec, decode_shader,
537  decode_dst, decode_dst_view,
538  1, 1,
539  VK_IMAGE_LAYOUT_GENERAL,
540  VK_NULL_HANDLE);
541  ff_vk_shader_update_desc_buffer(&ctx->s, exec, decode_shader,
542  1, 2, 0,
543  slice_status,
544  0, 2*f->slice_count*sizeof(uint32_t),
545  VK_FORMAT_UNDEFINED);
546  if (is_rgb)
547  ff_vk_shader_update_img_array(&ctx->s, exec, decode_shader,
548  f->picture.f, vp->view.out,
549  1, 3,
550  VK_IMAGE_LAYOUT_GENERAL,
551  VK_NULL_HANDLE);
552 
553  ff_vk_exec_bind_shader(&ctx->s, exec, decode_shader);
554  ff_vk_shader_update_push_const(&ctx->s, exec, decode_shader,
555  VK_SHADER_STAGE_COMPUTE_BIT,
556  0, sizeof(pd), &pd);
557 
558  /* Sync between reset and decode shaders */
559  buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
560  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
561  .srcStageMask = slice_state->stage,
562  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
563  .srcAccessMask = slice_state->access,
564  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
565  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
566  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
567  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
568  .buffer = slice_state->buf,
569  .offset = fp->slice_data_size*f->slice_count,
570  .size = f->slice_count*(fp->slice_state_size - fp->slice_data_size),
571  };
572 
573  /* Input frame barrier */
574  ff_vk_frame_barrier(&ctx->s, exec, f->picture.f, img_bar, &nb_img_bar,
575  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
576  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
577  VK_ACCESS_SHADER_WRITE_BIT |
578  (!is_rgb ? VK_ACCESS_SHADER_READ_BIT : 0),
579  VK_IMAGE_LAYOUT_GENERAL,
580  VK_QUEUE_FAMILY_IGNORED);
581  if (is_rgb)
582  ff_vk_frame_barrier(&ctx->s, exec, vp->dpb_frame, img_bar, &nb_img_bar,
583  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
584  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
585  VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
586  VK_IMAGE_LAYOUT_GENERAL,
587  VK_QUEUE_FAMILY_IGNORED);
588 
589  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
590  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
591  .pImageMemoryBarriers = img_bar,
592  .imageMemoryBarrierCount = nb_img_bar,
593  .pBufferMemoryBarriers = buf_bar,
594  .bufferMemoryBarrierCount = nb_buf_bar,
595  });
596  slice_state->stage = buf_bar[0].dstStageMask;
597  slice_state->access = buf_bar[0].dstAccessMask;
598  nb_img_bar = 0;
599  nb_buf_bar = 0;
600 
601  vk->CmdDispatch(exec->buf, f->num_h_slices, f->num_v_slices, 1);
602 
603  err = ff_vk_exec_submit(&ctx->s, exec);
604  if (err < 0)
605  return err;
606 
607  /* We don't need the temporary frame after decoding */
608  av_frame_free(&vp->dpb_frame);
609 
610 fail:
611  return 0;
612 }
613 
614 static void define_shared_code(FFVulkanShader *shd, int use32bit)
615 {
616  int smp_bits = use32bit ? 32 : 16;
617 
618  GLSLC(0, #define DECODE );
619 
620  av_bprintf(&shd->src, "#define RGB_LINECACHE %i\n" ,RGB_LINECACHE);
621  av_bprintf(&shd->src, "#define CONTEXT_SIZE %i\n" ,CONTEXT_SIZE);
622  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_MASK 0x%x\n" ,MAX_QUANT_TABLE_MASK);
623 
624  GLSLF(0, #define TYPE int%i_t ,smp_bits);
625  GLSLF(0, #define VTYPE2 i%ivec2 ,smp_bits);
626  GLSLF(0, #define VTYPE3 i%ivec3 ,smp_bits);
629 }
630 
632  FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
633  FFVulkanShader *shd)
634 {
635  int err;
637 
638  uint8_t *spv_data;
639  size_t spv_len;
640  void *spv_opaque = NULL;
641 
642  RET(ff_vk_shader_init(s, shd, "ffv1_dec_setup",
643  VK_SHADER_STAGE_COMPUTE_BIT,
644  (const char *[]) { "GL_EXT_buffer_reference",
645  "GL_EXT_buffer_reference2" }, 2,
646  1, 1, 1,
647  0));
648 
649  /* Common codec header */
651 
652  add_push_data(shd);
653 
654  av_bprintf(&shd->src, "#define MAX_QUANT_TABLES %i\n", MAX_QUANT_TABLES);
655  av_bprintf(&shd->src, "#define MAX_CONTEXT_INPUTS %i\n", MAX_CONTEXT_INPUTS);
656  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_SIZE %i\n", MAX_QUANT_TABLE_SIZE);
657 
658  desc_set = (FFVulkanDescriptorSetBinding []) {
659  {
660  .name = "rangecoder_static_buf",
661  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
662  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
663  .mem_layout = "scalar",
664  .buf_content = "uint8_t zero_one_state[512];",
665  },
666  {
667  .name = "crc_ieee_buf",
668  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
669  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
670  .mem_layout = "scalar",
671  .buf_content = "uint32_t crc_ieee[256];",
672  },
673  {
674  .name = "quant_buf",
675  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
676  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
677  .mem_layout = "scalar",
678  .buf_content = "int16_t quant_table[MAX_QUANT_TABLES]"
679  "[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];",
680  },
681  };
682 
683  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3, 1, 0));
684 
685  define_shared_code(shd, 0 /* Irrelevant */);
686 
687  desc_set = (FFVulkanDescriptorSetBinding []) {
688  {
689  .name = "slice_data_buf",
690  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
691  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
692  .buf_content = "SliceContext slice_ctx",
693  .buf_elems = f->max_slice_count,
694  },
695  {
696  .name = "slice_offsets_buf",
697  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
698  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
699  .mem_quali = "readonly",
700  .buf_content = "uint32_t slice_offsets",
701  .buf_elems = 2*f->max_slice_count,
702  },
703  {
704  .name = "slice_status_buf",
705  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
706  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
707  .mem_quali = "writeonly",
708  .buf_content = "uint32_t slice_status",
709  .buf_elems = 2*f->max_slice_count,
710  },
711  };
712  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3, 0, 0));
713 
715 
716  RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, "main",
717  &spv_opaque));
718  RET(ff_vk_shader_link(s, shd, spv_data, spv_len, "main"));
719 
720  RET(ff_vk_shader_register_exec(s, pool, shd));
721 
722 fail:
723  if (spv_opaque)
724  spv->free_shader(spv, &spv_opaque);
725 
726  return err;
727 }
728 
730  FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
731  FFVulkanShader *shd, int ac)
732 {
733  int err;
735 
736  uint8_t *spv_data;
737  size_t spv_len;
738  void *spv_opaque = NULL;
739  int wg_dim = FFMIN(s->props.properties.limits.maxComputeWorkGroupSize[0], 1024);
740 
741  RET(ff_vk_shader_init(s, shd, "ffv1_dec_reset",
742  VK_SHADER_STAGE_COMPUTE_BIT,
743  (const char *[]) { "GL_EXT_buffer_reference",
744  "GL_EXT_buffer_reference2" }, 2,
745  wg_dim, 1, 1,
746  0));
747 
748  if (ac == AC_GOLOMB_RICE)
749  av_bprintf(&shd->src, "#define GOLOMB\n");
750 
751  /* Common codec header */
753 
754  GLSLC(0, layout(push_constant, scalar) uniform pushConstants { );
755  GLSLF(1, uint context_count[%i]; ,MAX_QUANT_TABLES);
756  GLSLC(1, u8buf slice_state; );
757  GLSLC(1, uint plane_state_size; );
758  GLSLC(1, uint8_t codec_planes; );
759  GLSLC(1, uint8_t key_frame; );
760  GLSLC(1, uint8_t version; );
761  GLSLC(1, uint8_t micro_version; );
762  GLSLC(1, uint8_t padding[1]; );
763  GLSLC(0, }; );
765  VK_SHADER_STAGE_COMPUTE_BIT);
766 
767  av_bprintf(&shd->src, "#define MAX_QUANT_TABLES %i\n", MAX_QUANT_TABLES);
768  av_bprintf(&shd->src, "#define MAX_CONTEXT_INPUTS %i\n", MAX_CONTEXT_INPUTS);
769  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_SIZE %i\n", MAX_QUANT_TABLE_SIZE);
770 
771  desc_set = (FFVulkanDescriptorSetBinding []) {
772  {
773  .name = "rangecoder_static_buf",
774  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
775  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
776  .mem_layout = "scalar",
777  .buf_content = "uint8_t zero_one_state[512];",
778  },
779  {
780  .name = "quant_buf",
781  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
782  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
783  .mem_layout = "scalar",
784  .buf_content = "int16_t quant_table[MAX_QUANT_TABLES]"
785  "[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];",
786  },
787  };
788  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 1, 0));
789 
790  define_shared_code(shd, 0 /* Bit depth irrelevant for the reset shader */);
791  if (ac == AC_GOLOMB_RICE)
793 
794  desc_set = (FFVulkanDescriptorSetBinding []) {
795  {
796  .name = "slice_data_buf",
797  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
798  .mem_quali = "readonly",
799  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
800  .buf_content = "SliceContext slice_ctx",
801  .buf_elems = f->max_slice_count,
802  },
803  };
804  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 1, 0, 0));
805 
807 
808  RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, "main",
809  &spv_opaque));
810  RET(ff_vk_shader_link(s, shd, spv_data, spv_len, "main"));
811 
812  RET(ff_vk_shader_register_exec(s, pool, shd));
813 
814 fail:
815  if (spv_opaque)
816  spv->free_shader(spv, &spv_opaque);
817 
818  return err;
819 }
820 
822  FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
823  FFVulkanShader *shd,
824  AVHWFramesContext *dec_frames_ctx,
825  AVHWFramesContext *out_frames_ctx,
826  int use32bit, int ac, int rgb)
827 {
828  int err;
830 
831  uint8_t *spv_data;
832  size_t spv_len;
833  void *spv_opaque = NULL;
834  int use_cached_reader = ac != AC_GOLOMB_RICE &&
835  s->driver_props.driverID == VK_DRIVER_ID_MESA_RADV;
836 
837  RET(ff_vk_shader_init(s, shd, "ffv1_dec",
838  VK_SHADER_STAGE_COMPUTE_BIT,
839  (const char *[]) { "GL_EXT_buffer_reference",
840  "GL_EXT_buffer_reference2" }, 2,
841  use_cached_reader ? CONTEXT_SIZE : 1, 1, 1,
842  0));
843 
844  if (ac == AC_GOLOMB_RICE)
845  av_bprintf(&shd->src, "#define GOLOMB\n");
846 
847  if (rgb)
848  av_bprintf(&shd->src, "#define RGB\n");
849 
850  if (use_cached_reader)
851  av_bprintf(&shd->src, "#define CACHED_SYMBOL_READER 1\n");
852 
853  /* Common codec header */
855 
856  add_push_data(shd);
857 
858  av_bprintf(&shd->src, "#define MAX_QUANT_TABLES %i\n", MAX_QUANT_TABLES);
859  av_bprintf(&shd->src, "#define MAX_CONTEXT_INPUTS %i\n", MAX_CONTEXT_INPUTS);
860  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_SIZE %i\n", MAX_QUANT_TABLE_SIZE);
861 
862  desc_set = (FFVulkanDescriptorSetBinding []) {
863  {
864  .name = "rangecoder_static_buf",
865  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
866  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
867  .mem_layout = "scalar",
868  .buf_content = "uint8_t zero_one_state[512];",
869  },
870  {
871  .name = "quant_buf",
872  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
873  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
874  .mem_layout = "scalar",
875  .buf_content = "int16_t quant_table[MAX_QUANT_TABLES]"
876  "[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];",
877  },
878  };
879 
880  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 1, 0));
881 
882  define_shared_code(shd, use32bit);
883  if (ac == AC_GOLOMB_RICE)
885 
886  desc_set = (FFVulkanDescriptorSetBinding []) {
887  {
888  .name = "slice_data_buf",
889  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
890  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
891  .buf_content = "SliceContext slice_ctx",
892  .buf_elems = f->max_slice_count,
893  },
894  {
895  .name = "dec",
896  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
897  .dimensions = 2,
898  .mem_layout = ff_vk_shader_rep_fmt(dec_frames_ctx->sw_format,
900  .elems = av_pix_fmt_count_planes(dec_frames_ctx->sw_format),
901  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
902  },
903  {
904  .name = "slice_status_buf",
905  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
906  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
907  .mem_quali = "writeonly",
908  .buf_content = "uint32_t slice_status",
909  .buf_elems = 2*f->max_slice_count,
910  },
911  {
912  .name = "dst",
913  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
914  .dimensions = 2,
915  .mem_layout = ff_vk_shader_rep_fmt(out_frames_ctx->sw_format,
917  .mem_quali = "writeonly",
918  .elems = av_pix_fmt_count_planes(out_frames_ctx->sw_format),
919  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
920  },
921  };
922  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3 + rgb, 0, 0));
923 
925 
926  RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, "main",
927  &spv_opaque));
928  RET(ff_vk_shader_link(s, shd, spv_data, spv_len, "main"));
929 
930  RET(ff_vk_shader_register_exec(s, pool, shd));
931 
932 fail:
933  if (spv_opaque)
934  spv->free_shader(spv, &spv_opaque);
935 
936  return err;
937 }
938 
940  AVBufferRef **dst, enum AVPixelFormat sw_format)
941 {
942  int err;
943  AVHWFramesContext *frames_ctx;
944  AVVulkanFramesContext *vk_frames;
945  FFV1Context *f = avctx->priv_data;
946 
947  *dst = av_hwframe_ctx_alloc(s->device_ref);
948  if (!(*dst))
949  return AVERROR(ENOMEM);
950 
951  frames_ctx = (AVHWFramesContext *)((*dst)->data);
952  frames_ctx->format = AV_PIX_FMT_VULKAN;
953  frames_ctx->sw_format = sw_format;
954  frames_ctx->width = s->frames->width;
955  frames_ctx->height = f->num_v_slices*RGB_LINECACHE;
956 
957  vk_frames = frames_ctx->hwctx;
958  vk_frames->tiling = VK_IMAGE_TILING_OPTIMAL;
959  vk_frames->img_flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
960  vk_frames->usage = VK_IMAGE_USAGE_STORAGE_BIT |
961  VK_IMAGE_USAGE_TRANSFER_DST_BIT;
962 
963  err = av_hwframe_ctx_init(*dst);
964  if (err < 0) {
965  av_log(avctx, AV_LOG_ERROR, "Unable to initialize frame pool with format %s: %s\n",
966  av_get_pix_fmt_name(sw_format), av_err2str(err));
968  return err;
969  }
970 
971  return 0;
972 }
973 
975 {
976  FFv1VulkanDecodeContext *fv = ctx->sd_ctx;
977 
978  ff_vk_shader_free(&ctx->s, &fv->setup);
979 
980  for (int i = 0; i < 2; i++) /* 16/32 bit */
982 
983  for (int i = 0; i < 2; i++) /* AC/Golomb */
984  ff_vk_shader_free(&ctx->s, &fv->reset[i]);
985 
986  for (int i = 0; i < 2; i++) /* 16/32 bit */
987  for (int j = 0; j < 2; j++) /* AC/Golomb */
988  for (int k = 0; k < 2; k++) /* Normal/RGB */
989  ff_vk_shader_free(&ctx->s, &fv->decode[i][j][k]);
990 
991  ff_vk_free_buf(&ctx->s, &fv->quant_buf);
993  ff_vk_free_buf(&ctx->s, &fv->crc_tab_buf);
994 
998 }
999 
1001 {
1002  int err;
1003  FFV1Context *f = avctx->priv_data;
1007  FFVkSPIRVCompiler *spv;
1008 
1009  if (f->version < 3 ||
1010  (f->version == 4 && f->micro_version > 3))
1011  return AVERROR(ENOTSUP);
1012 
1013  spv = ff_vk_spirv_init();
1014  if (!spv) {
1015  av_log(avctx, AV_LOG_ERROR, "Unable to initialize SPIR-V compiler!\n");
1016  return AVERROR_EXTERNAL;
1017  }
1018 
1019  err = ff_vk_decode_init(avctx);
1020  if (err < 0)
1021  return err;
1022  ctx = dec->shared_ctx;
1023 
1024  fv = ctx->sd_ctx = av_mallocz(sizeof(*fv));
1025  if (!fv) {
1026  err = AVERROR(ENOMEM);
1027  goto fail;
1028  }
1029 
1030  ctx->sd_ctx_free = &vk_decode_ffv1_uninit;
1031 
1032  /* Intermediate frame pool for RCT */
1033  for (int i = 0; i < 2; i++) { /* 16/32 bit */
1034  err = init_indirect(avctx, &ctx->s, &fv->intermediate_frames_ref[i],
1036  if (err < 0)
1037  return err;
1038  }
1039 
1040  /* Setup shader */
1041  err = init_setup_shader(f, &ctx->s, &ctx->exec_pool, spv, &fv->setup);
1042  if (err < 0)
1043  return err;
1044 
1045  /* Reset shaders */
1046  for (int i = 0; i < 2; i++) { /* AC/Golomb */
1047  err = init_reset_shader(f, &ctx->s, &ctx->exec_pool,
1048  spv, &fv->reset[i], !i ? AC_RANGE_CUSTOM_TAB : 0);
1049  if (err < 0)
1050  return err;
1051  }
1052 
1053  /* Decode shaders */
1054  for (int i = 0; i < 2; i++) { /* 16/32 bit */
1055  for (int j = 0; j < 2; j++) { /* AC/Golomb */
1056  for (int k = 0; k < 2; k++) { /* Normal/RGB */
1057  AVHWFramesContext *dec_frames_ctx;
1058  dec_frames_ctx = k ? (AVHWFramesContext *)fv->intermediate_frames_ref[i]->data :
1060  err = init_decode_shader(f, &ctx->s, &ctx->exec_pool,
1061  spv, &fv->decode[i][j][k],
1062  dec_frames_ctx,
1064  i,
1066  k);
1067  if (err < 0)
1068  return err;
1069  }
1070  }
1071  }
1072 
1073  /* Range coder data */
1075  &fv->rangecoder_static_buf,
1076  f);
1077  if (err < 0)
1078  return err;
1079 
1080  /* Quantization table data */
1082  &fv->quant_buf,
1083  f);
1084  if (err < 0)
1085  return err;
1086 
1087  /* CRC table buffer */
1089  &fv->crc_tab_buf,
1090  f);
1091  if (err < 0)
1092  return err;
1093 
1094  /* Update setup global descriptors */
1095  RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
1096  &fv->setup, 0, 0, 0,
1097  &fv->rangecoder_static_buf,
1098  0, fv->rangecoder_static_buf.size,
1099  VK_FORMAT_UNDEFINED));
1100  RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
1101  &fv->setup, 0, 1, 0,
1102  &fv->crc_tab_buf,
1103  0, fv->crc_tab_buf.size,
1104  VK_FORMAT_UNDEFINED));
1105 
1106  /* Update decode global descriptors */
1107  for (int i = 0; i < 2; i++) { /* 16/32 bit */
1108  for (int j = 0; j < 2; j++) { /* AC/Golomb */
1109  for (int k = 0; k < 2; k++) { /* Normal/RGB */
1110  RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
1111  &fv->decode[i][j][k], 0, 0, 0,
1112  &fv->rangecoder_static_buf,
1113  0, fv->rangecoder_static_buf.size,
1114  VK_FORMAT_UNDEFINED));
1115  RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
1116  &fv->decode[i][j][k], 0, 1, 0,
1117  &fv->quant_buf,
1118  0, fv->quant_buf.size,
1119  VK_FORMAT_UNDEFINED));
1120  }
1121  }
1122  }
1123 
1124 fail:
1125  return err;
1126 }
1127 
1129 {
1130  AVHWDeviceContext *dev_ctx = _hwctx.nc;
1131  AVVulkanDeviceContext *hwctx = dev_ctx->hwctx;
1132 
1134  FFVulkanDecodePicture *vp = &fp->vp;
1135  FFVkBuffer *slice_status = (FFVkBuffer *)fp->slice_status_buf->data;
1136 
1137  ff_vk_decode_free_frame(dev_ctx, vp);
1138 
1139  /* Invalidate slice/output data if needed */
1140  if (!(slice_status->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
1141  VkMappedMemoryRange invalidate_data = {
1142  .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
1143  .memory = slice_status->mem,
1144  .offset = 0,
1145  .size = 2*fp->slice_num*sizeof(uint32_t),
1146  };
1147  vp->invalidate_memory_ranges(hwctx->act_dev,
1148  1, &invalidate_data);
1149  }
1150 
1151  for (int i = 0; i < fp->slice_num; i++) {
1152  uint32_t crc_res = 0;
1153  if (fp->crc_checked)
1154  crc_res = AV_RN32(slice_status->mapped_mem + 2*i*sizeof(uint32_t) + 0);
1155  uint32_t status = AV_RN32(slice_status->mapped_mem + 2*i*sizeof(uint32_t) + 4);
1156  if (status || crc_res)
1157  av_log(dev_ctx, AV_LOG_ERROR, "Slice %i status: 0x%x, CRC 0x%x\n",
1158  i, status, crc_res);
1159  }
1160 
1165 }
1166 
1168  .p.name = "ffv1_vulkan",
1169  .p.type = AVMEDIA_TYPE_VIDEO,
1170  .p.id = AV_CODEC_ID_FFV1,
1171  .p.pix_fmt = AV_PIX_FMT_VULKAN,
1172  .start_frame = &vk_ffv1_start_frame,
1173  .decode_slice = &vk_ffv1_decode_slice,
1174  .end_frame = &vk_ffv1_end_frame,
1175  .free_frame_priv = &vk_ffv1_free_frame_priv,
1176  .frame_priv_data_size = sizeof(FFv1VulkanDecodePicture),
1179  .decode_params = &ff_vk_params_invalidate,
1182  .frame_params = &ff_vk_frame_params,
1183  .priv_data_size = sizeof(FFVulkanDecodeContext),
1185 };
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:86
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:551
FFv1VkResetParameters::context_count
uint32_t context_count[MAX_QUANT_TABLES]
Definition: ffv1_vulkan.h:52
FFv1VkParameters::planes
uint8_t planes
Definition: ffv1enc_vulkan.c:144
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
FFv1VkParameters::extend_lookup
uint8_t extend_lookup[8]
Definition: ffv1enc_vulkan.c:136
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
AV_PIX_FMT_YA8
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:140
ff_source_ffv1_dec_setup_comp
const char * ff_source_ffv1_dec_setup_comp
ff_vk_shader_free
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition: vulkan.c:2862
FFv1VulkanDecodeContext::rangecoder_static_buf
FFVkBuffer rangecoder_static_buf
Definition: vulkan_ffv1.c:68
ff_vk_shader_init
int ff_vk_shader_init(FFVulkanContext *s, FFVulkanShader *shd, const char *name, VkPipelineStageFlags stage, const char *extensions[], int nb_extensions, int lg_x, int lg_y, int lg_z, uint32_t required_subgroup_size)
Initialize a shader object, with a specific set of extensions, type+bind, local group size,...
Definition: vulkan.c:1995
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:205
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3341
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
FFVulkanDecodeContext::shared_ctx
FFVulkanDecodeShared * shared_ctx
Definition: vulkan_decode.h:66
RET
#define RET(x)
Definition: vulkan.h:66
AVRefStructOpaque
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition: refstruct.h:58
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:198
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1398
FFv1VkParameters::slice_data
VkDeviceAddress slice_data
Definition: vulkan_ffv1.c:78
AVRefStructOpaque::nc
void * nc
Definition: refstruct.h:59
av_unused
#define av_unused
Definition: attributes.h:131
FFVulkanDecodePicture::invalidate_memory_ranges
PFN_vkInvalidateMappedMemoryRanges invalidate_memory_ranges
Definition: vulkan_decode.h:117
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
FFv1VulkanDecodeContext::reset
FFVulkanShader reset[2]
Definition: vulkan_ffv1.c:65
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:63
FFv1VkParameters::key_frame
uint8_t key_frame
Definition: ffv1enc_vulkan.c:142
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:333
ff_ffv1_vk_init_quant_table_data
int ff_ffv1_vk_init_quant_table_data(FFVulkanContext *s, FFVkBuffer *vkb, FFV1Context *f)
Definition: ffv1_vulkan.c:72
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
FFv1VkParameters::slice_state
VkDeviceAddress slice_state
Definition: ffv1enc_vulkan.c:122
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:259
FFv1VulkanDecodePicture::slice_data_size
uint32_t slice_data_size
Definition: vulkan_ffv1.c:51
FFVulkanShader::src
AVBPrint src
Definition: vulkan.h:195
MAX_QUANT_TABLE_SIZE
#define MAX_QUANT_TABLE_SIZE
Definition: ffv1.h:48
ff_source_ffv1_vlc_comp
const char * ff_source_ffv1_vlc_comp
data
const char data[16]
Definition: mxf.c:149
FFVulkanDecodeDescriptor::codec_id
enum AVCodecID codec_id
Definition: vulkan_decode.h:30
FFv1VkResetParameters::slice_state
VkDeviceAddress slice_state
Definition: ffv1_vulkan.h:53
FFVulkanDecodePicture::view
struct FFVulkanDecodePicture::@309 view
FFVkBuffer::address
VkDeviceAddress address
Definition: vulkan.h:92
ff_source_ffv1_common_comp
const char * ff_source_ffv1_common_comp
ff_vk_exec_get
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition: vulkan.c:509
FF_VK_REP_NATIVE
@ FF_VK_REP_NATIVE
Definition: vulkan.h:404
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:218
AC_RANGE_CUSTOM_TAB
#define AC_RANGE_CUSTOM_TAB
Definition: ffv1.h:54
FFv1VkParameters::micro_version
uint8_t micro_version
Definition: ffv1enc_vulkan.c:140
FFv1VkParameters::padding
uint8_t padding[3]
Definition: ffv1enc_vulkan.c:154
FFv1VulkanDecodePicture::slice_status_buf
AVBufferRef * slice_status_buf
Definition: vulkan_ffv1.c:57
FFv1VkParameters::golomb
uint8_t golomb
Definition: vulkan_ffv1.c:102
FFVulkanDecodeContext
Definition: vulkan_decode.h:65
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:741
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:431
FFv1VulkanDecodeContext::slice_state_pool
AVBufferPool * slice_state_pool
Definition: vulkan_ffv1.c:72
FFv1VkParameters::color_planes
uint8_t color_planes
Definition: vulkan_ffv1.c:97
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3381
rgb
Definition: rpzaenc.c:60
MAX_QUANT_TABLE_MASK
#define MAX_QUANT_TABLE_MASK
Definition: ffv1.h:49
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:546
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:302
fail
#define fail()
Definition: checkasm.h:196
FFVulkanDecodePicture::sem_value
uint64_t sem_value
Definition: vulkan_decode.h:97
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:544
init_indirect
static int init_indirect(AVCodecContext *avctx, FFVulkanContext *s, AVBufferRef **dst, enum AVPixelFormat sw_format)
Definition: vulkan_ffv1.c:939
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:2739
AVVulkanFramesContext
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
Definition: hwcontext_vulkan.h:208
FFv1VkParameters::transparency
uint8_t transparency
Definition: ffv1enc_vulkan.c:147
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:2502
init_setup_shader
static int init_setup_shader(FFV1Context *f, FFVulkanContext *s, FFVkExecPool *pool, FFVkSPIRVCompiler *spv, FFVulkanShader *shd)
Definition: vulkan_ffv1.c:631
FFv1VkParameters::plane_state_size
uint32_t plane_state_size
Definition: ffv1enc_vulkan.c:130
ff_vk_host_map_buffer
int ff_vk_host_map_buffer(FFVulkanContext *s, AVBufferRef **dst, uint8_t *src_data, const AVBufferRef *src_buf, VkBufferUsageFlags usage)
Maps a system RAM buffer into a Vulkan buffer.
Definition: vulkan.c:1313
ff_vk_shader_add_descriptor_set
int ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a shader.
Definition: vulkan.c:2367
CONTEXT_SIZE
#define CONTEXT_SIZE
Definition: ffv1.h:45
add_push_data
static void add_push_data(FFVulkanShader *shd)
Definition: vulkan_ffv1.c:107
FFVulkanDecodeShared
Definition: vulkan_decode.h:47
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:61
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:51
GLSLC
#define GLSLC(N, S)
Definition: vulkan.h:43
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FFv1VulkanDecodeContext::slice_status_pool
AVBufferPool * slice_status_pool
Definition: vulkan_ffv1.c:74
AVHWFramesContext::height
int height
Definition: hwcontext.h:218
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:625
FFv1VkParameters::codec_planes
uint8_t codec_planes
Definition: ffv1enc_vulkan.c:145
define_shared_code
static void define_shared_code(FFVulkanShader *shd, int use32bit)
Definition: vulkan_ffv1.c:614
s
#define s(width, name)
Definition: cbs_vp9.c:198
FFVulkanDecodePicture
Definition: vulkan_decode.h:85
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:840
FFv1VulkanDecodeContext
Definition: vulkan_ffv1.c:61
FFv1VkParameters::bits_per_raw_sample
uint8_t bits_per_raw_sample
Definition: ffv1enc_vulkan.c:137
ff_vk_set_perm
void ff_vk_set_perm(enum AVPixelFormat pix_fmt, int lut[4], int inv)
Since storage images may not be swizzled, we have to do this in the shader itself.
Definition: vulkan.c:1502
bits
uint8_t bits
Definition: vp3data.h:128
AVVulkanFramesContext::img_flags
VkImageCreateFlags img_flags
Flags to set during image creation.
Definition: hwcontext_vulkan.h:260
AV_PIX_FMT_GBRAP32
#define AV_PIX_FMT_GBRAP32
Definition: pixfmt.h:552
ctx
AVFormatContext * ctx
Definition: movenc.c:49
FFv1VulkanDecodePicture::vp
FFVulkanDecodePicture vp
Definition: vulkan_ffv1.c:46
vk_ffv1_decode_slice
static int vk_ffv1_decode_slice(AVCodecContext *avctx, const uint8_t *data, uint32_t size)
Definition: vulkan_ffv1.c:251
FFv1VulkanDecodePicture
Definition: vulkan_ffv1.c:45
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:581
GLSLD
#define GLSLD(D)
Definition: vulkan.h:58
FFv1VkParameters::crcref
uint32_t crcref
Definition: ffv1enc_vulkan.c:132
vk_decode_ffv1_uninit
static void vk_decode_ffv1_uninit(FFVulkanDecodeShared *ctx)
Definition: vulkan_ffv1.c:974
init_reset_shader
static int init_reset_shader(FFV1Context *f, FFVulkanContext *s, FFVkExecPool *pool, FFVkSPIRVCompiler *spv, FFVulkanShader *shd, int ac)
Definition: vulkan_ffv1.c:729
FFv1VulkanDecodePicture::slice_state
AVBufferRef * slice_state
Definition: vulkan_ffv1.c:48
FFv1VulkanDecodePicture::plane_state_size
uint32_t plane_state_size
Definition: vulkan_ffv1.c:49
ff_vk_exec_add_dep_wait_sem
int ff_vk_exec_add_dep_wait_sem(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore sem, uint64_t val, VkPipelineStageFlagBits2 stage)
Definition: vulkan.c:658
FFv1VkParameters::chroma_shift
uint32_t chroma_shift[2]
Definition: ffv1enc_vulkan.c:128
AVVulkanDeviceContext
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_vulkan.h:59
TYPE
#define TYPE
Definition: ffv1dec.c:91
HWACCEL_CAP_ASYNC_SAFE
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
Definition: hwaccel_internal.h:31
ff_vk_shader_rep_fmt
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt, enum FFVkShaderRepFormat rep_fmt)
Definition: vulkan.c:1540
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:211
AC_GOLOMB_RICE
#define AC_GOLOMB_RICE
Definition: ffv1.h:52
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
AVPixFmtDescriptor::nb_components
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
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:575
ff_source_rangecoder_comp
const char * ff_source_rangecoder_comp
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:466
FFv1VkParameters::version
uint8_t version
Definition: ffv1enc_vulkan.c:139
vk_ffv1_end_frame
static int vk_ffv1_end_frame(AVCodecContext *avctx)
Definition: vulkan_ffv1.c:286
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:360
av_buffer_pool_uninit
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:328
ff_vk_decode_uninit
int ff_vk_decode_uninit(AVCodecContext *avctx)
Free decoder.
Definition: vulkan_decode.c:1133
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:370
FFVkBuffer::size
size_t size
Definition: vulkan.h:91
AVVulkanFramesContext::usage
VkImageUsageFlagBits usage
Defines extra usage of output frames.
Definition: hwcontext_vulkan.h:227
ff_source_ffv1_dec_comp
const char * ff_source_ffv1_dec_comp
ffv1_vulkan.h
FFVkBuffer::mapped_mem
uint8_t * mapped_mem
Definition: vulkan.h:100
FFv1VulkanDecodeContext::slice_offset_pool
AVBufferPool * slice_offset_pool
Definition: vulkan_ffv1.c:73
FFVulkanContext
Definition: vulkan.h:274
FFv1VulkanDecodeContext::quant_buf
FFVkBuffer quant_buf
Definition: vulkan_ffv1.c:69
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:1017
AV_EF_CRCCHECK
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
Definition: defs.h:48
FFv1VkParameters::planar_rgb
uint8_t planar_rgb
Definition: ffv1enc_vulkan.c:146
AV_PIX_FMT_X2BGR10
#define AV_PIX_FMT_X2BGR10
Definition: pixfmt.h:597
FFv1VulkanDecodeContext::crc_tab_buf
FFVkBuffer crc_tab_buf
Definition: vulkan_ffv1.c:70
AV_CODEC_ID_FFV1
@ AV_CODEC_ID_FFV1
Definition: codec_id.h:85
f
f
Definition: af_crystalizer.c:122
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
FFv1VkParameters::fmt_lut
int32_t fmt_lut[4]
Definition: ffv1enc_vulkan.c:126
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:2818
FFVulkanDescriptorSetBinding
Definition: vulkan.h:74
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
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
AVVkFrame
Definition: hwcontext_vulkan.h:297
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
vk_ffv1_free_frame_priv
static void vk_ffv1_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
Definition: vulkan_ffv1.c:1128
size
int size
Definition: twinvq_data.h:10344
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:411
FFv1VkParameters::quant_table_count
uint8_t quant_table_count
Definition: vulkan_ffv1.c:91
FF_VK_EXT_PUSH_DESCRIPTOR
#define FF_VK_EXT_PUSH_DESCRIPTOR
Definition: vulkan_functions.h:48
FFVulkanShader
Definition: vulkan.h:190
ff_source_ffv1_reset_comp
const char * ff_source_ffv1_reset_comp
ff_ffv1_vk_init_crc_table_data
int ff_ffv1_vk_init_crc_table_data(FFVulkanContext *s, FFVkBuffer *vkb, FFV1Context *f)
Definition: ffv1_vulkan.c:100
DECODE
#define DECODE(size, endian, src, dst, n, shift, offset)
Read PCM samples macro.
Definition: pcm.c:360
FFVkBuffer::flags
VkMemoryPropertyFlagBits flags
Definition: vulkan.h:90
FFVkSPIRVCompiler::compile_shader
int(* compile_shader)(FFVulkanContext *s, struct FFVkSPIRVCompiler *ctx, FFVulkanShader *shd, uint8_t **data, size_t *size, const char *entrypoint, void **opaque)
Definition: vulkan_spirv.h:28
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
FFVkExecContext
Definition: vulkan.h:111
init_decode_shader
static int init_decode_shader(FFV1Context *f, FFVulkanContext *s, FFVkExecPool *pool, FFVkSPIRVCompiler *spv, FFVulkanShader *shd, AVHWFramesContext *dec_frames_ctx, AVHWFramesContext *out_frames_ctx, int use32bit, int ac, int rgb)
Definition: vulkan_ffv1.c:821
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:2752
FFVulkanDescriptorSetBinding::name
const char * name
Definition: vulkan.h:75
version
version
Definition: libkvazaar.c:315
ff_vk_mt_is_np_rgb
int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
Returns 1 if pixfmt is a usable RGB format.
Definition: vulkan.c:1480
FFv1VulkanDecodeContext::intermediate_frames_ref
AVBufferRef * intermediate_frames_ref[2]
Definition: vulkan_ffv1.c:62
FFVkSPIRVCompiler
Definition: vulkan_spirv.h:26
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:1942
layout
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
Definition: filter_design.txt:18
FF_VK_EXT_EXTERNAL_HOST_MEMORY
#define FF_VK_EXT_EXTERNAL_HOST_MEMORY
Definition: vulkan_functions.h:36
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
FFVulkanDecodePicture::out
VkImageView out[AV_NUM_DATA_POINTERS]
Definition: vulkan_decode.h:90
ff_vk_exec_start
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition: vulkan.c:521
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
FFv1VulkanDecodePicture::slice_state_size
uint32_t slice_state_size
Definition: vulkan_ffv1.c:50
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:545
ff_vk_frame_barrier
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e, AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar, VkPipelineStageFlags src_stage, VkPipelineStageFlags dst_stage, VkAccessFlagBits new_access, VkImageLayout new_layout, uint32_t new_qf)
Definition: vulkan.c:1952
planes
static const struct @500 planes[]
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_vk_shader_link
int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, uint8_t *spirv, size_t spirv_len, const char *entrypoint)
Link a shader into an executable.
Definition: vulkan.c:2292
ffv1.h
FFVkBuffer::mem
VkDeviceMemory mem
Definition: vulkan.h:89
FFVulkanDecodePicture::sem
VkSemaphore sem
Definition: vulkan_decode.h:96
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
vulkan_spirv.h
ff_vk_free_buf
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
Definition: vulkan.c:1164
MAX_CONTEXT_INPUTS
#define MAX_CONTEXT_INPUTS
Definition: ffv1.h:50
FFVkSPIRVCompiler::free_shader
void(* free_shader)(struct FFVkSPIRVCompiler *ctx, void **opaque)
Definition: vulkan_spirv.h:31
ff_vk_exec_bind_shader
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd)
Bind a shader.
Definition: vulkan.c:2828
AVCodecContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition: avcodec.h:1453
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:116
ff_vk_decode_flush
void ff_vk_decode_flush(AVCodecContext *avctx)
Flush decoder.
Definition: vulkan_decode.c:333
ff_ffv1_vulkan_hwaccel
const FFHWAccel ff_ffv1_vulkan_hwaccel
Definition: vulkan_ffv1.c:1167
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:1869
AVHWFramesContext::hwctx
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:151
FFVkExecPool
Definition: vulkan.h:252
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:252
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:99
ff_vk_shader_add_push_const
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
Definition: vulkan.c:1410
FFVkExecContext::buf
VkCommandBuffer buf
Definition: vulkan.h:122
AVCodecContext
main external API structure.
Definition: avcodec.h:431
status
ov_status_e status
Definition: dnn_backend_openvino.c:100
ff_ffv1_vk_init_state_transition_data
int ff_ffv1_vk_init_state_transition_data(FFVulkanContext *s, FFVkBuffer *vkb, FFV1Context *f)
Definition: ffv1_vulkan.c:65
FFv1VkParameters::img_size
uint32_t img_size[2]
Definition: vulkan_ffv1.c:82
ff_vk_dec_ffv1_desc
const FFVulkanDecodeDescriptor ff_vk_dec_ffv1_desc
Definition: vulkan_ffv1.c:39
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
FFv1VkParameters::rct_offset
int rct_offset
Definition: ffv1enc_vulkan.c:134
GLSLF
#define GLSLF(N, S,...)
Definition: vulkan.h:53
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
FFVulkanDecodeDescriptor
Definition: vulkan_decode.h:29
FFv1VulkanDecodePicture::slice_offset
uint32_t * slice_offset
Definition: vulkan_ffv1.c:54
ff_vk_params_invalidate
int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s)
Removes current session parameters to recreate them.
Definition: vulkan_decode.c:110
FFv1VulkanDecodeContext::decode
FFVulkanShader decode[2][2][2]
Definition: vulkan_ffv1.c:66
FFVulkanDecodePicture::dpb_frame
AVFrame * dpb_frame
Definition: vulkan_decode.h:86
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:91
AVVulkanFramesContext::tiling
VkImageTiling tiling
Controls the tiling of allocated frames.
Definition: hwcontext_vulkan.h:217
FFv1VkResetParameters
Definition: ffv1_vulkan.h:51
FFv1VkParameters::colorspace
uint8_t colorspace
Definition: ffv1enc_vulkan.c:148
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFVulkanDecodePicture::slices_buf
AVBufferRef * slices_buf
Definition: vulkan_decode.h:111
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
MAX_QUANT_TABLES
#define MAX_QUANT_TABLES
Definition: ffv1.h:47
AVVulkanDeviceContext::act_dev
VkDevice act_dev
Active device.
Definition: hwcontext_vulkan.h:84
vulkan_decode.h
FFV1Context
Definition: ffv1.h:122
ff_vk_count_images
static int ff_vk_count_images(AVVkFrame *f)
Definition: vulkan.h:321
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
FFv1VulkanDecodeContext::setup
FFVulkanShader setup
Definition: vulkan_ffv1.c:64
FFVkBuffer
Definition: vulkan.h:87
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:866
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_vk_decode_init
int ff_vk_decode_init(AVCodecContext *avctx)
Initialize decoder.
Definition: vulkan_decode.c:1182
FFv1VkParameters
Definition: ffv1enc_vulkan.c:121
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:638
FFv1VulkanDecodePicture::slice_offset_buf
AVBufferRef * slice_offset_buf
Definition: vulkan_ffv1.c:53
FFv1VulkanDecodePicture::crc_checked
int crc_checked
Definition: vulkan_ffv1.c:58
RGB_LINECACHE
#define RGB_LINECACHE
Definition: vulkan_ffv1.c:29
av_hwframe_get_buffer
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:502
FFv1VkParameters::check_crc
uint8_t check_crc
Definition: vulkan_ffv1.c:103
FFVulkanFunctions
Definition: vulkan_functions.h:268
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:1206
ff_source_common_comp
const char * ff_source_common_comp
vk_ffv1_start_frame
static int vk_ffv1_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition: vulkan_ffv1.c:142
vk_decode_ffv1_init
static int vk_decode_ffv1_init(AVCodecContext *avctx)
Definition: vulkan_ffv1.c:1000
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:3261
FFv1VkParameters::ec
uint8_t ec
Definition: ffv1enc_vulkan.c:150
FFv1VulkanDecodePicture::slice_num
int slice_num
Definition: vulkan_ffv1.c:55