Add matching by GL_VENDOR to QOpenGLConfig

This will be essential on Linux, especially Embedded where PCI IDs are
not that useful.

Change-Id: I2fa8ca07236e8aae203e21fe629d12aab092c7fd
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
Laszlo Agocs 2015-04-09 16:49:34 +02:00
parent 71e3ce7f0b
commit f3fad26bc9
5 changed files with 89 additions and 28 deletions

View File

@ -36,6 +36,7 @@
#include "qopenglcontext.h"
#include "qopenglfunctions.h"
#include "qoffscreensurface.h"
#include <QtCore/QDebug>
#include <QtCore/QJsonDocument>
@ -89,8 +90,8 @@ QOpenGLExtensionMatcher::QOpenGLExtensionMatcher()
}
/* Helpers to read out the list of features matching a device from
* a Chromium driver bug list of the format using a subset of keys
* (namely, matching by gl_vendor RegExp is not implemented):
* a Chromium driver bug list. Note that not all keys are supported and
* some may behave differently: gl_vendor is a substring match instead of regex.
{
"entries": [
{
@ -291,14 +292,14 @@ static bool matches(const QJsonObject &object,
const QJsonValue vendorV = object.value(vendorIdKey());
if (vendorV.isString()) {
if (gpu.vendorId != vendorV.toString().toUInt(Q_NULLPTR, /* base */ 0))
return false;
if (gpu.vendorId != vendorV.toString().toUInt(Q_NULLPTR, /* base */ 0))
return false;
} else {
if (object.contains(glVendorKey())) {
qWarning().nospace() << "Id " << object.value(idKey()).toInt()
<< ": Matching by " << glVendorKey() << " is not implemented.";
return false;
}
const QByteArray glVendorV = object.value(glVendorKey()).toString().toUtf8();
if (!gpu.glVendor.contains(glVendorV))
return false;
}
}
if (gpu.deviceId) {
@ -447,5 +448,30 @@ QSet<QString> QOpenGLConfig::gpuFeatures(const Gpu &gpu, const QString &fileName
return gpuFeatures(gpu, OsTypeTerm::hostOs(), OsTypeTerm::hostKernelVersion(), fileName);
}
QOpenGLConfig::Gpu QOpenGLConfig::Gpu::fromContext()
{
QOpenGLContext *ctx = QOpenGLContext::currentContext();
QScopedPointer<QOpenGLContext> tmpContext;
QScopedPointer<QOffscreenSurface> tmpSurface;
if (!ctx) {
tmpContext.reset(new QOpenGLContext);
if (!tmpContext->create()) {
qWarning("QOpenGLConfig::Gpu::fromContext: Failed to create temporary context");
return QOpenGLConfig::Gpu();
}
tmpSurface.reset(new QOffscreenSurface);
tmpSurface->setFormat(tmpContext->format());
tmpSurface->create();
tmpContext->makeCurrent(tmpSurface.data());
}
QOpenGLConfig::Gpu gpu;
ctx = QOpenGLContext::currentContext();
const GLubyte *p = ctx->functions()->glGetString(GL_VENDOR);
if (p)
gpu.glVendor = QByteArray(reinterpret_cast<const char *>(p));
return gpu;
}
QT_END_NAMESPACE

View File

@ -74,16 +74,34 @@ private:
class Q_GUI_EXPORT QOpenGLConfig
{
public:
struct Gpu {
struct Q_GUI_EXPORT Gpu {
Gpu() : vendorId(0), deviceId(0) {}
bool isValid() const { return deviceId; }
bool isValid() const { return deviceId || !glVendor.isEmpty(); }
bool equals(const Gpu &other) const {
return vendorId == other.vendorId && deviceId == other.deviceId && driverVersion == other.driverVersion;
return vendorId == other.vendorId && deviceId == other.deviceId && driverVersion == other.driverVersion
&& glVendor == other.glVendor;
}
uint vendorId;
uint deviceId;
QVersionNumber driverVersion;
QByteArray glVendor;
static Gpu fromDevice(uint vendorId, uint deviceId, QVersionNumber driverVersion) {
Gpu gpu;
gpu.vendorId = vendorId;
gpu.deviceId = deviceId;
gpu.driverVersion = driverVersion;
return gpu;
}
static Gpu fromGLVendor(const QByteArray &glVendor) {
Gpu gpu;
gpu.glVendor = glVendor;
return gpu;
}
static Gpu fromContext();
};
static QSet<QString> gpuFeatures(const Gpu &gpu,

View File

@ -224,10 +224,7 @@ QWindowsOpenGLTester::Renderers QWindowsOpenGLTester::detectSupportedRenderers(c
#elif defined(Q_OS_WINCE)
return QWindowsOpenGLTester::Gles;
#else
QOpenGLConfig::Gpu qgpu;
qgpu.deviceId = gpu.deviceId;
qgpu.vendorId = gpu.vendorId;
qgpu.driverVersion = gpu.driverVersion;
QOpenGLConfig::Gpu qgpu = QOpenGLConfig::Gpu::fromDevice(gpu.deviceId, gpu.vendorId, gpu.driverVersion);
SupportedRenderersCache *srCache = supportedRenderersCache();
SupportedRenderersCache::const_iterator it = srCache->find(qgpu);
if (it != srCache->cend())

View File

@ -101,6 +101,14 @@
"features": [
"feature1"
]
},
{
"id": 128,
"description": "check for matching GL_VENDOR",
"gl_vendor": "The Qt Company",
"features": [
"cool_feature"
]
}
]
}

View File

@ -217,6 +217,11 @@ void tst_QOpenGlConfig::testGlConfiguration()
context.doneCurrent();
qDebug().noquote() << '\n' << result;
// fromContext either uses the current context or creates a temporary dummy one.
QOpenGLConfig::Gpu gpu = QOpenGLConfig::Gpu::fromContext();
qDebug().noquote() << '\n' << "GL_VENDOR queried by QOpenGLConfig::Gpu:" << gpu.glVendor;
QVERIFY(!gpu.glVendor.isEmpty());
}
static inline QByteArray msgSetMismatch(const QSet<QString> &expected,
@ -235,21 +240,28 @@ void tst_QOpenGlConfig::testBugList()
const QString fileName = QFINDTESTDATA("buglist.json");
QVERIFY(!fileName.isEmpty());
QSet<QString> expectedFeatures;
expectedFeatures << "feature1";
QSet<QString> expectedFeatures;
expectedFeatures << "feature1";
QOpenGLConfig::Gpu gpu;
gpu.vendorId = 0x10DE;
gpu.deviceId = 0x0DE9;
QVersionNumber driverVersion(QVector<int>() << 9 << 18 << 13 << 4460);
QOpenGLConfig::Gpu gpu = QOpenGLConfig::Gpu::fromDevice(0x10DE, 0x0DE9, driverVersion);
#ifdef Q_COMPILER_INITIALIZER_LISTS
gpu.driverVersion = QVersionNumber({9, 18, 13, 4460});
#else
gpu.driverVersion = QVersionNumber(QVector<int>() << 9 << 18 << 13 << 4460);
#endif
const QSet<QString> actualFeatures =
QOpenGLConfig::gpuFeatures(gpu, QStringLiteral("win"),
QVersionNumber(6, 3), fileName);
QSet<QString> actualFeatures = QOpenGLConfig::gpuFeatures(gpu, QStringLiteral("win"),
QVersionNumber(6, 3), fileName);
QVERIFY2(expectedFeatures == actualFeatures,
msgSetMismatch(expectedFeatures, actualFeatures));
gpu = QOpenGLConfig::Gpu::fromGLVendor(QByteArrayLiteral("Somebody Else"));
expectedFeatures.clear();
actualFeatures = QOpenGLConfig::gpuFeatures(gpu, QStringLiteral("linux"),
QVersionNumber(1, 0), fileName);
QVERIFY2(expectedFeatures == actualFeatures,
msgSetMismatch(expectedFeatures, actualFeatures));
gpu = QOpenGLConfig::Gpu::fromGLVendor(QByteArrayLiteral("The Qt Company"));
expectedFeatures = QSet<QString>() << "cool_feature";
actualFeatures = QOpenGLConfig::gpuFeatures(gpu, QStringLiteral("linux"),
QVersionNumber(1, 0), fileName);
QVERIFY2(expectedFeatures == actualFeatures,
msgSetMismatch(expectedFeatures, actualFeatures));
}