@@ -57,9 +57,29 @@ int QgsNineCellFilter::processRaster( QgsFeedback *feedback )
5757 .arg ( openClProgramBaseName ( ) ), QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Info );
5858 return processRasterGPU ( source, feedback );
5959 }
60+ <<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
6061 catch ( cl::Error &e )
6162 {
6263 QString err = QObject::tr ( " Error running OpenCL program: %1 - %2" ).arg ( e.what ( ) ).arg ( QgsOpenClUtils::errorText ( e.err ( ) ) );
64+ =======
65+ catch ( cl::BuildError &e )
66+ {
67+ cl::BuildLogType build_logs = e.getBuildLog ();
68+ QString build_log;
69+ if ( build_logs.size () > 0 )
70+ build_log = QString::fromStdString ( build_logs[0 ].second );
71+ else
72+ build_log = QObject::tr ( " Build logs not available!" );
73+ QString err = QObject::tr ( " Error building OpenCL program: %1" )
74+ .arg ( build_log );
75+ QgsMessageLog::logMessage ( err, QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Critical );
76+ throw QgsProcessingException ( err );
77+ }
78+ catch ( cl::Error &e )
79+ {
80+ QString err = QObject::tr ( " Error %1 running OpenCL program in %2" )
81+ .arg ( QgsOpenClUtils::errorText ( e.err () ), QString::fromStdString ( e.what () ) );
82+ >>>>>>> Try to avoid crash on intel haswell
6383 QgsMessageLog::logMessage ( err, QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Critical );
6484 throw QgsProcessingException ( err );
6585 }
@@ -236,6 +256,7 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
236256 // used to pass additional args to opencl program
237257 addExtraRasterParams ( rasterParams );
238258
259+ <<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
239260 std::size_t bufferSize ( sizeof ( float ) * ( xSize + 2 ) );
240261 std::size_t inputSize ( sizeof ( float ) * ( xSize ) );
241262
@@ -263,17 +284,40 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
263284
264285 // values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
265286 for ( int i = 0 ; i < ySize; ++i )
287+ =======
288+ try
289+ >>>>>>> Try to avoid crash on intel haswell
266290 {
267- if ( feedback && feedback->isCanceled () )
268- {
269- break ;
270- }
271291
272- if ( feedback )
292+ cl::Buffer rasterParamsBuffer ( rasterParams.begin (), rasterParams.end (), true , false , &errorCode );
293+ cl::Buffer scanLine1Buffer ( CL_MEM_READ_ONLY, sizeof ( float ) * ( xSize + 2 ), nullptr , &errorCode );
294+ cl::Buffer scanLine2Buffer ( CL_MEM_READ_ONLY, sizeof ( float ) * ( xSize + 2 ), nullptr , &errorCode );
295+ cl::Buffer scanLine3Buffer ( CL_MEM_READ_ONLY, sizeof ( float ) * ( xSize + 2 ), nullptr , &errorCode );
296+ cl::Buffer resultLineBuffer ( CL_MEM_WRITE_ONLY, sizeof ( float ) * xSize, nullptr , &errorCode );
297+
298+ // Create a program from the kernel source
299+ cl::Program program ( source.toStdString () );
300+ // Use CL 1.1 for compatibility with older libs
301+ program.build ( " -cl-std=CL1.1" );
302+
303+ // Create the OpenCL kernel
304+ auto kernel = cl::KernelFunctor <
305+ cl::Buffer &,
306+ cl::Buffer &,
307+ cl::Buffer &,
308+ cl::Buffer &,
309+ cl::Buffer &
310+ > ( program, " processNineCellWindow" );
311+
312+ // values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
313+ for ( int i = 0 ; i < ySize; ++i )
273314 {
274- feedback->setProgress ( 100.0 * static_cast < double >( i ) / ySize );
275- }
315+ if ( feedback && feedback->isCanceled () )
316+ {
317+ break ;
318+ }
276319
320+ <<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
277321 if ( i == 0 )
278322 {
279323 // Fill scanline 1 with (input) nodata for the values above the first row and
@@ -286,9 +330,35 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
286330
287331 // Read scanline2: first real raster row
288332 if ( GDALRasterIO ( rasterBand, GF_Read, 0 , i, xSize, 1 , &scanLine[1 ], xSize, 1 , GDT_Float32, 0 , 0 ) != CE_None )
333+ =======
334+ if ( feedback )
289335 {
290- QgsDebugMsg ( " Raster IO Error " );
336+ feedback-> setProgress ( 100.0 * static_cast < double >( i ) / ySize );
291337 }
338+
339+ if ( i == 0 )
340+ >>>>>>> Try to avoid crash on intel haswell
341+ {
342+ // fill scanline 1 with (input) nodata for the values above the first row and feed scanline2 with the first row
343+ for ( int a = 0 ; a < xSize + 2 ; ++a )
344+ {
345+ scanLine1[a] = mInputNodataValue ;
346+ }
347+ // Read scanline2
348+ if ( GDALRasterIO ( rasterBand, GF_Read, 0 , 0 , xSize, 1 , &scanLine2[1 ], xSize, 1 , GDT_Float32, 0 , 0 ) != CE_None )
349+ {
350+ QgsDebugMsg ( " Raster IO Error" );
351+ }
352+ }
353+ else
354+ {
355+ // normally fetch only scanLine3 and release scanline 1 if we move forward one row
356+ CPLFree ( scanLine1 );
357+ scanLine1 = scanLine2;
358+ scanLine2 = scanLine3;
359+ scanLine3 = ( float * ) CPLMalloc ( sizeof ( float ) * ( xSize + 2 ) );
360+ }
361+ <<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
292362 queue.enqueueWriteBuffer ( scanLine2Buffer, CL_TRUE, 0 , bufferSize, scanLine.get () );
293363
294364 // Read scanline3: second real raster row
@@ -303,6 +373,49 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
303373 // Normally fetch only scanLine3 and move forward one row
304374 // Read scanline 3, fill the last row with nodata values if it's the last iteration
305375 if ( i == ySize - 1 ) // fill the row below the bottom with nodata values
376+ =======
377+
378+ // Read scanline 3
379+ if ( i == ySize - 1 ) // fill the row below the bottom with nodata values
380+ {
381+ for ( int a = 0 ; a < xSize + 2 ; ++a )
382+ {
383+ scanLine3[a] = mInputNodataValue ;
384+ }
385+ }
386+ else
387+ {
388+ if ( GDALRasterIO ( rasterBand, GF_Read, 0 , i + 1 , xSize, 1 , &scanLine3[1 ], xSize, 1 , GDT_Float32, 0 , 0 ) != CE_None )
389+ {
390+ QgsDebugMsg ( " Raster IO Error" );
391+ }
392+ }
393+ // Set first and last extra colums to nodata
394+ scanLine1[0 ] = scanLine1[xSize + 1 ] = mInputNodataValue ;
395+ scanLine2[0 ] = scanLine2[xSize + 1 ] = mInputNodataValue ;
396+ scanLine3[0 ] = scanLine3[xSize + 1 ] = mInputNodataValue ;
397+
398+ errorCode = cl::enqueueWriteBuffer ( scanLine1Buffer, CL_TRUE, 0 ,
399+ sizeof ( float ) * ( xSize + 2 ), scanLine1 );
400+ errorCode = cl::enqueueWriteBuffer ( scanLine2Buffer, CL_TRUE, 0 ,
401+ sizeof ( float ) * ( xSize + 2 ), scanLine2 );
402+ errorCode = cl::enqueueWriteBuffer ( scanLine3Buffer, CL_TRUE, 0 ,
403+ sizeof ( float ) * ( xSize + 2 ), scanLine3 );
404+
405+ kernel ( cl::EnqueueArgs (
406+ cl::NDRange ( xSize )
407+ ),
408+ scanLine1Buffer,
409+ scanLine2Buffer,
410+ scanLine3Buffer,
411+ resultLineBuffer,
412+ rasterParamsBuffer
413+ );
414+
415+ cl::enqueueReadBuffer ( resultLineBuffer, CL_TRUE, 0 , xSize * sizeof ( float ), resultLine );
416+
417+ if ( GDALRasterIO ( outputRasterBand, GF_Write, 0 , i, xSize, 1 , resultLine, xSize, 1 , GDT_Float32, 0 , 0 ) != CE_None )
418+ >>>>>>> Try to avoid crash on intel haswell
306419 {
307420 for ( int a = 0 ; a < xSize + 2 ; ++a )
308421 {
@@ -319,6 +432,7 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
319432 }
320433 queue.enqueueWriteBuffer ( *scanLineBuffer[rowIndex[2 ]], CL_TRUE, 0 , bufferSize, scanLine.get () ); // row 0
321434 }
435+ <<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
322436 }
323437
324438 kernel ( cl::EnqueueArgs (
@@ -339,6 +453,18 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
339453 QgsDebugMsg ( " Raster IO Error" );
340454 }
341455 std::rotate ( rowIndex.begin (), rowIndex.begin () + 1 , rowIndex.end () );
456+ =======
457+
458+ }
459+ }
460+ catch ( cl::Error &e )
461+ {
462+ CPLFree ( resultLine );
463+ CPLFree ( scanLine1 );
464+ CPLFree ( scanLine2 );
465+ CPLFree ( scanLine3 );
466+ throw e;
467+ >>>>>>> Try to avoid crash on intel haswell
342468 }
343469
344470 if ( feedback && feedback->isCanceled () )
0 commit comments