XCamReturn CLRgbPipeImageKernel::prepare_arguments ( SmartPtr<DrmBoBuffer> &input, SmartPtr<DrmBoBuffer> &output, CLArgument args[], uint32_t &arg_count, CLWorkSize &work_size) { SmartPtr<CLContext> context = get_context (); const VideoBufferInfo & video_info = input->get_video_info (); _image_in = new CLVaImage (context, input); _image_out = new CLVaImage (context, output); if (_image_in_list.size () < 4) { while (_image_in_list.size () < 4) { _image_in_list.push_back (_image_in); } } else { _image_in_list.pop_front (); _image_in_list.push_back (_image_in); } XCAM_ASSERT (_image_in->is_valid () && _image_out->is_valid ()); XCAM_FAIL_RETURN ( WARNING, _image_in->is_valid () && _image_out->is_valid (), XCAM_RETURN_ERROR_MEM, "cl image kernel(%s) in/out memory not available", get_kernel_name ()); //set args; args[0].arg_adress = &_image_out->get_mem_id (); args[0].arg_size = sizeof (cl_mem); args[1].arg_adress = &_tnr_config; args[1].arg_size = sizeof (CLRgbPipeTnrConfig); uint8_t index = 0; for (std::list<SmartPtr<CLImage>>::iterator it = _image_in_list.begin (); it != _image_in_list.end (); it++) { args[2 + index].arg_adress = &(*it)->get_mem_id (); args[2 + index].arg_size = sizeof (cl_mem); index++; } arg_count = 2 + index; work_size.dim = XCAM_DEFAULT_IMAGE_DIM; work_size.global[0] = XCAM_ALIGN_UP(video_info.width, 16); work_size.global[1] = XCAM_ALIGN_UP(video_info.height, 16); work_size.local[0] = 8; work_size.local[1] = 4; return XCAM_RETURN_NO_ERROR; }
SmartPtr<VKShader> VKDevice::create_shader (const char *file_name) { FileHandle file (file_name, "rb"); XCAM_FAIL_RETURN ( ERROR, file.is_valid (), NULL, "VKDevice load shader failed when opend shader file:%s.", XCAM_STR (file_name)); size_t file_size; XCAM_FAIL_RETURN ( ERROR, xcam_ret_is_ok (file.get_file_size (file_size)) || file_size == 0, NULL, "VKDevice load shader failed when read shader file:%s.", XCAM_STR (file_name)); std::vector<uint32_t> content (XCAM_ALIGN_UP (file_size, 4) / 4, 0); XCAM_FAIL_RETURN ( ERROR, xcam_ret_is_ok (file.read_file ((void *)content.data (), file_size)), NULL, "VKDevice load shader failed when read shader file:%s.", XCAM_STR (file_name)); file.close (); SmartPtr<VKShader> shader = create_shader (content); if (shader.ptr ()) shader->set_name (file_name); return shader; }
XCamReturn CLImageScaler::prepare_scaler_buf (const VideoBufferInfo &video_info, SmartPtr<VideoBuffer> &output) { if (!_scaler_buf_pool.ptr ()) { VideoBufferInfo scaler_video_info; uint32_t new_width = XCAM_ALIGN_UP ((uint32_t)(video_info.width * _h_scaler_factor), 2 * XCAM_CL_IMAGE_SCALER_KERNEL_LOCAL_WORK_SIZE0); uint32_t new_height = XCAM_ALIGN_UP ((uint32_t)(video_info.height * _v_scaler_factor), 2 * XCAM_CL_IMAGE_SCALER_KERNEL_LOCAL_WORK_SIZE1); scaler_video_info.init (video_info.format, new_width, new_height); SmartPtr<BufferPool> pool = new CLVideoBufferPool (); XCAM_ASSERT (pool.ptr ()); pool->set_video_info (scaler_video_info); pool->reserve (6); _scaler_buf_pool = pool; } output = _scaler_buf_pool->get_buffer (_scaler_buf_pool); XCAM_ASSERT (output.ptr ()); return XCAM_RETURN_NO_ERROR; }
XCamReturn CLDemoImageKernel::prepare_arguments ( SmartPtr<DrmBoBuffer> &input, SmartPtr<DrmBoBuffer> &output, CLArgument args[], uint32_t &arg_count, CLWorkSize &work_size) { SmartPtr<CLContext> context = get_context (); const VideoBufferInfo & video_info = input->get_video_info (); CLImageDesc image_info; uint32_t channel_bits = XCAM_ALIGN_UP (video_info.color_bits, 8); image_info.format.image_channel_order = CL_R; if (channel_bits == 8) image_info.format.image_channel_data_type = CL_UNORM_INT8; else if (channel_bits == 16) image_info.format.image_channel_data_type = CL_UNORM_INT16; image_info.width = video_info.strides[0] / CLImage::calculate_pixel_bytes (image_info.format); image_info.height = (video_info.size / video_info.strides[0]) / 4 * 4; image_info.row_pitch = video_info.strides[0]; _image_in = new CLVaImage (context, input, image_info); _image_out = new CLVaImage (context, output, image_info); XCAM_ASSERT (_image_in->is_valid () && _image_out->is_valid ()); XCAM_FAIL_RETURN ( WARNING, _image_in->is_valid () && _image_out->is_valid (), XCAM_RETURN_ERROR_MEM, "cl image kernel(%s) in/out memory not available", get_kernel_name ()); //set args; args[0].arg_adress = &_image_in->get_mem_id (); args[0].arg_size = sizeof (cl_mem); args[1].arg_adress = &_image_out->get_mem_id (); args[1].arg_size = sizeof (cl_mem); arg_count = 2; work_size.dim = XCAM_DEFAULT_IMAGE_DIM; work_size.global[0] = image_info.width; work_size.global[1] = image_info.height; work_size.local[0] = 8; work_size.local[1] = 4; return XCAM_RETURN_NO_ERROR; }
CLImage2DArray::CLImage2DArray ( SmartPtr<CLContext> &context, const VideoBufferInfo &video_info, cl_mem_flags flags) : CLImage (context) { CLImageDesc cl_desc; XCAM_ASSERT (video_info.components >= 2); if (!video_info_2_cl_image_desc (video_info, cl_desc)) { XCAM_LOG_WARNING ("CLVaImage create va image failed on default videoinfo"); return; } XCAM_ASSERT (cl_desc.array_size >= 2); //special process for BYT platform for slice-pitch //if (video_info.format == V4L2_PIX_FMT_NV12) cl_desc.height = XCAM_ALIGN_UP (cl_desc.height, 16); init_image_2d_array (context, cl_desc, flags); }
XCamReturn CLBayerBasicImageHandler::prepare_parameters ( SmartPtr<VideoBuffer> &input, SmartPtr<VideoBuffer> &output) { SmartPtr<CLContext> context = get_context (); const VideoBufferInfo & in_video_info = input->get_video_info (); const VideoBufferInfo & out_video_info = output->get_video_info (); CLImageDesc in_image_info; CLImageDesc out_image_info; CLArgList args; CLWorkSize work_size; XCAM_ASSERT (_bayer_kernel.ptr ()); if (!_3a_stats_context->is_ready () && !_3a_stats_context->allocate_data ( in_video_info, STANDARD_3A_STATS_SIZE / STATS_3A_CELL_X_SIZE, STANDARD_3A_STATS_SIZE / STATS_3A_CELL_Y_SIZE)) { XCAM_LOG_WARNING ("CL3AStatsCalculatorContext allocate data failed"); return XCAM_RETURN_ERROR_MEM; } if (_is_first_buf) { XCAM_FAIL_RETURN ( WARNING, _3a_stats_thread->start (), XCAM_RETURN_ERROR_THREAD, "cl bayer basic handler start 3a stats thread failed"); } in_image_info.format.image_channel_order = CL_RGBA; in_image_info.format.image_channel_data_type = CL_UNSIGNED_INT32; //CL_UNORM_INT16; in_image_info.width = in_video_info.aligned_width / 8; in_image_info.height = in_video_info.height; in_image_info.row_pitch = in_video_info.strides[0]; out_image_info.format.image_channel_order = CL_RGBA; out_image_info.format.image_channel_data_type = CL_UNSIGNED_INT32; //CL_UNORM_INT16; out_image_info.width = out_video_info.width / 8; out_image_info.height = out_video_info.aligned_height * 4; out_image_info.row_pitch = out_video_info.strides[0]; #if ENABLE_IMAGE_2D_INPUT SmartPtr<CLImage> image_in = convert_to_climage (context, input, in_image_info); #else SmartPtr<CLBuffer> buffer_in = convert_to_clbuffer (context, input); #endif uint32_t input_aligned_width = in_video_info.strides[0] / (2 * 8); // ushort8 SmartPtr<CLImage> image_out = convert_to_climage (context, output, out_image_info); uint32_t out_aligned_height = out_video_info.aligned_height; _blc_config.color_bits = in_video_info.color_bits; SmartPtr<CLBuffer> gamma_table_buffer = new CLBuffer( context, sizeof(float) * (XCAM_GAMMA_TABLE_SIZE + 1), CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, &_gamma_table); _stats_cl_buffer = _3a_stats_context->get_buffer (); XCAM_FAIL_RETURN ( WARNING, _stats_cl_buffer.ptr () && _stats_cl_buffer->is_valid (), XCAM_RETURN_ERROR_PARAM, "CLBayerBasic handler get 3a stats buffer failed"); XCAM_FAIL_RETURN ( WARNING, image_out->is_valid (), XCAM_RETURN_ERROR_MEM, "cl image handler(%s) out memory not available", XCAM_STR(get_name ())); //set args; #if ENABLE_IMAGE_2D_INPUT args.push_back (new CLMemArgument (image_in)); #else args.push_back (new CLMemArgument (buffer_in)); #endif args.push_back (new CLArgumentT<uint32_t> (input_aligned_width)); args.push_back (new CLMemArgument (image_out)); args.push_back (new CLArgumentT<uint32_t> (out_aligned_height)); args.push_back (new CLArgumentT<CLBLCConfig> (_blc_config)); args.push_back (new CLArgumentT<CLWBConfig> (_wb_config)); args.push_back (new CLMemArgument (gamma_table_buffer)); args.push_back (new CLMemArgument (_stats_cl_buffer)); work_size.dim = XCAM_DEFAULT_IMAGE_DIM; work_size.local[0] = 16; work_size.local[1] = 2; work_size.global[0] = XCAM_ALIGN_UP(out_video_info.width, GROUP_CELL_X_SIZE) / GROUP_CELL_X_SIZE * work_size.local[0]; work_size.global[1] = XCAM_ALIGN_UP(out_video_info.aligned_height, GROUP_CELL_Y_SIZE) / GROUP_CELL_Y_SIZE * work_size.local[1]; //printf ("work_size:g(%d, %d), l(%d, %d)\n", work_size.global[0], work_size.global[1], work_size.local[0], work_size.local[1]); XCAM_ASSERT (_bayer_kernel.ptr ()); XCamReturn ret = _bayer_kernel->set_arguments (args, work_size); XCAM_FAIL_RETURN ( WARNING, ret == XCAM_RETURN_NO_ERROR, ret, "bayer basic kernel set arguments failed."); return XCAM_RETURN_NO_ERROR; }
bool VideoBufferInfo::init ( uint32_t format, uint32_t width, uint32_t height, uint32_t aligned_width, uint32_t aligned_height, uint32_t size) { uint32_t image_size = 0; XCAM_ASSERT (!aligned_width || aligned_width >= width); XCAM_ASSERT (!aligned_height || aligned_height >= height); if (!aligned_width) aligned_width = XCAM_ALIGN_UP (width, 4); if (!aligned_height) aligned_height = XCAM_ALIGN_UP (height, 2); this->format = format; this->width = width; this->height = height; this->aligned_width = aligned_width; this->aligned_height = aligned_height; switch (format) { case V4L2_PIX_FMT_NV12: this->color_bits = 8; this->components = 2; this->strides [0] = aligned_width; this->strides [1] = this->strides [0]; this->offsets [0] = 0; this->offsets [1] = this->offsets [0] + this->strides [0] * aligned_height; image_size = this->strides [0] * aligned_height + this->strides [1] * aligned_height / 2; break; case V4L2_PIX_FMT_YUYV: this->color_bits = 8; this->components = 1; this->strides [0] = aligned_width * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case V4L2_PIX_FMT_RGB565: this->color_bits = 16; this->components = 1; this->strides [0] = aligned_width * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case V4L2_PIX_FMT_RGB24: this->color_bits = 8; this->components = 1; this->strides [0] = aligned_width * 3; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; // memory order RGBA 8-8-8-8 case V4L2_PIX_FMT_RGBA32: // memory order: BGRA 8-8-8-8 case V4L2_PIX_FMT_XBGR32: case V4L2_PIX_FMT_ABGR32: case V4L2_PIX_FMT_BGR32: // memory order: ARGB 8-8-8-8 case V4L2_PIX_FMT_RGB32: case V4L2_PIX_FMT_ARGB32: case V4L2_PIX_FMT_XRGB32: this->color_bits = 8; this->components = 1; this->strides [0] = aligned_width * 4; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case XCAM_PIX_FMT_RGB48: this->color_bits = 16; this->components = 1; this->strides [0] = aligned_width * 3 * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case XCAM_PIX_FMT_RGBA64: this->color_bits = 16; this->components = 1; this->strides [0] = aligned_width * 4 * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case V4L2_PIX_FMT_SBGGR8: case V4L2_PIX_FMT_SGBRG8: case V4L2_PIX_FMT_SGRBG8: case V4L2_PIX_FMT_SRGGB8: this->color_bits = 8; this->components = 1; this->strides [0] = aligned_width; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case V4L2_PIX_FMT_SBGGR10: case V4L2_PIX_FMT_SGBRG10: case V4L2_PIX_FMT_SGRBG10: case V4L2_PIX_FMT_SRGGB10: this->color_bits = 10; this->components = 1; this->strides [0] = aligned_width * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case V4L2_PIX_FMT_SBGGR12: case V4L2_PIX_FMT_SGBRG12: case V4L2_PIX_FMT_SGRBG12: case V4L2_PIX_FMT_SRGGB12: this->color_bits = 12; this->components = 1; this->strides [0] = aligned_width * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case V4L2_PIX_FMT_SBGGR16: case XCAM_PIX_FMT_SGRBG16: this->color_bits = 16; this->components = 1; this->strides [0] = aligned_width * 2; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; case XCAM_PIX_FMT_LAB: this->color_bits = 32; this->components = 1; this->strides [0] = aligned_width * 3 * 4; this->offsets [0] = 0; image_size = this->strides [0] * aligned_height; break; default: XCAM_LOG_WARNING ("VideoBufferInfo init failed, unsupported format:%s", xcam_fourcc_to_string (format)); return false; } if (!size) this->size = image_size; else { XCAM_ASSERT (size >= image_size); this->size = size; } return true; }