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 "vulkan_filter.h"
24 #include "vulkan_spirv.h"
25 #include "scale_eval.h"
26 #include "internal.h"
27 #include "colorspace.h"
28 
29 enum ScalerFunc {
32 
34 };
35 
36 typedef struct ScaleVulkanContext {
38 
44  VkSampler sampler;
45 
46  /* Push constants / options */
47  struct {
48  float yuv_matrix[4][4];
49  } opts;
50 
52  char *w_expr;
53  char *h_expr;
54 
58 
59 static const char scale_bilinear[] = {
60  C(0, vec4 scale_bilinear(int idx, ivec2 pos, vec2 crop_range, vec2 crop_off))
61  C(0, { )
62  C(1, vec2 npos = (vec2(pos) + 0.5f) / imageSize(output_img[idx]); )
63  C(1, npos *= crop_range; /* Reduce the range */ )
64  C(1, npos += crop_off; /* Offset the start */ )
65  C(1, return texture(input_img[idx], npos); )
66  C(0, } )
67 };
68 
69 static const char rgb2yuv[] = {
70  C(0, vec4 rgb2yuv(vec4 src, int fullrange) )
71  C(0, { )
72  C(1, src *= yuv_matrix; )
73  C(1, if (fullrange == 1) { )
74  C(2, src += vec4(0.0, 0.5, 0.5, 0.0); )
75  C(1, } else { )
76  C(2, src *= vec4(219.0 / 255.0, 224.0 / 255.0, 224.0 / 255.0, 1.0); )
77  C(2, src += vec4(16.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 0.0); )
78  C(1, } )
79  C(1, return src; )
80  C(0, } )
81 };
82 
83 static const char write_nv12[] = {
84  C(0, void write_nv12(vec4 src, ivec2 pos) )
85  C(0, { )
86  C(1, imageStore(output_img[0], pos, vec4(src.r, 0.0, 0.0, 0.0)); )
87  C(1, pos /= ivec2(2); )
88  C(1, imageStore(output_img[1], pos, vec4(src.g, src.b, 0.0, 0.0)); )
89  C(0, } )
90 };
91 
92 static const char write_420[] = {
93  C(0, void write_420(vec4 src, ivec2 pos) )
94  C(0, { )
95  C(1, imageStore(output_img[0], pos, vec4(src.r, 0.0, 0.0, 0.0)); )
96  C(1, pos /= ivec2(2); )
97  C(1, imageStore(output_img[1], pos, vec4(src.g, 0.0, 0.0, 0.0)); )
98  C(1, imageStore(output_img[2], pos, vec4(src.b, 0.0, 0.0, 0.0)); )
99  C(0, } )
100 };
101 
102 static const char write_444[] = {
103  C(0, void write_444(vec4 src, ivec2 pos) )
104  C(0, { )
105  C(1, imageStore(output_img[0], pos, vec4(src.r, 0.0, 0.0, 0.0)); )
106  C(1, imageStore(output_img[1], pos, vec4(src.g, 0.0, 0.0, 0.0)); )
107  C(1, imageStore(output_img[2], pos, vec4(src.b, 0.0, 0.0, 0.0)); )
108  C(0, } )
109 };
110 
112 {
113  int err;
114  uint8_t *spv_data;
115  size_t spv_len;
116  void *spv_opaque = NULL;
117  VkFilter sampler_mode;
118  ScaleVulkanContext *s = ctx->priv;
119  FFVulkanContext *vkctx = &s->vkctx;
120  FFVkSPIRVShader *shd = &s->shd;
121  FFVkSPIRVCompiler *spv;
123 
124  int crop_x = in->crop_left;
125  int crop_y = in->crop_top;
126  int crop_w = in->width - (in->crop_left + in->crop_right);
127  int crop_h = in->height - (in->crop_top + in->crop_bottom);
128  int in_planes = av_pix_fmt_count_planes(s->vkctx.input_format);
129 
130  switch (s->scaler) {
131  case F_NEAREST:
132  sampler_mode = VK_FILTER_NEAREST;
133  break;
134  case F_BILINEAR:
135  sampler_mode = VK_FILTER_LINEAR;
136  break;
137  };
138 
139  spv = ff_vk_spirv_init();
140  if (!spv) {
141  av_log(ctx, AV_LOG_ERROR, "Unable to initialize SPIR-V compiler!\n");
142  return AVERROR_EXTERNAL;
143  }
144 
145  ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
146  RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
147  RET(ff_vk_init_sampler(vkctx, &s->sampler, 0, sampler_mode));
148  RET(ff_vk_shader_init(&s->pl, &s->shd, "scale_compute",
149  VK_SHADER_STAGE_COMPUTE_BIT, 0));
150 
151  ff_vk_shader_set_compute_sizes(&s->shd, 32, 32, 1);
152 
153  GLSLC(0, layout(push_constant, std430) uniform pushConstants { );
154  GLSLC(1, mat4 yuv_matrix; );
155  GLSLC(0, }; );
156  GLSLC(0, );
157 
158  ff_vk_add_push_constant(&s->pl, 0, sizeof(s->opts),
159  VK_SHADER_STAGE_COMPUTE_BIT);
160 
162  {
163  .name = "input_img",
164  .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
165  .dimensions = 2,
166  .elems = in_planes,
167  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
168  .samplers = DUP_SAMPLER(s->sampler),
169  },
170  {
171  .name = "output_img",
172  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
173  .mem_layout = ff_vk_shader_rep_fmt(s->vkctx.output_format),
174  .mem_quali = "writeonly",
175  .dimensions = 2,
176  .elems = av_pix_fmt_count_planes(s->vkctx.output_format),
177  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
178  },
179  };
180 
181  RET(ff_vk_pipeline_descriptor_set_add(vkctx, &s->pl, shd, desc, 2, 0, 0));
182 
184 
185  if (s->vkctx.output_format != s->vkctx.input_format) {
186  GLSLD( rgb2yuv );
187  }
188 
189  switch (s->vkctx.output_format) {
190  case AV_PIX_FMT_NV12: GLSLD(write_nv12); break;
191  case AV_PIX_FMT_YUV420P: GLSLD( write_420); break;
192  case AV_PIX_FMT_YUV444P: GLSLD( write_444); break;
193  default: break;
194  }
195 
196  GLSLC(0, void main() );
197  GLSLC(0, { );
198  GLSLC(1, ivec2 size; );
199  GLSLC(1, ivec2 pos = ivec2(gl_GlobalInvocationID.xy); );
200  GLSLF(1, vec2 in_d = vec2(%i, %i); ,in->width, in->height);
201  GLSLF(1, vec2 c_r = vec2(%i, %i) / in_d; ,crop_w, crop_h);
202  GLSLF(1, vec2 c_o = vec2(%i, %i) / in_d; ,crop_x,crop_y);
203  GLSLC(0, );
204 
205  if (s->vkctx.output_format == s->vkctx.input_format) {
206  for (int i = 0; i < desc[i].elems; i++) {
207  GLSLF(1, size = imageSize(output_img[%i]); ,i);
208  GLSLC(1, if (IS_WITHIN(pos, size)) { );
209  switch (s->scaler) {
210  case F_NEAREST:
211  case F_BILINEAR:
212  GLSLF(2, vec4 res = scale_bilinear(%i, pos, c_r, c_o); ,i);
213  GLSLF(2, imageStore(output_img[%i], pos, res); ,i);
214  break;
215  };
216  GLSLC(1, } );
217  }
218  } else {
219  GLSLC(1, vec4 res = scale_bilinear(0, pos, c_r, c_o); );
220  GLSLF(1, res = rgb2yuv(res, %i); ,s->out_range == AVCOL_RANGE_JPEG);
221  switch (s->vkctx.output_format) {
222  case AV_PIX_FMT_NV12: GLSLC(1, write_nv12(res, pos); ); break;
223  case AV_PIX_FMT_YUV420P: GLSLC(1, write_420(res, pos); ); break;
224  case AV_PIX_FMT_YUV444P: GLSLC(1, write_444(res, pos); ); break;
225  default: return AVERROR(EINVAL);
226  }
227  }
228 
229  GLSLC(0, } );
230 
231  if (s->vkctx.output_format != s->vkctx.input_format) {
232  const AVLumaCoefficients *lcoeffs;
233  double tmp_mat[3][3];
234 
236  if (!lcoeffs) {
237  av_log(ctx, AV_LOG_ERROR, "Unsupported colorspace\n");
238  return AVERROR(EINVAL);
239  }
240 
241  ff_fill_rgb2yuv_table(lcoeffs, tmp_mat);
242 
243  for (int y = 0; y < 3; y++)
244  for (int x = 0; x < 3; x++)
245  s->opts.yuv_matrix[x][y] = tmp_mat[x][y];
246  s->opts.yuv_matrix[3][3] = 1.0;
247  }
248 
249  RET(spv->compile_shader(spv, ctx, shd, &spv_data, &spv_len, "main",
250  &spv_opaque));
251  RET(ff_vk_shader_create(vkctx, shd, spv_data, spv_len, "main"));
252 
253  RET(ff_vk_init_compute_pipeline(vkctx, &s->pl, shd));
254  RET(ff_vk_exec_pipeline_register(vkctx, &s->e, &s->pl));
255 
256  s->initialized = 1;
257 
258  return 0;
259 
260 fail:
261  if (spv_opaque)
262  spv->free_shader(spv, &spv_opaque);
263  if (spv)
264  spv->uninit(&spv);
265 
266  return err;
267 }
268 
270 {
271  int err;
272  AVFilterContext *ctx = link->dst;
273  ScaleVulkanContext *s = ctx->priv;
274  AVFilterLink *outlink = ctx->outputs[0];
275 
276  AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
277  if (!out) {
278  err = AVERROR(ENOMEM);
279  goto fail;
280  }
281 
282  if (!s->initialized)
283  RET(init_filter(ctx, in));
284 
285  RET(ff_vk_filter_process_simple(&s->vkctx, &s->e, &s->pl, out, in,
286  s->sampler, &s->opts, sizeof(s->opts)));
287 
288  err = av_frame_copy_props(out, in);
289  if (err < 0)
290  goto fail;
291 
292  if (s->out_range != AVCOL_RANGE_UNSPECIFIED)
293  out->color_range = s->out_range;
294  if (s->vkctx.output_format != s->vkctx.input_format)
295  out->chroma_location = AVCHROMA_LOC_TOPLEFT;
296 
297  av_frame_free(&in);
298 
299  return ff_filter_frame(outlink, out);
300 
301 fail:
302  av_frame_free(&in);
303  av_frame_free(&out);
304  return err;
305 }
306 
308 {
309  int err;
310  AVFilterContext *avctx = outlink->src;
311  ScaleVulkanContext *s = avctx->priv;
312  FFVulkanContext *vkctx = &s->vkctx;
313  AVFilterLink *inlink = outlink->src->inputs[0];
314 
315  err = ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink,
316  &vkctx->output_width,
317  &vkctx->output_height);
318  if (err < 0)
319  return err;
320 
321  if (s->out_format_string) {
322  s->vkctx.output_format = av_get_pix_fmt(s->out_format_string);
323  if (s->vkctx.output_format == AV_PIX_FMT_NONE) {
324  av_log(avctx, AV_LOG_ERROR, "Invalid output format.\n");
325  return AVERROR(EINVAL);
326  }
327  } else {
328  s->vkctx.output_format = s->vkctx.input_format;
329  }
330 
331  if (s->vkctx.output_format != s->vkctx.input_format) {
332  if (!ff_vk_mt_is_np_rgb(s->vkctx.input_format)) {
333  av_log(avctx, AV_LOG_ERROR, "Unsupported input format for conversion\n");
334  return AVERROR(EINVAL);
335  }
336  if (s->vkctx.output_format != AV_PIX_FMT_NV12 &&
337  s->vkctx.output_format != AV_PIX_FMT_YUV420P &&
338  s->vkctx.output_format != AV_PIX_FMT_YUV444P) {
339  av_log(avctx, AV_LOG_ERROR, "Unsupported output format\n");
340  return AVERROR(EINVAL);
341  }
342  } else if (s->out_range != AVCOL_RANGE_UNSPECIFIED) {
343  av_log(avctx, AV_LOG_ERROR, "Cannot change range without converting format\n");
344  return AVERROR(EINVAL);
345  }
346 
347  return ff_vk_filter_config_output(outlink);
348 }
349 
351 {
352  ScaleVulkanContext *s = avctx->priv;
353  FFVulkanContext *vkctx = &s->vkctx;
354  FFVulkanFunctions *vk = &vkctx->vkfn;
355 
356  ff_vk_exec_pool_free(vkctx, &s->e);
357  ff_vk_pipeline_free(vkctx, &s->pl);
358  ff_vk_shader_free(vkctx, &s->shd);
359 
360  if (s->sampler)
361  vk->DestroySampler(vkctx->hwctx->act_dev, s->sampler,
362  vkctx->hwctx->alloc);
363 
364  ff_vk_uninit(&s->vkctx);
365 
366  s->initialized = 0;
367 }
368 
369 #define OFFSET(x) offsetof(ScaleVulkanContext, x)
370 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
371 static const AVOption scale_vulkan_options[] = {
372  { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, .flags = FLAGS },
373  { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, .flags = FLAGS },
374  { "scaler", "Scaler function", OFFSET(scaler), AV_OPT_TYPE_INT, {.i64 = F_BILINEAR}, 0, F_NB, .flags = FLAGS, "scaler" },
375  { "bilinear", "Bilinear interpolation (fastest)", 0, AV_OPT_TYPE_CONST, {.i64 = F_BILINEAR}, 0, 0, .flags = FLAGS, "scaler" },
376  { "nearest", "Nearest (useful for pixel art)", 0, AV_OPT_TYPE_CONST, {.i64 = F_NEAREST}, 0, 0, .flags = FLAGS, "scaler" },
377  { "format", "Output video format (software format of hardware frames)", OFFSET(out_format_string), AV_OPT_TYPE_STRING, .flags = FLAGS },
378  { "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, "range" },
379  { "full", "Full range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, "range" },
380  { "limited", "Limited range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, "range" },
381  { "jpeg", "Full range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, "range" },
382  { "mpeg", "Limited range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, "range" },
383  { "tv", "Limited range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, "range" },
384  { "pc", "Full range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, "range" },
385  { NULL },
386 };
387 
388 AVFILTER_DEFINE_CLASS(scale_vulkan);
389 
391  {
392  .name = "default",
393  .type = AVMEDIA_TYPE_VIDEO,
394  .filter_frame = &scale_vulkan_filter_frame,
395  .config_props = &ff_vk_filter_config_input,
396  },
397 };
398 
400  {
401  .name = "default",
402  .type = AVMEDIA_TYPE_VIDEO,
403  .config_props = &scale_vulkan_config_output,
404  },
405 };
406 
408  .name = "scale_vulkan",
409  .description = NULL_IF_CONFIG_SMALL("Scale Vulkan frames"),
410  .priv_size = sizeof(ScaleVulkanContext),
416  .priv_class = &scale_vulkan_class,
417  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
418  .flags = AVFILTER_FLAG_HWDEVICE,
419 };
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
ff_vk_pipeline_free
void ff_vk_pipeline_free(FFVulkanContext *s, FFVulkanPipeline *pl)
Definition: vulkan.c:1829
FFVulkanContext::output_height
int output_height
Definition: vulkan.h:260
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
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:374
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:971
ff_vk_qf_init
int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, VkQueueFlagBits dev_family)
Chooses a QF and loads it into a context.
Definition: vulkan.c:202
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:100
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:657
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
OFFSET
#define OFFSET(x)
Definition: vf_scale_vulkan.c:369
AVFrame::width
int width
Definition: frame.h:402
ff_vk_filter_init
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
Definition: vulkan_filter.c:214
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:669
scale_vulkan_outputs
static const AVFilterPad scale_vulkan_outputs[]
Definition: vf_scale_vulkan.c:399
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
ff_vk_shader_create
int ff_vk_shader_create(FFVulkanContext *s, FFVkSPIRVShader *shd, uint8_t *spirv, size_t spirv_size, const char *entrypoint)
Definition: vulkan.c:1374
AVOption
AVOption.
Definition: opt.h:251
scale_vulkan_options
static const AVOption scale_vulkan_options[]
Definition: vf_scale_vulkan.c:371
rgb2yuv
static const char rgb2yuv[]
Definition: vf_scale_vulkan.c:69
write_nv12
static const char write_nv12[]
Definition: vf_scale_vulkan.c:83
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:1857
FFVkSPIRVCompiler::uninit
void(* uninit)(struct FFVkSPIRVCompiler **ctx)
Definition: vulkan_spirv.h:33
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
ff_vk_pipeline_descriptor_set_add
int ff_vk_pipeline_descriptor_set_add(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkSPIRVShader *shd, FFVulkanDescriptorSetBinding *desc, int nb, int read_only, int print_to_shader_only)
Add descriptor to a pipeline.
Definition: vulkan.c:1424
ScaleVulkanContext::sampler
VkSampler sampler
Definition: vf_scale_vulkan.c:44
ff_vk_shader_set_compute_sizes
void ff_vk_shader_set_compute_sizes(FFVkSPIRVShader *shd, int x, int y, int z)
Definition: vulkan.c:1332
ScaleVulkanContext::opts
struct ScaleVulkanContext::@263 opts
ScaleVulkanContext::yuv_matrix
float yuv_matrix[4][4]
Definition: vf_scale_vulkan.c:48
write_420
static const char write_420[]
Definition: vf_scale_vulkan.c:92
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:376
ScaleVulkanContext::e
FFVkExecPool e
Definition: vf_scale_vulkan.c:41
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(scale_vulkan)
ScalerFunc
ScalerFunc
Definition: vf_scale_vulkan.c:29
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2976
AVVulkanDeviceContext::alloc
const VkAllocationCallbacks * alloc
Custom memory allocator, else NULL.
Definition: hwcontext_vulkan.h:48
ff_vk_add_push_constant
int ff_vk_add_push_constant(FFVulkanPipeline *pl, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
Definition: vulkan.c:1104
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:412
fail
#define fail()
Definition: checkasm.h:137
vulkan_filter.h
colorspace.h
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
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
FFVulkanContext::output_width
int output_width
Definition: vulkan.h:259
F_NEAREST
@ F_NEAREST
Definition: vf_scale_vulkan.c:31
s
#define s(width, name)
Definition: cbs_vp9.c:256
F_BILINEAR
@ F_BILINEAR
Definition: vf_scale_vulkan.c:30
scale_vulkan_filter_frame
static int scale_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_scale_vulkan.c:269
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
ScaleVulkanContext::shd
FFVkSPIRVShader shd
Definition: vf_scale_vulkan.c:43
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AVFrame::crop_right
size_t crop_right
Definition: frame.h:771
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:66
FFVkSPIRVCompiler::compile_shader
int(* compile_shader)(struct FFVkSPIRVCompiler *ctx, void *avctx, struct FFVkSPIRVShader *shd, uint8_t **data, size_t *size, const char *entrypoint, void **opaque)
Definition: vulkan_spirv.h:29
ff_vk_exec_pool_free
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
Definition: vulkan.c:233
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:194
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
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:736
GLSLD
#define GLSLD(D)
Definition: vulkan.h:59
scale_vulkan_uninit
static void scale_vulkan_uninit(AVFilterContext *avctx)
Definition: vf_scale_vulkan.c:350
ScaleVulkanContext::h_expr
char * h_expr
Definition: vf_scale_vulkan.c:53
AVCHROMA_LOC_TOPLEFT
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition: pixfmt.h:692
AVFilterContext::inputs
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:405
ff_vk_filter_config_output
int ff_vk_filter_config_output(AVFilterLink *outlink)
Definition: vulkan_filter.c:191
ff_vk_init_compute_pipeline
int ff_vk_init_compute_pipeline(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkSPIRVShader *shd)
Definition: vulkan.c:1770
ff_vk_exec_pool_init
int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *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:272
FFVulkanContext
Definition: vulkan.h:227
ScaleVulkanContext::out_range
enum AVColorRange out_range
Definition: vf_scale_vulkan.c:56
F_NB
@ F_NB
Definition: vf_scale_vulkan.c:33
FLAGS
#define FLAGS
Definition: vf_scale_vulkan.c:370
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:635
ScaleVulkanContext::vkctx
FFVulkanContext vkctx
Definition: vf_scale_vulkan.c:37
FFVulkanPipeline
Definition: vulkan.h:131
AVFrame::crop_bottom
size_t crop_bottom
Definition: frame.h:769
ff_vk_shader_init
int ff_vk_shader_init(FFVulkanPipeline *pl, FFVkSPIRVShader *shd, const char *name, VkShaderStageFlags stage, uint32_t required_subgroup_size)
Shader management.
Definition: vulkan.c:1306
main
int main(int argc, char **argv)
Definition: avio_http_serve_files.c:99
AVFrame::crop_left
size_t crop_left
Definition: frame.h:770
f
f
Definition: af_crystalizer.c:122
FFVulkanDescriptorSetBinding
Definition: vulkan.h:83
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:114
AVFILTER_FLAG_HWDEVICE
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition: avfilter.h:138
size
int size
Definition: twinvq_data.h:10344
FFVkQueueFamilyCtx
Definition: vulkan.h:110
scale_eval.h
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:1156
internal.h
ff_vk_filter_process_simple
int ff_vk_filter_process_simple(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanPipeline *pl, AVFrame *out_f, AVFrame *in_f, VkSampler sampler, void *push_src, size_t push_size)
Submit a compute shader with a zero/one input and single out for execution.
Definition: vulkan_filter.c:223
FFVkSPIRVCompiler
Definition: vulkan_spirv.h:27
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:55
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: internal.h:184
ff_fill_rgb2yuv_table
void ff_fill_rgb2yuv_table(const AVLumaCoefficients *coeffs, double rgb2yuv[3][3])
Definition: colorspace.c:125
ff_vf_scale_vulkan
const AVFilter ff_vf_scale_vulkan
Definition: vf_scale_vulkan.c:407
ScaleVulkanContext::w_expr
char * w_expr
Definition: vf_scale_vulkan.c:52
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
scale_bilinear
static const char scale_bilinear[]
Definition: vf_scale_vulkan.c:59
write_444
static const char write_444[]
Definition: vf_scale_vulkan.c:102
DUP_SAMPLER
#define DUP_SAMPLER(x)
Definition: vulkan.h:73
ff_vk_shader_rep_fmt
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pixfmt)
Returns the format to use for images in shaders.
Definition: vulkan.c:1168
vulkan_spirv.h
scale_vulkan_inputs
static const AVFilterPad scale_vulkan_inputs[]
Definition: vf_scale_vulkan.c:390
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:55
GLSLF
#define GLSLF(N, S,...)
Definition: vulkan.h:54
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:652
FFVkSPIRVCompiler::free_shader
void(* free_shader)(struct FFVkSPIRVCompiler *ctx, void **opaque)
Definition: vulkan_spirv.h:32
AVFilter
Filter definition.
Definition: avfilter.h:166
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:89
FFVulkanContext::vkfn
FFVulkanFunctions vkfn
Definition: vulkan.h:230
FFVkExecPool
Definition: vulkan.h:208
pos
unsigned int pos
Definition: spdifenc.c:413
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2868
AVFrame::height
int height
Definition: frame.h:402
random_seed.h
ScaleVulkanContext::initialized
int initialized
Definition: vf_scale_vulkan.c:39
FFVkSPIRVShader
Definition: vulkan.h:75
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
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:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:397
ScaleVulkanContext
Definition: vf_scale_vulkan.c:36
desc
const char * desc
Definition: libsvtav1.c:83
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:160
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FFVulkanContext::hwctx
AVVulkanDeviceContext * hwctx
Definition: vulkan.h:248
AVVulkanDeviceContext::act_dev
VkDevice act_dev
Active device.
Definition: hwcontext_vulkan.h:70
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:195
ff_vk_init_sampler
int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler, int unnorm_coords, VkFilter filt)
Create a sampler.
Definition: vulkan.c:1124
AVFrame::crop_top
size_t crop_top
Definition: frame.h:768
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
ff_vk_exec_pipeline_register
int ff_vk_exec_pipeline_register(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanPipeline *pl)
Register a pipeline with an exec pool.
Definition: vulkan.c:1538
scale_vulkan_config_output
static int scale_vulkan_config_output(AVFilterLink *outlink)
Definition: vf_scale_vulkan.c:307
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ScaleVulkanContext::pl
FFVulkanPipeline pl
Definition: vf_scale_vulkan.c:40
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:285
init_filter
static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
Definition: vf_scale_vulkan.c:111
ScaleVulkanContext::qf
FFVkQueueFamilyCtx qf
Definition: vf_scale_vulkan.c:42
ff_vk_shader_free
void ff_vk_shader_free(FFVulkanContext *s, FFVkSPIRVShader *shd)
Definition: vulkan.c:1365
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:634
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
RET
#define RET(x)
Definition: vulkan.h:67
FFVulkanFunctions
Definition: vulkan_functions.h:224
ScaleVulkanContext::out_format_string
char * out_format_string
Definition: vf_scale_vulkan.c:51