Commit 3650cb2d authored by Mark Thompson's avatar Mark Thompson

lavu,lavfi,ffmpeg: Remove experimental OpenCL API

This was added in early 2013 and abandoned several months later; as far as
I can tell, there are no external users.  Future OpenCL use will be via
hwcontext, which requires neither special OpenCL-only API nor global state
in libavutil.

All internal users are also deleted - this is just the unsharp filter
(replaced by unsharp_opencl, which is more flexible) and the deshake filter
(no replacement).
parent 0f93cef2
......@@ -3209,7 +3209,6 @@ deinterlace_qsv_filter_deps="libmfx"
deinterlace_vaapi_filter_deps="vaapi"
delogo_filter_deps="gpl"
deshake_filter_select="pixelutils"
deshake_filter_suggest="opencl"
drawtext_filter_deps="libfreetype"
drawtext_filter_suggest="libfontconfig libfribidi"
elbg_filter_deps="avcodec"
......@@ -3285,7 +3284,6 @@ tinterlace_pad_test_deps="tinterlace_filter"
tonemap_filter_deps="const_nan"
unsharp_opencl_filter_deps="opencl"
uspp_filter_deps="gpl avcodec"
unsharp_filter_suggest="opencl"
vaguedenoiser_filter_deps="gpl"
vidstabdetect_filter_deps="libvidstab"
vidstabtransform_filter_deps="libvidstab"
......
......@@ -15,6 +15,9 @@ libavutil: 2017-10-21
API changes, most recent first:
2017-11-xx - xxxxxxx - lavu 55.3.0 - opencl.h
Remove experiental OpenCL API (av_opencl_*).
2017-11-xx - xxxxxxx - lavu 55.2.0 - hwcontext.h hwcontext_opencl.h
Add AV_HWDEVICE_TYPE_OPENCL and a new installed header with
OpenCL-specific hwcontext definitions.
......
......@@ -6913,10 +6913,6 @@ Default value is @samp{exhaustive}.
If set then a detailed log of the motion search is written to the
specified file.
@item opencl
If set to 1, specify using OpenCL capabilities, only available if
FFmpeg was configured with @code{--enable-opencl}. Default value is 0.
@end table
@section despill
......@@ -15048,10 +15044,6 @@ sharpen it, a value of zero will disable the effect.
Default value is 0.0.
@item opencl
If set to 1, specify using OpenCL capabilities, only available if
FFmpeg was configured with @code{--enable-opencl}. Default value is 0.
@end table
All parameters are optional and default to the equivalent of the
......
......@@ -1057,33 +1057,3 @@ indication of the corresponding powers of 10 and of 2.
@end table
@c man end EXPRESSION EVALUATION
@chapter OpenCL Options
@c man begin OPENCL OPTIONS
When FFmpeg is configured with @code{--enable-opencl}, it is possible
to set the options for the global OpenCL context.
The list of supported options follows:
@table @option
@item build_options
Set build options used to compile the registered kernels.
See reference "OpenCL Specification Version: 1.2 chapter 5.6.4".
@item platform_idx
Select the index of the platform to run OpenCL code.
The specified index must be one of the indexes in the device list
which can be obtained with @code{ffmpeg -opencl_bench} or @code{av_opencl_get_device_list()}.
@item device_idx
Select the index of the device used to run OpenCL code.
The specified index must be one of the indexes in the device list which
can be obtained with @code{ffmpeg -opencl_bench} or @code{av_opencl_get_device_list()}.
@end table
@c man end OPENCL OPTIONS
......@@ -29,7 +29,6 @@ $(1)$(PROGSSUF)_g$(EXESUF): FF_EXTRALIBS += $(EXTRALIBS-$(1))
-include $$(OBJS-$(1):.o=.d)
endef
$(foreach P,$(AVPROGS-yes),$(eval OBJS-$(P)-$(CONFIG_OPENCL) += fftools/cmdutils_opencl.o))
$(foreach P,$(AVPROGS-yes),$(eval $(call DOFFTOOL,$(P))))
all: $(AVPROGS)
......
......@@ -105,12 +105,6 @@ int opt_max_alloc(void *optctx, const char *opt, const char *arg);
int opt_codec_debug(void *optctx, const char *opt, const char *arg);
#if CONFIG_OPENCL
int opt_opencl(void *optctx, const char *opt, const char *arg);
int opt_opencl_bench(void *optctx, const char *opt, const char *arg);
#endif
/**
* Limit the execution time.
*/
......@@ -207,17 +201,6 @@ typedef struct OptionDef {
void show_help_options(const OptionDef *options, const char *msg, int req_flags,
int rej_flags, int alt_flags);
#if CONFIG_OPENCL
#define CMDUTILS_COMMON_OPTIONS_OPENCL \
{ "opencl_bench", OPT_EXIT, {.func_arg = opt_opencl_bench}, \
"run benchmark on all OpenCL devices and show results" }, \
{ "opencl_options", HAS_ARG, {.func_arg = opt_opencl}, \
"set OpenCL environment options" }, \
#else
#define CMDUTILS_COMMON_OPTIONS_OPENCL
#endif
#if CONFIG_AVDEVICE
#define CMDUTILS_COMMON_OPTIONS_AVDEVICE \
{ "sources" , OPT_EXIT | HAS_ARG, { .func_arg = show_sources }, \
......@@ -257,7 +240,6 @@ void show_help_options(const OptionDef *options, const char *msg, int req_flags,
{ "max_alloc", HAS_ARG, { .func_arg = opt_max_alloc }, "set maximum size of a single allocated block", "bytes" }, \
{ "cpuflags", HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, \
{ "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, \
CMDUTILS_COMMON_OPTIONS_OPENCL \
CMDUTILS_COMMON_OPTIONS_AVDEVICE \
/**
......
This diff is collapsed.
......@@ -19,7 +19,6 @@ OBJS = allfilters.o \
framequeue.o \
graphdump.o \
graphparser.o \
opencl_allkernels.o \
transform.o \
video.o \
......@@ -250,7 +249,6 @@ OBJS-$(CONFIG_NOISE_FILTER) += vf_noise.o
OBJS-$(CONFIG_NULL_FILTER) += vf_null.o
OBJS-$(CONFIG_OCR_FILTER) += vf_ocr.o
OBJS-$(CONFIG_OCV_FILTER) += vf_libopencv.o
OBJS-$(CONFIG_OPENCL) += deshake_opencl.o unsharp_opencl.o
OBJS-$(CONFIG_OSCILLOSCOPE_FILTER) += vf_datascope.o
OBJS-$(CONFIG_OVERLAY_FILTER) += vf_overlay.o framesync.o
OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER) += vf_overlay_opencl.o opencl.o \
......@@ -396,7 +394,6 @@ OBJS-$(CONFIG_MOVIE_FILTER) += src_movie.o
SLIBOBJS-$(HAVE_GNU_WINDRES) += avfilterres.o
SKIPHEADERS-$(CONFIG_LIBVIDSTAB) += vidstabutils.h
SKIPHEADERS-$(CONFIG_OPENCL) += opencl_internal.h deshake_opencl_kernel.h unsharp_opencl_kernel.h
OBJS-$(CONFIG_SHARED) += log2_tab.o
......
......@@ -22,7 +22,6 @@
#include "libavutil/thread.h"
#include "avfilter.h"
#include "config.h"
#include "opencl_allkernels.h"
#define REGISTER_FILTER(X, x, y) \
......@@ -407,7 +406,6 @@ static void register_all(void)
REGISTER_FILTER_UNCONDITIONAL(vsink_buffer);
REGISTER_FILTER_UNCONDITIONAL(af_afifo);
REGISTER_FILTER_UNCONDITIONAL(vf_fifo);
ff_opencl_register_filter_kernel_code_all();
}
void avfilter_register_all(void)
......
......@@ -26,9 +26,6 @@
#include "avfilter.h"
#include "transform.h"
#include "libavutil/pixelutils.h"
#if CONFIG_OPENCL
#include "libavutil/opencl.h"
#endif
enum SearchMethod {
......@@ -53,24 +50,6 @@ typedef struct Transform {
double zoom; ///< Zoom percentage
} Transform;
#if CONFIG_OPENCL
typedef struct DeshakeOpenclContext {
cl_command_queue command_queue;
cl_program program;
cl_kernel kernel_luma;
cl_kernel kernel_chroma;
int in_plane_size[8];
int out_plane_size[8];
int plane_num;
cl_mem cl_inbuf;
size_t cl_inbuf_size;
cl_mem cl_outbuf;
size_t cl_outbuf_size;
} DeshakeOpenclContext;
#endif
#define MAX_R 64
typedef struct DeshakeContext {
......@@ -96,9 +75,6 @@ typedef struct DeshakeContext {
int cy;
char *filename; ///< Motion search detailed log filename
int opencl;
#if CONFIG_OPENCL
DeshakeOpenclContext opencl_ctx;
#endif
int (* transform)(AVFilterContext *ctx, int width, int height, int cw, int ch,
const float *matrix_y, const float *matrix_uv, enum InterpolateMethod interpolate,
enum FillMethod fill, AVFrame *in, AVFrame *out);
......
/*
* Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
* Copyright (C) 2013 Lenny Wang
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* transform input video
*/
#include "libavutil/common.h"
#include "libavutil/dict.h"
#include "libavutil/pixdesc.h"
#include "deshake_opencl.h"
#include "libavutil/opencl_internal.h"
#define PLANE_NUM 3
#define ROUND_TO_16(a) (((((a) - 1)/16)+1)*16)
int ff_opencl_transform(AVFilterContext *ctx,
int width, int height, int cw, int ch,
const float *matrix_y, const float *matrix_uv,
enum InterpolateMethod interpolate,
enum FillMethod fill, AVFrame *in, AVFrame *out)
{
int ret = 0;
cl_int status;
DeshakeContext *deshake = ctx->priv;
float4 packed_matrix_lu = {matrix_y[0], matrix_y[1], matrix_y[2], matrix_y[5]};
float4 packed_matrix_ch = {matrix_uv[0], matrix_uv[1], matrix_uv[2], matrix_uv[5]};
size_t global_worksize_lu[2] = {(size_t)ROUND_TO_16(width), (size_t)ROUND_TO_16(height)};
size_t global_worksize_ch[2] = {(size_t)ROUND_TO_16(cw), (size_t)(2*ROUND_TO_16(ch))};
size_t local_worksize[2] = {16, 16};
FFOpenclParam param_lu = {0};
FFOpenclParam param_ch = {0};
param_lu.ctx = param_ch.ctx = ctx;
param_lu.kernel = deshake->opencl_ctx.kernel_luma;
param_ch.kernel = deshake->opencl_ctx.kernel_chroma;
if ((unsigned int)interpolate > INTERPOLATE_BIQUADRATIC) {
av_log(ctx, AV_LOG_ERROR, "Selected interpolate method is invalid\n");
return AVERROR(EINVAL);
}
ret = avpriv_opencl_set_parameter(&param_lu,
FF_OPENCL_PARAM_INFO(deshake->opencl_ctx.cl_inbuf),
FF_OPENCL_PARAM_INFO(deshake->opencl_ctx.cl_outbuf),
FF_OPENCL_PARAM_INFO(packed_matrix_lu),
FF_OPENCL_PARAM_INFO(interpolate),
FF_OPENCL_PARAM_INFO(fill),
FF_OPENCL_PARAM_INFO(in->linesize[0]),
FF_OPENCL_PARAM_INFO(out->linesize[0]),
FF_OPENCL_PARAM_INFO(height),
FF_OPENCL_PARAM_INFO(width),
NULL);
if (ret < 0)
return ret;
ret = avpriv_opencl_set_parameter(&param_ch,
FF_OPENCL_PARAM_INFO(deshake->opencl_ctx.cl_inbuf),
FF_OPENCL_PARAM_INFO(deshake->opencl_ctx.cl_outbuf),
FF_OPENCL_PARAM_INFO(packed_matrix_ch),
FF_OPENCL_PARAM_INFO(interpolate),
FF_OPENCL_PARAM_INFO(fill),
FF_OPENCL_PARAM_INFO(in->linesize[0]),
FF_OPENCL_PARAM_INFO(out->linesize[0]),
FF_OPENCL_PARAM_INFO(in->linesize[1]),
FF_OPENCL_PARAM_INFO(out->linesize[1]),
FF_OPENCL_PARAM_INFO(height),
FF_OPENCL_PARAM_INFO(width),
FF_OPENCL_PARAM_INFO(ch),
FF_OPENCL_PARAM_INFO(cw),
NULL);
if (ret < 0)
return ret;
status = clEnqueueNDRangeKernel(deshake->opencl_ctx.command_queue,
deshake->opencl_ctx.kernel_luma, 2, NULL,
global_worksize_lu, local_worksize, 0, NULL, NULL);
status |= clEnqueueNDRangeKernel(deshake->opencl_ctx.command_queue,
deshake->opencl_ctx.kernel_chroma, 2, NULL,
global_worksize_ch, local_worksize, 0, NULL, NULL);
if (status != CL_SUCCESS) {
av_log(ctx, AV_LOG_ERROR, "OpenCL run kernel error occurred: %s\n", av_opencl_errstr(status));
return AVERROR_EXTERNAL;
}
ret = av_opencl_buffer_read_image(out->data, deshake->opencl_ctx.out_plane_size,
deshake->opencl_ctx.plane_num, deshake->opencl_ctx.cl_outbuf,
deshake->opencl_ctx.cl_outbuf_size);
if (ret < 0)
return ret;
return ret;
}
int ff_opencl_deshake_init(AVFilterContext *ctx)
{
int ret = 0;
DeshakeContext *deshake = ctx->priv;
ret = av_opencl_init(NULL);
if (ret < 0)
return ret;
deshake->opencl_ctx.plane_num = PLANE_NUM;
deshake->opencl_ctx.command_queue = av_opencl_get_command_queue();
if (!deshake->opencl_ctx.command_queue) {
av_log(ctx, AV_LOG_ERROR, "Unable to get OpenCL command queue in filter 'deshake'\n");
return AVERROR(EINVAL);
}
deshake->opencl_ctx.program = av_opencl_compile("avfilter_transform", NULL);
if (!deshake->opencl_ctx.program) {
av_log(ctx, AV_LOG_ERROR, "OpenCL failed to compile program 'avfilter_transform'\n");
return AVERROR(EINVAL);
}
if (!deshake->opencl_ctx.kernel_luma) {
deshake->opencl_ctx.kernel_luma = clCreateKernel(deshake->opencl_ctx.program,
"avfilter_transform_luma", &ret);
if (ret != CL_SUCCESS) {
av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'avfilter_transform_luma'\n");
return AVERROR(EINVAL);
}
}
if (!deshake->opencl_ctx.kernel_chroma) {
deshake->opencl_ctx.kernel_chroma = clCreateKernel(deshake->opencl_ctx.program,
"avfilter_transform_chroma", &ret);
if (ret != CL_SUCCESS) {
av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'avfilter_transform_chroma'\n");
return AVERROR(EINVAL);
}
}
return ret;
}
void ff_opencl_deshake_uninit(AVFilterContext *ctx)
{
DeshakeContext *deshake = ctx->priv;
av_opencl_buffer_release(&deshake->opencl_ctx.cl_inbuf);
av_opencl_buffer_release(&deshake->opencl_ctx.cl_outbuf);
clReleaseKernel(deshake->opencl_ctx.kernel_luma);
clReleaseKernel(deshake->opencl_ctx.kernel_chroma);
clReleaseProgram(deshake->opencl_ctx.program);
deshake->opencl_ctx.command_queue = NULL;
av_opencl_uninit();
}
int ff_opencl_deshake_process_inout_buf(AVFilterContext *ctx, AVFrame *in, AVFrame *out)
{
int ret = 0;
AVFilterLink *link = ctx->inputs[0];
DeshakeContext *deshake = ctx->priv;
const int hshift = av_pix_fmt_desc_get(link->format)->log2_chroma_h;
int chroma_height = AV_CEIL_RSHIFT(link->h, hshift);
if ((!deshake->opencl_ctx.cl_inbuf) || (!deshake->opencl_ctx.cl_outbuf)) {
deshake->opencl_ctx.in_plane_size[0] = (in->linesize[0] * in->height);
deshake->opencl_ctx.in_plane_size[1] = (in->linesize[1] * chroma_height);
deshake->opencl_ctx.in_plane_size[2] = (in->linesize[2] * chroma_height);
deshake->opencl_ctx.out_plane_size[0] = (out->linesize[0] * out->height);
deshake->opencl_ctx.out_plane_size[1] = (out->linesize[1] * chroma_height);
deshake->opencl_ctx.out_plane_size[2] = (out->linesize[2] * chroma_height);
deshake->opencl_ctx.cl_inbuf_size = deshake->opencl_ctx.in_plane_size[0] +
deshake->opencl_ctx.in_plane_size[1] +
deshake->opencl_ctx.in_plane_size[2];
deshake->opencl_ctx.cl_outbuf_size = deshake->opencl_ctx.out_plane_size[0] +
deshake->opencl_ctx.out_plane_size[1] +
deshake->opencl_ctx.out_plane_size[2];
if (!deshake->opencl_ctx.cl_inbuf) {
ret = av_opencl_buffer_create(&deshake->opencl_ctx.cl_inbuf,
deshake->opencl_ctx.cl_inbuf_size,
CL_MEM_READ_ONLY, NULL);
if (ret < 0)
return ret;
}
if (!deshake->opencl_ctx.cl_outbuf) {
ret = av_opencl_buffer_create(&deshake->opencl_ctx.cl_outbuf,
deshake->opencl_ctx.cl_outbuf_size,
CL_MEM_READ_WRITE, NULL);
if (ret < 0)
return ret;
}
}
ret = av_opencl_buffer_write_image(deshake->opencl_ctx.cl_inbuf,
deshake->opencl_ctx.cl_inbuf_size,
0, in->data,deshake->opencl_ctx.in_plane_size,
deshake->opencl_ctx.plane_num);
return ret;
}
/*
* Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFILTER_DESHAKE_OPENCL_H
#define AVFILTER_DESHAKE_OPENCL_H
#include "deshake.h"
typedef struct float4 {
float x;
float y;
float z;
float w;
} float4;
int ff_opencl_deshake_init(AVFilterContext *ctx);
void ff_opencl_deshake_uninit(AVFilterContext *ctx);
int ff_opencl_deshake_process_inout_buf(AVFilterContext *ctx, AVFrame *in, AVFrame *out);
int ff_opencl_transform(AVFilterContext *ctx,
int width, int height, int cw, int ch,
const float *matrix_y, const float *matrix_uv,
enum InterpolateMethod interpolate,
enum FillMethod fill, AVFrame *in, AVFrame *out);
#endif /* AVFILTER_DESHAKE_OPENCL_H */
/*
* Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
* Copyright (C) 2013 Lenny Wang
*
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFILTER_DESHAKE_OPENCL_KERNEL_H
#define AVFILTER_DESHAKE_OPENCL_KERNEL_H
#include "libavutil/opencl.h"
const char *ff_kernel_deshake_opencl = AV_OPENCL_KERNEL(
inline unsigned char pixel(global const unsigned char *src, int x, int y,
int w, int h,int stride, unsigned char def)
{
return (x < 0 || y < 0 || x >= w || y >= h) ? def : src[x + y * stride];
}
unsigned char interpolate_nearest(float x, float y, global const unsigned char *src,
int width, int height, int stride, unsigned char def)
{
return pixel(src, (int)(x + 0.5f), (int)(y + 0.5f), width, height, stride, def);
}
unsigned char interpolate_bilinear(float x, float y, global const unsigned char *src,
int width, int height, int stride, unsigned char def)
{
int x_c, x_f, y_c, y_f;
int v1, v2, v3, v4;
x_f = (int)x;
y_f = (int)y;
x_c = x_f + 1;
y_c = y_f + 1;
if (x_f < -1 || x_f > width || y_f < -1 || y_f > height) {
return def;
} else {
v4 = pixel(src, x_f, y_f, width, height, stride, def);
v2 = pixel(src, x_c, y_f, width, height, stride, def);
v3 = pixel(src, x_f, y_c, width, height, stride, def);
v1 = pixel(src, x_c, y_c, width, height, stride, def);
return (v1*(x - x_f)*(y - y_f) + v2*((x - x_f)*(y_c - y)) +
v3*(x_c - x)*(y - y_f) + v4*((x_c - x)*(y_c - y)));
}
}
unsigned char interpolate_biquadratic(float x, float y, global const unsigned char *src,
int width, int height, int stride, unsigned char def)
{
int x_c, x_f, y_c, y_f;
unsigned char v1, v2, v3, v4;
float f1, f2, f3, f4;
x_f = (int)x;
y_f = (int)y;
x_c = x_f + 1;
y_c = y_f + 1;
if (x_f < - 1 || x_f > width || y_f < -1 || y_f > height)
return def;
else {
v4 = pixel(src, x_f, y_f, width, height, stride, def);
v2 = pixel(src, x_c, y_f, width, height, stride, def);
v3 = pixel(src, x_f, y_c, width, height, stride, def);
v1 = pixel(src, x_c, y_c, width, height, stride, def);
f1 = 1 - sqrt((x_c - x) * (y_c - y));
f2 = 1 - sqrt((x_c - x) * (y - y_f));
f3 = 1 - sqrt((x - x_f) * (y_c - y));
f4 = 1 - sqrt((x - x_f) * (y - y_f));
return (v1 * f1 + v2 * f2 + v3 * f3 + v4 * f4) / (f1 + f2 + f3 + f4);
}
}
inline const float clipf(float a, float amin, float amax)
{
if (a < amin) return amin;
else if (a > amax) return amax;
else return a;
}
inline int mirror(int v, int m)
{
while ((unsigned)v > (unsigned)m) {
v = -v;
if (v < 0)
v += 2 * m;
}
return v;
}
kernel void avfilter_transform_luma(global unsigned char *src,
global unsigned char *dst,
float4 matrix,
int interpolate,
int fill,
int src_stride_lu,
int dst_stride_lu,
int height,
int width)
{
int x = get_global_id(0);
int y = get_global_id(1);
int idx_dst = y * dst_stride_lu + x;
unsigned char def = 0;
float x_s = x * matrix.x + y * matrix.y + matrix.z;
float y_s = x * (-matrix.y) + y * matrix.x + matrix.w;
if (x < width && y < height) {
switch (fill) {
case 0: //FILL_BLANK
def = 0;
break;
case 1: //FILL_ORIGINAL
def = src[y*src_stride_lu + x];
break;
case 2: //FILL_CLAMP
y_s = clipf(y_s, 0, height - 1);
x_s = clipf(x_s, 0, width - 1);
def = src[(int)y_s * src_stride_lu + (int)x_s];
break;
case 3: //FILL_MIRROR
y_s = mirror(y_s, height - 1);
x_s = mirror(x_s, width - 1);
def = src[(int)y_s * src_stride_lu + (int)x_s];
break;
}
switch (interpolate) {
case 0: //INTERPOLATE_NEAREST
dst[idx_dst] = interpolate_nearest(x_s, y_s, src, width, height, src_stride_lu, def);
break;
case 1: //INTERPOLATE_BILINEAR
dst[idx_dst] = interpolate_bilinear(x_s, y_s, src, width, height, src_stride_lu, def);
break;
case 2: //INTERPOLATE_BIQUADRATIC
dst[idx_dst] = interpolate_biquadratic(x_s, y_s, src, width, height, src_stride_lu, def);
break;
default:
return;
}
}
}
kernel void avfilter_transform_chroma(global unsigned char *src,
global unsigned char *dst,
float4 matrix,
int interpolate,
int fill,
int src_stride_lu,
int dst_stride_lu,
int src_stride_ch,
int dst_stride_ch,
int height,
int width,
int ch,
int cw)
{
int x = get_global_id(0);
int y = get_global_id(1);
int pad_ch = get_global_size(1)>>1;
global unsigned char *dst_u = dst + height * dst_stride_lu;
global unsigned char *src_u = src + height * src_stride_lu;
global unsigned char *dst_v = dst_u + ch * dst_stride_ch;
global unsigned char *src_v = src_u + ch * src_stride_ch;
src = y < pad_ch ? src_u : src_v;
dst = y < pad_ch ? dst_u : dst_v;
y = select(y - pad_ch, y, y < pad_ch);
float x_s = x * matrix.x + y * matrix.y + matrix.z;
float y_s = x * (-matrix.y) + y * matrix.x + matrix.w;
int idx_dst = y * dst_stride_ch + x;
unsigned char def;
if (x < cw && y < ch) {
switch (fill) {
case 0: //FILL_BLANK
def = 0;
break;
case 1: //FILL_ORIGINAL
def = src[y*src_stride_ch + x];
break;
case 2: //FILL_CLAMP
y_s = clipf(y_s, 0, ch - 1);
x_s = clipf(x_s, 0, cw - 1);
def = src[(int)y_s * src_stride_ch + (int)x_s];
break;
case 3: //FILL_MIRROR
y_s = mirror(y_s, ch - 1);
x_s = mirror(x_s, cw - 1);
def = src[(int)y_s * src_stride_ch + (int)x_s];
break;
}
switch (interpolate) {
case 0: //INTERPOLATE_NEAREST
dst[idx_dst] = interpolate_nearest(x_s, y_s, src, cw, ch, src_stride_ch, def);
break;
case 1: //INTERPOLATE_BILINEAR
dst[idx_dst] = interpolate_bilinear(x_s, y_s, src, cw, ch, src_stride_ch, def);
break;
case 2: //INTERPOLATE_BIQUADRATIC
dst[idx_dst] = interpolate_biquadratic(x_s, y_s, src, cw, ch, src_stride_ch, def);
break;
default:
return;
}
}
}
);
#endif /* AVFILTER_DESHAKE_OPENCL_KERNEL_H */
/*
* Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "opencl_allkernels.h"
#if CONFIG_OPENCL
#include "libavutil/opencl.h"
#include "deshake_opencl_kernel.h"
#include "unsharp_opencl_kernel.h"
#endif
#define OPENCL_REGISTER_KERNEL_CODE(X, x) \
{ \
if (CONFIG_##X##_FILTER) { \
av_opencl_register_kernel_code(ff_kernel_##x##_opencl); \
} \
}
void ff_opencl_register_filter_kernel_code_all(void)
{
#if CONFIG_OPENCL
OPENCL_REGISTER_KERNEL_CODE(DESHAKE, deshake);
OPENCL_REGISTER_KERNEL_CODE(UNSHARP, unsharp);
#endif
}
/*
* Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFILTER_OPENCL_ALLKERNELS_H
#define AVFILTER_OPENCL_ALLKERNELS_H
#include "avfilter.h"
#include "config.h"
void ff_opencl_register_filter_kernel_code_all(void);
#endif /* AVFILTER_OPENCL_ALLKERNELS_H */
......@@ -24,38 +24,10 @@
#include "config.h"
#include "avfilter.h"
#if CONFIG_OPENCL
#include "libavutil/opencl.h"
#endif
#define MIN_MATRIX_SIZE 3
#define MAX_MATRIX_SIZE 63
#if CONFIG_OPENCL
typedef struct UnsharpOpenclContext {
cl_command_queue command_queue;
cl_program program;
cl_kernel kernel_default;
cl_kernel kernel_luma;
cl_kernel kernel_chroma;
cl_mem cl_luma_mask;
cl_mem cl_chroma_mask;
cl_mem cl_luma_mask_x;
cl_mem cl_chroma_mask_x;
cl_mem cl_luma_mask_y;
cl_mem cl_chroma_mask_y;
int in_plane_size[8];
int out_plane_size[8];
int plane_num;
cl_mem cl_inbuf;
size_t cl_inbuf_size;
cl_mem cl_outbuf;
size_t cl_outbuf_size;
int use_fast_kernels;
} UnsharpOpenclContext;
#endif
typedef struct UnsharpFilterParam {
int msize_x; ///< matrix width
......@@ -76,9 +48,6 @@ typedef struct UnsharpContext {
UnsharpFilterParam chroma; ///< chroma parameters (width, height, amount)
int hsub, vsub;
int opencl;
#if CONFIG_OPENCL
UnsharpOpenclContext opencl_ctx;
#endif
int (* apply_unsharp)(AVFilterContext *ctx, AVFrame *in, AVFrame *out);
} UnsharpContext;
......
This diff is collapsed.
/*
* Copyright (C) 2013 Wei Gao <weigao@multicorewareinc.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFILTER_UNSHARP_OPENCL_H
#define AVFILTER_UNSHARP_OPENCL_H
#include "unsharp.h"
int ff_opencl_unsharp_init(AVFilterContext *ctx);
void ff_opencl_unsharp_uninit(AVFilterContext *ctx);
int ff_opencl_unsharp_process_inout_buf(AVFilterContext *ctx, AVFrame *in, AVFrame *out);
int ff_opencl_apply_unsharp(AVFilterContext *ctx, AVFrame *in, AVFrame *out);
#endif /* AVFILTER_UNSHARP_OPENCL_H */
This diff is collapsed.
......@@ -60,7 +60,6 @@
#include "libavutil/qsort.h"
#include "deshake.h"
#include "deshake_opencl.h"
#define OFFSET(x) offsetof(DeshakeContext, x)
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
......@@ -83,7 +82,7 @@ static const AVOption deshake_options[] = {
{ "exhaustive", "exhaustive search", 0, AV_OPT_TYPE_CONST, {.i64=EXHAUSTIVE}, INT_MIN, INT_MAX, FLAGS, "smode" },
{ "less", "less exhaustive search", 0, AV_OPT_TYPE_CONST, {.i64=SMART_EXHAUSTIVE}, INT_MIN, INT_MAX, FLAGS, "smode" },
{ "filename", "set motion search detailed log file name", OFFSET(filename), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
{ "opencl", "use OpenCL filtering capabilities", OFFSET(opencl), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = FLAGS },
{ "opencl", "ignored", OFFSET(opencl), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, .flags = FLAGS },
{ NULL }
};
......@@ -341,7 +340,6 @@ static int deshake_transform_c(AVFilterContext *ctx,
static av_cold int init(AVFilterContext *ctx)
{
int ret;
DeshakeContext *deshake = ctx->priv;
deshake->sad = av_pixelutils_get_sad_fn(4, 4, 1, deshake); // 16x16, 2nd source unaligned
......@@ -369,17 +367,7 @@ static av_cold int init(AVFilterContext *ctx)
deshake->cx &= ~15;
}
deshake->transform = deshake_transform_c;
if (!CONFIG_OPENCL && deshake->opencl) {
av_log(ctx, AV_LOG_ERROR, "OpenCL support was not enabled in this build, cannot be selected\n");
return AVERROR(EINVAL);
}
if (CONFIG_OPENCL && deshake->opencl) {
deshake->transform = ff_opencl_transform;
ret = ff_opencl_deshake_init(ctx);
if (ret < 0)
return ret;
}
av_log(ctx, AV_LOG_VERBOSE, "cx: %d, cy: %d, cw: %d, ch: %d, rx: %d, ry: %d, edge: %d blocksize: %d contrast: %d search: %d\n",
deshake->cx, deshake->cy, deshake->cw, deshake->ch,
deshake->rx, deshake->ry, deshake->edge, deshake->blocksize * 2, deshake->contrast, deshake->search);
......@@ -416,9 +404,6 @@ static int config_props(AVFilterLink *link)
static av_cold void uninit(AVFilterContext *ctx)
{
DeshakeContext *deshake = ctx->priv;
if (CONFIG_OPENCL && deshake->opencl) {
ff_opencl_deshake_uninit(ctx);
}
av_frame_free(&deshake->ref);
av_freep(&deshake->angles);
deshake->angles_size = 0;
......@@ -447,12 +432,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
}
av_frame_copy_props(out, in);
if (CONFIG_OPENCL && deshake->opencl) {
ret = ff_opencl_deshake_process_inout_buf(link->dst,in, out);
if (ret < 0)
goto fail;
}
if (deshake->cx < 0 || deshake->cy < 0 || deshake->cw < 0 || deshake->ch < 0) {
// Find the most likely global motion for the current frame
find_motion(deshake, (deshake->ref == NULL) ? in->data[0] : deshake->ref->data[0], in->data[0], link->w, link->h, in->linesize[0], &t);
......
......@@ -46,7 +46,6 @@
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "unsharp.h"
#include "unsharp_opencl.h"
static void apply_unsharp( uint8_t *dst, int dst_stride,
const uint8_t *src, int src_stride,
......@@ -134,10 +133,8 @@ static void set_filter_param(UnsharpFilterParam *fp, int msize_x, int msize_y, f
static av_cold int init(AVFilterContext *ctx)
{
int ret = 0;
UnsharpContext *s = ctx->priv;
set_filter_param(&s->luma, s->lmsize_x, s->lmsize_y, s->lamount);
set_filter_param(&s->chroma, s->cmsize_x, s->cmsize_y, s->camount);
......@@ -146,16 +143,6 @@ static av_cold int init(AVFilterContext *ctx)
return AVERROR(EINVAL);
}
s->apply_unsharp = apply_unsharp_c;
if (!CONFIG_OPENCL && s->opencl) {
av_log(ctx, AV_LOG_ERROR, "OpenCL support was not enabled in this build, cannot be selected\n");
return AVERROR(EINVAL);
}
if (CONFIG_OPENCL && s->opencl) {
s->apply_unsharp = ff_opencl_apply_unsharp;
ret = ff_opencl_unsharp_init(ctx);
if (ret < 0)
return ret;
}
return 0;
}
......@@ -227,10 +214,6 @@ static av_cold void uninit(AVFilterContext *ctx)
{
UnsharpContext *s = ctx->priv;
if (CONFIG_OPENCL && s->opencl) {
ff_opencl_unsharp_uninit(ctx);
}
free_filter_param(&s->luma);
free_filter_param(&s->chroma);
}
......@@ -248,14 +231,9 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
return AVERROR(ENOMEM);
}
av_frame_copy_props(out, in);
if (CONFIG_OPENCL && s->opencl) {
ret = ff_opencl_unsharp_process_inout_buf(link->dst, in, out);
if (ret < 0)
goto end;
}
ret = s->apply_unsharp(link->dst, in, out);
end:
av_frame_free(&in);
if (ret < 0) {
......@@ -282,7 +260,7 @@ static const AVOption unsharp_options[] = {
{ "cy", "set chroma matrix vertical size", OFFSET(cmsize_y), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS },
{ "chroma_amount", "set chroma effect strength", OFFSET(camount), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, -2, 5, FLAGS },
{ "ca", "set chroma effect strength", OFFSET(camount), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, -2, 5, FLAGS },
{ "opencl", "use OpenCL filtering capabilities", OFFSET(opencl), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ "opencl", "ignored", OFFSET(opencl), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ NULL }
};
......
......@@ -79,8 +79,6 @@ HEADERS = adler32.h \
HEADERS-$(CONFIG_LZO) += lzo.h
HEADERS-$(CONFIG_OPENCL) += opencl.h
ARCH_HEADERS = bswap.h \
intmath.h \
intreadwrite.h \
......@@ -164,7 +162,6 @@ OBJS-$(CONFIG_DXVA2) += hwcontext_dxva2.o
OBJS-$(CONFIG_QSV) += hwcontext_qsv.o
OBJS-$(CONFIG_LIBDRM) += hwcontext_drm.o
OBJS-$(CONFIG_LZO) += lzo.o
OBJS-$(CONFIG_OPENCL) += opencl.o opencl_internal.o
OBJS-$(CONFIG_OPENCL) += hwcontext_opencl.o
OBJS-$(CONFIG_VAAPI) += hwcontext_vaapi.o
OBJS-$(CONFIG_VIDEOTOOLBOX) += hwcontext_videotoolbox.o
......@@ -187,7 +184,6 @@ SKIPHEADERS-$(CONFIG_VDPAU) += hwcontext_vdpau.h
SKIPHEADERS-$(HAVE_ATOMICS_GCC) += atomic_gcc.h
SKIPHEADERS-$(HAVE_ATOMICS_SUNCC) += atomic_suncc.h
SKIPHEADERS-$(HAVE_ATOMICS_WIN32) += atomic_win32.h
SKIPHEADERS-$(CONFIG_OPENCL) += opencl.h
TESTPROGS = adler32 \
aes \
......
This diff is collapsed.
/*
* Copyright (C) 2012 Peng Gao <peng@multicorewareinc.com>
* Copyright (C) 2012 Li Cao <li@multicorewareinc.com>
* Copyright (C) 2012 Wei Gao <weigao@multicorewareinc.com>
* Copyright (C) 2013 Lenny Wang <lwanghpc@gmail.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* OpenCL wrapper
*
* This interface is considered still experimental and its API and ABI may
* change without prior notice.
*/
#ifndef AVUTIL_OPENCL_H
#define AVUTIL_OPENCL_H
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS 1
#ifdef __APPLE__
#include <OpenCL/cl.h>
#else
#include <CL/cl.h>
#endif
#include <stdint.h>
#include "dict.h"
#include "libavutil/version.h"
#define AV_OPENCL_KERNEL( ... )# __VA_ARGS__
typedef struct {
int device_type;
char *device_name;
cl_device_id device_id;
} AVOpenCLDeviceNode;
typedef struct {
cl_platform_id platform_id;
char *platform_name;
int device_num;
AVOpenCLDeviceNode **device_node;
} AVOpenCLPlatformNode;
typedef struct {
int platform_num;
AVOpenCLPlatformNode **platform_node;
} AVOpenCLDeviceList;
typedef struct {
cl_platform_id platform_id;
cl_device_type device_type;
cl_context context;
cl_device_id device_id;
cl_command_queue command_queue;
char *platform_name;
} AVOpenCLExternalEnv;
/**
* Get OpenCL device list.
*
* It must be freed with av_opencl_free_device_list().
*
* @param device_list pointer to OpenCL environment device list,
* should be released by av_opencl_free_device_list()
*
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_get_device_list(AVOpenCLDeviceList **device_list);
/**
* Free OpenCL device list.
*
* @param device_list pointer to OpenCL environment device list
* created by av_opencl_get_device_list()
*/
void av_opencl_free_device_list(AVOpenCLDeviceList **device_list);
/**
* Set option in the global OpenCL context.
*
* This options affect the operation performed by the next
* av_opencl_init() operation.
*
* The currently accepted options are:
* - platform: set index of platform in device list
* - device: set index of device in device list
*
* See reference "OpenCL Specification Version: 1.2 chapter 5.6.4".
*
* @param key option key
* @param val option value
* @return >=0 on success, a negative error code in case of failure
* @see av_opencl_get_option()
*/
int av_opencl_set_option(const char *key, const char *val);
/**
* Get option value from the global OpenCL context.
*
* @param key option key
* @param out_val pointer to location where option value will be
* written, must be freed with av_freep()
* @return >=0 on success, a negative error code in case of failure
* @see av_opencl_set_option()
*/
int av_opencl_get_option(const char *key, uint8_t **out_val);
/**
* Free option values of the global OpenCL context.
*
*/
void av_opencl_free_option(void);
/**
* Allocate OpenCL external environment.
*
* It must be freed with av_opencl_free_external_env().
*
* @return pointer to allocated OpenCL external environment
*/
AVOpenCLExternalEnv *av_opencl_alloc_external_env(void);
/**
* Free OpenCL external environment.
*
* @param ext_opencl_env pointer to OpenCL external environment
* created by av_opencl_alloc_external_env()
*/
void av_opencl_free_external_env(AVOpenCLExternalEnv **ext_opencl_env);
/**
* Get OpenCL error string.
*
* @param status OpenCL error code
* @return OpenCL error string
*/
const char *av_opencl_errstr(cl_int status);
/**
* Register kernel code.
*
* The registered kernel code is stored in a global context, and compiled
* in the runtime environment when av_opencl_init() is called.
*
* @param kernel_code kernel code to be compiled in the OpenCL runtime environment
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_register_kernel_code(const char *kernel_code);
/**
* Initialize the run time OpenCL environment
*
* @param ext_opencl_env external OpenCL environment, created by an
* application program, ignored if set to NULL
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_init(AVOpenCLExternalEnv *ext_opencl_env);
/**
* compile specific OpenCL kernel source
*
* @param program_name pointer to a program name used for identification
* @param build_opts pointer to a string that describes the preprocessor
* build options to be used for building the program
* @return a cl_program object
*/
cl_program av_opencl_compile(const char *program_name, const char* build_opts);
/**
* get OpenCL command queue
*
* @return a cl_command_queue object
*/
cl_command_queue av_opencl_get_command_queue(void);
/**
* Create OpenCL buffer.
*
* The buffer is used to save the data used or created by an OpenCL
* kernel.
* The created buffer must be released with av_opencl_buffer_release().
*
* See clCreateBuffer() function reference for more information about
* the parameters.
*
* @param cl_buf pointer to OpenCL buffer
* @param cl_buf_size size in bytes of the OpenCL buffer to create
* @param flags flags used to control buffer attributes
* @param host_ptr host pointer of the OpenCL buffer
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_buffer_create(cl_mem *cl_buf, size_t cl_buf_size, int flags, void *host_ptr);
/**
* Write OpenCL buffer with data from src_buf.
*
* @param dst_cl_buf pointer to OpenCL destination buffer
* @param src_buf pointer to source buffer
* @param buf_size size in bytes of the source and destination buffers
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_buffer_write(cl_mem dst_cl_buf, uint8_t *src_buf, size_t buf_size);
/**
* Read data from OpenCL buffer to memory buffer.
*
* @param dst_buf pointer to destination buffer (CPU memory)
* @param src_cl_buf pointer to source OpenCL buffer
* @param buf_size size in bytes of the source and destination buffers
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_buffer_read(uint8_t *dst_buf, cl_mem src_cl_buf, size_t buf_size);
/**
* Write image data from memory to OpenCL buffer.
*
* The source must be an array of pointers to image plane buffers.
*
* @param dst_cl_buf pointer to destination OpenCL buffer
* @param dst_cl_buf_size size in bytes of OpenCL buffer
* @param dst_cl_buf_offset the offset of the OpenCL buffer start position
* @param src_data array of pointers to source plane buffers
* @param src_plane_sizes array of sizes in bytes of the source plane buffers
* @param src_plane_num number of source image planes
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_buffer_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int dst_cl_offset,
uint8_t **src_data, int *plane_size, int plane_num);
/**
* Read image data from OpenCL buffer.
*
* @param dst_data array of pointers to destination plane buffers
* @param dst_plane_sizes array of pointers to destination plane buffers
* @param dst_plane_num number of destination image planes
* @param src_cl_buf pointer to source OpenCL buffer
* @param src_cl_buf_size size in bytes of OpenCL buffer
* @return >=0 on success, a negative error code in case of failure
*/
int av_opencl_buffer_read_image(uint8_t **dst_data, int *plane_size, int plane_num,
cl_mem src_cl_buf, size_t cl_buffer_size);
/**
* Release OpenCL buffer.
*
* @param cl_buf pointer to OpenCL buffer to release, which was
* previously filled with av_opencl_buffer_create()
*/
void av_opencl_buffer_release(cl_mem *cl_buf);
/**
* Release OpenCL environment.
*
* The OpenCL environment is effectively released only if all the created
* kernels had been released with av_opencl_release_kernel().
*/
void av_opencl_uninit(void);
/**
* Benchmark an OpenCL device with a user defined callback function. This function
* sets up an external OpenCL environment including context and command queue on
* the device then tears it down in the end. The callback function should perform
* the rest of the work.
*
* @param device pointer to the OpenCL device to be used
* @param platform cl_platform_id handle to which the device belongs to
* @param benchmark callback function to perform the benchmark, return a
* negative value in case of failure
* @return the score passed from the callback function, a negative error code in case
* of failure
*/
int64_t av_opencl_benchmark(AVOpenCLDeviceNode *device, cl_platform_id platform,
int64_t (*benchmark)(AVOpenCLExternalEnv *ext_opencl_env));
#endif /* AVUTIL_OPENCL_H */
/*
* Copyright (C) 2012 Peng Gao <peng@multicorewareinc.com>
* Copyright (C) 2012 Li Cao <li@multicorewareinc.com>
* Copyright (C) 2012 Wei Gao <weigao@multicorewareinc.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "opencl_internal.h"
#include "libavutil/log.h"
int avpriv_opencl_set_parameter(FFOpenclParam *opencl_param, ...)
{
int ret = 0;
va_list arg_ptr;
void *param;
size_t param_size;
cl_int status;
if (!opencl_param->kernel) {
av_log(opencl_param->ctx, AV_LOG_ERROR, "OpenCL kernel must be set\n");
return AVERROR(EINVAL);
}
va_start(arg_ptr, opencl_param);
do {
param = va_arg(arg_ptr, void *);
if (!param)
break;
param_size = va_arg(arg_ptr, size_t);
if (!param_size) {
av_log(opencl_param->ctx, AV_LOG_ERROR, "Parameter size must not be 0\n");
ret = AVERROR(EINVAL);
goto end;
}
status = clSetKernelArg(opencl_param->kernel, opencl_param->param_num, param_size, param);
if (status != CL_SUCCESS) {
av_log(opencl_param->ctx, AV_LOG_ERROR, "Cannot set kernel argument: %s\n", av_opencl_errstr(status));
ret = AVERROR_EXTERNAL;
goto end;
}
opencl_param->param_num++;
} while (param && param_size);
end:
va_end(arg_ptr);
return ret;
}
/*
* Copyright (C) 2012 Peng Gao <peng@multicorewareinc.com>
* Copyright (C) 2012 Li Cao <li@multicorewareinc.com>
* Copyright (C) 2012 Wei Gao <weigao@multicorewareinc.com>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVUTIL_OPENCL_INTERNAL_H
#define AVUTIL_OPENCL_INTERNAL_H
#include "attributes.h"
#include "opencl.h"
#define FF_OPENCL_PARAM_INFO(a) ((void*)(&(a))), (sizeof(a))
typedef struct {
cl_kernel kernel;
int param_num;
void *ctx;
} FFOpenclParam;
av_warn_unused_result
int avpriv_opencl_set_parameter(FFOpenclParam *opencl_param, ...);
#endif /* AVUTIL_OPENCL_INTERNAL_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment