Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qquickgraphicsconfiguration.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <QCoreApplication>
6#include <rhi/qrhi.h>
7
9
326{
327}
328
332void QQuickGraphicsConfiguration::detach()
333{
334 qAtomicDetach(d);
335}
336
341 : d(other.d)
342{
343 d->ref.ref();
344}
345
350{
351 qAtomicAssign(d, other.d);
352 return *this;
353}
354
359{
360 if (!d->ref.deref())
361 delete d;
362}
363
380{
381#if QT_CONFIG(vulkan)
382 return QRhiVulkanInitParams::preferredInstanceExtensions();
383#else
384 return {};
385#endif
386}
387
399{
400 if (d->deviceExtensions != extensions) {
401 detach();
402 d->deviceExtensions = extensions;
403 }
404}
405
410{
411 return d->deviceExtensions;
412}
413
449{
451 detach();
453 }
454}
455
463{
465}
466
507{
509 detach();
511 }
512}
513
522{
524}
525
553{
555 detach();
557 }
558}
559
568{
570}
571
594{
596 detach();
598 }
599}
600
610{
612}
613
639{
641 detach();
643 }
644}
645
654{
656}
657
670{
672 detach();
674 }
675}
676
689{
691}
692
728{
729 if (d->pipelineCacheSaveFile != filename) {
730 detach();
731 d->pipelineCacheSaveFile = filename;
732 }
733}
734
741{
742 return d->pipelineCacheSaveFile;
743}
744
788{
789 if (d->pipelineCacheLoadFile != filename) {
790 detach();
791 d->pipelineCacheLoadFile = filename;
792 }
793}
794
801{
802 return d->pipelineCacheLoadFile;
803}
804
830{
832 detach();
834 }
835}
836
850{
852}
853
855 : ref(1)
856{
857 // Defaults based on env.vars. NB! many of these variables are documented
858 // and should be considered (semi-)public API. Changing the env.var. names
859 // is therefore not allowed.
860
861 flags = {};
862
863 static const bool useDepthBufferFor2D = qEnvironmentVariableIsEmpty("QSG_NO_DEPTH_BUFFER");
864 if (useDepthBufferFor2D)
866
867 static const bool enableDebugLayer = qEnvironmentVariableIntValue("QSG_RHI_DEBUG_LAYER");
868 if (enableDebugLayer)
870
871 static const bool enableProfilingRelated = qEnvironmentVariableIntValue("QSG_RHI_PROFILE");
872 if (enableProfilingRelated)
874
875 static const bool preferSoftwareDevice = qEnvironmentVariableIntValue("QSG_RHI_PREFER_SOFTWARE_RENDERER");
876 if (preferSoftwareDevice)
878
879 // here take the existing QOpenGL disk cache attribute and env.var. into account as well
880 static const bool autoPipelineCache = !QCoreApplication::instance()->testAttribute(Qt::AA_DisableShaderDiskCache)
881 && !qEnvironmentVariableIntValue("QT_DISABLE_SHADER_DISK_CACHE")
882 && !qEnvironmentVariableIntValue("QSG_RHI_DISABLE_DISK_CACHE");
883 if (autoPipelineCache)
885
886 static const QString pipelineCacheSaveFileEnv = qEnvironmentVariable("QSG_RHI_PIPELINE_CACHE_SAVE");
887 pipelineCacheSaveFile = pipelineCacheSaveFileEnv;
888
889 static const QString pipelineCacheLoadFileEnv = qEnvironmentVariable("QSG_RHI_PIPELINE_CACHE_LOAD");
890 pipelineCacheLoadFile = pipelineCacheLoadFileEnv;
891
892 static const QByteArray hdrRequest = qgetenv("QSG_RHI_HDR");
893 if (hdrRequest == QByteArrayLiteral("auto"))
894 flags |= EnableHdr;
895}
896
898 : ref(1),
899 deviceExtensions(other->deviceExtensions),
900 flags(other->flags),
901 pipelineCacheSaveFile(other->pipelineCacheSaveFile),
902 pipelineCacheLoadFile(other->pipelineCacheLoadFile)
903{
904}
905
906#ifndef QT_NO_DEBUG_STREAM
908{
909 QDebugStateSaver saver(dbg);
911 dbg.nospace() << "QQuickGraphicsConfiguration("
912 << "flags=0x" << Qt::hex << cd->flags << Qt::dec
913 << " flag-isDepthBufferEnabledFor2D=" << config.isDepthBufferEnabledFor2D()
914 << " flag-isDebugLayerEnabled=" << config.isDebugLayerEnabled()
915 << " flag-isDebugMarkersEnabled=" << config.isDebugMarkersEnabled()
916 << " flag-prefersSoftwareDevice=" << config.prefersSoftwareDevice()
917 << " flag-isAutomaticPipelineCacheEnabled=" << config.isAutomaticPipelineCacheEnabled()
918 << " pipelineCacheSaveFile=" << cd->pipelineCacheSaveFile
919 << " piplineCacheLoadFile=" << cd->pipelineCacheLoadFile
920 << " extra-device-extension-requests=" << cd->deviceExtensions
921 << ')';
922 return dbg;
923}
924#endif // QT_NO_DEBUG_STREAM
925
bool ref() noexcept
bool deref() noexcept
\inmodule QtCore
\inmodule QtCore
Definition qbytearray.h:57
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
\inmodule QtCore
\inmodule QtCore
static QQuickGraphicsConfigurationPrivate * get(QQuickGraphicsConfiguration *p)
QQuickGraphicsConfiguration controls lower level graphics settings for the QQuickWindow.
void setPreferSoftwareDevice(bool enable)
Requests choosing an adapter or physical device that uses software-based rasterization.
void setDepthBufferFor2D(bool enable)
Sets the usage of depth buffer for 2D content to enable.
void setPipelineCacheSaveFile(const QString &filename)
Sets the filename where the QQuickWindow is expected to store its graphics/compute pipeline cache con...
void setAutomaticPipelineCache(bool enable)
Changes the usage of the automatic pipeline cache based on enable.
void setDeviceExtensions(const QByteArrayList &extensions)
Sets the list of additional extensions to enable on the graphics device (such as, the VkDevice).
void setTimestamps(bool enable)
When enabled, GPU timing data is collected from command buffers on platforms and 3D APIs where this i...
void setPipelineCacheLoadFile(const QString &filename)
Sets the filename where the QQuickWindow is expected to load the initial contents of its graphics/com...
QQuickGraphicsConfiguration & operator=(const QQuickGraphicsConfiguration &other)
void setDebugLayer(bool enable)
Enables the graphics API implementation's debug or validation layers, if available.
static QByteArrayList preferredInstanceExtensions()
QQuickGraphicsConfiguration()
Constructs a default QQuickGraphicsConfiguration that does not specify any additional settings for th...
void setDebugMarkers(bool enable)
Where applicable, enable controls inserting debug markers and object names into the graphics command ...
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
Combined button and popup list for selecting options.
QTextStream & hex(QTextStream &stream)
Calls QTextStream::setIntegerBase(16) on stream and returns stream.
QTextStream & dec(QTextStream &stream)
Calls QTextStream::setIntegerBase(10) on stream and returns stream.
@ AA_DisableShaderDiskCache
Definition qnamespace.h:461
QT_WARNING_POP void qAtomicAssign(T *&d, T *x)
This is a helper for the assignment operators of implicitly shared classes.
Definition qatomic.h:180
void qAtomicDetach(T *&d)
This is a helper for the detach method of implicitly shared classes.
Definition qatomic.h:199
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
EGLConfig config
GLbitfield flags
GLboolean enable
GLint ref
QDebug operator<<(QDebug dbg, const QQuickGraphicsConfiguration &config)
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) noexcept
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
QSharedPointer< T > other(t)
[5]