diff options
author | Lenny Wang <lenny@multicorewareinc.com> | 2013-11-03 21:58:09 -0600 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-11-05 14:29:55 +0100 |
commit | 89a3be8921e265a487a5dfbd68671393b532edb7 (patch) | |
tree | 8864d1a3ac32a28d38d29ed387ef777a30a685ab /libavfilter/deshake_opencl.c | |
parent | 668255479085728bdf875a1b01c76201e2562a47 (diff) |
avfilter/opencl: compile kernels separately
Reviewed-by: Wei Gao <highgod0401@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavfilter/deshake_opencl.c')
-rw-r--r-- | libavfilter/deshake_opencl.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/libavfilter/deshake_opencl.c b/libavfilter/deshake_opencl.c index eea873ea4a..e4e4df19e8 100644 --- a/libavfilter/deshake_opencl.c +++ b/libavfilter/deshake_opencl.c @@ -45,7 +45,7 @@ int ff_opencl_transform(AVFilterContext *ctx, FFOpenclParam opencl_param = {0}; opencl_param.ctx = ctx; - opencl_param.kernel = deshake->opencl_ctx.kernel_env.kernel; + opencl_param.kernel = deshake->opencl_ctx.kernel; ret = av_opencl_buffer_write(deshake->opencl_ctx.cl_matrix_y, (uint8_t *)matrix_y, deshake->opencl_ctx.matrix_size * sizeof(cl_float)); if (ret < 0) return ret; @@ -75,14 +75,14 @@ int ff_opencl_transform(AVFilterContext *ctx, NULL); if (ret < 0) return ret; - status = clEnqueueNDRangeKernel(deshake->opencl_ctx.kernel_env.command_queue, - deshake->opencl_ctx.kernel_env.kernel, 1, NULL, + status = clEnqueueNDRangeKernel(deshake->opencl_ctx.command_queue, + deshake->opencl_ctx.kernel, 1, NULL, &global_work_size, NULL, 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; } - clFinish(deshake->opencl_ctx.kernel_env.command_queue); + clFinish(deshake->opencl_ctx.command_queue); 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); @@ -108,11 +108,21 @@ int ff_opencl_deshake_init(AVFilterContext *ctx) deshake->opencl_ctx.matrix_size*sizeof(cl_float), CL_MEM_READ_ONLY, NULL); if (ret < 0) return ret; - if (!deshake->opencl_ctx.kernel_env.kernel) { - ret = av_opencl_create_kernel(&deshake->opencl_ctx.kernel_env, "avfilter_transform"); - if (ret < 0) { - av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel for name 'avfilter_transform'\n"); - return ret; + 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) { + deshake->opencl_ctx.kernel = clCreateKernel(deshake->opencl_ctx.program, "avfilter_transform", &ret); + if (ret != CL_SUCCESS) { + av_log(ctx, AV_LOG_ERROR, "OpenCL failed to create kernel 'avfilter_transform'\n"); + return AVERROR(EINVAL); } } return ret; @@ -125,11 +135,12 @@ void ff_opencl_deshake_uninit(AVFilterContext *ctx) av_opencl_buffer_release(&deshake->opencl_ctx.cl_outbuf); av_opencl_buffer_release(&deshake->opencl_ctx.cl_matrix_y); av_opencl_buffer_release(&deshake->opencl_ctx.cl_matrix_uv); - av_opencl_release_kernel(&deshake->opencl_ctx.kernel_env); + clReleaseKernel(deshake->opencl_ctx.kernel); + 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; |