@@ -41,7 +41,7 @@ int QgsNineCellFilter::processRaster( QgsFeedback *feedback )
41
41
if ( QgsOpenClUtils::enabled () && QgsOpenClUtils::available () && ! openClProgramBaseName ( ).isEmpty () )
42
42
{
43
43
// Load the program sources
44
- QString source ( QgsOpenClUtils::sourceFromPath ( QStringLiteral ( " /home/ale/dev/QGIS/src/analysis/raster/%1.cl " ). arg ( openClProgramBaseName ( ) ) ) );
44
+ QString source ( QgsOpenClUtils::sourceFromBaseName ( openClProgramBaseName ( ) ) );
45
45
if ( ! source.isEmpty () )
46
46
{
47
47
try
@@ -50,19 +50,6 @@ int QgsNineCellFilter::processRaster( QgsFeedback *feedback )
50
50
.arg ( openClProgramBaseName ( ) ), QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Info );
51
51
return processRasterGPU ( source, feedback );
52
52
}
53
- catch ( cl::BuildError &e )
54
- {
55
- cl::BuildLogType build_logs = e.getBuildLog ();
56
- QString build_log;
57
- if ( build_logs.size () > 0 )
58
- build_log = QString::fromStdString ( build_logs[0 ].second );
59
- else
60
- build_log = QObject::tr ( " Build logs not available!" );
61
- QString err = QObject::tr ( " Error building OpenCL program: %1" )
62
- .arg ( build_log );
63
- QgsMessageLog::logMessage ( err, QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Critical );
64
- throw QgsProcessingException ( err );
65
- }
66
53
catch ( cl::Error &e )
67
54
{
68
55
QString err = QObject::tr ( " Error %1 running OpenCL program in %2" )
@@ -220,18 +207,15 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
220
207
return 6 ;
221
208
}
222
209
223
- // Prepare context
210
+ // Prepare context and queue
224
211
cl::Context ctx = QgsOpenClUtils::context ();
225
212
cl::Context::setDefault ( ctx );
213
+ cl::CommandQueue queue ( ctx );
226
214
227
215
// keep only three scanlines in memory at a time, make room for initial and final nodata
228
216
QgsOpenClUtils::CPLAllocator<float > scanLine1 ( xSize + 2 );
229
217
QgsOpenClUtils::CPLAllocator<float > scanLine2 ( xSize + 2 );
230
218
QgsOpenClUtils::CPLAllocator<float > scanLine3 ( xSize + 2 );
231
- // float *scanLine2 = ( float * ) CPLMalloc( sizeof( float ) * ( xSize + 2 ) );
232
- // float *scanLine3 = ( float * ) CPLMalloc( sizeof( float ) * ( xSize + 2 ) );
233
-
234
- // float *resultLine = ( float * ) CPLMalloc( sizeof( float ) * xSize );
235
219
QgsOpenClUtils::CPLAllocator<float > resultLine ( xSize );
236
220
237
221
cl_int errorCode = 0 ;
@@ -255,9 +239,7 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
255
239
cl::Buffer resultLineBuffer ( CL_MEM_WRITE_ONLY, sizeof ( float ) * xSize, nullptr , &errorCode );
256
240
257
241
// Create a program from the kernel source
258
- cl::Program program ( source.toStdString () );
259
- // Use CL 1.1 for compatibility with older libs
260
- program.build ( " -cl-std=CL1.1" );
242
+ cl::Program program ( QgsOpenClUtils::buildProgram ( ctx, source, QgsOpenClUtils::ExceptionBehavior::Throw ) );
261
243
262
244
// Create the OpenCL kernel
263
245
auto kernel = cl::KernelFunctor <
@@ -297,9 +279,6 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
297
279
else
298
280
{
299
281
// normally fetch only scanLine3 and release scanline 1 if we move forward one row
300
- // scanLine1 = scanLine2;
301
- // scanLine2 = scanLine3;
302
- // scanLine3 = ( float * ) CPLMalloc( sizeof( float ) * ( xSize + 2 ) );
303
282
scanLine1.reset ( scanLine2.release () );
304
283
scanLine2.reset ( scanLine3.release () );
305
284
scanLine3.reset ( xSize + 2 );
@@ -325,6 +304,9 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
325
304
scanLine2[0 ] = scanLine2[xSize + 1 ] = mInputNodataValue ;
326
305
scanLine3[0 ] = scanLine3[xSize + 1 ] = mInputNodataValue ;
327
306
307
+ // TODO: There is room for further optimization here: instead of replacing the buffers
308
+ // we could just replace just hthe new one (the top row) and switch the order
309
+ // of buffer arguments in the kernell call.
328
310
errorCode = cl::enqueueWriteBuffer ( scanLine1Buffer, CL_TRUE, 0 ,
329
311
sizeof ( float ) * ( xSize + 2 ), scanLine1.get () );
330
312
errorCode = cl::enqueueWriteBuffer ( scanLine2Buffer, CL_TRUE, 0 ,
@@ -333,6 +315,7 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
333
315
sizeof ( float ) * ( xSize + 2 ), scanLine3.get () );
334
316
335
317
kernel ( cl::EnqueueArgs (
318
+ queue,
336
319
cl::NDRange ( xSize )
337
320
),
338
321
scanLine1Buffer,
0 commit comments