Skip to content

Commit 1decb48

Browse files
committedAug 8, 2018
[opencl] Add options widget
1 parent 3054da0 commit 1decb48

File tree

6 files changed

+141
-4
lines changed

6 files changed

+141
-4
lines changed
 

‎images/images.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@
699699
<file>themes/default/mIndicatorEmbedded.svg</file>
700700
<file>themes/default/mIconHistory.svg</file>
701701
<file>themes/default/mIndicatorMemory.svg</file>
702+
<file>themes/default/mIconGPU.svg</file>
702703
</qresource>
703704
<qresource prefix="/images/tips">
704705
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>

‎images/themes/default/mIconGPU.svg

Lines changed: 14 additions & 0 deletions
Loading

‎src/app/qgsoptions.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
#include "qgslocatorwidget.h"
5252
#include "qgslocatoroptionswidget.h"
5353

54+
#ifdef HAVE_OPENCL
55+
#include "qgsopenclutils.h"
56+
#endif
57+
5458
#include <QInputDialog>
5559
#include <QFileDialog>
5660
#include <QColorDialog>
@@ -1076,6 +1080,43 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
10761080
mOptionsStackedWidget->addWidget( page );
10771081
}
10781082

1083+
#ifdef HAVE_OPENCL
1084+
1085+
// Setup OpenCL (GPU) widget
1086+
mGPUEnableCheckBox->setChecked( QgsOpenClUtils::enabled( ) );
1087+
if ( QgsOpenClUtils::available( ) )
1088+
{
1089+
mGPUEnableCheckBox->setEnabled( true );
1090+
mGPUInfoLabel->setText( QStringLiteral( "OpenCL compatible GPU found on your system:<br>"
1091+
"Name: <b>%1</b><br>"
1092+
"Vendor: <b>%2</b><br>"
1093+
"Profile: <b>%3</b><br>"
1094+
"Version: <b>%4</b><br>"
1095+
).arg( QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Name ),
1096+
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Vendor ),
1097+
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Profile ),
1098+
QgsOpenClUtils::deviceInfo( QgsOpenClUtils::Info::Version ) )
1099+
);
1100+
connect( mGPUEnableCheckBox, &QCheckBox::toggled, this, []( bool status )
1101+
{
1102+
QgsOpenClUtils::setEnabled( status );
1103+
}, Qt::UniqueConnection );
1104+
}
1105+
else
1106+
{
1107+
mGPUEnableCheckBox->setEnabled( false );
1108+
mGPUInfoLabel->setText( QStringLiteral( "OpenCL compatible GPU was not found on your system. You may need to install additional libraries in order to enable OpenCL." ) );
1109+
}
1110+
1111+
1112+
#else
1113+
1114+
mOptionsListWidget->removeItemWidget( mOptionsListWidget->findItems( QStringLiteral( "GPU" ), Qt::MatchExactly ).first() );
1115+
mOptionsStackedWidget->removeWidget( mOptionsPageGPU );
1116+
1117+
1118+
#endif
1119+
10791120
connect( pbnEditCreateOptions, &QAbstractButton::pressed, this, &QgsOptions::editCreateOptions );
10801121
connect( pbnEditPyramidsOptions, &QAbstractButton::pressed, this, &QgsOptions::editPyramidsOptions );
10811122

‎src/core/qgsopenclutils.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,30 @@ void QgsOpenClUtils::setSourcePath( const QString &value )
114114
sSourcePath = value;
115115
}
116116

117+
QString QgsOpenClUtils::deviceInfo( const Info infoType )
118+
{
119+
if ( available( ) )
120+
{
121+
switch ( infoType )
122+
{
123+
case Info::Vendor:
124+
return QString::fromStdString( sDevice.getInfo<CL_DEVICE_VENDOR>() );
125+
case Info::Profile:
126+
return QString::fromStdString( sDevice.getInfo<CL_DEVICE_PROFILE>() );
127+
case Info::Version:
128+
return QString::fromStdString( sDevice.getInfo<CL_DEVICE_VERSION>() );
129+
case Info::Name:
130+
default:
131+
return QString::fromStdString( sDevice.getInfo<CL_DEVICE_NAME>() );
132+
}
133+
}
134+
return QString();
135+
}
136+
117137

118138
bool QgsOpenClUtils::enabled()
119139
{
120-
return QgsSettings().value( SETTINGS_KEY, true, QgsSettings::Section::Core ).toBool();
140+
return QgsSettings().value( SETTINGS_KEY, false, QgsSettings::Section::Core ).toBool();
121141
}
122142

