FFmpeg
vf_gblur_vulkan.c
Go to the documentation of this file.
1 /*
2  * copyright (c) 2021-2022 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 sizeV;
46  int planes;
47  float sigma;
48  float sigmaV;
51 
52 static const char gblur_func[] = {
53  C(0, void gblur(const ivec2 pos, const int index) )
54  C(0, { )
55  C(1, vec4 sum = texture(input_images[index], pos) * kernel[0]; )
56  C(0, )
57  C(1, for(int i = 1; i < kernel.length(); i++) { )
58  C(2, sum += texture(input_images[index], pos + OFFSET) * kernel[i]; )
59  C(2, sum += texture(input_images[index], pos - OFFSET) * kernel[i]; )
60  C(1, } )
61  C(0, )
62  C(1, imageStore(output_images[index], pos, sum); )
63  C(0, } )
64 };
65 
66 static inline float gaussian(float sigma, float x)
67 {
68  return 1.0 / (sqrt(2.0 * M_PI) * sigma) *
69  exp(-(x * x) / (2.0 * sigma * sigma));
70 }
71 
72 static inline float gaussian_simpson_integration(float sigma, float a, float b)
73 {
74  return (b - a) * (1.0 / 6.0) * ((gaussian(sigma, a) +
75  4.0 * gaussian(sigma, (a + b) * 0.5) + gaussian(sigma, b)));
76 }
77 
78 static void init_gaussian_kernel(float *kernel, float sigma, float kernel_size)
79 {
80  int x;
81  float sum;
82 
83  sum = 0;
84  for (x = 0; x < kernel_size; x++) {
85  kernel[x] = gaussian_simpson_integration(sigma, x - 0.5f, x + 0.5f);
86  if (!x)
87  sum += kernel[x];
88  else
89  sum += kernel[x] * 2.0;
90  }
91  /* Normalized */
92  sum = 1.0 / sum;
93  for (x = 0; x < kernel_size; x++) {
94  kernel[x] *= sum;
95  }
96 }
97 
98 static inline void init_kernel_size(GBlurVulkanContext *s, int *out_size)
99 {
100  int size = *out_size;
101 
102  if (!(size & 1)) {
103  av_log(s, AV_LOG_WARNING, "The kernel size should be odd\n");
104  size++;
105  }
106 
107  *out_size = (size >> 1) + 1;
108 }
109 
111 {
112  if (s->sigmaV <= 0)
113  s->sigmaV = s->sigma;
114 
115  init_kernel_size(s, &s->size);
116 
117  if (s->sizeV <= 0)
118  s->sizeV = s->size;
119  else
120  init_kernel_size(s, &s->sizeV);
121 
122  s->tmpframe = NULL;
123 }
124 
126  FFVkBuffer *params_buf, VkDescriptorBufferInfo *params_desc,
127  int ksize, float sigma)
128 {
129  int err = 0;
130  uint8_t *kernel_mapped;
131 
132  const int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
133 
134  FFVulkanDescriptorSetBinding buf_desc = {
135  .name = "data",
136  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
137  .mem_quali = "readonly",
138  .mem_layout = "std430",
139  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
140  .updater = NULL,
141  .buf_content = NULL,
142  };
143 
144  char *kernel_def = av_asprintf("float kernel[%i];", ksize);
145  if (!kernel_def)
146  return AVERROR(ENOMEM);
147 
148  buf_desc.updater = params_desc;
149  buf_desc.buf_content = kernel_def;
150 
151  RET(ff_vk_add_descriptor_set(&s->vkctx, pl, shd, &buf_desc, 1, 0));
152 
153  GLSLD( gblur_func );
154  GLSLC(0, void main() );
155  GLSLC(0, { );
156  GLSLC(1, ivec2 size; );
157  GLSLC(1, const ivec2 pos = ivec2(gl_GlobalInvocationID.xy); );
158  for (int i = 0; i < planes; i++) {
159  GLSLC(0, );
160  GLSLF(1, size = imageSize(output_images[%i]); ,i);
161  GLSLC(1, if (IS_WITHIN(pos, size)) { );
162  if (s->planes & (1 << i)) {
163  GLSLF(2, gblur(pos, %i); ,i);
164  } else {
165  GLSLF(2, vec4 res = texture(input_images[%i], pos); ,i);
166  GLSLF(2, imageStore(output_images[%i], pos, res); ,i);
167  }
168  GLSLC(1, } );
169  }
170  GLSLC(0, } );
171 
172  RET(ff_vk_compile_shader(&s->vkctx, shd, "main"));
173 
174  RET(ff_vk_init_pipeline_layout(&s->vkctx, pl));
175  RET(ff_vk_init_compute_pipeline(&s->vkctx, pl));
176 
177  RET(ff_vk_create_buf(&s->vkctx, params_buf, sizeof(float) * ksize,
178  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
179  RET(ff_vk_map_buffers(&s->vkctx, params_buf, &kernel_mapped, 1, 0));
180 
181  init_gaussian_kernel((float *)kernel_mapped, sigma, ksize);
182 
183  RET(ff_vk_unmap_buffers(&s->vkctx, params_buf, 1, 1));
184 
185  params_desc->buffer = params_buf->buf;
186  params_desc->range = VK_WHOLE_SIZE;
187 
188  ff_vk_update_descriptor_set(&s->vkctx, pl, 1);
189 
190 fail:
191  av_free(kernel_def);
192  return err;
193 }
194 
196 {
197  int err = 0;
198  GBlurVulkanContext *s = ctx->priv;
199  FFVkSPIRVShader *shd;
200  const int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
201 
202  FFVulkanDescriptorSetBinding image_descs[] = {
203  {
204  .name = "input_images",
205  .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
206  .dimensions = 2,
207  .elems = planes,
208  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
209  },
210  {
211  .name = "output_images",
212  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
213  .mem_layout = ff_vk_shader_rep_fmt(s->vkctx.output_format),
214  .mem_quali = "writeonly",
215  .dimensions = 2,
216  .elems = planes,
217  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
218  },
219  };
220 
221  image_descs[0].sampler = ff_vk_init_sampler(&s->vkctx, 1, VK_FILTER_LINEAR);
222  if (!image_descs[0].sampler)
223  return AVERROR_EXTERNAL;
224 
226 
227  ff_vk_qf_init(&s->vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT, 0);
228 
229  {
230  /* Create shader for the horizontal pass */
231  image_descs[0].updater = s->input_images;
232  image_descs[1].updater = s->tmp_images;
233 
234  s->pl_hor = ff_vk_create_pipeline(&s->vkctx, &s->qf);
235  if (!s->pl_hor) {
236  err = AVERROR(ENOMEM);
237  goto fail;
238  }
239 
240  shd = ff_vk_init_shader(s->pl_hor, "gblur_compute_hor", image_descs[0].stages);
241  if (!shd) {
242  err = AVERROR(ENOMEM);
243  goto fail;
244  }
245 
246  ff_vk_set_compute_shader_sizes(shd, (int [3]){ CGS, 1, 1 });
247  RET(ff_vk_add_descriptor_set(&s->vkctx, s->pl_hor, shd, image_descs, FF_ARRAY_ELEMS(image_descs), 0));
248 
249  GLSLC(0, #define OFFSET (vec2(i, 0.0)));
250  RET(init_gblur_pipeline(s, s->pl_hor, shd, &s->params_buf_hor, &s->params_desc_hor,
251  s->size, s->sigma));
252  }
253 
254  {
255  /* Create shader for the vertical pass */
256  image_descs[0].updater = s->tmp_images;
257  image_descs[1].updater = s->output_images;
258 
259  s->pl_ver = ff_vk_create_pipeline(&s->vkctx, &s->qf);
260  if (!s->pl_ver) {
261  err = AVERROR(ENOMEM);
262  goto fail;
263  }
264 
265  shd = ff_vk_init_shader(s->pl_ver, "gblur_compute_ver", image_descs[0].stages);
266  if (!shd) {
267  err = AVERROR(ENOMEM);
268  goto fail;
269  }
270 
271  ff_vk_set_compute_shader_sizes(shd, (int [3]){ 1, CGS, 1 });
272  RET(ff_vk_add_descriptor_set(&s->vkctx, s->pl_ver, shd, image_descs, FF_ARRAY_ELEMS(image_descs), 0));
273 
274  GLSLC(0, #define OFFSET (vec2(0.0, i)));
275  RET(init_gblur_pipeline(s, s->pl_ver, shd, &s->params_buf_ver, &s->params_desc_ver,
276  s->sizeV, s->sigmaV));
277  }
278 
279  RET(ff_vk_create_exec_ctx(&s->vkctx, &s->exec, &s->qf));
280 
281  s->initialized = 1;
282 
283 fail:
284  return err;
285 }
286 
288 {
289  GBlurVulkanContext *s = avctx->priv;
290 
291  av_frame_free(&s->tmpframe);
292 
293  ff_vk_free_buf(&s->vkctx, &s->params_buf_hor);
294  ff_vk_free_buf(&s->vkctx, &s->params_buf_ver);
295  ff_vk_uninit(&s->vkctx);
296 
297  s->initialized = 0;
298 }
299 
300 static int process_frames(AVFilterContext *avctx, AVFrame *outframe, AVFrame *inframe)
301 {
302  int err;
303  VkCommandBuffer cmd_buf;
304  GBlurVulkanContext *s = avctx->priv;
305  FFVulkanFunctions *vk = &s->vkctx.vkfn;
306 
307  const int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
308 
309  AVVkFrame *in = (AVVkFrame *)inframe->data[0];
310  AVVkFrame *out = (AVVkFrame *)outframe->data[0];
311  AVVkFrame *tmp = (AVVkFrame *)s->tmpframe->data[0];
312 
313  const VkFormat *input_formats = av_vkfmt_from_pixfmt(s->vkctx.input_format);
314  const VkFormat *output_formats = av_vkfmt_from_pixfmt(s->vkctx.output_format);
315 
316  ff_vk_start_exec_recording(&s->vkctx, s->exec);
317  cmd_buf = ff_vk_get_exec_buf(s->exec);
318 
319  for (int i = 0; i < planes; i++) {
320  RET(ff_vk_create_imageview(&s->vkctx, s->exec, &s->input_images[i].imageView,
321  in->img[i],
322  input_formats[i],
324 
325  RET(ff_vk_create_imageview(&s->vkctx, s->exec, &s->tmp_images[i].imageView,
326  tmp->img[i],
327  output_formats[i],
329 
330  RET(ff_vk_create_imageview(&s->vkctx, s->exec, &s->output_images[i].imageView,
331  out->img[i],
332  output_formats[i],
334 
335  s->input_images[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
336  s->tmp_images[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
337  s->output_images[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
338  }
339 
340  ff_vk_update_descriptor_set(&s->vkctx, s->pl_hor, 0);
341  ff_vk_update_descriptor_set(&s->vkctx, s->pl_ver, 0);
342 
343  for (int i = 0; i < planes; i++) {
344  VkImageMemoryBarrier barriers[] = {
345  {
346  .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
347  .srcAccessMask = 0,
348  .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
349  .oldLayout = in->layout[i],
350  .newLayout = s->input_images[i].imageLayout,
351  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
352  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
353  .image = in->img[i],
354  .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
355  .subresourceRange.levelCount = 1,
356  .subresourceRange.layerCount = 1,
357  },
358  {
359  .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
360  .srcAccessMask = 0,
361  .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_SHADER_READ_BIT,
362  .oldLayout = tmp->layout[i],
363  .newLayout = s->tmp_images[i].imageLayout,
364  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
365  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
366  .image = tmp->img[i],
367  .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
368  .subresourceRange.levelCount = 1,
369  .subresourceRange.layerCount = 1,
370  },
371  {
372  .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
373  .srcAccessMask = 0,
374  .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
375  .oldLayout = out->layout[i],
376  .newLayout = s->output_images[i].imageLayout,
377  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
378  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
379  .image = out->img[i],
380  .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
381  .subresourceRange.levelCount = 1,
382  .subresourceRange.layerCount = 1,
383  },
384  };
385 
386  vk->CmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
387  VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0,
388  0, NULL, 0, NULL, FF_ARRAY_ELEMS(barriers), barriers);
389 
390  in->layout[i] = barriers[0].newLayout;
391  in->access[i] = barriers[0].dstAccessMask;
392 
393  tmp->layout[i] = barriers[1].newLayout;
394  tmp->access[i] = barriers[1].dstAccessMask;
395 
396  out->layout[i] = barriers[2].newLayout;
397  out->access[i] = barriers[2].dstAccessMask;
398  }
399 
400  ff_vk_bind_pipeline_exec(&s->vkctx, s->exec, s->pl_hor);
401 
402  vk->CmdDispatch(cmd_buf, FFALIGN(s->vkctx.output_width, CGS)/CGS,
403  s->vkctx.output_height, 1);
404 
405  ff_vk_bind_pipeline_exec(&s->vkctx, s->exec, s->pl_ver);
406 
407  vk->CmdDispatch(cmd_buf,s->vkctx.output_width,
408  FFALIGN(s->vkctx.output_height, CGS)/CGS, 1);
409 
410  ff_vk_add_exec_dep(&s->vkctx, s->exec, inframe, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
411  ff_vk_add_exec_dep(&s->vkctx, s->exec, outframe, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
412 
413  err = ff_vk_submit_exec_queue(&s->vkctx, s->exec);
414  if (err)
415  return err;
416 
417  ff_vk_qf_rotate(&s->qf);
418 
419  return 0;
420 
421 fail:
422  ff_vk_discard_exec_deps(s->exec);
423  return err;
424 }
425 
427 {
428  int err;
429  AVFrame *out = NULL;
430  AVFilterContext *ctx = link->dst;
431  GBlurVulkanContext *s = ctx->priv;
432  AVFilterLink *outlink = ctx->outputs[0];
433 
434  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
435  if (!out) {
436  err = AVERROR(ENOMEM);
437  goto fail;
438  }
439 
440  if (!s->initialized) {
441  RET(init_filter(ctx, in));
442  s->tmpframe = ff_get_video_buffer(outlink, outlink->w, outlink->h);
443  if (!s->tmpframe) {
444  err = AVERROR(ENOMEM);
445  goto fail;
446  }
447  }
448 
449  RET(process_frames(ctx, out, in));
450 
452 
453  av_frame_free(&in);
454 
455  return ff_filter_frame(outlink, out);
456 
457 fail:
458  av_frame_free(&in);
459  av_frame_free(&out);
460  av_frame_free(&s->tmpframe);
461 
462  return err;
463 }
464 
465 #define OFFSET(x) offsetof(GBlurVulkanContext, x)
466 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
467 static const AVOption gblur_vulkan_options[] = {
468  { "sigma", "Set sigma", OFFSET(sigma), AV_OPT_TYPE_FLOAT, { .dbl = 0.5 }, 0.01, 1024.0, FLAGS },
469  { "sigmaV", "Set vertical sigma", OFFSET(sigmaV), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0.0, 1024.0, FLAGS },
470  { "planes", "Set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, { .i64 = 0xF }, 0, 0xF, FLAGS },
471  { "size", "Set kernel size", OFFSET(size), AV_OPT_TYPE_INT, { .i64 = 19 }, 1, GBLUR_MAX_KERNEL_SIZE, FLAGS },
472  { "sizeV", "Set vertical kernel size", OFFSET(sizeV), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, GBLUR_MAX_KERNEL_SIZE, FLAGS },
473  { NULL },
474 };
475 
476 AVFILTER_DEFINE_CLASS(gblur_vulkan);
477 
479  {
480  .name = "default",
481  .type = AVMEDIA_TYPE_VIDEO,
482  .filter_frame = &gblur_vulkan_filter_frame,
483  .config_props = &ff_vk_filter_config_input,
484  }
485 };
486 
488  {
489  .name = "default",
490  .type = AVMEDIA_TYPE_VIDEO,
491  .config_props = &ff_vk_filter_config_output,
492  }
493 };
494 
496  .name = "gblur_vulkan",
497  .description = NULL_IF_CONFIG_SMALL("Gaussian Blur in Vulkan"),
498  .priv_size = sizeof(GBlurVulkanContext),
504  .priv_class = &gblur_vulkan_class,
505  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
506 };
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:101
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
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:370
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:72
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1009
FLAGS
#define FLAGS
Definition: vf_gblur_vulkan.c:466
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:1264
OFFSET
#define OFFSET(x)
Definition: vf_gblur_vulkan.c:465
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:116
out_size
int out_size
Definition: movenc.c:55
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:116
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
FFVulkanDescriptorSetBinding::stages
VkShaderStageFlags stages
Definition: vulkan.h:86
GBlurVulkanContext::planes
int planes
Definition: vf_gblur_vulkan.c:46
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:251
b
#define b
Definition: input.c:41
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:849
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:1379
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:175
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:376
gblur_vulkan_inputs
static const AVFilterPad gblur_vulkan_inputs[]
Definition: vf_gblur_vulkan.c:478
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:346
init_gaussian_kernel
static void init_gaussian_kernel(float *kernel, float sigma, float kernel_size)
Definition: vf_gblur_vulkan.c:78
FFVkBuffer::buf
VkBuffer buf
Definition: vulkan.h: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
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:2898
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:430
CGS
#define CGS
Definition: vf_gblur_vulkan.c:25
fail
#define fail()
Definition: checkasm.h:134
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:487
GBlurVulkanContext::qf
FFVkQueueFamilyCtx qf
Definition: vf_gblur_vulkan.c:30
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
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:256
GBlurVulkanContext::params_desc_hor
VkDescriptorBufferInfo params_desc_hor
Definition: vf_gblur_vulkan.c:40
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:363
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:467
GBlurVulkanContext::tmp_images
VkDescriptorImageInfo tmp_images[3]
Definition: vf_gblur_vulkan.c:38
planes
static const struct @345 planes[]
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:190
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:195
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:1080
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
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:603
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
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
index
int index
Definition: gxfenc.c:89
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
f
f
Definition: af_crystalizer.c:122
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:115
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:1116
size
int size
Definition: twinvq_data.h:10344
FFVkQueueFamilyCtx
Definition: vulkan.h:97
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:287
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_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_stub.c:30
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: internal.h:180
init_kernel_size
static void init_kernel_size(GBlurVulkanContext *s, int *out_size)
Definition: vf_gblur_vulkan.c:98
ff_vk_init_compute_pipeline
int ff_vk_init_compute_pipeline(FFVulkanContext *s, FFVulkanPipeline *pl)
Initializes a compute pipeline.
Definition: vulkan.c:1229
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
VkFormat
enum VkFormat VkFormat
Definition: hwcontext_stub.c:25
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:55
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:1220
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:171
init_gaussian_params
static av_cold void init_gaussian_params(GBlurVulkanContext *s)
Definition: vf_gblur_vulkan.c:110
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:426
init_gblur_pipeline
static int init_gblur_pipeline(GBlurVulkanContext *s, FFVulkanPipeline *pl, FFVkSPIRVShader *shd, FFVkBuffer *params_buf, VkDescriptorBufferInfo *params_desc, int ksize, float sigma)
Definition: vf_gblur_vulkan.c:125
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:923
gblur_func
static const char gblur_func[]
Definition: vf_gblur_vulkan.c:52
random_seed.h
FFVkSPIRVShader
Definition: vulkan.h:58
ff_vf_gblur_vulkan
const AVFilter ff_vf_gblur_vulkan
Definition: vf_gblur_vulkan.c:495
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
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:415
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:300
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:191
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:27
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:285
GBlurVulkanContext::sizeV
int sizeV
Definition: vf_gblur_vulkan.c:45
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:66