From 224048d516ca2284c4852f85789167e85595dd34 Mon Sep 17 00:00:00 2001 From: sono Date: Mon, 16 Mar 2020 15:54:19 +0330 Subject: [PATCH] Add scratchPad feature --- MainWindow.cpp | 7 ++++++- MainWindow.h | 3 +++ header/IProcessStrategy.h | 6 +++--- header/strategies/Rejection.h | 2 +- header/strategies/ScanConversion.h | 2 +- source/IProcessStrategy.cpp | 4 ++-- source/strategies/Rejection.cpp | 2 +- source/strategies/ScanConversion.cpp | 2 +- 8 files changed, 18 insertions(+), 10 deletions(-) diff --git a/MainWindow.cpp b/MainWindow.cpp index 23175a5..e35fde2 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -28,6 +28,10 @@ MainWindow::MainWindow(QWidget *parent) .getDevicesByContext( _CLContext)[0]); + _scratchPad = new Buffer(_CLContext, CL_MEM_READ_WRITE, 1024); + _scratch = new double[128]; + CLQueue.enqueueWriteBuffer(*_scratchPad, CL_TRUE, 0, 1024, _scratch); + registerStrategies(); _strategy = Q_NULLPTR; } @@ -182,7 +186,8 @@ void MainWindow::on_btn_test_clicked() update_field(&_scenGenOutput.outputWidth, OUT_WIDTH); update_field(&_scenGenOutput.outputHeight, OUT_HEIGHT); _strategy->cpuProcess(_scenGenOutput); - auto outFrame = _strategy->processKernel(inFrame); + + auto outFrame = _strategy->processKernel(inFrame, _scratchPad); char *out; out = (char*)malloc(OUT_WIDTH * OUT_WIDTH * sizeof (char) * sizeof (myflt)); diff --git a/MainWindow.h b/MainWindow.h index 0edd7fb..a407011 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -64,5 +64,8 @@ private: IProcessStrategy* _strategy; ScenGenOutput_t _scenGenOutput; + Buffer* _scratchPad; + double* _scratch; + }; #endif // MAINWINDOW_H diff --git a/header/IProcessStrategy.h b/header/IProcessStrategy.h index 77e305b..37851ec 100644 --- a/header/IProcessStrategy.h +++ b/header/IProcessStrategy.h @@ -23,7 +23,7 @@ public: virtual void cpuProcess(ScenGenOutput_t parameters) = 0; virtual void finalize() = 0; virtual void ReadParams(QString path, ScenGenOutput_t* params) = 0; - virtual Image* processKernel(Image* inputFrame) = 0; + virtual Image* processKernel(Image* inputFrame, Buffer* scratchPad) = 0; protected: Kernel _kernel; @@ -39,10 +39,10 @@ protected: OpenCLHelper _openCLHelper; signals: - void sgl_outputReady(Image* frames); + void sgl_outputReady(Image* frames, Buffer* scratchPad); public slots: - void slt_process(Image* frames); + void slt_process(Image* frames, Buffer* scratchPad); }; diff --git a/header/strategies/Rejection.h b/header/strategies/Rejection.h index f5fd01e..60d220f 100644 --- a/header/strategies/Rejection.h +++ b/header/strategies/Rejection.h @@ -23,7 +23,7 @@ public: private: KernelFunctor _kernelFunctor; - virtual Image* processKernel(Image *frames) override; + virtual Image* processKernel(Image *frames, Buffer* scratchPad) override; Rejection_t _kernelParameters; double _rejectionThr; diff --git a/header/strategies/ScanConversion.h b/header/strategies/ScanConversion.h index 2cce609..c46d846 100644 --- a/header/strategies/ScanConversion.h +++ b/header/strategies/ScanConversion.h @@ -25,7 +25,7 @@ public: private: KernelFunctor _kernelFunctor; - virtual Image* processKernel(Image *frames) override; + virtual Image* processKernel(Image *frames, Buffer* scratchPad) override; ScanConversion_t _kernelParameters; quint64 _width; quint64 _height; diff --git a/source/IProcessStrategy.cpp b/source/IProcessStrategy.cpp index acb9650..a660c4e 100644 --- a/source/IProcessStrategy.cpp +++ b/source/IProcessStrategy.cpp @@ -2,9 +2,9 @@ #include #include -void IProcessStrategy::slt_process(Image* inputFrame) +void IProcessStrategy::slt_process(Image* inputFrame, Buffer* scratchPad) { - emit sgl_outputReady(processKernel(inputFrame)); + } IProcessStrategy::IProcessStrategy(const Context context, diff --git a/source/strategies/Rejection.cpp b/source/strategies/Rejection.cpp index 0ea26e4..ceebd0e 100644 --- a/source/strategies/Rejection.cpp +++ b/source/strategies/Rejection.cpp @@ -43,7 +43,7 @@ void Rejection::ReadParams(QString path, ScenGenOutput_t *params) } -Image* Rejection::processKernel(Image *frames) +Image* Rejection::processKernel(Image *frames, Buffer* scratchPad) { Context context = _openCLHelper.getContext(); auto format = frames->getImageInfo(); diff --git a/source/strategies/ScanConversion.cpp b/source/strategies/ScanConversion.cpp index 4544bdc..3bd169d 100644 --- a/source/strategies/ScanConversion.cpp +++ b/source/strategies/ScanConversion.cpp @@ -226,7 +226,7 @@ void ScanConversion::ReadParams(QString path, ScenGenOutput_t *params) } -Image* ScanConversion::processKernel(Image *frames) +Image* ScanConversion::processKernel(Image *frames, Buffer* scratchPad) { Context context = _openCLHelper.getContext(); auto format = frames->getImageInfo();