diff --git a/src/core/qgsopenclutils.cpp b/src/core/qgsopenclutils.cpp index fae95bcac12..4fcec93428d 100644 --- a/src/core/qgsopenclutils.cpp +++ b/src/core/qgsopenclutils.cpp @@ -528,3 +528,35 @@ cl::Program QgsOpenClUtils::buildProgram( const cl::Context &context, const QStr } return program; } + +cl::Program QgsOpenClUtils::buildProgram( const cl::Context &context, const QString &source, ExceptionBehavior exceptionBehavior ) +{ + cl::Program program; + try + { + program = cl::Program( context, source.toStdString( ) ); + program.build( "-cl-std=CL1.1" ); + } + 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, LOGMESSAGE_TAG, Qgis::Critical ); + if ( exceptionBehavior == Throw ) + throw e; + } + catch ( cl::Error &e ) + { + QString err = QObject::tr( "Error %1 running OpenCL program in %2" ) + .arg( errorText( e.err() ), QString::fromStdString( e.what() ) ); + QgsMessageLog::logMessage( err, LOGMESSAGE_TAG, Qgis::Critical ); + throw e; + } + return program; +} diff --git a/src/core/qgsopenclutils.h b/src/core/qgsopenclutils.h index b35926d1a48..258d368f5f5 100644 --- a/src/core/qgsopenclutils.h +++ b/src/core/qgsopenclutils.h @@ -65,6 +65,7 @@ class CORE_EXPORT QgsOpenClUtils public: +<<<<<<< 79f0eadb05fe4d845ab29045c40c34e1e08b4710 /** * The ExceptionBehavior enum define how exceptions generated by OpenCL should be treated */ @@ -113,6 +114,15 @@ class CORE_EXPORT QgsOpenClUtils * * This function must always be called before using QGIS OpenCL utils */ +======= + enum ExceptionBehavior + { + Catch, + Throw + }; + + static bool enabled(); +>>>>>>> Wrap make program in OpenCL utils static bool available(); //! Returns true if OpenCL is enabled in the user settings @@ -166,6 +176,7 @@ class CORE_EXPORT QgsOpenClUtils //! Returns a string representation from an OpenCL \a errorCode static QString errorText( const int errorCode ); +<<<<<<< 79f0eadb05fe4d845ab29045c40c34e1e08b4710 /** * Build the program from \a source in the given \a context and depending on \a exceptionBehavior @@ -181,6 +192,9 @@ class CORE_EXPORT QgsOpenClUtils * no device were identified or OpenCL support is not available * and enabled */ +======= + static cl::Program buildProgram( const cl::Context &context, const QString &source, ExceptionBehavior exceptionBehavior = Catch ); +>>>>>>> Wrap make program in OpenCL utils static cl::Context context(); //! Returns the base path to OpenCL program directory