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 extern const char *ff_source_common_comp;
30 extern const char *ff_source_rangecoder_comp;
31 extern const char *ff_source_ffv1_vlc_comp;
32 extern const char *ff_source_ffv1_common_comp;
33 extern const char *ff_source_ffv1_dec_setup_comp;
34 extern const char *ff_source_ffv1_reset_comp;
35 extern const char *ff_source_ffv1_dec_comp;
36 extern const char *ff_source_ffv1_dec_rct_comp;
37 
40  .decode_extension = FF_VK_EXT_PUSH_DESCRIPTOR,
41  .queue_flags = VK_QUEUE_COMPUTE_BIT,
42 };
43 
44 #define HOST_MAP
45 
46 typedef struct FFv1VulkanDecodePicture {
48 
50 
52  uint32_t plane_state_size;
53  uint32_t slice_state_size;
54  uint32_t slice_data_size;
56 
58  uint32_t *slice_offset;
59  int slice_num;
60 
64 
65 typedef struct FFv1VulkanDecodeContext {
66  AVBufferRef *intermediate_frames_ref[2]; /* 16/32 bit */
67 
69  FFVulkanShader reset[2]; /* AC/Golomb */
70  FFVulkanShader decode[2][2][2]; /* 16/32 bit, AC/Golomb, Normal/RGB */
71  FFVulkanShader rct[2]; /* 16/32 bit */
72 
76 
82 
83 typedef struct FFv1VkParameters {
85 
86  VkDeviceAddress slice_data;
87  VkDeviceAddress slice_state;
88  VkDeviceAddress scratch_data;
89 
90  uint32_t img_size[2];
91  uint32_t chroma_shift[2];
92 
93  uint32_t plane_state_size;
94  uint32_t crcref;
95 
96  uint8_t bits_per_raw_sample;
98  uint8_t version;
99  uint8_t micro_version;
100  uint8_t key_frame;
101  uint8_t planes;
102  uint8_t codec_planes;
103  uint8_t color_planes;
104  uint8_t transparency;
105  uint8_t colorspace;
106  uint8_t ec;
107  uint8_t golomb;
108  uint8_t check_crc;
109  uint8_t padding[3];
111 
112 static void add_push_data(FFVulkanShader *shd)
113 {
114  GLSLC(0, layout(push_constant, scalar) uniform pushConstants { );
115  GLSLF(1, uint context_count[%i]; ,MAX_QUANT_TABLES);
116  GLSLC(0, );
117  GLSLC(1, u8buf slice_data; );
118  GLSLC(1, u8buf slice_state; );
119  GLSLC(1, u8buf scratch_data; );
120  GLSLC(0, );
121  GLSLC(1, uvec2 img_size; );
122  GLSLC(1, uvec2 chroma_shift; );
123  GLSLC(0, );
124  GLSLC(1, uint plane_state_size; );
125  GLSLC(1, uint32_t crcref; );
126  GLSLC(0, );
127  GLSLC(1, uint8_t bits_per_raw_sample; );
128  GLSLC(1, uint8_t quant_table_count; );
129  GLSLC(1, uint8_t version; );
130  GLSLC(1, uint8_t micro_version; );
131  GLSLC(1, uint8_t key_frame; );
132  GLSLC(1, uint8_t planes; );
133  GLSLC(1, uint8_t codec_planes; );
134  GLSLC(1, uint8_t color_planes; );
135  GLSLC(1, uint8_t transparency; );
136  GLSLC(1, uint8_t colorspace; );
137  GLSLC(1, uint8_t ec; );
138  GLSLC(1, uint8_t golomb; );
139  GLSLC(1, uint8_t check_crc; );
140  GLSLC(1, uint8_t padding[3]; );
141  GLSLC(0, }; );
143  VK_SHADER_STAGE_COMPUTE_BIT);
144 }
145 
147  const AVBufferRef *buffer_ref,
148  av_unused const uint8_t *buffer,
149  av_unused uint32_t size)
150 {
151  int err;
154  FFv1VulkanDecodeContext *fv = ctx->sd_ctx;
155  FFV1Context *f = avctx->priv_data;
156 
157  FFv1VulkanDecodePicture *fp = f->hwaccel_picture_private;
158  FFVulkanDecodePicture *vp = &fp->vp;
159 
161  enum AVPixelFormat sw_format = hwfc->sw_format;
162 
163  int is_rgb = !(f->colorspace == 0 && sw_format != AV_PIX_FMT_YA8) &&
164  !(sw_format == AV_PIX_FMT_YA8);
165 
166  fp->slice_num = 0;
167 
168  for (int i = 0; i < f->quant_table_count; i++)
169  fp->max_context_count = FFMAX(f->context_count[i], fp->max_context_count);
170 
171  /* Allocate slice buffer data */
172  if (f->ac == AC_GOLOMB_RICE)
173  fp->plane_state_size = 8;
174  else
176 
178  fp->slice_state_size = fp->plane_state_size*f->plane_count;
179 
180  fp->slice_data_size = 256; /* Overestimation for the SliceContext struct */
183 
184  fp->crc_checked = f->ec && (avctx->err_recognition & AV_EF_CRCCHECK);
185 
186  /* Host map the input slices data if supported */
187  if (ctx->s.extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY) {
188  err = ff_vk_host_map_buffer(&ctx->s, &vp->slices_buf, buffer_ref->data,
189  buffer_ref,
190  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
191  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
192  if (err < 0)
193  return err;
194  }
195 
196  /* Allocate slice state data */
197  if (f->picture.f->flags & AV_FRAME_FLAG_KEY) {
199  &fp->slice_state,
200  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
201  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
202  NULL, f->max_slice_count*fp->slice_state_size,
203  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
204  if (err < 0)
205  return err;
206  } else {
207  FFv1VulkanDecodePicture *fpl = f->hwaccel_last_picture_private;
209  if (!fp->slice_state)
210  return AVERROR(ENOMEM);
211  }
212 
213  /* Allocate temporary data buffer */
214  err = ff_vk_get_pooled_buffer(&ctx->s, &fv->tmp_data_pool,
215  &fp->tmp_data,
216  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
217  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
218  NULL, f->max_slice_count*CONTEXT_SIZE,
219  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
220  if (err < 0)
221  return err;
222 
223  /* Allocate slice offsets buffer */
225  &fp->slice_offset_buf,
226  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
227  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
228  NULL, 2*f->max_slice_count*sizeof(uint32_t),
229  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
230  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
231  if (err < 0)
232  return err;
233 
234  /* Allocate slice status buffer */
236  &fp->slice_status_buf,
237  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
238  VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
239  NULL, f->max_slice_count*sizeof(uint32_t),
240  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
241  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
242  if (err < 0)
243  return err;
244 
245  /* Prepare frame to be used */
246  err = ff_vk_decode_prepare_frame_sdr(dec, f->picture.f, vp, 1,
247  FF_VK_REP_NATIVE, 0);
248  if (err < 0)
249  return err;
250 
251  /* Create a temporaty frame for RGB */
252  if (is_rgb) {
253  vp->dpb_frame = av_frame_alloc();
254  if (!vp->dpb_frame)
255  return AVERROR(ENOMEM);
256 
257  err = av_hwframe_get_buffer(fv->intermediate_frames_ref[f->use32bit],
258  vp->dpb_frame, 0);
259  if (err < 0)
260  return err;
261  }
262 
263  return 0;
264 }
265 
267  const uint8_t *data,
268  uint32_t size)
269 {
270  FFV1Context *f = avctx->priv_data;
273 
274  FFv1VulkanDecodePicture *fp = f->hwaccel_picture_private;
275  FFVulkanDecodePicture *vp = &fp->vp;
276 
277  FFVkBuffer *slice_offset = (FFVkBuffer *)fp->slice_offset_buf->data;
278 
279  if (ctx->s.extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY) {
280  FFVkBuffer *slices_buf = (FFVkBuffer *)vp->slices_buf->data;
281  AV_WN32(slice_offset->mapped_mem + (2*fp->slice_num + 0)*sizeof(uint32_t),
282  data - slices_buf->mapped_mem);
283  AV_WN32(slice_offset->mapped_mem + (2*fp->slice_num + 1)*sizeof(uint32_t),
284  size);
285 
286  fp->slice_num++;
287  } else {
288  int err = ff_vk_decode_add_slice(avctx, vp, data, size, 0,
289  &fp->slice_num,
290  (const uint32_t **)&fp->slice_offset);
291  if (err < 0)
292  return err;
293 
294  AV_WN32(slice_offset->mapped_mem + (2*(fp->slice_num - 1) + 0)*sizeof(uint32_t),
295  fp->slice_offset[fp->slice_num - 1]);
296  AV_WN32(slice_offset->mapped_mem + (2*(fp->slice_num - 1) + 1)*sizeof(uint32_t),
297  size);
298  }
299 
300  return 0;
301 }
302 
304 {
305  int err;
308  FFVulkanFunctions *vk = &ctx->s.vkfn;
309 
310  FFV1Context *f = avctx->priv_data;
311  FFv1VulkanDecodeContext *fv = ctx->sd_ctx;
312  FFv1VkParameters pd;
313  FFv1VkResetParameters pd_reset;
314 
316  enum AVPixelFormat sw_format = hwfc->sw_format;
317 
318  int bits = f->avctx->bits_per_raw_sample > 0 ? f->avctx->bits_per_raw_sample : 8;
319  int is_rgb = !(f->colorspace == 0 && sw_format != AV_PIX_FMT_YA8) &&
320  !(sw_format == AV_PIX_FMT_YA8);
321  int color_planes = av_pix_fmt_desc_get(avctx->sw_pix_fmt)->nb_components;
322 
323  FFVulkanShader *reset_shader;
324  FFVulkanShader *decode_shader;
325 
326  FFv1VulkanDecodePicture *fp = f->hwaccel_picture_private;
327  FFVulkanDecodePicture *vp = &fp->vp;
328 
329  FFVkBuffer *slices_buf = (FFVkBuffer *)vp->slices_buf->data;
330  FFVkBuffer *slice_state = (FFVkBuffer *)fp->slice_state->data;
331  FFVkBuffer *slice_offset = (FFVkBuffer *)fp->slice_offset_buf->data;
332  FFVkBuffer *slice_status = (FFVkBuffer *)fp->slice_status_buf->data;
333 
334  FFVkBuffer *tmp_data = (FFVkBuffer *)fp->tmp_data->data;
335  VkImageView rct_image_views[AV_NUM_DATA_POINTERS];
336 
337  AVFrame *decode_dst = is_rgb ? vp->dpb_frame : f->picture.f;
338  VkImageView *decode_dst_view = is_rgb ? rct_image_views : vp->view.out;
339 
340  VkImageMemoryBarrier2 img_bar[37];
341  int nb_img_bar = 0;
342  VkBufferMemoryBarrier2 buf_bar[8];
343  int nb_buf_bar = 0;
344 
345  FFVkExecContext *exec = ff_vk_exec_get(&ctx->s, &ctx->exec_pool);
346  ff_vk_exec_start(&ctx->s, exec);
347 
348  /* Prepare deps */
349  RET(ff_vk_exec_add_dep_frame(&ctx->s, exec, f->picture.f,
350  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
351  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
352 
353  err = ff_vk_exec_mirror_sem_value(&ctx->s, exec, &vp->sem, &vp->sem_value,
354  f->picture.f);
355  if (err < 0)
356  return err;
357 
358  if (is_rgb) {
359  RET(ff_vk_exec_add_dep_frame(&ctx->s, exec, vp->dpb_frame,
360  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
361  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
362  RET(ff_vk_create_imageviews(&ctx->s, exec, rct_image_views,
364  }
365 
366  if (!(f->picture.f->flags & AV_FRAME_FLAG_KEY)) {
367  FFv1VulkanDecodePicture *fpl = f->hwaccel_last_picture_private;
368  FFVulkanDecodePicture *vpl = &fpl->vp;
369 
370  /* Wait on the previous frame */
371  RET(ff_vk_exec_add_dep_wait_sem(&ctx->s, exec, vpl->sem, vpl->sem_value,
372  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT));
373  }
374 
375  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &fp->slice_state, 1, 1));
376  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &fp->slice_status_buf, 1, 1));
377  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &vp->slices_buf, 1, 0));
378  vp->slices_buf = NULL;
379  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &fp->slice_offset_buf, 1, 0));
380  fp->slice_offset_buf = NULL;
381  RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &fp->tmp_data, 1, 0));
382  fp->tmp_data = NULL;
383 
384  /* Entry barrier for the slice state */
385  if (!(f->picture.f->flags & AV_FRAME_FLAG_KEY)) {
386  buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
387  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
388  .srcStageMask = slice_state->stage,
389  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
390  .srcAccessMask = slice_state->access,
391  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
392  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
393  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
394  .buffer = slice_state->buf,
395  .offset = 0,
396  .size = VK_WHOLE_SIZE,
397  };
398  }
399 
400  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
401  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
402  .pBufferMemoryBarriers = buf_bar,
403  .bufferMemoryBarrierCount = nb_buf_bar,
404  });
405  if (nb_buf_bar) {
406  slice_state->stage = buf_bar[1].dstStageMask;
407  slice_state->access = buf_bar[1].dstAccessMask;
408  nb_buf_bar = 0;
409  }
410 
411  /* Setup shader */
412  ff_vk_shader_update_desc_buffer(&ctx->s, exec, &fv->setup,
413  1, 0, 0,
414  slice_state,
415  0, fp->slice_data_size*f->slice_count,
416  VK_FORMAT_UNDEFINED);
417  ff_vk_shader_update_desc_buffer(&ctx->s, exec, &fv->setup,
418  1, 1, 0,
419  slice_offset,
420  0, 2*f->slice_count*sizeof(uint32_t),
421  VK_FORMAT_UNDEFINED);
422  ff_vk_shader_update_desc_buffer(&ctx->s, exec, &fv->setup,
423  1, 2, 0,
424  slice_status,
425  0, f->slice_count*sizeof(uint32_t),
426  VK_FORMAT_UNDEFINED);
427 
428  ff_vk_exec_bind_shader(&ctx->s, exec, &fv->setup);
429  pd = (FFv1VkParameters) {
430  /* context_count */
431 
432  .slice_data = slices_buf->address,
433  .slice_state = slice_state->address + f->slice_count*fp->slice_data_size,
434  .scratch_data = tmp_data->address,
435 
436  .img_size[0] = f->picture.f->width,
437  .img_size[1] = f->picture.f->height,
438  .chroma_shift[0] = f->chroma_h_shift,
439  .chroma_shift[1] = f->chroma_v_shift,
440 
441  .plane_state_size = fp->plane_state_size,
442  .crcref = f->crcref,
443 
444  .bits_per_raw_sample = bits,
445  .quant_table_count = f->quant_table_count,
446  .version = f->version,
447  .micro_version = f->micro_version,
448  .key_frame = f->picture.f->flags & AV_FRAME_FLAG_KEY,
449  .planes = av_pix_fmt_count_planes(sw_format),
450  .codec_planes = f->plane_count,
451  .color_planes = color_planes,
452  .transparency = f->transparency,
453  .colorspace = f->colorspace,
454  .ec = f->ec,
455  .golomb = f->ac == AC_GOLOMB_RICE,
456  .check_crc = !!(avctx->err_recognition & AV_EF_CRCCHECK),
457  };
458  for (int i = 0; i < MAX_QUANT_TABLES; i++)
459  pd.context_count[i] = f->context_count[i];
460 
461  ff_vk_shader_update_push_const(&ctx->s, exec, &fv->setup,
462  VK_SHADER_STAGE_COMPUTE_BIT,
463  0, sizeof(pd), &pd);
464 
465  vk->CmdDispatch(exec->buf, f->num_h_slices, f->num_v_slices, 1);
466 
467  /* Reset shader */
468  reset_shader = &fv->reset[f->ac == AC_GOLOMB_RICE];
469  ff_vk_shader_update_desc_buffer(&ctx->s, exec, reset_shader,
470  1, 0, 0,
471  slice_state,
472  0, fp->slice_data_size*f->slice_count,
473  VK_FORMAT_UNDEFINED);
474 
475  ff_vk_exec_bind_shader(&ctx->s, exec, reset_shader);
476 
477  pd_reset = (FFv1VkResetParameters) {
478  .slice_state = slice_state->address + f->slice_count*fp->slice_data_size,
479  .plane_state_size = fp->plane_state_size,
480  .context_count = fp->max_context_count,
481  .codec_planes = f->plane_count,
482  .key_frame = f->picture.f->flags & AV_FRAME_FLAG_KEY,
483  .version = f->version,
484  .micro_version = f->micro_version,
485  };
486  ff_vk_shader_update_push_const(&ctx->s, exec, reset_shader,
487  VK_SHADER_STAGE_COMPUTE_BIT,
488  0, sizeof(pd_reset), &pd_reset);
489 
490  /* Sync between setup and reset shaders */
491  buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
492  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
493  .srcStageMask = slice_state->stage,
494  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
495  .srcAccessMask = slice_state->access,
496  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
497  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
498  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
499  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
500  .buffer = slice_state->buf,
501  .offset = 0,
502  .size = fp->slice_data_size*f->slice_count,
503  };
504  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
505  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
506  .pBufferMemoryBarriers = buf_bar,
507  .bufferMemoryBarrierCount = nb_buf_bar,
508  });
509  slice_state->stage = buf_bar[0].dstStageMask;
510  slice_state->access = buf_bar[0].dstAccessMask;
511  nb_buf_bar = 0;
512 
513  vk->CmdDispatch(exec->buf, f->num_h_slices, f->num_v_slices,
514  f->plane_count);
515 
516  /* Decode */
517  decode_shader = &fv->decode[f->use32bit][f->ac == AC_GOLOMB_RICE][is_rgb];
518  ff_vk_shader_update_desc_buffer(&ctx->s, exec, decode_shader,
519  1, 0, 0,
520  slice_state,
521  0, fp->slice_data_size*f->slice_count,
522  VK_FORMAT_UNDEFINED);
523  ff_vk_shader_update_img_array(&ctx->s, exec, decode_shader,
524  decode_dst, decode_dst_view,
525  1, 1,
526  VK_IMAGE_LAYOUT_GENERAL,
527  VK_NULL_HANDLE);
528 
529  ff_vk_exec_bind_shader(&ctx->s, exec, decode_shader);
530  ff_vk_shader_update_push_const(&ctx->s, exec, decode_shader,
531  VK_SHADER_STAGE_COMPUTE_BIT,
532  0, sizeof(pd), &pd);
533 
534  /* Sync between reset and decode shaders */
535  buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
536  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
537  .srcStageMask = slice_state->stage,
538  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
539  .srcAccessMask = slice_state->access,
540  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
541  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
542  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
543  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
544  .buffer = slice_state->buf,
545  .offset = fp->slice_data_size*f->slice_count,
546  .size = slice_state->size - fp->slice_data_size*f->slice_count,
547  };
548 
549  /* Input frame barrier */
550  ff_vk_frame_barrier(&ctx->s, exec, decode_dst, img_bar, &nb_img_bar,
551  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
552  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
553  VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
554  VK_IMAGE_LAYOUT_GENERAL,
555  VK_QUEUE_FAMILY_IGNORED);
556 
557  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
558  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
559  .pImageMemoryBarriers = img_bar,
560  .imageMemoryBarrierCount = nb_img_bar,
561  .pBufferMemoryBarriers = buf_bar,
562  .bufferMemoryBarrierCount = nb_buf_bar,
563  });
564  slice_state->stage = buf_bar[0].dstStageMask;
565  slice_state->access = buf_bar[0].dstAccessMask;
566  nb_img_bar = 0;
567  nb_buf_bar = 0;
568 
569  vk->CmdDispatch(exec->buf, f->num_h_slices, f->num_v_slices, 1);
570 
571  /* RCT */
572  if (is_rgb) {
573  FFVulkanShader *rct_shader = &fv->rct[f->use32bit];
574  FFv1VkRCTParameters pd_rct;
575 
576  ff_vk_shader_update_desc_buffer(&ctx->s, exec, rct_shader,
577  1, 0, 0,
578  slice_state,
579  0, fp->slice_data_size*f->slice_count,
580  VK_FORMAT_UNDEFINED);
581  ff_vk_shader_update_img_array(&ctx->s, exec, rct_shader,
582  decode_dst, decode_dst_view,
583  1, 1,
584  VK_IMAGE_LAYOUT_GENERAL,
585  VK_NULL_HANDLE);
586  ff_vk_shader_update_img_array(&ctx->s, exec, rct_shader,
587  f->picture.f, vp->view.out,
588  1, 2,
589  VK_IMAGE_LAYOUT_GENERAL,
590  VK_NULL_HANDLE);
591 
592  ff_vk_exec_bind_shader(&ctx->s, exec, rct_shader);
593 
594  pd_rct = (FFv1VkRCTParameters) {
595  .offset = 1 << bits,
596  .bits = bits,
597  .planar_rgb = ff_vk_mt_is_np_rgb(sw_format) &&
598  (ff_vk_count_images((AVVkFrame *)f->picture.f->data[0]) > 1),
599  .color_planes = color_planes,
600  .transparency = f->transparency,
601  };
602 
603  /* For some reason the C FFv1 encoder/decoder treats these differently */
604  if (sw_format == AV_PIX_FMT_GBRP10 || sw_format == AV_PIX_FMT_GBRP12 ||
605  sw_format == AV_PIX_FMT_GBRP14)
606  memcpy(pd_rct.fmt_lut, (int [4]) { 2, 1, 0, 3 }, 4*sizeof(int));
607  else if (sw_format == AV_PIX_FMT_X2BGR10)
608  memcpy(pd_rct.fmt_lut, (int [4]) { 0, 2, 1, 3 }, 4*sizeof(int));
609  else
610  ff_vk_set_perm(sw_format, pd_rct.fmt_lut, 0);
611 
612  ff_vk_shader_update_push_const(&ctx->s, exec, rct_shader,
613  VK_SHADER_STAGE_COMPUTE_BIT,
614  0, sizeof(pd_rct), &pd_rct);
615 
616  ff_vk_frame_barrier(&ctx->s, exec, decode_dst, img_bar, &nb_img_bar,
617  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
618  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
619  VK_ACCESS_SHADER_READ_BIT,
620  VK_IMAGE_LAYOUT_GENERAL,
621  VK_QUEUE_FAMILY_IGNORED);
622  ff_vk_frame_barrier(&ctx->s, exec, f->picture.f, img_bar, &nb_img_bar,
623  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
624  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
625  VK_ACCESS_SHADER_WRITE_BIT,
626  VK_IMAGE_LAYOUT_GENERAL,
627  VK_QUEUE_FAMILY_IGNORED);
628 
629  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
630  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
631  .pImageMemoryBarriers = img_bar,
632  .imageMemoryBarrierCount = nb_img_bar,
633  });
634  nb_img_bar = 0;
635 
636  vk->CmdDispatch(exec->buf, f->num_h_slices, f->num_v_slices, 1);
637  }
638 
639  err = ff_vk_exec_submit(&ctx->s, exec);
640  if (err < 0)
641  return err;
642 
643  /* We don't need the temporary frame after decoding */
644  av_frame_free(&vp->dpb_frame);
645 
646 fail:
647  return 0;
648 }
649 
650 static void define_shared_code(FFVulkanShader *shd, int use32bit)
651 {
652  int smp_bits = use32bit ? 32 : 16;
653 
654  GLSLC(0, #define DECODE );
655 
656  av_bprintf(&shd->src, "#define CONTEXT_SIZE %i\n" ,CONTEXT_SIZE);
657  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_MASK 0x%x\n" ,MAX_QUANT_TABLE_MASK);
658 
659  GLSLF(0, #define TYPE int%i_t ,smp_bits);
660  GLSLF(0, #define VTYPE2 i%ivec2 ,smp_bits);
661  GLSLF(0, #define VTYPE3 i%ivec3 ,smp_bits);
664 }
665 
667  FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
668  FFVulkanShader *shd)
669 {
670  int err;
672 
673  uint8_t *spv_data;
674  size_t spv_len;
675  void *spv_opaque = NULL;
676 
677  RET(ff_vk_shader_init(s, shd, "ffv1_dec_setup",
678  VK_SHADER_STAGE_COMPUTE_BIT,
679  (const char *[]) { "GL_EXT_buffer_reference",
680  "GL_EXT_buffer_reference2" }, 2,
681  1, 1, 1,
682  0));
683 
684  /* Common codec header */
686 
687  add_push_data(shd);
688 
689  av_bprintf(&shd->src, "#define MAX_QUANT_TABLES %i\n", MAX_QUANT_TABLES);
690  av_bprintf(&shd->src, "#define MAX_CONTEXT_INPUTS %i\n", MAX_CONTEXT_INPUTS);
691  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_SIZE %i\n", MAX_QUANT_TABLE_SIZE);
692 
693  desc_set = (FFVulkanDescriptorSetBinding []) {
694  {
695  .name = "rangecoder_static_buf",
696  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
697  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
698  .mem_layout = "scalar",
699  .buf_content = "uint8_t zero_one_state[512];",
700  },
701  {
702  .name = "crc_ieee_buf",
703  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
704  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
705  .mem_layout = "scalar",
706  .buf_content = "uint32_t crc_ieee[256];",
707  },
708  {
709  .name = "quant_buf",
710  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
711  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
712  .mem_layout = "scalar",
713  .buf_content = "int16_t quant_table[MAX_QUANT_TABLES]"
714  "[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];",
715  },
716  };
717 
718  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3, 1, 0));
719 
720  define_shared_code(shd, 0 /* Irrelevant */);
721 
722  desc_set = (FFVulkanDescriptorSetBinding []) {
723  {
724  .name = "slice_data_buf",
725  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
726  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
727  .buf_content = "SliceContext slice_ctx",
728  .buf_elems = f->max_slice_count,
729  },
730  {
731  .name = "slice_offsets_buf",
732  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
733  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
734  .mem_quali = "readonly",
735  .buf_content = "uint32_t slice_offsets",
736  .buf_elems = 2*f->max_slice_count,
737  },
738  {
739  .name = "slice_status_buf",
740  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
741  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
742  .mem_quali = "writeonly",
743  .buf_content = "uint32_t slice_crc_mismatch",
744  .buf_elems = f->max_slice_count,
745  },
746  };
747  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3, 0, 0));
748 
750 
751  RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, "main",
752  &spv_opaque));
753  RET(ff_vk_shader_link(s, shd, spv_data, spv_len, "main"));
754 
755  RET(ff_vk_shader_register_exec(s, pool, shd));
756 
757 fail:
758  if (spv_opaque)
759  spv->free_shader(spv, &spv_opaque);
760 
761  return err;
762 }
763 
765  FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
766  FFVulkanShader *shd, int ac)
767 {
768  int err;
770 
771  uint8_t *spv_data;
772  size_t spv_len;
773  void *spv_opaque = NULL;
774  int wg_dim = FFMIN(s->props.properties.limits.maxComputeWorkGroupSize[0], 1024);
775 
776  RET(ff_vk_shader_init(s, shd, "ffv1_dec_reset",
777  VK_SHADER_STAGE_COMPUTE_BIT,
778  (const char *[]) { "GL_EXT_buffer_reference",
779  "GL_EXT_buffer_reference2" }, 2,
780  wg_dim, 1, 1,
781  0));
782 
783  if (ac == AC_GOLOMB_RICE)
784  av_bprintf(&shd->src, "#define GOLOMB\n");
785 
786  /* Common codec header */
788 
789  GLSLC(0, layout(push_constant, scalar) uniform pushConstants { );
790  GLSLC(1, u8buf slice_state; );
791  GLSLC(1, uint plane_state_size; );
792  GLSLC(1, uint context_count; );
793  GLSLC(1, uint8_t codec_planes; );
794  GLSLC(1, uint8_t key_frame; );
795  GLSLC(1, uint8_t version; );
796  GLSLC(1, uint8_t micro_version; );
797  GLSLC(1, uint8_t padding[1]; );
798  GLSLC(0, }; );
800  VK_SHADER_STAGE_COMPUTE_BIT);
801 
802  av_bprintf(&shd->src, "#define MAX_QUANT_TABLES %i\n", MAX_QUANT_TABLES);
803  av_bprintf(&shd->src, "#define MAX_CONTEXT_INPUTS %i\n", MAX_CONTEXT_INPUTS);
804  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_SIZE %i\n", MAX_QUANT_TABLE_SIZE);
805 
806  desc_set = (FFVulkanDescriptorSetBinding []) {
807  {
808  .name = "rangecoder_static_buf",
809  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
810  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
811  .mem_layout = "scalar",
812  .buf_content = "uint8_t zero_one_state[512];",
813  },
814  {
815  .name = "quant_buf",
816  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
817  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
818  .mem_layout = "scalar",
819  .buf_content = "int16_t quant_table[MAX_QUANT_TABLES]"
820  "[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];",
821  },
822  };
823  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 1, 0));
824 
825  define_shared_code(shd, 0 /* Bit depth irrelevant for the reset shader */);
826  if (ac == AC_GOLOMB_RICE)
828 
829  desc_set = (FFVulkanDescriptorSetBinding []) {
830  {
831  .name = "slice_data_buf",
832  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
833  .mem_quali = "readonly",
834  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
835  .buf_content = "SliceContext slice_ctx",
836  .buf_elems = f->max_slice_count,
837  },
838  };
839  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 1, 0, 0));
840 
842 
843  RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, "main",
844  &spv_opaque));
845  RET(ff_vk_shader_link(s, shd, spv_data, spv_len, "main"));
846 
847  RET(ff_vk_shader_register_exec(s, pool, shd));
848 
849 fail:
850  if (spv_opaque)
851  spv->free_shader(spv, &spv_opaque);
852 
853  return err;
854 }
855 
857  FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
858  FFVulkanShader *shd, AVHWFramesContext *frames_ctx,
859  int use32bit, int ac, int rgb)
860 {
861  int err;
863 
864  uint8_t *spv_data;
865  size_t spv_len;
866  void *spv_opaque = NULL;
867 
868  RET(ff_vk_shader_init(s, shd, "ffv1_dec",
869  VK_SHADER_STAGE_COMPUTE_BIT,
870  (const char *[]) { "GL_EXT_buffer_reference",
871  "GL_EXT_buffer_reference2" }, 2,
872  1, 1, 1,
873  0));
874 
875  if (ac == AC_GOLOMB_RICE)
876  av_bprintf(&shd->src, "#define GOLOMB\n");
877 
878  if (rgb)
879  av_bprintf(&shd->src, "#define RGB\n");
880 
881  /* Common codec header */
883 
884  add_push_data(shd);
885 
886  av_bprintf(&shd->src, "#define MAX_QUANT_TABLES %i\n", MAX_QUANT_TABLES);
887  av_bprintf(&shd->src, "#define MAX_CONTEXT_INPUTS %i\n", MAX_CONTEXT_INPUTS);
888  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_SIZE %i\n", MAX_QUANT_TABLE_SIZE);
889 
890  desc_set = (FFVulkanDescriptorSetBinding []) {
891  {
892  .name = "rangecoder_static_buf",
893  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
894  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
895  .mem_layout = "scalar",
896  .buf_content = "uint8_t zero_one_state[512];",
897  },
898  {
899  .name = "quant_buf",
900  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
901  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
902  .mem_layout = "scalar",
903  .buf_content = "int16_t quant_table[MAX_QUANT_TABLES]"
904  "[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];",
905  },
906  };
907 
908  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 1, 0));
909 
910  define_shared_code(shd, use32bit);
911  if (ac == AC_GOLOMB_RICE)
913 
914  desc_set = (FFVulkanDescriptorSetBinding []) {
915  {
916  .name = "slice_data_buf",
917  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
918  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
919  .buf_content = "SliceContext slice_ctx",
920  .buf_elems = f->max_slice_count,
921  },
922  {
923  .name = "dst",
924  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
925  .dimensions = 2,
926  .mem_layout = ff_vk_shader_rep_fmt(frames_ctx->sw_format,
928  .elems = av_pix_fmt_count_planes(frames_ctx->sw_format),
929  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
930  },
931  };
932  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 0, 0));
933 
935 
936  RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, "main",
937  &spv_opaque));
938  RET(ff_vk_shader_link(s, shd, spv_data, spv_len, "main"));
939 
940  RET(ff_vk_shader_register_exec(s, pool, shd));
941 
942 fail:
943  if (spv_opaque)
944  spv->free_shader(spv, &spv_opaque);
945 
946  return err;
947 }
948 
950  FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
951  FFVulkanShader *shd, int use32bit,
952  AVHWFramesContext *src_ctx, AVHWFramesContext *dst_ctx)
953 {
954  int err;
956 
957  uint8_t *spv_data;
958  size_t spv_len;
959  void *spv_opaque = NULL;
960  int wg_count = sqrt(s->props.properties.limits.maxComputeWorkGroupInvocations);
961 
962  RET(ff_vk_shader_init(s, shd, "ffv1_rct",
963  VK_SHADER_STAGE_COMPUTE_BIT,
964  (const char *[]) { "GL_EXT_buffer_reference",
965  "GL_EXT_buffer_reference2" }, 2,
966  wg_count, wg_count, 1,
967  0));
968 
969  /* Common codec header */
971 
972  GLSLC(0, layout(push_constant, scalar) uniform pushConstants { );
973  GLSLC(1, ivec4 fmt_lut; );
974  GLSLC(1, int offset; );
975  GLSLC(1, uint8_t bits; );
976  GLSLC(1, uint8_t planar_rgb; );
977  GLSLC(1, uint8_t color_planes; );
978  GLSLC(1, uint8_t transparency; );
979  GLSLC(1, uint8_t version; );
980  GLSLC(1, uint8_t micro_version; );
981  GLSLC(1, uint8_t padding[2]; );
982  GLSLC(0, }; );
984  VK_SHADER_STAGE_COMPUTE_BIT);
985 
986  av_bprintf(&shd->src, "#define MAX_QUANT_TABLES %i\n", MAX_QUANT_TABLES);
987  av_bprintf(&shd->src, "#define MAX_CONTEXT_INPUTS %i\n", MAX_CONTEXT_INPUTS);
988  av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_SIZE %i\n", MAX_QUANT_TABLE_SIZE);
989 
990  desc_set = (FFVulkanDescriptorSetBinding []) {
991  {
992  .name = "rangecoder_static_buf",
993  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
994  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
995  .mem_layout = "scalar",
996  .buf_content = "uint8_t zero_one_state[512];",
997  },
998  {
999  .name = "quant_buf",
1000  .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
1001  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1002  .mem_layout = "scalar",
1003  .buf_content = "int16_t quant_table[MAX_QUANT_TABLES]"
1004  "[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];",
1005  },
1006  };
1007  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 1, 0));
1008 
1009  define_shared_code(shd, use32bit);
1010 
1011  desc_set = (FFVulkanDescriptorSetBinding []) {
1012  {
1013  .name = "slice_data_buf",
1014  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1015  .mem_quali = "readonly",
1016  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1017  .buf_content = "SliceContext slice_ctx",
1018  .buf_elems = f->max_slice_count,
1019  },
1020  {
1021  .name = "src",
1022  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
1023  .dimensions = 2,
1024  .mem_layout = ff_vk_shader_rep_fmt(src_ctx->sw_format,
1026  .mem_quali = "readonly",
1027  .elems = av_pix_fmt_count_planes(src_ctx->sw_format),
1028  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1029  },
1030  {
1031  .name = "dst",
1032  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
1033  .dimensions = 2,
1034  .mem_layout = ff_vk_shader_rep_fmt(dst_ctx->sw_format,
1036  .mem_quali = "writeonly",
1037  .elems = av_pix_fmt_count_planes(dst_ctx->sw_format),
1038  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
1039  },
1040  };
1041  RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3, 0, 0));
1042 
1044 
1045  RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, "main",
1046  &spv_opaque));
1047  RET(ff_vk_shader_link(s, shd, spv_data, spv_len, "main"));
1048 
1049  RET(ff_vk_shader_register_exec(s, pool, shd));
1050 
1051 fail:
1052  if (spv_opaque)
1053  spv->free_shader(spv, &spv_opaque);
1054 
1055  return err;
1056 }
1057 
1059  AVBufferRef **dst, enum AVPixelFormat sw_format)
1060 {
1061  int err;
1062  AVHWFramesContext *frames_ctx;
1063  AVVulkanFramesContext *vk_frames;
1064 
1065  *dst = av_hwframe_ctx_alloc(s->device_ref);
1066  if (!(*dst))
1067  return AVERROR(ENOMEM);
1068 
1069  frames_ctx = (AVHWFramesContext *)((*dst)->data);
1070  frames_ctx->format = AV_PIX_FMT_VULKAN;
1071  frames_ctx->sw_format = sw_format;
1072  frames_ctx->width = FFALIGN(s->frames->width, 32);
1073  frames_ctx->height = FFALIGN(s->frames->height, 32);
1074 
1075  vk_frames = frames_ctx->hwctx;
1076  vk_frames->tiling = VK_IMAGE_TILING_OPTIMAL;
1077  vk_frames->usage = VK_IMAGE_USAGE_STORAGE_BIT;
1078  vk_frames->img_flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
1079 
1080  err = av_hwframe_ctx_init(*dst);
1081  if (err < 0) {
1082  av_log(avctx, AV_LOG_ERROR, "Unable to initialize frame pool with format %s: %s\n",
1083  av_get_pix_fmt_name(sw_format), av_err2str(err));
1085  return err;
1086  }
1087 
1088  return 0;
1089 }
1090 
1092 {
1093  FFv1VulkanDecodeContext *fv = ctx->sd_ctx;
1094 
1095  ff_vk_shader_free(&ctx->s, &fv->setup);
1096 
1097  for (int i = 0; i < 2; i++) /* 16/32 bit */
1099 
1100  for (int i = 0; i < 2; i++) /* AC/Golomb */
1101  ff_vk_shader_free(&ctx->s, &fv->reset[i]);
1102 
1103  for (int i = 0; i < 2; i++) /* 16/32 bit */
1104  for (int j = 0; j < 2; j++) /* AC/Golomb */
1105  for (int k = 0; k < 2; k++) /* Normal/RGB */
1106  ff_vk_shader_free(&ctx->s, &fv->decode[i][j][k]);
1107 
1108  for (int i = 0; i < 2; i++) /* 16/32 bit */
1109  ff_vk_shader_free(&ctx->s, &fv->rct[i]);
1110 
1111  ff_vk_free_buf(&ctx->s, &fv->quant_buf);
1113  ff_vk_free_buf(&ctx->s, &fv->crc_tab_buf);
1114 
1119 }
1120 
1122 {
1123  int err;
1124  FFV1Context *f = avctx->priv_data;
1128  FFVkSPIRVCompiler *spv;
1129 
1130  if (f->version < 3 ||
1131  (f->version == 4 && f->micro_version > 3))
1132  return AVERROR(ENOTSUP);
1133 
1134  spv = ff_vk_spirv_init();
1135  if (!spv) {
1136  av_log(avctx, AV_LOG_ERROR, "Unable to initialize SPIR-V compiler!\n");
1137  return AVERROR_EXTERNAL;
1138  }
1139 
1140  err = ff_vk_decode_init(avctx);
1141  if (err < 0)
1142  return err;
1143  ctx = dec->shared_ctx;
1144 
1145  switch (ctx->s.driver_props.driverID) {
1146  case VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS:
1147  case VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA:
1149  av_log(avctx, AV_LOG_ERROR,
1150  "Intel's drivers are unsupported, use -strict -1 to enable acceleration.\n");
1151  return AVERROR(ENOTSUP);
1152  } else {
1153  av_log(avctx, AV_LOG_WARNING,
1154  "Enabling acceleration on Intel's drivers.\n");
1155  }
1156  break;
1157  };
1158 
1159  fv = ctx->sd_ctx = av_mallocz(sizeof(*fv));
1160  if (!fv) {
1161  err = AVERROR(ENOMEM);
1162  goto fail;
1163  }
1164 
1165  ctx->sd_ctx_free = &vk_decode_ffv1_uninit;
1166 
1167  /* Intermediate frame pool for RCT */
1168  for (int i = 0; i < 2; i++) { /* 16/32 bit */
1169  err = init_indirect(avctx, &ctx->s, &fv->intermediate_frames_ref[i],
1171  if (err < 0)
1172  return err;
1173  }
1174 
1175  /* Setup shader */
1176  err = init_setup_shader(f, &ctx->s, &ctx->exec_pool, spv, &fv->setup);
1177  if (err < 0)
1178  return err;
1179 
1180  /* Reset shaders */
1181  for (int i = 0; i < 2; i++) { /* AC/Golomb */
1182  err = init_reset_shader(f, &ctx->s, &ctx->exec_pool,
1183  spv, &fv->reset[i], !i ? AC_RANGE_CUSTOM_TAB : 0);
1184  if (err < 0)
1185  return err;
1186  }
1187 
1188  /* Decode shaders */
1189  for (int i = 0; i < 2; i++) { /* 16/32 bit */
1190  for (int j = 0; j < 2; j++) { /* AC/Golomb */
1191  for (int k = 0; k < 2; k++) { /* Normal/RGB */
1192  AVHWFramesContext *frames_ctx;
1193  frames_ctx = k ? (AVHWFramesContext *)fv->intermediate_frames_ref[i]->data :
1195  err = init_decode_shader(f, &ctx->s, &ctx->exec_pool,
1196  spv, &fv->decode[i][j][k],
1197  frames_ctx,
1198  i,
1200  k);
1201  if (err < 0)
1202  return err;
1203  }
1204  }
1205  }
1206 
1207  /* RCT shaders */
1208  for (int i = 0; i < 2; i++) { /* 16/32 bit */
1209  err = init_rct_shader(f, &ctx->s, &ctx->exec_pool,
1210  spv, &fv->rct[i], i,
1212  (AVHWFramesContext *)avctx->hw_frames_ctx->data);
1213  if (err < 0)
1214  return err;
1215  }
1216 
1217  /* Range coder data */
1219  &fv->rangecoder_static_buf,
1220  f);
1221  if (err < 0)
1222  return err;
1223 
1224  /* Quantization table data */
1226  &fv->quant_buf,
1227  f);
1228  if (err < 0)
1229  return err;
1230 
1231  /* CRC table buffer */
1233  &fv->crc_tab_buf,
1234  f);
1235  if (err < 0)
1236  return err;
1237 
1238  /* Update setup global descriptors */
1239  RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
1240  &fv->setup, 0, 0, 0,
1241  &fv->rangecoder_static_buf,
1242  0, fv->rangecoder_static_buf.size,
1243  VK_FORMAT_UNDEFINED));
1244  RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
1245  &fv->setup, 0, 1, 0,
1246  &fv->crc_tab_buf,
1247  0, fv->crc_tab_buf.size,
1248  VK_FORMAT_UNDEFINED));
1249 
1250  /* Update decode global descriptors */
1251  for (int i = 0; i < 2; i++) { /* 16/32 bit */
1252  for (int j = 0; j < 2; j++) { /* AC/Golomb */
1253  for (int k = 0; k < 2; k++) { /* Normal/RGB */
1254  RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
1255  &fv->decode[i][j][k], 0, 0, 0,
1256  &fv->rangecoder_static_buf,
1257  0, fv->rangecoder_static_buf.size,
1258  VK_FORMAT_UNDEFINED));
1259  RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
1260  &fv->decode[i][j][k], 0, 1, 0,
1261  &fv->quant_buf,
1262  0, fv->quant_buf.size,
1263  VK_FORMAT_UNDEFINED));
1264  }
1265  }
1266  }
1267 
1268 fail:
1269  return err;
1270 }
1271 
1273 {
1274  AVHWDeviceContext *hwctx = _hwctx.nc;
1275 
1277  FFVulkanDecodePicture *vp = &fp->vp;
1278 
1279  ff_vk_decode_free_frame(hwctx, vp);
1280 
1281  if (fp->crc_checked) {
1282  FFVkBuffer *slice_status = (FFVkBuffer *)fp->slice_status_buf->data;
1283  for (int i = 0; i < fp->slice_num; i++) {
1284  uint32_t crc_res;
1285  crc_res = AV_RN32(slice_status->mapped_mem + i*sizeof(uint32_t));
1286  if (crc_res != 0)
1287  av_log(hwctx, AV_LOG_ERROR, "CRC mismatch in slice %i, res: 0x%x\n",
1288  i, crc_res);
1289  }
1290  }
1291 
1296  av_buffer_unref(&fp->tmp_data);
1297 }
1298 
1300  .p.name = "ffv1_vulkan",
1301  .p.type = AVMEDIA_TYPE_VIDEO,
1302  .p.id = AV_CODEC_ID_FFV1,
1303  .p.pix_fmt = AV_PIX_FMT_VULKAN,
1304  .start_frame = &vk_ffv1_start_frame,
1305  .decode_slice = &vk_ffv1_decode_slice,
1306  .end_frame = &vk_ffv1_end_frame,
1307  .free_frame_priv = &vk_ffv1_free_frame_priv,
1308  .frame_priv_data_size = sizeof(FFv1VulkanDecodePicture),
1311  .decode_params = &ff_vk_params_invalidate,
1314  .frame_params = &ff_vk_frame_params,
1315  .priv_data_size = sizeof(FFVulkanDecodeContext),
1317 };
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:551
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
FFv1VkParameters::planes
uint8_t planes
Definition: ffv1enc_vulkan.c:144
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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:2849
FFv1VulkanDecodeContext::rangecoder_static_buf
FFVkBuffer rangecoder_static_buf
Definition: vulkan_ffv1.c:73
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:1992
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:206
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3341
FFv1VkParameters::scratch_data
VkDeviceAddress scratch_data
Definition: ffv1enc_vulkan.c:127
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:67
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:1438
FFv1VkParameters::slice_data
VkDeviceAddress slice_data
Definition: vulkan_ffv1.c:86
AVRefStructOpaque::nc
void * nc
Definition: refstruct.h:59
av_unused
#define av_unused
Definition: attributes.h:131
FFHWAccel::p
AVHWAccel p
The public AVHWAccel.
Definition: hwaccel_internal.h:38
FFv1VulkanDecodeContext::reset
FFVulkanShader reset[2]
Definition: vulkan_ffv1.c:69
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:70
FFv1VkParameters::key_frame
uint8_t key_frame
Definition: ffv1enc_vulkan.c:143
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:326
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:126
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:252
FFv1VulkanDecodePicture::slice_data_size
uint32_t slice_data_size
Definition: vulkan_ffv1.c:54
FFVulkanShader::src
AVBPrint src
Definition: vulkan.h:197
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:52
FFVkBuffer::address
VkDeviceAddress address
Definition: vulkan.h:93
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:477
FF_VK_REP_NATIVE
@ FF_VK_REP_NATIVE
Definition: vulkan.h:390
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:141
FFv1VulkanDecodePicture::slice_status_buf
AVBufferRef * slice_status_buf
Definition: vulkan_ffv1.c:61
FFv1VkParameters::golomb
uint8_t golomb
Definition: vulkan_ffv1.c:107
FFVulkanDecodeContext
Definition: vulkan_decode.h:65
FFv1VulkanDecodePicture::max_context_count
uint32_t max_context_count
Definition: vulkan_ffv1.c:55
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:706
FFv1VulkanDecodeContext::slice_state_pool
AVBufferPool * slice_state_pool
Definition: vulkan_ffv1.c:77
FFv1VkParameters::color_planes
uint8_t color_planes
Definition: vulkan_ffv1.c:103
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
fail
#define fail()
Definition: checkasm.h:193
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:1058
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:2726
AVVulkanFramesContext
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
Definition: hwcontext_vulkan.h:213
FFv1VkParameters::transparency
uint8_t transparency
Definition: ffv1enc_vulkan.c:146
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:2489
init_setup_shader
static int init_setup_shader(FFV1Context *f, FFVulkanContext *s, FFVkExecPool *pool, FFVkSPIRVCompiler *spv, FFVulkanShader *shd)
Definition: vulkan_ffv1.c:666
FFv1VkParameters::plane_state_size
uint32_t plane_state_size
Definition: ffv1enc_vulkan.c:133
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:1278
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:2356
CONTEXT_SIZE
#define CONTEXT_SIZE
Definition: ffv1.h:45
add_push_data
static void add_push_data(FFVulkanShader *shd)
Definition: vulkan_ffv1.c:112
FFVulkanDecodeShared
Definition: vulkan_decode.h:47
FFv1VkRCTParameters::fmt_lut
int fmt_lut[4]
Definition: ffv1_vulkan.h:40
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:58
FFv1VulkanDecodeContext::tmp_data_pool
AVBufferPool * tmp_data_pool
Definition: vulkan_ffv1.c:78
GLSLC
#define GLSLC(N, S)
Definition: vulkan.h:44
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FFv1VulkanDecodeContext::slice_status_pool
AVBufferPool * slice_status_pool
Definition: vulkan_ffv1.c:80
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:661
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:650
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:805
FFv1VulkanDecodeContext
Definition: vulkan_ffv1.c:65
FFv1VkParameters::bits_per_raw_sample
uint8_t bits_per_raw_sample
Definition: ffv1enc_vulkan.c:138
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:1466
bits
uint8_t bits
Definition: vp3data.h:128
AVVulkanFramesContext::img_flags
VkImageCreateFlags img_flags
Flags to set during image creation.
Definition: hwcontext_vulkan.h:265
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:47
vk_ffv1_decode_slice
static int vk_ffv1_decode_slice(AVCodecContext *avctx, const uint8_t *data, uint32_t size)
Definition: vulkan_ffv1.c:266
FFv1VulkanDecodePicture
Definition: vulkan_ffv1.c:46
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:549
GLSLD
#define GLSLD(D)
Definition: vulkan.h:59
FFv1VkParameters::crcref
uint32_t crcref
Definition: ffv1enc_vulkan.c:135
vk_decode_ffv1_uninit
static void vk_decode_ffv1_uninit(FFVulkanDecodeShared *ctx)
Definition: vulkan_ffv1.c:1091
FFv1VkRCTParameters::offset
int offset
Definition: ffv1_vulkan.h:41
init_reset_shader
static int init_reset_shader(FFV1Context *f, FFVulkanContext *s, FFVkExecPool *pool, FFVkSPIRVCompiler *spv, FFVulkanShader *shd, int ac)
Definition: vulkan_ffv1.c:764
FFv1VulkanDecodePicture::slice_state
AVBufferRef * slice_state
Definition: vulkan_ffv1.c:51
FFv1VulkanDecodePicture::plane_state_size
uint32_t plane_state_size
Definition: vulkan_ffv1.c:52
if
if(ret)
Definition: filter_design.txt:179
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:623
FFv1VkParameters::chroma_shift
uint32_t chroma_shift[2]
Definition: ffv1enc_vulkan.c:131
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:1513
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:570
ff_source_rangecoder_comp
const char * ff_source_rangecoder_comp
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:486
FFv1VkParameters::version
uint8_t version
Definition: ffv1enc_vulkan.c:140
vk_ffv1_end_frame
static int vk_ffv1_end_frame(AVCodecContext *avctx)
Definition: vulkan_ffv1.c:303
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:1129
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:370
ff_source_ffv1_dec_rct_comp
const char * ff_source_ffv1_dec_rct_comp
FFVkBuffer::size
size_t size
Definition: vulkan.h:92
AVVulkanFramesContext::usage
VkImageUsageFlagBits usage
Defines extra usage of output frames.
Definition: hwcontext_vulkan.h:232
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:101
FFv1VulkanDecodeContext::slice_offset_pool
AVBufferPool * slice_offset_pool
Definition: vulkan_ffv1.c:79
FFVulkanContext
Definition: vulkan.h:276
FFv1VulkanDecodeContext::quant_buf
FFVkBuffer quant_buf
Definition: vulkan_ffv1.c:74
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:1012
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
init_rct_shader
static int init_rct_shader(FFV1Context *f, FFVulkanContext *s, FFVkExecPool *pool, FFVkSPIRVCompiler *spv, FFVulkanShader *shd, int use32bit, AVHWFramesContext *src_ctx, AVHWFramesContext *dst_ctx)
Definition: vulkan_ffv1.c:949
FFv1VulkanDecodePicture::tmp_data
AVBufferRef * tmp_data
Definition: vulkan_ffv1.c:49
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:75
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
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:2805
FFVulkanDescriptorSetBinding
Definition: vulkan.h:75
FFv1VkParameters::padding
uint8_t padding[2]
Definition: ffv1enc_vulkan.c:152
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:83
AVVkFrame
Definition: hwcontext_vulkan.h:302
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:1272
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:97
FF_VK_EXT_PUSH_DESCRIPTOR
#define FF_VK_EXT_PUSH_DESCRIPTOR
Definition: vulkan_functions.h:47
FFVulkanShader
Definition: vulkan.h:192
ff_source_ffv1_reset_comp
const char * ff_source_ffv1_reset_comp
init_decode_shader
static int init_decode_shader(FFV1Context *f, FFVulkanContext *s, FFVkExecPool *pool, FFVkSPIRVCompiler *spv, FFVulkanShader *shd, AVHWFramesContext *frames_ctx, int use32bit, int ac, int rgb)
Definition: vulkan_ffv1.c:856
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
FFVulkanDecodePicture::view
struct FFVulkanDecodePicture::@291 view
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
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
FFVkExecContext
Definition: vulkan.h:112
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:2739
FFVulkanDescriptorSetBinding::name
const char * name
Definition: vulkan.h:76
FF_COMPLIANCE_UNOFFICIAL
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition: defs.h:61
version
version
Definition: libkvazaar.c:321
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:1445
FFv1VulkanDecodeContext::intermediate_frames_ref
AVBufferRef * intermediate_frames_ref[2]
Definition: vulkan_ffv1.c:66
FFVkSPIRVCompiler
Definition: vulkan_spirv.h:26
AVHWAccel::name
const char * name
Name of the hardware accelerated codec.
Definition: avcodec.h:2124
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:35
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:489
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:53
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:1949
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:2281
ffv1.h
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:1129
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:2815
AVCodecContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition: avcodec.h:1493
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:329
ff_ffv1_vulkan_hwaccel
const FFHWAccel ff_ffv1_vulkan_hwaccel
Definition: vulkan_ffv1.c:1299
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:1865
AVHWFramesContext::hwctx
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:151
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1397
FFVkExecPool
Definition: vulkan.h:254
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:253
planes
static const struct @482 planes[]
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:1375
AVCodecContext
main external API structure.
Definition: avcodec.h:451
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:90
ff_vk_dec_ffv1_desc
const FFVulkanDecodeDescriptor ff_vk_dec_ffv1_desc
Definition: vulkan_ffv1.c:38
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
GLSLF
#define GLSLF(N, S,...)
Definition: vulkan.h:54
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:58
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:112
FFv1VulkanDecodeContext::decode
FFVulkanShader decode[2][2][2]
Definition: vulkan_ffv1.c:70
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:222
FFv1VkResetParameters
Definition: ffv1_vulkan.h:51
FFv1VkParameters::colorspace
uint8_t colorspace
Definition: ffv1enc_vulkan.c:147
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
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
vulkan_decode.h
FFV1Context
Definition: ffv1.h:112
ff_vk_count_images
static int ff_vk_count_images(AVVkFrame *f)
Definition: vulkan.h:322
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
FFv1VulkanDecodeContext::setup
FFVulkanShader setup
Definition: vulkan_ffv1.c:68
FFVkBuffer
Definition: vulkan.h:88
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:831
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:1178
FFv1VkParameters
Definition: ffv1enc_vulkan.c:125
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:678
FFv1VulkanDecodePicture::slice_offset_buf
AVBufferRef * slice_offset_buf
Definition: vulkan_ffv1.c:57
FFv1VulkanDecodePicture::crc_checked
int crc_checked
Definition: vulkan_ffv1.c:62
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:495
FFv1VkParameters::check_crc
uint8_t check_crc
Definition: vulkan_ffv1.c:108
FFv1VkParameters::context_count
uint32_t context_count
Definition: ffv1enc_vulkan.c:134
FFVulkanFunctions
Definition: vulkan_functions.h:264
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:1171
FFv1VkRCTParameters
Definition: ffv1_vulkan.h:39
FFv1VulkanDecodeContext::rct
FFVulkanShader rct[2]
Definition: vulkan_ffv1.c:71
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:146
vk_decode_ffv1_init
static int vk_decode_ffv1_init(AVCodecContext *avctx)
Definition: vulkan_ffv1.c:1121
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:149
FFv1VulkanDecodePicture::slice_num
int slice_num
Definition: vulkan_ffv1.c:59