You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
4.2 KiB

#include "model/processor/strategies/Sri.h"
#include "model/processor/BIP.h"
#include <QPixmap>
#include <QImage>
Sri::Sri(const Context context,
const QString kernelPath,
const QObject *parent = Q_NULLPTR) :
IProcessStrategy(context, kernelPath, "Sri", parent),
_kernelFunctor(KernelFunctor<Image2D, Image2D,
LocalSpaceArg, Buffer, Sri_t>(_kernel))
{
memset(&_kernelParameters, 0, sizeof (Sri_t));
}
void Sri::cpuProcess(ScenGenOutput_t parameters)
{
if(parameters.sri.isUpdated)
{
_kernelParameters.sri = parameters.sri.value;
}
}
void Sri::finalize()
{
}
Image* Sri::processKernel(Image *frames, Buffer* scratchPad)
{
auto format = frames->getImageInfo<CL_IMAGE_FORMAT>();
auto width = frames->getImageInfo<CL_IMAGE_WIDTH>();
auto height = frames->getImageInfo<CL_IMAGE_HEIGHT>();
_kernelParameters.width = width;
_kernelParameters.height = height;
auto imageOutput = new Image2D(_CLContext,
CL_MEM_READ_WRITE,
ImageFormat(format.image_channel_order, format.image_channel_data_type),
width,
height);
if(_kernelParameters.sri != 0)
{
//width should be lass than CL_DEVICE_MAX_WORK_GROUP_SIZE(1024 for current machine) or this will break
cl::EnqueueArgs eargs(BIP::getInstance()->CLQueue, cl::NDRange(width, height), cl::NDRange(width, 1));
_kernelParameters.state = 1;
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor,
eargs,
*static_cast<Image2D*>(frames),
*imageOutput,
Local(width * sizeof (myflt)),
*scratchPad,
_kernelParameters);
cl::EnqueueArgs eargs2(BIP::getInstance()->CLQueue, cl::NDRange(height, 1), cl::NDRange(height, 1));
_kernelParameters.state = 2;
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor,
eargs2,
*static_cast<Image2D*>(frames),
*imageOutput,
Local(height * sizeof (myflt)),
*scratchPad,
_kernelParameters);
_kernelParameters.state = 3;
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor,
eargs,
*static_cast<Image2D*>(frames),
*imageOutput,
Local(1),
*scratchPad,
_kernelParameters);
_kernelParameters.state = 4;
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor,
eargs,
*static_cast<Image2D*>(imageOutput),
*imageOutput,
Local(width * sizeof (myflt)),
*scratchPad,
_kernelParameters);
_kernelParameters.state = 5;
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor,
eargs2,
*static_cast<Image2D*>(frames),
*imageOutput,
Local(height * sizeof (myflt)),
*scratchPad,
_kernelParameters);
cl::EnqueueArgs eargs3(BIP::getInstance()->CLQueue, cl::NDRange(width, height));
_kernelParameters.state = 6;
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor,
eargs3,
*static_cast<Image2D*>(frames),
*imageOutput,
Local(1),
*scratchPad,
_kernelParameters);
}
else
{
cl::EnqueueArgs eargs(BIP::getInstance()->CLQueue, cl::NDRange(width, height));
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor,
eargs,
*static_cast<Image2D*>(frames),
*imageOutput,
Local(49 * sizeof (myflt)),
*scratchPad,
_kernelParameters);
}
delete frames;
return imageOutput;
}