FFmpeg
vulkan_filter.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) Lynne
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 "filters.h"
22 #include "vulkan_filter.h"
24 
26  AVBufferRef *frames_ref,
27  int width, int height, enum AVPixelFormat sw_format)
28 {
29  int err;
30  AVHWFramesContext *frames_ctx;
31  AVHWDeviceContext *device_ctx;
32  AVVulkanFramesContext *vk_frames;
33  AVVulkanDeviceContext *vk_dev;
34  AVBufferRef *device_ref = avctx->hw_device_ctx;
35 
36  /* Check if context is reusable as-is */
37  if (frames_ref) {
38  int no_storage = 0;
40  VkImageUsageFlagBits usage_req;
41  const VkFormat *sub = av_vkfmt_from_pixfmt(sw_format);
42 
43  frames_ctx = (AVHWFramesContext *)frames_ref->data;
44  device_ctx = (AVHWDeviceContext *)frames_ctx->device_ref->data;
45  vk_frames = frames_ctx->hwctx;
46  vk_dev = device_ctx->hwctx;
47 
48  /* Width and height mismatch */
49  if (width != frames_ctx->width ||
50  height != frames_ctx->height)
51  goto skip;
52 
53  /* Format mismatch */
54  if (sw_format != frames_ctx->sw_format)
55  goto skip;
56 
57  /* Don't let linear through. */
58  if (vk_frames->tiling == VK_IMAGE_TILING_LINEAR)
59  goto skip;
60 
63 
64  /* More advanced format checks */
65  err = ff_vk_load_functions(device_ctx, &s->vkfn, s->extensions, 1, 1);
66  if (err < 0)
67  return err;
68  vk = &s->vkfn;
69 
70  /* Usage mismatch */
71  usage_req = VK_IMAGE_USAGE_SAMPLED_BIT;
72 
73  /* If format supports hardware encoding, make sure
74  * the context includes it. */
75  if (vk_frames->format[1] == VK_FORMAT_UNDEFINED &&
76  (s->extensions & (FF_VK_EXT_VIDEO_ENCODE_QUEUE |
78  VkFormatProperties3 fprops = {
79  .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3,
80  };
81  VkFormatProperties2 prop = {
82  .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2,
83  .pNext = &fprops,
84  };
85  vk->GetPhysicalDeviceFormatProperties2(vk_dev->phys_dev,
86  vk_frames->format[0],
87  &prop);
88  if (fprops.optimalTilingFeatures & VK_FORMAT_FEATURE_2_VIDEO_ENCODE_INPUT_BIT_KHR)
89  usage_req |= VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
90  }
91 
92  if ((vk_frames->usage & usage_req) != usage_req)
93  goto skip;
94 
95  /* Check if the subformats can do storage */
96  for (int i = 0; sub[i] != VK_FORMAT_UNDEFINED; i++) {
97  VkFormatProperties2 prop = {
98  .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2,
99  };
100  vk->GetPhysicalDeviceFormatProperties2(vk_dev->phys_dev, sub[i],
101  &prop);
102  no_storage |= !(prop.formatProperties.optimalTilingFeatures &
103  VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT);
104  }
105 
106  /* Check if it's usable */
107  if (no_storage) {
108 skip:
109  device_ref = frames_ctx->device_ref;
110  frames_ref = NULL;
111  } else {
112  frames_ref = av_buffer_ref(frames_ref);
113  if (!frames_ref)
114  return AVERROR(ENOMEM);
115  }
116  }
117 
118  if (!frames_ref) {
119  if (!device_ref) {
120  av_log(avctx, AV_LOG_ERROR,
121  "Vulkan filtering requires a device context!\n");
122  return AVERROR(EINVAL);
123  }
124 
125  frames_ref = av_hwframe_ctx_alloc(device_ref);
126 
127  frames_ctx = (AVHWFramesContext *)frames_ref->data;
128  frames_ctx->format = AV_PIX_FMT_VULKAN;
129  frames_ctx->sw_format = sw_format;
130  frames_ctx->width = width;
131  frames_ctx->height = height;
132 
133  err = av_hwframe_ctx_init(frames_ref);
134  if (err < 0) {
135  av_buffer_unref(&frames_ref);
136  return err;
137  }
138 
139  device_ctx = (AVHWDeviceContext *)frames_ctx->device_ref->data;
140  vk_dev = device_ctx->hwctx;
141  }
142 
143  s->extensions = ff_vk_extensions_to_mask(vk_dev->enabled_dev_extensions,
144  vk_dev->nb_enabled_dev_extensions);
145 
146  /**
147  * libplacebo does not use descriptor buffers.
148  */
149  if (!(s->extensions & FF_VK_EXT_DESCRIPTOR_BUFFER) &&
150  strcmp(avctx->filter->name, "libplacebo")) {
151  av_log(avctx, AV_LOG_ERROR, "Vulkan filtering requires that "
152  "the %s extension is supported!\n",
153  VK_EXT_DESCRIPTOR_BUFFER_EXTENSION_NAME);
154  av_buffer_unref(&frames_ref);
155  return AVERROR(EINVAL);
156  }
157 
158  err = ff_vk_load_functions(device_ctx, &s->vkfn, s->extensions, 1, 1);
159  if (err < 0) {
160  av_buffer_unref(&frames_ref);
161  return err;
162  }
163 
164  s->frames_ref = frames_ref;
165  s->frames = frames_ctx;
166  s->hwfc = vk_frames;
167  s->device = device_ctx;
168  s->hwctx = device_ctx->hwctx;
169 
170  err = ff_vk_load_props(s);
171  if (err < 0)
172  av_buffer_unref(&s->frames_ref);
173 
174  return err;
175 }
176 
178 {
180  AVHWFramesContext *input_frames;
181  AVFilterContext *avctx = inlink->dst;
182  FFVulkanContext *s = inlink->dst->priv;
183 
184  if (!l->hw_frames_ctx) {
185  av_log(inlink->dst, AV_LOG_ERROR, "Vulkan filtering requires a "
186  "hardware frames context on the input.\n");
187  return AVERROR(EINVAL);
188  }
189 
190  input_frames = (AVHWFramesContext *)l->hw_frames_ctx->data;
191  if (input_frames->format != AV_PIX_FMT_VULKAN)
192  return AVERROR(EINVAL);
193 
194  /* Extract the device and default output format from the first input. */
195  if (avctx->inputs[0] != inlink)
196  return 0;
197 
198  /* Save the ref, without reffing it */
199  s->input_frames_ref = l->hw_frames_ctx;
200 
201  /* Defaults */
202  s->input_format = input_frames->sw_format;
203  s->output_format = input_frames->sw_format;
204  s->output_width = inlink->w;
205  s->output_height = inlink->h;
206 
207  return 0;
208 }
209 
211 {
212  int err;
213  FilterLink *l = ff_filter_link(outlink);
214  FFVulkanContext *s = outlink->src->priv;
215 
217 
218  err = ff_vk_filter_init_context(outlink->src, s, s->input_frames_ref,
219  s->output_width, s->output_height,
220  s->output_format);
221  if (err < 0)
222  return err;
223 
224  l->hw_frames_ctx = av_buffer_ref(s->frames_ref);
225  if (!l->hw_frames_ctx)
226  return AVERROR(ENOMEM);
227 
228  outlink->w = s->output_width;
229  outlink->h = s->output_height;
230 
231  return err;
232 }
233 
235 {
236  FFVulkanContext *s = avctx->priv;
237 
238  s->output_format = AV_PIX_FMT_NONE;
239 
240  return 0;
241 }
242 
244  FFVulkanPipeline *pl, AVFrame *out_f, AVFrame *in_f,
245  VkSampler sampler, void *push_src, size_t push_size)
246 {
247  int err = 0;
248  FFVulkanFunctions *vk = &vkctx->vkfn;
249  VkImageView in_views[AV_NUM_DATA_POINTERS];
250  VkImageView out_views[AV_NUM_DATA_POINTERS];
251  VkImageMemoryBarrier2 img_bar[37];
252  int nb_img_bar = 0;
253 
254  /* Update descriptors and init the exec context */
255  FFVkExecContext *exec = ff_vk_exec_get(e);
256  ff_vk_exec_start(vkctx, exec);
257 
258  ff_vk_exec_bind_pipeline(vkctx, exec, pl);
259 
260  if (push_src)
261  ff_vk_update_push_exec(vkctx, exec, pl, VK_SHADER_STAGE_COMPUTE_BIT,
262  0, push_size, push_src);
263 
264  if (in_f) {
265  RET(ff_vk_exec_add_dep_frame(vkctx, exec, in_f,
266  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
267  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
268  RET(ff_vk_create_imageviews(vkctx, exec, in_views, in_f));
269  ff_vk_update_descriptor_img_array(vkctx, pl, exec, in_f, in_views, 0, 0,
270  VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
271  sampler);
272  ff_vk_frame_barrier(vkctx, exec, in_f, img_bar, &nb_img_bar,
273  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
274  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
275  VK_ACCESS_SHADER_READ_BIT,
276  VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
277  VK_QUEUE_FAMILY_IGNORED);
278  }
279 
280  RET(ff_vk_exec_add_dep_frame(vkctx, exec, out_f,
281  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
282  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
283  RET(ff_vk_create_imageviews(vkctx, exec, out_views, out_f));
284  ff_vk_update_descriptor_img_array(vkctx, pl, exec, out_f, out_views, 0, !!in_f,
285  VK_IMAGE_LAYOUT_GENERAL,
286  VK_NULL_HANDLE);
287  ff_vk_frame_barrier(vkctx, exec, out_f, img_bar, &nb_img_bar,
288  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
289  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
290  VK_ACCESS_SHADER_WRITE_BIT,
291  VK_IMAGE_LAYOUT_GENERAL,
292  VK_QUEUE_FAMILY_IGNORED);
293 
294  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
295  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
296  .pImageMemoryBarriers = img_bar,
297  .imageMemoryBarrierCount = nb_img_bar,
298  });
299 
300  vk->CmdDispatch(exec->buf,
301  FFALIGN(vkctx->output_width, pl->wg_size[0])/pl->wg_size[0],
302  FFALIGN(vkctx->output_height, pl->wg_size[1])/pl->wg_size[1],
303  pl->wg_size[2]);
304 
305  return ff_vk_exec_submit(vkctx, exec);
306 fail:
307  ff_vk_exec_discard_deps(vkctx, exec);
308  return err;
309 }
310 
312  FFVulkanPipeline *pls[2],
313  AVFrame *out, AVFrame *tmp, AVFrame *in,
314  VkSampler sampler, void *push_src, size_t push_size)
315 {
316  int err = 0;
317  FFVulkanFunctions *vk = &vkctx->vkfn;
318  VkImageView in_views[AV_NUM_DATA_POINTERS];
319  VkImageView tmp_views[AV_NUM_DATA_POINTERS];
320  VkImageView out_views[AV_NUM_DATA_POINTERS];
321  VkImageMemoryBarrier2 img_bar[37];
322  int nb_img_bar = 0;
323 
324  /* Update descriptors and init the exec context */
325  FFVkExecContext *exec = ff_vk_exec_get(e);
326  ff_vk_exec_start(vkctx, exec);
327 
328  RET(ff_vk_exec_add_dep_frame(vkctx, exec, in,
329  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
330  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
331  RET(ff_vk_exec_add_dep_frame(vkctx, exec, tmp,
332  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
333  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
334  RET(ff_vk_exec_add_dep_frame(vkctx, exec, out,
335  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
336  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
337 
338  RET(ff_vk_create_imageviews(vkctx, exec, in_views, in));
339  RET(ff_vk_create_imageviews(vkctx, exec, tmp_views, tmp));
340  RET(ff_vk_create_imageviews(vkctx, exec, out_views, out));
341 
342  ff_vk_frame_barrier(vkctx, exec, in, img_bar, &nb_img_bar,
343  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
344  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
345  VK_ACCESS_SHADER_READ_BIT,
346  VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
347  VK_QUEUE_FAMILY_IGNORED);
348  ff_vk_frame_barrier(vkctx, exec, tmp, img_bar, &nb_img_bar,
349  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
350  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
351  VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
352  VK_IMAGE_LAYOUT_GENERAL,
353  VK_QUEUE_FAMILY_IGNORED);
354  ff_vk_frame_barrier(vkctx, exec, out, img_bar, &nb_img_bar,
355  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
356  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
357  VK_ACCESS_SHADER_WRITE_BIT,
358  VK_IMAGE_LAYOUT_GENERAL,
359  VK_QUEUE_FAMILY_IGNORED);
360 
361  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
362  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
363  .pImageMemoryBarriers = img_bar,
364  .imageMemoryBarrierCount = nb_img_bar,
365  });
366 
367  for (int i = 0; i < 2; i++) {
368  FFVulkanPipeline *pl = pls[i];
369  AVFrame *src_f = !i ? in : tmp;
370  AVFrame *dst_f = !i ? tmp : out;
371  VkImageView *src_views = !i ? in_views : tmp_views;
372  VkImageView *dst_views = !i ? tmp_views : out_views;
373 
374  ff_vk_exec_bind_pipeline(vkctx, exec, pl);
375 
376  if (push_src)
377  ff_vk_update_push_exec(vkctx, exec, pl, VK_SHADER_STAGE_COMPUTE_BIT,
378  0, push_size, push_src);
379 
380  ff_vk_update_descriptor_img_array(vkctx, pl, exec, src_f, src_views, 0, 0,
381  !i ? VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL :
382  VK_IMAGE_LAYOUT_GENERAL,
383  sampler);
384  ff_vk_update_descriptor_img_array(vkctx, pl, exec, dst_f, dst_views, 0, 1,
385  VK_IMAGE_LAYOUT_GENERAL,
386  VK_NULL_HANDLE);
387 
388  vk->CmdDispatch(exec->buf,
389  FFALIGN(vkctx->output_width, pl->wg_size[0])/pl->wg_size[0],
390  FFALIGN(vkctx->output_height, pl->wg_size[1])/pl->wg_size[1],
391  pl->wg_size[2]);
392  }
393 
394  return ff_vk_exec_submit(vkctx, exec);
395 fail:
396  ff_vk_exec_discard_deps(vkctx, exec);
397  return err;
398 }
399 
401  FFVulkanPipeline *pl,
402  AVFrame *out, AVFrame *in[], int nb_in,
403  VkSampler sampler, void *push_src, size_t push_size)
404 {
405  int err = 0;
406  FFVulkanFunctions *vk = &vkctx->vkfn;
407  VkImageView in_views[16][AV_NUM_DATA_POINTERS];
408  VkImageView out_views[AV_NUM_DATA_POINTERS];
409  VkImageMemoryBarrier2 img_bar[128];
410  int nb_img_bar = 0;
411 
412  /* Update descriptors and init the exec context */
413  FFVkExecContext *exec = ff_vk_exec_get(e);
414  ff_vk_exec_start(vkctx, exec);
415 
416  /* Inputs */
417  for (int i = 0; i < nb_in; i++) {
418  RET(ff_vk_exec_add_dep_frame(vkctx, exec, in[i],
419  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
420  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
421  RET(ff_vk_create_imageviews(vkctx, exec, in_views[i], in[i]));
422 
423  ff_vk_frame_barrier(vkctx, exec, in[i], img_bar, &nb_img_bar,
424  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
425  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
426  VK_ACCESS_SHADER_READ_BIT,
427  VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
428  VK_QUEUE_FAMILY_IGNORED);
429  }
430 
431  /* Output */
432  RET(ff_vk_exec_add_dep_frame(vkctx, exec, out,
433  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
434  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
435  RET(ff_vk_create_imageviews(vkctx, exec, out_views, out));
436  ff_vk_frame_barrier(vkctx, exec, out, img_bar, &nb_img_bar,
437  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
438  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
439  VK_ACCESS_SHADER_WRITE_BIT,
440  VK_IMAGE_LAYOUT_GENERAL,
441  VK_QUEUE_FAMILY_IGNORED);
442 
443  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
444  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
445  .pImageMemoryBarriers = img_bar,
446  .imageMemoryBarrierCount = nb_img_bar,
447  });
448 
449  ff_vk_exec_bind_pipeline(vkctx, exec, pl);
450 
451  if (push_src)
452  ff_vk_update_push_exec(vkctx, exec, pl, VK_SHADER_STAGE_COMPUTE_BIT,
453  0, push_size, push_src);
454 
455  for (int i = 0; i < nb_in; i++)
456  ff_vk_update_descriptor_img_array(vkctx, pl, exec, in[i], in_views[i], 0, i,
457  VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
458  sampler);
459 
460  ff_vk_update_descriptor_img_array(vkctx, pl, exec, out, out_views, 0, nb_in,
461  VK_IMAGE_LAYOUT_GENERAL,
462  VK_NULL_HANDLE);
463 
464  vk->CmdDispatch(exec->buf,
465  FFALIGN(vkctx->output_width, pl->wg_size[0])/pl->wg_size[0],
466  FFALIGN(vkctx->output_height, pl->wg_size[1])/pl->wg_size[1],
467  pl->wg_size[2]);
468 
469  return ff_vk_exec_submit(vkctx, exec);
470 fail:
471  ff_vk_exec_discard_deps(vkctx, exec);
472  return err;
473 }
vulkan_loader.h
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:85
ff_vk_load_props
int ff_vk_load_props(FFVulkanContext *s)
Loads props/mprops/driver_props.
Definition: vulkan.c:105
FF_VK_EXT_VIDEO_ENCODE_QUEUE
@ FF_VK_EXT_VIDEO_ENCODE_QUEUE
Definition: vulkan_functions.h:53
AVVulkanDeviceContext::phys_dev
VkPhysicalDevice phys_dev
Physical device.
Definition: hwcontext_vulkan.h:79
ff_vk_exec_get
FFVkExecContext * ff_vk_exec_get(FFVkExecPool *pool)
Retrieve an execution pool.
Definition: vulkan.c:484
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
ff_vk_update_descriptor_img_array
void ff_vk_update_descriptor_img_array(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkExecContext *e, AVFrame *f, VkImageView *views, int set, int binding, VkImageLayout layout, VkSampler sampler)
Definition: vulkan.c:1713
FFVulkanContext::output_height
int output_height
Definition: vulkan.h:267
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
out
FILE * out
Definition: movenc.c:55
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:197
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:322
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
ff_vk_filter_init
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
Definition: vulkan_filter.c:234
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:248
ff_vk_filter_process_Nin
int ff_vk_filter_process_Nin(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanPipeline *pl, AVFrame *out, AVFrame *in[], int nb_in, VkSampler sampler, void *push_src, size_t push_size)
Up to 16 inputs, one output.
Definition: vulkan_filter.c:400
FF_VK_EXT_DESCRIPTOR_BUFFER
@ FF_VK_EXT_DESCRIPTOR_BUFFER
Definition: vulkan_functions.h:40
AVFilterContext::hw_device_ctx
AVBufferRef * hw_device_ctx
For filters which will create hardware frames, sets the device the filter should create them in.
Definition: avfilter.h:469
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:217
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:586
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:422
fail
#define fail()
Definition: checkasm.h:188
FFVulkanPipeline::wg_size
int wg_size[3]
Definition: vulkan.h:144
vulkan_filter.h
ff_vk_filter_init_context
int ff_vk_filter_init_context(AVFilterContext *avctx, FFVulkanContext *s, AVBufferRef *frames_ref, int width, int height, enum AVPixelFormat sw_format)
Can be called manually, if not using ff_vk_filter_config_output.
Definition: vulkan_filter.c:25
AVVulkanFramesContext
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
Definition: hwcontext_vulkan.h:213
ff_vk_filter_process_2pass
int ff_vk_filter_process_2pass(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanPipeline *pls[2], AVFrame *out, AVFrame *tmp, AVFrame *in, VkSampler sampler, void *push_src, size_t push_size)
Submit a compute shader with a single in and single out with 2 stages.
Definition: vulkan_filter.c:311
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVHWFramesContext::height
int height
Definition: hwcontext.h:217
FFVulkanContext::output_width
int output_width
Definition: vulkan.h:266
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:198
FF_VK_EXT_VIDEO_MAINTENANCE_1
@ FF_VK_EXT_VIDEO_MAINTENANCE_1
Definition: vulkan_functions.h:52
ff_vk_load_functions
static int ff_vk_load_functions(AVHWDeviceContext *ctx, FFVulkanFunctions *vk, uint64_t extensions_mask, int has_inst, int has_dev)
Function loader.
Definition: vulkan_loader.h:97
filters.h
ff_vk_exec_bind_pipeline
void ff_vk_exec_bind_pipeline(FFVulkanContext *s, FFVkExecContext *e, FFVulkanPipeline *pl)
Definition: vulkan.c:1808
if
if(ret)
Definition: filter_design.txt:179
AVVulkanDeviceContext
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_vulkan.h:59
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:210
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
AVVulkanDeviceContext::nb_enabled_dev_extensions
int nb_enabled_dev_extensions
Definition: hwcontext_vulkan.h:113
AVHWFramesContext::device_ref
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:126
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:415
ff_vk_filter_config_output
int ff_vk_filter_config_output(AVFilterLink *outlink)
Definition: vulkan_filter.c:210
AVVulkanFramesContext::format
VkFormat format[AV_NUM_DATA_POINTERS]
Vulkan format for each image.
Definition: hwcontext_vulkan.h:273
AVVulkanFramesContext::usage
VkImageUsageFlagBits usage
Defines extra usage of output frames.
Definition: hwcontext_vulkan.h:232
FFVulkanContext
Definition: vulkan.h:229
FFVulkanPipeline
Definition: vulkan.h:132
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:375
height
#define height
FFVkExecContext
Definition: vulkan.h:153
ff_vk_update_push_exec
void ff_vk_update_push_exec(FFVulkanContext *s, FFVkExecContext *e, FFVulkanPipeline *pl, VkShaderStageFlagBits stage, int offset, size_t size, void *src)
Definition: vulkan.c:1726
ff_vk_filter_process_simple
int ff_vk_filter_process_simple(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanPipeline *pl, AVFrame *out_f, AVFrame *in_f, VkSampler sampler, void *push_src, size_t push_size)
Submit a compute shader with a zero/one input and single out for execution.
Definition: vulkan_filter.c:243
av_vkfmt_from_pixfmt
const VkFormat * av_vkfmt_from_pixfmt(enum AVPixelFormat p)
Returns the optimal per-plane Vulkan format for a given sw_format, one for each plane.
Definition: hwcontext_stub.c:30
ff_vk_exec_start
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition: vulkan.c:500
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
VkFormat
enum VkFormat VkFormat
Definition: hwcontext_stub.c:25
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:1288
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:115
FFVulkanContext::vkfn
FFVulkanFunctions vkfn
Definition: vulkan.h:232
AVHWFramesContext::hwctx
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:150
FFVkExecPool
Definition: vulkan.h:211
FFVkExecContext::buf
VkCommandBuffer buf
Definition: vulkan.h:165
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AVVulkanFramesContext::tiling
VkImageTiling tiling
Controls the tiling of allocated frames.
Definition: hwcontext_vulkan.h:222
AVFilterContext
An instance of a filter.
Definition: avfilter.h:407
AVVulkanDeviceContext::enabled_dev_extensions
const char *const * enabled_dev_extensions
Enabled device extensions.
Definition: hwcontext_vulkan.h:112
ff_vk_filter_config_input
int ff_vk_filter_config_input(AVFilterLink *inlink)
Definition: vulkan_filter.c:177
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
ff_vk_exec_discard_deps
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:536
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:711
ff_vk_extensions_to_mask
static uint64_t ff_vk_extensions_to_mask(const char *const *extensions, int nb_extensions)
Definition: vulkan_loader.h:36
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_vk_create_imageviews
int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e, VkImageView views[AV_NUM_DATA_POINTERS], AVFrame *f)
Create an imageview and add it as a dependency to an execution.
Definition: vulkan.c:1215
AVFilterContext::filter
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:410
RET
#define RET(x)
Definition: vulkan.h:67
FFVulkanFunctions
Definition: vulkan_functions.h:249
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375