123143
bool QgsOpenClUtils::available()

‎src/core/qgsopenclutils.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#define CL_HPP_TARGET_OPENCL_VERSION 110
2424
#include <CL/cl2.hpp>
2525

26-
2726
#include "qgis_core.h"
2827
#include "qgis.h"
2928

@@ -51,6 +50,14 @@ class CORE_EXPORT QgsOpenClUtils
5150
Throw // Write errors in the message log and re-throw exceptions
5251
};
5352

53+
enum Info
54+
{
55+
Name = CL_DEVICE_NAME,
56+
Vendor = CL_DEVICE_VENDOR,
57+
Version = CL_DEVICE_VERSION,
58+
Profile = CL_DEVICE_PROFILE
59+
};
60+
5461
static bool enabled();
5562
static bool available();
5663
static void setEnabled( bool enabled );
@@ -63,6 +70,7 @@ class CORE_EXPORT QgsOpenClUtils
6370
static cl::Context context();
6471
static QString sourcePath();
6572
static void setSourcePath( const QString &value );
73+
static QString deviceInfo( const Info infoType = Info::Name );
6674

6775
/**
6876
* Tiny smart-pointer-like wrapper around CPLMalloc and CPLFree: this is needed because

‎src/ui/qgsoptionsbase.ui

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,18 @@
287287
<normaloff>:/images/themes/default/mIconWarning.svg</normaloff>:/images/themes/default/mIconWarning.svg</iconset>
288288
</property>
289289
</item>
290+
<item>
291+
<property name="text">
292+
<string>GPU</string>
293+
</property>
294+
<property name="toolTip">
295+
<string>Configure GPU for processing algorithms</string>
296+
</property>
297+
<property name="icon">
298+
<iconset resource="../../images/images.qrc">
299+
<normaloff>:/images/themes/default/mIconGPU.svg</normaloff>:/images/themes/default/mIconGPU.svg</iconset>
300+
</property>
301+
</item>
290302
</widget>
291303
</item>
292304
</layout>
@@ -320,7 +332,7 @@
320332
<item>
321333
<widget class="QStackedWidget" name="mOptionsStackedWidget">
322334
<property name="currentIndex">
323-
<number>0</number>
335+
<number>16</number>
324336
</property>
325337
<widget class="QWidget" name="mOptionsPageGeneral">
326338
<layout class="QVBoxLayout" name="verticalLayout_3">
@@ -1070,7 +1082,7 @@
10701082
<rect>
10711083
<x>0</x>
10721084
<y>0</y>
1073-
<width>544</width>
1085+
<width>843</width>
10741086
<height>1094</height>
10751087
</rect>
10761088
</property>
@@ -5307,6 +5319,47 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
53075319
</item>
53085320
</layout>
53095321
</widget>
5322+
<widget class="QWidget" name="mOptionsPageGPU">
5323+
<layout class="QVBoxLayout" name="verticalLayout_29">
5324+
<item>
5325+
<widget class="QLabel" name="label_53">
5326+
<property name="text">
5327+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Some of the internal C++ processing core algorithms can take advantage of an OpenCL compatible GPU to increase the performances.&lt;br/&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;QGIS support is highly experimental and can crash QGIS because of bugs in the underlying libraries, enable at your own risk!&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
5328+
</property>
5329+
<property name="wordWrap">
5330+
<bool>true</bool>
5331+
</property>
5332+
</widget>
5333+
</item>
5334+
<item>
5335+
<widget class="QLabel" name="mGPUInfoLabel">
5336+
<property name="text">
5337+
<string>Placemark for OpenCL information results (mGPUInfoLabel)</string>
5338+
</property>
5339+
</widget>
5340+
</item>
5341+
<item>
5342+
<widget class="QCheckBox" name="mGPUEnableCheckBox">
5343+
<property name="text">
5344+
<string>Enable OpenCL GPU acceleration</string>
5345+
</property>
5346+
</widget>
5347+
</item>
5348+
<item>
5349+
<spacer name="verticalSpacer_2">
5350+
<property name="orientation">
5351+
<enum>Qt::Vertical</enum>
5352+
</property>
5353+
<property name="sizeHint" stdset="0">
5354+
<size>
5355+
<width>20</width>
5356+
<height>40</height>
5357+
</size>
5358+
</property>
5359+
</spacer>
5360+
</item>
5361+
</layout>
5362+
</widget>
53105363
</widget>
53115364
</item>
53125365
</layout>

0 commit comments

Comments
 (0)
Please sign in to comment.