7#include <QtCore/qvariant.h>
8#include <QtCore/qmap.h>
9#include <QtCore/qdebug.h>
10#include <QtCore/qtextstream.h>
11#include <QtCore/qcoreapplication.h>
12#include <QtCore/qfile.h>
13#include <QtCore/qfileinfo.h>
14#include <QtCore/qstandardpaths.h>
15#include <QtCore/qlibraryinfo.h>
16#include <QtCore/qhash.h>
17#include <private/qsystemlibrary_p.h>
18#include <QtGui/qtgui-config.h>
21#include <private/qopengl_p.h>
24#include <QtCore/qt_windows.h>
34 result.vendorId = adapterIdentifier.VendorId;
35 result.deviceId = adapterIdentifier.DeviceId;
36 result.revision = adapterIdentifier.Revision;
37 result.subSysId = adapterIdentifier.SubSysId;
38 QList<
int> version(4, 0);
39 version[0] = HIWORD(adapterIdentifier.DriverVersion.HighPart);
40 version[1] = LOWORD(adapterIdentifier.DriverVersion.HighPart);
41 version[2] = HIWORD(adapterIdentifier.DriverVersion.LowPart);
42 version[3] = LOWORD(adapterIdentifier.DriverVersion.LowPart);
43 result.driverVersion = QVersionNumber(version);
44 result.driverName = adapterIdentifier.Driver;
45 result.description = adapterIdentifier.Description;
57 bool isValid()
const {
return m_direct3D9 !=
nullptr; }
59 UINT adapterCount()
const {
return m_direct3D9 ? m_direct3D9->GetAdapterCount() : 0u; }
63 IDirect3D9 *m_direct3D9 =
nullptr;
69 m_direct3D9 = Direct3DCreate9(D3D_SDK_VERSION);
76 m_direct3D9->Release();
82 && SUCCEEDED(m_direct3D9->GetAdapterIdentifier(n, 0, adapterIdentifier));
92 D3DADAPTER_IDENTIFIER9 adapterIdentifier;
100 if (direct3D9.retrieveAdapterIdentifier(0, &adapterIdentifier)) {
101 result = adapterIdentifierToGpuDescription(adapterIdentifier);
102 isAMD = result.vendorId == VENDOR_ID_AMD;
109 const UINT adapterCount = direct3D9.adapterCount();
110 for (UINT adp = 1; adp < adapterCount; ++adp) {
111 if (direct3D9.retrieveAdapterIdentifier(adp, &adapterIdentifier)
112 && adapterIdentifier.VendorId != VENDOR_ID_AMD) {
115 memset(&dd, 0,
sizeof(dd));
117 for (
int dev = 0; EnumDisplayDevices(
nullptr, dev, &dd, 0); ++dev) {
118 if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
121 result.gpuSuitableScreen = QString::fromWCharArray(dd.DeviceName);
135 QList<GpuDescription> result;
137 if (
const UINT adapterCount = direct3D9.adapterCount()) {
138 for (UINT adp = 0; adp < adapterCount; ++adp) {
139 D3DADAPTER_IDENTIFIER9 adapterIdentifier;
140 if (direct3D9.retrieveAdapterIdentifier(adp, &adapterIdentifier))
141 result.append(adapterIdentifierToGpuDescription(adapterIdentifier));
147#ifndef QT_NO_DEBUG_STREAM
150 QDebugStateSaver s(d);
152 d << Qt::hex << Qt::showbase <<
"GpuDescription(vendorId=" << gd.vendorId
153 <<
", deviceId=" << gd.deviceId <<
", subSysId=" << gd.subSysId
154 << Qt::dec << Qt::noshowbase <<
", revision=" << gd.revision
155 <<
", driver: " << gd.driverName
156 <<
", version=" << gd.driverVersion <<
", " << gd.description
157 << gd.gpuSuitableScreen <<
')';
166 QTextStream str(&result);
167 str <<
" Card name : " << description
168 <<
"\n Driver Name : " << driverName
169 <<
"\n Driver Version : " << driverVersion.toString()
170 <<
"\n Vendor ID : 0x" << qSetPadChar(u'0')
171 << Qt::uppercasedigits << Qt::hex << qSetFieldWidth(4) << vendorId
172 <<
"\n Device ID : 0x" << qSetFieldWidth(4) << deviceId
173 <<
"\n SubSys ID : 0x" << qSetFieldWidth(8) << subSysId
174 <<
"\n Revision ID : 0x" << qSetFieldWidth(4) << revision
176 if (!gpuSuitableScreen.isEmpty())
177 str <<
"\nGL windows forced to screen: " << gpuSuitableScreen;
184 result.insert(QStringLiteral(
"vendorId"), QVariant(vendorId));
185 result.insert(QStringLiteral(
"deviceId"), QVariant(deviceId));
186 result.insert(QStringLiteral(
"subSysId"),QVariant(subSysId));
187 result.insert(QStringLiteral(
"revision"), QVariant(revision));
188 result.insert(QStringLiteral(
"driver"), QVariant(QLatin1StringView(driverName)));
189 result.insert(QStringLiteral(
"driverProduct"), QVariant(driverVersion.segmentAt(0)));
190 result.insert(QStringLiteral(
"driverVersion"), QVariant(driverVersion.segmentAt(1)));
191 result.insert(QStringLiteral(
"driverSubVersion"), QVariant(driverVersion.segmentAt(2)));
192 result.insert(QStringLiteral(
"driverBuild"), QVariant(driverVersion.segmentAt(3)));
193 result.insert(QStringLiteral(
"driverVersionString"), driverVersion.toString());
194 result.insert(QStringLiteral(
"description"), QVariant(QLatin1StringView(description)));
195 result.insert(QStringLiteral(
"printable"), QVariant(toString()));
201 const char openGlVar[] =
"QT_OPENGL";
202 if (QCoreApplication::testAttribute(Qt::AA_UseOpenGLES))
203 qWarning(
"Qt::AA_UseOpenGLES is no longer supported in Qt 6");
204 if (QCoreApplication::testAttribute(Qt::AA_UseDesktopOpenGL))
206 if (QCoreApplication::testAttribute(Qt::AA_UseSoftwareOpenGL))
208 if (qEnvironmentVariableIsSet(openGlVar)) {
209 const QByteArray requested = qgetenv(openGlVar);
210 if (requested ==
"angle")
211 qWarning(
"QT_OPENGL=angle is no longer supported in Qt 6");
212 if (requested ==
"desktop")
214 if (requested ==
"software")
216 qCWarning(lcQpaGl) <<
"Invalid value set for " << openGlVar <<
": " << requested;
223 if (QFileInfo(fileName).isAbsolute())
227 const QString settingsPath = QLibraryInfo::path(QLibraryInfo::SettingsPath);
228 if (!settingsPath.isEmpty()) {
229 const QFileInfo fi(settingsPath + u'/' + fileName);
231 return fi.absoluteFilePath();
233 return QStandardPaths::locate(QStandardPaths::ConfigLocation, fileName);
238Q_GLOBAL_STATIC(SupportedRenderersCache, supportedRenderersCache)
241QWindowsOpenGLTester::Renderers QWindowsOpenGLTester::detectSupportedRenderers(
const GpuDescription &gpu,
244#if defined(QT_NO_OPENGL)
249 QOpenGLConfig::Gpu qgpu = QOpenGLConfig::Gpu::fromDevice(gpu.vendorId, gpu.deviceId, gpu.driverVersion, gpu.description);
250 SupportedRenderersCache *srCache = supportedRenderersCache();
251 SupportedRenderersCache::const_iterator it = srCache->constFind(qgpu);
252 if (it != srCache->cend())
255 QWindowsOpenGLTester::Renderers result(QWindowsOpenGLTester::SoftwareRasterizer);
258 if (requested == DesktopGl || testDesktopGL())
259 result |= QWindowsOpenGLTester::DesktopGl;
261 QSet<QString> features;
262 if (!qEnvironmentVariableIsSet(
"QT_NO_OPENGL_BUGLIST")) {
263 const char bugListFileVar[] =
"QT_OPENGL_BUGLIST";
264 QString buglistFileName = QStringLiteral(
":/qt-project.org/windows/openglblacklists/default.json");
265 if (qEnvironmentVariableIsSet(bugListFileVar)) {
266 const QString fileName = resolveBugListFile(QFile::decodeName(qgetenv(bugListFileVar)));
267 if (!fileName.isEmpty())
268 buglistFileName = fileName;
270 features = QOpenGLConfig::gpuFeatures(qgpu, buglistFileName);
272 qCDebug(lcQpaGl) <<
"GPU features:" << features;
274 if (features.contains(QStringLiteral(
"disable_desktopgl"))) {
275 qCDebug(lcQpaGl) <<
"Disabling Desktop GL: " << gpu;
276 result &= ~QWindowsOpenGLTester::DesktopGl;
278 if (features.contains(QStringLiteral(
"disable_rotation"))) {
279 qCDebug(lcQpaGl) <<
"Disabling rotation: " << gpu;
280 result |= DisableRotationFlag;
282 if (features.contains(QStringLiteral(
"disable_program_cache"))) {
283 qCDebug(lcQpaGl) <<
"Disabling program cache: " << gpu;
284 result |= DisableProgramCacheFlag;
286 srCache->insert(qgpu, result);
291QWindowsOpenGLTester::Renderers QWindowsOpenGLTester::supportedRenderers(Renderer requested)
293 const GpuDescription gpu = GpuDescription::detect();
294 const QWindowsOpenGLTester::Renderers result = detectSupportedRenderers(gpu, requested);
295 qCDebug(lcQpaGl) <<
__FUNCTION__ << gpu << requested <<
"renderer: " << result;
299bool QWindowsOpenGLTester::testDesktopGL()
301#if !defined(QT_NO_OPENGL)
302 typedef HGLRC (WINAPI *CreateContextType)(HDC);
303 typedef BOOL (WINAPI *DeleteContextType)(HGLRC);
304 typedef BOOL (WINAPI *MakeCurrentType)(HDC, HGLRC);
305 typedef PROC (WINAPI *WglGetProcAddressType)(LPCSTR);
307 HMODULE lib =
nullptr;
310 HGLRC context =
nullptr;
311 LPCTSTR className = L"qtopengltest";
313 CreateContextType CreateContext =
nullptr;
314 DeleteContextType DeleteContext =
nullptr;
315 MakeCurrentType MakeCurrent =
nullptr;
316 WglGetProcAddressType WGL_GetProcAddress =
nullptr;
322 lib = QSystemLibrary::load(L"opengl32");
324 CreateContext =
reinterpret_cast<CreateContextType>(
325 reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib,
"wglCreateContext")));
328 DeleteContext =
reinterpret_cast<DeleteContextType>(
329 reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib,
"wglDeleteContext")));
332 MakeCurrent =
reinterpret_cast<MakeCurrentType>(
333 reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib,
"wglMakeCurrent")));
336 WGL_GetProcAddress =
reinterpret_cast<WglGetProcAddressType>(
337 reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib,
"wglGetProcAddress")));
338 if (!WGL_GetProcAddress)
342 wclass.cbClsExtra = 0;
343 wclass.cbWndExtra = 0;
344 wclass.hInstance =
static_cast<HINSTANCE>(GetModuleHandle(
nullptr));
345 wclass.hIcon =
nullptr;
346 wclass.hCursor =
nullptr;
347 wclass.hbrBackground = HBRUSH(COLOR_BACKGROUND);
348 wclass.lpszMenuName =
nullptr;
349 wclass.lpfnWndProc = DefWindowProc;
350 wclass.lpszClassName = className;
351 wclass.style = CS_OWNDC;
352 if (!RegisterClass(&wclass))
354 wnd = CreateWindow(className, L"qtopenglproxytest", WS_OVERLAPPED,
355 0, 0, 640, 480,
nullptr,
nullptr, wclass.hInstance,
nullptr);
362 PIXELFORMATDESCRIPTOR pfd;
363 memset(&pfd, 0,
sizeof(PIXELFORMATDESCRIPTOR));
364 pfd.nSize =
sizeof(PIXELFORMATDESCRIPTOR);
366 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_GENERIC_FORMAT;
367 pfd.iPixelType = PFD_TYPE_RGBA;
369 int pixelFormat = ChoosePixelFormat(dc, &pfd);
372 if (!SetPixelFormat(dc, pixelFormat, &pfd))
374 context = CreateContext(dc);
377 if (!MakeCurrent(dc, context))
383 typedef const GLubyte * (APIENTRY * GetString_t)(GLenum name);
384 auto GetString =
reinterpret_cast<GetString_t>(
385 reinterpret_cast<QFunctionPointer>(::GetProcAddress(lib,
"glGetString")));
387 if (
const char *versionStr =
reinterpret_cast<
const char *>(GetString(GL_VERSION))) {
388 const QByteArray version(versionStr);
389 const int majorDot = version.indexOf(
'.');
390 if (majorDot != -1) {
391 int minorDot = version.indexOf(
'.', majorDot + 1);
393 minorDot = version.size();
394 const int major = version.mid(0, majorDot).toInt();
395 const int minor = version.mid(majorDot + 1, minorDot - majorDot - 1).toInt();
396 qCDebug(lcQpaGl,
"Basic wglCreateContext gives version %d.%d", major, minor);
402 qCDebug(lcQpaGl,
"OpenGL version too low");
408 qCDebug(lcQpaGl,
"OpenGL 1.x entry points not found");
412 if (WGL_GetProcAddress(
"glCreateShader") && WGL_GetProcAddress(
"glBindFramebuffer")) {
414 qCDebug(lcQpaGl,
"OpenGL 2.0 entry points available");
416 qCDebug(lcQpaGl,
"OpenGL 2.0 entry points not found");
419 qCDebug(lcQpaGl,
"Failed to load opengl32.dll");
424 MakeCurrent(
nullptr,
nullptr);
426 DeleteContext(context);
431 UnregisterClass(className, GetModuleHandle(
nullptr));
UINT adapterCount() const
bool retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const
static GpuDescription adapterIdentifierToGpuDescription(const D3DADAPTER_IDENTIFIER9 &adapterIdentifier)
static QT_BEGIN_NAMESPACE const DWORD VENDOR_ID_AMD
static QString resolveBugListFile(const QString &fileName)
QHash< QOpenGLConfig::Gpu, QWindowsOpenGLTester::Renderers > SupportedRenderersCache
static GpuDescription detect()
QVariant toVariant() const