19 #ifndef AVFILTER_OPENCL_H
20 #define AVFILTER_OPENCL_H
26 #define CL_USE_DEPRECATED_OPENCL_1_2_APIS
61 #define CL_SET_KERNEL_ARG(kernel, arg_num, type, arg) \
62 cle = clSetKernelArg(kernel, arg_num, sizeof(type), arg); \
63 if (cle != CL_SUCCESS) { \
64 av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " \
65 "argument %d: error %d.\n", arg_num, cle); \
74 #define CL_FAIL_ON_ERROR(errcode, ...) do { \
75 if (cle != CL_SUCCESS) { \
76 av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
93 #define CL_CREATE_KERNEL(ctx, kernel_name) do { \
94 ctx->kernel_ ## kernel_name = clCreateKernel(ctx->ocf.program, #kernel_name, &cle); \
95 CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to create %s kernel: %d.\n", #kernel_name, cle); \
101 #define CL_RELEASE_KERNEL(k) \
104 cle = clReleaseKernel(k); \
105 if (cle != CL_SUCCESS) \
106 av_log(avctx, AV_LOG_ERROR, "Failed to release " \
107 "OpenCL kernel: %d.\n", cle); \
114 #define CL_RELEASE_MEMORY(m) \
117 cle = clReleaseMemObject(m); \
118 if (cle != CL_SUCCESS) \
119 av_log(avctx, AV_LOG_ERROR, "Failed to release " \
120 "OpenCL memory: %d.\n", cle); \
127 #define CL_RELEASE_QUEUE(q) \
130 cle = clReleaseCommandQueue(q); \
131 if (cle != CL_SUCCESS) \
132 av_log(avctx, AV_LOG_ERROR, "Failed to release " \
133 "OpenCL command queue: %d.\n", cle); \
146 #define CL_ENQUEUE_KERNEL_WITH_ARGS(queue, kernel, global_work_size, local_work_size, event, ...) \
148 OpenCLKernelArg args[] = {__VA_ARGS__}; \
149 for (int i = 0; i < FF_ARRAY_ELEMS(args); i++) { \
150 cle = clSetKernelArg(kernel, i, args[i].arg_size, args[i].arg_val); \
151 if (cle != CL_SUCCESS) { \
152 av_log(avctx, AV_LOG_ERROR, "Failed to set kernel " \
153 "argument %d: error %d.\n", i, cle); \
154 err = AVERROR(EIO); \
159 cle = clEnqueueNDRangeKernel( \
162 FF_ARRAY_ELEMS(global_work_size), \
170 CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to enqueue kernel: %d.\n", cle); \
180 #define CL_RUN_KERNEL_WITH_ARGS(queue, kernel, global_work_size, local_work_size, event, ...) do { \
181 CL_ENQUEUE_KERNEL_WITH_ARGS( \
182 queue, kernel, global_work_size, local_work_size, event, __VA_ARGS__ \
185 cle = clFinish(queue); \
186 CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to finish command queue: %d.\n", cle); \
197 #define CL_CREATE_BUFFER_FLAGS(ctx, buffer_name, flags, size, host_ptr) do { \
198 ctx->buffer_name = clCreateBuffer( \
199 ctx->ocf.hwctx->context, \
205 CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to create buffer %s: %d.\n", #buffer_name, cle); \
214 #define CL_BLOCKING_WRITE_BUFFER(queue, buffer, size, host_ptr, event) do { \
215 cle = clEnqueueWriteBuffer( \
226 CL_FAIL_ON_ERROR(AVERROR(EIO), "Failed to write buffer to device: %d.\n", cle); \
237 #define CL_CREATE_BUFFER(ctx, buffer_name, size) CL_CREATE_BUFFER_FLAGS(ctx, buffer_name, 0, size, NULL)
272 const char **program_source_array,
281 const char *filename);
289 int block_alignment);
Main libavfilter public API header.
refcounted data buffer API
API-specific header for AV_HWDEVICE_TYPE_OPENCL.
void ff_opencl_filter_uninit(AVFilterContext *avctx)
Uninitialise an OpenCL filter context.
int ff_opencl_filter_load_program(AVFilterContext *avctx, const char **program_source_array, int nb_strings)
Load a new OpenCL program from strings in memory.
int ff_opencl_filter_config_input(AVFilterLink *inlink)
Check that the input link contains a suitable hardware frames context and extract the device from it.
int ff_opencl_filter_init(AVFilterContext *avctx)
Initialise an OpenCL filter context.
cl_ulong ff_opencl_get_event_time(cl_event event)
Gets the command start and end times for the given event and returns the difference (the time that th...
int ff_opencl_filter_work_size_from_image(AVFilterContext *avctx, size_t *work_size, AVFrame *frame, int plane, int block_alignment)
Find the work size needed needed for a given plane of an image.
int ff_opencl_filter_config_output(AVFilterLink *outlink)
Create a suitable hardware frames context for the output.
int ff_opencl_filter_query_formats(AVFilterContext *avctx)
Return that all inputs and outputs support only AV_PIX_FMT_OPENCL.
int ff_opencl_filter_load_program_from_file(AVFilterContext *avctx, const char *filename)
Load a new OpenCL program from a file.
void ff_opencl_print_const_matrix_3x3(AVBPrint *buf, const char *name_str, double mat[3][3])
Print a 3x3 matrix into a buffer as __constant array, which could be included in an OpenCL program.
AVPixelFormat
Pixel format.
A reference to a data buffer.
Describe the class of an AVClass context structure.
A link between two filters.
This structure describes decoded (raw) audio or video data.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
AVHWDeviceContext * device
enum AVPixelFormat output_format
AVOpenCLDeviceContext * hwctx