mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
Added context
This commit is contained in:
parent
4756873282
commit
79f0eadb05
@ -57,29 +57,9 @@ int QgsNineCellFilter::processRaster( QgsFeedback *feedback )
|
|||||||
.arg( openClProgramBaseName( ) ), QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Info );
|
.arg( openClProgramBaseName( ) ), QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Info );
|
||||||
return processRasterGPU( source, feedback );
|
return processRasterGPU( source, feedback );
|
||||||
}
|
}
|
||||||
<<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
|
|
||||||
catch ( cl::Error &e )
|
catch ( cl::Error &e )
|
||||||
{
|
{
|
||||||
QString err = QObject::tr( "Error running OpenCL program: %1 - %2" ).arg( e.what( ) ).arg( QgsOpenClUtils::errorText( e.err( ) ) );
|
QString err = QObject::tr( "Error running OpenCL program: %1 - %2" ).arg( e.what( ) ).arg( QgsOpenClUtils::errorText( e.err( ) ) );
|
||||||
=======
|
|
||||||
catch ( cl::BuildError &e )
|
|
||||||
{
|
|
||||||
cl::BuildLogType build_logs = e.getBuildLog();
|
|
||||||
QString build_log;
|
|
||||||
if ( build_logs.size() > 0 )
|
|
||||||
build_log = QString::fromStdString( build_logs[0].second );
|
|
||||||
else
|
|
||||||
build_log = QObject::tr( "Build logs not available!" );
|
|
||||||
QString err = QObject::tr( "Error building OpenCL program: %1" )
|
|
||||||
.arg( build_log );
|
|
||||||
QgsMessageLog::logMessage( err, QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Critical );
|
|
||||||
throw QgsProcessingException( err );
|
|
||||||
}
|
|
||||||
catch ( cl::Error &e )
|
|
||||||
{
|
|
||||||
QString err = QObject::tr( "Error %1 running OpenCL program in %2" )
|
|
||||||
.arg( QgsOpenClUtils::errorText( e.err() ), QString::fromStdString( e.what() ) );
|
|
||||||
>>>>>>> Try to avoid crash on intel haswell
|
|
||||||
QgsMessageLog::logMessage( err, QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Critical );
|
QgsMessageLog::logMessage( err, QgsOpenClUtils::LOGMESSAGE_TAG, Qgis::Critical );
|
||||||
throw QgsProcessingException( err );
|
throw QgsProcessingException( err );
|
||||||
}
|
}
|
||||||
@ -235,21 +215,9 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
|
|||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
|
|
||||||
// Prepare context and queue
|
// Prepare context and queue
|
||||||
cl::Context ctx = QgsOpenClUtils::context();
|
cl::Context ctx = QgsOpenClUtils::context();
|
||||||
cl::CommandQueue queue( ctx );
|
cl::CommandQueue queue( ctx );
|
||||||
=======
|
|
||||||
//keep only three scanlines in memory at a time, make room for initial and final nodata
|
|
||||||
QgsOpenClUtils::CPLAllocator<float> scanLine1( xSize + 2 );
|
|
||||||
QgsOpenClUtils::CPLAllocator<float> scanLine2( xSize + 2 );
|
|
||||||
QgsOpenClUtils::CPLAllocator<float> scanLine3( xSize + 2 );
|
|
||||||
//float *scanLine2 = ( float * ) CPLMalloc( sizeof( float ) * ( xSize + 2 ) );
|
|
||||||
//float *scanLine3 = ( float * ) CPLMalloc( sizeof( float ) * ( xSize + 2 ) );
|
|
||||||
|
|
||||||
//float *resultLine = ( float * ) CPLMalloc( sizeof( float ) * xSize );
|
|
||||||
QgsOpenClUtils::CPLAllocator<float> resultLine( xSize );
|
|
||||||
>>>>>>> CPLAllocator smart wrapper
|
|
||||||
|
|
||||||
//keep only three scanlines in memory at a time, make room for initial and final nodata
|
//keep only three scanlines in memory at a time, make room for initial and final nodata
|
||||||
QgsOpenClUtils::CPLAllocator<float> scanLine( xSize + 2 );
|
QgsOpenClUtils::CPLAllocator<float> scanLine( xSize + 2 );
|
||||||
@ -268,8 +236,6 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
|
|||||||
// used to pass additional args to opencl program
|
// used to pass additional args to opencl program
|
||||||
addExtraRasterParams( rasterParams );
|
addExtraRasterParams( rasterParams );
|
||||||
|
|
||||||
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
|
|
||||||
<<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
|
|
||||||
std::size_t bufferSize( sizeof( float ) * ( xSize + 2 ) );
|
std::size_t bufferSize( sizeof( float ) * ( xSize + 2 ) );
|
||||||
std::size_t inputSize( sizeof( float ) * ( xSize ) );
|
std::size_t inputSize( sizeof( float ) * ( xSize ) );
|
||||||
|
|
||||||
@ -297,43 +263,17 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
|
|||||||
|
|
||||||
// values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
|
// values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
|
||||||
for ( int i = 0; i < ySize; ++i )
|
for ( int i = 0; i < ySize; ++i )
|
||||||
=======
|
|
||||||
try
|
|
||||||
>>>>>>> Try to avoid crash on intel haswell
|
|
||||||
{
|
|
||||||
=======
|
|
||||||
>>>>>>> CPLAllocator smart wrapper
|
|
||||||
|
|
||||||
cl::Buffer rasterParamsBuffer( rasterParams.begin(), rasterParams.end(), true, false, &errorCode );
|
|
||||||
cl::Buffer scanLine1Buffer( CL_MEM_READ_ONLY, sizeof( float ) * ( xSize + 2 ), nullptr, &errorCode );
|
|
||||||
cl::Buffer scanLine2Buffer( CL_MEM_READ_ONLY, sizeof( float ) * ( xSize + 2 ), nullptr, &errorCode );
|
|
||||||
cl::Buffer scanLine3Buffer( CL_MEM_READ_ONLY, sizeof( float ) * ( xSize + 2 ), nullptr, &errorCode );
|
|
||||||
cl::Buffer resultLineBuffer( CL_MEM_WRITE_ONLY, sizeof( float ) * xSize, nullptr, &errorCode );
|
|
||||||
|
|
||||||
// Create a program from the kernel source
|
|
||||||
cl::Program program( source.toStdString() );
|
|
||||||
// Use CL 1.1 for compatibility with older libs
|
|
||||||
program.build( "-cl-std=CL1.1" );
|
|
||||||
|
|
||||||
// Create the OpenCL kernel
|
|
||||||
auto kernel = cl::KernelFunctor <
|
|
||||||
cl::Buffer &,
|
|
||||||
cl::Buffer &,
|
|
||||||
cl::Buffer &,
|
|
||||||
cl::Buffer &,
|
|
||||||
cl::Buffer &
|
|
||||||
> ( program, "processNineCellWindow" );
|
|
||||||
|
|
||||||
//values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
|
|
||||||
for ( int i = 0; i < ySize; ++i )
|
|
||||||
{
|
{
|
||||||
if ( feedback && feedback->isCanceled() )
|
if ( feedback && feedback->isCanceled() )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
|
if ( feedback )
|
||||||
<<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
|
{
|
||||||
|
feedback->setProgress( 100.0 * static_cast< double >( i ) / ySize );
|
||||||
|
}
|
||||||
|
|
||||||
if ( i == 0 )
|
if ( i == 0 )
|
||||||
{
|
{
|
||||||
// Fill scanline 1 with (input) nodata for the values above the first row and
|
// Fill scanline 1 with (input) nodata for the values above the first row and
|
||||||
@ -346,35 +286,9 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
|
|||||||
|
|
||||||
// Read scanline2: first real raster row
|
// Read scanline2: first real raster row
|
||||||
if ( GDALRasterIO( rasterBand, GF_Read, 0, i, xSize, 1, &scanLine[1], xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
|
if ( GDALRasterIO( rasterBand, GF_Read, 0, i, xSize, 1, &scanLine[1], xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
|
||||||
=======
|
|
||||||
if ( feedback )
|
|
||||||
{
|
|
||||||
feedback->setProgress( 100.0 * static_cast< double >( i ) / ySize );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( i == 0 )
|
|
||||||
>>>>>>> Try to avoid crash on intel haswell
|
|
||||||
=======
|
|
||||||
if ( feedback )
|
|
||||||
{
|
|
||||||
feedback->setProgress( 100.0 * static_cast< double >( i ) / ySize );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( i == 0 )
|
|
||||||
{
|
|
||||||
//fill scanline 1 with (input) nodata for the values above the first row and feed scanline2 with the first row
|
|
||||||
for ( int a = 0; a < xSize + 2 ; ++a )
|
|
||||||
>>>>>>> CPLAllocator smart wrapper
|
|
||||||
{
|
|
||||||
scanLine1[a] = mInputNodataValue;
|
|
||||||
}
|
|
||||||
// Read scanline2
|
|
||||||
if ( GDALRasterIO( rasterBand, GF_Read, 0, 0, xSize, 1, &scanLine2[1], xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
|
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "Raster IO Error" );
|
QgsDebugMsg( "Raster IO Error" );
|
||||||
}
|
}
|
||||||
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
|
|
||||||
<<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
|
|
||||||
queue.enqueueWriteBuffer( scanLine2Buffer, CL_TRUE, 0, bufferSize, scanLine.get() );
|
queue.enqueueWriteBuffer( scanLine2Buffer, CL_TRUE, 0, bufferSize, scanLine.get() );
|
||||||
|
|
||||||
// Read scanline3: second real raster row
|
// Read scanline3: second real raster row
|
||||||
@ -389,61 +303,6 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
|
|||||||
// Normally fetch only scanLine3 and move forward one row
|
// Normally fetch only scanLine3 and move forward one row
|
||||||
// Read scanline 3, fill the last row with nodata values if it's the last iteration
|
// Read scanline 3, fill the last row with nodata values if it's the last iteration
|
||||||
if ( i == ySize - 1 ) //fill the row below the bottom with nodata values
|
if ( i == ySize - 1 ) //fill the row below the bottom with nodata values
|
||||||
=======
|
|
||||||
=======
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//normally fetch only scanLine3 and release scanline 1 if we move forward one row
|
|
||||||
//scanLine1 = scanLine2;
|
|
||||||
//scanLine2 = scanLine3;
|
|
||||||
//scanLine3 = ( float * ) CPLMalloc( sizeof( float ) * ( xSize + 2 ) );
|
|
||||||
scanLine1.reset( scanLine2.release() );
|
|
||||||
scanLine2.reset( scanLine3.release() );
|
|
||||||
scanLine3.reset( xSize + 2 );
|
|
||||||
}
|
|
||||||
>>>>>>> CPLAllocator smart wrapper
|
|
||||||
|
|
||||||
// Read scanline 3
|
|
||||||
if ( i == ySize - 1 ) //fill the row below the bottom with nodata values
|
|
||||||
{
|
|
||||||
for ( int a = 0; a < xSize + 2; ++a )
|
|
||||||
{
|
|
||||||
scanLine3[a] = mInputNodataValue;
|
|
||||||
}
|
|
||||||
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
|
|
||||||
// Set first and last extra colums to nodata
|
|
||||||
scanLine1[0] = scanLine1[xSize + 1] = mInputNodataValue;
|
|
||||||
scanLine2[0] = scanLine2[xSize + 1] = mInputNodataValue;
|
|
||||||
scanLine3[0] = scanLine3[xSize + 1] = mInputNodataValue;
|
|
||||||
|
|
||||||
errorCode = cl::enqueueWriteBuffer( scanLine1Buffer, CL_TRUE, 0,
|
|
||||||
sizeof( float ) * ( xSize + 2 ), scanLine1 );
|
|
||||||
errorCode = cl::enqueueWriteBuffer( scanLine2Buffer, CL_TRUE, 0,
|
|
||||||
sizeof( float ) * ( xSize + 2 ), scanLine2 );
|
|
||||||
errorCode = cl::enqueueWriteBuffer( scanLine3Buffer, CL_TRUE, 0,
|
|
||||||
sizeof( float ) * ( xSize + 2 ), scanLine3 );
|
|
||||||
|
|
||||||
kernel( cl::EnqueueArgs(
|
|
||||||
cl::NDRange( xSize )
|
|
||||||
),
|
|
||||||
scanLine1Buffer,
|
|
||||||
scanLine2Buffer,
|
|
||||||
scanLine3Buffer,
|
|
||||||
resultLineBuffer,
|
|
||||||
rasterParamsBuffer
|
|
||||||
);
|
|
||||||
|
|
||||||
cl::enqueueReadBuffer( resultLineBuffer, CL_TRUE, 0, xSize * sizeof( float ), resultLine );
|
|
||||||
|
|
||||||
if ( GDALRasterIO( outputRasterBand, GF_Write, 0, i, xSize, 1, resultLine, xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
|
|
||||||
>>>>>>> Try to avoid crash on intel haswell
|
|
||||||
=======
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( GDALRasterIO( rasterBand, GF_Read, 0, i + 1, xSize, 1, &scanLine3[1], xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
|
|
||||||
>>>>>>> CPLAllocator smart wrapper
|
|
||||||
{
|
{
|
||||||
for ( int a = 0; a < xSize + 2; ++a )
|
for ( int a = 0; a < xSize + 2; ++a )
|
||||||
{
|
{
|
||||||
@ -451,7 +310,6 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
|
|||||||
}
|
}
|
||||||
queue.enqueueWriteBuffer( *scanLineBuffer[rowIndex[2]], CL_TRUE, 0, bufferSize, scanLine.get() ); // row 0
|
queue.enqueueWriteBuffer( *scanLineBuffer[rowIndex[2]], CL_TRUE, 0, bufferSize, scanLine.get() ); // row 0
|
||||||
}
|
}
|
||||||
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
|
|
||||||
else // Read line i + 1 and put it into scanline 3
|
else // Read line i + 1 and put it into scanline 3
|
||||||
// Overwrite from input, skip first and last
|
// Overwrite from input, skip first and last
|
||||||
{
|
{
|
||||||
@ -461,7 +319,6 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
|
|||||||
}
|
}
|
||||||
queue.enqueueWriteBuffer( *scanLineBuffer[rowIndex[2]], CL_TRUE, 0, bufferSize, scanLine.get() ); // row 0
|
queue.enqueueWriteBuffer( *scanLineBuffer[rowIndex[2]], CL_TRUE, 0, bufferSize, scanLine.get() ); // row 0
|
||||||
}
|
}
|
||||||
<<<<<<< 583c7ae28727cddaff53706903980733bd4b8979
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kernel( cl::EnqueueArgs(
|
kernel( cl::EnqueueArgs(
|
||||||
@ -482,54 +339,8 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
|
|||||||
QgsDebugMsg( "Raster IO Error" );
|
QgsDebugMsg( "Raster IO Error" );
|
||||||
}
|
}
|
||||||
std::rotate( rowIndex.begin(), rowIndex.begin() + 1, rowIndex.end() );
|
std::rotate( rowIndex.begin(), rowIndex.begin() + 1, rowIndex.end() );
|
||||||
=======
|
|
||||||
=======
|
|
||||||
}
|
|
||||||
// Set first and last extra colums to nodata
|
|
||||||
scanLine1[0] = scanLine1[xSize + 1] = mInputNodataValue;
|
|
||||||
scanLine2[0] = scanLine2[xSize + 1] = mInputNodataValue;
|
|
||||||
scanLine3[0] = scanLine3[xSize + 1] = mInputNodataValue;
|
|
||||||
>>>>>>> CPLAllocator smart wrapper
|
|
||||||
|
|
||||||
errorCode = cl::enqueueWriteBuffer( scanLine1Buffer, CL_TRUE, 0,
|
|
||||||
sizeof( float ) * ( xSize + 2 ), scanLine1.get() );
|
|
||||||
errorCode = cl::enqueueWriteBuffer( scanLine2Buffer, CL_TRUE, 0,
|
|
||||||
sizeof( float ) * ( xSize + 2 ), scanLine2.get() );
|
|
||||||
errorCode = cl::enqueueWriteBuffer( scanLine3Buffer, CL_TRUE, 0,
|
|
||||||
sizeof( float ) * ( xSize + 2 ), scanLine3.get() );
|
|
||||||
|
|
||||||
kernel( cl::EnqueueArgs(
|
|
||||||
cl::NDRange( xSize )
|
|
||||||
),
|
|
||||||
scanLine1Buffer,
|
|
||||||
scanLine2Buffer,
|
|
||||||
scanLine3Buffer,
|
|
||||||
resultLineBuffer,
|
|
||||||
rasterParamsBuffer
|
|
||||||
);
|
|
||||||
|
|
||||||
cl::enqueueReadBuffer( resultLineBuffer, CL_TRUE, 0, xSize * sizeof( float ), resultLine.get() );
|
|
||||||
|
|
||||||
if ( GDALRasterIO( outputRasterBand, GF_Write, 0, i, xSize, 1, resultLine.get(), xSize, 1, GDT_Float32, 0, 0 ) != CE_None )
|
|
||||||
{
|
|
||||||
QgsDebugMsg( "Raster IO Error" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
<<<<<<< 7e1d9298000637436eb49d0a886978ad33476894
|
|
||||||
catch ( cl::Error &e )
|
|
||||||
{
|
|
||||||
CPLFree( resultLine );
|
|
||||||
CPLFree( scanLine1 );
|
|
||||||
CPLFree( scanLine2 );
|
|
||||||
CPLFree( scanLine3 );
|
|
||||||
throw e;
|
|
||||||
>>>>>>> Try to avoid crash on intel haswell
|
|
||||||
}
|
}
|
||||||
|
|
||||||
=======
|
|
||||||
|
|
||||||
|
|
||||||
>>>>>>> CPLAllocator smart wrapper
|
|
||||||
if ( feedback && feedback->isCanceled() )
|
if ( feedback && feedback->isCanceled() )
|
||||||
{
|
{
|
||||||
//delete the dataset without closing (because it is faster)
|
//delete the dataset without closing (because it is faster)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user