[FFmpeg-devel] [PATCH] avfilter/vf_program_opencl: make it possible to pass plane as argument to kernel
Paul B Mahol
onemda at gmail.com
Fri Feb 14 12:41:34 EET 2020
Fixes #7190
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
doc/filters.texi | 4 ++++
libavfilter/vf_program_opencl.c | 17 +++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/doc/filters.texi b/doc/filters.texi
index b957b9302e..5bd0e44b67 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -21297,6 +21297,8 @@ Number of inputs to the filter. Defaults to 1.
@item size, s
Size of output frames. Defaults to the same as the first input.
+ at item plane
+Currently processed plane number is set as last kernel argument.
@end table
The program source file must contain a kernel function with the given name,
@@ -22483,6 +22485,8 @@ Pixel format to use for the generated frames. This must be set.
@item rate, r
Number of frames generated every second. Default value is '25'.
+ at item plane
+Currently processed plane number is set as last kernel argument.
@end table
For details of how the program loading works, see the @ref{program_opencl}
diff --git a/libavfilter/vf_program_opencl.c b/libavfilter/vf_program_opencl.c
index ec25e931f5..3cf93464ba 100644
--- a/libavfilter/vf_program_opencl.c
+++ b/libavfilter/vf_program_opencl.c
@@ -42,6 +42,7 @@ typedef struct ProgramOpenCLContext {
const char *source_file;
const char *kernel_name;
int nb_inputs;
+ int plane_is_arg;
int width, height;
enum AVPixelFormat source_format;
AVRational source_rate;
@@ -138,6 +139,16 @@ static int program_opencl_run(AVFilterContext *avctx)
}
}
+ if (ctx->plane_is_arg) {
+ cle = clSetKernelArg(ctx->kernel, 2 + ctx->nb_inputs, sizeof(cl_int), &plane);
+ if (cle != CL_SUCCESS) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to set kernel "
+ "plane argument %d: %d.\n", plane, cle);
+ err = AVERROR_UNKNOWN;
+ goto fail;
+ }
+ }
+
err = ff_opencl_filter_work_size_from_image(avctx, global_work,
output, plane, 0);
if (err < 0)
@@ -348,6 +359,9 @@ static const AVOption program_opencl_options[] = {
{ "s", "Video size", OFFSET(width),
AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, FLAGS },
+ { "plane", "Pass currently processed plane as argument", OFFSET(plane_is_arg),
+ AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
+
{ NULL },
};
@@ -400,6 +414,9 @@ static const AVOption openclsrc_options[] = {
{ "r", "Video frame rate", OFFSET(source_rate),
AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, 0, INT_MAX, FLAGS },
+ { "plane", "Pass currently processed plane as argument", OFFSET(plane_is_arg),
+ AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
+
{ NULL },
};
--
2.17.1
More information about the ffmpeg-devel
mailing list