summaryrefslogtreecommitdiffstats
path: root/src/opencl
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2010-06-10 08:33:45 +1000
committerRhys Weatherley <rhys.weatherley@nokia.com>2010-06-10 08:37:36 +1000
commite0f8e1a59b55f57363fad3c4d1386505a38351a5 (patch)
tree86561d9f81c6f60c15708f9a8464fcdb646ecd5b /src/opencl
parent5a09f29da57f415ef8d776e497fd571c65a76e25 (diff)
Add toString() and fromString() to QCLWorkSize.
Diffstat (limited to 'src/opencl')
-rw-r--r--src/opencl/qclworksize.cpp51
-rw-r--r--src/opencl/qclworksize.h3
2 files changed, 54 insertions, 0 deletions
diff --git a/src/opencl/qclworksize.cpp b/src/opencl/qclworksize.cpp
index 79a351a..8a7c0fa 100644
--- a/src/opencl/qclworksize.cpp
+++ b/src/opencl/qclworksize.cpp
@@ -220,4 +220,55 @@ QCLWorkSize QCLWorkSize::toLocalWorkSize(const QCLDevice &device) const
device.maximumWorkItemsPerGroup());
}
+/*!
+ Returns the string form of this work size, with components
+ separated by 'x'.
+
+ \sa fromString()
+*/
+QString QCLWorkSize::toString() const
+{
+ if (m_dim == 1) {
+ return QString::number(qulonglong(m_sizes[0]));
+ } else if (m_dim == 2) {
+ return QString::number(qulonglong(m_sizes[0])) + QLatin1Char('x') +
+ QString::number(qulonglong(m_sizes[1]));
+ } else {
+ return QString::number(qulonglong(m_sizes[0])) + QLatin1Char('x') +
+ QString::number(qulonglong(m_sizes[1])) + QLatin1Char('x') +
+ QString::number(qulonglong(m_sizes[2]));
+ }
+}
+
+/*!
+ Returns the work size that corresponds to the contents of \a str.
+ Components are assumed to be separated by 'x'.
+
+ \sa toString()
+*/
+QCLWorkSize QCLWorkSize::fromString(const QString &str)
+{
+ QStringList split = str.split(QLatin1Char('x'));
+ if (split.size() >= 3) {
+ return QCLWorkSize(size_t(split[0].toULongLong()),
+ size_t(split[1].toULongLong()),
+ size_t(split[2].toULongLong()));
+ } else if (split.size() == 2) {
+ return QCLWorkSize(size_t(split[0].toULongLong()),
+ size_t(split[1].toULongLong()));
+ } else if (split.size() == 1) {
+ // An empty string will turn into a single-element list,
+ // which we want to result in (1, 1, 1), not (0, 1, 1)
+ // so it matches the default QCLWorkSize().
+ bool ok;
+ qulonglong value = split[0].toULongLong(&ok);
+ if (ok)
+ return QCLWorkSize(value);
+ else
+ return QCLWorkSize();
+ } else {
+ return QCLWorkSize();
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/opencl/qclworksize.h b/src/opencl/qclworksize.h
index 0c5541e..e0c5b7f 100644
--- a/src/opencl/qclworksize.h
+++ b/src/opencl/qclworksize.h
@@ -82,6 +82,9 @@ public:
(const QCLWorkSize &maxWorkItemSize, size_t maxItemsPerGroup) const;
QCLWorkSize toLocalWorkSize(const QCLDevice &device) const;
+ QString toString() const;
+ static QCLWorkSize fromString(const QString &str);
+
private:
size_t m_dim;
size_t m_sizes[3];