aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h')
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h126
1 files changed, 61 insertions, 65 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
index a42c41304f..a84797a4c6 100644
--- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
+++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h
@@ -1,43 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
-** Copyright (C) 2016 Robin Burchell <robin.burchell@viroteck.net>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 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
#ifndef QSGBATCHRENDERER_P_H
#define QSGBATCHRENDERER_P_H
@@ -63,7 +27,7 @@
#include <QtCore/QBitArray>
#include <QtCore/QStack>
-#include <QtGui/private/qrhi_p.h>
+#include <rhi/qrhi.h>
QT_BEGIN_NAMESPACE
@@ -151,7 +115,7 @@ public:
// one. when an item is released, we'll reset m_freePage anyway.
if (!p) {
p = new AllocatorPage<Type, PageSize>();
- m_freePage = pages.count();
+ m_freePage = pages.size();
pages.push_back(p);
}
uint pos = p->blocks[PageSize - p->available];
@@ -295,7 +259,7 @@ inline QDebug operator << (QDebug d, const Rect &r) {
}
struct Buffer {
- int size;
+ quint32 size;
// Data is only valid while preparing the upload. Exception is if we are using the
// broken IBO workaround or we are using a visualization mode.
char *data;
@@ -633,6 +597,8 @@ struct GraphicsState
bool blending = false;
QRhiGraphicsPipeline::BlendFactor srcColor = QRhiGraphicsPipeline::One;
QRhiGraphicsPipeline::BlendFactor dstColor = QRhiGraphicsPipeline::OneMinusSrcAlpha;
+ QRhiGraphicsPipeline::BlendFactor srcAlpha = QRhiGraphicsPipeline::One;
+ QRhiGraphicsPipeline::BlendFactor dstAlpha = QRhiGraphicsPipeline::OneMinusSrcAlpha;
QRhiGraphicsPipeline::ColorMask colorWrite = QRhiGraphicsPipeline::ColorMask(0xF);
QRhiGraphicsPipeline::CullMode cullMode = QRhiGraphicsPipeline::None;
bool usesScissor = false;
@@ -640,6 +606,8 @@ struct GraphicsState
int sampleCount = 1;
QSGGeometry::DrawingMode drawMode = QSGGeometry::DrawTriangles;
float lineWidth = 1.0f;
+ QRhiGraphicsPipeline::PolygonMode polygonMode = QRhiGraphicsPipeline::Fill;
+ int multiViewCount = 0;
};
bool operator==(const GraphicsState &a, const GraphicsState &b) noexcept;
@@ -652,24 +620,46 @@ struct GraphicsPipelineStateKey
{
GraphicsState state;
const ShaderManagerShader *sms;
- const QRhiRenderPassDescriptor *compatibleRenderPassDescriptor;
- const QRhiShaderResourceBindings *layoutCompatibleSrb;
+ QVector<quint32> renderTargetDescription;
+ QVector<quint32> srbLayoutDescription;
+ struct {
+ size_t renderTargetDescriptionHash;
+ size_t srbLayoutDescriptionHash;
+ } extra;
+ static GraphicsPipelineStateKey create(const GraphicsState &state,
+ const ShaderManagerShader *sms,
+ const QRhiRenderPassDescriptor *rpDesc,
+ const QRhiShaderResourceBindings *srb)
+ {
+ const QVector<quint32> rtDesc = rpDesc->serializedFormat();
+ const QVector<quint32> srbDesc = srb->serializedLayoutDescription();
+ return { state, sms, rtDesc, srbDesc, { qHash(rtDesc), qHash(srbDesc) } };
+ }
};
bool operator==(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) noexcept;
bool operator!=(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) noexcept;
size_t qHash(const GraphicsPipelineStateKey &k, size_t seed = 0) noexcept;
+struct ShaderKey
+{
+ QSGMaterialType *type;
+ QSGRendererInterface::RenderMode renderMode;
+ int multiViewCount;
+};
+
+bool operator==(const ShaderKey &a, const ShaderKey &b) noexcept;
+bool operator!=(const ShaderKey &a, const ShaderKey &b) noexcept;
+size_t qHash(const ShaderKey &k, size_t seed = 0) noexcept;
+
struct ShaderManagerShader
{
~ShaderManagerShader() {
- delete programRhi.program;
+ delete materialShader;
}
- struct {
- QSGMaterialShader *program = nullptr;
- QRhiVertexInputLayout inputLayout;
- QVarLengthArray<QRhiGraphicsShaderStage, 2> shaderStages;
- } programRhi;
+ QSGMaterialShader *materialShader = nullptr;
+ QRhiVertexInputLayout inputLayout;
+ QVarLengthArray<QRhiShaderStage, 2> stages;
float lastOpacity;
};
@@ -687,26 +677,29 @@ public:
void clearCachedRendererData();
- using ShaderResourceBindingList = QVarLengthArray<QRhiShaderResourceBinding, 8>;
- QRhiShaderResourceBindings *srb(const ShaderResourceBindingList &bindings);
-
QHash<GraphicsPipelineStateKey, QRhiGraphicsPipeline *> pipelineCache;
+ QMultiHash<QVector<quint32>, QRhiShaderResourceBindings *> srbPool;
+ QVector<quint32> srbLayoutDescSerializeWorkspace;
+
public Q_SLOTS:
void invalidated();
public:
- Shader *prepareMaterial(QSGMaterial *material, const QSGGeometry *geometry = nullptr, QSGRendererInterface::RenderMode renderMode = QSGRendererInterface::RenderMode2D);
- Shader *prepareMaterialNoRewrite(QSGMaterial *material, const QSGGeometry *geometry = nullptr, QSGRendererInterface::RenderMode renderMode = QSGRendererInterface::RenderMode2D);
+ Shader *prepareMaterial(QSGMaterial *material,
+ const QSGGeometry *geometry = nullptr,
+ QSGRendererInterface::RenderMode renderMode = QSGRendererInterface::RenderMode2D,
+ int multiViewCount = 0);
+ Shader *prepareMaterialNoRewrite(QSGMaterial *material,
+ const QSGGeometry *geometry = nullptr,
+ QSGRendererInterface::RenderMode renderMode = QSGRendererInterface::RenderMode2D,
+ int multiViewCount = 0);
private:
- typedef QPair<QSGMaterialType *, QSGRendererInterface::RenderMode> ShaderKey;
QHash<ShaderKey, Shader *> rewrittenShaders;
QHash<ShaderKey, Shader *> stockShaders;
QSGDefaultRenderContext *context;
-
- QHash<ShaderResourceBindingList, QRhiShaderResourceBindings *> srbCache;
};
struct RenderPassState
@@ -747,7 +740,7 @@ protected:
QHash<Node *, uint> m_visualizeChangeSet;
};
-class Q_QUICK_PRIVATE_EXPORT Renderer : public QSGRenderer
+class Q_QUICK_EXPORT Renderer : public QSGRenderer
{
public:
Renderer(QSGDefaultRenderContext *ctx, QSGRendererInterface::RenderMode renderMode = QSGRendererInterface::RenderMode2D);
@@ -801,7 +794,7 @@ private:
friend class RhiVisualizer;
void destroyGraphicsResources();
- void map(Buffer *buffer, int size, bool isIndexBuf = false);
+ void map(Buffer *buffer, quint32 byteSize, bool isIndexBuf = false);
void unmap(Buffer *buffer, bool isIndexBuf = false);
void buildRenderListsFromScratch();
@@ -822,8 +815,7 @@ private:
bool ensurePipelineState(Element *e, const ShaderManager::Shader *sms, bool depthPostPass = false);
QRhiTexture *dummyTexture();
void updateMaterialDynamicData(ShaderManager::Shader *sms, QSGMaterialShader::RenderState &renderState,
- QSGMaterial *material, ShaderManager::ShaderResourceBindingList *bindings,
- const Batch *batch, int ubufOffset, int ubufRegionSize);
+ QSGMaterial *material, const Batch *batch, Element *e, int ubufOffset, int ubufRegionSize);
void updateMaterialStaticData(ShaderManager::Shader *sms, QSGMaterialShader::RenderState &renderState,
QSGMaterial *material, Batch *batch, bool *gstateChanged);
void checkLineWidth(QSGGeometry *g);
@@ -858,12 +850,11 @@ private:
inline Batch *newBatch();
void invalidateAndRecycleBatch(Batch *b);
+ void releaseElement(Element *e, bool inDestructor = false);
void setVisualizationMode(const QByteArray &mode) override;
bool hasVisualizationModeWithContinuousUpdate() const override;
- void invalidatePipelineCacheDependency(QRhiRenderPassDescriptor *rpDesc) override;
-
QSGDefaultRenderContext *m_context;
QSGRendererInterface::RenderMode m_renderMode;
QSet<Node *> m_taggedRoots;
@@ -884,6 +875,9 @@ private:
QDataBuffer<Element *> m_tmpAlphaElements;
QDataBuffer<Element *> m_tmpOpaqueElements;
+ QDataBuffer<QRhiBuffer *> m_vboPool;
+ QDataBuffer<QRhiBuffer *> m_iboPool;
+
uint m_rebuild;
qreal m_zRange;
#if defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
@@ -893,6 +887,7 @@ private:
int m_batchNodeThreshold;
int m_batchVertexThreshold;
+ int m_srbPoolThreshold;
Visualizer *m_visualizer;
@@ -1020,6 +1015,7 @@ void StencilClipState::reset()
Q_DECLARE_TYPEINFO(QSGBatchRenderer::GraphicsState, Q_RELOCATABLE_TYPE);
Q_DECLARE_TYPEINFO(QSGBatchRenderer::GraphicsPipelineStateKey, Q_RELOCATABLE_TYPE);
Q_DECLARE_TYPEINFO(QSGBatchRenderer::RenderPassState, Q_RELOCATABLE_TYPE);
+Q_DECLARE_TYPEINFO(QSGBatchRenderer::DrawSet, Q_PRIMITIVE_TYPE);
QT_END_NAMESPACE