Skip to content

Commit 868b04d

Browse files
committed
[opencl] Remove all static members
and rely on the default() mechanism, this prevents random crashes on exit when dtor is called on the statics.
1 parent dcba255 commit 868b04d

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/core/qgsopenclutils.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ QLatin1String QgsOpenClUtils::SETTINGS_GLOBAL_ENABLED_KEY = QLatin1Literal( "Ope
2727
QLatin1String QgsOpenClUtils::SETTINGS_DEFAULT_DEVICE_KEY = QLatin1Literal( "OpenClDefaultDevice" );
2828
QLatin1String QgsOpenClUtils::LOGMESSAGE_TAG = QLatin1Literal( "OpenCL" );
2929
bool QgsOpenClUtils::sAvailable = false;
30-
cl::Platform QgsOpenClUtils::sDefaultPlatform = cl::Platform();
31-
cl::Device QgsOpenClUtils::sActiveDevice = cl::Device();
3230
QString QgsOpenClUtils::sSourcePath = QString();
3331

3432

@@ -163,15 +161,15 @@ bool QgsOpenClUtils::enabled()
163161

164162
cl::Device QgsOpenClUtils::activeDevice()
165163
{
166-
return sActiveDevice;
164+
return cl::Device::getDefault();
167165
}
168166

169167
QString QgsOpenClUtils::activePlatformVersion()
170168
{
171169
QString version;
172-
if ( QgsOpenClUtils::sDefaultPlatform() )
170+
if ( cl::Platform::getDefault()() )
173171
{
174-
std::string platver = QgsOpenClUtils::sDefaultPlatform.getInfo<CL_PLATFORM_VERSION>();
172+
std::string platver = cl::Platform::getDefault().getInfo<CL_PLATFORM_VERSION>();
175173
if ( platver.find( "OpenCL " ) != std::string::npos )
176174
{
177175
version = QString::fromStdString( platver.substr( 7 ) ).split( ' ' ).first();
@@ -203,6 +201,7 @@ bool QgsOpenClUtils::activate( const QString &preferredDeviceId )
203201
{
204202
if ( deviceId( activeDevice() ) == preferredDeviceId )
205203
{
204+
sAvailable = true;
206205
return false;
207206
}
208207
try
@@ -306,8 +305,6 @@ bool QgsOpenClUtils::activate( const QString &preferredDeviceId )
306305
.arg( QString::fromStdString( dev.getInfo<CL_DEVICE_NAME>() ) ),
307306
LOGMESSAGE_TAG, Qgis::Success );
308307
sAvailable = true;
309-
sActiveDevice = dev;
310-
sDefaultPlatform = plat;
311308
}
312309
}
313310
}
@@ -526,9 +523,9 @@ cl::Context QgsOpenClUtils::context()
526523
static std::once_flag contextCreated;
527524
std::call_once( contextCreated, [ = ]()
528525
{
529-
if ( available() && sDefaultPlatform() && sActiveDevice() )
526+
if ( available() && cl::Platform::getDefault()() && cl::Device::getDefault()() )
530527
{
531-
context = cl::Context( sActiveDevice );
528+
context = cl::Context( cl::Device::getDefault() );
532529
}
533530
} );
534531
return context;

src/core/qgsopenclutils.h

-2
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ class CORE_EXPORT QgsOpenClUtils
310310
static void init();
311311

312312
static bool sAvailable;
313-
static cl::Device sActiveDevice;
314-
static cl::Platform sDefaultPlatform;
315313
static QLatin1String SETTINGS_GLOBAL_ENABLED_KEY;
316314
static QLatin1String SETTINGS_DEFAULT_DEVICE_KEY;
317315
static QString sSourcePath;

0 commit comments

Comments
 (0)