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  VK_IMAGE_USAGE_STORAGE_BIT;
73 
74  /* If format supports hardware encoding, make sure
75  * the context includes it. */
76  if (vk_frames->format[1] == VK_FORMAT_UNDEFINED &&
77  (s->extensions & FF_VK_EXT_VIDEO_ENCODE_QUEUE) &&
78  (s->extensions & FF_VK_EXT_VIDEO_MAINTENANCE_1)) {
79  VkFormatProperties3 fprops = {
80  .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3,
81  };
82  VkFormatProperties2 prop = {
83  .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2,
84  .pNext = &fprops,
85  };
86  vk->GetPhysicalDeviceFormatProperties2(vk_dev->phys_dev,
87  vk_frames->format[0],
88  &prop);
89  if (fprops.optimalTilingFeatures & VK_FORMAT_FEATURE_2_VIDEO_ENCODE_INPUT_BIT_KHR)
90  usage_req |= VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
91  }
92 
93  if ((vk_frames->usage & usage_req) != usage_req)
94  goto skip;
95 
96  /* Check if the subformats can do storage */
97  for (int i = 0; sub[i] != VK_FORMAT_UNDEFINED; i++) {
98  VkFormatProperties2 prop = {
99  .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2,
100  };
101  vk->GetPhysicalDeviceFormatProperties2(vk_dev->phys_dev, sub[i],
102  &prop);
103  no_storage |= !(prop.formatProperties.optimalTilingFeatures &
104  VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT);
105  }
106 
107  /* Check if it's usable */
108  if (no_storage) {
109 skip:
110  av_log(avctx, AV_LOG_VERBOSE, "Cannot reuse context, creating a new one\n");
111  device_ref = frames_ctx->device_ref;
112  frames_ref = NULL;
113  } else {
114  av_log(avctx, AV_LOG_VERBOSE, "Reusing existing frames context\n");
115  frames_ref = av_buffer_ref(frames_ref);
116  if (!frames_ref)
117  return AVERROR(ENOMEM);
118  }
119  }
120 
121  if (!frames_ref) {
122  if (!device_ref) {
123  av_log(avctx, AV_LOG_ERROR,
124  "Vulkan filtering requires a device context!\n");
125  return AVERROR(EINVAL);
126  }
127 
128  frames_ref = av_hwframe_ctx_alloc(device_ref);
129 
130  frames_ctx = (AVHWFramesContext *)frames_ref->data;
131  frames_ctx->format = AV_PIX_FMT_VULKAN;
132  frames_ctx->sw_format = sw_format;
133  frames_ctx->width = width;
134  frames_ctx->height = height;
135 
136  vk_frames = frames_ctx->hwctx;
137  vk_frames->tiling = VK_IMAGE_TILING_OPTIMAL;
138  vk_frames->usage = VK_IMAGE_USAGE_SAMPLED_BIT |
139  VK_IMAGE_USAGE_STORAGE_BIT |
140  VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
141 
142  err = av_hwframe_ctx_init(frames_ref);
143  if (err < 0) {
144  av_buffer_unref(&frames_ref);
145  return err;
146  }
147 
148  device_ctx = (AVHWDeviceContext *)frames_ctx->device_ref->data;
149  vk_dev = device_ctx->hwctx;
150  }
151 
152  s->extensions = ff_vk_extensions_to_mask(vk_dev->enabled_dev_extensions,
153  vk_dev->nb_enabled_dev_extensions);
154  s->extensions |= ff_vk_extensions_to_mask(vk_dev->enabled_inst_extensions,
156 
157  err = ff_vk_load_functions(device_ctx, &s->vkfn, s->extensions, 1, 1);
158  if (err < 0) {
159  av_buffer_unref(&frames_ref);
160  return err;
161  }
162 
163  s->frames_ref = frames_ref;
164  s->frames = frames_ctx;
165  s->hwfc = vk_frames;
166  s->device = device_ctx;
167  s->hwctx = device_ctx->hwctx;
168 
169  err = ff_vk_load_props(s);
170  if (err < 0)
171  av_buffer_unref(&s->frames_ref);
172 
173  return err;
174 }
175 
177 {
179  AVHWFramesContext *input_frames;
180  AVFilterContext *avctx = inlink->dst;
181  FFVulkanContext *s = inlink->dst->priv;
182 
183  if (!l->hw_frames_ctx) {
184  av_log(inlink->dst, AV_LOG_ERROR, "Vulkan filtering requires a "
185  "hardware frames context on the input.\n");
186  return AVERROR(EINVAL);
187  }
188 
189  input_frames = (AVHWFramesContext *)l->hw_frames_ctx->data;
190  if (input_frames->format != AV_PIX_FMT_VULKAN)
191  return AVERROR(EINVAL);
192 
193  /* Extract the device and default output format from the first input. */
194  if (avctx->inputs[0] != inlink)
195  return 0;
196 
197  /* Save the ref, without reffing it */
198  s->input_frames_ref = l->hw_frames_ctx;
199 
200  /* Defaults */
201  s->input_format = input_frames->sw_format;
202  s->output_format = input_frames->sw_format;
203  s->output_width = inlink->w;
204  s->output_height = inlink->h;
205 
206  return 0;
207 }
208 
210 {
211  int err;
212  FilterLink *l = ff_filter_link(outlink);
213  FFVulkanContext *s = outlink->src->priv;
214 
216 
217  err = ff_vk_filter_init_context(outlink->src, s, s->input_frames_ref,
218  s->output_width, s->output_height,
219  s->output_format);
220  if (err < 0)
221  return err;
222 
223  l->hw_frames_ctx = av_buffer_ref(s->frames_ref);
224  if (!l->hw_frames_ctx)
225  return AVERROR(ENOMEM);
226 
227  outlink->w = s->output_width;
228  outlink->h = s->output_height;
229 
230  return err;
231 }
232 
234 {
235  FFVulkanContext *s = avctx->priv;
236 
237  s->output_format = AV_PIX_FMT_NONE;
238 
239  return 0;
240 }
241 
243  FFVulkanShader *shd, AVFrame *out_f, AVFrame *in_f,
244  VkSampler sampler, uint32_t wgc_z,
245  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  VkImageLayout in_layout = sampler != VK_NULL_HANDLE ?
254  VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL :
255  VK_IMAGE_LAYOUT_GENERAL;
256 
257  /* Update descriptors and init the exec context */
258  FFVkExecContext *exec = ff_vk_exec_get(vkctx, e);
259  ff_vk_exec_start(vkctx, exec);
260 
261  RET(ff_vk_exec_add_dep_frame(vkctx, exec, out_f,
262  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
263  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
264  RET(ff_vk_create_imageviews(vkctx, exec, out_views, out_f, FF_VK_REP_FLOAT));
265  ff_vk_shader_update_img_array(vkctx, exec, shd, out_f, out_views, 0, !!in_f,
266  VK_IMAGE_LAYOUT_GENERAL,
267  VK_NULL_HANDLE);
268  if (in_f) {
269  RET(ff_vk_exec_add_dep_frame(vkctx, exec, in_f,
270  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
271  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
272  RET(ff_vk_create_imageviews(vkctx, exec, in_views, in_f, FF_VK_REP_FLOAT));
273  ff_vk_shader_update_img_array(vkctx, exec, shd, in_f, in_views, 0, 0,
274  in_layout,
275  sampler);
276  }
277 
278  /* Bind pipeline, update push data */
279  ff_vk_exec_bind_shader(vkctx, exec, shd);
280  if (push_src)
281  ff_vk_shader_update_push_const(vkctx, exec, shd, VK_SHADER_STAGE_COMPUTE_BIT,
282  0, push_size, push_src);
283 
284  /* Add data sync barriers */
285  ff_vk_frame_barrier(vkctx, exec, out_f, img_bar, &nb_img_bar,
286  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
287  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
288  VK_ACCESS_SHADER_WRITE_BIT,
289  VK_IMAGE_LAYOUT_GENERAL,
290  VK_QUEUE_FAMILY_IGNORED);
291  if (in_f)
292  ff_vk_frame_barrier(vkctx, exec, in_f, img_bar, &nb_img_bar,
293  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
294  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
295  VK_ACCESS_SHADER_READ_BIT,
296  in_layout,
297  VK_QUEUE_FAMILY_IGNORED);
298 
299  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
300  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
301  .pImageMemoryBarriers = img_bar,
302  .imageMemoryBarrierCount = nb_img_bar,
303  });
304 
305  vk->CmdDispatch(exec->buf,
306  FFALIGN(vkctx->output_width, shd->lg_size[0])/shd->lg_size[0],
307  FFALIGN(vkctx->output_height, shd->lg_size[1])/shd->lg_size[1],
308  wgc_z);
309 
310  return ff_vk_exec_submit(vkctx, exec);
311 fail:
312  ff_vk_exec_discard_deps(vkctx, exec);
313  return err;
314 }
315 
317  FFVulkanShader *shd_list[2],
318  AVFrame *out, AVFrame *tmp, AVFrame *in,
319  VkSampler sampler, uint32_t wgc_z,
320  void *push_src, size_t push_size)
321 {
322  int err = 0;
323  FFVulkanFunctions *vk = &vkctx->vkfn;
324  VkImageView in_views[AV_NUM_DATA_POINTERS];
325  VkImageView tmp_views[AV_NUM_DATA_POINTERS];
326  VkImageView out_views[AV_NUM_DATA_POINTERS];
327  VkImageMemoryBarrier2 img_bar[37];
328  int nb_img_bar = 0;
329  VkImageLayout in_layout = sampler != VK_NULL_HANDLE ?
330  VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL :
331  VK_IMAGE_LAYOUT_GENERAL;
332 
333  /* Update descriptors and init the exec context */
334  FFVkExecContext *exec = ff_vk_exec_get(vkctx, e);
335  ff_vk_exec_start(vkctx, exec);
336 
337  RET(ff_vk_exec_add_dep_frame(vkctx, exec, in,
338  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
339  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
340  RET(ff_vk_exec_add_dep_frame(vkctx, exec, tmp,
341  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
342  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
343  RET(ff_vk_exec_add_dep_frame(vkctx, exec, out,
344  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
345  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
346 
347  RET(ff_vk_create_imageviews(vkctx, exec, in_views, in, FF_VK_REP_FLOAT));
348  RET(ff_vk_create_imageviews(vkctx, exec, tmp_views, tmp, FF_VK_REP_FLOAT));
349  RET(ff_vk_create_imageviews(vkctx, exec, out_views, out, FF_VK_REP_FLOAT));
350 
351  ff_vk_frame_barrier(vkctx, exec, in, img_bar, &nb_img_bar,
352  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
353  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
354  VK_ACCESS_SHADER_READ_BIT,
355  in_layout,
356  VK_QUEUE_FAMILY_IGNORED);
357  ff_vk_frame_barrier(vkctx, exec, tmp, img_bar, &nb_img_bar,
358  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
359  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
360  VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
361  VK_IMAGE_LAYOUT_GENERAL,
362  VK_QUEUE_FAMILY_IGNORED);
363  ff_vk_frame_barrier(vkctx, exec, out, img_bar, &nb_img_bar,
364  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
365  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
366  VK_ACCESS_SHADER_WRITE_BIT,
367  VK_IMAGE_LAYOUT_GENERAL,
368  VK_QUEUE_FAMILY_IGNORED);
369 
370  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
371  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
372  .pImageMemoryBarriers = img_bar,
373  .imageMemoryBarrierCount = nb_img_bar,
374  });
375 
376  for (int i = 0; i < 2; i++) {
377  FFVulkanShader *shd = shd_list[i];
378  AVFrame *src_f = !i ? in : tmp;
379  AVFrame *dst_f = !i ? tmp : out;
380  VkImageView *src_views = !i ? in_views : tmp_views;
381  VkImageView *dst_views = !i ? tmp_views : out_views;
382 
383  ff_vk_shader_update_img_array(vkctx, exec, shd, src_f, src_views, 0, 0,
384  !i ? in_layout :
385  VK_IMAGE_LAYOUT_GENERAL,
386  sampler);
387  ff_vk_shader_update_img_array(vkctx, exec, shd, dst_f, dst_views, 0, 1,
388  VK_IMAGE_LAYOUT_GENERAL,
389  VK_NULL_HANDLE);
390 
391  /* Bind pipeline, update push data */
392  ff_vk_exec_bind_shader(vkctx, exec, shd);
393  if (push_src)
394  ff_vk_shader_update_push_const(vkctx, exec, shd, VK_SHADER_STAGE_COMPUTE_BIT,
395  0, push_size, push_src);
396 
397  vk->CmdDispatch(exec->buf,
398  FFALIGN(vkctx->output_width, shd->lg_size[0])/shd->lg_size[0],
399  FFALIGN(vkctx->output_height, shd->lg_size[1])/shd->lg_size[1],
400  wgc_z);
401  }
402 
403  return ff_vk_exec_submit(vkctx, exec);
404 fail:
405  ff_vk_exec_discard_deps(vkctx, exec);
406  return err;
407 }
408 
410  FFVulkanShader *shd,
411  AVFrame *out, AVFrame *in[], int nb_in,
412  VkSampler sampler, uint32_t wgc_z,
413  void *push_src, size_t push_size)
414 {
415  int err = 0;
416  FFVulkanFunctions *vk = &vkctx->vkfn;
417  VkImageView in_views[16][AV_NUM_DATA_POINTERS];
418  VkImageView out_views[AV_NUM_DATA_POINTERS];
419  VkImageMemoryBarrier2 img_bar[128];
420  int nb_img_bar = 0;
421  VkImageLayout in_layout = sampler != VK_NULL_HANDLE ?
422  VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL :
423  VK_IMAGE_LAYOUT_GENERAL;
424 
425  /* Update descriptors and init the exec context */
426  FFVkExecContext *exec = ff_vk_exec_get(vkctx, e);
427  ff_vk_exec_start(vkctx, exec);
428 
429  /* Add deps and create temporary imageviews */
430  RET(ff_vk_exec_add_dep_frame(vkctx, exec, out,
431  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
432  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
433  RET(ff_vk_create_imageviews(vkctx, exec, out_views, out, FF_VK_REP_FLOAT));
434  for (int i = 0; i < nb_in; i++) {
435  RET(ff_vk_exec_add_dep_frame(vkctx, exec, in[i],
436  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
437  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
438  RET(ff_vk_create_imageviews(vkctx, exec, in_views[i], in[i], FF_VK_REP_FLOAT));
439  }
440 
441  /* Update descriptor sets */
442  ff_vk_shader_update_img_array(vkctx, exec, shd, out, out_views, 0, nb_in,
443  VK_IMAGE_LAYOUT_GENERAL,
444  VK_NULL_HANDLE);
445  for (int i = 0; i < nb_in; i++)
446  ff_vk_shader_update_img_array(vkctx, exec, shd, in[i], in_views[i], 0, i,
447  in_layout,
448  sampler);
449 
450  /* Bind pipeline, update push data */
451  ff_vk_exec_bind_shader(vkctx, exec, shd);
452  if (push_src)
453  ff_vk_shader_update_push_const(vkctx, exec, shd, VK_SHADER_STAGE_COMPUTE_BIT,
454  0, push_size, push_src);
455 
456  /* Add data sync barriers */
457  ff_vk_frame_barrier(vkctx, exec, out, img_bar, &nb_img_bar,
458  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
459  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
460  VK_ACCESS_SHADER_WRITE_BIT,
461  VK_IMAGE_LAYOUT_GENERAL,
462  VK_QUEUE_FAMILY_IGNORED);
463  for (int i = 0; i < nb_in; i++)
464  ff_vk_frame_barrier(vkctx, exec, in[i], img_bar, &nb_img_bar,
465  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
466  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
467  VK_ACCESS_SHADER_READ_BIT,
468  in_layout,
469  VK_QUEUE_FAMILY_IGNORED);
470 
471  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
472  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
473  .pImageMemoryBarriers = img_bar,
474  .imageMemoryBarrierCount = nb_img_bar,
475  });
476 
477  vk->CmdDispatch(exec->buf,
478  FFALIGN(vkctx->output_width, shd->lg_size[0])/shd->lg_size[0],
479  FFALIGN(vkctx->output_height, shd->lg_size[1])/shd->lg_size[1],
480  wgc_z);
481 
482  return ff_vk_exec_submit(vkctx, exec);
483 fail:
484  ff_vk_exec_discard_deps(vkctx, exec);
485  return err;
486 }
vulkan_loader.h
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:88
ff_vk_load_props
int ff_vk_load_props(FFVulkanContext *s)
Loads props/mprops/driver_props.
Definition: vulkan.c:147
AVVulkanDeviceContext::phys_dev
VkPhysicalDevice phys_dev
Physical device.
Definition: hwcontext_vulkan.h:79
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
FFVulkanContext::output_height
int output_height
Definition: vulkan.h:361
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
static FILE * out
Definition: movenc.c:55
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
RET
#define RET(x)
Definition: vulkan.h:68
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:200
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:337
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:435
ff_vk_filter_init
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
Definition: vulkan_filter.c:233
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:263
filters.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
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:356
ff_vk_exec_get
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition: vulkan.c:558
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:220
ff_vk_exec_bind_shader
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition: vulkan.c:2797
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
ff_vk_exec_add_dep_frame
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
Definition: vulkan.c:790
ff_vk_filter_process_Nin
int ff_vk_filter_process_Nin(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanShader *shd, AVFrame *out, AVFrame *in[], int nb_in, VkSampler sampler, uint32_t wgc_z, void *push_src, size_t push_size)
Up to 16 inputs, one output.
Definition: vulkan_filter.c:409
ff_vk_filter_process_simple
int ff_vk_filter_process_simple(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanShader *shd, AVFrame *out_f, AVFrame *in_f, VkSampler sampler, uint32_t wgc_z, 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:242
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:289
fail
#define fail()
Definition: checkasm.h:224
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
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:2748
AVVulkanFramesContext
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
Definition: hwcontext_vulkan.h:220
ff_vk_frame_barrier
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e, AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar, VkPipelineStageFlags2 src_stage, VkPipelineStageFlags2 dst_stage, VkAccessFlagBits2 new_access, VkImageLayout new_layout, uint32_t new_qf)
Definition: vulkan.c:2060
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:63
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
AVHWFramesContext::height
int height
Definition: hwcontext.h:220
FFVulkanContext::output_width
int output_width
Definition: vulkan.h:360
s
#define s(width, name)
Definition: cbs_vp9.c:198
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:131
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:199
FF_VK_REP_FLOAT
@ FF_VK_REP_FLOAT
Definition: vulkan.h:451
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
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:213
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
AVVulkanDeviceContext::nb_enabled_dev_extensions
int nb_enabled_dev_extensions
Definition: hwcontext_vulkan.h:117
AVHWFramesContext::device_ref
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:129
FF_VK_EXT_VIDEO_ENCODE_QUEUE
#define FF_VK_EXT_VIDEO_ENCODE_QUEUE
Definition: vulkan_functions.h:69
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:282
AVVulkanDeviceContext::enabled_inst_extensions
const char *const * enabled_inst_extensions
Enabled instance extensions.
Definition: hwcontext_vulkan.h:103
ff_vk_filter_config_output
int ff_vk_filter_config_output(AVFilterLink *outlink)
Definition: vulkan_filter.c:209
AVVulkanFramesContext::format
VkFormat format[AV_NUM_DATA_POINTERS]
Vulkan format for each image.
Definition: hwcontext_vulkan.h:281
AVVulkanFramesContext::usage
VkImageUsageFlagBits usage
Defines extra usage of output frames.
Definition: hwcontext_vulkan.h:240
FFVulkanContext
Definition: vulkan.h:312
FF_VK_EXT_VIDEO_MAINTENANCE_1
#define FF_VK_EXT_VIDEO_MAINTENANCE_1
Definition: vulkan_functions.h:60
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:2787
height
#define height
Definition: dsp.h:89
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:436
FFVulkanShader
Definition: vulkan.h:225
FFVkExecContext
Definition: vulkan.h:145
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:570
VkFormat
enum VkFormat VkFormat
Definition: hwcontext_stub.c:25
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:118
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:1977
FFVulkanContext::vkfn
FFVulkanFunctions vkfn
Definition: vulkan.h:316
AVHWFramesContext::hwctx
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition: hwcontext.h:153
FFVkExecPool
Definition: vulkan.h:290
FFVkExecContext::buf
VkCommandBuffer buf
Definition: vulkan.h:156
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
ff_vk_filter_process_2pass
int ff_vk_filter_process_2pass(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanShader *shd_list[2], AVFrame *out, AVFrame *tmp, AVFrame *in, VkSampler sampler, uint32_t wgc_z, 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:316
FFVulkanShader::lg_size
uint32_t lg_size[3]
Definition: vulkan.h:237
AVVulkanFramesContext::tiling
VkImageTiling tiling
Controls the tiling of allocated frames.
Definition: hwcontext_vulkan.h:229
AVFilterContext
An instance of a filter.
Definition: avfilter.h:274
AVVulkanDeviceContext::enabled_dev_extensions
const char *const * enabled_dev_extensions
Enabled device extensions.
Definition: hwcontext_vulkan.h:116
ff_vk_filter_config_input
int ff_vk_filter_config_input(AVFilterLink *inlink)
Definition: vulkan_filter.c:176
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVVulkanDeviceContext::nb_enabled_inst_extensions
int nb_enabled_inst_extensions
Definition: hwcontext_vulkan.h:104
ff_vk_exec_discard_deps
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:602
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:915
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
width
#define width
Definition: dsp.h:89
FFVulkanFunctions
Definition: vulkan_functions.h:275
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:383