blob: 262742da629d0df0cb602b81f3a95e55f491c4b4 [file] [log] [blame]
Wind Yuan87926782015-02-15 15:53:15 +08001/*
2 * cl_demo_handler.cpp - CL demo handler
3 *
4 * Copyright (c) 2015 Intel Corporation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Wind Yuan <feng.yuan@intel.com>
19 */
20#include "xcam_utils.h"
21#include "cl_demo_handler.h"
22
23namespace XCam {
24
25CLDemoImageKernel::CLDemoImageKernel (SmartPtr<CLContext> &context)
26 : CLImageKernel (context, "kernel_demo")
27{
28}
29
30XCamReturn
31CLDemoImageKernel::prepare_arguments (
32 SmartPtr<DrmBoBuffer> &input, SmartPtr<DrmBoBuffer> &output,
33 CLArgument args[], uint32_t &arg_count,
34 CLWorkSize &work_size)
35{
36 SmartPtr<CLContext> context = get_context ();
37 const VideoBufferInfo & video_info = input->get_video_info ();
38 cl_libva_image image_info;
Wind Yuan36b88352015-03-05 16:14:08 +080039 uint32_t channel_bits = XCAM_ALIGN_UP (video_info.color_bits, 8);
Wind Yuan87926782015-02-15 15:53:15 +080040
41 xcam_mem_clear (&image_info);
42 image_info.fmt.image_channel_order = CL_R;
Wind Yuan36b88352015-03-05 16:14:08 +080043 if (channel_bits == 8)
44 image_info.fmt.image_channel_data_type = CL_UNORM_INT8;
45 else if (channel_bits == 16)
46 image_info.fmt.image_channel_data_type = CL_UNORM_INT16;
Wind Yuan87926782015-02-15 15:53:15 +080047 image_info.offset = 0;
48 image_info.width = video_info.width;
Wind Yuan9d769892015-02-25 14:00:40 +080049 image_info.height = (video_info.size / video_info.strides[0])/4*4;
Wind Yuan87926782015-02-15 15:53:15 +080050 image_info.row_pitch = video_info.strides[0];
51
52 _image_in = new CLVaImage (context, input, &image_info);
53 _image_out = new CLVaImage (context, output, &image_info);
54
55 XCAM_ASSERT (_image_in->is_valid () && _image_out->is_valid ());
56 XCAM_FAIL_RETURN (
57 WARNING,
58 _image_in->is_valid () && _image_out->is_valid (),
59 XCAM_RETURN_ERROR_MEM,
60 "cl image kernel(%s) in/out memory not available", get_kernel_name ());
61
62 //set args;
63 args[0].arg_adress = &_image_in->get_mem_id ();
64 args[0].arg_size = sizeof (cl_mem);
65 args[1].arg_adress = &_image_out->get_mem_id ();
66 args[1].arg_size = sizeof (cl_mem);
67 arg_count = 2;
68
69 work_size.dim = XCAM_DEFAULT_IMAGE_DIM;
70 work_size.global[0] = image_info.row_pitch;
71 work_size.global[1] = image_info.height;
Wind Yuan9d769892015-02-25 14:00:40 +080072 work_size.local[0] = 8;
73 work_size.local[1] = 4;
Wind Yuan87926782015-02-15 15:53:15 +080074
75 return XCAM_RETURN_NO_ERROR;
76}
77
78
79XCamReturn
80CLDemoImageKernel::post_execute ()
81{
82 return CLImageKernel::post_execute ();
83}
84
85SmartPtr<CLImageHandler>
86create_cl_demo_image_handler (SmartPtr<CLContext> &context)
87{
88 SmartPtr<CLImageHandler> demo_handler;
89 SmartPtr<CLImageKernel> demo_kernel;
90 XCamReturn ret = XCAM_RETURN_NO_ERROR;
91
92 demo_kernel = new CLDemoImageKernel (context);
93 {
94 XCAM_CL_KERNEL_FUNC_SOURCE_BEGIN(kernel_demo)
95#include "kernel_demo.cl"
96 XCAM_CL_KERNEL_FUNC_END;
97 ret = demo_kernel->load_from_source (kernel_demo_body, strlen (kernel_demo_body));
98 XCAM_FAIL_RETURN (
99 WARNING,
100 ret == XCAM_RETURN_NO_ERROR,
101 NULL,
102 "CL image handler(%s) load source failed", demo_kernel->get_kernel_name());
103 }
104 XCAM_ASSERT (demo_kernel->is_valid ());
105 demo_handler = new CLImageHandler ("cl_handler_demo");
106 demo_handler->add_kernel (demo_kernel);
107
108 return demo_handler;
109}
110
111};