FFmpeg
vf_gblur_vulkan.c
Go to the documentation of this file.
1 /*
2  * copyright (c) 2021 Wu Jianhua <jianhua.wu@intel.com>
3  * This file is part of FFmpeg.
4  *
5  * FFmpeg is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * FFmpeg is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with FFmpeg; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #include "libavutil/random_seed.h"
21 #include "libavutil/opt.h"
22 #include "vulkan_filter.h"
23 #include "internal.h"
24 
25 #define CGS 32
26 #define GBLUR_MAX_KERNEL_SIZE 127
27 
28 typedef struct GBlurVulkanContext {
36 
37  VkDescriptorImageInfo input_images[3];
38  VkDescriptorImageInfo tmp_images[3];
39  VkDescriptorImageInfo output_images[3];
40  VkDescriptorBufferInfo params_desc_hor;
41  VkDescriptorBufferInfo params_desc_ver;
42 
44  int size;
45  int planes;
47  float sigma;
48  float sigmaV;
51 
52 static const char gblur_horizontal[] = {
53  C(0, void gblur(const ivec2 pos, const int index) )
54  C(0, { )
55  C(1, vec4 sum = texture(input_image[index], pos) * kernel[0]; )
56  C(0, )
57  C(1, for(int i = 1; i < kernel.length(); i++) { )
58  C(2, sum += texture(input_image[index], pos + vec2(i, 0.0)) * kernel[i]; )
59  C(2, sum += texture(input_image[index], pos - vec2(i, 0.0)) * kernel[i]; )
60  C(1, } )
61  C(0, )
62  C(1, imageStore(output_image[index], pos, sum); )
63  C(0, } )
64 };
65 
66 static const char gblur_vertical[] = {
67  C(0, void gblur(const ivec2 pos, const int index) )
68  C(0, { )
69  C(1, vec4 sum = texture(input_image[index], pos) * kernel[0]; )
70  C(0, )
71  C(1, for(int i = 1; i < kernel.length(); i++) { )
72  C(2, sum += texture(input_image[index], pos + vec2(0.0, i)) * kernel[i]; )
73  C(2, sum += texture(input_image[index], pos - vec2(0.0, i)) * kernel[i]; )
74  C(1, } )
75  C(0, )
76  C(1, imageStore(output_image[index], pos, sum); )
77  C(0, } )
78 };
79 
80 static inline float gaussian(float sigma, float x)
81 {
82  return 1.0 / (sqrt(2.0 * M_PI) * sigma) *
83  exp(-(x * x) / (2.0 * sigma * sigma));
84 }
85 
86 static inline float gaussian_simpson_integration(float sigma, float a, float b)
87 {
88  return (b - a) * (1.0 / 6.0) * ((gaussian(sigma, a) +
89  4.0 * gaussian(sigma, (a + b) * 0.5) + gaussian(sigma, b)));
90 }
91 
92 static void init_gaussian_kernel(float *kernel, float sigma, float kernel_size)
93 {
94  int x;
95  float sum;
96 
97  sum = 0;
98  for (x = 0; x < kernel_size; x++) {
99  kernel[x] = gaussian_simpson_integration(sigma, x - 0.5f, x + 0.5f);
100  if (!x)
101  sum += kernel[x];
102  else
103  sum += kernel[x] * 2.0;
104  }
105  /* Normalized */
106  sum = 1.0 / sum;
107  for (x = 0; x < kernel_size; x++) {
108  kernel[x] *= sum;
109  }
110 }
111 
113 {
114  if (!(s->size & 1)) {
115  av_log(s, AV_LOG_WARNING, "kernel size should be odd\n");
116  s->size++;
117  }
118  if (s->sigmaV <= 0)
119  s->sigmaV = s->sigma;
120 
121  s->kernel_size = (s->size >> 1) + 1;
122  s->tmpframe = NULL;
123 }
124 
126 {
127  int err = 0;
128  char *kernel_def;
129  uint8_t *kernel_mapped;
130  FFVkSPIRVShader *shd;
131  GBlurVulkanContext *s = ctx->priv;
132  const int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
133 
134  FFVulkanDescriptorSetBinding image_descs[] = {
135  {
136  .name = "input_image",
137  .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
138  .dimensions = 2,
139  .elems = planes,
140  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
141  },
142  {
143  .name = "output_image",
144  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
145  .mem_layout = ff_vk_shader_rep_fmt(s->vkctx.output_format),
146  .mem_quali = "writeonly",
147  .dimensions = 2,
148  .elems = planes,
149  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
150  },
151  };
152 
153  FFVulkanDescriptorSetBinding buf_desc = {
154  .name = "data",
155  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
156  .mem_quali = "readonly",
157  .mem_layout = "std430",
158  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
159  .updater = NULL,
160  .buf_content = NULL,
161  };
162 
163  image_descs[0].sampler = ff_vk_init_sampler(&s->vkctx, 1, VK_FILTER_LINEAR);
164  if (!image_descs[0].sampler)
165  return AVERROR_EXTERNAL;
166 
168 
169  kernel_def = av_asprintf("float kernel[%i];", s->kernel_size);
170  if (!kernel_def)
171  return AVERROR(ENOMEM);
172 
173  buf_desc.buf_content = kernel_def;
174 
175  ff_vk_qf_init(&s->vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT, 0);
176 
177  { /* Create shader for the horizontal pass */
178  image_descs[0].updater = s->input_images;
179  image_descs[1].updater = s->tmp_images;
180  buf_desc.updater = &s->params_desc_hor;
181 
182  s->pl_hor = ff_vk_create_pipeline(&s->vkctx, &s->qf);
183  if (!s->pl_hor) {
184  err = AVERROR(ENOMEM);
185  goto fail;
186  }
187 
188  shd = ff_vk_init_shader(s->pl_hor, "gblur_compute_hor", image_descs[0].stages);
189  if (!shd) {
190  err = AVERROR(ENOMEM);
191  goto fail;
192  }
193 
194  ff_vk_set_compute_shader_sizes(shd, (int [3]){ CGS, CGS, 1 });
195  RET(ff_vk_add_descriptor_set(&s->vkctx, s->pl_hor, shd, image_descs, FF_ARRAY_ELEMS(image_descs), 0));
196  RET(ff_vk_add_descriptor_set(&s->vkctx, s->pl_hor, shd, &buf_desc, 1, 0));
197 
199  GLSLC(0, void main() );
200  GLSLC(0, { );
201  GLSLC(1, ivec2 size; );
202  GLSLC(1, const ivec2 pos = ivec2(gl_GlobalInvocationID.xy); );
203  for (int i = 0; i < planes; i++) {
204  GLSLC(0, );
205  GLSLF(1, size = imageSize(output_image[%i]); ,i);
206  GLSLC(1, if (IS_WITHIN(pos, size)) { );
207  if (s->planes & (1 << i)) {
208  GLSLF(2, gblur(pos, %i); ,i);
209  } else {
210  GLSLF(2, vec4 res = texture(input_image[%i], pos); ,i);
211  GLSLF(2, imageStore(output_image[%i], pos, res); ,i);
212  }
213  GLSLC(1, } );
214  }
215  GLSLC(0, } );
216 
217  RET(ff_vk_compile_shader(&s->vkctx, shd, "main"));
218 
219  RET(ff_vk_init_pipeline_layout(&s->vkctx, s->pl_hor));
220  RET(ff_vk_init_compute_pipeline(&s->vkctx, s->pl_hor));
221 
222  RET(ff_vk_create_buf(&s->vkctx, &s->params_buf_hor, sizeof(float) * s->kernel_size,
223  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
224  RET(ff_vk_map_buffers(&s->vkctx, &s->params_buf_hor, &kernel_mapped, 1, 0));
225 
226  init_gaussian_kernel((float *)kernel_mapped, s->sigma, s->kernel_size);
227 
228  RET(ff_vk_unmap_buffers(&s->vkctx, &s->params_buf_hor, 1, 1));
229 
230  s->params_desc_hor.buffer = s->params_buf_hor.buf;
231  s->params_desc_hor.range = VK_WHOLE_SIZE;
232 
233  ff_vk_update_descriptor_set(&s->vkctx, s->pl_hor, 1);
234  }
235 
236  { /* Create shader for the vertical pass */
237  image_descs[0].updater = s->tmp_images;
238  image_descs[1].updater = s->output_images;
239  buf_desc.updater = &s->params_desc_ver;
240 
241  s->pl_ver = ff_vk_create_pipeline(&s->vkctx, &s->qf);
242  if (!s->pl_ver) {
243  err = AVERROR(ENOMEM);
244  goto fail;
245  }
246 
247  shd = ff_vk_init_shader(s->pl_ver, "gblur_compute_ver", image_descs[0].stages);
248  if (!shd) {
249  err = AVERROR(ENOMEM);
250  goto fail;
251  }
252 
253  ff_vk_set_compute_shader_sizes(shd, (int [3]){ CGS, CGS, 1 });
254  RET(ff_vk_add_descriptor_set(&s->vkctx, s->pl_ver, shd, image_descs, FF_ARRAY_ELEMS(image_descs), 0));
255  RET(ff_vk_add_descriptor_set(&s->vkctx, s->pl_ver, shd, &buf_desc, 1, 0));
256 
258  GLSLC(0, void main() );
259  GLSLC(0, { );
260  GLSLC(1, ivec2 size; );
261  GLSLC(1, const ivec2 pos = ivec2(gl_GlobalInvocationID.xy); );
262  for (int i = 0; i < planes; i++) {
263  GLSLC(0, );
264  GLSLF(1, size = imageSize(output_image[%i]); ,i);
265  GLSLC(1, if (IS_WITHIN(pos, size)) { );
266  if (s->planes & (1 << i)) {
267  GLSLF(2, gblur(pos, %i); ,i);
268  } else {
269  GLSLF(2, vec4 res = texture(input_image[%i], pos); ,i);
270  GLSLF(2, imageStore(output_image[%i], pos, res); ,i);
271  }
272  GLSLC(1, } );
273  }
274  GLSLC(0, } );
275 
276  RET(ff_vk_compile_shader(&s->vkctx, shd, "main"));
277 
278  RET(ff_vk_init_pipeline_layout(&s->vkctx, s->pl_ver));
279  RET(ff_vk_init_compute_pipeline(&s->vkctx, s->pl_ver));
280 
281  RET(ff_vk_create_buf(&s->vkctx, &s->params_buf_ver, sizeof(float) * s->kernel_size,
282  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
283  RET(ff_vk_map_buffers(&s->vkctx, &s->params_buf_ver, &kernel_mapped, 1, 0));
284 
285  init_gaussian_kernel((float *)kernel_mapped, s->sigmaV, s->kernel_size);
286 
287  RET(ff_vk_unmap_buffers(&s->vkctx, &s->params_buf_ver, 1, 1));
288 
289  s->params_desc_ver.buffer = s->params_buf_ver.buf;
290  s->params_desc_ver.range = VK_WHOLE_SIZE;
291 
292  ff_vk_update_descriptor_set(&s->vkctx, s->pl_ver, 1);
293  }
294 
295  RET(ff_vk_create_exec_ctx(&s->vkctx, &s->exec, &s->qf));
296 
297  s->initialized = 1;
298 
299 fail:
300  av_free(kernel_def);
301  return err;
302 }
303 
305 {
306  GBlurVulkanContext *s = avctx->priv;
307 
308  av_frame_free(&s->tmpframe);
309 
310  ff_vk_free_buf(&s->vkctx, &s->params_buf_hor);
311  ff_vk_free_buf(&s->vkctx, &s->params_buf_ver);
312  ff_vk_uninit(&s->vkctx);
313 
314  s->initialized = 0;
315 }
316 
317 static int process_frames(AVFilterContext *avctx, AVFrame *outframe, AVFrame *inframe)
318 {
319  int err;
320  VkCommandBuffer cmd_buf;
321 
322  const VkFormat *input_formats = NULL;
323  const VkFormat *output_formats = NULL;
324  GBlurVulkanContext *s = avctx->priv;
325  FFVulkanFunctions *vk = &s->vkctx.vkfn;
326  AVVkFrame *in = (AVVkFrame *)inframe->data[0];
327  AVVkFrame *tmp = (AVVkFrame *)s->tmpframe->data[0];
328  AVVkFrame *out = (AVVkFrame *)outframe->data[0];
329 
330  int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
331 
332  ff_vk_start_exec_recording(&s->vkctx, s->exec);
333  cmd_buf = ff_vk_get_exec_buf(s->exec);
334 
335  input_formats = av_vkfmt_from_pixfmt(s->vkctx.input_format);
336  output_formats = av_vkfmt_from_pixfmt(s->vkctx.output_format);
337  for (int i = 0; i < planes; i++) {
338  RET(ff_vk_create_imageview(&s->vkctx, s->exec, &s->input_images[i].imageView,
339  in->img[i],
340  input_formats[i],
342 
343  RET(ff_vk_create_imageview(&s->vkctx, s->exec, &s->tmp_images[i].imageView,
344  tmp->img[i],
345  output_formats[i],
347 
348  RET(ff_vk_create_imageview(&s->vkctx, s->exec, &s->output_images[i].imageView,
349  out->img[i],
350  output_formats[i],
352 
353  s->input_images[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
354  s->tmp_images[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
355  s->output_images[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
356  }
357 
358  ff_vk_update_descriptor_set(&s->vkctx, s->pl_hor, 0);
359  ff_vk_update_descriptor_set(&s->vkctx, s->pl_ver, 0);
360 
361  for (int i = 0; i < planes; i++) {
362  VkImageMemoryBarrier barriers[] = {
363  {
364  .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
365  .srcAccessMask = 0,
366  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
367  .oldLayout = in->layout[i],
368  .newLayout = s->input_images[i].imageLayout,
369  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
370  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
371  .image = in->img[i],
372  .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
373  .subresourceRange.levelCount = 1,
374  .subresourceRange.layerCount = 1,
375  },
376  {
377  .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
378  .srcAccessMask = 0,
379  .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_SHADER_READ_BIT,
380  .oldLayout = tmp->layout[i],
381  .newLayout = s->tmp_images[i].imageLayout,
382  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
383  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
384  .image = tmp->img[i],
385  .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
386  .subresourceRange.levelCount = 1,
387  .subresourceRange.layerCount = 1,
388  },
389  {
390  .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
391  .srcAccessMask = 0,
392  .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
393  .oldLayout = out->layout[i],
394  .newLayout = s->output_images[i].imageLayout,
395  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
396  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
397  .image = out->img[i],
398  .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
399  .subresourceRange.levelCount = 1,
400  .subresourceRange.layerCount = 1,
401  },
402  };
403 
404  vk->CmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
405  VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0,
406  0, NULL, 0, NULL, FF_ARRAY_ELEMS(barriers), barriers);
407 
408  in->layout[i] = barriers[0].newLayout;
409  in->access[i] = barriers[0].dstAccessMask;
410 
411  tmp->layout[i] = barriers[1].newLayout;
412  tmp->access[i] = barriers[1].dstAccessMask;
413 
414  out->layout[i] = barriers[2].newLayout;
415  out->access[i] = barriers[2].dstAccessMask;
416  }
417 
418  ff_vk_bind_pipeline_exec(&s->vkctx, s->exec, s->pl_hor);
419 
420  vk->CmdDispatch(cmd_buf, FFALIGN(s->vkctx.output_width, CGS)/CGS,
421  FFALIGN(s->vkctx.output_height, CGS)/CGS, 1);
422 
423  ff_vk_bind_pipeline_exec(&s->vkctx, s->exec, s->pl_ver);
424 
425  vk->CmdDispatch(cmd_buf, FFALIGN(s->vkctx.output_width, CGS)/CGS,
426  FFALIGN(s->vkctx.output_height, CGS)/CGS, 1);
427 
428  ff_vk_add_exec_dep(&s->vkctx, s->exec, inframe, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
429  ff_vk_add_exec_dep(&s->vkctx, s->exec, outframe, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
430 
431  err = ff_vk_submit_exec_queue(&s->vkctx, s->exec);
432  if (err)
433  return err;
434 
435  ff_vk_qf_rotate(&s->qf);
436 
437  return 0;
438 fail:
439  ff_vk_discard_exec_deps(s->exec);
440  return err;
441 }
442 
444 {
445  int err;
446  AVFrame *out = NULL;
447  AVFilterContext *ctx = link->dst;
448  GBlurVulkanContext *s = ctx->priv;
449  AVFilterLink *outlink = ctx->outputs[0];
450 
451  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
452  if (!out) {
453  err = AVERROR(ENOMEM);
454  goto fail;
455  }
456 
457  if (!s->initialized) {
458  RET(init_filter(ctx, in));
459  s->tmpframe = ff_get_video_buffer(outlink, outlink->w, outlink->h);
460  if (!s->tmpframe) {
461  err = AVERROR(ENOMEM);
462  goto fail;
463  }
464  }
465 
466  RET(process_frames(ctx, out, in));
467 
469 
470  av_frame_free(&in);
471 
472  return ff_filter_frame(outlink, out);
473 
474 fail:
475  av_frame_free(&in);
476  av_frame_free(&out);
477  av_frame_free(&s->tmpframe);
478 
479  return err;
480 }
481 
482 #define OFFSET(x) offsetof(GBlurVulkanContext, x)
483 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
484 static const AVOption gblur_vulkan_options[] = {
485  { "sigma", "Set sigma", OFFSET(sigma), AV_OPT_TYPE_FLOAT, {.dbl = 0.5}, 0.01, 1024.0, FLAGS },
486  { "sigmaV", "Set vertical sigma", OFFSET(sigmaV), AV_OPT_TYPE_FLOAT, {.dbl = 0}, 0.0, 1024.0, FLAGS },
487  { "planes", "Set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64 = 0xF}, 0, 0xF, FLAGS },
488  { "size", "Set kernel size", OFFSET(size), AV_OPT_TYPE_INT, {.i64 = 19}, 1, GBLUR_MAX_KERNEL_SIZE, FLAGS },
489  { NULL },
490 };
491 
492 AVFILTER_DEFINE_CLASS(gblur_vulkan);
493 
495  {
496  .name = "default",
497  .type = AVMEDIA_TYPE_VIDEO,
498  .filter_frame = &gblur_vulkan_filter_frame,
499  .config_props = &ff_vk_filter_config_input,
500  }
501 };
502 
504  {
505  .name = "default",
506  .type = AVMEDIA_TYPE_VIDEO,
507  .config_props = &ff_vk_filter_config_output,
508  }
509 };
510 
512  .name = "gblur_vulkan",
513  .description = NULL_IF_CONFIG_SMALL("Gaussian Blur in Vulkan"),
514  .priv_size = sizeof(GBlurVulkanContext),
520  .priv_class = &gblur_vulkan_class,
521  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
522 };
GBlurVulkanContext::input_images
VkDescriptorImageInfo input_images[3]
Definition: vf_gblur_vulkan.c:37
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:98
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
gblur_horizontal
static const char gblur_horizontal[]
Definition: vf_gblur_vulkan.c:52
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(gblur_vulkan)
GBlurVulkanContext::sigma
float sigma
Definition: vf_gblur_vulkan.c:47
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
opt.h
ff_comp_identity_map
const VkComponentMapping ff_comp_identity_map
Definition: vulkan.c:51
out
FILE * out
Definition: movenc.c:54
FF_FILTER_FLAG_HWFRAME_AWARE
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: internal.h:371
ff_vk_create_buf
int ff_vk_create_buf(FFVulkanContext *s, FFVkBuffer *buf, size_t size, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags)
Create a VkBuffer with the specified parameters.
Definition: vulkan.c:193
gaussian_simpson_integration
static float gaussian_simpson_integration(float sigma, float a, float b)
Definition: vf_gblur_vulkan.c:86
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
FLAGS
#define FLAGS
Definition: vf_gblur_vulkan.c:483
ff_vk_bind_pipeline_exec
void ff_vk_bind_pipeline_exec(FFVulkanContext *s, FFVkExecContext *e, FFVulkanPipeline *pl)
Add a command to bind the completed pipeline and its descriptor sets.
Definition: vulkan.c:1263
OFFSET
#define OFFSET(x)
Definition: vf_gblur_vulkan.c:482
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:109
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
FFVulkanDescriptorSetBinding::stages
VkShaderStageFlags stages
Definition: vulkan.h:86
index
fg index
Definition: ffmpeg_filter.c:167
GBlurVulkanContext::planes
int planes
Definition: vf_gblur_vulkan.c:45
ff_vk_filter_init
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
Definition: vulkan_filter.c:184
AVOption
AVOption.
Definition: opt.h:247
b
#define b
Definition: input.c:40
GBlurVulkanContext::tmpframe
AVFrame * tmpframe
Definition: vf_gblur_vulkan.c:49
ff_vk_compile_shader
int ff_vk_compile_shader(FFVulkanContext *s, FFVkSPIRVShader *shd, const char *entrypoint)
Compiles the shader, entrypoint must be set to "main".
Definition: vulkan.c:848
GBlurVulkanContext::pl_hor
FFVulkanPipeline * pl_hor
Definition: vf_gblur_vulkan.c:32
GBlurVulkanContext::size
int size
Definition: vf_gblur_vulkan.c:44
GBlurVulkanContext::pl_ver
FFVulkanPipeline * pl_ver
Definition: vf_gblur_vulkan.c:33
ff_vk_uninit
void ff_vk_uninit(FFVulkanContext *s)
Frees the main Vulkan context.
Definition: vulkan.c:1378
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:169
FFVulkanDescriptorSetBinding::buf_content
const char * buf_content
Definition: vulkan.h:83
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:346
gblur_vulkan_inputs
static const AVFilterPad gblur_vulkan_inputs[]
Definition: vf_gblur_vulkan.c:494
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:338
init_gaussian_kernel
static void init_gaussian_kernel(float *kernel, float sigma, float kernel_size)
Definition: vf_gblur_vulkan.c:92
ff_vk_add_exec_dep
int ff_vk_add_exec_dep(FFVulkanContext *s, FFVkExecContext *e, AVFrame *frame, VkPipelineStageFlagBits in_wait_dst_flag)
Adds a frame as a queue dependency.
Definition: vulkan.c:509
init
static int init
Definition: av_tx.c:47
ff_vk_get_exec_buf
VkCommandBuffer ff_vk_get_exec_buf(FFVkExecContext *e)
Gets the command buffer to use for this submission from the exe context.
Definition: vulkan.c:504
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2700
GBlurVulkanContext::output_images
VkDescriptorImageInfo output_images[3]
Definition: vf_gblur_vulkan.c:39
AVVkFrame::img
VkImage img[AV_NUM_DATA_POINTERS]
Vulkan images to which the memory is bound to.
Definition: hwcontext_vulkan.h:217
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:417
CGS
#define CGS
Definition: vf_gblur_vulkan.c:25
fail
#define fail()
Definition: checkasm.h:127
vulkan_filter.h
GBlurVulkanContext::params_buf_ver
FFVkBuffer params_buf_ver
Definition: vf_gblur_vulkan.c:35
gblur_vulkan_outputs
static const AVFilterPad gblur_vulkan_outputs[]
Definition: vf_gblur_vulkan.c:503
GBlurVulkanContext::qf
FFVkQueueFamilyCtx qf
Definition: vf_gblur_vulkan.c:30
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
C
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going which in turn will define variables for the build system and the C
Definition: writing_filters.txt:58
ff_vk_qf_init
void ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, VkQueueFlagBits dev_family, int nb_queues)
Initialize a queue family with a specific number of queues.
Definition: vulkan.c:96
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
ff_vk_create_imageview
int ff_vk_create_imageview(FFVulkanContext *s, FFVkExecContext *e, VkImageView *v, VkImage img, VkFormat fmt, const VkComponentMapping map)
Create an imageview.
Definition: vulkan.c:742
s
#define s(width, name)
Definition: cbs_vp9.c:257
GBlurVulkanContext::params_desc_hor
VkDescriptorBufferInfo params_desc_hor
Definition: vf_gblur_vulkan.c:40
ff_vk_init_shader
FFVkSPIRVShader * ff_vk_init_shader(FFVulkanPipeline *pl, const char *name, VkShaderStageFlags stage)
Inits a shader for a specific pipeline.
Definition: vulkan.c:795
ctx
AVFormatContext * ctx
Definition: movenc.c:48
gblur_vulkan_options
static const AVOption gblur_vulkan_options[]
Definition: vf_gblur_vulkan.c:484
GBlurVulkanContext::tmp_images
VkDescriptorImageInfo tmp_images[3]
Definition: vf_gblur_vulkan.c:38
f
#define f(width, name)
Definition: cbs_vp9.c:255
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
link
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 link
Definition: filter_design.txt:23
init_filter
static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
Definition: vf_gblur_vulkan.c:125
ff_vk_update_descriptor_set
void ff_vk_update_descriptor_set(FFVulkanContext *s, FFVulkanPipeline *pl, int set_id)
Updates a descriptor set via the updaters defined.
Definition: vulkan.c:1079
planes
static const struct @321 planes[]
ff_vk_start_exec_recording
int ff_vk_start_exec_recording(FFVulkanContext *s, FFVkExecContext *e)
Begin recording to the command buffer.
Definition: vulkan.c:463
av_vkfmt_from_pixfmt
const VkFormat * av_vkfmt_from_pixfmt(enum AVPixelFormat p)
Returns the format of each image up to the number of planes for a given sw_format.
Definition: hwcontext_vulkan.c:238
main
int main(int argc, char *argv[])
Definition: avio_list_dir.c:112
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:537
GLSLD
#define GLSLD(D)
Definition: vulkan.h:47
ff_vk_create_exec_ctx
int ff_vk_create_exec_ctx(FFVulkanContext *s, FFVkExecContext **ctx, FFVkQueueFamilyCtx *qf)
Init an execution context for command recording and queue submission.
Definition: vulkan.c:385
ff_vk_filter_config_output
int ff_vk_filter_config_output(AVFilterLink *outlink)
Definition: vulkan_filter.c:133
ff_vk_qf_rotate
void ff_vk_qf_rotate(FFVkQueueFamilyCtx *qf)
Rotate through the queues in a queue family.
Definition: vulkan.c:132
GBlurVulkanContext::kernel_size
int kernel_size
Definition: vf_gblur_vulkan.c:46
FFVulkanDescriptorSetBinding::updater
void * updater
Definition: vulkan.h:88
FFVulkanContext
Definition: vulkan.h:188
GBLUR_MAX_KERNEL_SIZE
#define GBLUR_MAX_KERNEL_SIZE
Definition: vf_gblur_vulkan.c:26
exp
int8_t exp
Definition: eval.c:72
FFVulkanPipeline
Definition: vulkan.h:104
ff_vk_discard_exec_deps
void ff_vk_discard_exec_deps(FFVkExecContext *e)
Discards all queue dependencies.
Definition: vulkan.c:447
ff_vk_unmap_buffers
int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer *buf, int nb_buffers, int flush)
Unmaps the buffer from userspace.
Definition: vulkan.c:307
AVVkFrame::access
VkAccessFlagBits access[AV_NUM_DATA_POINTERS]
Updated after every barrier.
Definition: hwcontext_vulkan.h:240
GBlurVulkanContext::params_desc_ver
VkDescriptorBufferInfo params_desc_ver
Definition: vf_gblur_vulkan.c:41
FFVulkanDescriptorSetBinding
Definition: vulkan.h:78
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AVVkFrame
Definition: hwcontext_vulkan.h:213
GBlurVulkanContext::initialized
int initialized
Definition: vf_gblur_vulkan.c:43
ff_vk_init_pipeline_layout
int ff_vk_init_pipeline_layout(FFVulkanContext *s, FFVulkanPipeline *pl)
Initializes the pipeline layout after all shaders and descriptor sets have been finished.
Definition: vulkan.c:1115
size
int size
Definition: twinvq_data.h:10344
FFVkQueueFamilyCtx
Definition: vulkan.h:97
gblur_vertical
static const char gblur_vertical[]
Definition: vf_gblur_vulkan.c:66
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
GBlurVulkanContext
Definition: vf_gblur_vulkan.c:28
gblur_vulkan_uninit
static av_cold void gblur_vulkan_uninit(AVFilterContext *avctx)
Definition: vf_gblur_vulkan.c:304
ff_vk_submit_exec_queue
int ff_vk_submit_exec_queue(FFVulkanContext *s, FFVkExecContext *e)
Submits a command buffer to the queue for execution.
Definition: vulkan.c:590
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
FFVkExecContext
Definition: vulkan.h:154
FFVulkanDescriptorSetBinding::name
const char * name
Definition: vulkan.h:79
M_PI
#define M_PI
Definition: mathematics.h:52
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:227
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: internal.h:181
ff_vk_init_compute_pipeline
int ff_vk_init_compute_pipeline(FFVulkanContext *s, FFVulkanPipeline *pl)
Initializes a compute pipeline.
Definition: vulkan.c:1228
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
ff_vk_shader_rep_fmt
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pixfmt)
Gets the glsl format string for a pixel format.
Definition: vulkan.c:721
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
GLSLF
#define GLSLF(N, S,...)
Definition: vulkan.h:46
ff_vk_create_pipeline
FFVulkanPipeline * ff_vk_create_pipeline(FFVulkanContext *s, FFVkQueueFamilyCtx *qf)
Inits a pipeline.
Definition: vulkan.c:1219
ff_vk_free_buf
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
Frees a buffer.
Definition: vulkan.c:349
AVFilter
Filter definition.
Definition: avfilter.h:165
init_gaussian_params
static av_cold void init_gaussian_params(GBlurVulkanContext *s)
Definition: vf_gblur_vulkan.c:112
pos
unsigned int pos
Definition: spdifenc.c:412
gblur_vulkan_filter_frame
static int gblur_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_gblur_vulkan.c:443
ff_vk_add_descriptor_set
int ff_vk_add_descriptor_set(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkSPIRVShader *shd, FFVulkanDescriptorSetBinding *desc, int num, int only_print_to_shader)
Adds a descriptor set to the shader and registers them in the pipeline.
Definition: vulkan.c:922
random_seed.h
FFVkSPIRVShader
Definition: vulkan.h:58
ff_vf_gblur_vulkan
const AVFilter ff_vf_gblur_vulkan
Definition: vf_gblur_vulkan.c:511
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
FFVulkanDescriptorSetBinding::sampler
FFVkSampler * sampler
Definition: vulkan.h:87
ff_vk_init_sampler
FFVkSampler * ff_vk_init_sampler(FFVulkanContext *s, int unnorm_coords, VkFilter filt)
Create a Vulkan sampler, will be auto-freed in ff_vk_filter_uninit()
Definition: vulkan.c:670
AVFilterContext
An instance of a filter.
Definition: avfilter.h:402
GLSLC
#define GLSLC(N, S)
Definition: vulkan.h:44
ff_vk_filter_config_input
int ff_vk_filter_config_input(AVFilterLink *inlink)
Definition: vulkan_filter.c:52
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVVkFrame::layout
VkImageLayout layout[AV_NUM_DATA_POINTERS]
Definition: hwcontext_vulkan.h:241
GBlurVulkanContext::sigmaV
float sigmaV
Definition: vf_gblur_vulkan.c:48
ff_vk_map_buffers
int ff_vk_map_buffers(FFVulkanContext *s, FFVkBuffer *buf, uint8_t *mem[], int nb_buffers, int invalidate)
Maps the buffer to userspace.
Definition: vulkan.c:258
process_frames
static int process_frames(AVFilterContext *avctx, AVFrame *outframe, AVFrame *inframe)
Definition: vf_gblur_vulkan.c:317
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
ff_vk_set_compute_shader_sizes
void ff_vk_set_compute_shader_sizes(FFVkSPIRVShader *shd, int local_size[3])
Writes the workgroup size for a shader.
Definition: vulkan.c:816
FFVkBuffer
Definition: vulkan.h:91
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:282
GBlurVulkanContext::exec
FFVkExecContext * exec
Definition: vf_gblur_vulkan.c:31
RET
#define RET(x)
Definition: vulkan.h:52
FFVulkanFunctions
Definition: vulkan_functions.h:175
GBlurVulkanContext::params_buf_hor
FFVkBuffer params_buf_hor
Definition: vf_gblur_vulkan.c:34
GBlurVulkanContext::vkctx
FFVulkanContext vkctx
Definition: vf_gblur_vulkan.c:29
gaussian
static float gaussian(float sigma, float x)
Definition: vf_gblur_vulkan.c:80