FFmpeg
vf_scale_vulkan.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 "libavutil/random_seed.h"
22 #include "libavutil/opt.h"
23 #include "libavutil/vulkan_spirv.h"
24 #include "vulkan_filter.h"
25 #include "scale_eval.h"
26 #include "filters.h"
27 #include "colorspace.h"
28 #include "video.h"
29 
30 extern const char *ff_source_debayer_comp;
31 
32 enum ScalerFunc {
35 
37 };
38 
42 
44 };
45 
46 typedef struct ScaleVulkanContext {
48 
53  VkSampler sampler;
54 
55  /* Push constants / options */
56  struct {
57  float yuv_matrix[4][4];
58  int crop_x;
59  int crop_y;
60  int crop_w;
61  int crop_h;
62  } opts;
63 
65  char *w_expr;
66  char *h_expr;
67 
72 
73 static const char scale_bilinear[] = {
74  C(0, vec4 scale_bilinear(int idx, ivec2 pos, vec2 crop_range, vec2 crop_off))
75  C(0, { )
76  C(1, vec2 npos = (vec2(pos) + 0.5f) / imageSize(output_img[idx]); )
77  C(1, npos *= crop_range; /* Reduce the range */ )
78  C(1, npos += crop_off; /* Offset the start */ )
79  C(1, return texture(input_img[idx], npos); )
80  C(0, } )
81 };
82 
83 static const char rgb2yuv[] = {
84  C(0, vec4 rgb2yuv(vec4 src, int fullrange) )
85  C(0, { )
86  C(1, src *= yuv_matrix; )
87  C(1, if (fullrange == 1) { )
88  C(2, src += vec4(0.0, 0.5, 0.5, 0.0); )
89  C(1, } else { )
90  C(2, src *= vec4(219.0 / 255.0, 224.0 / 255.0, 224.0 / 255.0, 1.0); )
91  C(2, src += vec4(16.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 0.0); )
92  C(1, } )
93  C(1, return src; )
94  C(0, } )
95 };
96 
97 static const char write_nv12[] = {
98  C(0, void write_nv12(vec4 src, ivec2 pos) )
99  C(0, { )
100  C(1, imageStore(output_img[0], pos, vec4(src.r, 0.0, 0.0, 0.0)); )
101  C(1, pos /= ivec2(2); )
102  C(1, imageStore(output_img[1], pos, vec4(src.g, src.b, 0.0, 0.0)); )
103  C(0, } )
104 };
105 
106 static const char write_420[] = {
107  C(0, void write_420(vec4 src, ivec2 pos) )
108  C(0, { )
109  C(1, imageStore(output_img[0], pos, vec4(src.r, 0.0, 0.0, 0.0)); )
110  C(1, pos /= ivec2(2); )
111  C(1, imageStore(output_img[1], pos, vec4(src.g, 0.0, 0.0, 0.0)); )
112  C(1, imageStore(output_img[2], pos, vec4(src.b, 0.0, 0.0, 0.0)); )
113  C(0, } )
114 };
115 
116 static const char write_444[] = {
117  C(0, void write_444(vec4 src, ivec2 pos) )
118  C(0, { )
119  C(1, imageStore(output_img[0], pos, vec4(src.r, 0.0, 0.0, 0.0)); )
120  C(1, imageStore(output_img[1], pos, vec4(src.g, 0.0, 0.0, 0.0)); )
121  C(1, imageStore(output_img[2], pos, vec4(src.b, 0.0, 0.0, 0.0)); )
122  C(0, } )
123 };
124 
127 {
128  ScaleVulkanContext *s = ctx->priv;
130 
131  if (s->vkctx.output_format != s->vkctx.input_format) {
132  GLSLD( rgb2yuv );
133  }
134 
135  switch (s->vkctx.output_format) {
136  case AV_PIX_FMT_NV12: GLSLD(write_nv12); break;
137  case AV_PIX_FMT_YUV420P: GLSLD( write_420); break;
138  case AV_PIX_FMT_YUV444P: GLSLD( write_444); break;
139  default: break;
140  }
141 
142  GLSLC(0, void main() );
143  GLSLC(0, { );
144  GLSLC(1, ivec2 size; );
145  GLSLC(1, ivec2 pos = ivec2(gl_GlobalInvocationID.xy); );
146  GLSLF(1, vec2 in_d = vec2(%i, %i); ,in->width, in->height);
147  GLSLC(1, vec2 c_r = vec2(crop_w, crop_h) / in_d; );
148  GLSLC(1, vec2 c_o = vec2(crop_x, crop_y) / in_d; );
149  GLSLC(0, );
150 
151  if (s->vkctx.output_format == s->vkctx.input_format) {
152  for (int i = 0; i < desc[1].elems; i++) {
153  GLSLF(1, size = imageSize(output_img[%i]); ,i);
154  GLSLC(1, if (IS_WITHIN(pos, size)) { );
155  switch (s->scaler) {
156  case F_NEAREST:
157  case F_BILINEAR:
158  GLSLF(2, vec4 res = scale_bilinear(%i, pos, c_r, c_o); ,i);
159  GLSLF(2, imageStore(output_img[%i], pos, res); ,i);
160  break;
161  };
162  GLSLC(1, } );
163  }
164  } else {
165  GLSLC(1, vec4 res = scale_bilinear(0, pos, c_r, c_o); );
166  GLSLF(1, res = rgb2yuv(res, %i); ,s->out_range == AVCOL_RANGE_JPEG);
167  switch (s->vkctx.output_format) {
168  case AV_PIX_FMT_NV12: GLSLC(1, write_nv12(res, pos); ); break;
169  case AV_PIX_FMT_YUV420P: GLSLC(1, write_420(res, pos); ); break;
170  case AV_PIX_FMT_YUV444P: GLSLC(1, write_444(res, pos); ); break;
171  default: return AVERROR(EINVAL);
172  }
173  }
174 
175  GLSLC(0, } );
176 
177  if (s->vkctx.output_format != s->vkctx.input_format) {
178  const AVLumaCoefficients *lcoeffs;
179  double tmp_mat[3][3];
180 
182  if (!lcoeffs) {
183  av_log(ctx, AV_LOG_ERROR, "Unsupported colorspace\n");
184  return AVERROR(EINVAL);
185  }
186 
187  ff_fill_rgb2yuv_table(lcoeffs, tmp_mat);
188 
189  for (int y = 0; y < 3; y++)
190  for (int x = 0; x < 3; x++)
191  s->opts.yuv_matrix[x][y] = tmp_mat[x][y];
192  s->opts.yuv_matrix[3][3] = 1.0;
193  }
194 
195  return 0;
196 }
197 
200 {
202 
203  GLSLC(0, void main(void));
204  GLSLC(0, { );
205  if (s->debayer == DB_BILINEAR)
206  GLSLC(1, debayer_bilinear(););
207  else if (s->debayer == DB_BILINEAR_HQ)
208  GLSLC(1, debayer_bilinear_hq(););
209  GLSLC(0, } );
210 
211  shd->lg_size[0] <<= 1;
212  shd->lg_size[1] <<= 1;
213 
214  return 0;
215 }
216 
218 {
219  int err;
220  uint8_t *spv_data;
221  size_t spv_len;
222  void *spv_opaque = NULL;
223  VkFilter sampler_mode;
224  ScaleVulkanContext *s = ctx->priv;
225  FFVulkanContext *vkctx = &s->vkctx;
226  FFVulkanShader *shd = &s->shd;
227  FFVkSPIRVCompiler *spv;
229 
230  int debayer = s->vkctx.input_format == AV_PIX_FMT_BAYER_RGGB16;
231  int in_planes = av_pix_fmt_count_planes(s->vkctx.input_format);
232 
233  switch (s->scaler) {
234  case F_NEAREST:
235  sampler_mode = VK_FILTER_NEAREST;
236  break;
237  case F_BILINEAR:
238  sampler_mode = VK_FILTER_LINEAR;
239  break;
240  };
241 
242  spv = ff_vk_spirv_init();
243  if (!spv) {
244  av_log(ctx, AV_LOG_ERROR, "Unable to initialize SPIR-V compiler!\n");
245  return AVERROR_EXTERNAL;
246  }
247 
248  s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
249  if (!s->qf) {
250  av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
251  err = AVERROR(ENOTSUP);
252  goto fail;
253  }
254 
255  RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
256 
257  if (!debayer)
258  RET(ff_vk_init_sampler(vkctx, &s->sampler, 0, sampler_mode));
259 
260  RET(ff_vk_shader_init(vkctx, &s->shd, "scale",
261  VK_SHADER_STAGE_COMPUTE_BIT,
262  NULL, 0,
263  32, 32, 1,
264  0));
265 
267  {
268  .name = "input_img",
269  .type = debayer ?
270  VK_DESCRIPTOR_TYPE_STORAGE_IMAGE :
271  VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
272  .mem_layout = debayer ?
273  ff_vk_shader_rep_fmt(s->vkctx.input_format, FF_VK_REP_FLOAT) :
274  NULL,
275  .mem_quali = "readonly",
276  .dimensions = 2,
277  .elems = in_planes,
278  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
279  .samplers = DUP_SAMPLER(s->sampler),
280  },
281  {
282  .name = "output_img",
283  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
284  .mem_layout = ff_vk_shader_rep_fmt(s->vkctx.output_format, FF_VK_REP_FLOAT),
285  .mem_quali = "writeonly",
286  .dimensions = 2,
287  .elems = av_pix_fmt_count_planes(s->vkctx.output_format),
288  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
289  },
290  };
291 
292  RET(ff_vk_shader_add_descriptor_set(vkctx, &s->shd, desc, 2, 0, 0));
293 
294  GLSLC(0, layout(push_constant, std430) uniform pushConstants { );
295  GLSLC(1, mat4 yuv_matrix; );
296  GLSLC(1, int crop_x; );
297  GLSLC(1, int crop_y; );
298  GLSLC(1, int crop_w; );
299  GLSLC(1, int crop_h; );
300  GLSLC(0, }; );
301  GLSLC(0, );
302 
303  ff_vk_shader_add_push_const(&s->shd, 0, sizeof(s->opts),
304  VK_SHADER_STAGE_COMPUTE_BIT);
305 
306  if (debayer)
307  err = init_debayer_shader(s, shd, desc, in);
308  else
309  err = init_scale_shader(ctx, shd, desc, in);
310  if (err < 0)
311  goto fail;
312 
313  RET(spv->compile_shader(vkctx, spv, shd, &spv_data, &spv_len, "main",
314  &spv_opaque));
315  RET(ff_vk_shader_link(vkctx, shd, spv_data, spv_len, "main"));
316 
317  RET(ff_vk_shader_register_exec(vkctx, &s->e, &s->shd));
318 
319  s->initialized = 1;
320 
321 fail:
322  if (spv_opaque)
323  spv->free_shader(spv, &spv_opaque);
324  if (spv)
325  spv->uninit(&spv);
326 
327  return err;
328 }
329 
331 {
332  int err;
333  AVFilterContext *ctx = link->dst;
334  ScaleVulkanContext *s = ctx->priv;
335  AVFilterLink *outlink = ctx->outputs[0];
336 
337  AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
338  if (!out) {
339  err = AVERROR(ENOMEM);
340  goto fail;
341  }
342 
343  if (!s->initialized)
344  RET(init_filter(ctx, in));
345 
346  s->opts.crop_x = in->crop_left;
347  s->opts.crop_y = in->crop_top;
348  s->opts.crop_w = in->width - (in->crop_left + in->crop_right);
349  s->opts.crop_h = in->height - (in->crop_top + in->crop_bottom);
350 
351  RET(ff_vk_filter_process_simple(&s->vkctx, &s->e, &s->shd, out, in,
352  s->sampler, &s->opts, sizeof(s->opts)));
353 
354  err = av_frame_copy_props(out, in);
355  if (err < 0)
356  goto fail;
357 
358  if (out->width != in->width || out->height != in->height) {
359  av_frame_side_data_remove_by_props(&out->side_data, &out->nb_side_data,
361  }
362 
363  if (s->out_range != AVCOL_RANGE_UNSPECIFIED)
364  out->color_range = s->out_range;
365  if (s->vkctx.output_format != s->vkctx.input_format)
366  out->chroma_location = AVCHROMA_LOC_TOPLEFT;
367 
368  av_frame_free(&in);
369 
370  return ff_filter_frame(outlink, out);
371 
372 fail:
373  av_frame_free(&in);
374  av_frame_free(&out);
375  return err;
376 }
377 
379 {
380  int err;
381  AVFilterContext *avctx = outlink->src;
382  ScaleVulkanContext *s = avctx->priv;
383  FFVulkanContext *vkctx = &s->vkctx;
384  AVFilterLink *inlink = outlink->src->inputs[0];
385 
386  err = ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink,
387  &vkctx->output_width,
388  &vkctx->output_height);
389  if (err < 0)
390  return err;
391 
392  ff_scale_adjust_dimensions(inlink, &vkctx->output_width, &vkctx->output_height, 0, 1, 1.f);
393 
394  outlink->w = vkctx->output_width;
395  outlink->h = vkctx->output_height;
396 
397  if (s->out_format_string) {
398  s->vkctx.output_format = av_get_pix_fmt(s->out_format_string);
399  if (s->vkctx.output_format == AV_PIX_FMT_NONE) {
400  av_log(avctx, AV_LOG_ERROR, "Invalid output format.\n");
401  return AVERROR(EINVAL);
402  }
403  } else {
404  s->vkctx.output_format = s->vkctx.input_format;
405  }
406 
407  if (s->vkctx.input_format == AV_PIX_FMT_BAYER_RGGB16) {
408  if (s->vkctx.output_format == s->vkctx.input_format) {
409  s->vkctx.output_format = AV_PIX_FMT_RGBA64;
410  } else if (!ff_vk_mt_is_np_rgb(s->vkctx.output_format)) {
411  av_log(avctx, AV_LOG_ERROR, "Unsupported output format for debayer\n");
412  return AVERROR(EINVAL);
413  }
414  if (inlink->w != outlink->w || inlink->w != outlink->w) {
415  av_log(avctx, AV_LOG_ERROR, "Scaling is not supported with debayering\n");
416  return AVERROR_PATCHWELCOME;
417  }
418  } else if (s->vkctx.output_format != s->vkctx.input_format) {
419  if (!ff_vk_mt_is_np_rgb(s->vkctx.input_format)) {
420  av_log(avctx, AV_LOG_ERROR, "Unsupported input format for conversion\n");
421  return AVERROR(EINVAL);
422  }
423  if (s->vkctx.output_format != AV_PIX_FMT_NV12 &&
424  s->vkctx.output_format != AV_PIX_FMT_YUV420P &&
425  s->vkctx.output_format != AV_PIX_FMT_YUV444P) {
426  av_log(avctx, AV_LOG_ERROR, "Unsupported output format\n");
427  return AVERROR(EINVAL);
428  }
429  } else if (s->out_range != AVCOL_RANGE_UNSPECIFIED) {
430  av_log(avctx, AV_LOG_ERROR, "Cannot change range without converting format\n");
431  return AVERROR(EINVAL);
432  }
433 
434  return ff_vk_filter_config_output(outlink);
435 }
436 
438 {
439  ScaleVulkanContext *s = avctx->priv;
440  FFVulkanContext *vkctx = &s->vkctx;
441  FFVulkanFunctions *vk = &vkctx->vkfn;
442 
443  ff_vk_exec_pool_free(vkctx, &s->e);
444  ff_vk_shader_free(vkctx, &s->shd);
445 
446  if (s->sampler)
447  vk->DestroySampler(vkctx->hwctx->act_dev, s->sampler,
448  vkctx->hwctx->alloc);
449 
450  ff_vk_uninit(&s->vkctx);
451 
452  s->initialized = 0;
453 }
454 
455 #define OFFSET(x) offsetof(ScaleVulkanContext, x)
456 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
457 static const AVOption scale_vulkan_options[] = {
458  { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, .flags = FLAGS },
459  { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, .flags = FLAGS },
460  { "scaler", "Scaler function", OFFSET(scaler), AV_OPT_TYPE_INT, {.i64 = F_BILINEAR}, 0, F_NB, .flags = FLAGS, .unit = "scaler" },
461  { "bilinear", "Bilinear interpolation (fastest)", 0, AV_OPT_TYPE_CONST, {.i64 = F_BILINEAR}, 0, 0, .flags = FLAGS, .unit = "scaler" },
462  { "nearest", "Nearest (useful for pixel art)", 0, AV_OPT_TYPE_CONST, {.i64 = F_NEAREST}, 0, 0, .flags = FLAGS, .unit = "scaler" },
463  { "debayer", "Debayer algorithm to use", OFFSET(debayer), AV_OPT_TYPE_INT, {.i64 = DB_BILINEAR_HQ}, 0, DB_NB, .flags = FLAGS, .unit = "debayer" },
464  { "bilinear", "Bilinear debayering (fastest)", 0, AV_OPT_TYPE_CONST, {.i64 = DB_BILINEAR}, 0, 0, .flags = FLAGS, .unit = "debayer" },
465  { "bilinear_hq", "Bilinear debayering (high quality)", 0, AV_OPT_TYPE_CONST, {.i64 = DB_BILINEAR_HQ}, 0, 0, .flags = FLAGS, .unit = "debayer" },
466  { "format", "Output video format (software format of hardware frames)", OFFSET(out_format_string), AV_OPT_TYPE_STRING, .flags = FLAGS },
467  { "out_range", "Output colour range (from 0 to 2) (default 0)", OFFSET(out_range), AV_OPT_TYPE_INT, {.i64 = AVCOL_RANGE_UNSPECIFIED}, AVCOL_RANGE_UNSPECIFIED, AVCOL_RANGE_JPEG, .flags = FLAGS, .unit = "range" },
468  { "full", "Full range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, .unit = "range" },
469  { "limited", "Limited range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, .unit = "range" },
470  { "jpeg", "Full range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, .unit = "range" },
471  { "mpeg", "Limited range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, .unit = "range" },
472  { "tv", "Limited range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, .unit = "range" },
473  { "pc", "Full range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, .unit = "range" },
474  { NULL },
475 };
476 
477 AVFILTER_DEFINE_CLASS(scale_vulkan);
478 
480  {
481  .name = "default",
482  .type = AVMEDIA_TYPE_VIDEO,
483  .filter_frame = &scale_vulkan_filter_frame,
484  .config_props = &ff_vk_filter_config_input,
485  },
486 };
487 
489  {
490  .name = "default",
491  .type = AVMEDIA_TYPE_VIDEO,
492  .config_props = &scale_vulkan_config_output,
493  },
494 };
495 
497  .p.name = "scale_vulkan",
498  .p.description = NULL_IF_CONFIG_SMALL("Scale Vulkan frames"),
499  .p.priv_class = &scale_vulkan_class,
500  .p.flags = AVFILTER_FLAG_HWDEVICE,
501  .priv_size = sizeof(ScaleVulkanContext),
507  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
508 };
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:117
init_debayer_shader
static int init_debayer_shader(ScaleVulkanContext *s, FFVulkanShader *shd, FFVulkanDescriptorSetBinding *desc, AVFrame *in)
Definition: vf_scale_vulkan.c:198
FFVulkanContext::output_height
int output_height
Definition: vulkan.h:318
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_vk_shader_free
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition: vulkan.c:2923
ff_vk_shader_init
int ff_vk_shader_init(FFVulkanContext *s, FFVulkanShader *shd, const char *name, VkPipelineStageFlags stage, const char *extensions[], int nb_extensions, int lg_x, int lg_y, int lg_z, uint32_t required_subgroup_size)
Initialize a shader object, with a specific set of extensions, type+bind, local group size,...
Definition: vulkan.c:2056
out
FILE * out
Definition: movenc.c:55
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1067
RET
#define RET(x)
Definition: vulkan.h:66
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, 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
ff_vk_exec_pool_init
int ff_vk_exec_pool_init(FFVulkanContext *s, AVVulkanDeviceQueueFamily *qf, FFVkExecPool *pool, int nb_contexts, int nb_queries, VkQueryType query_type, int query_64bit, const void *query_create_pnext)
Allocates/frees an execution pool.
Definition: vulkan.c:356
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
DB_NB
@ DB_NB
Definition: vf_scale_vulkan.c:43
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:689
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:263
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
OFFSET
#define OFFSET(x)
Definition: vf_scale_vulkan.c:455
AVFrame::width
int width
Definition: frame.h:499
ff_vk_filter_init
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
Definition: vulkan_filter.c:233
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:767
scale_vulkan_outputs
static const AVFilterPad scale_vulkan_outputs[]
Definition: vf_scale_vulkan.c:488
av_csp_luma_coeffs_from_avcsp
const struct AVLumaCoefficients * av_csp_luma_coeffs_from_avcsp(enum AVColorSpace csp)
Retrieves the Luma coefficients necessary to construct a conversion matrix from an enum constant desc...
Definition: csp.c:58
AVOption
AVOption.
Definition: opt.h:429
DB_BILINEAR_HQ
@ DB_BILINEAR_HQ
Definition: vf_scale_vulkan.c:41
scale_vulkan_options
static const AVOption scale_vulkan_options[]
Definition: vf_scale_vulkan.c:457
rgb2yuv
static const char rgb2yuv[]
Definition: vf_scale_vulkan.c:83
write_nv12
static const char write_nv12[]
Definition: vf_scale_vulkan.c:97
ff_scale_eval_dimensions
int ff_scale_eval_dimensions(void *log_ctx, const char *w_expr, const char *h_expr, AVFilterLink *inlink, AVFilterLink *outlink, int *ret_w, int *ret_h)
Parse and evaluate string expressions for width and height.
Definition: scale_eval.c:57
AVLumaCoefficients
Struct containing luma coefficients to be used for RGB to YUV/YCoCg, or similar calculations.
Definition: csp.h:48
ff_vk_uninit
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition: vulkan.c:2964
FFVkSPIRVCompiler::uninit
void(* uninit)(struct FFVkSPIRVCompiler **ctx)
Definition: vulkan_spirv.h:32
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:220
ScaleVulkanContext::sampler
VkSampler sampler
Definition: vf_scale_vulkan.c:53
video.h
ScaleVulkanContext::yuv_matrix
float yuv_matrix[4][4]
Definition: vf_scale_vulkan.c:57
write_420
static const char write_420[]
Definition: vf_scale_vulkan.c:106
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
ScaleVulkanContext::e
FFVkExecPool e
Definition: vf_scale_vulkan.c:50
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(scale_vulkan)
ScalerFunc
ScalerFunc
Definition: vf_scale_vulkan.c:32
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3487
AVVulkanDeviceContext::alloc
const VkAllocationCallbacks * alloc
Custom memory allocator, else NULL.
Definition: hwcontext_vulkan.h:63
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:289
fail
#define fail()
Definition: checkasm.h:200
vulkan_filter.h
colorspace.h
ff_vk_shader_register_exec
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
Definition: vulkan.c:2563
DebayerFunc
DebayerFunc
Definition: vf_scale_vulkan.c:39
ff_vk_shader_add_descriptor_set
int ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a shader.
Definition: vulkan.c:2428
AV_SIDE_DATA_PROP_SIZE_DEPENDENT
@ AV_SIDE_DATA_PROP_SIZE_DEPENDENT
Side data depends on the video dimensions.
Definition: frame.h:309
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:39
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
GLSLC
#define GLSLC(N, S)
Definition: vulkan.h:43
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
av_cold
#define av_cold
Definition: attributes.h:90
main
int main
Definition: dovi_rpuenc.c:38
FFFilter
Definition: filters.h:266
FFVulkanContext::output_width
int output_width
Definition: vulkan.h:317
F_NEAREST
@ F_NEAREST
Definition: vf_scale_vulkan.c:34
s
#define s(width, name)
Definition: cbs_vp9.c:198
F_BILINEAR
@ F_BILINEAR
Definition: vf_scale_vulkan.c:33
scale_vulkan_filter_frame
static int scale_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_scale_vulkan.c:330
ScaleVulkanContext::crop_x
int crop_x
Definition: vf_scale_vulkan.c:58
ff_vf_scale_vulkan
const FFFilter ff_vf_scale_vulkan
Definition: vf_scale_vulkan.c:496
filters.h
FF_VK_REP_FLOAT
@ FF_VK_REP_FLOAT
Definition: vulkan.h:408
ctx
AVFormatContext * ctx
Definition: movenc.c:49
GLSLD
#define GLSLD(D)
Definition: vulkan.h:58
AVFrame::crop_right
size_t crop_right
Definition: frame.h:753
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
ff_vk_exec_pool_free
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
Definition: vulkan.c:287
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:264
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
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:529
ff_vk_shader_rep_fmt
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt, enum FFVkShaderRepFormat rep_fmt)
Definition: vulkan.c:1589
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
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:599
DUP_SAMPLER
#define DUP_SAMPLER(x)
Definition: vulkan.h:72
scale_vulkan_uninit
static void scale_vulkan_uninit(AVFilterContext *avctx)
Definition: vf_scale_vulkan.c:437
ScaleVulkanContext::h_expr
char * h_expr
Definition: vf_scale_vulkan.c:66
AVCHROMA_LOC_TOPLEFT
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition: pixfmt.h:790
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:282
ff_vk_filter_config_output
int ff_vk_filter_config_output(AVFilterLink *outlink)
Definition: vulkan_filter.c:209
ScaleVulkanContext::debayer
enum DebayerFunc debayer
Definition: vf_scale_vulkan.c:70
ScaleVulkanContext::crop_h
int crop_h
Definition: vf_scale_vulkan.c:61
FFVulkanContext
Definition: vulkan.h:274
ScaleVulkanContext::out_range
enum AVColorRange out_range
Definition: vf_scale_vulkan.c:69
F_NB
@ F_NB
Definition: vf_scale_vulkan.c:36
FLAGS
#define FLAGS
Definition: vf_scale_vulkan.c:456
ff_source_debayer_comp
const char * ff_source_debayer_comp
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:733
ScaleVulkanContext::vkctx
FFVulkanContext vkctx
Definition: vf_scale_vulkan.c:47
AVFrame::crop_bottom
size_t crop_bottom
Definition: frame.h:751
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: filters.h:207
AVFrame::crop_left
size_t crop_left
Definition: frame.h:752
ScaleVulkanContext::qf
AVVulkanDeviceQueueFamily * qf
Definition: vf_scale_vulkan.c:51
f
f
Definition: af_crystalizer.c:122
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
FFVulkanDescriptorSetBinding
Definition: vulkan.h:74
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:94
AVFILTER_FLAG_HWDEVICE
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition: avfilter.h:188
size
int size
Definition: twinvq_data.h:10344
FFVulkanShader
Definition: vulkan.h:190
ScaleVulkanContext::crop_y
int crop_y
Definition: vf_scale_vulkan.c:59
scale_eval.h
FFVkSPIRVCompiler::compile_shader
int(* compile_shader)(FFVulkanContext *s, struct FFVkSPIRVCompiler *ctx, FFVulkanShader *shd, uint8_t **data, size_t *size, const char *entrypoint, void **opaque)
Definition: vulkan_spirv.h:28
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
ff_vk_mt_is_np_rgb
int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
Returns 1 if pixfmt is a usable RGB format.
Definition: vulkan.c:1529
av_frame_side_data_remove_by_props
void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd, int props)
Remove and free all side data instances that match any of the given side data properties.
Definition: side_data.c:117
FFVkSPIRVCompiler
Definition: vulkan_spirv.h:26
layout
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
Definition: filter_design.txt:18
ScaleVulkanContext::scaler
enum ScalerFunc scaler
Definition: vf_scale_vulkan.c:68
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
ff_fill_rgb2yuv_table
void ff_fill_rgb2yuv_table(const AVLumaCoefficients *coeffs, double rgb2yuv[3][3])
Definition: colorspace.c:125
ScaleVulkanContext::w_expr
char * w_expr
Definition: vf_scale_vulkan.c:65
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
scale_bilinear
static const char scale_bilinear[]
Definition: vf_scale_vulkan.c:73
write_444
static const char write_444[]
Definition: vf_scale_vulkan.c:116
ff_vk_shader_link
int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, uint8_t *spirv, size_t spirv_len, const char *entrypoint)
Link a shader into an executable.
Definition: vulkan.c:2353
vulkan_spirv.h
scale_vulkan_inputs
static const AVFilterPad scale_vulkan_inputs[]
Definition: vf_scale_vulkan.c:479
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:45
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:750
FFVkSPIRVCompiler::free_shader
void(* free_shader)(struct FFVkSPIRVCompiler *ctx, void **opaque)
Definition: vulkan_spirv.h:31
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:96
FFVulkanContext::vkfn
FFVulkanFunctions vkfn
Definition: vulkan.h:278
FFVkExecPool
Definition: vulkan.h:252
pos
unsigned int pos
Definition: spdifenc.c:414
ScaleVulkanContext::shd
FFVulkanShader shd
Definition: vf_scale_vulkan.c:52
ff_vk_shader_add_push_const
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
Definition: vulkan.c:1459
ff_vk_qf_find
AVVulkanDeviceQueueFamily * ff_vk_qf_find(FFVulkanContext *s, VkQueueFlagBits dev_family, VkVideoCodecOperationFlagBitsKHR vid_ops)
Chooses an appropriate QF.
Definition: vulkan.c:274
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:3379
AVFrame::height
int height
Definition: frame.h:499
random_seed.h
ScaleVulkanContext::initialized
int initialized
Definition: vf_scale_vulkan.c:49
GLSLF
#define GLSLF(N, S,...)
Definition: vulkan.h:53
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
ScaleVulkanContext::crop_w
int crop_w
Definition: vf_scale_vulkan.c:60
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
AVFilterContext
An instance of a filter.
Definition: avfilter.h:274
ScaleVulkanContext
Definition: vf_scale_vulkan.c:46
desc
const char * desc
Definition: libsvtav1.c:79
ff_vk_filter_config_input
int ff_vk_filter_config_input(AVFilterLink *inlink)
Definition: vulkan_filter.c:176
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:270
FFVulkanContext::hwctx
AVVulkanDeviceContext * hwctx
Definition: vulkan.h:306
AVVulkanDeviceContext::act_dev
VkDevice act_dev
Active device.
Definition: hwcontext_vulkan.h:84
ScaleVulkanContext::opts
struct ScaleVulkanContext::@394 opts
ff_vk_init_sampler
int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler, int unnorm_coords, VkFilter filt)
Create a sampler.
Definition: vulkan.c:1480
AVFrame::crop_top
size_t crop_top
Definition: frame.h:750
scale_vulkan_config_output
static int scale_vulkan_config_output(AVFilterLink *outlink)
Definition: vf_scale_vulkan.c:378
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVVulkanDeviceQueueFamily
Definition: hwcontext_vulkan.h:33
DB_BILINEAR
@ DB_BILINEAR
Definition: vf_scale_vulkan.c:40
init_filter
static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
Definition: vf_scale_vulkan.c:217
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
AV_PIX_FMT_BAYER_RGGB16
#define AV_PIX_FMT_BAYER_RGGB16
Definition: pixfmt.h:572
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:732
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: filters.h:253
FFVulkanFunctions
Definition: vulkan_functions.h:276
ff_scale_adjust_dimensions
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by, double w_adj)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
Definition: scale_eval.c:113
init_scale_shader
static int init_scale_shader(AVFilterContext *ctx, FFVulkanShader *shd, FFVulkanDescriptorSetBinding *desc, AVFrame *in)
Definition: vf_scale_vulkan.c:125
ScaleVulkanContext::out_format_string
char * out_format_string
Definition: vf_scale_vulkan.c:64
src
#define src
Definition: vp8dsp.c:248
FFVulkanShader::lg_size
int lg_size[3]
Definition: vulkan.h:198