32 #define ROUND_TO_16(a) (((((a) - 1)/16)+1)*16)
37 for (i = 0; i <
len; i++) {
38 dst[i] = counter1[i] + counter2[i];
45 int counter_size =
sizeof(uint32_t) * (2 * step + 1);
46 uint32_t *temp1_counter, *temp2_counter, **counter;
62 for (i = 0; i < 2 * step + 1; i++) {
69 for (i = 0; i < 2 * step + 1; i++) {
70 memset(temp1_counter, 0, counter_size);
72 for (z = 0; z < step * 2; z += 2) {
74 memcpy(counter[z], temp1_counter, counter_size);
76 memcpy(counter[z + 1], temp2_counter, counter_size);
79 memcpy(mask, temp1_counter, counter_size);
83 for (i = 0; i < 2 * step + 1; i++) {
94 size_t size_matrix =
sizeof(uint32_t) * (2 * step_x + 1) * (2 * step_y + 1);
116 for (j = 0; j < 2 * step_y + 1; j++) {
117 for (i = 0; i < 2 * step_x + 1; i++) {
118 mask_matrix[i + j * (2 * step_x + 1)] = mask_y[j] * mask_x[i];
132 int i,
ret = 0, step_x[2], step_y[2];
134 mask_matrix[0] = unsharp->opencl_ctx.cl_luma_mask;
135 mask_matrix[1] = unsharp->opencl_ctx.cl_chroma_mask;
142 if (step_x[0]>8 || step_x[1]>8 || step_y[0]>8 || step_y[1]>8)
143 unsharp->opencl_ctx.use_fast_kernels = 0;
145 unsharp->opencl_ctx.use_fast_kernels = 1;
147 if (!mask_matrix[0] || !mask_matrix[1]) {
151 for (i = 0; i < 2; i++) {
171 size_t globalWorkSize1d = width * height + 2 * ch * cw;
172 size_t globalWorkSize2dLuma[2];
173 size_t globalWorkSize2dChroma[2];
174 size_t localWorkSize2d[2] = {16, 16};
176 if (unsharp->opencl_ctx.use_fast_kernels) {
177 globalWorkSize2dLuma[0] = (size_t)
ROUND_TO_16(width);
178 globalWorkSize2dLuma[1] = (size_t)
ROUND_TO_16(height);
179 globalWorkSize2dChroma[0] = (size_t)
ROUND_TO_16(cw);
180 globalWorkSize2dChroma[1] = (size_t)(2*
ROUND_TO_16(ch));
183 kernel1.
kernel = unsharp->opencl_ctx.kernel_luma;
200 kernel2.
kernel = unsharp->opencl_ctx.kernel_chroma;
219 status = clEnqueueNDRangeKernel(unsharp->opencl_ctx.command_queue,
220 unsharp->opencl_ctx.kernel_luma, 2, NULL,
221 globalWorkSize2dLuma, localWorkSize2d, 0, NULL, NULL);
222 status |=clEnqueueNDRangeKernel(unsharp->opencl_ctx.command_queue,
223 unsharp->opencl_ctx.kernel_chroma, 2, NULL,
224 globalWorkSize2dChroma, localWorkSize2d, 0, NULL, NULL);
225 if (status != CL_SUCCESS) {
231 kernel1.
kernel = unsharp->opencl_ctx.kernel_default;
259 status = clEnqueueNDRangeKernel(unsharp->opencl_ctx.command_queue,
260 unsharp->opencl_ctx.kernel_default, 1, NULL,
261 &globalWorkSize1d, NULL, 0, NULL, NULL);
262 if (status != CL_SUCCESS) {
267 clFinish(unsharp->opencl_ctx.command_queue);
269 unsharp->opencl_ctx.plane_num, unsharp->opencl_ctx.cl_outbuf,
270 unsharp->opencl_ctx.cl_outbuf_size);
283 CL_MEM_READ_ONLY, NULL);
288 CL_MEM_READ_ONLY, NULL);
294 unsharp->opencl_ctx.plane_num =
PLANE_NUM;
296 if (!unsharp->opencl_ctx.command_queue) {
297 av_log(ctx,
AV_LOG_ERROR,
"Unable to get OpenCL command queue in filter 'unsharp'\n");
300 snprintf(build_opts, 96,
"-D LU_RADIUS_X=%d -D LU_RADIUS_Y=%d -D CH_RADIUS_X=%d -D CH_RADIUS_Y=%d",
303 if (!unsharp->opencl_ctx.program) {
307 if (unsharp->opencl_ctx.use_fast_kernels) {
308 if (!unsharp->opencl_ctx.kernel_luma) {
309 unsharp->opencl_ctx.kernel_luma = clCreateKernel(unsharp->opencl_ctx.program,
"unsharp_luma", &ret);
310 if (ret != CL_SUCCESS) {
315 if (!unsharp->opencl_ctx.kernel_chroma) {
316 unsharp->opencl_ctx.kernel_chroma = clCreateKernel(unsharp->opencl_ctx.program,
"unsharp_chroma", &ret);
324 if (!unsharp->opencl_ctx.kernel_default) {
325 unsharp->opencl_ctx.kernel_default = clCreateKernel(unsharp->opencl_ctx.program,
"unsharp_default", &ret);
342 clReleaseKernel(unsharp->opencl_ctx.kernel_default);
343 clReleaseKernel(unsharp->opencl_ctx.kernel_luma);
344 clReleaseKernel(unsharp->opencl_ctx.kernel_chroma);
345 clReleaseProgram(unsharp->opencl_ctx.program);
346 unsharp->opencl_ctx.command_queue = NULL;
357 if ((!unsharp->opencl_ctx.cl_inbuf) || (!unsharp->opencl_ctx.cl_outbuf)) {
358 unsharp->opencl_ctx.in_plane_size[0] = (in->
linesize[0] * in->
height);
359 unsharp->opencl_ctx.in_plane_size[1] = (in->
linesize[1] * ch);
360 unsharp->opencl_ctx.in_plane_size[2] = (in->
linesize[2] * ch);
361 unsharp->opencl_ctx.out_plane_size[0] = (out->
linesize[0] * out->
height);
362 unsharp->opencl_ctx.out_plane_size[1] = (out->
linesize[1] * ch);
363 unsharp->opencl_ctx.out_plane_size[2] = (out->
linesize[2] * ch);
364 unsharp->opencl_ctx.cl_inbuf_size = unsharp->opencl_ctx.in_plane_size[0] +
365 unsharp->opencl_ctx.in_plane_size[1] +
366 unsharp->opencl_ctx.in_plane_size[2];
367 unsharp->opencl_ctx.cl_outbuf_size = unsharp->opencl_ctx.out_plane_size[0] +
368 unsharp->opencl_ctx.out_plane_size[1] +
369 unsharp->opencl_ctx.out_plane_size[2];
370 if (!unsharp->opencl_ctx.cl_inbuf) {
372 unsharp->opencl_ctx.cl_inbuf_size,
373 CL_MEM_READ_ONLY, NULL);
377 if (!unsharp->opencl_ctx.cl_outbuf) {
379 unsharp->opencl_ctx.cl_outbuf_size,
380 CL_MEM_READ_WRITE, NULL);
386 unsharp->opencl_ctx.cl_inbuf_size,
387 0, in->
data, unsharp->opencl_ctx.in_plane_size,
388 unsharp->opencl_ctx.plane_num);