2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2019 The Qt Company Ltd.
|
|
|
|
// Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
|
|
|
|
// Copyright (C) 2016 Robin Burchell <robin.burchell@viroteck.net>
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
#include "qsgbatchrenderer_p.h"
|
|
|
|
|
2013-12-07 08:41:44 +00:00
|
|
|
#include <qmath.h>
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
#include <QtCore/QElapsedTimer>
|
2014-01-24 12:24:19 +00:00
|
|
|
#include <QtCore/QtNumeric>
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
#include <QtGui/QGuiApplication>
|
|
|
|
|
2017-10-06 15:30:36 +00:00
|
|
|
#include <private/qnumeric_p.h>
|
2020-05-02 12:27:13 +00:00
|
|
|
#include "qsgmaterialshader_p.h"
|
2013-09-30 11:19:30 +00:00
|
|
|
|
2019-07-31 13:17:52 +00:00
|
|
|
#include "qsgrhivisualizer_p.h"
|
|
|
|
|
2013-09-12 09:06:59 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
Q_QUICK_PRIVATE_EXPORT bool qsg_test_and_clear_material_failure();
|
|
|
|
#endif
|
|
|
|
|
2015-10-22 10:36:18 +00:00
|
|
|
int qt_sg_envInt(const char *name, int defaultValue);
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
namespace QSGBatchRenderer
|
|
|
|
{
|
|
|
|
|
2014-09-16 22:20:53 +00:00
|
|
|
#define DECLARE_DEBUG_VAR(variable) \
|
|
|
|
static bool debug_ ## variable() \
|
|
|
|
{ static bool value = qgetenv("QSG_RENDERER_DEBUG").contains(QT_STRINGIFY(variable)); return value; }
|
|
|
|
DECLARE_DEBUG_VAR(render)
|
|
|
|
DECLARE_DEBUG_VAR(build)
|
|
|
|
DECLARE_DEBUG_VAR(change)
|
|
|
|
DECLARE_DEBUG_VAR(upload)
|
|
|
|
DECLARE_DEBUG_VAR(roots)
|
|
|
|
DECLARE_DEBUG_VAR(dump)
|
|
|
|
DECLARE_DEBUG_VAR(noalpha)
|
|
|
|
DECLARE_DEBUG_VAR(noopaque)
|
|
|
|
DECLARE_DEBUG_VAR(noclip)
|
|
|
|
#undef DECLARE_DEBUG_VAR
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
#define QSGNODE_TRAVERSE(NODE) for (QSGNode *child = NODE->firstChild(); child; child = child->nextSibling())
|
2016-11-08 11:47:25 +00:00
|
|
|
#define SHADOWNODE_TRAVERSE(NODE) for (Node *child = NODE->firstChild(); child; child = child->sibling())
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
static inline int size_of_type(int type)
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
|
|
|
static int sizes[] = {
|
|
|
|
sizeof(char),
|
|
|
|
sizeof(unsigned char),
|
|
|
|
sizeof(short),
|
|
|
|
sizeof(unsigned short),
|
|
|
|
sizeof(int),
|
|
|
|
sizeof(unsigned int),
|
|
|
|
sizeof(float),
|
|
|
|
2,
|
|
|
|
3,
|
|
|
|
4,
|
|
|
|
sizeof(double)
|
|
|
|
};
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
Q_ASSERT(type >= QSGGeometry::ByteType && type <= QSGGeometry::DoubleType);
|
|
|
|
return sizes[type - QSGGeometry::ByteType];
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool qsg_sort_element_increasing_order(Element *a, Element *b) { return a->order < b->order; }
|
|
|
|
bool qsg_sort_element_decreasing_order(Element *a, Element *b) { return a->order > b->order; }
|
|
|
|
bool qsg_sort_batch_is_valid(Batch *a, Batch *b) { return a->first && !b->first; }
|
|
|
|
bool qsg_sort_batch_increasing_order(Batch *a, Batch *b) { return a->first->order < b->first->order; }
|
|
|
|
bool qsg_sort_batch_decreasing_order(Batch *a, Batch *b) { return a->first->order > b->first->order; }
|
|
|
|
|
2013-12-04 14:44:57 +00:00
|
|
|
QSGMaterial::Flag QSGMaterial_FullMatrix = (QSGMaterial::Flag) (QSGMaterial::RequiresFullMatrix & ~QSGMaterial::RequiresFullMatrixExceptTranslate);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2020-05-28 11:02:17 +00:00
|
|
|
static bool isTranslate(const QMatrix4x4 &m) { return m.flags() <= QMatrix4x4::Translation; }
|
|
|
|
static bool isScale(const QMatrix4x4 &m) { return m.flags() <= QMatrix4x4::Scale; }
|
|
|
|
static bool is2DSafe(const QMatrix4x4 &m) { return m.flags() < QMatrix4x4::Rotation; }
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
const float OPAQUE_LIMIT = 0.999f;
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
const uint DYNAMIC_VERTEX_INDEX_BUFFER_THRESHOLD = 4;
|
|
|
|
const int VERTEX_BUFFER_BINDING = 0;
|
|
|
|
const int ZORDER_BUFFER_BINDING = VERTEX_BUFFER_BINDING + 1;
|
|
|
|
|
2022-07-08 08:15:58 +00:00
|
|
|
template <class Int>
|
|
|
|
inline Int aligned(Int v, Int byteAlign)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
return (v + byteAlign - 1) & ~(byteAlign - 1);
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:17:52 +00:00
|
|
|
QRhiVertexInputAttribute::Format qsg_vertexInputFormat(const QSGGeometry::Attribute &a)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
switch (a.type) {
|
|
|
|
case QSGGeometry::FloatType:
|
|
|
|
if (a.tupleSize == 4)
|
|
|
|
return QRhiVertexInputAttribute::Float4;
|
|
|
|
if (a.tupleSize == 3)
|
|
|
|
return QRhiVertexInputAttribute::Float3;
|
|
|
|
if (a.tupleSize == 2)
|
|
|
|
return QRhiVertexInputAttribute::Float2;
|
|
|
|
if (a.tupleSize == 1)
|
|
|
|
return QRhiVertexInputAttribute::Float;
|
|
|
|
break;
|
|
|
|
case QSGGeometry::UnsignedByteType:
|
|
|
|
if (a.tupleSize == 4)
|
|
|
|
return QRhiVertexInputAttribute::UNormByte4;
|
|
|
|
if (a.tupleSize == 2)
|
|
|
|
return QRhiVertexInputAttribute::UNormByte2;
|
|
|
|
if (a.tupleSize == 1)
|
|
|
|
return QRhiVertexInputAttribute::UNormByte;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
qWarning("Unsupported attribute type 0x%x with %d components", a.type, a.tupleSize);
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
return QRhiVertexInputAttribute::Float;
|
|
|
|
}
|
|
|
|
|
2020-05-02 12:27:13 +00:00
|
|
|
static QRhiVertexInputLayout calculateVertexInputLayout(const QSGMaterialShader *s, const QSGGeometry *geometry, bool batchable)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(geometry);
|
2020-05-02 12:27:13 +00:00
|
|
|
const QSGMaterialShaderPrivate *sd = QSGMaterialShaderPrivate::get(s);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (!sd->vertexShader) {
|
2020-05-02 12:27:13 +00:00
|
|
|
qWarning("No vertex shader in QSGMaterialShader %p", s);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
return QRhiVertexInputLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
const int attrCount = geometry->attributeCount();
|
2019-10-02 09:10:21 +00:00
|
|
|
QVarLengthArray<QRhiVertexInputAttribute, 8> inputAttributes;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
inputAttributes.reserve(attrCount + 1);
|
2022-07-08 08:15:58 +00:00
|
|
|
quint32 offset = 0;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
for (int i = 0; i < attrCount; ++i) {
|
|
|
|
const QSGGeometry::Attribute &a = geometry->attributes()[i];
|
|
|
|
if (!sd->vertexShader->vertexInputLocations.contains(a.position)) {
|
|
|
|
qWarning("Vertex input %d is present in material but not in shader. This is wrong.",
|
|
|
|
a.position);
|
|
|
|
}
|
2019-07-31 13:17:52 +00:00
|
|
|
inputAttributes.append(QRhiVertexInputAttribute(VERTEX_BUFFER_BINDING, a.position, qsg_vertexInputFormat(a), offset));
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
offset += a.tupleSize * size_of_type(a.type);
|
|
|
|
}
|
|
|
|
if (batchable) {
|
|
|
|
inputAttributes.append(QRhiVertexInputAttribute(ZORDER_BUFFER_BINDING, sd->vertexShader->qt_order_attrib_location,
|
|
|
|
QRhiVertexInputAttribute::Float, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(VERTEX_BUFFER_BINDING == 0 && ZORDER_BUFFER_BINDING == 1); // not very flexible
|
2019-10-02 09:10:21 +00:00
|
|
|
QVarLengthArray<QRhiVertexInputBinding, 2> inputBindings;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
inputBindings.append(QRhiVertexInputBinding(geometry->sizeOfVertex()));
|
|
|
|
if (batchable)
|
|
|
|
inputBindings.append(QRhiVertexInputBinding(sizeof(float)));
|
|
|
|
|
|
|
|
QRhiVertexInputLayout inputLayout;
|
2019-10-02 09:10:21 +00:00
|
|
|
inputLayout.setBindings(inputBindings.cbegin(), inputBindings.cend());
|
|
|
|
inputLayout.setAttributes(inputAttributes.cbegin(), inputAttributes.cend());
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
return inputLayout;
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:17:52 +00:00
|
|
|
QRhiCommandBuffer::IndexFormat qsg_indexFormat(const QSGGeometry *geometry)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
switch (geometry->indexType()) {
|
|
|
|
case QSGGeometry::UnsignedShortType:
|
|
|
|
return QRhiCommandBuffer::IndexUInt16;
|
|
|
|
break;
|
|
|
|
case QSGGeometry::UnsignedIntType:
|
|
|
|
return QRhiCommandBuffer::IndexUInt32;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
return QRhiCommandBuffer::IndexUInt16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:17:52 +00:00
|
|
|
QRhiGraphicsPipeline::Topology qsg_topology(int geomDrawMode)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
QRhiGraphicsPipeline::Topology topology = QRhiGraphicsPipeline::Triangles;
|
|
|
|
switch (geomDrawMode) {
|
|
|
|
case QSGGeometry::DrawPoints:
|
|
|
|
topology = QRhiGraphicsPipeline::Points;
|
|
|
|
break;
|
|
|
|
case QSGGeometry::DrawLines:
|
|
|
|
topology = QRhiGraphicsPipeline::Lines;
|
|
|
|
break;
|
|
|
|
case QSGGeometry::DrawLineStrip:
|
|
|
|
topology = QRhiGraphicsPipeline::LineStrip;
|
|
|
|
break;
|
|
|
|
case QSGGeometry::DrawTriangles:
|
|
|
|
topology = QRhiGraphicsPipeline::Triangles;
|
|
|
|
break;
|
|
|
|
case QSGGeometry::DrawTriangleStrip:
|
|
|
|
topology = QRhiGraphicsPipeline::TriangleStrip;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qWarning("Primitive topology 0x%x not supported", geomDrawMode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return topology;
|
|
|
|
}
|
|
|
|
|
2020-06-09 08:57:35 +00:00
|
|
|
ShaderManager::Shader *ShaderManager::prepareMaterial(QSGMaterial *material,
|
|
|
|
const QSGGeometry *geometry,
|
|
|
|
QSGRendererInterface::RenderMode renderMode)
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
|
|
|
QSGMaterialType *type = material->type();
|
2020-06-09 08:57:35 +00:00
|
|
|
|
|
|
|
ShaderKey key = qMakePair(type, renderMode);
|
|
|
|
Shader *shader = rewrittenShaders.value(key, nullptr);
|
2013-08-14 05:27:07 +00:00
|
|
|
if (shader)
|
|
|
|
return shader;
|
|
|
|
|
|
|
|
shader = new Shader;
|
2020-06-09 08:57:35 +00:00
|
|
|
QSGMaterialShader *s = static_cast<QSGMaterialShader *>(material->createShader(renderMode));
|
2020-05-06 12:16:05 +00:00
|
|
|
context->initializeRhiShader(s, QShader::BatchableVertexShader);
|
|
|
|
shader->programRhi.program = s;
|
|
|
|
shader->programRhi.inputLayout = calculateVertexInputLayout(s, geometry, true);
|
|
|
|
QSGMaterialShaderPrivate *sD = QSGMaterialShaderPrivate::get(s);
|
|
|
|
shader->programRhi.shaderStages = {
|
|
|
|
{ QRhiGraphicsShaderStage::Vertex, sD->shader(QShader::VertexStage), QShader::BatchableVertexShader },
|
|
|
|
{ QRhiGraphicsShaderStage::Fragment, sD->shader(QShader::FragmentStage) }
|
|
|
|
};
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
shader->lastOpacity = 0;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2020-06-09 08:57:35 +00:00
|
|
|
rewrittenShaders[key] = shader;
|
2013-08-14 05:27:07 +00:00
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
2020-06-09 08:57:35 +00:00
|
|
|
ShaderManager::Shader *ShaderManager::prepareMaterialNoRewrite(QSGMaterial *material,
|
|
|
|
const QSGGeometry *geometry,
|
|
|
|
QSGRendererInterface::RenderMode renderMode)
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
|
|
|
QSGMaterialType *type = material->type();
|
2020-06-09 08:57:35 +00:00
|
|
|
|
|
|
|
ShaderKey key = qMakePair(type, renderMode);
|
|
|
|
Shader *shader = stockShaders.value(key, nullptr);
|
2013-08-14 05:27:07 +00:00
|
|
|
if (shader)
|
|
|
|
return shader;
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
shader = new Shader;
|
2020-06-09 08:57:35 +00:00
|
|
|
QSGMaterialShader *s = static_cast<QSGMaterialShader *>(material->createShader(renderMode));
|
2020-05-06 12:16:05 +00:00
|
|
|
context->initializeRhiShader(s, QShader::StandardShader);
|
|
|
|
shader->programRhi.program = s;
|
|
|
|
shader->programRhi.inputLayout = calculateVertexInputLayout(s, geometry, false);
|
|
|
|
QSGMaterialShaderPrivate *sD = QSGMaterialShaderPrivate::get(s);
|
|
|
|
shader->programRhi.shaderStages = {
|
|
|
|
{ QRhiGraphicsShaderStage::Vertex, sD->shader(QShader::VertexStage) },
|
|
|
|
{ QRhiGraphicsShaderStage::Fragment, sD->shader(QShader::FragmentStage) }
|
|
|
|
};
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
shader->lastOpacity = 0;
|
|
|
|
|
2020-06-09 08:57:35 +00:00
|
|
|
stockShaders[key] = shader;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderManager::invalidated()
|
|
|
|
{
|
2015-06-19 16:57:54 +00:00
|
|
|
qDeleteAll(stockShaders);
|
2013-08-14 05:27:07 +00:00
|
|
|
stockShaders.clear();
|
2015-06-19 16:57:54 +00:00
|
|
|
qDeleteAll(rewrittenShaders);
|
2013-08-14 05:27:07 +00:00
|
|
|
rewrittenShaders.clear();
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
2019-11-25 20:36:23 +00:00
|
|
|
qDeleteAll(pipelineCache);
|
|
|
|
pipelineCache.clear();
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
|
|
|
|
qDeleteAll(srbPool);
|
|
|
|
srbPool.clear();
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShaderManager::clearCachedRendererData()
|
|
|
|
{
|
2021-08-17 11:06:47 +00:00
|
|
|
for (ShaderManager::Shader *sms : qAsConst(stockShaders)) {
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShader *s = sms->programRhi.program;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (s) {
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShaderPrivate *sd = QSGMaterialShaderPrivate::get(s);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
sd->clearCachedRendererData();
|
|
|
|
}
|
|
|
|
}
|
2021-08-17 11:06:47 +00:00
|
|
|
for (ShaderManager::Shader *sms : qAsConst(rewrittenShaders)) {
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShader *s = sms->programRhi.program;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (s) {
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShaderPrivate *sd = QSGMaterialShaderPrivate::get(s);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
sd->clearCachedRendererData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
void qsg_dumpShadowRoots(BatchRootInfo *i, int indent)
|
|
|
|
{
|
|
|
|
static int extraIndent = 0;
|
|
|
|
++extraIndent;
|
|
|
|
|
|
|
|
QByteArray ind(indent + extraIndent + 10, ' ');
|
|
|
|
|
|
|
|
if (!i) {
|
2018-02-13 08:57:29 +00:00
|
|
|
qDebug("%s - no info", ind.constData());
|
2013-08-14 05:27:07 +00:00
|
|
|
} else {
|
2013-09-05 12:12:53 +00:00
|
|
|
qDebug() << ind.constData() << "- parent:" << i->parentRoot << "orders" << i->firstOrder << "->" << i->lastOrder << ", avail:" << i->availableOrders;
|
2013-08-14 05:27:07 +00:00
|
|
|
for (QSet<Node *>::const_iterator it = i->subRoots.constBegin();
|
|
|
|
it != i->subRoots.constEnd(); ++it) {
|
|
|
|
qDebug() << ind.constData() << "-" << *it;
|
|
|
|
qsg_dumpShadowRoots((*it)->rootInfo(), indent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
--extraIndent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void qsg_dumpShadowRoots(Node *n)
|
|
|
|
{
|
2014-10-22 22:34:09 +00:00
|
|
|
#ifndef QT_NO_DEBUG_OUTPUT
|
2013-08-14 05:27:07 +00:00
|
|
|
static int indent = 0;
|
|
|
|
++indent;
|
|
|
|
|
|
|
|
QByteArray ind(indent, ' ');
|
|
|
|
|
|
|
|
if (n->type() == QSGNode::ClipNodeType || n->isBatchRoot) {
|
2019-06-26 14:46:23 +00:00
|
|
|
qDebug() << ind.constData() << "[X]" << n->sgNode << Qt::hex << uint(n->sgNode->flags());
|
2013-08-14 05:27:07 +00:00
|
|
|
qsg_dumpShadowRoots(n->rootInfo(), indent);
|
|
|
|
} else {
|
2013-09-05 12:12:53 +00:00
|
|
|
QDebug d = qDebug();
|
2019-06-26 14:46:23 +00:00
|
|
|
d << ind.constData() << "[ ]" << n->sgNode << Qt::hex << uint(n->sgNode->flags());
|
2013-09-05 12:12:53 +00:00
|
|
|
if (n->type() == QSGNode::GeometryNodeType)
|
2019-06-26 14:46:23 +00:00
|
|
|
d << "order" << Qt::dec << n->element()->order;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SHADOWNODE_TRAVERSE(n)
|
2015-06-04 22:45:31 +00:00
|
|
|
qsg_dumpShadowRoots(child);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
--indent;
|
2014-10-22 22:34:09 +00:00
|
|
|
#else
|
2020-06-26 12:43:02 +00:00
|
|
|
Q_UNUSED(n);
|
2014-10-22 22:34:09 +00:00
|
|
|
#endif
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Updater::Updater(Renderer *r)
|
|
|
|
: renderer(r)
|
|
|
|
, m_roots(32)
|
|
|
|
, m_rootMatrices(8)
|
|
|
|
{
|
|
|
|
m_roots.add(0);
|
|
|
|
m_combined_matrix_stack.add(&m_identityMatrix);
|
|
|
|
m_rootMatrices.add(m_identityMatrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Updater::updateStates(QSGNode *n)
|
|
|
|
{
|
2018-02-21 09:41:54 +00:00
|
|
|
m_current_clip = nullptr;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
m_added = 0;
|
|
|
|
m_transformChange = 0;
|
2014-02-11 20:55:58 +00:00
|
|
|
m_opacityChange = 0;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
Node *sn = renderer->m_nodes.value(n, 0);
|
|
|
|
Q_ASSERT(sn);
|
|
|
|
|
2014-09-16 22:20:53 +00:00
|
|
|
if (Q_UNLIKELY(debug_roots()))
|
2013-08-14 05:27:07 +00:00
|
|
|
qsg_dumpShadowRoots(sn);
|
|
|
|
|
2014-09-16 22:20:53 +00:00
|
|
|
if (Q_UNLIKELY(debug_build())) {
|
2018-02-13 08:57:29 +00:00
|
|
|
qDebug("Updater::updateStates()");
|
2013-08-14 05:27:07 +00:00
|
|
|
if (sn->dirtyState & (QSGNode::DirtyNodeAdded << 16))
|
2018-02-13 08:57:29 +00:00
|
|
|
qDebug(" - nodes have been added");
|
2013-08-14 05:27:07 +00:00
|
|
|
if (sn->dirtyState & (QSGNode::DirtyMatrix << 16))
|
2018-02-13 08:57:29 +00:00
|
|
|
qDebug(" - transforms have changed");
|
2013-08-14 05:27:07 +00:00
|
|
|
if (sn->dirtyState & (QSGNode::DirtyOpacity << 16))
|
2018-02-13 08:57:29 +00:00
|
|
|
qDebug(" - opacity has changed");
|
2017-04-27 19:49:40 +00:00
|
|
|
if (uint(sn->dirtyState) & uint(QSGNode::DirtyForceUpdate << 16))
|
2018-02-13 08:57:29 +00:00
|
|
|
qDebug(" - forceupdate");
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:17:52 +00:00
|
|
|
if (Q_UNLIKELY(renderer->m_visualizer->mode() == Visualizer::VisualizeChanges))
|
|
|
|
renderer->m_visualizer->visualizeChangesPrepare(sn);
|
2013-12-07 08:41:44 +00:00
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
visitNode(sn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Updater::visitNode(Node *n)
|
|
|
|
{
|
2014-01-28 19:53:01 +00:00
|
|
|
if (m_added == 0 && n->dirtyState == 0 && m_force_update == 0 && m_transformChange == 0 && m_opacityChange == 0)
|
2013-08-14 05:27:07 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
int count = m_added;
|
|
|
|
if (n->dirtyState & QSGNode::DirtyNodeAdded)
|
|
|
|
++m_added;
|
|
|
|
|
2013-10-04 08:39:20 +00:00
|
|
|
int force = m_force_update;
|
|
|
|
if (n->dirtyState & QSGNode::DirtyForceUpdate)
|
|
|
|
++m_force_update;
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
switch (n->type()) {
|
|
|
|
case QSGNode::OpacityNodeType:
|
|
|
|
visitOpacityNode(n);
|
|
|
|
break;
|
|
|
|
case QSGNode::TransformNodeType:
|
|
|
|
visitTransformNode(n);
|
|
|
|
break;
|
|
|
|
case QSGNode::GeometryNodeType:
|
|
|
|
visitGeometryNode(n);
|
|
|
|
break;
|
|
|
|
case QSGNode::ClipNodeType:
|
|
|
|
visitClipNode(n);
|
|
|
|
break;
|
|
|
|
case QSGNode::RenderNodeType:
|
|
|
|
if (m_added)
|
|
|
|
n->renderNodeElement()->root = m_roots.last();
|
2017-04-19 04:06:54 +00:00
|
|
|
Q_FALLTHROUGH(); // to visit children
|
2013-08-14 05:27:07 +00:00
|
|
|
default:
|
2015-06-04 22:45:31 +00:00
|
|
|
SHADOWNODE_TRAVERSE(n) visitNode(child);
|
2013-08-14 05:27:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_added = count;
|
2013-10-04 08:39:20 +00:00
|
|
|
m_force_update = force;
|
2019-11-25 10:49:14 +00:00
|
|
|
n->dirtyState = {};
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Updater::visitClipNode(Node *n)
|
|
|
|
{
|
|
|
|
ClipBatchRootInfo *extra = n->clipInfo();
|
|
|
|
|
|
|
|
QSGClipNode *cn = static_cast<QSGClipNode *>(n->sgNode);
|
|
|
|
|
|
|
|
if (m_roots.last() && m_added > 0)
|
|
|
|
renderer->registerBatchRoot(n, m_roots.last());
|
|
|
|
|
2016-05-27 09:36:15 +00:00
|
|
|
cn->setRendererClipList(m_current_clip);
|
2013-08-14 05:27:07 +00:00
|
|
|
m_current_clip = cn;
|
|
|
|
m_roots << n;
|
|
|
|
m_rootMatrices.add(m_rootMatrices.last() * *m_combined_matrix_stack.last());
|
|
|
|
extra->matrix = m_rootMatrices.last();
|
2016-05-27 09:36:15 +00:00
|
|
|
cn->setRendererMatrix(&extra->matrix);
|
2013-08-14 05:27:07 +00:00
|
|
|
m_combined_matrix_stack << &m_identityMatrix;
|
|
|
|
|
2015-06-04 22:45:31 +00:00
|
|
|
SHADOWNODE_TRAVERSE(n) visitNode(child);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2016-05-27 09:36:15 +00:00
|
|
|
m_current_clip = cn->clipList();
|
2013-08-14 05:27:07 +00:00
|
|
|
m_rootMatrices.pop_back();
|
|
|
|
m_combined_matrix_stack.pop_back();
|
|
|
|
m_roots.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Updater::visitOpacityNode(Node *n)
|
|
|
|
{
|
|
|
|
QSGOpacityNode *on = static_cast<QSGOpacityNode *>(n->sgNode);
|
|
|
|
|
|
|
|
qreal combined = m_opacity_stack.last() * on->opacity();
|
|
|
|
on->setCombinedOpacity(combined);
|
|
|
|
m_opacity_stack.add(combined);
|
|
|
|
|
|
|
|
if (m_added == 0 && n->dirtyState & QSGNode::DirtyOpacity) {
|
|
|
|
bool was = n->isOpaque;
|
|
|
|
bool is = on->opacity() > OPAQUE_LIMIT;
|
|
|
|
if (was != is) {
|
|
|
|
renderer->m_rebuild = Renderer::FullRebuild;
|
|
|
|
n->isOpaque = is;
|
|
|
|
}
|
2014-01-28 19:53:01 +00:00
|
|
|
++m_opacityChange;
|
2015-06-04 22:45:31 +00:00
|
|
|
SHADOWNODE_TRAVERSE(n) visitNode(child);
|
2014-01-28 19:53:01 +00:00
|
|
|
--m_opacityChange;
|
2013-08-14 05:27:07 +00:00
|
|
|
} else {
|
|
|
|
if (m_added > 0)
|
|
|
|
n->isOpaque = on->opacity() > OPAQUE_LIMIT;
|
2015-06-04 22:45:31 +00:00
|
|
|
SHADOWNODE_TRAVERSE(n) visitNode(child);
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_opacity_stack.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Updater::visitTransformNode(Node *n)
|
|
|
|
{
|
|
|
|
bool popMatrixStack = false;
|
|
|
|
bool popRootStack = false;
|
|
|
|
bool dirty = n->dirtyState & QSGNode::DirtyMatrix;
|
|
|
|
|
|
|
|
QSGTransformNode *tn = static_cast<QSGTransformNode *>(n->sgNode);
|
|
|
|
|
|
|
|
if (n->isBatchRoot) {
|
2013-09-18 08:48:41 +00:00
|
|
|
if (m_added > 0 && m_roots.last())
|
2013-08-14 05:27:07 +00:00
|
|
|
renderer->registerBatchRoot(n, m_roots.last());
|
|
|
|
tn->setCombinedMatrix(m_rootMatrices.last() * *m_combined_matrix_stack.last() * tn->matrix());
|
|
|
|
|
|
|
|
// The only change in this subtree is ourselves and we are a batch root, so
|
|
|
|
// only update subroots and return, saving tons of child-processing (flickable-panning)
|
|
|
|
|
2014-06-04 16:59:58 +00:00
|
|
|
if (!n->becameBatchRoot && m_added == 0 && m_force_update == 0 && m_opacityChange == 0 && dirty && (n->dirtyState & ~QSGNode::DirtyMatrix) == 0) {
|
2013-08-14 05:27:07 +00:00
|
|
|
BatchRootInfo *info = renderer->batchRootInfo(n);
|
|
|
|
for (QSet<Node *>::const_iterator it = info->subRoots.constBegin();
|
|
|
|
it != info->subRoots.constEnd(); ++it) {
|
|
|
|
updateRootTransforms(*it, n, tn->combinedMatrix());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n->becameBatchRoot = false;
|
|
|
|
|
|
|
|
m_combined_matrix_stack.add(&m_identityMatrix);
|
|
|
|
m_roots.add(n);
|
|
|
|
m_rootMatrices.add(tn->combinedMatrix());
|
|
|
|
|
|
|
|
popMatrixStack = true;
|
|
|
|
popRootStack = true;
|
|
|
|
} else if (!tn->matrix().isIdentity()) {
|
|
|
|
tn->setCombinedMatrix(*m_combined_matrix_stack.last() * tn->matrix());
|
|
|
|
m_combined_matrix_stack.add(&tn->combinedMatrix());
|
|
|
|
popMatrixStack = true;
|
|
|
|
} else {
|
|
|
|
tn->setCombinedMatrix(*m_combined_matrix_stack.last());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dirty)
|
|
|
|
++m_transformChange;
|
|
|
|
|
2015-06-04 22:45:31 +00:00
|
|
|
SHADOWNODE_TRAVERSE(n) visitNode(child);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
if (dirty)
|
|
|
|
--m_transformChange;
|
|
|
|
if (popMatrixStack)
|
|
|
|
m_combined_matrix_stack.pop_back();
|
|
|
|
if (popRootStack) {
|
|
|
|
m_roots.pop_back();
|
|
|
|
m_rootMatrices.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Updater::visitGeometryNode(Node *n)
|
|
|
|
{
|
|
|
|
QSGGeometryNode *gn = static_cast<QSGGeometryNode *>(n->sgNode);
|
|
|
|
|
2016-05-27 09:36:15 +00:00
|
|
|
gn->setRendererMatrix(m_combined_matrix_stack.last());
|
|
|
|
gn->setRendererClipList(m_current_clip);
|
2013-08-14 05:27:07 +00:00
|
|
|
gn->setInheritedOpacity(m_opacity_stack.last());
|
|
|
|
|
|
|
|
if (m_added) {
|
|
|
|
Element *e = n->element();
|
|
|
|
e->root = m_roots.last();
|
2020-05-28 11:02:17 +00:00
|
|
|
e->translateOnlyToRoot = isTranslate(*gn->matrix());
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
if (e->root) {
|
|
|
|
BatchRootInfo *info = renderer->batchRootInfo(e->root);
|
2018-02-21 09:41:54 +00:00
|
|
|
while (info != nullptr) {
|
2014-10-30 08:08:00 +00:00
|
|
|
info->availableOrders--;
|
|
|
|
if (info->availableOrders < 0) {
|
|
|
|
renderer->m_rebuild |= Renderer::BuildRenderLists;
|
|
|
|
} else {
|
|
|
|
renderer->m_rebuild |= Renderer::BuildRenderListsForTaggedRoots;
|
|
|
|
renderer->m_taggedRoots << e->root;
|
|
|
|
}
|
2018-02-21 09:41:54 +00:00
|
|
|
if (info->parentRoot != nullptr)
|
2014-10-30 08:08:00 +00:00
|
|
|
info = renderer->batchRootInfo(info->parentRoot);
|
|
|
|
else
|
2018-02-21 09:41:54 +00:00
|
|
|
info = nullptr;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
renderer->m_rebuild |= Renderer::FullRebuild;
|
|
|
|
}
|
2014-01-28 19:53:01 +00:00
|
|
|
} else {
|
|
|
|
if (m_transformChange) {
|
|
|
|
Element *e = n->element();
|
2020-05-28 11:02:17 +00:00
|
|
|
e->translateOnlyToRoot = isTranslate(*gn->matrix());
|
2014-01-28 19:53:01 +00:00
|
|
|
}
|
|
|
|
if (m_opacityChange) {
|
|
|
|
Element *e = n->element();
|
|
|
|
if (e->batch)
|
|
|
|
renderer->invalidateBatchAndOverlappingRenderOrders(e->batch);
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 22:45:31 +00:00
|
|
|
SHADOWNODE_TRAVERSE(n) visitNode(child);
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Updater::updateRootTransforms(Node *node, Node *root, const QMatrix4x4 &combined)
|
|
|
|
{
|
|
|
|
BatchRootInfo *info = renderer->batchRootInfo(node);
|
|
|
|
QMatrix4x4 m;
|
|
|
|
Node *n = node;
|
|
|
|
|
|
|
|
while (n != root) {
|
|
|
|
if (n->type() == QSGNode::TransformNodeType)
|
|
|
|
m = static_cast<QSGTransformNode *>(n->sgNode)->matrix() * m;
|
2016-11-08 11:47:25 +00:00
|
|
|
n = n->parent();
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m = combined * m;
|
|
|
|
|
|
|
|
if (node->type() == QSGNode::ClipNodeType) {
|
|
|
|
static_cast<ClipBatchRootInfo *>(info)->matrix = m;
|
|
|
|
} else {
|
|
|
|
Q_ASSERT(node->type() == QSGNode::TransformNodeType);
|
|
|
|
static_cast<QSGTransformNode *>(node->sgNode)->setCombinedMatrix(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (QSet<Node *>::const_iterator it = info->subRoots.constBegin();
|
|
|
|
it != info->subRoots.constEnd(); ++it) {
|
|
|
|
updateRootTransforms(*it, node, m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
int qsg_positionAttribute(QSGGeometry *g)
|
|
|
|
{
|
2013-08-14 05:27:07 +00:00
|
|
|
int vaOffset = 0;
|
|
|
|
for (int a=0; a<g->attributeCount(); ++a) {
|
|
|
|
const QSGGeometry::Attribute &attr = g->attributes()[a];
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (attr.isVertexCoordinate && attr.tupleSize == 2 && attr.type == QSGGeometry::FloatType) {
|
2013-08-14 05:27:07 +00:00
|
|
|
return vaOffset;
|
|
|
|
}
|
|
|
|
vaOffset += attr.tupleSize * size_of_type(attr.type);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-12 11:13:11 +00:00
|
|
|
|
|
|
|
void Rect::map(const QMatrix4x4 &matrix)
|
|
|
|
{
|
|
|
|
const float *m = matrix.constData();
|
2020-05-28 11:02:17 +00:00
|
|
|
if (isScale(matrix)) {
|
2013-11-12 11:13:11 +00:00
|
|
|
tl.x = tl.x * m[0] + m[12];
|
|
|
|
tl.y = tl.y * m[5] + m[13];
|
|
|
|
br.x = br.x * m[0] + m[12];
|
|
|
|
br.y = br.y * m[5] + m[13];
|
|
|
|
if (tl.x > br.x)
|
|
|
|
qSwap(tl.x, br.x);
|
|
|
|
if (tl.y > br.y)
|
|
|
|
qSwap(tl.y, br.y);
|
|
|
|
} else {
|
|
|
|
Pt mtl = tl;
|
|
|
|
Pt mtr = { br.x, tl.y };
|
|
|
|
Pt mbl = { tl.x, br.y };
|
|
|
|
Pt mbr = br;
|
|
|
|
|
|
|
|
mtl.map(matrix);
|
|
|
|
mtr.map(matrix);
|
|
|
|
mbl.map(matrix);
|
|
|
|
mbr.map(matrix);
|
|
|
|
|
|
|
|
set(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX);
|
|
|
|
(*this) |= mtl;
|
|
|
|
(*this) |= mtr;
|
|
|
|
(*this) |= mbl;
|
|
|
|
(*this) |= mbr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
void Element::computeBounds()
|
|
|
|
{
|
|
|
|
Q_ASSERT(!boundsComputed);
|
|
|
|
boundsComputed = true;
|
|
|
|
|
|
|
|
QSGGeometry *g = node->geometry();
|
|
|
|
int offset = qsg_positionAttribute(g);
|
|
|
|
if (offset == -1) {
|
|
|
|
// No position attribute means overlaps with everything..
|
|
|
|
bounds.set(-FLT_MAX, -FLT_MAX, FLT_MAX, FLT_MAX);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bounds.set(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX);
|
|
|
|
char *vd = (char *) g->vertexData() + offset;
|
|
|
|
for (int i=0; i<g->vertexCount(); ++i) {
|
|
|
|
bounds |= *(Pt *) vd;
|
|
|
|
vd += g->sizeOfVertex();
|
|
|
|
}
|
|
|
|
bounds.map(*node->matrix());
|
2013-11-04 14:45:22 +00:00
|
|
|
|
2016-04-28 11:07:56 +00:00
|
|
|
if (!qt_is_finite(bounds.tl.x) || bounds.tl.x == FLT_MAX)
|
2013-11-04 14:45:22 +00:00
|
|
|
bounds.tl.x = -FLT_MAX;
|
2016-04-28 11:07:56 +00:00
|
|
|
if (!qt_is_finite(bounds.tl.y) || bounds.tl.y == FLT_MAX)
|
2013-11-04 14:45:22 +00:00
|
|
|
bounds.tl.y = -FLT_MAX;
|
2016-04-28 11:07:56 +00:00
|
|
|
if (!qt_is_finite(bounds.br.x) || bounds.br.x == -FLT_MAX)
|
2013-11-04 14:45:22 +00:00
|
|
|
bounds.br.x = FLT_MAX;
|
2016-04-28 11:07:56 +00:00
|
|
|
if (!qt_is_finite(bounds.br.y) || bounds.br.y == -FLT_MAX)
|
2013-11-04 14:45:22 +00:00
|
|
|
bounds.br.y = FLT_MAX;
|
2013-11-06 09:06:27 +00:00
|
|
|
|
2013-11-28 10:44:39 +00:00
|
|
|
Q_ASSERT(bounds.tl.x <= bounds.br.x);
|
|
|
|
Q_ASSERT(bounds.tl.y <= bounds.br.y);
|
|
|
|
|
2013-11-06 09:06:27 +00:00
|
|
|
boundsOutsideFloatRange = bounds.isOutsideFloatRange();
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 20:24:26 +00:00
|
|
|
BatchCompatibility Batch::isMaterialCompatible(Element *e) const
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
|
|
|
Element *n = first;
|
|
|
|
// Skip to the first node other than e which has not been removed
|
|
|
|
while (n && (n == e || n->removed))
|
|
|
|
n = n->nextInBatch;
|
|
|
|
|
|
|
|
// Only 'e' in this batch, so a material change doesn't change anything as long as
|
|
|
|
// its blending is still in sync with this batch...
|
|
|
|
if (!n)
|
2014-03-12 20:24:26 +00:00
|
|
|
return BatchIsCompatible;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2014-04-25 14:21:00 +00:00
|
|
|
QSGMaterial *m = e->node->activeMaterial();
|
2013-08-14 05:27:07 +00:00
|
|
|
QSGMaterial *nm = n->node->activeMaterial();
|
2014-03-12 20:24:26 +00:00
|
|
|
return (nm->type() == m->type() && nm->compare(m) == 0)
|
|
|
|
? BatchIsCompatible
|
|
|
|
: BatchBreaksOnCompare;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Marks this batch as dirty or in the case where the geometry node has
|
|
|
|
* changed to be incompatible with this batch, return false so that
|
|
|
|
* the caller can mark the entire sg for a full rebuild...
|
|
|
|
*/
|
|
|
|
bool Batch::geometryWasChanged(QSGGeometryNode *gn)
|
|
|
|
{
|
|
|
|
Element *e = first;
|
|
|
|
Q_ASSERT_X(e, "Batch::geometryWasChanged", "Batch is expected to 'valid' at this time");
|
|
|
|
// 'gn' is the first node in the batch, compare against the next one.
|
|
|
|
while (e && (e->node == gn || e->removed))
|
|
|
|
e = e->nextInBatch;
|
|
|
|
if (!e || e->node->geometry()->attributes() == gn->geometry()->attributes()) {
|
|
|
|
needsUpload = true;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Batch::cleanupRemovedElements()
|
|
|
|
{
|
2020-05-20 12:33:50 +00:00
|
|
|
if (!needsPurge)
|
|
|
|
return;
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
// remove from front of batch..
|
|
|
|
while (first && first->removed) {
|
|
|
|
first = first->nextInBatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then continue and remove other nodes further out in the batch..
|
|
|
|
if (first) {
|
|
|
|
Element *e = first;
|
|
|
|
while (e->nextInBatch) {
|
|
|
|
if (e->nextInBatch->removed)
|
|
|
|
e->nextInBatch = e->nextInBatch->nextInBatch;
|
|
|
|
else
|
|
|
|
e = e->nextInBatch;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2020-05-20 12:33:50 +00:00
|
|
|
|
|
|
|
needsPurge = false;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterates through all geometry nodes in this batch and unsets their batch,
|
|
|
|
* thus forcing them to be rebuilt
|
|
|
|
*/
|
|
|
|
void Batch::invalidate()
|
|
|
|
{
|
|
|
|
cleanupRemovedElements();
|
|
|
|
Element *e = first;
|
2018-02-21 09:41:54 +00:00
|
|
|
first = nullptr;
|
|
|
|
root = nullptr;
|
2013-08-14 05:27:07 +00:00
|
|
|
while (e) {
|
2018-02-21 09:41:54 +00:00
|
|
|
e->batch = nullptr;
|
2013-08-14 05:27:07 +00:00
|
|
|
Element *n = e->nextInBatch;
|
2018-02-21 09:41:54 +00:00
|
|
|
e->nextInBatch = nullptr;
|
2013-08-14 05:27:07 +00:00
|
|
|
e = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Batch::isTranslateOnlyToRoot() const {
|
|
|
|
bool only = true;
|
|
|
|
Element *e = first;
|
|
|
|
while (e && only) {
|
|
|
|
only &= e->translateOnlyToRoot;
|
|
|
|
e = e->nextInBatch;
|
|
|
|
}
|
|
|
|
return only;
|
|
|
|
}
|
|
|
|
|
2013-10-07 08:17:56 +00:00
|
|
|
/*
|
|
|
|
* Iterates through all the nodes in the batch and returns true if the
|
2013-11-06 09:06:27 +00:00
|
|
|
* nodes are all safe to batch. There are two separate criteria:
|
|
|
|
*
|
|
|
|
* - The matrix is such that the z component of the result is of no
|
|
|
|
* consequence.
|
|
|
|
*
|
|
|
|
* - The bounds are inside the stable floating point range. This applies
|
|
|
|
* to desktop only where we in this case can trigger a fallback to
|
|
|
|
* unmerged in which case we pass the geometry straight through and
|
|
|
|
* just apply the matrix.
|
|
|
|
*
|
|
|
|
* NOTE: This also means a slight performance impact for geometries which
|
|
|
|
* are defined to be outside the stable floating point range and still
|
|
|
|
* use single precision float, but given that this implicitly fixes
|
|
|
|
* huge lists and tables, it is worth it.
|
2013-10-07 08:17:56 +00:00
|
|
|
*/
|
2013-11-06 09:06:27 +00:00
|
|
|
bool Batch::isSafeToBatch() const {
|
2013-10-07 08:17:56 +00:00
|
|
|
Element *e = first;
|
|
|
|
while (e) {
|
2013-11-06 09:06:27 +00:00
|
|
|
if (e->boundsOutsideFloatRange)
|
|
|
|
return false;
|
2020-05-28 11:02:17 +00:00
|
|
|
if (!is2DSafe(*e->node->matrix()))
|
2013-10-07 08:17:56 +00:00
|
|
|
return false;
|
|
|
|
e = e->nextInBatch;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
static int qsg_countNodesInBatch(const Batch *batch)
|
|
|
|
{
|
|
|
|
int sum = 0;
|
|
|
|
Element *e = batch->first;
|
|
|
|
while (e) {
|
|
|
|
++sum;
|
|
|
|
e = e->nextInBatch;
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int qsg_countNodesInBatches(const QDataBuffer<Batch *> &batches)
|
|
|
|
{
|
|
|
|
int sum = 0;
|
|
|
|
for (int i=0; i<batches.size(); ++i) {
|
|
|
|
sum += qsg_countNodesInBatch(batches.at(i));
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2020-06-11 10:35:04 +00:00
|
|
|
Renderer::Renderer(QSGDefaultRenderContext *ctx, QSGRendererInterface::RenderMode renderMode)
|
2013-08-14 05:27:07 +00:00
|
|
|
: QSGRenderer(ctx)
|
2016-03-15 12:39:41 +00:00
|
|
|
, m_context(ctx)
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
, m_renderMode(renderMode)
|
2013-08-14 05:27:07 +00:00
|
|
|
, m_opaqueRenderList(64)
|
|
|
|
, m_alphaRenderList(64)
|
|
|
|
, m_nextRenderOrder(0)
|
2013-09-05 12:12:53 +00:00
|
|
|
, m_partialRebuild(false)
|
2018-02-21 09:41:54 +00:00
|
|
|
, m_partialRebuildRoot(nullptr)
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
, m_forceNoDepthBuffer(false)
|
2013-08-14 05:27:07 +00:00
|
|
|
, m_opaqueBatches(16)
|
|
|
|
, m_alphaBatches(16)
|
|
|
|
, m_batchPool(16)
|
|
|
|
, m_elementsToDelete(64)
|
|
|
|
, m_tmpAlphaElements(16)
|
|
|
|
, m_tmpOpaqueElements(16)
|
|
|
|
, m_rebuild(FullRebuild)
|
|
|
|
, m_zRange(0)
|
2021-02-12 06:43:22 +00:00
|
|
|
#if defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
|
2014-03-19 10:58:04 +00:00
|
|
|
, m_renderOrderRebuildLower(-1)
|
|
|
|
, m_renderOrderRebuildUpper(-1)
|
2021-02-12 06:43:22 +00:00
|
|
|
#endif
|
2018-02-21 09:41:54 +00:00
|
|
|
, m_currentMaterial(nullptr)
|
|
|
|
, m_currentShader(nullptr)
|
2015-01-06 07:40:21 +00:00
|
|
|
, m_vertexUploadPool(256)
|
|
|
|
, m_indexUploadPool(64)
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
m_rhi = m_context->rhi();
|
2020-05-06 12:16:05 +00:00
|
|
|
Q_ASSERT(m_rhi); // no more direct OpenGL code path in Qt 6
|
|
|
|
|
|
|
|
m_ubufAlignment = m_rhi->ubufAlignment();
|
|
|
|
|
|
|
|
m_uint32IndexForRhi = !m_rhi->isFeatureSupported(QRhi::NonFourAlignedEffectiveIndexBufferOffset);
|
|
|
|
if (qEnvironmentVariableIntValue("QSG_RHI_UINT32_INDEX"))
|
|
|
|
m_uint32IndexForRhi = true;
|
|
|
|
|
|
|
|
m_visualizer = new RhiVisualizer(this);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
setNodeUpdater(new Updater(this));
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
// The shader manager is shared between renderers (think for example Item
|
2020-05-06 12:16:05 +00:00
|
|
|
// layers that create a new Renderer each) with the same rendercontext (and
|
|
|
|
// so same QRhi).
|
2022-06-02 16:29:06 +00:00
|
|
|
m_shaderManager = ctx->findChild<ShaderManager *>(QString(), Qt::FindDirectChildrenOnly);
|
2013-08-14 05:27:07 +00:00
|
|
|
if (!m_shaderManager) {
|
2014-02-11 21:49:08 +00:00
|
|
|
m_shaderManager = new ShaderManager(ctx);
|
2013-08-14 05:27:07 +00:00
|
|
|
m_shaderManager->setObjectName(QStringLiteral("__qt_ShaderManager"));
|
|
|
|
m_shaderManager->setParent(ctx);
|
|
|
|
QObject::connect(ctx, SIGNAL(invalidated()), m_shaderManager, SLOT(invalidated()), Qt::DirectConnection);
|
|
|
|
}
|
|
|
|
|
2015-10-22 10:36:18 +00:00
|
|
|
m_batchNodeThreshold = qt_sg_envInt("QSG_RENDERER_BATCH_NODE_THRESHOLD", 64);
|
|
|
|
m_batchVertexThreshold = qt_sg_envInt("QSG_RENDERER_BATCH_VERTEX_THRESHOLD", 1024);
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
m_srbPoolThreshold = qt_sg_envInt("QSG_RENDERER_SRB_POOL_THRESHOLD", 1024);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2014-09-16 22:20:53 +00:00
|
|
|
if (Q_UNLIKELY(debug_build() || debug_render())) {
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
qDebug("Batch thresholds: nodes: %d vertices: %d Srb pool threshold: %d",
|
|
|
|
m_batchNodeThreshold, m_batchVertexThreshold, m_srbPoolThreshold);
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
static void qsg_wipeBuffer(Buffer *buffer)
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
2022-01-03 16:51:34 +00:00
|
|
|
delete buffer->buf;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
2015-01-06 07:40:21 +00:00
|
|
|
// The free here is ok because we're in one of two situations.
|
|
|
|
// 1. We're using the upload pool in which case unmap will have set the
|
|
|
|
// data pointer to 0 and calling free on 0 is ok.
|
|
|
|
// 2. We're using dedicated buffers because of visualization or IBO workaround
|
|
|
|
// and the data something we malloced and must be freed.
|
2013-08-14 05:27:07 +00:00
|
|
|
free(buffer->data);
|
|
|
|
}
|
|
|
|
|
2022-02-07 11:52:33 +00:00
|
|
|
static void qsg_wipeBatch(Batch *batch)
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
2020-05-06 12:16:05 +00:00
|
|
|
qsg_wipeBuffer(&batch->vbo);
|
2022-02-07 11:52:33 +00:00
|
|
|
qsg_wipeBuffer(&batch->ibo);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
delete batch->ubuf;
|
|
|
|
batch->stencilClipState.reset();
|
2013-08-14 05:27:07 +00:00
|
|
|
delete batch;
|
|
|
|
}
|
|
|
|
|
|
|
|
Renderer::~Renderer()
|
|
|
|
{
|
2020-05-06 12:16:05 +00:00
|
|
|
if (m_rhi) {
|
2014-04-11 14:21:54 +00:00
|
|
|
// Clean up batches and buffers
|
2018-02-05 16:20:08 +00:00
|
|
|
for (int i = 0; i < m_opaqueBatches.size(); ++i)
|
2022-02-07 11:52:33 +00:00
|
|
|
qsg_wipeBatch(m_opaqueBatches.at(i));
|
2018-02-05 16:20:08 +00:00
|
|
|
for (int i = 0; i < m_alphaBatches.size(); ++i)
|
2022-02-07 11:52:33 +00:00
|
|
|
qsg_wipeBatch(m_alphaBatches.at(i));
|
2018-02-05 16:20:08 +00:00
|
|
|
for (int i = 0; i < m_batchPool.size(); ++i)
|
2022-02-07 11:52:33 +00:00
|
|
|
qsg_wipeBatch(m_batchPool.at(i));
|
2014-04-11 14:21:54 +00:00
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2016-05-13 15:57:24 +00:00
|
|
|
for (Node *n : qAsConst(m_nodes))
|
2014-10-22 11:32:27 +00:00
|
|
|
m_nodeAllocator.release(n);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
// Remaining elements...
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
for (int i=0; i<m_elementsToDelete.size(); ++i)
|
|
|
|
releaseElement(m_elementsToDelete.at(i), true);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
destroyGraphicsResources();
|
2019-07-31 13:17:52 +00:00
|
|
|
|
|
|
|
delete m_visualizer;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::destroyGraphicsResources()
|
|
|
|
{
|
|
|
|
// If this is from the dtor, then the shader manager and its already
|
|
|
|
// prepared shaders will stay around for other renderers -> the cached data
|
|
|
|
// in the rhi shaders have to be purged as it may refer to samplers we
|
|
|
|
// are going to destroy.
|
|
|
|
m_shaderManager->clearCachedRendererData();
|
|
|
|
|
|
|
|
qDeleteAll(m_samplers);
|
|
|
|
m_stencilClipCommon.reset();
|
|
|
|
delete m_dummyTexture;
|
2019-07-31 13:17:52 +00:00
|
|
|
m_visualizer->releaseResources();
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::releaseCachedResources()
|
|
|
|
{
|
|
|
|
m_shaderManager->invalidated();
|
|
|
|
|
|
|
|
destroyGraphicsResources();
|
|
|
|
|
|
|
|
m_samplers.clear();
|
|
|
|
m_dummyTexture = nullptr;
|
2019-09-09 08:21:40 +00:00
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
m_rhi->releaseCachedResources();
|
2021-10-14 09:03:31 +00:00
|
|
|
|
2021-11-10 12:15:24 +00:00
|
|
|
m_vertexUploadPool.resize(0);
|
|
|
|
m_indexUploadPool.resize(0);
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::invalidateAndRecycleBatch(Batch *b)
|
|
|
|
{
|
|
|
|
b->invalidate();
|
|
|
|
for (int i=0; i<m_batchPool.size(); ++i)
|
|
|
|
if (b == m_batchPool.at(i))
|
|
|
|
return;
|
|
|
|
m_batchPool.add(b);
|
|
|
|
}
|
|
|
|
|
2022-07-08 08:15:58 +00:00
|
|
|
void Renderer::map(Buffer *buffer, quint32 byteSize, bool isIndexBuf)
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
2020-06-08 08:25:22 +00:00
|
|
|
if (m_visualizer->mode() == Visualizer::VisualizeNothing) {
|
2015-01-06 07:40:21 +00:00
|
|
|
// Common case, use a shared memory pool for uploading vertex data to avoid
|
|
|
|
// excessive reevaluation
|
2022-02-07 11:52:33 +00:00
|
|
|
QDataBuffer<char> &pool = isIndexBuf ? m_indexUploadPool : m_vertexUploadPool;
|
2022-07-08 08:15:58 +00:00
|
|
|
if (byteSize > quint32(pool.size()))
|
2015-01-06 07:40:21 +00:00
|
|
|
pool.resize(byteSize);
|
|
|
|
buffer->data = pool.data();
|
2015-10-16 06:07:32 +00:00
|
|
|
} else if (buffer->size != byteSize) {
|
|
|
|
free(buffer->data);
|
2013-08-14 05:27:07 +00:00
|
|
|
buffer->data = (char *) malloc(byteSize);
|
2016-12-12 12:44:49 +00:00
|
|
|
Q_CHECK_PTR(buffer->data);
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
2015-01-06 07:40:21 +00:00
|
|
|
buffer->size = byteSize;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
2014-01-05 19:36:13 +00:00
|
|
|
void Renderer::unmap(Buffer *buffer, bool isIndexBuf)
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
2020-05-06 12:16:05 +00:00
|
|
|
// Batches are pooled and reused which means the QRhiBuffer will be
|
|
|
|
// still valid in a recycled Batch. We only hit the newBuffer() path
|
|
|
|
// for brand new Batches.
|
|
|
|
if (!buffer->buf) {
|
|
|
|
buffer->buf = m_rhi->newBuffer(QRhiBuffer::Immutable,
|
|
|
|
isIndexBuf ? QRhiBuffer::IndexBuffer : QRhiBuffer::VertexBuffer,
|
|
|
|
buffer->size);
|
2022-01-03 16:51:34 +00:00
|
|
|
if (!buffer->buf->create()) {
|
2022-07-08 08:15:58 +00:00
|
|
|
qWarning("Failed to build vertex/index buffer of size %u", buffer->size);
|
2022-01-03 16:51:34 +00:00
|
|
|
delete buffer->buf;
|
|
|
|
buffer->buf = nullptr;
|
|
|
|
}
|
2020-05-06 12:16:05 +00:00
|
|
|
} else {
|
|
|
|
bool needsRebuild = false;
|
|
|
|
if (buffer->buf->size() < buffer->size) {
|
|
|
|
buffer->buf->setSize(buffer->size);
|
|
|
|
needsRebuild = true;
|
|
|
|
}
|
|
|
|
if (buffer->buf->type() != QRhiBuffer::Dynamic
|
|
|
|
&& buffer->nonDynamicChangeCount > DYNAMIC_VERTEX_INDEX_BUFFER_THRESHOLD)
|
|
|
|
{
|
|
|
|
buffer->buf->setType(QRhiBuffer::Dynamic);
|
|
|
|
buffer->nonDynamicChangeCount = 0;
|
|
|
|
needsRebuild = true;
|
|
|
|
}
|
2022-01-03 16:51:34 +00:00
|
|
|
if (needsRebuild) {
|
|
|
|
if (!buffer->buf->create()) {
|
2022-07-08 08:15:58 +00:00
|
|
|
qWarning("Failed to (re)build vertex/index buffer of size %u", buffer->size);
|
2022-01-03 16:51:34 +00:00
|
|
|
delete buffer->buf;
|
|
|
|
buffer->buf = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2020-05-06 12:16:05 +00:00
|
|
|
}
|
2022-01-03 16:51:34 +00:00
|
|
|
if (buffer->buf) {
|
|
|
|
if (buffer->buf->type() != QRhiBuffer::Dynamic) {
|
|
|
|
m_resourceUpdates->uploadStaticBuffer(buffer->buf,
|
|
|
|
0, buffer->size, buffer->data);
|
|
|
|
buffer->nonDynamicChangeCount += 1;
|
|
|
|
} else {
|
|
|
|
m_resourceUpdates->updateDynamicBuffer(buffer->buf, 0, buffer->size,
|
|
|
|
buffer->data);
|
|
|
|
}
|
2015-01-06 07:40:21 +00:00
|
|
|
}
|
2020-05-06 12:16:05 +00:00
|
|
|
if (m_visualizer->mode() == Visualizer::VisualizeNothing)
|
|
|
|
buffer->data = nullptr;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BatchRootInfo *Renderer::batchRootInfo(Node *node)
|
|
|
|
{
|
|
|
|
BatchRootInfo *info = node->rootInfo();
|
|
|
|
if (!info) {
|
|
|
|
if (node->type() == QSGNode::ClipNodeType)
|
|
|
|
info = new ClipBatchRootInfo;
|
|
|
|
else {
|
|
|
|
Q_ASSERT(node->type() == QSGNode::TransformNodeType);
|
|
|
|
info = new BatchRootInfo;
|
|
|
|
}
|
|
|
|
node->data = info;
|
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::removeBatchRootFromParent(Node *childRoot)
|
|
|
|
{
|
|
|
|
BatchRootInfo *childInfo = batchRootInfo(childRoot);
|
|
|
|
if (!childInfo->parentRoot)
|
|
|
|
return;
|
|
|
|
BatchRootInfo *parentInfo = batchRootInfo(childInfo->parentRoot);
|
|
|
|
|
|
|
|
Q_ASSERT(parentInfo->subRoots.contains(childRoot));
|
|
|
|
parentInfo->subRoots.remove(childRoot);
|
2018-02-21 09:41:54 +00:00
|
|
|
childInfo->parentRoot = nullptr;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::registerBatchRoot(Node *subRoot, Node *parentRoot)
|
|
|
|
{
|
|
|
|
BatchRootInfo *subInfo = batchRootInfo(subRoot);
|
|
|
|
BatchRootInfo *parentInfo = batchRootInfo(parentRoot);
|
|
|
|
subInfo->parentRoot = parentRoot;
|
|
|
|
parentInfo->subRoots << subRoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Renderer::changeBatchRoot(Node *node, Node *root)
|
|
|
|
{
|
|
|
|
BatchRootInfo *subInfo = batchRootInfo(node);
|
|
|
|
if (subInfo->parentRoot == root)
|
|
|
|
return false;
|
|
|
|
if (subInfo->parentRoot) {
|
|
|
|
BatchRootInfo *oldRootInfo = batchRootInfo(subInfo->parentRoot);
|
|
|
|
oldRootInfo->subRoots.remove(node);
|
|
|
|
}
|
|
|
|
BatchRootInfo *newRootInfo = batchRootInfo(root);
|
|
|
|
newRootInfo->subRoots << node;
|
|
|
|
subInfo->parentRoot = root;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::nodeChangedBatchRoot(Node *node, Node *root)
|
|
|
|
{
|
|
|
|
if (node->type() == QSGNode::ClipNodeType || node->isBatchRoot) {
|
2017-06-16 06:03:45 +00:00
|
|
|
// When we reach a batchroot, we only need to update it. Its subtree
|
|
|
|
// is relative to that root, so no need to recurse further.
|
|
|
|
changeBatchRoot(node, root);
|
|
|
|
return;
|
2013-08-14 05:27:07 +00:00
|
|
|
} else if (node->type() == QSGNode::GeometryNodeType) {
|
|
|
|
// Only need to change the root as nodeChanged anyway flags a full update.
|
|
|
|
Element *e = node->element();
|
2013-10-02 10:58:42 +00:00
|
|
|
if (e) {
|
2013-08-14 05:27:07 +00:00
|
|
|
e->root = root;
|
2013-10-02 10:58:42 +00:00
|
|
|
e->boundsComputed = false;
|
|
|
|
}
|
2016-12-13 13:24:49 +00:00
|
|
|
} else if (node->type() == QSGNode::RenderNodeType) {
|
|
|
|
RenderNodeElement *e = node->renderNodeElement();
|
|
|
|
if (e)
|
|
|
|
e->root = root;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SHADOWNODE_TRAVERSE(node)
|
2015-06-04 22:45:31 +00:00
|
|
|
nodeChangedBatchRoot(child, root);
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::nodeWasTransformed(Node *node, int *vertexCount)
|
|
|
|
{
|
|
|
|
if (node->type() == QSGNode::GeometryNodeType) {
|
|
|
|
QSGGeometryNode *gn = static_cast<QSGGeometryNode *>(node->sgNode);
|
|
|
|
*vertexCount += gn->geometry()->vertexCount();
|
|
|
|
Element *e = node->element();
|
|
|
|
if (e) {
|
|
|
|
e->boundsComputed = false;
|
|
|
|
if (e->batch) {
|
|
|
|
if (!e->batch->isOpaque) {
|
2014-01-28 19:53:01 +00:00
|
|
|
invalidateBatchAndOverlappingRenderOrders(e->batch);
|
2013-08-14 05:27:07 +00:00
|
|
|
} else if (e->batch->merged) {
|
|
|
|
e->batch->needsUpload = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SHADOWNODE_TRAVERSE(node)
|
2015-06-04 22:45:31 +00:00
|
|
|
nodeWasTransformed(child, vertexCount);
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::nodeWasAdded(QSGNode *node, Node *shadowParent)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!m_nodes.contains(node));
|
|
|
|
if (node->isSubtreeBlocked())
|
|
|
|
return;
|
|
|
|
|
2014-10-22 11:32:27 +00:00
|
|
|
Node *snode = m_nodeAllocator.allocate();
|
|
|
|
snode->sgNode = node;
|
2013-08-14 05:27:07 +00:00
|
|
|
m_nodes.insert(node, snode);
|
2016-11-08 11:47:25 +00:00
|
|
|
if (shadowParent)
|
|
|
|
shadowParent->append(snode);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
if (node->type() == QSGNode::GeometryNodeType) {
|
2014-10-22 11:32:27 +00:00
|
|
|
snode->data = m_elementAllocator.allocate();
|
|
|
|
snode->element()->setNode(static_cast<QSGGeometryNode *>(node));
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
} else if (node->type() == QSGNode::ClipNodeType) {
|
|
|
|
snode->data = new ClipBatchRootInfo;
|
2013-09-04 12:08:41 +00:00
|
|
|
m_rebuild |= FullRebuild;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
} else if (node->type() == QSGNode::RenderNodeType) {
|
2016-07-27 09:59:17 +00:00
|
|
|
QSGRenderNode *rn = static_cast<QSGRenderNode *>(node);
|
|
|
|
RenderNodeElement *e = new RenderNodeElement(rn);
|
2013-08-14 05:27:07 +00:00
|
|
|
snode->data = e;
|
2016-07-27 09:59:17 +00:00
|
|
|
Q_ASSERT(!m_renderNodeElements.contains(rn));
|
2013-08-14 05:27:07 +00:00
|
|
|
m_renderNodeElements.insert(e->renderNode, e);
|
2016-07-27 09:59:17 +00:00
|
|
|
if (!rn->flags().testFlag(QSGRenderNode::DepthAwareRendering))
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
m_forceNoDepthBuffer = true;
|
2014-01-21 14:57:19 +00:00
|
|
|
m_rebuild |= FullRebuild;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QSGNODE_TRAVERSE(node)
|
|
|
|
nodeWasAdded(child, snode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::nodeWasRemoved(Node *node)
|
|
|
|
{
|
2015-06-04 22:45:31 +00:00
|
|
|
// Prefix traversal as removeBatchRootFromParent below removes nodes
|
|
|
|
// in a bottom-up manner. Note that we *cannot* use SHADOWNODE_TRAVERSE
|
|
|
|
// here, because we delete 'child' (when recursed, down below), so we'd
|
|
|
|
// have a use-after-free.
|
|
|
|
{
|
2016-11-08 11:47:25 +00:00
|
|
|
Node *child = node->firstChild();
|
2015-06-04 22:45:31 +00:00
|
|
|
while (child) {
|
|
|
|
// Remove (and delete) child
|
2016-11-08 11:47:25 +00:00
|
|
|
node->remove(child);
|
2015-06-04 22:45:31 +00:00
|
|
|
nodeWasRemoved(child);
|
2016-11-08 11:47:25 +00:00
|
|
|
child = node->firstChild();
|
2015-06-04 22:45:31 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
if (node->type() == QSGNode::GeometryNodeType) {
|
|
|
|
Element *e = node->element();
|
|
|
|
if (e) {
|
|
|
|
e->removed = true;
|
|
|
|
m_elementsToDelete.add(e);
|
2018-02-21 09:41:54 +00:00
|
|
|
e->node = nullptr;
|
2013-08-14 05:27:07 +00:00
|
|
|
if (e->root) {
|
|
|
|
BatchRootInfo *info = batchRootInfo(e->root);
|
|
|
|
info->availableOrders++;
|
|
|
|
}
|
|
|
|
if (e->batch) {
|
|
|
|
e->batch->needsUpload = true;
|
2020-05-20 12:33:50 +00:00
|
|
|
e->batch->needsPurge = true;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (node->type() == QSGNode::ClipNodeType) {
|
|
|
|
removeBatchRootFromParent(node);
|
|
|
|
delete node->clipInfo();
|
|
|
|
m_rebuild |= FullRebuild;
|
|
|
|
m_taggedRoots.remove(node);
|
|
|
|
|
|
|
|
} else if (node->isBatchRoot) {
|
|
|
|
removeBatchRootFromParent(node);
|
|
|
|
delete node->rootInfo();
|
|
|
|
m_rebuild |= FullRebuild;
|
|
|
|
m_taggedRoots.remove(node);
|
|
|
|
|
|
|
|
} else if (node->type() == QSGNode::RenderNodeType) {
|
|
|
|
RenderNodeElement *e = m_renderNodeElements.take(static_cast<QSGRenderNode *>(node->sgNode));
|
|
|
|
if (e) {
|
|
|
|
e->removed = true;
|
|
|
|
m_elementsToDelete.add(e);
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
if (m_renderNodeElements.isEmpty())
|
|
|
|
m_forceNoDepthBuffer = false;
|
2020-05-20 12:33:50 +00:00
|
|
|
|
|
|
|
if (e->batch != nullptr)
|
|
|
|
e->batch->needsPurge = true;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(m_nodes.contains(node->sgNode));
|
2016-11-08 11:47:25 +00:00
|
|
|
|
2014-10-22 11:32:27 +00:00
|
|
|
m_nodeAllocator.release(m_nodes.take(node->sgNode));
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::turnNodeIntoBatchRoot(Node *node)
|
|
|
|
{
|
2018-02-13 08:57:29 +00:00
|
|
|
if (Q_UNLIKELY(debug_change())) qDebug(" - new batch root");
|
2013-08-14 05:27:07 +00:00
|
|
|
m_rebuild |= FullRebuild;
|
|
|
|
node->isBatchRoot = true;
|
|
|
|
node->becameBatchRoot = true;
|
|
|
|
|
2016-11-08 11:47:25 +00:00
|
|
|
Node *p = node->parent();
|
2013-08-14 05:27:07 +00:00
|
|
|
while (p) {
|
|
|
|
if (p->type() == QSGNode::ClipNodeType || p->isBatchRoot) {
|
|
|
|
registerBatchRoot(node, p);
|
|
|
|
break;
|
|
|
|
}
|
2016-11-08 11:47:25 +00:00
|
|
|
p = p->parent();
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SHADOWNODE_TRAVERSE(node)
|
2015-06-04 22:45:31 +00:00
|
|
|
nodeChangedBatchRoot(child, node);
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Renderer::nodeChanged(QSGNode *node, QSGNode::DirtyState state)
|
|
|
|
{
|
2014-10-22 22:34:09 +00:00
|
|
|
#ifndef QT_NO_DEBUG_OUTPUT
|
2014-09-16 22:20:53 +00:00
|
|
|
if (Q_UNLIKELY(debug_change())) {
|
2013-08-14 05:27:07 +00:00
|
|
|
QDebug debug = qDebug();
|
|
|
|
debug << "dirty:";
|
|
|
|
if (state & QSGNode::DirtyGeometry)
|
|
|
|
debug << "Geometry";
|
|
|
|
if (state & QSGNode::DirtyMaterial)
|
|
|
|
debug << "Material";
|
|
|
|
if (state & QSGNode::DirtyMatrix)
|
|
|
|
debug << "Matrix";
|
|
|
|
if (state & QSGNode::DirtyNodeAdded)
|
|
|
|
debug << "Added";
|
|
|
|
if (state & QSGNode::DirtyNodeRemoved)
|
|
|
|
debug << "Removed";
|
|
|
|
if (state & QSGNode::DirtyOpacity)
|
|
|
|
debug << "Opacity";
|
|
|
|
if (state & QSGNode::DirtySubtreeBlocked)
|
|
|
|
debug << "SubtreeBlocked";
|
|
|
|
if (state & QSGNode::DirtyForceUpdate)
|
|
|
|
debug << "ForceUpdate";
|
|
|
|
|
|
|
|
// when removed, some parts of the node could already have been destroyed
|
|
|
|
// so don't debug it out.
|
|
|
|
if (state & QSGNode::DirtyNodeRemoved)
|
|
|
|
debug << (void *) node << node->type();
|
|
|
|
else
|
|
|
|
debug << node;
|
|
|
|
}
|
2014-10-22 22:34:09 +00:00
|
|
|
#endif
|
2013-08-14 05:27:07 +00:00
|
|
|
// As this function calls nodeChanged recursively, we do it at the top
|
|
|
|
// to avoid that any of the others are processed twice.
|
|
|
|
if (state & QSGNode::DirtySubtreeBlocked) {
|
|
|
|
Node *sn = m_nodes.value(node);
|
2020-08-11 09:28:36 +00:00
|
|
|
|
|
|
|
// Force a batch rebuild if this includes an opacity change
|
|
|
|
if (state & QSGNode::DirtyOpacity)
|
|
|
|
m_rebuild |= FullRebuild;
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
bool blocked = node->isSubtreeBlocked();
|
|
|
|
if (blocked && sn) {
|
|
|
|
nodeChanged(node, QSGNode::DirtyNodeRemoved);
|
|
|
|
Q_ASSERT(m_nodes.value(node) == 0);
|
|
|
|
} else if (!blocked && !sn) {
|
|
|
|
nodeChanged(node, QSGNode::DirtyNodeAdded);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state & QSGNode::DirtyNodeAdded) {
|
|
|
|
if (nodeUpdater()->isNodeBlocked(node, rootNode())) {
|
|
|
|
QSGRenderer::nodeChanged(node, state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (node == rootNode())
|
2018-02-21 09:41:54 +00:00
|
|
|
nodeWasAdded(node, nullptr);
|
2013-08-14 05:27:07 +00:00
|
|
|
else
|
|
|
|
nodeWasAdded(node, m_nodes.value(node->parent()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark this node dirty in the shadow tree.
|
|
|
|
Node *shadowNode = m_nodes.value(node);
|
|
|
|
|
|
|
|
// Blocked subtrees won't have shadow nodes, so we can safely abort
|
|
|
|
// here..
|
|
|
|
if (!shadowNode) {
|
|
|
|
QSGRenderer::nodeChanged(node, state);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
shadowNode->dirtyState |= state;
|
|
|
|
|
|
|
|
if (state & QSGNode::DirtyMatrix && !shadowNode->isBatchRoot) {
|
|
|
|
Q_ASSERT(node->type() == QSGNode::TransformNodeType);
|
|
|
|
if (node->m_subtreeRenderableCount > m_batchNodeThreshold) {
|
|
|
|
turnNodeIntoBatchRoot(shadowNode);
|
|
|
|
} else {
|
|
|
|
int vertices = 0;
|
|
|
|
nodeWasTransformed(shadowNode, &vertices);
|
|
|
|
if (vertices > m_batchVertexThreshold) {
|
|
|
|
turnNodeIntoBatchRoot(shadowNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state & QSGNode::DirtyGeometry && node->type() == QSGNode::GeometryNodeType) {
|
|
|
|
QSGGeometryNode *gn = static_cast<QSGGeometryNode *>(node);
|
|
|
|
Element *e = shadowNode->element();
|
|
|
|
if (e) {
|
|
|
|
e->boundsComputed = false;
|
|
|
|
Batch *b = e->batch;
|
|
|
|
if (b) {
|
2014-01-28 19:53:01 +00:00
|
|
|
if (!e->batch->geometryWasChanged(gn) || !e->batch->isOpaque) {
|
|
|
|
invalidateBatchAndOverlappingRenderOrders(e->batch);
|
2013-08-14 05:27:07 +00:00
|
|
|
} else {
|
|
|
|
b->needsUpload = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-05 12:12:53 +00:00
|
|
|
if (state & QSGNode::DirtyMaterial && node->type() == QSGNode::GeometryNodeType) {
|
2013-08-14 05:27:07 +00:00
|
|
|
Element *e = shadowNode->element();
|
|
|
|
if (e) {
|
2014-04-25 14:21:00 +00:00
|
|
|
bool blended = hasMaterialWithBlending(static_cast<QSGGeometryNode *>(node));
|
|
|
|
if (e->isMaterialBlended != blended) {
|
|
|
|
m_rebuild |= Renderer::FullRebuild;
|
|
|
|
e->isMaterialBlended = blended;
|
2016-04-26 06:39:15 +00:00
|
|
|
} else if (e->batch) {
|
|
|
|
if (e->batch->isMaterialCompatible(e) == BatchBreaksOnCompare)
|
|
|
|
invalidateBatchAndOverlappingRenderOrders(e->batch);
|
|
|
|
} else {
|
2013-09-04 12:08:41 +00:00
|
|
|
m_rebuild |= Renderer::BuildBatches;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark the shadow tree dirty all the way back to the root...
|
|
|
|
QSGNode::DirtyState dirtyChain = state & (QSGNode::DirtyNodeAdded
|
|
|
|
| QSGNode::DirtyOpacity
|
|
|
|
| QSGNode::DirtyMatrix
|
2013-10-04 08:39:20 +00:00
|
|
|
| QSGNode::DirtySubtreeBlocked
|
|
|
|
| QSGNode::DirtyForceUpdate);
|
2013-08-14 05:27:07 +00:00
|
|
|
if (dirtyChain != 0) {
|
|
|
|
dirtyChain = QSGNode::DirtyState(dirtyChain << 16);
|
2016-11-08 11:47:25 +00:00
|
|
|
Node *sn = shadowNode->parent();
|
2013-08-14 05:27:07 +00:00
|
|
|
while (sn) {
|
|
|
|
sn->dirtyState |= dirtyChain;
|
2016-11-08 11:47:25 +00:00
|
|
|
sn = sn->parent();
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete happens at the very end because it deletes the shadownode.
|
|
|
|
if (state & QSGNode::DirtyNodeRemoved) {
|
2016-11-08 11:47:25 +00:00
|
|
|
Node *parent = shadowNode->parent();
|
|
|
|
if (parent)
|
|
|
|
parent->remove(shadowNode);
|
2013-08-14 05:27:07 +00:00
|
|
|
nodeWasRemoved(shadowNode);
|
|
|
|
Q_ASSERT(m_nodes.value(node) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSGRenderer::nodeChanged(node, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Traverses the tree and builds two list of geometry nodes. One for
|
|
|
|
* the opaque and one for the translucent. These are populated
|
|
|
|
* in the order they should visually appear in, meaning first
|
|
|
|
* to the back and last to the front.
|
|
|
|
*
|
|
|
|
* We split opaque and translucent as we can perform different
|
|
|
|
* types of reordering / batching strategies on them, depending
|
|
|
|
*
|
|
|
|
* Note: It would be tempting to use the shadow nodes instead of the QSGNodes
|
|
|
|
* for traversal to avoid hash lookups, but the order of the children
|
|
|
|
* is important and they are not preserved in the shadow tree, so we must
|
|
|
|
* use the actual QSGNode tree.
|
|
|
|
*/
|
|
|
|
void Renderer::buildRenderLists(QSGNode *node)
|
|
|
|
{
|
|
|
|
if (node->isSubtreeBlocked())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Node *shadowNode = m_nodes.value(node);
|
2014-10-22 11:32:27 +00:00
|
|
|
Q_ASSERT(shadowNode);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
if (node->type() == QSGNode::GeometryNodeType) {
|
|
|
|
QSGGeometryNode *gn = static_cast<QSGGeometryNode *>(node);
|
|
|
|
|
|
|
|
Element *e = shadowNode->element();
|
|
|
|
Q_ASSERT(e);
|
|
|
|
|
|
|
|
bool opaque = gn->inheritedOpacity() > OPAQUE_LIMIT && !(gn->activeMaterial()->flags() & QSGMaterial::Blending);
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
if (opaque && useDepthBuffer())
|
2013-08-14 05:27:07 +00:00
|
|
|
m_opaqueRenderList << e;
|
|
|
|
else
|
|
|
|
m_alphaRenderList << e;
|
|
|
|
|
|
|
|
e->order = ++m_nextRenderOrder;
|
|
|
|
// Used while rebuilding partial roots.
|
2013-09-05 12:12:53 +00:00
|
|
|
if (m_partialRebuild)
|
2013-08-14 05:27:07 +00:00
|
|
|
e->orphaned = false;
|
|
|
|
|
|
|
|
} else if (node->type() == QSGNode::ClipNodeType || shadowNode->isBatchRoot) {
|
|
|
|
Q_ASSERT(m_nodes.contains(node));
|
2014-10-22 11:32:27 +00:00
|
|
|
BatchRootInfo *info = batchRootInfo(shadowNode);
|
2013-09-05 12:12:53 +00:00
|
|
|
if (node == m_partialRebuildRoot) {
|
2013-08-14 05:27:07 +00:00
|
|
|
m_nextRenderOrder = info->firstOrder;
|
2013-09-05 12:12:53 +00:00
|
|
|
QSGNODE_TRAVERSE(node)
|
|
|
|
buildRenderLists(child);
|
2013-08-14 05:27:07 +00:00
|
|
|
m_nextRenderOrder = info->lastOrder + 1;
|
|
|
|
} else {
|
2013-09-05 12:12:53 +00:00
|
|
|
int currentOrder = m_nextRenderOrder;
|
|
|
|
QSGNODE_TRAVERSE(node)
|
|
|
|
buildRenderLists(child);
|
|
|
|
int padding = (m_nextRenderOrder - currentOrder) >> 2;
|
2013-08-14 05:27:07 +00:00
|
|
|
info->firstOrder = currentOrder;
|
|
|
|
info->availableOrders = padding;
|
|
|
|
info->lastOrder = m_nextRenderOrder + padding;
|
2013-09-05 12:12:53 +00:00
|
|
|
m_nextRenderOrder = info->lastOrder;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if (node->type() == QSGNode::RenderNodeType) {
|
|
|
|
RenderNodeElement *e = shadowNode->renderNodeElement();
|
|
|
|
m_alphaRenderList << e;
|
|
|
|
e->order = ++m_nextRenderOrder;
|
|
|
|
Q_ASSERT(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSGNODE_TRAVERSE(node)
|
|
|
|
buildRenderLists(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::tagSubRoots(Node *node)
|
|
|
|
{
|
|
|
|
BatchRootInfo *i = batchRootInfo(node);
|
|
|
|
m_taggedRoots << node;
|
|
|
|
for (QSet<Node *>::const_iterator it = i->subRoots.constBegin();
|
|
|
|
it != i->subRoots.constEnd(); ++it) {
|
|
|
|
tagSubRoots(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qsg_addOrphanedElements(QDataBuffer<Element *> &orphans, const QDataBuffer<Element *> &renderList)
|
|
|
|
{
|
|
|
|
orphans.reset();
|
|
|
|
for (int i=0; i<renderList.size(); ++i) {
|
|
|
|
Element *e = renderList.at(i);
|
2013-09-04 12:08:41 +00:00
|
|
|
if (e && !e->removed) {
|
2013-08-14 05:27:07 +00:00
|
|
|
e->orphaned = true;
|
|
|
|
orphans.add(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qsg_addBackOrphanedElements(QDataBuffer<Element *> &orphans, QDataBuffer<Element *> &renderList)
|
|
|
|
{
|
|
|
|
for (int i=0; i<orphans.size(); ++i) {
|
|
|
|
Element *e = orphans.at(i);
|
|
|
|
if (e->orphaned)
|
|
|
|
renderList.add(e);
|
|
|
|
}
|
|
|
|
orphans.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To rebuild the tagged roots, we start by putting all subroots of tagged
|
|
|
|
* roots into the list of tagged roots. This is to make the rest of the
|
|
|
|
* algorithm simpler.
|
|
|
|
*
|
|
|
|
* Second, we invalidate all batches which belong to tagged roots, which now
|
|
|
|
* includes the entire subtree under a given root
|
|
|
|
*
|
|
|
|
* Then we call buildRenderLists for all tagged subroots which do not have
|
|
|
|
* parents which are tagged, aka, we traverse only the topmosts roots.
|
|
|
|
*
|
|
|
|
* Then we sort the render lists based on their render order, to restore the
|
|
|
|
* right order for rendering.
|
|
|
|
*/
|
|
|
|
void Renderer::buildRenderListsForTaggedRoots()
|
|
|
|
{
|
|
|
|
// Flag any element that is currently in the render lists, but which
|
|
|
|
// is not in a batch. This happens when we have a partial rebuild
|
|
|
|
// in one sub tree while we have a BuildBatches change in another
|
|
|
|
// isolated subtree. So that batch-building takes into account
|
|
|
|
// these "orphaned" nodes, we flag them now. The ones under tagged
|
|
|
|
// roots will be cleared again. The remaining ones are added into the
|
|
|
|
// render lists so that they contain all visual nodes after the
|
|
|
|
// function completes.
|
|
|
|
qsg_addOrphanedElements(m_tmpOpaqueElements, m_opaqueRenderList);
|
|
|
|
qsg_addOrphanedElements(m_tmpAlphaElements, m_alphaRenderList);
|
|
|
|
|
|
|
|
// Take a copy now, as we will be adding to this while traversing..
|
|
|
|
QSet<Node *> roots = m_taggedRoots;
|
|
|
|
for (QSet<Node *>::const_iterator it = roots.constBegin();
|
|
|
|
it != roots.constEnd(); ++it) {
|
|
|
|
tagSubRoots(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0; i<m_opaqueBatches.size(); ++i) {
|
|
|
|
Batch *b = m_opaqueBatches.at(i);
|
|
|
|
if (m_taggedRoots.contains(b->root))
|
|
|
|
invalidateAndRecycleBatch(b);
|
|
|
|
|
|
|
|
}
|
|
|
|
for (int i=0; i<m_alphaBatches.size(); ++i) {
|
|
|
|
Batch *b = m_alphaBatches.at(i);
|
|
|
|
if (m_taggedRoots.contains(b->root))
|
|
|
|
invalidateAndRecycleBatch(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_opaqueRenderList.reset();
|
|
|
|
m_alphaRenderList.reset();
|
|
|
|
int maxRenderOrder = m_nextRenderOrder;
|
2013-09-05 12:12:53 +00:00
|
|
|
m_partialRebuild = true;
|
2013-08-14 05:27:07 +00:00
|
|
|
// Traverse each root, assigning it
|
|
|
|
for (QSet<Node *>::const_iterator it = m_taggedRoots.constBegin();
|
|
|
|
it != m_taggedRoots.constEnd(); ++it) {
|
|
|
|
Node *root = *it;
|
|
|
|
BatchRootInfo *i = batchRootInfo(root);
|
|
|
|
if ((!i->parentRoot || !m_taggedRoots.contains(i->parentRoot))
|
|
|
|
&& !nodeUpdater()->isNodeBlocked(root->sgNode, rootNode())) {
|
|
|
|
m_nextRenderOrder = i->firstOrder;
|
2013-09-05 12:12:53 +00:00
|
|
|
m_partialRebuildRoot = root->sgNode;
|
2013-08-14 05:27:07 +00:00
|
|
|
buildRenderLists(root->sgNode);
|
|
|
|
}
|
|
|
|
}
|
2013-09-05 12:12:53 +00:00
|
|
|
m_partialRebuild = false;
|
2018-02-21 09:41:54 +00:00
|
|
|
m_partialRebuildRoot = nullptr;
|
2013-08-14 05:27:07 +00:00
|
|
|
m_taggedRoots.clear();
|
|
|
|
m_nextRenderOrder = qMax(m_nextRenderOrder, maxRenderOrder);
|
|
|
|
|
|
|
|
// Add orphaned elements back into the list and then sort it..
|
|
|
|
qsg_addBackOrphanedElements(m_tmpOpaqueElements, m_opaqueRenderList);
|
|
|
|
qsg_addBackOrphanedElements(m_tmpAlphaElements, m_alphaRenderList);
|
|
|
|
|
|
|
|
if (m_opaqueRenderList.size())
|
2013-09-12 09:06:59 +00:00
|
|
|
std::sort(&m_opaqueRenderList.first(), &m_opaqueRenderList.last() + 1, qsg_sort_element_decreasing_order);
|
2013-08-14 05:27:07 +00:00
|
|
|
if (m_alphaRenderList.size())
|
2013-09-12 09:06:59 +00:00
|
|
|
std::sort(&m_alphaRenderList.first(), &m_alphaRenderList.last() + 1, qsg_sort_element_increasing_order);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::buildRenderListsFromScratch()
|
|
|
|
{
|
|
|
|
m_opaqueRenderList.reset();
|
|
|
|
m_alphaRenderList.reset();
|
|
|
|
|
|
|
|
for (int i=0; i<m_opaqueBatches.size(); ++i)
|
|
|
|
invalidateAndRecycleBatch(m_opaqueBatches.at(i));
|
|
|
|
for (int i=0; i<m_alphaBatches.size(); ++i)
|
|
|
|
invalidateAndRecycleBatch(m_alphaBatches.at(i));
|
|
|
|
m_opaqueBatches.reset();
|
|
|
|
m_alphaBatches.reset();
|
|
|
|
|
|
|
|
m_nextRenderOrder = 0;
|
|
|
|
|
|
|
|
buildRenderLists(rootNode());
|
|
|
|
}
|
|
|
|
|
2014-01-28 19:53:01 +00:00
|
|
|
void Renderer::invalidateBatchAndOverlappingRenderOrders(Batch *batch)
|
2013-10-31 21:14:12 +00:00
|
|
|
{
|
2014-01-28 19:53:01 +00:00
|
|
|
Q_ASSERT(batch);
|
|
|
|
Q_ASSERT(batch->first);
|
|
|
|
|
2021-02-12 06:43:22 +00:00
|
|
|
#if defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
|
2014-03-19 10:58:04 +00:00
|
|
|
if (m_renderOrderRebuildLower < 0 || batch->first->order < m_renderOrderRebuildLower)
|
|
|
|
m_renderOrderRebuildLower = batch->first->order;
|
|
|
|
if (m_renderOrderRebuildUpper < 0 || batch->lastOrderInBatch > m_renderOrderRebuildUpper)
|
|
|
|
m_renderOrderRebuildUpper = batch->lastOrderInBatch;
|
|
|
|
|
2021-02-12 06:43:22 +00:00
|
|
|
int first = m_renderOrderRebuildLower;
|
|
|
|
int last = m_renderOrderRebuildUpper;
|
|
|
|
#else
|
|
|
|
int first = batch->first->order;
|
|
|
|
int last = batch->lastOrderInBatch;
|
|
|
|
#endif
|
|
|
|
|
2014-01-28 19:53:01 +00:00
|
|
|
batch->invalidate();
|
|
|
|
|
2013-10-31 21:14:12 +00:00
|
|
|
for (int i=0; i<m_alphaBatches.size(); ++i) {
|
|
|
|
Batch *b = m_alphaBatches.at(i);
|
2014-01-28 19:53:01 +00:00
|
|
|
if (b->first) {
|
|
|
|
int bf = b->first->order;
|
|
|
|
int bl = b->lastOrderInBatch;
|
2021-02-12 06:43:22 +00:00
|
|
|
if (bl > first && bf < last)
|
2014-01-28 19:53:01 +00:00
|
|
|
b->invalidate();
|
|
|
|
}
|
2013-10-31 21:14:12 +00:00
|
|
|
}
|
2014-01-28 19:53:01 +00:00
|
|
|
|
|
|
|
m_rebuild |= BuildBatches;
|
2013-10-31 21:14:12 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
/* Clean up batches by making it a consecutive list of "valid"
|
|
|
|
* batches and moving all invalidated batches to the batches pool.
|
|
|
|
*/
|
|
|
|
void Renderer::cleanupBatches(QDataBuffer<Batch *> *batches) {
|
|
|
|
if (batches->size()) {
|
2014-03-15 04:27:06 +00:00
|
|
|
std::stable_sort(&batches->first(), &batches->last() + 1, qsg_sort_batch_is_valid);
|
2013-08-14 05:27:07 +00:00
|
|
|
int count = 0;
|
|
|
|
while (count < batches->size() && batches->at(count)->first)
|
|
|
|
++count;
|
2013-09-04 06:26:06 +00:00
|
|
|
for (int i=count; i<batches->size(); ++i)
|
2013-08-14 05:27:07 +00:00
|
|
|
invalidateAndRecycleBatch(batches->at(i));
|
|
|
|
batches->resize(count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::prepareOpaqueBatches()
|
|
|
|
{
|
|
|
|
for (int i=m_opaqueRenderList.size() - 1; i >= 0; --i) {
|
|
|
|
Element *ei = m_opaqueRenderList.at(i);
|
2014-03-26 09:05:21 +00:00
|
|
|
if (!ei || ei->batch || ei->node->geometry()->vertexCount() == 0)
|
2013-08-14 05:27:07 +00:00
|
|
|
continue;
|
|
|
|
Batch *batch = newBatch();
|
|
|
|
batch->first = ei;
|
|
|
|
batch->root = ei->root;
|
|
|
|
batch->isOpaque = true;
|
|
|
|
batch->needsUpload = true;
|
|
|
|
batch->positionAttribute = qsg_positionAttribute(ei->node->geometry());
|
|
|
|
|
|
|
|
m_opaqueBatches.add(batch);
|
|
|
|
|
|
|
|
ei->batch = batch;
|
|
|
|
Element *next = ei;
|
|
|
|
|
|
|
|
QSGGeometryNode *gni = ei->node;
|
|
|
|
|
|
|
|
for (int j = i - 1; j >= 0; --j) {
|
|
|
|
Element *ej = m_opaqueRenderList.at(j);
|
|
|
|
if (!ej)
|
|
|
|
continue;
|
|
|
|
if (ej->root != ei->root)
|
|
|
|
break;
|
2014-03-26 09:05:21 +00:00
|
|
|
if (ej->batch || ej->node->geometry()->vertexCount() == 0)
|
2013-08-14 05:27:07 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
QSGGeometryNode *gnj = ej->node;
|
|
|
|
|
|
|
|
if (gni->clipList() == gnj->clipList()
|
|
|
|
&& gni->geometry()->drawingMode() == gnj->geometry()->drawingMode()
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
&& (gni->geometry()->drawingMode() != QSGGeometry::DrawLines || gni->geometry()->lineWidth() == gnj->geometry()->lineWidth())
|
2013-08-14 05:27:07 +00:00
|
|
|
&& gni->geometry()->attributes() == gnj->geometry()->attributes()
|
|
|
|
&& gni->inheritedOpacity() == gnj->inheritedOpacity()
|
|
|
|
&& gni->activeMaterial()->type() == gnj->activeMaterial()->type()
|
|
|
|
&& gni->activeMaterial()->compare(gnj->activeMaterial()) == 0) {
|
|
|
|
ej->batch = batch;
|
|
|
|
next->nextInBatch = ej;
|
|
|
|
next = ej;
|
|
|
|
}
|
|
|
|
}
|
2014-01-28 19:53:01 +00:00
|
|
|
|
|
|
|
batch->lastOrderInBatch = next->order;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Renderer::checkOverlap(int first, int last, const Rect &bounds)
|
|
|
|
{
|
|
|
|
for (int i=first; i<=last; ++i) {
|
|
|
|
Element *e = m_alphaRenderList.at(i);
|
2021-02-12 06:43:22 +00:00
|
|
|
#if defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
|
2013-08-14 05:27:07 +00:00
|
|
|
if (!e || e->batch)
|
2021-02-12 06:43:22 +00:00
|
|
|
#else
|
|
|
|
if (!e)
|
|
|
|
#endif
|
2013-08-14 05:27:07 +00:00
|
|
|
continue;
|
|
|
|
Q_ASSERT(e->boundsComputed);
|
|
|
|
if (e->bounds.intersects(bounds))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* To avoid the O(n^2) checkOverlap check in most cases, we have the
|
|
|
|
* overlapBounds which is the union of all bounding rects to check overlap
|
|
|
|
* for. We know that if it does not overlap, then none of the individual
|
|
|
|
* ones will either. For the typical list case, this results in no calls
|
|
|
|
* to checkOverlap what-so-ever. This also ensures that when all consecutive
|
|
|
|
* items are matching (such as a table of text), we don't build up an
|
|
|
|
* overlap bounds and thus do not require full overlap checks.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Renderer::prepareAlphaBatches()
|
|
|
|
{
|
|
|
|
for (int i=0; i<m_alphaRenderList.size(); ++i) {
|
|
|
|
Element *e = m_alphaRenderList.at(i);
|
|
|
|
if (!e || e->isRenderNode)
|
|
|
|
continue;
|
|
|
|
Q_ASSERT(!e->removed);
|
|
|
|
e->ensureBoundsValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0; i<m_alphaRenderList.size(); ++i) {
|
|
|
|
Element *ei = m_alphaRenderList.at(i);
|
|
|
|
if (!ei || ei->batch)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ei->isRenderNode) {
|
|
|
|
Batch *rnb = newBatch();
|
|
|
|
rnb->first = ei;
|
|
|
|
rnb->root = ei->root;
|
|
|
|
rnb->isOpaque = false;
|
|
|
|
rnb->isRenderNode = true;
|
|
|
|
ei->batch = rnb;
|
|
|
|
m_alphaBatches.add(rnb);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-03-26 09:05:21 +00:00
|
|
|
if (ei->node->geometry()->vertexCount() == 0)
|
|
|
|
continue;
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
Batch *batch = newBatch();
|
|
|
|
batch->first = ei;
|
|
|
|
batch->root = ei->root;
|
|
|
|
batch->isOpaque = false;
|
|
|
|
batch->needsUpload = true;
|
|
|
|
m_alphaBatches.add(batch);
|
|
|
|
ei->batch = batch;
|
|
|
|
|
|
|
|
QSGGeometryNode *gni = ei->node;
|
|
|
|
batch->positionAttribute = qsg_positionAttribute(gni->geometry());
|
|
|
|
|
|
|
|
Rect overlapBounds;
|
|
|
|
overlapBounds.set(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX);
|
|
|
|
|
|
|
|
Element *next = ei;
|
|
|
|
|
|
|
|
for (int j = i + 1; j < m_alphaRenderList.size(); ++j) {
|
|
|
|
Element *ej = m_alphaRenderList.at(j);
|
|
|
|
if (!ej)
|
|
|
|
continue;
|
|
|
|
if (ej->root != ei->root || ej->isRenderNode)
|
|
|
|
break;
|
2021-02-12 06:43:22 +00:00
|
|
|
if (ej->batch) {
|
|
|
|
#if !defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
|
|
|
|
overlapBounds |= ej->bounds;
|
|
|
|
#endif
|
2013-08-14 05:27:07 +00:00
|
|
|
continue;
|
2021-02-12 06:43:22 +00:00
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
QSGGeometryNode *gnj = ej->node;
|
2014-03-26 09:05:21 +00:00
|
|
|
if (gnj->geometry()->vertexCount() == 0)
|
|
|
|
continue;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
if (gni->clipList() == gnj->clipList()
|
|
|
|
&& gni->geometry()->drawingMode() == gnj->geometry()->drawingMode()
|
2021-03-29 11:36:27 +00:00
|
|
|
&& (gni->geometry()->drawingMode() != QSGGeometry::DrawLines
|
|
|
|
|| (gni->geometry()->lineWidth() == gnj->geometry()->lineWidth()
|
|
|
|
// Must not do overlap checks when the line width is not 1,
|
|
|
|
// we have no knowledge how such lines are rasterized.
|
|
|
|
&& gni->geometry()->lineWidth() == 1.0f))
|
2013-08-14 05:27:07 +00:00
|
|
|
&& gni->geometry()->attributes() == gnj->geometry()->attributes()
|
|
|
|
&& gni->inheritedOpacity() == gnj->inheritedOpacity()
|
|
|
|
&& gni->activeMaterial()->type() == gnj->activeMaterial()->type()
|
|
|
|
&& gni->activeMaterial()->compare(gnj->activeMaterial()) == 0) {
|
|
|
|
if (!overlapBounds.intersects(ej->bounds) || !checkOverlap(i+1, j - 1, ej->bounds)) {
|
|
|
|
ej->batch = batch;
|
|
|
|
next->nextInBatch = ej;
|
|
|
|
next = ej;
|
2013-11-15 06:23:04 +00:00
|
|
|
} else {
|
|
|
|
/* When we come across a compatible element which hits an overlap, we
|
|
|
|
* need to stop the batch right away. We cannot add more elements
|
|
|
|
* to the current batch as they will be rendered before the batch that the
|
|
|
|
* current 'ej' will be added to.
|
|
|
|
*/
|
|
|
|
break;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
overlapBounds |= ej->bounds;
|
|
|
|
}
|
|
|
|
}
|
2014-01-28 19:53:01 +00:00
|
|
|
|
|
|
|
batch->lastOrderInBatch = next->order;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
static inline int qsg_fixIndexCount(int iCount, int drawMode)
|
|
|
|
{
|
2015-01-12 12:54:45 +00:00
|
|
|
switch (drawMode) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
case QSGGeometry::DrawTriangleStrip:
|
2015-01-12 12:54:45 +00:00
|
|
|
// Merged triangle strips need to contain degenerate triangles at the beginning and end.
|
|
|
|
// One could save 2 uploaded ushorts here by ditching the padding for the front of the
|
|
|
|
// first and the end of the last, but for simplicity, we simply don't care.
|
|
|
|
// Those extra triangles will be skipped while drawing to preserve the strip's parity
|
|
|
|
// anyhow.
|
|
|
|
return iCount + 2;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
case QSGGeometry::DrawLines:
|
2015-01-12 12:54:45 +00:00
|
|
|
// For lines we drop the last vertex if the number of vertices is uneven.
|
|
|
|
return iCount - (iCount % 2);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
case QSGGeometry::DrawTriangles:
|
2015-01-12 12:54:45 +00:00
|
|
|
// For triangles we drop trailing vertices until the result is divisible by 3.
|
|
|
|
return iCount - (iCount % 3);
|
|
|
|
default:
|
|
|
|
return iCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
/* These parameters warrant some explanation...
|
|
|
|
*
|
|
|
|
* vaOffset: The byte offset into the vertex data to the location of the
|
|
|
|
* 2D float point vertex attributes.
|
|
|
|
*
|
|
|
|
* vertexData: destination where the geometry's vertex data should go
|
|
|
|
*
|
|
|
|
* zData: destination of geometries injected Z positioning
|
|
|
|
*
|
|
|
|
* indexData: destination of the indices for this element
|
|
|
|
*
|
|
|
|
* iBase: The starting index for this element in the batch
|
|
|
|
*/
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
void Renderer::uploadMergedElement(Element *e, int vaOffset, char **vertexData, char **zData, char **indexData, void *iBasePtr, int *indexCount)
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
2014-09-16 22:20:53 +00:00
|
|
|
if (Q_UNLIKELY(debug_upload())) qDebug() << " - uploading element:" << e << e->node << (void *) *vertexData << (qintptr) (*zData - *vertexData) << (qintptr) (*indexData - *vertexData);
|
2013-08-14 05:27:07 +00:00
|
|
|
QSGGeometry *g = e->node->geometry();
|
|
|
|
|
|
|
|
const QMatrix4x4 &localx = *e->node->matrix();
|
2020-05-28 11:02:17 +00:00
|
|
|
const float *localxdata = localx.constData();
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
const int vCount = g->vertexCount();
|
|
|
|
const int vSize = g->sizeOfVertex();
|
|
|
|
memcpy(*vertexData, g->vertexData(), vSize * vCount);
|
|
|
|
|
|
|
|
// apply vertex transform..
|
|
|
|
char *vdata = *vertexData + vaOffset;
|
2020-05-28 11:02:17 +00:00
|
|
|
if (localx.flags() == QMatrix4x4::Translation) {
|
2013-08-14 05:27:07 +00:00
|
|
|
for (int i=0; i<vCount; ++i) {
|
|
|
|
Pt *p = (Pt *) vdata;
|
2020-05-28 11:02:17 +00:00
|
|
|
p->x += localxdata[12];
|
|
|
|
p->y += localxdata[13];
|
2013-08-14 05:27:07 +00:00
|
|
|
vdata += vSize;
|
|
|
|
}
|
2020-05-28 11:02:17 +00:00
|
|
|
} else if (localx.flags() > QMatrix4x4::Translation) {
|
2013-08-14 05:27:07 +00:00
|
|
|
for (int i=0; i<vCount; ++i) {
|
|
|
|
((Pt *) vdata)->map(localx);
|
|
|
|
vdata += vSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
if (useDepthBuffer()) {
|
2014-01-21 12:28:53 +00:00
|
|
|
float *vzorder = (float *) *zData;
|
|
|
|
float zorder = 1.0f - e->order * m_zRange;
|
|
|
|
for (int i=0; i<vCount; ++i)
|
|
|
|
vzorder[i] = zorder;
|
|
|
|
*zData += vCount * sizeof(float);
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
int iCount = g->indexCount();
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (m_uint32IndexForRhi) {
|
|
|
|
// can only happen when using the rhi
|
|
|
|
quint32 *iBase = (quint32 *) iBasePtr;
|
|
|
|
quint32 *indices = (quint32 *) *indexData;
|
|
|
|
if (iCount == 0) {
|
|
|
|
iCount = vCount;
|
|
|
|
if (g->drawingMode() == QSGGeometry::DrawTriangleStrip)
|
|
|
|
*indices++ = *iBase;
|
|
|
|
else
|
|
|
|
iCount = qsg_fixIndexCount(iCount, g->drawingMode());
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
for (int i=0; i<iCount; ++i)
|
|
|
|
indices[i] = *iBase + i;
|
|
|
|
} else {
|
|
|
|
// source index data in QSGGeometry is always ushort (we would not merge otherwise)
|
|
|
|
const quint16 *srcIndices = g->indexDataAsUShort();
|
|
|
|
if (g->drawingMode() == QSGGeometry::DrawTriangleStrip)
|
|
|
|
*indices++ = *iBase + srcIndices[0];
|
|
|
|
else
|
|
|
|
iCount = qsg_fixIndexCount(iCount, g->drawingMode());
|
2015-01-12 12:54:45 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
for (int i=0; i<iCount; ++i)
|
|
|
|
indices[i] = *iBase + srcIndices[i];
|
|
|
|
}
|
|
|
|
if (g->drawingMode() == QSGGeometry::DrawTriangleStrip) {
|
|
|
|
indices[iCount] = indices[iCount - 1];
|
|
|
|
iCount += 2;
|
|
|
|
}
|
|
|
|
*iBase += vCount;
|
2013-08-14 05:27:07 +00:00
|
|
|
} else {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
// normally batching is only done for ushort index data
|
|
|
|
quint16 *iBase = (quint16 *) iBasePtr;
|
|
|
|
quint16 *indices = (quint16 *) *indexData;
|
|
|
|
if (iCount == 0) {
|
|
|
|
iCount = vCount;
|
|
|
|
if (g->drawingMode() == QSGGeometry::DrawTriangleStrip)
|
|
|
|
*indices++ = *iBase;
|
|
|
|
else
|
|
|
|
iCount = qsg_fixIndexCount(iCount, g->drawingMode());
|
2015-01-12 12:54:45 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
for (int i=0; i<iCount; ++i)
|
|
|
|
indices[i] = *iBase + i;
|
|
|
|
} else {
|
|
|
|
const quint16 *srcIndices = g->indexDataAsUShort();
|
|
|
|
if (g->drawingMode() == QSGGeometry::DrawTriangleStrip)
|
|
|
|
*indices++ = *iBase + srcIndices[0];
|
|
|
|
else
|
|
|
|
iCount = qsg_fixIndexCount(iCount, g->drawingMode());
|
|
|
|
|
|
|
|
for (int i=0; i<iCount; ++i)
|
|
|
|
indices[i] = *iBase + srcIndices[i];
|
|
|
|
}
|
|
|
|
if (g->drawingMode() == QSGGeometry::DrawTriangleStrip) {
|
|
|
|
indices[iCount] = indices[iCount - 1];
|
|
|
|
iCount += 2;
|
|
|
|
}
|
|
|
|
*iBase += vCount;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*vertexData += vCount * vSize;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
*indexData += iCount * mergedIndexElemSize();
|
2013-08-14 05:27:07 +00:00
|
|
|
*indexCount += iCount;
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:17:52 +00:00
|
|
|
QMatrix4x4 qsg_matrixForRoot(Node *node)
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
|
|
|
if (node->type() == QSGNode::TransformNodeType)
|
|
|
|
return static_cast<QSGTransformNode *>(node->sgNode)->combinedMatrix();
|
|
|
|
Q_ASSERT(node->type() == QSGNode::ClipNodeType);
|
|
|
|
QSGClipNode *c = static_cast<QSGClipNode *>(node->sgNode);
|
|
|
|
return *c->matrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::uploadBatch(Batch *b)
|
|
|
|
{
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
// Early out if nothing has changed in this batch..
|
|
|
|
if (!b->needsUpload) {
|
|
|
|
if (Q_UNLIKELY(debug_upload())) qDebug() << " Batch:" << b << "already uploaded...";
|
|
|
|
return;
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (!b->first) {
|
|
|
|
if (Q_UNLIKELY(debug_upload())) qDebug() << " Batch:" << b << "is invalid...";
|
|
|
|
return;
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (b->isRenderNode) {
|
|
|
|
if (Q_UNLIKELY(debug_upload())) qDebug() << " Batch: " << b << "is a render node...";
|
|
|
|
return;
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
// Figure out if we can merge or not, if not, then just render the batch as is..
|
|
|
|
Q_ASSERT(b->first);
|
|
|
|
Q_ASSERT(b->first->node);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
QSGGeometryNode *gn = b->first->node;
|
|
|
|
QSGGeometry *g = gn->geometry();
|
|
|
|
QSGMaterial::Flags flags = gn->activeMaterial()->flags();
|
|
|
|
bool canMerge = (g->drawingMode() == QSGGeometry::DrawTriangles || g->drawingMode() == QSGGeometry::DrawTriangleStrip ||
|
|
|
|
g->drawingMode() == QSGGeometry::DrawLines || g->drawingMode() == QSGGeometry::DrawPoints)
|
|
|
|
&& b->positionAttribute >= 0
|
|
|
|
&& g->indexType() == QSGGeometry::UnsignedShortType
|
2021-08-11 07:59:59 +00:00
|
|
|
&& (flags & (QSGMaterial::NoBatching | QSGMaterial_FullMatrix)) == 0
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
&& ((flags & QSGMaterial::RequiresFullMatrixExceptTranslate) == 0 || b->isTranslateOnlyToRoot())
|
|
|
|
&& b->isSafeToBatch();
|
|
|
|
|
|
|
|
b->merged = canMerge;
|
|
|
|
|
|
|
|
// Figure out how much memory we need...
|
|
|
|
b->vertexCount = 0;
|
|
|
|
b->indexCount = 0;
|
|
|
|
int unmergedIndexSize = 0;
|
|
|
|
Element *e = b->first;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
while (e) {
|
|
|
|
QSGGeometry *eg = e->node->geometry();
|
|
|
|
b->vertexCount += eg->vertexCount();
|
|
|
|
int iCount = eg->indexCount();
|
|
|
|
if (b->merged) {
|
|
|
|
if (iCount == 0)
|
|
|
|
iCount = eg->vertexCount();
|
|
|
|
iCount = qsg_fixIndexCount(iCount, g->drawingMode());
|
|
|
|
} else {
|
|
|
|
const int effectiveIndexSize = m_uint32IndexForRhi ? sizeof(quint32) : eg->sizeOfIndex();
|
|
|
|
unmergedIndexSize += iCount * effectiveIndexSize;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
b->indexCount += iCount;
|
|
|
|
e = e->nextInBatch;
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
// Abort if there are no vertices in this batch.. We abort this late as
|
|
|
|
// this is a broken usecase which we do not care to optimize for...
|
|
|
|
if (b->vertexCount == 0 || (b->merged && b->indexCount == 0))
|
|
|
|
return;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
/* Allocate memory for this batch. Merged batches are divided into three separate blocks
|
2013-08-14 05:27:07 +00:00
|
|
|
1. Vertex data for all elements, as they were in the QSGGeometry object, but
|
|
|
|
with the tranform relative to this batch's root applied. The vertex data
|
|
|
|
is otherwise unmodified.
|
|
|
|
2. Z data for all elements, derived from each elements "render order".
|
|
|
|
This is present for merged data only.
|
|
|
|
3. Indices for all elements, as they were in the QSGGeometry object, but
|
|
|
|
adjusted so that each index matches its.
|
|
|
|
And for TRIANGLE_STRIPs, we need to insert degenerate between each
|
|
|
|
primitive. These are unsigned shorts for merged and arbitrary for
|
|
|
|
non-merged.
|
|
|
|
*/
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
int bufferSize = b->vertexCount * g->sizeOfVertex();
|
|
|
|
int ibufferSize = 0;
|
|
|
|
if (b->merged) {
|
|
|
|
ibufferSize = b->indexCount * mergedIndexElemSize();
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
if (useDepthBuffer())
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
bufferSize += b->vertexCount * sizeof(float);
|
|
|
|
} else {
|
|
|
|
ibufferSize = unmergedIndexSize;
|
|
|
|
}
|
2014-01-05 19:36:13 +00:00
|
|
|
|
2022-02-07 11:52:33 +00:00
|
|
|
map(&b->ibo, ibufferSize, true);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
map(&b->vbo, bufferSize);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (Q_UNLIKELY(debug_upload())) qDebug() << " - batch" << b << " first:" << b->first << " root:"
|
|
|
|
<< b->root << " merged:" << b->merged << " positionAttribute" << b->positionAttribute
|
2020-05-06 12:16:05 +00:00
|
|
|
<< " vbo:" << b->vbo.buf << ":" << b->vbo.size;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (b->merged) {
|
|
|
|
char *vertexData = b->vbo.data;
|
|
|
|
char *zData = vertexData + b->vertexCount * g->sizeOfVertex();
|
2022-02-07 11:52:33 +00:00
|
|
|
char *indexData = b->ibo.data;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
quint16 iOffset16 = 0;
|
|
|
|
quint32 iOffset32 = 0;
|
|
|
|
e = b->first;
|
|
|
|
uint verticesInSet = 0;
|
|
|
|
// Start a new set already after 65534 vertices because 0xFFFF may be
|
|
|
|
// used for an always-on primitive restart with some apis (adapt for
|
|
|
|
// uint32 indices as appropriate).
|
|
|
|
const uint verticesInSetLimit = m_uint32IndexForRhi ? 0xfffffffe : 0xfffe;
|
|
|
|
int indicesInSet = 0;
|
|
|
|
b->drawSets.reset();
|
2022-02-07 11:52:33 +00:00
|
|
|
int drawSetIndices = 0;
|
|
|
|
const char *indexBase = b->ibo.data;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
b->drawSets << DrawSet(0, zData - vertexData, drawSetIndices);
|
|
|
|
while (e) {
|
|
|
|
verticesInSet += e->node->geometry()->vertexCount();
|
|
|
|
if (verticesInSet > verticesInSetLimit) {
|
|
|
|
b->drawSets.last().indexCount = indicesInSet;
|
|
|
|
if (g->drawingMode() == QSGGeometry::DrawTriangleStrip) {
|
|
|
|
b->drawSets.last().indices += 1 * mergedIndexElemSize();
|
|
|
|
b->drawSets.last().indexCount -= 2;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
drawSetIndices = indexData - indexBase;
|
|
|
|
b->drawSets << DrawSet(vertexData - b->vbo.data,
|
|
|
|
zData - b->vbo.data,
|
|
|
|
drawSetIndices);
|
|
|
|
iOffset16 = 0;
|
|
|
|
iOffset32 = 0;
|
|
|
|
verticesInSet = e->node->geometry()->vertexCount();
|
|
|
|
indicesInSet = 0;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
void *iBasePtr = &iOffset16;
|
|
|
|
if (m_uint32IndexForRhi)
|
|
|
|
iBasePtr = &iOffset32;
|
|
|
|
uploadMergedElement(e, b->positionAttribute, &vertexData, &zData, &indexData, iBasePtr, &indicesInSet);
|
|
|
|
e = e->nextInBatch;
|
|
|
|
}
|
|
|
|
b->drawSets.last().indexCount = indicesInSet;
|
|
|
|
// We skip the very first and very last degenerate triangles since they aren't needed
|
|
|
|
// and the first one would reverse the vertex ordering of the merged strips.
|
|
|
|
if (g->drawingMode() == QSGGeometry::DrawTriangleStrip) {
|
|
|
|
b->drawSets.last().indices += 1 * mergedIndexElemSize();
|
|
|
|
b->drawSets.last().indexCount -= 2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
char *vboData = b->vbo.data;
|
2022-02-07 11:52:33 +00:00
|
|
|
char *iboData = b->ibo.data;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
Element *e = b->first;
|
|
|
|
while (e) {
|
|
|
|
QSGGeometry *g = e->node->geometry();
|
|
|
|
int vbs = g->vertexCount() * g->sizeOfVertex();
|
|
|
|
memcpy(vboData, g->vertexData(), vbs);
|
|
|
|
vboData = vboData + vbs;
|
|
|
|
const int indexCount = g->indexCount();
|
|
|
|
if (indexCount) {
|
2020-05-06 12:16:05 +00:00
|
|
|
const int effectiveIndexSize = m_uint32IndexForRhi ? sizeof(quint32) : g->sizeOfIndex();
|
|
|
|
const int ibs = indexCount * effectiveIndexSize;
|
|
|
|
if (g->sizeOfIndex() == effectiveIndexSize) {
|
2013-08-14 05:27:07 +00:00
|
|
|
memcpy(iboData, g->indexData(), ibs);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
} else {
|
2020-05-06 12:16:05 +00:00
|
|
|
if (g->sizeOfIndex() == sizeof(quint16) && effectiveIndexSize == sizeof(quint32)) {
|
|
|
|
quint16 *src = g->indexDataAsUShort();
|
|
|
|
quint32 *dst = (quint32 *) iboData;
|
|
|
|
for (int i = 0; i < indexCount; ++i)
|
|
|
|
dst[i] = src[i];
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
} else {
|
2020-05-06 12:16:05 +00:00
|
|
|
Q_ASSERT_X(false, "uploadBatch (unmerged)", "uint index with ushort effective index - cannot happen");
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
2020-05-06 12:16:05 +00:00
|
|
|
iboData += ibs;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
e = e->nextInBatch;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
2014-10-22 22:34:09 +00:00
|
|
|
#ifndef QT_NO_DEBUG_OUTPUT
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (Q_UNLIKELY(debug_upload())) {
|
|
|
|
const char *vd = b->vbo.data;
|
|
|
|
qDebug() << " -- Vertex Data, count:" << b->vertexCount << " - " << g->sizeOfVertex() << "bytes/vertex";
|
|
|
|
for (int i=0; i<b->vertexCount; ++i) {
|
|
|
|
QDebug dump = qDebug().nospace();
|
|
|
|
dump << " --- " << i << ": ";
|
|
|
|
int offset = 0;
|
|
|
|
for (int a=0; a<g->attributeCount(); ++a) {
|
|
|
|
const QSGGeometry::Attribute &attr = g->attributes()[a];
|
|
|
|
dump << attr.position << ":(" << attr.tupleSize << ",";
|
|
|
|
if (attr.type == QSGGeometry::FloatType) {
|
|
|
|
dump << "float ";
|
|
|
|
if (attr.isVertexCoordinate)
|
|
|
|
dump << "* ";
|
|
|
|
for (int t=0; t<attr.tupleSize; ++t)
|
|
|
|
dump << *(const float *)(vd + offset + t * sizeof(float)) << " ";
|
|
|
|
} else if (attr.type == QSGGeometry::UnsignedByteType) {
|
|
|
|
dump << "ubyte ";
|
|
|
|
for (int t=0; t<attr.tupleSize; ++t)
|
|
|
|
dump << *(const unsigned char *)(vd + offset + t * sizeof(unsigned char)) << " ";
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
dump << ") ";
|
|
|
|
offset += attr.tupleSize * size_of_type(attr.type);
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
if (b->merged && useDepthBuffer()) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
float zorder = ((float*)(b->vbo.data + b->vertexCount * g->sizeOfVertex()))[i];
|
|
|
|
dump << " Z:(" << zorder << ")";
|
|
|
|
}
|
|
|
|
vd += g->sizeOfVertex();
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (!b->drawSets.isEmpty()) {
|
|
|
|
if (m_uint32IndexForRhi) {
|
2022-02-07 11:52:33 +00:00
|
|
|
const quint32 *id = (const quint32 *) b->ibo.data;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
QDebug iDump = qDebug();
|
|
|
|
iDump << " -- Index Data, count:" << b->indexCount;
|
|
|
|
for (int i=0; i<b->indexCount; ++i) {
|
|
|
|
if ((i % 24) == 0)
|
2019-07-08 11:01:56 +00:00
|
|
|
iDump << Qt::endl << " --- ";
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
iDump << id[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2022-02-07 11:52:33 +00:00
|
|
|
const quint16 *id = (const quint16 *) b->ibo.data;
|
2015-09-24 17:55:39 +00:00
|
|
|
{
|
|
|
|
QDebug iDump = qDebug();
|
|
|
|
iDump << " -- Index Data, count:" << b->indexCount;
|
|
|
|
for (int i=0; i<b->indexCount; ++i) {
|
|
|
|
if ((i % 24) == 0)
|
2019-07-08 09:36:14 +00:00
|
|
|
iDump << Qt::endl << " --- ";
|
2015-09-24 17:55:39 +00:00
|
|
|
iDump << id[i];
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
for (int i=0; i<b->drawSets.size(); ++i) {
|
|
|
|
const DrawSet &s = b->drawSets.at(i);
|
|
|
|
qDebug() << " -- DrawSet: indexCount:" << s.indexCount << " vertices:" << s.vertices << " z:" << s.zorders << " indices:" << s.indices;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
2014-10-22 22:34:09 +00:00
|
|
|
#endif // QT_NO_DEBUG_OUTPUT
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
unmap(&b->vbo);
|
2022-02-07 11:52:33 +00:00
|
|
|
unmap(&b->ibo, true);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (Q_UNLIKELY(debug_upload())) qDebug() << " --- vertex/index buffers unmapped, batch upload completed...";
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
b->needsUpload = false;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (Q_UNLIKELY(debug_render()))
|
|
|
|
b->uploadedThisFrame = true;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
void Renderer::applyClipStateToGraphicsState()
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
m_gstate.usesScissor = (m_currentClipState.type & ClipState::ScissorClip);
|
|
|
|
m_gstate.stencilTest = (m_currentClipState.type & ClipState::StencilClip);
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
QRhiGraphicsPipeline *Renderer::buildStencilPipeline(const Batch *batch, bool firstStencilClipInBatch)
|
|
|
|
{
|
|
|
|
QRhiGraphicsPipeline *ps = m_rhi->newGraphicsPipeline();
|
|
|
|
ps->setFlags(QRhiGraphicsPipeline::UsesStencilRef);
|
|
|
|
QRhiGraphicsPipeline::TargetBlend blend;
|
2019-11-25 10:49:14 +00:00
|
|
|
blend.colorWrite = {};
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
ps->setTargetBlends({ blend });
|
2022-04-19 11:01:42 +00:00
|
|
|
ps->setSampleCount(renderTarget().rt->sampleCount());
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
ps->setStencilTest(true);
|
|
|
|
QRhiGraphicsPipeline::StencilOpState stencilOp;
|
|
|
|
if (firstStencilClipInBatch) {
|
|
|
|
stencilOp.compareOp = QRhiGraphicsPipeline::Always;
|
|
|
|
stencilOp.failOp = QRhiGraphicsPipeline::Keep;
|
|
|
|
stencilOp.depthFailOp = QRhiGraphicsPipeline::Keep;
|
|
|
|
stencilOp.passOp = QRhiGraphicsPipeline::Replace;
|
|
|
|
} else {
|
|
|
|
stencilOp.compareOp = QRhiGraphicsPipeline::Equal;
|
|
|
|
stencilOp.failOp = QRhiGraphicsPipeline::Keep;
|
|
|
|
stencilOp.depthFailOp = QRhiGraphicsPipeline::Keep;
|
|
|
|
stencilOp.passOp = QRhiGraphicsPipeline::IncrementAndClamp;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
ps->setStencilFront(stencilOp);
|
|
|
|
ps->setStencilBack(stencilOp);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
ps->setTopology(m_stencilClipCommon.topology);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
ps->setShaderStages({ QRhiGraphicsShaderStage(QRhiGraphicsShaderStage::Vertex, m_stencilClipCommon.vs),
|
|
|
|
QRhiGraphicsShaderStage(QRhiGraphicsShaderStage::Fragment, m_stencilClipCommon.fs) });
|
|
|
|
ps->setVertexInputLayout(m_stencilClipCommon.inputLayout);
|
|
|
|
ps->setShaderResourceBindings(batch->stencilClipState.srb); // use something, it just needs to be layout-compatible
|
|
|
|
ps->setRenderPassDescriptor(renderPassDescriptor());
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2020-05-27 15:54:41 +00:00
|
|
|
if (!ps->create()) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
qWarning("Failed to build stencil clip pipeline");
|
|
|
|
delete ps;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
return ps;
|
|
|
|
}
|
2013-10-30 13:09:18 +00:00
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
void Renderer::updateClipState(const QSGClipNode *clipList, Batch *batch)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
// Note: No use of the clip-related speparate m_current* vars is allowed
|
|
|
|
// here. All stored in batch->clipState instead. To collect state during
|
2019-08-07 13:27:24 +00:00
|
|
|
// the prepare steps, m_currentClipState is used. It should not be used in
|
|
|
|
// the render steps afterwards.
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
// The stenciling logic is slightly different from Qt 5's direct OpenGL version
|
|
|
|
// as we cannot just randomly clear the stencil buffer. We now put all clip
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
// shapes into the stencil buffer for all batches in the frame. This means
|
|
|
|
// that the number of total clips in a scene is reduced (since the stencil
|
|
|
|
// value cannot exceed 255) but we do not need any clears inbetween.
|
|
|
|
|
|
|
|
Q_ASSERT(m_rhi);
|
|
|
|
batch->stencilClipState.updateStencilBuffer = false;
|
|
|
|
if (clipList == m_currentClipState.clipList || Q_UNLIKELY(debug_noclip())) {
|
|
|
|
applyClipStateToGraphicsState();
|
|
|
|
batch->clipState = m_currentClipState;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClipState::ClipType clipType = ClipState::NoClip;
|
|
|
|
QRect scissorRect;
|
|
|
|
QVarLengthArray<const QSGClipNode *, 4> stencilClipNodes;
|
|
|
|
const QSGClipNode *clip = clipList;
|
|
|
|
|
|
|
|
batch->stencilClipState.drawCalls.reset();
|
2022-07-08 08:15:58 +00:00
|
|
|
quint32 totalVSize = 0;
|
|
|
|
quint32 totalISize = 0;
|
|
|
|
quint32 totalUSize = 0;
|
|
|
|
const quint32 StencilClipUbufSize = 64;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
while (clip) {
|
|
|
|
QMatrix4x4 m = m_current_projection_matrix_native_ndc;
|
|
|
|
if (clip->matrix())
|
|
|
|
m *= *clip->matrix();
|
|
|
|
|
|
|
|
bool isRectangleWithNoPerspective = clip->isRectangular()
|
|
|
|
&& qFuzzyIsNull(m(3, 0)) && qFuzzyIsNull(m(3, 1));
|
|
|
|
bool noRotate = qFuzzyIsNull(m(0, 1)) && qFuzzyIsNull(m(1, 0));
|
|
|
|
bool isRotate90 = qFuzzyIsNull(m(0, 0)) && qFuzzyIsNull(m(1, 1));
|
|
|
|
|
|
|
|
if (isRectangleWithNoPerspective && (noRotate || isRotate90)) {
|
|
|
|
QRectF bbox = clip->clipRect();
|
|
|
|
qreal invW = 1 / m(3, 3);
|
|
|
|
qreal fx1, fy1, fx2, fy2;
|
|
|
|
if (noRotate) {
|
|
|
|
fx1 = (bbox.left() * m(0, 0) + m(0, 3)) * invW;
|
|
|
|
fy1 = (bbox.bottom() * m(1, 1) + m(1, 3)) * invW;
|
|
|
|
fx2 = (bbox.right() * m(0, 0) + m(0, 3)) * invW;
|
|
|
|
fy2 = (bbox.top() * m(1, 1) + m(1, 3)) * invW;
|
|
|
|
} else {
|
|
|
|
Q_ASSERT(isRotate90);
|
|
|
|
fx1 = (bbox.bottom() * m(0, 1) + m(0, 3)) * invW;
|
|
|
|
fy1 = (bbox.left() * m(1, 0) + m(1, 3)) * invW;
|
|
|
|
fx2 = (bbox.top() * m(0, 1) + m(0, 3)) * invW;
|
|
|
|
fy2 = (bbox.right() * m(1, 0) + m(1, 3)) * invW;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fx1 > fx2)
|
|
|
|
qSwap(fx1, fx2);
|
|
|
|
if (fy1 > fy2)
|
|
|
|
qSwap(fy1, fy2);
|
|
|
|
|
|
|
|
QRect deviceRect = this->deviceRect();
|
|
|
|
|
2020-06-16 15:03:47 +00:00
|
|
|
qint32 ix1 = qRound((fx1 + 1) * deviceRect.width() * qreal(0.5));
|
|
|
|
qint32 iy1 = qRound((fy1 + 1) * deviceRect.height() * qreal(0.5));
|
|
|
|
qint32 ix2 = qRound((fx2 + 1) * deviceRect.width() * qreal(0.5));
|
|
|
|
qint32 iy2 = qRound((fy2 + 1) * deviceRect.height() * qreal(0.5));
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
if (!(clipType & ClipState::ScissorClip)) {
|
|
|
|
clipType |= ClipState::ScissorClip;
|
|
|
|
scissorRect = QRect(ix1, iy1, ix2 - ix1, iy2 - iy1);
|
|
|
|
} else {
|
|
|
|
scissorRect &= QRect(ix1, iy1, ix2 - ix1, iy2 - iy1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
clipType |= ClipState::StencilClip;
|
|
|
|
|
|
|
|
const QSGGeometry *g = clip->geometry();
|
|
|
|
Q_ASSERT(g->attributeCount() > 0);
|
|
|
|
|
|
|
|
const int vertexByteSize = g->sizeOfVertex() * g->vertexCount();
|
|
|
|
// the 4 byte alignment may not actually be needed here
|
2022-07-08 08:15:58 +00:00
|
|
|
totalVSize = aligned(totalVSize, 4u) + vertexByteSize;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (g->indexCount()) {
|
|
|
|
const int indexByteSize = g->sizeOfIndex() * g->indexCount();
|
|
|
|
// so no need to worry about NonFourAlignedEffectiveIndexBufferOffset
|
2022-07-08 08:15:58 +00:00
|
|
|
totalISize = aligned(totalISize, 4u) + indexByteSize;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
// ubuf start offsets must be aligned (typically to 256 bytes)
|
|
|
|
totalUSize = aligned(totalUSize, m_ubufAlignment) + StencilClipUbufSize;
|
|
|
|
|
|
|
|
stencilClipNodes.append(clip);
|
|
|
|
}
|
|
|
|
|
|
|
|
clip = clip->clipList();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clipType & ClipState::StencilClip) {
|
|
|
|
bool rebuildVBuf = false;
|
|
|
|
if (!batch->stencilClipState.vbuf) {
|
|
|
|
batch->stencilClipState.vbuf = m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::VertexBuffer, totalVSize);
|
|
|
|
rebuildVBuf = true;
|
|
|
|
} else if (batch->stencilClipState.vbuf->size() < totalVSize) {
|
|
|
|
batch->stencilClipState.vbuf->setSize(totalVSize);
|
|
|
|
rebuildVBuf = true;
|
|
|
|
}
|
|
|
|
if (rebuildVBuf) {
|
2020-05-27 15:54:41 +00:00
|
|
|
if (!batch->stencilClipState.vbuf->create()) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
qWarning("Failed to build stencil clip vertex buffer");
|
|
|
|
delete batch->stencilClipState.vbuf;
|
|
|
|
batch->stencilClipState.vbuf = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totalISize) {
|
|
|
|
bool rebuildIBuf = false;
|
|
|
|
if (!batch->stencilClipState.ibuf) {
|
|
|
|
batch->stencilClipState.ibuf = m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::IndexBuffer, totalISize);
|
|
|
|
rebuildIBuf = true;
|
|
|
|
} else if (batch->stencilClipState.ibuf->size() < totalISize) {
|
|
|
|
batch->stencilClipState.ibuf->setSize(totalISize);
|
|
|
|
rebuildIBuf = true;
|
|
|
|
}
|
|
|
|
if (rebuildIBuf) {
|
2020-05-27 15:54:41 +00:00
|
|
|
if (!batch->stencilClipState.ibuf->create()) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
qWarning("Failed to build stencil clip index buffer");
|
|
|
|
delete batch->stencilClipState.ibuf;
|
|
|
|
batch->stencilClipState.ibuf = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool rebuildUBuf = false;
|
|
|
|
if (!batch->stencilClipState.ubuf) {
|
|
|
|
batch->stencilClipState.ubuf = m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, totalUSize);
|
|
|
|
rebuildUBuf = true;
|
|
|
|
} else if (batch->stencilClipState.ubuf->size() < totalUSize) {
|
|
|
|
batch->stencilClipState.ubuf->setSize(totalUSize);
|
|
|
|
rebuildUBuf = true;
|
|
|
|
}
|
|
|
|
if (rebuildUBuf) {
|
2020-05-27 15:54:41 +00:00
|
|
|
if (!batch->stencilClipState.ubuf->create()) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
qWarning("Failed to build stencil clip uniform buffer");
|
|
|
|
delete batch->stencilClipState.ubuf;
|
|
|
|
batch->stencilClipState.ubuf = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!batch->stencilClipState.srb) {
|
|
|
|
batch->stencilClipState.srb = m_rhi->newShaderResourceBindings();
|
|
|
|
const QRhiShaderResourceBinding ubufBinding = QRhiShaderResourceBinding::uniformBufferWithDynamicOffset(
|
|
|
|
0, QRhiShaderResourceBinding::VertexStage, batch->stencilClipState.ubuf, StencilClipUbufSize);
|
|
|
|
batch->stencilClipState.srb->setBindings({ ubufBinding });
|
2020-05-27 15:54:41 +00:00
|
|
|
if (!batch->stencilClipState.srb->create()) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
qWarning("Failed to build stencil clip srb");
|
|
|
|
delete batch->stencilClipState.srb;
|
|
|
|
batch->stencilClipState.srb = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-08 08:15:58 +00:00
|
|
|
quint32 vOffset = 0;
|
|
|
|
quint32 iOffset = 0;
|
|
|
|
quint32 uOffset = 0;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
for (const QSGClipNode *clip : stencilClipNodes) {
|
|
|
|
const QSGGeometry *g = clip->geometry();
|
|
|
|
const QSGGeometry::Attribute *a = g->attributes();
|
|
|
|
StencilClipState::StencilDrawCall drawCall;
|
|
|
|
const bool firstStencilClipInBatch = batch->stencilClipState.drawCalls.isEmpty();
|
|
|
|
|
|
|
|
if (firstStencilClipInBatch) {
|
|
|
|
m_stencilClipCommon.inputLayout.setBindings({ QRhiVertexInputBinding(g->sizeOfVertex()) });
|
2019-07-31 13:17:52 +00:00
|
|
|
m_stencilClipCommon.inputLayout.setAttributes({ QRhiVertexInputAttribute(0, 0, qsg_vertexInputFormat(*a), 0) });
|
|
|
|
m_stencilClipCommon.topology = qsg_topology(g->drawingMode());
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
else {
|
2019-07-31 13:17:52 +00:00
|
|
|
if (qsg_topology(g->drawingMode()) != m_stencilClipCommon.topology)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
qWarning("updateClipState: Clip list entries have different primitive topologies, this is not currently supported.");
|
2019-10-07 07:33:50 +00:00
|
|
|
if (qsg_vertexInputFormat(*a) != m_stencilClipCommon.inputLayout.cbeginAttributes()->format())
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
qWarning("updateClipState: Clip list entries have different vertex input layouts, this is must not happen.");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-07-08 08:15:58 +00:00
|
|
|
drawCall.vbufOffset = aligned(vOffset, 4u);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
const int vertexByteSize = g->sizeOfVertex() * g->vertexCount();
|
2019-08-01 20:02:06 +00:00
|
|
|
vOffset = drawCall.vbufOffset + vertexByteSize;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
int indexByteSize = 0;
|
|
|
|
if (g->indexCount()) {
|
2022-07-08 08:15:58 +00:00
|
|
|
drawCall.ibufOffset = aligned(iOffset, 4u);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
indexByteSize = g->sizeOfIndex() * g->indexCount();
|
2019-08-01 20:02:06 +00:00
|
|
|
iOffset = drawCall.ibufOffset + indexByteSize;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
drawCall.ubufOffset = aligned(uOffset, m_ubufAlignment);
|
2019-08-01 20:02:06 +00:00
|
|
|
uOffset = drawCall.ubufOffset + StencilClipUbufSize;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
QMatrix4x4 matrixYUpNDC = m_current_projection_matrix;
|
|
|
|
if (clip->matrix())
|
|
|
|
matrixYUpNDC *= *clip->matrix();
|
|
|
|
|
|
|
|
m_resourceUpdates->updateDynamicBuffer(batch->stencilClipState.ubuf, drawCall.ubufOffset, 64, matrixYUpNDC.constData());
|
|
|
|
m_resourceUpdates->updateDynamicBuffer(batch->stencilClipState.vbuf, drawCall.vbufOffset, vertexByteSize, g->vertexData());
|
|
|
|
if (indexByteSize)
|
|
|
|
m_resourceUpdates->updateDynamicBuffer(batch->stencilClipState.ibuf, drawCall.ibufOffset, indexByteSize, g->indexData());
|
|
|
|
|
|
|
|
// stencil ref goes 1, 1, 2, 3, 4, ..., N for the clips in the first batch,
|
|
|
|
// then N+1, N+1, N+2, N+3, ... for the next batch,
|
|
|
|
// and so on.
|
|
|
|
// Note the different stencilOp for the first and the subsequent clips.
|
|
|
|
drawCall.stencilRef = firstStencilClipInBatch ? m_currentClipState.stencilRef + 1 : m_currentClipState.stencilRef;
|
|
|
|
m_currentClipState.stencilRef += 1;
|
|
|
|
|
|
|
|
drawCall.vertexCount = g->vertexCount();
|
|
|
|
drawCall.indexCount = g->indexCount();
|
2019-07-31 13:17:52 +00:00
|
|
|
drawCall.indexFormat = qsg_indexFormat(g);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
batch->stencilClipState.drawCalls.add(drawCall);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_stencilClipCommon.vs.isValid())
|
2020-05-02 12:27:13 +00:00
|
|
|
m_stencilClipCommon.vs = QSGMaterialShaderPrivate::loadShader(QLatin1String(":/qt-project.org/scenegraph/shaders_ng/stencilclip.vert.qsb"));
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
if (!m_stencilClipCommon.fs.isValid())
|
2020-05-02 12:27:13 +00:00
|
|
|
m_stencilClipCommon.fs = QSGMaterialShaderPrivate::loadShader(QLatin1String(":/qt-project.org/scenegraph/shaders_ng/stencilclip.frag.qsb"));
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
if (!m_stencilClipCommon.replacePs)
|
|
|
|
m_stencilClipCommon.replacePs = buildStencilPipeline(batch, true);
|
|
|
|
|
|
|
|
if (!m_stencilClipCommon.incrPs)
|
|
|
|
m_stencilClipCommon.incrPs = buildStencilPipeline(batch, false);
|
|
|
|
|
|
|
|
batch->stencilClipState.updateStencilBuffer = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentClipState.clipList = clipList;
|
|
|
|
m_currentClipState.type = clipType;
|
|
|
|
m_currentClipState.scissor = QRhiScissor(scissorRect.x(), scissorRect.y(),
|
|
|
|
scissorRect.width(), scissorRect.height());
|
|
|
|
|
|
|
|
applyClipStateToGraphicsState();
|
|
|
|
batch->clipState = m_currentClipState;
|
|
|
|
}
|
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
void Renderer::enqueueStencilDraw(const Batch *batch)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
// cliptype stencil + updateStencilBuffer==false means the batch uses
|
|
|
|
// stenciling but relies on the stencil data generated by a previous batch
|
|
|
|
// (due to the having the same clip node). Do not enqueue draw calls for
|
|
|
|
// stencil in this case as the stencil buffer is already up-to-date.
|
|
|
|
if (!batch->stencilClipState.updateStencilBuffer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QRhiCommandBuffer *cb = commandBuffer();
|
|
|
|
const int count = batch->stencilClipState.drawCalls.size();
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
const StencilClipState::StencilDrawCall &drawCall(batch->stencilClipState.drawCalls.at(i));
|
|
|
|
QRhiShaderResourceBindings *srb = batch->stencilClipState.srb;
|
|
|
|
QRhiCommandBuffer::DynamicOffset ubufOffset(0, drawCall.ubufOffset);
|
|
|
|
if (i == 0) {
|
|
|
|
cb->setGraphicsPipeline(m_stencilClipCommon.replacePs);
|
|
|
|
cb->setViewport(m_pstate.viewport);
|
|
|
|
} else if (i == 1) {
|
|
|
|
cb->setGraphicsPipeline(m_stencilClipCommon.incrPs);
|
|
|
|
cb->setViewport(m_pstate.viewport);
|
|
|
|
}
|
2019-08-01 20:02:06 +00:00
|
|
|
// else incrPs is already bound
|
|
|
|
cb->setShaderResources(srb, 1, &ubufOffset);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
cb->setStencilRef(drawCall.stencilRef);
|
|
|
|
const QRhiCommandBuffer::VertexInput vbufBinding(batch->stencilClipState.vbuf, drawCall.vbufOffset);
|
|
|
|
if (drawCall.indexCount) {
|
|
|
|
cb->setVertexInput(0, 1, &vbufBinding,
|
|
|
|
batch->stencilClipState.ibuf, drawCall.ibufOffset, drawCall.indexFormat);
|
|
|
|
cb->drawIndexed(drawCall.indexCount);
|
|
|
|
} else {
|
|
|
|
cb->setVertexInput(0, 1, &vbufBinding);
|
|
|
|
cb->draw(drawCall.vertexCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
void Renderer::setActiveRhiShader(QSGMaterialShader *program, ShaderManager::Shader *shader)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
Q_ASSERT(m_rhi);
|
2020-05-02 12:27:13 +00:00
|
|
|
m_currentProgram = program;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
m_currentShader = shader;
|
|
|
|
m_currentMaterial = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool needsBlendConstant(QRhiGraphicsPipeline::BlendFactor f)
|
|
|
|
{
|
|
|
|
return f == QRhiGraphicsPipeline::ConstantColor
|
|
|
|
|| f == QRhiGraphicsPipeline::OneMinusConstantColor
|
|
|
|
|| f == QRhiGraphicsPipeline::ConstantAlpha
|
|
|
|
|| f == QRhiGraphicsPipeline::OneMinusConstantAlpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
// With QRhi renderBatches() is split to two steps: prepare and render.
|
|
|
|
//
|
|
|
|
// Prepare goes through the batches and elements, and set up a graphics
|
|
|
|
// pipeline, srb, uniform buffer, calculates clipping, based on m_gstate, the
|
|
|
|
// material (shaders), and the batches. This step does not touch the command
|
|
|
|
// buffer or renderpass-related state (m_pstate).
|
|
|
|
//
|
|
|
|
// The render step then starts a renderpass, and goes through all
|
|
|
|
// batches/elements again and records setGraphicsPipeline, drawIndexed, etc. on
|
|
|
|
// the command buffer. The prepare step's accumulated global state like
|
|
|
|
// m_gstate must not be used here. Rather, all data needed for rendering is
|
|
|
|
// available from Batch/Element at this stage. Bookkeeping of state in the
|
|
|
|
// renderpass is done via m_pstate.
|
|
|
|
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
bool Renderer::ensurePipelineState(Element *e, const ShaderManager::Shader *sms, bool depthPostPass)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
Get rid of renderpass descriptor objects from the pipeline cache keys
Follow what we did to the srb: instead of storing an object reference,
store an opaque blob to test for compatibility. This works even if the
object is destroyed in the meantime. Thus, the annoying and error-prone
invalidatePipelineCacheDependency() goes away, finally.
All this works because creating a QRhiGraphicsPipeline with a given
QRhiRenderPassDescriptor only needs the renderpass object for building
(as in create()). Afterwards the object can be destroyed, even. The
pipeline is still usable with any render targets that have a
_compatible_ rp descriptor. Therefore, it is ideal if there is a way
to test for this compatibility without having to have the original
object around for ever.
Relies on enablers (most importantly,
QRhiRenderPassDescriptor::serializedFormat()) added to QRhi in qtbase.
While not necessarily obvious, the real benefit here is significant
performance gains in certain situations: consider rendering a scene to a
given render target, then to another one, then yet another one, for
example via QQuickRenderControl. We no longer have to do aggressive
purging of the pipelines just because a QRhiRenderPassDescriptor some of
the recently created pipelines may be associated with is going to
disappear. Rather, everything can stay as-is, there are no crashes due
to dangling pointers in the pipeline cache keys. The majority
of cases involve highly compatible render targets (e.g. rendering
into textures of the same format), so reuse is highly beneficial.
Pick-to: 6.2
Change-Id: I8ad4bfcb3c7e66c7364c91a749e2a2e6837b4f1a
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-09-15 12:07:15 +00:00
|
|
|
// Note the key's == and qHash implementations: the renderpass descriptor
|
|
|
|
// and srb are tested for compatibility, not pointer equality.
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
//
|
|
|
|
// We do not store the srb pointer itself because the ownership stays with
|
|
|
|
// the Element and that can go away more often that we would like it
|
|
|
|
// to. (think scrolling a list view, constantly dropping and creating new
|
|
|
|
// nodes) Rather, use an opaque blob of a few uints and store and compare
|
|
|
|
// that. This works because once the pipeline is built, we will always call
|
|
|
|
// setShaderResources with an explicitly specified srb which is fine even if
|
|
|
|
// e->srb we used here to bake the pipeline is already gone by that point.
|
|
|
|
//
|
|
|
|
// A typical QSGMaterial's serialized srb layout is 8 uints. (uniform buffer
|
|
|
|
// + texture, 4 fields each) Regardless, using an implicitly shared
|
|
|
|
// container is essential here. (won't detach so no more allocs and copies
|
|
|
|
// are done, unless the Element decides to rebake the srb with a different
|
|
|
|
// layout - but then the detach is exactly what we need)
|
Get rid of renderpass descriptor objects from the pipeline cache keys
Follow what we did to the srb: instead of storing an object reference,
store an opaque blob to test for compatibility. This works even if the
object is destroyed in the meantime. Thus, the annoying and error-prone
invalidatePipelineCacheDependency() goes away, finally.
All this works because creating a QRhiGraphicsPipeline with a given
QRhiRenderPassDescriptor only needs the renderpass object for building
(as in create()). Afterwards the object can be destroyed, even. The
pipeline is still usable with any render targets that have a
_compatible_ rp descriptor. Therefore, it is ideal if there is a way
to test for this compatibility without having to have the original
object around for ever.
Relies on enablers (most importantly,
QRhiRenderPassDescriptor::serializedFormat()) added to QRhi in qtbase.
While not necessarily obvious, the real benefit here is significant
performance gains in certain situations: consider rendering a scene to a
given render target, then to another one, then yet another one, for
example via QQuickRenderControl. We no longer have to do aggressive
purging of the pipelines just because a QRhiRenderPassDescriptor some of
the recently created pipelines may be associated with is going to
disappear. Rather, everything can stay as-is, there are no crashes due
to dangling pointers in the pipeline cache keys. The majority
of cases involve highly compatible render targets (e.g. rendering
into textures of the same format), so reuse is highly beneficial.
Pick-to: 6.2
Change-Id: I8ad4bfcb3c7e66c7364c91a749e2a2e6837b4f1a
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-09-15 12:07:15 +00:00
|
|
|
//
|
|
|
|
// Same story for the renderpass descriptor: the object can go away but
|
|
|
|
// that's fine because that has no effect on an already built pipeline, and
|
|
|
|
// for comparison we only rely on the serialized blob in order decide if the
|
|
|
|
// render target is compatible with the pipeline.
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
|
Get rid of renderpass descriptor objects from the pipeline cache keys
Follow what we did to the srb: instead of storing an object reference,
store an opaque blob to test for compatibility. This works even if the
object is destroyed in the meantime. Thus, the annoying and error-prone
invalidatePipelineCacheDependency() goes away, finally.
All this works because creating a QRhiGraphicsPipeline with a given
QRhiRenderPassDescriptor only needs the renderpass object for building
(as in create()). Afterwards the object can be destroyed, even. The
pipeline is still usable with any render targets that have a
_compatible_ rp descriptor. Therefore, it is ideal if there is a way
to test for this compatibility without having to have the original
object around for ever.
Relies on enablers (most importantly,
QRhiRenderPassDescriptor::serializedFormat()) added to QRhi in qtbase.
While not necessarily obvious, the real benefit here is significant
performance gains in certain situations: consider rendering a scene to a
given render target, then to another one, then yet another one, for
example via QQuickRenderControl. We no longer have to do aggressive
purging of the pipelines just because a QRhiRenderPassDescriptor some of
the recently created pipelines may be associated with is going to
disappear. Rather, everything can stay as-is, there are no crashes due
to dangling pointers in the pipeline cache keys. The majority
of cases involve highly compatible render targets (e.g. rendering
into textures of the same format), so reuse is highly beneficial.
Pick-to: 6.2
Change-Id: I8ad4bfcb3c7e66c7364c91a749e2a2e6837b4f1a
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-09-15 12:07:15 +00:00
|
|
|
const GraphicsPipelineStateKey k = GraphicsPipelineStateKey::create(m_gstate, sms, renderPassDescriptor(), e->srb);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
// Note: dynamic state (viewport rect, scissor rect, stencil ref, blend
|
|
|
|
// constant) is never a part of GraphicsState/QRhiGraphicsPipeline.
|
|
|
|
|
|
|
|
// See if there is an existing, matching pipeline state object.
|
2019-11-25 20:36:23 +00:00
|
|
|
auto it = m_shaderManager->pipelineCache.constFind(k);
|
|
|
|
if (it != m_shaderManager->pipelineCache.constEnd()) {
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
if (depthPostPass)
|
|
|
|
e->depthPostPassPs = *it;
|
|
|
|
else
|
|
|
|
e->ps = *it;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build a new one. This is potentially expensive.
|
|
|
|
QRhiGraphicsPipeline *ps = m_rhi->newGraphicsPipeline();
|
2019-09-28 15:21:03 +00:00
|
|
|
ps->setShaderStages(sms->programRhi.shaderStages.cbegin(), sms->programRhi.shaderStages.cend());
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
ps->setVertexInputLayout(sms->programRhi.inputLayout);
|
|
|
|
ps->setShaderResourceBindings(e->srb);
|
|
|
|
ps->setRenderPassDescriptor(renderPassDescriptor());
|
|
|
|
|
2019-11-21 12:10:02 +00:00
|
|
|
QRhiGraphicsPipeline::Flags flags;
|
2022-06-15 11:17:11 +00:00
|
|
|
if (needsBlendConstant(m_gstate.srcColor) || needsBlendConstant(m_gstate.dstColor)
|
|
|
|
|| needsBlendConstant(m_gstate.srcAlpha) || needsBlendConstant(m_gstate.dstAlpha))
|
|
|
|
{
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
flags |= QRhiGraphicsPipeline::UsesBlendConstants;
|
2022-06-15 11:17:11 +00:00
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (m_gstate.usesScissor)
|
|
|
|
flags |= QRhiGraphicsPipeline::UsesScissor;
|
|
|
|
if (m_gstate.stencilTest)
|
|
|
|
flags |= QRhiGraphicsPipeline::UsesStencilRef;
|
|
|
|
|
|
|
|
ps->setFlags(flags);
|
2019-07-31 13:17:52 +00:00
|
|
|
ps->setTopology(qsg_topology(m_gstate.drawMode));
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
ps->setCullMode(m_gstate.cullMode);
|
2022-02-01 05:22:26 +00:00
|
|
|
ps->setPolygonMode(m_gstate.polygonMode);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
QRhiGraphicsPipeline::TargetBlend blend;
|
|
|
|
blend.colorWrite = m_gstate.colorWrite;
|
|
|
|
blend.enable = m_gstate.blending;
|
2022-06-15 11:17:11 +00:00
|
|
|
blend.srcColor = m_gstate.srcColor;
|
|
|
|
blend.dstColor = m_gstate.dstColor;
|
|
|
|
blend.srcAlpha = m_gstate.srcAlpha;
|
|
|
|
blend.dstAlpha = m_gstate.dstAlpha;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
ps->setTargetBlends({ blend });
|
|
|
|
|
|
|
|
ps->setDepthTest(m_gstate.depthTest);
|
|
|
|
ps->setDepthWrite(m_gstate.depthWrite);
|
|
|
|
ps->setDepthOp(m_gstate.depthFunc);
|
|
|
|
|
|
|
|
if (m_gstate.stencilTest) {
|
|
|
|
ps->setStencilTest(true);
|
|
|
|
QRhiGraphicsPipeline::StencilOpState stencilOp;
|
|
|
|
stencilOp.compareOp = QRhiGraphicsPipeline::Equal;
|
|
|
|
stencilOp.failOp = QRhiGraphicsPipeline::Keep;
|
|
|
|
stencilOp.depthFailOp = QRhiGraphicsPipeline::Keep;
|
|
|
|
stencilOp.passOp = QRhiGraphicsPipeline::Keep;
|
|
|
|
ps->setStencilFront(stencilOp);
|
|
|
|
ps->setStencilBack(stencilOp);
|
|
|
|
}
|
|
|
|
|
|
|
|
ps->setSampleCount(m_gstate.sampleCount);
|
|
|
|
|
2019-06-24 14:53:46 +00:00
|
|
|
ps->setLineWidth(m_gstate.lineWidth);
|
|
|
|
|
2020-05-27 15:54:41 +00:00
|
|
|
if (!ps->create()) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
qWarning("Failed to build graphics pipeline state");
|
|
|
|
delete ps;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:36:23 +00:00
|
|
|
m_shaderManager->pipelineCache.insert(k, ps);
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
if (depthPostPass)
|
|
|
|
e->depthPostPassPs = ps;
|
|
|
|
else
|
|
|
|
e->ps = ps;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static QRhiSampler *newSampler(QRhi *rhi, const QSGSamplerDescription &desc)
|
|
|
|
{
|
|
|
|
QRhiSampler::Filter magFilter;
|
|
|
|
QRhiSampler::Filter minFilter;
|
|
|
|
QRhiSampler::Filter mipmapMode;
|
|
|
|
QRhiSampler::AddressMode u;
|
|
|
|
QRhiSampler::AddressMode v;
|
|
|
|
|
|
|
|
switch (desc.filtering) {
|
|
|
|
case QSGTexture::None:
|
|
|
|
Q_FALLTHROUGH();
|
|
|
|
case QSGTexture::Nearest:
|
|
|
|
magFilter = minFilter = QRhiSampler::Nearest;
|
|
|
|
break;
|
|
|
|
case QSGTexture::Linear:
|
|
|
|
magFilter = minFilter = QRhiSampler::Linear;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
magFilter = minFilter = QRhiSampler::Nearest;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (desc.mipmapFiltering) {
|
|
|
|
case QSGTexture::None:
|
|
|
|
mipmapMode = QRhiSampler::None;
|
|
|
|
break;
|
|
|
|
case QSGTexture::Nearest:
|
|
|
|
mipmapMode = QRhiSampler::Nearest;
|
|
|
|
break;
|
|
|
|
case QSGTexture::Linear:
|
|
|
|
mipmapMode = QRhiSampler::Linear;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
mipmapMode = QRhiSampler::None;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (desc.horizontalWrap) {
|
|
|
|
case QSGTexture::Repeat:
|
|
|
|
u = QRhiSampler::Repeat;
|
|
|
|
break;
|
|
|
|
case QSGTexture::ClampToEdge:
|
|
|
|
u = QRhiSampler::ClampToEdge;
|
|
|
|
break;
|
|
|
|
case QSGTexture::MirroredRepeat:
|
|
|
|
u = QRhiSampler::Mirror;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
u = QRhiSampler::ClampToEdge;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (desc.verticalWrap) {
|
|
|
|
case QSGTexture::Repeat:
|
|
|
|
v = QRhiSampler::Repeat;
|
|
|
|
break;
|
|
|
|
case QSGTexture::ClampToEdge:
|
|
|
|
v = QRhiSampler::ClampToEdge;
|
|
|
|
break;
|
|
|
|
case QSGTexture::MirroredRepeat:
|
|
|
|
v = QRhiSampler::Mirror;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
v = QRhiSampler::ClampToEdge;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rhi->newSampler(magFilter, minFilter, mipmapMode, u, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRhiTexture *Renderer::dummyTexture()
|
|
|
|
{
|
|
|
|
if (!m_dummyTexture) {
|
|
|
|
m_dummyTexture = m_rhi->newTexture(QRhiTexture::RGBA8, QSize(64, 64));
|
2020-05-27 15:54:41 +00:00
|
|
|
if (m_dummyTexture->create()) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (m_resourceUpdates) {
|
|
|
|
QImage img(m_dummyTexture->pixelSize(), QImage::Format_RGBA8888_Premultiplied);
|
|
|
|
img.fill(0);
|
|
|
|
m_resourceUpdates->uploadTexture(m_dummyTexture, img);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_dummyTexture;
|
|
|
|
}
|
|
|
|
|
2020-05-02 12:27:13 +00:00
|
|
|
static void rendererToMaterialGraphicsState(QSGMaterialShader::GraphicsPipelineState *dst,
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
GraphicsState *src)
|
|
|
|
{
|
|
|
|
dst->blendEnable = src->blending;
|
|
|
|
|
|
|
|
// the enum values should match, sanity check it
|
2020-05-02 12:27:13 +00:00
|
|
|
Q_ASSERT(int(QSGMaterialShader::GraphicsPipelineState::OneMinusSrc1Alpha) == int(QRhiGraphicsPipeline::OneMinusSrc1Alpha));
|
|
|
|
Q_ASSERT(int(QSGMaterialShader::GraphicsPipelineState::A) == int(QRhiGraphicsPipeline::A));
|
|
|
|
Q_ASSERT(int(QSGMaterialShader::GraphicsPipelineState::CullBack) == int(QRhiGraphicsPipeline::Back));
|
2022-02-01 05:22:26 +00:00
|
|
|
Q_ASSERT(int(QSGMaterialShader::GraphicsPipelineState::Line) == int(QRhiGraphicsPipeline::Line));
|
2020-05-02 12:27:13 +00:00
|
|
|
dst->srcColor = QSGMaterialShader::GraphicsPipelineState::BlendFactor(src->srcColor);
|
|
|
|
dst->dstColor = QSGMaterialShader::GraphicsPipelineState::BlendFactor(src->dstColor);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
2022-06-15 11:17:11 +00:00
|
|
|
// For compatibility with any existing code, separateBlendFactors defaults
|
|
|
|
// to _false_ which means that materials that do not touch srcAlpha and
|
|
|
|
// dstAlpha will continue to use srcColor and dstColor as the alpha
|
|
|
|
// blending factors. New code that needs different values for color/alpha,
|
|
|
|
// can explicitly set separateBlendFactors to true and then set srcAlpha
|
|
|
|
// and dstAlpha as well.
|
|
|
|
dst->separateBlendFactors = false;
|
|
|
|
|
|
|
|
dst->srcAlpha = QSGMaterialShader::GraphicsPipelineState::BlendFactor(src->srcAlpha);
|
|
|
|
dst->dstAlpha = QSGMaterialShader::GraphicsPipelineState::BlendFactor(src->dstAlpha);
|
|
|
|
|
2020-05-02 12:27:13 +00:00
|
|
|
dst->colorWrite = QSGMaterialShader::GraphicsPipelineState::ColorMask(int(src->colorWrite));
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
2020-05-02 12:27:13 +00:00
|
|
|
dst->cullMode = QSGMaterialShader::GraphicsPipelineState::CullMode(src->cullMode);
|
2022-02-01 05:22:26 +00:00
|
|
|
dst->polygonMode = QSGMaterialShader::GraphicsPipelineState::PolygonMode(src->polygonMode);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void materialToRendererGraphicsState(GraphicsState *dst,
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShader::GraphicsPipelineState *src)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
dst->blending = src->blendEnable;
|
|
|
|
dst->srcColor = QRhiGraphicsPipeline::BlendFactor(src->srcColor);
|
|
|
|
dst->dstColor = QRhiGraphicsPipeline::BlendFactor(src->dstColor);
|
2022-06-15 11:17:11 +00:00
|
|
|
if (src->separateBlendFactors) {
|
|
|
|
dst->srcAlpha = QRhiGraphicsPipeline::BlendFactor(src->srcAlpha);
|
|
|
|
dst->dstAlpha = QRhiGraphicsPipeline::BlendFactor(src->dstAlpha);
|
|
|
|
} else {
|
|
|
|
dst->srcAlpha = dst->srcColor;
|
|
|
|
dst->dstAlpha = dst->dstColor;
|
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
dst->colorWrite = QRhiGraphicsPipeline::ColorMask(int(src->colorWrite));
|
|
|
|
dst->cullMode = QRhiGraphicsPipeline::CullMode(src->cullMode);
|
2022-02-01 05:22:26 +00:00
|
|
|
dst->polygonMode = QRhiGraphicsPipeline::PolygonMode(src->polygonMode);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::updateMaterialDynamicData(ShaderManager::Shader *sms,
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShader::RenderState &renderState,
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
QSGMaterial *material,
|
|
|
|
const Batch *batch,
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
Element *e,
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
int ubufOffset,
|
2020-05-06 12:16:05 +00:00
|
|
|
int ubufRegionSize)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
m_current_resource_update_batch = m_resourceUpdates;
|
|
|
|
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShader *shader = sms->programRhi.program;
|
|
|
|
QSGMaterialShaderPrivate *pd = QSGMaterialShaderPrivate::get(shader);
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
QVarLengthArray<QRhiShaderResourceBinding, 8> bindings;
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (pd->ubufBinding >= 0) {
|
|
|
|
m_current_uniform_data = &pd->masterUniformData;
|
|
|
|
const bool changed = shader->updateUniformData(renderState, material, m_currentMaterial);
|
2019-09-16 15:44:16 +00:00
|
|
|
m_current_uniform_data = nullptr;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
if (changed || !batch->ubufDataValid)
|
|
|
|
m_resourceUpdates->updateDynamicBuffer(batch->ubuf, ubufOffset, ubufRegionSize, pd->masterUniformData.constData());
|
|
|
|
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
bindings.append(QRhiShaderResourceBinding::uniformBuffer(pd->ubufBinding,
|
|
|
|
pd->ubufStages,
|
|
|
|
batch->ubuf,
|
|
|
|
ubufOffset,
|
|
|
|
ubufRegionSize));
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 12:27:13 +00:00
|
|
|
for (int binding = 0; binding < QSGMaterialShaderPrivate::MAX_SHADER_RESOURCE_BINDINGS; ++binding) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
const QRhiShaderResourceBinding::StageFlags stages = pd->combinedImageSamplerBindings[binding];
|
|
|
|
if (!stages)
|
|
|
|
continue;
|
|
|
|
|
2022-01-24 22:47:47 +00:00
|
|
|
QVarLengthArray<QSGTexture *, 4> prevTex = pd->textureBindingTable[binding];
|
|
|
|
QVarLengthArray<QSGTexture *, 4> nextTex = prevTex;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
2022-01-24 22:47:47 +00:00
|
|
|
const int count = pd->combinedImageSamplerCount[binding];
|
|
|
|
nextTex.resize(count);
|
|
|
|
|
|
|
|
shader->updateSampledImage(renderState, binding, nextTex.data(), material,
|
|
|
|
m_currentMaterial);
|
|
|
|
|
|
|
|
if (nextTex.contains(nullptr)) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
qWarning("No QSGTexture provided from updateSampledImage(). This is wrong.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-01-24 22:47:47 +00:00
|
|
|
bool hasDirtySamplerOptions = false;
|
|
|
|
bool isAnisotropic = false;
|
|
|
|
for (QSGTexture *t : nextTex) {
|
|
|
|
QSGTexturePrivate *td = QSGTexturePrivate::get(t);
|
|
|
|
hasDirtySamplerOptions |= td->hasDirtySamplerOptions();
|
|
|
|
isAnisotropic |= t->anisotropyLevel() != QSGTexture::AnisotropyNone;
|
|
|
|
td->resetDirtySamplerOptions();
|
|
|
|
}
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
// prevTex may be invalid at this point, avoid dereferencing it
|
2022-01-24 22:47:47 +00:00
|
|
|
if (nextTex != prevTex || hasDirtySamplerOptions) {
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
// The QSGTexture, and so the sampler parameters, may have changed.
|
|
|
|
// The rhiTexture is not relevant here.
|
2022-01-24 22:47:47 +00:00
|
|
|
pd->textureBindingTable[binding] = nextTex; // does not own
|
|
|
|
pd->samplerBindingTable[binding].clear();
|
|
|
|
|
|
|
|
if (isAnisotropic) // ###
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
qWarning("QSGTexture anisotropy levels are not currently supported");
|
|
|
|
|
2022-01-24 22:47:47 +00:00
|
|
|
QVarLengthArray<QRhiSampler *, 4> samplers;
|
|
|
|
|
|
|
|
for (QSGTexture *t : nextTex) {
|
|
|
|
const QSGSamplerDescription samplerDesc = QSGSamplerDescription::fromTexture(t);
|
|
|
|
|
|
|
|
QRhiSampler *sampler = m_samplers[samplerDesc];
|
|
|
|
|
|
|
|
if (!sampler) {
|
|
|
|
sampler = newSampler(m_rhi, samplerDesc);
|
|
|
|
if (!sampler->create()) {
|
|
|
|
qWarning("Failed to build sampler");
|
|
|
|
delete sampler;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
m_samplers[samplerDesc] = sampler;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
2022-01-24 22:47:47 +00:00
|
|
|
samplers.append(sampler);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
2022-01-24 22:47:47 +00:00
|
|
|
|
|
|
|
pd->samplerBindingTable[binding] = samplers; // does not own
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 22:47:47 +00:00
|
|
|
if (pd->textureBindingTable[binding].count() == pd->samplerBindingTable[binding].count()) {
|
|
|
|
|
|
|
|
QVarLengthArray<QRhiShaderResourceBinding::TextureAndSampler, 4> textureSamplers;
|
|
|
|
|
|
|
|
for (int i = 0; i < pd->textureBindingTable[binding].count(); ++i) {
|
|
|
|
|
|
|
|
QRhiTexture *texture = pd->textureBindingTable[binding].at(i)->rhiTexture();
|
|
|
|
|
|
|
|
// texture may be null if the update above failed for any reason,
|
|
|
|
// or if the QSGTexture chose to return null intentionally. This is
|
|
|
|
// valid and we still need to provide something to the shader.
|
|
|
|
if (!texture)
|
|
|
|
texture = dummyTexture();
|
|
|
|
|
|
|
|
QRhiSampler *sampler = pd->samplerBindingTable[binding].at(i);
|
|
|
|
|
|
|
|
textureSamplers.append(
|
|
|
|
QRhiShaderResourceBinding::TextureAndSampler { texture, sampler });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!textureSamplers.isEmpty())
|
|
|
|
bindings.append(QRhiShaderResourceBinding::sampledTextures(
|
|
|
|
binding, stages, count, textureSamplers.constData()));
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef QT_NO_DEBUG
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
if (bindings.isEmpty())
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
qWarning("No shader resources for material %p, this is odd.", material);
|
|
|
|
#endif
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
|
|
|
|
enum class SrbAction {
|
|
|
|
Unknown,
|
|
|
|
DoNothing,
|
|
|
|
UpdateResources,
|
|
|
|
Rebake
|
|
|
|
} srbAction = SrbAction::Unknown;
|
|
|
|
|
|
|
|
// First, if the Element has no srb created at all, then try to find an existing,
|
|
|
|
// currently unused srb that is layout-compatible with our binding list.
|
|
|
|
if (!e->srb) {
|
|
|
|
// reuse a QVector as our work area, thus possibly reusing the underlying allocation too
|
|
|
|
QVector<quint32> &layoutDesc(m_shaderManager->srbLayoutDescSerializeWorkspace);
|
|
|
|
layoutDesc.clear();
|
|
|
|
QRhiShaderResourceBinding::serializeLayoutDescription(bindings.cbegin(), bindings.cend(), std::back_inserter(layoutDesc));
|
|
|
|
e->srb = m_shaderManager->srbPool.take(layoutDesc);
|
|
|
|
if (e->srb) {
|
|
|
|
// Here we know layout compatibility is satisfied, but do not spend time on full
|
|
|
|
// comparison. The chance of getting an srb that refers to the same resources
|
|
|
|
// (buffer, textures) is low in practice. So reuse, but write new resources.
|
|
|
|
srbAction = SrbAction::UpdateResources;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the Element had an existing srb, investigate:
|
|
|
|
// - It may be used as-is (when nothing changed in the scene regarding this node compared to the previous frame).
|
|
|
|
// - Otherwise it may be able to go with a lightweight update (replace resources, binding list layout is the same).
|
|
|
|
// - If all else fails rebake the full thing, meaning we reuse the memory allocation but will recreate everything underneath.
|
|
|
|
if (srbAction == SrbAction::Unknown && e->srb) {
|
|
|
|
if (std::equal(e->srb->cbeginBindings(), e->srb->cendBindings(), bindings.cbegin(), bindings.cend())) {
|
|
|
|
srbAction = SrbAction::DoNothing;
|
|
|
|
} else if (std::equal(e->srb->cbeginBindings(), e->srb->cendBindings(), bindings.cbegin(), bindings.cend(),
|
|
|
|
[](const auto &a, const auto &b) { return a.isLayoutCompatible(b); }))
|
|
|
|
{
|
|
|
|
srbAction = SrbAction::UpdateResources;
|
|
|
|
} else {
|
|
|
|
srbAction = SrbAction::Rebake;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the Element had no srb associated at all and could not find a layout-compatible
|
|
|
|
// one from the pool, then create a whole new object.
|
|
|
|
if (!e->srb) {
|
|
|
|
e->srb = m_rhi->newShaderResourceBindings();
|
|
|
|
srbAction = SrbAction::Rebake;
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(srbAction != SrbAction::Unknown && e->srb);
|
|
|
|
|
|
|
|
switch (srbAction) {
|
|
|
|
case SrbAction::DoNothing:
|
|
|
|
break;
|
|
|
|
case SrbAction::UpdateResources:
|
|
|
|
{
|
|
|
|
e->srb->setBindings(bindings.cbegin(), bindings.cend());
|
|
|
|
QRhiShaderResourceBindings::UpdateFlags flags;
|
|
|
|
// Due to the way the binding list is built up above, if we have a uniform buffer
|
|
|
|
// at binding point 0 (or none at all) then the sampledTexture bindings are added
|
|
|
|
// with increasing binding points afterwards, so the list is already sorted based
|
|
|
|
// on the binding points, thus we can save some time by telling the QRhi backend
|
|
|
|
// not to sort again.
|
|
|
|
if (pd->ubufBinding <= 0 || bindings.count() <= 1)
|
|
|
|
flags |= QRhiShaderResourceBindings::BindingsAreSorted;
|
|
|
|
|
|
|
|
e->srb->updateResources(flags);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SrbAction::Rebake:
|
|
|
|
e->srb->setBindings(bindings.cbegin(), bindings.cend());
|
|
|
|
if (!e->srb->create())
|
|
|
|
qWarning("Failed to build srb");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT_X(false, "updateMaterialDynamicData", "No srb action set, this cannot happen");
|
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::updateMaterialStaticData(ShaderManager::Shader *sms,
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShader::RenderState &renderState,
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
QSGMaterial *material,
|
|
|
|
Batch *batch,
|
2020-05-06 12:16:05 +00:00
|
|
|
bool *gstateChanged)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShader *shader = sms->programRhi.program;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
*gstateChanged = false;
|
2020-05-02 12:27:13 +00:00
|
|
|
if (shader->flags().testFlag(QSGMaterialShader::UpdatesGraphicsPipelineState)) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
// generate the public mini-state from m_gstate, invoke the material,
|
|
|
|
// write the changes, if any, back to m_gstate, together with a way to
|
|
|
|
// roll those back.
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShader::GraphicsPipelineState shaderPs;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
rendererToMaterialGraphicsState(&shaderPs, &m_gstate);
|
|
|
|
const bool changed = shader->updateGraphicsPipelineState(renderState, &shaderPs, material, m_currentMaterial);
|
|
|
|
if (changed) {
|
|
|
|
m_gstateStack.push(m_gstate);
|
|
|
|
materialToRendererGraphicsState(&m_gstate, &shaderPs);
|
2022-06-15 11:17:11 +00:00
|
|
|
if (needsBlendConstant(m_gstate.srcColor) || needsBlendConstant(m_gstate.dstColor)
|
|
|
|
|| needsBlendConstant(m_gstate.srcAlpha) || needsBlendConstant(m_gstate.dstAlpha))
|
|
|
|
{
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
batch->blendConstant = shaderPs.blendConstant;
|
2022-06-15 11:17:11 +00:00
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
*gstateChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
bool Renderer::prepareRenderMergedBatch(Batch *batch, PreparedRenderBatch *renderBatch)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
if (batch->vertexCount == 0 || batch->indexCount == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Element *e = batch->first;
|
|
|
|
Q_ASSERT(e);
|
|
|
|
|
|
|
|
#ifndef QT_NO_DEBUG_OUTPUT
|
|
|
|
if (Q_UNLIKELY(debug_render())) {
|
|
|
|
QDebug debug = qDebug();
|
|
|
|
debug << " -"
|
|
|
|
<< batch
|
|
|
|
<< (batch->uploadedThisFrame ? "[ upload]" : "[retained]")
|
|
|
|
<< (e->node->clipList() ? "[ clip]" : "[noclip]")
|
|
|
|
<< (batch->isOpaque ? "[opaque]" : "[ alpha]")
|
|
|
|
<< "[ merged]"
|
|
|
|
<< " Nodes:" << QString::fromLatin1("%1").arg(qsg_countNodesInBatch(batch), 4).toLatin1().constData()
|
|
|
|
<< " Vertices:" << QString::fromLatin1("%1").arg(batch->vertexCount, 5).toLatin1().constData()
|
|
|
|
<< " Indices:" << QString::fromLatin1("%1").arg(batch->indexCount, 5).toLatin1().constData()
|
|
|
|
<< " root:" << batch->root;
|
|
|
|
if (batch->drawSets.size() > 1)
|
|
|
|
debug << "sets:" << batch->drawSets.size();
|
|
|
|
if (!batch->isOpaque)
|
|
|
|
debug << "opacity:" << e->node->inheritedOpacity();
|
|
|
|
batch->uploadedThisFrame = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QSGGeometryNode *gn = e->node;
|
|
|
|
|
|
|
|
// We always have dirty matrix as all batches are at a unique z range.
|
|
|
|
QSGMaterialShader::RenderState::DirtyStates dirty = QSGMaterialShader::RenderState::DirtyMatrix;
|
|
|
|
if (batch->root)
|
|
|
|
m_current_model_view_matrix = qsg_matrixForRoot(batch->root);
|
|
|
|
else
|
|
|
|
m_current_model_view_matrix.setToIdentity();
|
|
|
|
m_current_determinant = m_current_model_view_matrix.determinant();
|
|
|
|
m_current_projection_matrix = projectionMatrix();
|
|
|
|
m_current_projection_matrix_native_ndc = projectionMatrixWithNativeNDC();
|
|
|
|
|
|
|
|
QSGMaterial *material = gn->activeMaterial();
|
2020-06-11 10:35:04 +00:00
|
|
|
if (m_renderMode != QSGRendererInterface::RenderMode3D)
|
2020-06-09 15:06:02 +00:00
|
|
|
updateClipState(gn->clipList(), batch);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
const QSGGeometry *g = gn->geometry();
|
2020-06-09 08:57:35 +00:00
|
|
|
ShaderManager::Shader *sms = useDepthBuffer() ? m_shaderManager->prepareMaterial(material, g, m_renderMode)
|
|
|
|
: m_shaderManager->prepareMaterialNoRewrite(material, g, m_renderMode);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (!sms)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Q_ASSERT(sms->programRhi.program);
|
|
|
|
if (m_currentShader != sms)
|
|
|
|
setActiveRhiShader(sms->programRhi.program, sms);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
m_current_opacity = gn->inheritedOpacity();
|
2017-12-18 15:13:40 +00:00
|
|
|
if (!qFuzzyCompare(sms->lastOpacity, float(m_current_opacity))) {
|
2013-08-14 05:27:07 +00:00
|
|
|
dirty |= QSGMaterialShader::RenderState::DirtyOpacity;
|
|
|
|
sms->lastOpacity = m_current_opacity;
|
|
|
|
}
|
|
|
|
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShaderPrivate *pd = QSGMaterialShaderPrivate::get(sms->programRhi.program);
|
2022-07-08 08:15:58 +00:00
|
|
|
const quint32 ubufSize = quint32(pd->masterUniformData.size());
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (pd->ubufBinding >= 0) {
|
|
|
|
bool ubufRebuild = false;
|
|
|
|
if (!batch->ubuf) {
|
|
|
|
batch->ubuf = m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, ubufSize);
|
|
|
|
ubufRebuild = true;
|
|
|
|
} else {
|
|
|
|
if (batch->ubuf->size() < ubufSize) {
|
|
|
|
batch->ubuf->setSize(ubufSize);
|
|
|
|
ubufRebuild = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ubufRebuild) {
|
|
|
|
batch->ubufDataValid = false;
|
2020-05-27 15:54:41 +00:00
|
|
|
if (!batch->ubuf->create()) {
|
2022-07-08 08:15:58 +00:00
|
|
|
qWarning("Failed to build uniform buffer of size %u bytes", ubufSize);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
delete batch->ubuf;
|
|
|
|
batch->ubuf = nullptr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShader::RenderState renderState = state(QSGMaterialShader::RenderState::DirtyStates(int(dirty)));
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
bool pendingGStatePop = false;
|
|
|
|
updateMaterialStaticData(sms, renderState, material, batch, &pendingGStatePop);
|
|
|
|
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
updateMaterialDynamicData(sms, renderState, material, batch, e, 0, ubufSize);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2014-07-03 10:15:46 +00:00
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
if (qsg_test_and_clear_material_failure()) {
|
2018-02-13 08:57:29 +00:00
|
|
|
qDebug("QSGMaterial::updateState triggered an error (merged), batch will be skipped:");
|
2014-07-03 10:15:46 +00:00
|
|
|
Element *ee = e;
|
|
|
|
while (ee) {
|
|
|
|
qDebug() << " -" << ee->node;
|
|
|
|
ee = ee->nextInBatch;
|
|
|
|
}
|
|
|
|
QSGNodeDumper::dump(rootNode());
|
|
|
|
qFatal("Aborting: scene graph is invalid...");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
m_gstate.drawMode = QSGGeometry::DrawingMode(g->drawingMode());
|
2019-06-24 14:53:46 +00:00
|
|
|
m_gstate.lineWidth = g->lineWidth();
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
const bool hasPipeline = ensurePipelineState(e, sms);
|
2019-06-24 14:53:46 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (pendingGStatePop)
|
|
|
|
m_gstate = m_gstateStack.pop();
|
|
|
|
|
|
|
|
if (!hasPipeline)
|
|
|
|
return false;
|
|
|
|
|
2020-06-11 10:35:04 +00:00
|
|
|
if (m_renderMode == QSGRendererInterface::RenderMode3D) {
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
m_gstateStack.push(m_gstate);
|
|
|
|
setStateForDepthPostPass();
|
|
|
|
ensurePipelineState(e, sms, true);
|
|
|
|
m_gstate = m_gstateStack.pop();
|
|
|
|
}
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
batch->ubufDataValid = true;
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
m_currentMaterial = material;
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
renderBatch->batch = batch;
|
|
|
|
renderBatch->sms = sms;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-24 14:53:46 +00:00
|
|
|
void Renderer::checkLineWidth(QSGGeometry *g)
|
|
|
|
{
|
|
|
|
if (g->drawingMode() == QSGGeometry::DrawLines || g->drawingMode() == QSGGeometry::DrawLineLoop
|
|
|
|
|| g->drawingMode() == QSGGeometry::DrawLineStrip)
|
|
|
|
{
|
|
|
|
if (g->lineWidth() != 1.0f) {
|
|
|
|
static bool checkedWideLineSupport = false;
|
|
|
|
if (!checkedWideLineSupport) {
|
|
|
|
checkedWideLineSupport = true;
|
|
|
|
if (!m_rhi->isFeatureSupported(QRhi::WideLines))
|
|
|
|
qWarning("Line widths other than 1 are not supported by the graphics API");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (g->drawingMode() == QSGGeometry::DrawPoints) {
|
|
|
|
if (g->lineWidth() != 1.0f) {
|
|
|
|
static bool warnedPointSize = false;
|
|
|
|
if (!warnedPointSize) {
|
|
|
|
warnedPointSize = true;
|
|
|
|
qWarning("Point size is not controllable by QSGGeometry. "
|
|
|
|
"Set gl_PointSize from the vertex shader instead.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
void Renderer::renderMergedBatch(PreparedRenderBatch *renderBatch, bool depthPostPass)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
const Batch *batch = renderBatch->batch;
|
2022-01-03 16:51:34 +00:00
|
|
|
if (!batch->vbo.buf || !batch->ibo.buf)
|
|
|
|
return;
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
Element *e = batch->first;
|
|
|
|
QSGGeometryNode *gn = e->node;
|
|
|
|
QSGGeometry *g = gn->geometry();
|
2019-06-24 14:53:46 +00:00
|
|
|
checkLineWidth(g);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (batch->clipState.type & ClipState::StencilClip)
|
|
|
|
enqueueStencilDraw(batch);
|
2014-07-03 10:15:46 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
QRhiCommandBuffer *cb = commandBuffer();
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
setGraphicsPipeline(cb, batch, e, depthPostPass);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
for (int i = 0, ie = batch->drawSets.size(); i != ie; ++i) {
|
2013-08-14 05:27:07 +00:00
|
|
|
const DrawSet &draw = batch->drawSets.at(i);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
const QRhiCommandBuffer::VertexInput vbufBindings[] = {
|
|
|
|
{ batch->vbo.buf, quint32(draw.vertices) },
|
|
|
|
{ batch->vbo.buf, quint32(draw.zorders) }
|
|
|
|
};
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
cb->setVertexInput(VERTEX_BUFFER_BINDING, useDepthBuffer() ? 2 : 1, vbufBindings,
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
batch->ibo.buf, draw.indices,
|
|
|
|
m_uint32IndexForRhi ? QRhiCommandBuffer::IndexUInt32 : QRhiCommandBuffer::IndexUInt16);
|
|
|
|
cb->drawIndexed(draw.indexCount);
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
bool Renderer::prepareRenderUnmergedBatch(Batch *batch, PreparedRenderBatch *renderBatch)
|
2013-08-14 05:27:07 +00:00
|
|
|
{
|
|
|
|
if (batch->vertexCount == 0)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
return false;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
Element *e = batch->first;
|
|
|
|
Q_ASSERT(e);
|
|
|
|
|
2014-09-16 22:20:53 +00:00
|
|
|
if (Q_UNLIKELY(debug_render())) {
|
2013-08-14 05:27:07 +00:00
|
|
|
qDebug() << " -"
|
2013-09-05 12:12:53 +00:00
|
|
|
<< batch
|
2013-08-14 05:27:07 +00:00
|
|
|
<< (batch->uploadedThisFrame ? "[ upload]" : "[retained]")
|
|
|
|
<< (e->node->clipList() ? "[ clip]" : "[noclip]")
|
|
|
|
<< (batch->isOpaque ? "[opaque]" : "[ alpha]")
|
|
|
|
<< "[unmerged]"
|
|
|
|
<< " Nodes:" << QString::fromLatin1("%1").arg(qsg_countNodesInBatch(batch), 4).toLatin1().constData()
|
|
|
|
<< " Vertices:" << QString::fromLatin1("%1").arg(batch->vertexCount, 5).toLatin1().constData()
|
|
|
|
<< " Indices:" << QString::fromLatin1("%1").arg(batch->indexCount, 5).toLatin1().constData()
|
|
|
|
<< " root:" << batch->root;
|
|
|
|
|
|
|
|
batch->uploadedThisFrame = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_current_projection_matrix = projectionMatrix();
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
m_current_projection_matrix_native_ndc = projectionMatrixWithNativeNDC();
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
QSGGeometryNode *gn = e->node;
|
2020-06-11 10:35:04 +00:00
|
|
|
if (m_renderMode != QSGRendererInterface::RenderMode3D)
|
2020-06-09 15:06:02 +00:00
|
|
|
updateClipState(gn->clipList(), batch);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
// We always have dirty matrix as all batches are at a unique z range.
|
|
|
|
QSGMaterialShader::RenderState::DirtyStates dirty = QSGMaterialShader::RenderState::DirtyMatrix;
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
// The vertex attributes are assumed to be the same for all elements in the
|
|
|
|
// unmerged batch since the material (and so the shaders) is the same.
|
|
|
|
QSGGeometry *g = gn->geometry();
|
2013-08-14 05:27:07 +00:00
|
|
|
QSGMaterial *material = gn->activeMaterial();
|
2020-05-06 12:16:05 +00:00
|
|
|
ShaderManager::Shader *sms = m_shaderManager->prepareMaterialNoRewrite(material, g);
|
2014-03-06 12:59:42 +00:00
|
|
|
if (!sms)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
return false;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
Q_ASSERT(sms->programRhi.program);
|
|
|
|
if (m_currentShader != sms)
|
|
|
|
setActiveRhiShader(sms->programRhi.program, sms);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
m_current_opacity = gn->inheritedOpacity();
|
|
|
|
if (sms->lastOpacity != m_current_opacity) {
|
|
|
|
dirty |= QSGMaterialShader::RenderState::DirtyOpacity;
|
|
|
|
sms->lastOpacity = m_current_opacity;
|
|
|
|
}
|
|
|
|
|
2013-12-07 08:41:44 +00:00
|
|
|
QMatrix4x4 rootMatrix = batch->root ? qsg_matrixForRoot(batch->root) : QMatrix4x4();
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShaderPrivate *pd = QSGMaterialShaderPrivate::get(sms->programRhi.program);
|
2022-07-08 08:15:58 +00:00
|
|
|
const quint32 ubufSize = quint32(pd->masterUniformData.size());
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (pd->ubufBinding >= 0) {
|
2022-07-08 08:15:58 +00:00
|
|
|
quint32 totalUBufSize = 0;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
while (e) {
|
|
|
|
totalUBufSize += aligned(ubufSize, m_ubufAlignment);
|
|
|
|
e = e->nextInBatch;
|
|
|
|
}
|
|
|
|
bool ubufRebuild = false;
|
|
|
|
if (!batch->ubuf) {
|
|
|
|
batch->ubuf = m_rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, totalUBufSize);
|
|
|
|
ubufRebuild = true;
|
|
|
|
} else {
|
|
|
|
if (batch->ubuf->size() < totalUBufSize) {
|
|
|
|
batch->ubuf->setSize(totalUBufSize);
|
|
|
|
ubufRebuild = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ubufRebuild) {
|
|
|
|
batch->ubufDataValid = false;
|
2020-05-27 15:54:41 +00:00
|
|
|
if (!batch->ubuf->create()) {
|
2022-07-08 08:15:58 +00:00
|
|
|
qWarning("Failed to build uniform buffer of size %u bytes", totalUBufSize);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
delete batch->ubuf;
|
|
|
|
batch->ubuf = nullptr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShader::RenderState renderState = state(QSGMaterialShader::RenderState::DirtyStates(int(dirty)));
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
bool pendingGStatePop = false;
|
2019-09-16 15:44:16 +00:00
|
|
|
updateMaterialStaticData(sms, renderState,
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
material, batch, &pendingGStatePop);
|
|
|
|
|
|
|
|
int ubufOffset = 0;
|
|
|
|
QRhiGraphicsPipeline *ps = nullptr;
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
QRhiGraphicsPipeline *depthPostPassPs = nullptr;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
e = batch->first;
|
2013-08-14 05:27:07 +00:00
|
|
|
while (e) {
|
|
|
|
gn = e->node;
|
|
|
|
|
|
|
|
m_current_model_view_matrix = rootMatrix * *gn->matrix();
|
|
|
|
m_current_determinant = m_current_model_view_matrix.determinant();
|
|
|
|
|
|
|
|
m_current_projection_matrix = projectionMatrix();
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
m_current_projection_matrix_native_ndc = projectionMatrixWithNativeNDC();
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
if (useDepthBuffer()) {
|
2014-01-21 12:28:53 +00:00
|
|
|
m_current_projection_matrix(2, 2) = m_zRange;
|
|
|
|
m_current_projection_matrix(2, 3) = 1.0f - e->order * m_zRange;
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2020-05-02 12:27:13 +00:00
|
|
|
QSGMaterialShader::RenderState renderState = state(QSGMaterialShader::RenderState::DirtyStates(int(dirty)));
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
updateMaterialDynamicData(sms, renderState, material, batch, e, ubufOffset, ubufSize);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2014-07-03 10:15:46 +00:00
|
|
|
#ifndef QT_NO_DEBUG
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (qsg_test_and_clear_material_failure()) {
|
|
|
|
qDebug("QSGMaterial::updateState() triggered an error (unmerged), batch will be skipped:");
|
|
|
|
qDebug() << " - offending node is" << e->node;
|
|
|
|
QSGNodeDumper::dump(rootNode());
|
|
|
|
qFatal("Aborting: scene graph is invalid...");
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-03 10:15:46 +00:00
|
|
|
#endif
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
ubufOffset += aligned(ubufSize, m_ubufAlignment);
|
|
|
|
|
|
|
|
const QSGGeometry::DrawingMode prevDrawMode = m_gstate.drawMode;
|
2019-06-24 14:53:46 +00:00
|
|
|
const float prevLineWidth = m_gstate.lineWidth;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
m_gstate.drawMode = QSGGeometry::DrawingMode(g->drawingMode());
|
2019-06-24 14:53:46 +00:00
|
|
|
m_gstate.lineWidth = g->lineWidth();
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
// Do not bother even looking up the ps if the topology has not changed
|
|
|
|
// since everything else is the same for all elements in the batch.
|
|
|
|
// (except if the material modified blend state)
|
2019-06-24 14:53:46 +00:00
|
|
|
if (!ps || m_gstate.drawMode != prevDrawMode || m_gstate.lineWidth != prevLineWidth || pendingGStatePop) {
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (!ensurePipelineState(e, sms)) {
|
|
|
|
if (pendingGStatePop)
|
|
|
|
m_gstate = m_gstateStack.pop();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ps = e->ps;
|
2020-06-11 10:35:04 +00:00
|
|
|
if (m_renderMode == QSGRendererInterface::RenderMode3D) {
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
m_gstateStack.push(m_gstate);
|
|
|
|
setStateForDepthPostPass();
|
|
|
|
ensurePipelineState(e, sms, true);
|
|
|
|
m_gstate = m_gstateStack.pop();
|
|
|
|
depthPostPassPs = e->depthPostPassPs;
|
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
} else {
|
|
|
|
e->ps = ps;
|
2020-06-11 10:35:04 +00:00
|
|
|
if (m_renderMode == QSGRendererInterface::RenderMode3D)
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
e->depthPostPassPs = depthPostPassPs;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
2013-11-06 11:08:42 +00:00
|
|
|
// We don't need to bother with asking each node for its material as they
|
|
|
|
// are all identical (compare==0) since they are in the same batch.
|
|
|
|
m_currentMaterial = material;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
// We only need to push this on the very first iteration...
|
|
|
|
dirty &= ~QSGMaterialShader::RenderState::DirtyOpacity;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
e = e->nextInBatch;
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (pendingGStatePop)
|
|
|
|
m_gstate = m_gstateStack.pop();
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
batch->ubufDataValid = true;
|
|
|
|
|
|
|
|
renderBatch->batch = batch;
|
|
|
|
renderBatch->sms = sms;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
void Renderer::renderUnmergedBatch(PreparedRenderBatch *renderBatch, bool depthPostPass)
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
const Batch *batch = renderBatch->batch;
|
2022-01-03 16:51:34 +00:00
|
|
|
if (!batch->vbo.buf)
|
|
|
|
return;
|
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
Element *e = batch->first;
|
|
|
|
|
|
|
|
if (batch->clipState.type & ClipState::StencilClip)
|
|
|
|
enqueueStencilDraw(batch);
|
|
|
|
|
2022-07-08 08:15:58 +00:00
|
|
|
quint32 vOffset = 0;
|
|
|
|
quint32 iOffset = 0;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
QRhiCommandBuffer *cb = commandBuffer();
|
|
|
|
|
|
|
|
while (e) {
|
2021-08-17 11:00:21 +00:00
|
|
|
QSGGeometry *g = e->node->geometry();
|
2019-06-24 14:53:46 +00:00
|
|
|
checkLineWidth(g);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
const int effectiveIndexSize = m_uint32IndexForRhi ? sizeof(quint32) : g->sizeOfIndex();
|
|
|
|
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
setGraphicsPipeline(cb, batch, e, depthPostPass);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
const QRhiCommandBuffer::VertexInput vbufBinding(batch->vbo.buf, vOffset);
|
|
|
|
if (g->indexCount()) {
|
2022-01-03 16:51:34 +00:00
|
|
|
if (batch->ibo.buf) {
|
|
|
|
cb->setVertexInput(VERTEX_BUFFER_BINDING, 1, &vbufBinding,
|
|
|
|
batch->ibo.buf, iOffset,
|
|
|
|
effectiveIndexSize == sizeof(quint32) ? QRhiCommandBuffer::IndexUInt32
|
|
|
|
: QRhiCommandBuffer::IndexUInt16);
|
|
|
|
cb->drawIndexed(g->indexCount());
|
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
} else {
|
|
|
|
cb->setVertexInput(VERTEX_BUFFER_BINDING, 1, &vbufBinding);
|
|
|
|
cb->draw(g->vertexCount());
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
vOffset += g->sizeOfVertex() * g->vertexCount();
|
|
|
|
iOffset += g->indexCount() * effectiveIndexSize;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
e = e->nextInBatch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
void Renderer::setGraphicsPipeline(QRhiCommandBuffer *cb, const Batch *batch, Element *e, bool depthPostPass)
|
2015-08-11 16:33:01 +00:00
|
|
|
{
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
cb->setGraphicsPipeline(depthPostPass ? e->depthPostPassPs : e->ps);
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
|
|
|
|
if (!m_pstate.viewportSet) {
|
|
|
|
m_pstate.viewportSet = true;
|
|
|
|
cb->setViewport(m_pstate.viewport);
|
|
|
|
}
|
|
|
|
if (batch->clipState.type & ClipState::ScissorClip) {
|
|
|
|
Q_ASSERT(e->ps->flags().testFlag(QRhiGraphicsPipeline::UsesScissor));
|
|
|
|
m_pstate.scissorSet = true;
|
|
|
|
cb->setScissor(batch->clipState.scissor);
|
|
|
|
} else {
|
|
|
|
Q_ASSERT(!e->ps->flags().testFlag(QRhiGraphicsPipeline::UsesScissor));
|
|
|
|
// Regardless of the ps not using scissor, the scissor may need to be
|
|
|
|
// reset, depending on the backend. So set the viewport again, which in
|
|
|
|
// turn also sets the scissor on backends where a scissor rect is
|
|
|
|
// always-on (Vulkan).
|
|
|
|
if (m_pstate.scissorSet) {
|
|
|
|
m_pstate.scissorSet = false;
|
|
|
|
cb->setViewport(m_pstate.viewport);
|
2018-01-18 13:42:41 +00:00
|
|
|
}
|
2015-08-11 16:33:01 +00:00
|
|
|
}
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
if (batch->clipState.type & ClipState::StencilClip) {
|
|
|
|
Q_ASSERT(e->ps->flags().testFlag(QRhiGraphicsPipeline::UsesStencilRef));
|
|
|
|
cb->setStencilRef(batch->clipState.stencilRef);
|
|
|
|
}
|
2020-06-09 17:51:12 +00:00
|
|
|
if (!depthPostPass && e->ps->flags().testFlag(QRhiGraphicsPipeline::UsesBlendConstants))
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
cb->setBlendConstants(batch->blendConstant);
|
|
|
|
|
|
|
|
cb->setShaderResources(e->srb);
|
2015-08-11 16:33:01 +00:00
|
|
|
}
|
|
|
|
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
void Renderer::releaseElement(Element *e, bool inDestructor)
|
|
|
|
{
|
|
|
|
if (e->isRenderNode) {
|
|
|
|
delete static_cast<RenderNodeElement *>(e);
|
|
|
|
} else {
|
|
|
|
if (e->srb) {
|
|
|
|
if (!inDestructor) {
|
|
|
|
if (m_shaderManager->srbPool.count() < m_srbPoolThreshold)
|
|
|
|
m_shaderManager->srbPool.insert(e->srb->serializedLayoutDescription(), e->srb);
|
|
|
|
else
|
|
|
|
delete e->srb;
|
|
|
|
} else {
|
|
|
|
delete e->srb;
|
|
|
|
}
|
|
|
|
e->srb = nullptr;
|
|
|
|
}
|
|
|
|
m_elementAllocator.release(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
void Renderer::deleteRemovedElements()
|
|
|
|
{
|
|
|
|
if (!m_elementsToDelete.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (int i=0; i<m_opaqueRenderList.size(); ++i) {
|
|
|
|
Element **e = m_opaqueRenderList.data() + i;
|
|
|
|
if (*e && (*e)->removed)
|
2018-02-21 09:41:54 +00:00
|
|
|
*e = nullptr;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
for (int i=0; i<m_alphaRenderList.size(); ++i) {
|
|
|
|
Element **e = m_alphaRenderList.data() + i;
|
|
|
|
if (*e && (*e)->removed)
|
2018-02-21 09:41:54 +00:00
|
|
|
*e = nullptr;
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
for (int i=0; i<m_elementsToDelete.size(); ++i)
|
|
|
|
releaseElement(m_elementsToDelete.at(i));
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
m_elementsToDelete.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::render()
|
|
|
|
{
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
// Gracefully handle the lack of a render target - some autotests may rely
|
|
|
|
// on this in odd cases.
|
2022-04-19 11:01:42 +00:00
|
|
|
if (!renderTarget().rt)
|
2020-05-06 16:25:23 +00:00
|
|
|
return;
|
|
|
|
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
prepareRenderPass(&m_mainRenderPassContext);
|
|
|
|
beginRenderPass(&m_mainRenderPassContext);
|
|
|
|
recordRenderPass(&m_mainRenderPassContext);
|
|
|
|
endRenderPass(&m_mainRenderPassContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
// An alternative to render() is to call prepareInline() and renderInline() at
|
|
|
|
// the appropriate times (i.e. outside of a QRhi::beginPass() and then inside,
|
|
|
|
// respectively) These allow rendering within a render pass that is started by
|
|
|
|
// another component. In contrast, render() records a full render pass on its
|
|
|
|
// own.
|
|
|
|
|
|
|
|
void Renderer::prepareInline()
|
|
|
|
{
|
|
|
|
prepareRenderPass(&m_mainRenderPassContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::renderInline()
|
|
|
|
{
|
|
|
|
recordRenderPass(&m_mainRenderPassContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::prepareRenderPass(RenderPassContext *ctx)
|
|
|
|
{
|
|
|
|
if (ctx->valid)
|
|
|
|
qWarning("prepareRenderPass() called with an already prepared render pass context");
|
|
|
|
|
|
|
|
ctx->valid = true;
|
|
|
|
|
2014-09-16 22:20:53 +00:00
|
|
|
if (Q_UNLIKELY(debug_dump())) {
|
2014-01-07 10:10:59 +00:00
|
|
|
qDebug("\n");
|
2013-08-14 05:27:07 +00:00
|
|
|
QSGNodeDumper::dump(rootNode());
|
|
|
|
}
|
|
|
|
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
ctx->timeRenderLists = 0;
|
|
|
|
ctx->timePrepareOpaque = 0;
|
|
|
|
ctx->timePrepareAlpha = 0;
|
|
|
|
ctx->timeSorting = 0;
|
|
|
|
ctx->timeUploadOpaque = 0;
|
|
|
|
ctx->timeUploadAlpha = 0;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2015-04-23 12:00:04 +00:00
|
|
|
if (Q_UNLIKELY(debug_render() || debug_build())) {
|
2013-08-14 05:27:07 +00:00
|
|
|
QByteArray type("rebuild:");
|
|
|
|
if (m_rebuild == 0)
|
|
|
|
type += " none";
|
|
|
|
if (m_rebuild == FullRebuild)
|
|
|
|
type += " full";
|
|
|
|
else {
|
|
|
|
if (m_rebuild & BuildRenderLists)
|
|
|
|
type += " renderlists";
|
|
|
|
else if (m_rebuild & BuildRenderListsForTaggedRoots)
|
|
|
|
type += " partial";
|
|
|
|
else if (m_rebuild & BuildBatches)
|
|
|
|
type += " batches";
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << "Renderer::render()" << this << type;
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
ctx->timer.start();
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
m_resourceUpdates = m_rhi->nextResourceUpdateBatch();
|
2015-01-29 16:18:49 +00:00
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
if (m_rebuild & (BuildRenderLists | BuildRenderListsForTaggedRoots)) {
|
|
|
|
bool complete = (m_rebuild & BuildRenderLists) != 0;
|
|
|
|
if (complete)
|
|
|
|
buildRenderListsFromScratch();
|
|
|
|
else
|
|
|
|
buildRenderListsForTaggedRoots();
|
|
|
|
m_rebuild |= BuildBatches;
|
|
|
|
|
2014-09-16 22:20:53 +00:00
|
|
|
if (Q_UNLIKELY(debug_build())) {
|
2018-02-13 08:57:29 +00:00
|
|
|
qDebug("Opaque render lists %s:", (complete ? "(complete)" : "(partial)"));
|
2013-08-14 05:27:07 +00:00
|
|
|
for (int i=0; i<m_opaqueRenderList.size(); ++i) {
|
|
|
|
Element *e = m_opaqueRenderList.at(i);
|
|
|
|
qDebug() << " - element:" << e << " batch:" << e->batch << " node:" << e->node << " order:" << e->order;
|
|
|
|
}
|
2018-02-13 08:57:29 +00:00
|
|
|
qDebug("Alpha render list %s:", complete ? "(complete)" : "(partial)");
|
2013-08-14 05:27:07 +00:00
|
|
|
for (int i=0; i<m_alphaRenderList.size(); ++i) {
|
|
|
|
Element *e = m_alphaRenderList.at(i);
|
|
|
|
qDebug() << " - element:" << e << " batch:" << e->batch << " node:" << e->node << " order:" << e->order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
if (Q_UNLIKELY(debug_render())) ctx->timeRenderLists = ctx->timer.restart();
|
2013-08-14 05:27:07 +00:00
|
|
|
|
|
|
|
for (int i=0; i<m_opaqueBatches.size(); ++i)
|
|
|
|
m_opaqueBatches.at(i)->cleanupRemovedElements();
|
|
|
|
for (int i=0; i<m_alphaBatches.size(); ++i)
|
|
|
|
m_alphaBatches.at(i)->cleanupRemovedElements();
|
|
|
|
deleteRemovedElements();
|
|
|
|
|
|
|
|
cleanupBatches(&m_opaqueBatches);
|
|
|
|
cleanupBatches(&m_alphaBatches);
|
|
|
|
|
|
|
|
if (m_rebuild & BuildBatches) {
|
|
|
|
prepareOpaqueBatches();
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
if (Q_UNLIKELY(debug_render())) ctx->timePrepareOpaque = ctx->timer.restart();
|
2013-08-14 05:27:07 +00:00
|
|
|
prepareAlphaBatches();
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
if (Q_UNLIKELY(debug_render())) ctx->timePrepareAlpha = ctx->timer.restart();
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2014-09-16 22:20:53 +00:00
|
|
|
if (Q_UNLIKELY(debug_build())) {
|
2018-02-13 08:57:29 +00:00
|
|
|
qDebug("Opaque Batches:");
|
2013-08-14 05:27:07 +00:00
|
|
|
for (int i=0; i<m_opaqueBatches.size(); ++i) {
|
|
|
|
Batch *b = m_opaqueBatches.at(i);
|
|
|
|
qDebug() << " - Batch " << i << b << (b->needsUpload ? "upload" : "") << " root:" << b->root;
|
|
|
|
for (Element *e = b->first; e; e = e->nextInBatch) {
|
|
|
|
qDebug() << " - element:" << e << " node:" << e->node << e->order;
|
|
|
|
}
|
|
|
|
}
|
2018-02-13 08:57:29 +00:00
|
|
|
qDebug("Alpha Batches:");
|
2013-08-14 05:27:07 +00:00
|
|
|
for (int i=0; i<m_alphaBatches.size(); ++i) {
|
|
|
|
Batch *b = m_alphaBatches.at(i);
|
|
|
|
qDebug() << " - Batch " << i << b << (b->needsUpload ? "upload" : "") << " root:" << b->root;
|
|
|
|
for (Element *e = b->first; e; e = e->nextInBatch) {
|
|
|
|
qDebug() << " - element:" << e << e->bounds << " node:" << e->node << " order:" << e->order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-23 12:00:04 +00:00
|
|
|
} else {
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
if (Q_UNLIKELY(debug_render())) ctx->timePrepareOpaque = ctx->timePrepareAlpha = ctx->timer.restart();
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-23 12:00:04 +00:00
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
deleteRemovedElements();
|
|
|
|
|
2014-03-04 14:30:29 +00:00
|
|
|
if (m_rebuild != 0) {
|
|
|
|
// Then sort opaque batches so that we're drawing the batches with the highest
|
|
|
|
// order first, maximizing the benefit of front-to-back z-ordering.
|
|
|
|
if (m_opaqueBatches.size())
|
|
|
|
std::sort(&m_opaqueBatches.first(), &m_opaqueBatches.last() + 1, qsg_sort_batch_decreasing_order);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2014-03-04 14:30:29 +00:00
|
|
|
// Sort alpha batches back to front so that they render correctly.
|
|
|
|
if (m_alphaBatches.size())
|
|
|
|
std::sort(&m_alphaBatches.first(), &m_alphaBatches.last() + 1, qsg_sort_batch_increasing_order);
|
|
|
|
|
2016-02-15 07:02:50 +00:00
|
|
|
m_zRange = m_nextRenderOrder != 0
|
|
|
|
? 1.0 / (m_nextRenderOrder)
|
|
|
|
: 0;
|
2014-03-04 14:30:29 +00:00
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
if (Q_UNLIKELY(debug_render())) ctx->timeSorting = ctx->timer.restart();
|
2015-04-23 12:00:04 +00:00
|
|
|
|
2022-07-08 08:15:58 +00:00
|
|
|
quint32 largestVBO = 0;
|
|
|
|
quint32 largestIBO = 0;
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2018-02-13 08:57:29 +00:00
|
|
|
if (Q_UNLIKELY(debug_upload())) qDebug("Uploading Opaque Batches:");
|
2015-01-06 07:40:21 +00:00
|
|
|
for (int i=0; i<m_opaqueBatches.size(); ++i) {
|
|
|
|
Batch *b = m_opaqueBatches.at(i);
|
|
|
|
largestVBO = qMax(b->vbo.size, largestVBO);
|
|
|
|
largestIBO = qMax(b->ibo.size, largestIBO);
|
|
|
|
uploadBatch(b);
|
|
|
|
}
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
if (Q_UNLIKELY(debug_render())) ctx->timeUploadOpaque = ctx->timer.restart();
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2018-02-13 08:57:29 +00:00
|
|
|
if (Q_UNLIKELY(debug_upload())) qDebug("Uploading Alpha Batches:");
|
2015-01-06 07:40:21 +00:00
|
|
|
for (int i=0; i<m_alphaBatches.size(); ++i) {
|
|
|
|
Batch *b = m_alphaBatches.at(i);
|
|
|
|
uploadBatch(b);
|
|
|
|
largestVBO = qMax(b->vbo.size, largestVBO);
|
|
|
|
largestIBO = qMax(b->ibo.size, largestIBO);
|
|
|
|
}
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
if (Q_UNLIKELY(debug_render())) ctx->timeUploadAlpha = ctx->timer.restart();
|
2015-01-06 07:40:21 +00:00
|
|
|
|
2022-07-08 08:15:58 +00:00
|
|
|
if (largestVBO * 2 < quint32(m_vertexUploadPool.size()))
|
2015-01-06 07:40:21 +00:00
|
|
|
m_vertexUploadPool.resize(largestVBO * 2);
|
2022-07-08 08:15:58 +00:00
|
|
|
if (largestIBO * 2 < quint32(m_indexUploadPool.size()))
|
2015-01-06 07:40:21 +00:00
|
|
|
m_indexUploadPool.resize(largestIBO * 2);
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2015-04-23 12:00:04 +00:00
|
|
|
if (Q_UNLIKELY(debug_render())) {
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
qDebug().nospace() << "Rendering:" << Qt::endl
|
|
|
|
<< " -> Opaque: " << qsg_countNodesInBatches(m_opaqueBatches) << " nodes in " << m_opaqueBatches.size() << " batches..." << Qt::endl
|
|
|
|
<< " -> Alpha: " << qsg_countNodesInBatches(m_alphaBatches) << " nodes in " << m_alphaBatches.size() << " batches...";
|
|
|
|
}
|
|
|
|
|
|
|
|
m_current_opacity = 1;
|
|
|
|
m_currentMaterial = nullptr;
|
|
|
|
m_currentShader = nullptr;
|
|
|
|
m_currentProgram = nullptr;
|
|
|
|
m_currentClipState.reset();
|
|
|
|
|
|
|
|
const QRect viewport = viewportRect();
|
|
|
|
|
|
|
|
bool renderOpaque = !debug_noopaque();
|
|
|
|
bool renderAlpha = !debug_noalpha();
|
|
|
|
|
|
|
|
m_pstate.viewport = QRhiViewport(viewport.x(), deviceRect().bottom() - viewport.bottom(), viewport.width(), viewport.height());
|
|
|
|
m_pstate.clearColor = clearColor();
|
|
|
|
m_pstate.dsClear = QRhiDepthStencilClearValue(1.0f, 0);
|
|
|
|
m_pstate.viewportSet = false;
|
|
|
|
m_pstate.scissorSet = false;
|
|
|
|
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
m_gstate.depthTest = useDepthBuffer();
|
|
|
|
m_gstate.depthWrite = useDepthBuffer();
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
m_gstate.depthFunc = QRhiGraphicsPipeline::Less;
|
|
|
|
m_gstate.blending = false;
|
|
|
|
|
|
|
|
m_gstate.cullMode = QRhiGraphicsPipeline::None;
|
2022-02-01 05:22:26 +00:00
|
|
|
m_gstate.polygonMode = QRhiGraphicsPipeline::Fill;
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
m_gstate.colorWrite = QRhiGraphicsPipeline::R
|
|
|
|
| QRhiGraphicsPipeline::G
|
|
|
|
| QRhiGraphicsPipeline::B
|
|
|
|
| QRhiGraphicsPipeline::A;
|
|
|
|
m_gstate.usesScissor = false;
|
|
|
|
m_gstate.stencilTest = false;
|
|
|
|
|
2022-04-19 11:01:42 +00:00
|
|
|
m_gstate.sampleCount = renderTarget().rt->sampleCount();
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
|
|
|
|
ctx->opaqueRenderBatches.clear();
|
|
|
|
if (Q_LIKELY(renderOpaque)) {
|
|
|
|
for (int i = 0, ie = m_opaqueBatches.size(); i != ie; ++i) {
|
|
|
|
Batch *b = m_opaqueBatches.at(i);
|
|
|
|
PreparedRenderBatch renderBatch;
|
|
|
|
bool ok;
|
|
|
|
if (b->merged)
|
|
|
|
ok = prepareRenderMergedBatch(b, &renderBatch);
|
|
|
|
else
|
|
|
|
ok = prepareRenderUnmergedBatch(b, &renderBatch);
|
|
|
|
if (ok)
|
|
|
|
ctx->opaqueRenderBatches.append(renderBatch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_gstate.blending = true;
|
|
|
|
// factors never change, always set for premultiplied alpha based blending
|
|
|
|
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
// depth test stays enabled (if useDepthBuffer(), that is) but no need
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
// to write out depth from the transparent (back-to-front) pass
|
|
|
|
m_gstate.depthWrite = false;
|
|
|
|
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
// special case: the 3D plane mode tests against the depth buffer, but does
|
|
|
|
// not write (and all batches are alpha because this render mode evaluates
|
|
|
|
// to useDepthBuffer()==false)
|
2020-06-11 10:35:04 +00:00
|
|
|
if (m_renderMode == QSGRendererInterface::RenderMode3D) {
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
Q_ASSERT(m_opaqueBatches.isEmpty());
|
|
|
|
m_gstate.depthTest = true;
|
|
|
|
}
|
|
|
|
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
ctx->alphaRenderBatches.clear();
|
|
|
|
if (Q_LIKELY(renderAlpha)) {
|
|
|
|
for (int i = 0, ie = m_alphaBatches.size(); i != ie; ++i) {
|
|
|
|
Batch *b = m_alphaBatches.at(i);
|
|
|
|
PreparedRenderBatch renderBatch;
|
|
|
|
bool ok;
|
|
|
|
if (b->merged)
|
|
|
|
ok = prepareRenderMergedBatch(b, &renderBatch);
|
|
|
|
else if (b->isRenderNode)
|
|
|
|
ok = prepareRhiRenderNode(b, &renderBatch);
|
|
|
|
else
|
|
|
|
ok = prepareRenderUnmergedBatch(b, &renderBatch);
|
|
|
|
if (ok)
|
|
|
|
ctx->alphaRenderBatches.append(renderBatch);
|
|
|
|
}
|
2015-04-23 12:00:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 05:27:07 +00:00
|
|
|
m_rebuild = 0;
|
2021-02-12 06:43:22 +00:00
|
|
|
|
|
|
|
#if defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
|
2014-03-19 10:58:04 +00:00
|
|
|
m_renderOrderRebuildLower = -1;
|
|
|
|
m_renderOrderRebuildUpper = -1;
|
2021-02-12 06:43:22 +00:00
|
|
|
#endif
|
2013-11-06 13:07:58 +00:00
|
|
|
|
2019-07-31 13:17:52 +00:00
|
|
|
if (m_visualizer->mode() != Visualizer::VisualizeNothing)
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
m_visualizer->prepareVisualize();
|
2013-12-07 08:41:44 +00:00
|
|
|
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
commandBuffer()->resourceUpdate(m_resourceUpdates);
|
|
|
|
m_resourceUpdates = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::beginRenderPass(RenderPassContext *)
|
|
|
|
{
|
2022-04-19 11:01:42 +00:00
|
|
|
commandBuffer()->beginPass(renderTarget().rt, m_pstate.clearColor, m_pstate.dsClear, nullptr,
|
2020-09-30 13:44:49 +00:00
|
|
|
// we cannot tell if the application will have
|
|
|
|
// native rendering thrown in to this pass
|
|
|
|
// (QQuickWindow::beginExternalCommands()), so
|
|
|
|
// we have no choice but to set the flag always
|
|
|
|
// (thus triggering using secondary command
|
|
|
|
// buffers with Vulkan)
|
|
|
|
QRhiCommandBuffer::ExternalContent);
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
|
|
|
|
if (m_renderPassRecordingCallbacks.start)
|
|
|
|
m_renderPassRecordingCallbacks.start(m_renderPassRecordingCallbacks.userData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Renderer::recordRenderPass(RenderPassContext *ctx)
|
|
|
|
{
|
|
|
|
// prepareRenderPass and recordRenderPass must always be called together.
|
|
|
|
// They are separate because beginRenderPass and endRenderPass are optional.
|
|
|
|
//
|
|
|
|
// The valid call sequence are therefore:
|
|
|
|
// prepare, begin, record, end
|
|
|
|
// or
|
|
|
|
// prepare, record
|
|
|
|
|
|
|
|
if (!ctx->valid)
|
|
|
|
qWarning("recordRenderPass() called without a prepared render pass context");
|
|
|
|
|
|
|
|
ctx->valid = false;
|
|
|
|
|
|
|
|
QRhiCommandBuffer *cb = commandBuffer();
|
|
|
|
cb->debugMarkBegin(QByteArrayLiteral("Qt Quick scene render"));
|
|
|
|
|
|
|
|
for (int i = 0, ie = ctx->opaqueRenderBatches.count(); i != ie; ++i) {
|
|
|
|
PreparedRenderBatch *renderBatch = &ctx->opaqueRenderBatches[i];
|
|
|
|
if (renderBatch->batch->merged)
|
|
|
|
renderMergedBatch(renderBatch);
|
|
|
|
else
|
|
|
|
renderUnmergedBatch(renderBatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0, ie = ctx->alphaRenderBatches.count(); i != ie; ++i) {
|
|
|
|
PreparedRenderBatch *renderBatch = &ctx->alphaRenderBatches[i];
|
|
|
|
if (renderBatch->batch->merged)
|
|
|
|
renderMergedBatch(renderBatch);
|
|
|
|
else if (renderBatch->batch->isRenderNode)
|
|
|
|
renderRhiRenderNode(renderBatch->batch);
|
|
|
|
else
|
|
|
|
renderUnmergedBatch(renderBatch);
|
|
|
|
}
|
2019-07-31 13:17:52 +00:00
|
|
|
|
2020-06-11 10:35:04 +00:00
|
|
|
if (m_renderMode == QSGRendererInterface::RenderMode3D) {
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
// depth post-pass
|
|
|
|
for (int i = 0, ie = ctx->alphaRenderBatches.count(); i != ie; ++i) {
|
|
|
|
PreparedRenderBatch *renderBatch = &ctx->alphaRenderBatches[i];
|
|
|
|
if (renderBatch->batch->merged)
|
|
|
|
renderMergedBatch(renderBatch, true);
|
|
|
|
else if (!renderBatch->batch->isRenderNode) // rendernodes are skipped here for now
|
|
|
|
renderUnmergedBatch(renderBatch, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
if (m_currentShader)
|
|
|
|
setActiveRhiShader(nullptr, nullptr);
|
|
|
|
|
|
|
|
cb->debugMarkEnd();
|
|
|
|
|
|
|
|
if (Q_UNLIKELY(debug_render())) {
|
|
|
|
qDebug(" -> times: build: %d, prepare(opaque/alpha): %d/%d, sorting: %d, upload(opaque/alpha): %d/%d, record rendering: %d",
|
|
|
|
(int) ctx->timeRenderLists,
|
|
|
|
(int) ctx->timePrepareOpaque, (int) ctx->timePrepareAlpha,
|
|
|
|
(int) ctx->timeSorting,
|
|
|
|
(int) ctx->timeUploadOpaque, (int) ctx->timeUploadAlpha,
|
|
|
|
(int) ctx->timer.elapsed());
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
|
|
|
|
Enable invoking the scenegraph rendering without a full render pass
Split the monolithic render() and renderBatches() into four steps
(prepare, begin-pass, render, end-pass), of which two are optional.
The behavior of the batch renderer's render() (the entry point when
rendering a Qt Quick scene normally) remains unchanged: it just calls
prepare, beginPass, render, endPass which together should boil down to
exactly what the monolithic implementation was doing before.
However, we can now also support recording rendering of the 2D scene
as part of a render pass that is started by something else (e.g. the 3D
scene). To enable this, the renderer interface gets prepareInline() and
renderInline() virtuals that are only implemented by the batch renderer
(and are no-ops by default).
These are complemented by prepareSceneLine() and renderSceneInline()
which are public (as in the class, not API-wise), like renderScene().
The former does preprocess() and triggers the internal prepareInline(),
whereas renderSceneLine() is where renderInline() is called from. The
rendercontext has no corresponding wrappers since one can just directly
call these on the QSGRenderer.
Change-Id: Iddfcec6970bad2bc73e6e8af19fe95d16c6ac9e5
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
2020-05-22 12:14:13 +00:00
|
|
|
void Renderer::endRenderPass(RenderPassContext *)
|
|
|
|
{
|
|
|
|
if (m_renderPassRecordingCallbacks.end)
|
|
|
|
m_renderPassRecordingCallbacks.end(m_renderPassRecordingCallbacks.userData);
|
|
|
|
|
|
|
|
if (m_visualizer->mode() != Visualizer::VisualizeNothing)
|
|
|
|
m_visualizer->visualize();
|
|
|
|
|
|
|
|
commandBuffer()->endPass();
|
|
|
|
}
|
|
|
|
|
2016-04-13 10:33:00 +00:00
|
|
|
struct RenderNodeState : public QSGRenderNode::RenderState
|
|
|
|
{
|
|
|
|
const QMatrix4x4 *projectionMatrix() const override { return m_projectionMatrix; }
|
2016-07-05 08:27:19 +00:00
|
|
|
QRect scissorRect() const override { return m_scissorRect; }
|
|
|
|
bool scissorEnabled() const override { return m_scissorEnabled; }
|
|
|
|
int stencilValue() const override { return m_stencilValue; }
|
|
|
|
bool stencilEnabled() const override { return m_stencilEnabled; }
|
2016-07-15 11:43:08 +00:00
|
|
|
const QRegion *clipRegion() const override { return nullptr; }
|
2016-04-13 10:33:00 +00:00
|
|
|
|
|
|
|
const QMatrix4x4 *m_projectionMatrix;
|
|
|
|
QRect m_scissorRect;
|
|
|
|
int m_stencilValue;
|
2016-07-05 08:30:01 +00:00
|
|
|
bool m_scissorEnabled;
|
2016-04-13 10:33:00 +00:00
|
|
|
bool m_stencilEnabled;
|
|
|
|
};
|
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
bool Renderer::prepareRhiRenderNode(Batch *batch, PreparedRenderBatch *renderBatch)
|
2019-08-07 13:27:24 +00:00
|
|
|
{
|
|
|
|
if (Q_UNLIKELY(debug_render()))
|
|
|
|
qDebug() << " -" << batch << "rendernode";
|
|
|
|
|
|
|
|
Q_ASSERT(batch->first->isRenderNode);
|
|
|
|
RenderNodeElement *e = static_cast<RenderNodeElement *>(batch->first);
|
|
|
|
|
|
|
|
setActiveRhiShader(nullptr, nullptr);
|
|
|
|
|
|
|
|
QSGRenderNodePrivate *rd = QSGRenderNodePrivate::get(e->renderNode);
|
|
|
|
rd->m_clip_list = nullptr;
|
2020-06-11 10:35:04 +00:00
|
|
|
if (m_renderMode != QSGRendererInterface::RenderMode3D) {
|
2020-06-09 15:06:02 +00:00
|
|
|
QSGNode *clip = e->renderNode->parent();
|
|
|
|
while (clip != rootNode()) {
|
|
|
|
if (clip->type() == QSGNode::ClipNodeType) {
|
|
|
|
rd->m_clip_list = static_cast<QSGClipNode *>(clip);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
clip = clip->parent();
|
2019-08-07 13:27:24 +00:00
|
|
|
}
|
2020-06-09 15:06:02 +00:00
|
|
|
updateClipState(rd->m_clip_list, batch);
|
2019-08-07 13:27:24 +00:00
|
|
|
}
|
|
|
|
|
2020-03-10 14:34:13 +00:00
|
|
|
QSGNode *xform = e->renderNode->parent();
|
|
|
|
QMatrix4x4 matrix;
|
|
|
|
QSGNode *root = rootNode();
|
|
|
|
if (e->root) {
|
|
|
|
matrix = qsg_matrixForRoot(e->root);
|
|
|
|
root = e->root->sgNode;
|
|
|
|
}
|
|
|
|
while (xform != root) {
|
|
|
|
if (xform->type() == QSGNode::TransformNodeType) {
|
|
|
|
matrix = matrix * static_cast<QSGTransformNode *>(xform)->combinedMatrix();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
xform = xform->parent();
|
|
|
|
}
|
|
|
|
rd->m_matrix = &matrix;
|
|
|
|
|
|
|
|
QSGNode *opacity = e->renderNode->parent();
|
|
|
|
rd->m_opacity = 1.0;
|
|
|
|
while (opacity != rootNode()) {
|
|
|
|
if (opacity->type() == QSGNode::OpacityNodeType) {
|
|
|
|
rd->m_opacity = static_cast<QSGOpacityNode *>(opacity)->combinedOpacity();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
opacity = opacity->parent();
|
|
|
|
}
|
|
|
|
|
2020-05-02 11:05:29 +00:00
|
|
|
e->renderNode->prepare();
|
2020-03-10 14:34:13 +00:00
|
|
|
|
2019-08-07 13:27:24 +00:00
|
|
|
renderBatch->batch = batch;
|
|
|
|
renderBatch->sms = nullptr;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-06 12:16:05 +00:00
|
|
|
void Renderer::renderRhiRenderNode(const Batch *batch)
|
2019-08-07 13:27:24 +00:00
|
|
|
{
|
|
|
|
if (batch->clipState.type & ClipState::StencilClip)
|
|
|
|
enqueueStencilDraw(batch);
|
|
|
|
|
|
|
|
RenderNodeElement *e = static_cast<RenderNodeElement *>(batch->first);
|
|
|
|
QSGRenderNodePrivate *rd = QSGRenderNodePrivate::get(e->renderNode);
|
|
|
|
|
|
|
|
QMatrix4x4 pm = projectionMatrix();
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
if (useDepthBuffer()) {
|
2019-08-07 13:27:24 +00:00
|
|
|
pm(2, 2) = m_zRange;
|
|
|
|
pm(2, 3) = 1.0f - e->order * m_zRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderNodeState state;
|
|
|
|
state.m_projectionMatrix = ±
|
|
|
|
const std::array<int, 4> scissor = batch->clipState.scissor.scissor();
|
|
|
|
state.m_scissorRect = QRect(scissor[0], scissor[1], scissor[2], scissor[3]);
|
|
|
|
state.m_stencilValue = batch->clipState.stencilRef;
|
|
|
|
state.m_scissorEnabled = batch->clipState.type & ClipState::ScissorClip;
|
|
|
|
state.m_stencilEnabled = batch->clipState.type & ClipState::StencilClip;
|
|
|
|
|
|
|
|
const QSGRenderNode::StateFlags changes = e->renderNode->changedStates();
|
|
|
|
|
|
|
|
QRhiCommandBuffer *cb = commandBuffer();
|
2020-05-02 11:05:29 +00:00
|
|
|
const bool needsExternal = !e->renderNode->flags().testFlag(QSGRenderNode::NoExternalRendering);
|
2020-03-10 14:34:13 +00:00
|
|
|
if (needsExternal)
|
|
|
|
cb->beginExternal();
|
2019-08-07 13:27:24 +00:00
|
|
|
e->renderNode->render(&state);
|
2020-03-10 14:34:13 +00:00
|
|
|
if (needsExternal)
|
|
|
|
cb->endExternal();
|
2019-08-07 13:27:24 +00:00
|
|
|
|
|
|
|
rd->m_matrix = nullptr;
|
|
|
|
rd->m_clip_list = nullptr;
|
|
|
|
|
2019-08-16 12:21:15 +00:00
|
|
|
if ((changes & QSGRenderNode::ViewportState)
|
|
|
|
|| (changes & QSGRenderNode::ScissorState))
|
|
|
|
{
|
|
|
|
// Reset both flags if either is reported as changed, since with the rhi
|
|
|
|
// it could be setViewport() that will record the resetting of the scissor.
|
2019-08-07 13:27:24 +00:00
|
|
|
m_pstate.viewportSet = false;
|
|
|
|
m_pstate.scissorSet = false;
|
2019-08-16 12:21:15 +00:00
|
|
|
}
|
2019-08-07 13:27:24 +00:00
|
|
|
|
|
|
|
// Do not bother with RenderTargetState. Where applicable, endExternal()
|
|
|
|
// ensures the correct target is rebound. For others (like Vulkan) it makes
|
|
|
|
// no sense since render() could not possibly do that on our command buffer
|
|
|
|
// which is in renderpass recording state.
|
|
|
|
}
|
|
|
|
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
void Renderer::setVisualizationMode(const QByteArray &mode)
|
2013-12-07 08:41:44 +00:00
|
|
|
{
|
2019-07-31 13:17:52 +00:00
|
|
|
if (mode.isEmpty())
|
|
|
|
m_visualizer->setMode(Visualizer::VisualizeNothing);
|
|
|
|
else if (mode == "clip")
|
|
|
|
m_visualizer->setMode(Visualizer::VisualizeClipping);
|
|
|
|
else if (mode == "overdraw")
|
|
|
|
m_visualizer->setMode(Visualizer::VisualizeOverdraw);
|
|
|
|
else if (mode == "batches")
|
|
|
|
m_visualizer->setMode(Visualizer::VisualizeBatches);
|
|
|
|
else if (mode == "changes")
|
|
|
|
m_visualizer->setMode(Visualizer::VisualizeChanges);
|
2013-12-07 08:41:44 +00:00
|
|
|
}
|
|
|
|
|
Add perspective 3D plane render mode
One can now do rc->createRenderer(QSGRenderContext::RenderMode3D) in Quick3D.
By default nothing changes, both QQuickWindow and QSGRhiLayer default to
either RenderMode2D or RenderMode2DNoDepthBuffer, depending on
QSG_NO_DEPTH_BUFFER. (the environment variable handling is moved out of
qsgbatchrenderer.cpp however, leaving it up to whoever is creating the
renderer to passing the appropriate flag)
The RenderMode3D mode is a modified version of the QSG_NO_DEPTH_BUFFER case:
only alpha batches are used, which are then rendered back to front. The
difference is that this is done with depth test on (no write), so the
2D content gets depth tested against whatever is already in the depth buffer.
Then, there's an additional depth "post pass" to fill the depth buffer with the
2D content. This must be separate from the color-write enabled stage because
otherwise unavoidable Z fighting would occur. By filling the depth buffer,
other 3D or 2D content, that is rendered afterwards, can depth test correctly
against the 2D elements rendered here.
customRenderMode and related functions are renamed to visualization
(because that's what it is about), in order to prevent confusing name
clashes.
Change-Id: I0d43b273e0a8020af05a652a236c0ad5fb150685
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2020-06-05 16:10:30 +00:00
|
|
|
bool Renderer::hasVisualizationModeWithContinuousUpdate() const
|
2013-12-07 08:41:44 +00:00
|
|
|
{
|
2019-07-31 13:17:52 +00:00
|
|
|
return m_visualizer->mode() == Visualizer::VisualizeOverdraw;
|
2013-12-07 08:41:44 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 15:00:24 +00:00
|
|
|
bool operator==(const GraphicsState &a, const GraphicsState &b) noexcept
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
return a.depthTest == b.depthTest
|
|
|
|
&& a.depthWrite == b.depthWrite
|
|
|
|
&& a.depthFunc == b.depthFunc
|
|
|
|
&& a.blending == b.blending
|
|
|
|
&& a.srcColor == b.srcColor
|
|
|
|
&& a.dstColor == b.dstColor
|
2022-06-15 11:17:11 +00:00
|
|
|
&& a.srcAlpha == b.srcAlpha
|
|
|
|
&& a.dstAlpha == b.dstAlpha
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
&& a.colorWrite == b.colorWrite
|
|
|
|
&& a.cullMode == b.cullMode
|
|
|
|
&& a.usesScissor == b.usesScissor
|
|
|
|
&& a.stencilTest == b.stencilTest
|
|
|
|
&& a.sampleCount == b.sampleCount
|
2019-06-24 14:53:46 +00:00
|
|
|
&& a.drawMode == b.drawMode
|
2022-02-01 05:22:26 +00:00
|
|
|
&& a.lineWidth == b.lineWidth
|
|
|
|
&& a.polygonMode == b.polygonMode;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 15:00:24 +00:00
|
|
|
bool operator!=(const GraphicsState &a, const GraphicsState &b) noexcept
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
2020-10-30 15:00:24 +00:00
|
|
|
size_t qHash(const GraphicsState &s, size_t seed) noexcept
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
// do not bother with all fields
|
|
|
|
return seed
|
|
|
|
+ s.depthTest * 1000
|
|
|
|
+ s.depthWrite * 100
|
|
|
|
+ s.depthFunc
|
|
|
|
+ s.blending * 10
|
|
|
|
+ s.srcColor
|
|
|
|
+ s.cullMode
|
|
|
|
+ s.usesScissor
|
|
|
|
+ s.stencilTest
|
|
|
|
+ s.sampleCount;
|
|
|
|
}
|
|
|
|
|
2020-10-30 15:00:24 +00:00
|
|
|
bool operator==(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) noexcept
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
return a.state == b.state
|
|
|
|
&& a.sms->programRhi.program == b.sms->programRhi.program
|
Get rid of renderpass descriptor objects from the pipeline cache keys
Follow what we did to the srb: instead of storing an object reference,
store an opaque blob to test for compatibility. This works even if the
object is destroyed in the meantime. Thus, the annoying and error-prone
invalidatePipelineCacheDependency() goes away, finally.
All this works because creating a QRhiGraphicsPipeline with a given
QRhiRenderPassDescriptor only needs the renderpass object for building
(as in create()). Afterwards the object can be destroyed, even. The
pipeline is still usable with any render targets that have a
_compatible_ rp descriptor. Therefore, it is ideal if there is a way
to test for this compatibility without having to have the original
object around for ever.
Relies on enablers (most importantly,
QRhiRenderPassDescriptor::serializedFormat()) added to QRhi in qtbase.
While not necessarily obvious, the real benefit here is significant
performance gains in certain situations: consider rendering a scene to a
given render target, then to another one, then yet another one, for
example via QQuickRenderControl. We no longer have to do aggressive
purging of the pipelines just because a QRhiRenderPassDescriptor some of
the recently created pipelines may be associated with is going to
disappear. Rather, everything can stay as-is, there are no crashes due
to dangling pointers in the pipeline cache keys. The majority
of cases involve highly compatible render targets (e.g. rendering
into textures of the same format), so reuse is highly beneficial.
Pick-to: 6.2
Change-Id: I8ad4bfcb3c7e66c7364c91a749e2a2e6837b4f1a
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-09-15 12:07:15 +00:00
|
|
|
&& a.renderTargetDescription == b.renderTargetDescription
|
Remove the per-rendercontext srb cache
Remove the srbCache which is effectively a map of unbounded size.
Depending on scene structure and changes to the scene that trigger
rebuilding the batching structures of the scenegraph, it can grow
unexpectedly large, potentially growing continuously on every frame,
with animated scenes that manage to trigger the "right" kind of
changes to the scene.
Other similar structures, such as the graphics pipeline or the sampler
tables have a known maximum size, because we know that there can only
be a certain number of combinations in the values that form the keys
to the map. Whereas with QRhiShaderResourceBindings objects the key is
the full binding list, including the QRhiBuffer/Texture/Sampler
pointers.
This becomes complex pretty quickly when combined with the internal
mechanisms of the scenegraph's batching system and the lifecycle of
these QRhiResource objects. For instance, uniform buffers live in
Batch, which is a pooled, (semi-)transient object: changes to the
scene that lead to full or partial rebuild will generate a new set of
Batches, meaning a QSGGeometryNode can be associated with a different
QRhiBuffer afterwards (not that we create new buffers all the time,
they are reused, but they can be associated with different nodes over
their lifetime). Which then means that to render the node, we now need
a different srb as well (that references the correct
QRhiBuffer). Depending on the scene and how it changes over time, this
may lead to an explosive number of combinations, thus a "continuously"
growing srbCache map, inserting more and more new entries, while
leaving perhaps-unused entries in there for ever. Trimming is far from
trivial as the costs of managing the purging of unused entries is
likely more expensive than not having the "cache" in the first place.
Thus, drop the whole data structure and give ownership of the srb to
Element (which is the object in the shadow tree for each
QSGGeometryNode). To not completely degrade performance, this needs
some new enablers in QRhi, namely the ability to have a fast path for
replacing the QRhiResources (buffers, textures, samplers) in the
binding list of an already baked srb without having to go through full
rebaking. (e.g. with Vulkan, we want to reuse all the existing
descriptor set layouts and the descriptor sets themselves, it's just
the descriptors themselves that need new values written)
So now, instead of looking up in a QHash, we first compare the full
binding list (this is what one gets with the QHash when there's a hit
anyway: at minimum the binding list is hashed and then compared). If
this matches then fine (and we saved the time spent on hashing even).
Then, if there's a mismatch, we now do a layout-only comparison. If
this matches, then we use the new enablers in QRhi to do a "light
update" (different resources, but same binding points, types, etc.) to
the srb. Finally, if there was a mismatch here too, we go through
create() to do a full rebuild.
Therefore, the performance effects of this patch depend heavily on the
scene. Scenes that do not do changes that trigger re-batching often
may see improvements even. Others are assumed to have small or
negligible consequences with regards to performance (due to now
spending time on a layout-compatible comparison of binding lists which
was not there before). In return, we do not need to have the srbCache
QHash at all, leading to, with scenes exhibiting the relevant
patterns, significantly reduced memory usage.
Once srbCache is gone, the following issues need to be handled:
First, now that the srb ownership stays with the shadow node
(Element), instead of guaranteed to stay around for ever in an srb
cache data structure, throwing references into the keys used to look
up pipelines is problematic (and was never nice to begin with).
Get rid of this, building on the new QRhi API that gives us a list of
uints that can be used to test for layout compatibility. The
container is implicitly shared, which makes the switch quite simple
and efficient.
Second, all this does not mean that some sort of reuse of srb objects
is not needed. Consider scrolling a list view. Nodes (and so shadow
nodes, i.e. Element objects) come and go in this case. Creating full
new srb objects for the Elements for the list items becoming visible
is not ideal. (even if only really dubious with Vulkan, where there
are true Vulkan API objects underneath)
To facilitate reuse, reintroduce an srb pool in ShaderManager, but
this time with different semantics: this stores unused srb objects,
with the serialized layout description as the key. When a new Element
needs an srb, we try to pick a (layout compatible) srb from this
pool. If there is a match, the Element gets the srb with ownership,
and the srb is removed from the pool. When an Element is about to go
away, its srb may be "moved" to the pool when the pool is not too
large already. The threshold for being too large is currently simply
1024 elements (in the QMultiHash). This can be overridden with an
environment variable, although that should pretty much be never needed
in practice.
Pick-to: 6.2
Fixes: QTBUG-96130
Change-Id: Ie5a49beeb6dea0db6a81fdceebf39374ad192b0e
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
2021-08-31 16:27:50 +00:00
|
|
|
&& a.srbLayoutDescription == b.srbLayoutDescription;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 15:00:24 +00:00
|
|
|
bool operator!=(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) noexcept
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
2020-10-30 15:00:24 +00:00
|
|
|
size_t qHash(const GraphicsPipelineStateKey &k, size_t seed) noexcept
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
{
|
Get rid of renderpass descriptor objects from the pipeline cache keys
Follow what we did to the srb: instead of storing an object reference,
store an opaque blob to test for compatibility. This works even if the
object is destroyed in the meantime. Thus, the annoying and error-prone
invalidatePipelineCacheDependency() goes away, finally.
All this works because creating a QRhiGraphicsPipeline with a given
QRhiRenderPassDescriptor only needs the renderpass object for building
(as in create()). Afterwards the object can be destroyed, even. The
pipeline is still usable with any render targets that have a
_compatible_ rp descriptor. Therefore, it is ideal if there is a way
to test for this compatibility without having to have the original
object around for ever.
Relies on enablers (most importantly,
QRhiRenderPassDescriptor::serializedFormat()) added to QRhi in qtbase.
While not necessarily obvious, the real benefit here is significant
performance gains in certain situations: consider rendering a scene to a
given render target, then to another one, then yet another one, for
example via QQuickRenderControl. We no longer have to do aggressive
purging of the pipelines just because a QRhiRenderPassDescriptor some of
the recently created pipelines may be associated with is going to
disappear. Rather, everything can stay as-is, there are no crashes due
to dangling pointers in the pipeline cache keys. The majority
of cases involve highly compatible render targets (e.g. rendering
into textures of the same format), so reuse is highly beneficial.
Pick-to: 6.2
Change-Id: I8ad4bfcb3c7e66c7364c91a749e2a2e6837b4f1a
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
2021-09-15 12:07:15 +00:00
|
|
|
return qHash(k.state, seed)
|
|
|
|
^ qHash(k.sms->programRhi.program)
|
|
|
|
^ k.extra.renderTargetDescriptionHash
|
|
|
|
^ k.extra.srbLayoutDescriptionHash;
|
Add the graphics api independent scenegraph port
Opt in via environment variables:
QSG_RHI=1 -> enable using QRhi instead of GL
QSG_RHI_BACKEND -> set to vulkan, metal, d3d11, gl to override the default
(the default is d3d11 on Windows, metal on Mac, gl elsewhere)
Or force a given rhi backend via the existing
QQuickWindow::setSceneGraphBackend().
Otherwise the default behavior is the same as before, the rhi code path
is never active by default.
-no-opengl builds are supported in the sense that they work and default
to the software backend. However, the rhi code path cannot currently be
used in such builds, even though QRhi from qtbase is fully functional
with Vulkan, D3D, or Metal even when qtbase was configured with
-no-opengl. This cannot be utilized by Quick atm due to OpenGL usage
being all over the place in the sources corresponding to the default
backend, and those host the rhi code path as well. This will be cleaned up
hopefully in Qt 6, with the removal all direct OpenGL usage.
Other env.vars.:
QSG_RHI_DEBUG_LAYER=1 -> enable D3D debug or Vulkan validation layer
(assuming the system is set up for this)
QSG_RHI_SHADEREFFECT_DEBUG=1 -> print stuff from ShaderEffect
QSG_SAMPLES=1,2,4,... -> MSAA sample count (but QSurfaceFormat works too)
QT_D3D_ADAPTER_INDEX=0,1,... -> D3D adapter index
QT_VK_PHYSICAL_DEVICE_INDEX=0,1,... -> Vulkan physical device index
QSG_RHI_UINT32_INDEX=1 -> always use uint index data (both
merged/unmerged, convert when needed - with some rhi backends this is
implicit)
QSG_RENDER_LOOP -> to override the render loop as usual. The default
with RHI is threaded for Metal, threaded for Vulkan on Windows, basic
for Vulkan on Linux and Android (to be checked later), while the existing
rules apply for OpenGL.
Not supported when running with QRhi:
- particles
- compressed atlases (though this is transparent to the apps)
- QSGRenderNode
- QQuickRenderControl
- QQuickFramebufferObject
- certain QQuickWindow functionality that depends directly on OpenGL
- anisotropic filtering for textures
- native text may lack some gamma correction
- QSGEngine applicability unclear
- some QML profiler logs may be incorrect or irrelevant
Change-Id: I7822e99ad79e342e4166275da6e9e66498d76521
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2019-04-23 07:40:59 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:17:52 +00:00
|
|
|
Visualizer::Visualizer(Renderer *renderer)
|
|
|
|
: m_renderer(renderer),
|
|
|
|
m_visualizeMode(VisualizeNothing)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Visualizer::~Visualizer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#define QSGNODE_DIRTY_PARENT (QSGNode::DirtyNodeAdded \
|
|
|
|
| QSGNode::DirtyOpacity \
|
|
|
|
| QSGNode::DirtyMatrix \
|
|
|
|
| QSGNode::DirtyNodeRemoved)
|
2013-08-14 05:27:07 +00:00
|
|
|
|
2019-07-31 13:17:52 +00:00
|
|
|
void Visualizer::visualizeChangesPrepare(Node *n, uint parentChanges)
|
|
|
|
{
|
|
|
|
uint childDirty = (parentChanges | n->dirtyState) & QSGNODE_DIRTY_PARENT;
|
|
|
|
uint selfDirty = n->dirtyState | parentChanges;
|
|
|
|
if (n->type() == QSGNode::GeometryNodeType && selfDirty != 0)
|
|
|
|
m_visualizeChangeSet.insert(n, selfDirty);
|
|
|
|
SHADOWNODE_TRAVERSE(n) {
|
|
|
|
visualizeChangesPrepare(child, childDirty);
|
|
|
|
}
|
2013-08-14 05:27:07 +00:00
|
|
|
}
|
2017-04-25 21:08:46 +00:00
|
|
|
|
2019-07-31 13:17:52 +00:00
|
|
|
} // namespace QSGBatchRenderer
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2017-04-25 21:08:46 +00:00
|
|
|
#include "moc_qsgbatchrenderer_p.cpp"
|