X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fopencl.h;h=1b7f117865304e95934ce93bd1fa91f0a73fdc0b;hb=1431ff2d379e25890309569dd99ca613b4fbb564;hp=4d740c18abaec0807d8db1de147086fde0a07227;hpb=061337a073236cb0bc6c56036f50f883d2887681;p=ffmpeg diff --git a/libavfilter/opencl.h b/libavfilter/opencl.h index 4d740c18aba..1b7f1178653 100644 --- a/libavfilter/opencl.h +++ b/libavfilter/opencl.h @@ -19,6 +19,12 @@ #ifndef AVFILTER_OPENCL_H #define AVFILTER_OPENCL_H +// The intended target is OpenCL 1.2, so disable warnings for APIs +// deprecated after that. This primarily applies to clCreateCommandQueue(), +// we can't use the replacement clCreateCommandQueueWithProperties() because +// it was introduced in OpenCL 2.0. +#define CL_USE_DEPRECATED_OPENCL_1_2_APIS + #include "libavutil/buffer.h" #include "libavutil/hwcontext.h" #include "libavutil/hwcontext_opencl.h" @@ -40,6 +46,33 @@ typedef struct OpenCLFilterContext { int output_height; } OpenCLFilterContext; + +/** + * set argument to specific Kernel. + * This macro relies on usage of local label "fail" and variables: + * avctx, cle and err. + */ +#define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg) \ + cle = clSetKernelArg(kernel, arg_num, sizeof(type), arg); \ + if (cle != CL_SUCCESS) { \ + av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " \ + "argument %d: error %d.\n", arg_num, cle); \ + err = AVERROR(EIO); \ + goto fail; \ + } + +/** + * A helper macro to handle OpenCL errors. It will assign errcode to + * variable err, log error msg, and jump to fail label on error. + */ +#define CL_FAIL_ON_ERROR(errcode, ...) do { \ + if (cle != CL_SUCCESS) { \ + av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \ + err = errcode; \ + goto fail; \ + } \ + } while(0) + /** * Return that all inputs and outputs support only AV_PIX_FMT_OPENCL. */ @@ -84,4 +117,12 @@ int ff_opencl_filter_load_program(AVFilterContext *avctx, int ff_opencl_filter_load_program_from_file(AVFilterContext *avctx, const char *filename); +/** + * Find the work size needed needed for a given plane of an image. + */ +int ff_opencl_filter_work_size_from_image(AVFilterContext *avctx, + size_t *work_size, + AVFrame *frame, int plane, + int block_alignment); + #endif /* AVFILTER_OPENCL_H */