Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgrhivisualizer_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 Jolla Ltd, author: <gunnar.sletta@jollamobile.com>
3// Copyright (C) 2016 Robin Burchell <robin.burchell@viroteck.net>
4// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
5// Qt-Security score:significant reason:default
6
7#ifndef QSGRHIVISUALIZER_P_H
8#define QSGRHIVISUALIZER_P_H
9
10//
11// W A R N I N G
12// -------------
13//
14// This file is not part of the Qt API. It exists purely as an
15// implementation detail. This header file may change from version to
16// version without notice, or even be removed.
17//
18// We mean it.
19//
20
22
23#include <QtCore/qrandom.h>
24
26
27namespace QSGBatchRenderer
28{
29
31{
32public:
33 RhiVisualizer(Renderer *renderer);
35
36 void prepareVisualize() override;
37 void visualize() override;
38
39 void releaseResources() override;
40
41 struct DrawCall
42 {
43 static const int UBUF_SIZE = 152; // visualization.vert/frag
44 struct {
45 char data[UBUF_SIZE]; // matrix, rotation, color, pattern, projection
46 } uniforms;
47 struct {
50 int count;
51 int stride;
52 const void *data; // only when using own vbuf
53 } vertex;
54 struct {
56 int count;
57 int stride;
58 const void *data; // only when using own ibuf
59 } index;
60 struct {
61 QRhiBuffer *vbuf; // either same for all draw calls and owned by the *Vis, or points to a Batch.Buffer.vbo.buf
63 QRhiBuffer *ibuf; // same, but for index
66 } buf;
67 };
68
69private:
70 QShader m_vs;
71 QShader m_fs;
72
73 void recordDrawCalls(const QList<DrawCall> &drawCalls,
74 QRhiCommandBuffer *cb,
75 QRhiShaderResourceBindings *srb,
76 bool blendOneOne = false);
77
78 class PipelineCache {
79 public:
80 QRhiGraphicsPipeline *pipeline(RhiVisualizer *visualizer,
81 QRhi *rhi,
82 QRhiShaderResourceBindings *srb,
83 QRhiRenderPassDescriptor *rpDesc,
84 QRhiGraphicsPipeline::Topology topology,
85 QRhiVertexInputAttribute::Format vertexFormat,
86 quint32 vertexStride,
87 bool blendOneOne);
88 void releaseResources();
89 private:
90 struct Pipeline {
91 QRhiGraphicsPipeline::Topology topology;
92 QRhiVertexInputAttribute::Format format;
93 quint32 stride;
94 QRhiGraphicsPipeline *ps;
95 };
96 QVarLengthArray<Pipeline, 16> pipelines;
97 };
98
99 PipelineCache m_pipelines;
100
101 class Fade {
102 public:
103 void prepare(RhiVisualizer *visualizer,
104 QRhi *rhi, QRhiResourceUpdateBatch *u, QRhiRenderPassDescriptor *rpDesc);
105 void releaseResources();
106 void render(QRhiCommandBuffer *cb);
107 private:
108 RhiVisualizer *visualizer;
109 QRhiBuffer *vbuf = nullptr;
110 QRhiBuffer *ubuf = nullptr;
111 QRhiGraphicsPipeline *ps = nullptr;
112 QRhiShaderResourceBindings *srb = nullptr;
113 } m_fade;
114
115 class ChangeVis {
116 public:
117 void prepare(Node *n, RhiVisualizer *visualizer,
118 QRhi *rhi, QRhiResourceUpdateBatch *u);
119 void releaseResources();
120 void render(QRhiCommandBuffer *cb);
121 private:
122 void gather(Node *n);
123 RhiVisualizer *visualizer;
124 QList<DrawCall> drawCalls;
125 QRhiBuffer *vbuf = nullptr;
126 QRhiBuffer *ibuf = nullptr;
127 QRhiBuffer *ubuf = nullptr;
128 QRhiShaderResourceBindings *srb = nullptr;
129 } m_changeVis;
130
131 class BatchVis {
132 public:
133 void prepare(const QDataBuffer<Batch *> &opaqueBatches,
134 const QDataBuffer<Batch *> &alphaBatches,
135 RhiVisualizer *visualizer,
136 QRhi *rhi, QRhiResourceUpdateBatch *u,
137 bool forceUintIndex);
138 void releaseResources();
139 void render(QRhiCommandBuffer *cb);
140 private:
141 void gather(Batch *b);
142 RhiVisualizer *visualizer;
143 bool forceUintIndex;
144 QList<DrawCall> drawCalls;
145 QRhiBuffer *ubuf = nullptr;
146 QRhiShaderResourceBindings *srb = nullptr;
147 } m_batchVis;
148
149 class ClipVis {
150 public:
151 void prepare(QSGNode *node, RhiVisualizer *visualizer,
152 QRhi *rhi, QRhiResourceUpdateBatch *u);
153 void releaseResources();
154 void render(QRhiCommandBuffer *cb);
155 private:
156 void gather(QSGNode *node);
157 RhiVisualizer *visualizer;
158 QList<DrawCall> drawCalls;
159 QRhiBuffer *vbuf = nullptr;
160 QRhiBuffer *ibuf = nullptr;
161 QRhiBuffer *ubuf = nullptr;
162 QRhiShaderResourceBindings *srb = nullptr;
163 } m_clipVis;
164
165 class OverdrawVis {
166 public:
167 void prepare(Node *n, RhiVisualizer *visualizer,
168 QRhi *rhi, QRhiResourceUpdateBatch *u);
169 void releaseResources();
170 void render(QRhiCommandBuffer *cb);
171 private:
172 void gather(Node *n);
173 RhiVisualizer *visualizer;
174 QList<DrawCall> drawCalls;
175 QRhiBuffer *vbuf = nullptr;
176 QRhiBuffer *ibuf = nullptr;
177 QRhiBuffer *ubuf = nullptr;
178 QRhiShaderResourceBindings *srb = nullptr;
179 float step = 0.0f;
180 QMatrix4x4 rotation;
181 struct {
182 QRhiBuffer *vbuf = nullptr;
183 QRhiBuffer *ubuf = nullptr;
184 QRhiShaderResourceBindings *srb = nullptr;
185 QRhiGraphicsPipeline *ps = nullptr;
186 } box;
187 } m_overdrawVis;
188
189 QRandomGenerator m_randomGenerator;
190
191 friend class Fade;
192 friend class PipelineCache;
193 friend class ChangeVis;
194 friend class ClipVis;
195 friend class OverdrawVis;
196};
197
198} // namespace QSGBatchRenderer
199
200QT_END_NAMESPACE
201
202#endif // QSGRHIVISUALIZER_P_H
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:323
const Type * at(uint index) const
char data[sizeof(Type) *PageSize]
QList< AllocatorPage< Type, PageSize > * > pages
void releaseExplicit(uint pageIndex, uint index)
QMultiHash< QList< quint32 >, QRhiShaderResourceBindings * > srbPool
Shader * prepareMaterial(QSGMaterial *material, const QSGGeometry *geometry=nullptr, QSGRendererInterface::RenderMode renderMode=QSGRendererInterface::RenderMode2D, int multiViewCount=0)
QList< quint32 > srbLayoutDescSerializeWorkspace
QHash< GraphicsPipelineStateKey, QRhiGraphicsPipeline * > pipelineCache
ShaderManager(QSGDefaultRenderContext *ctx)
Shader * prepareMaterialNoRewrite(QSGMaterial *material, const QSGGeometry *geometry=nullptr, QSGRendererInterface::RenderMode renderMode=QSGRendererInterface::RenderMode2D, int multiViewCount=0)
void updateRootTransforms(Node *n, Node *root, const QMatrix4x4 &combined)
void registerWithParentRoot(QSGNode *subRoot, QSGNode *parentRoot)
void updateStates(QSGNode *n) override
void updateRootTransforms(Node *n)
virtual void visualize()=0
void setMode(VisualizeMode mode)
virtual void visualizeChangesPrepare(Node *n, uint parentChanges=0)
virtual void prepareVisualize()=0
virtual void releaseResources()=0
QHash< Node *, uint > m_visualizeChangeSet
The QSGMaterialShader class represents a graphics API independent shader program.
const int ZORDER_BUFFER_BINDING
static void qsg_wipeBuffer(Buffer *buffer)
static void rendererToMaterialGraphicsState(QSGMaterialShader::GraphicsPipelineState *dst, GraphicsState *src)
size_t qHash(const GraphicsState &s, size_t seed) noexcept
static QRhiVertexInputLayout calculateVertexInputLayout(const QSGMaterialShader *s, const QSGGeometry *geometry, bool batchable)
static void qsg_addBackOrphanedElements(QDataBuffer< Element * > &orphans, QDataBuffer< Element * > &renderList)
bool operator!=(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) noexcept
const float VIEWPORT_MIN_DEPTH
QSGMaterial::Flag QSGMaterial_FullMatrix
bool qsg_sort_batch_decreasing_order(Batch *a, Batch *b)
QDebug operator<<(QDebug d, const Pt &p)
QDebug operator<<(QDebug d, const Rect &r)
bool operator==(const ShaderKey &a, const ShaderKey &b) noexcept
bool operator==(const GraphicsPipelineStateKey &a, const GraphicsPipelineStateKey &b) noexcept
bool operator!=(const ShaderKey &a, const ShaderKey &b) noexcept
static void qsg_wipeBatch(Batch *batch)
static QRhiSampler * newSampler(QRhi *rhi, const QSGSamplerDescription &desc)
QRhiVertexInputAttribute::Format qsg_vertexInputFormat(const QSGGeometry::Attribute &a)
QRhiGraphicsPipeline::Topology qsg_topology(int geomDrawMode, QRhi *rhi)
QMatrix4x4 qsg_matrixForRoot(Node *node)
bool qsg_sort_batch_increasing_order(Batch *a, Batch *b)
static void qsg_addOrphanedElements(QDataBuffer< Element * > &orphans, const QDataBuffer< Element * > &renderList)
void qsg_setMultiViewFlagsOnMaterial(QSGMaterial *material, int multiViewCount)
const float VIEWPORT_MAX_DEPTH
int qsg_positionAttribute(QSGGeometry *g)
static int size_of_type(int type)
static bool isTranslate(const QMatrix4x4 &m)
static int qsg_countNodesInBatches(const QDataBuffer< Batch * > &batches)
static float calculateElementZOrder(const Element *e, qreal zRange)
static int qsg_fixIndexCount(int iCount, int drawMode)
bool qsg_sort_element_increasing_order(Element *a, Element *b)
static void materialToRendererGraphicsState(GraphicsState *dst, QSGMaterialShader::GraphicsPipelineState *src)
static bool needsBlendConstant(QRhiGraphicsPipeline::BlendFactor f)
const int VERTEX_BUFFER_BINDING
const uint DYNAMIC_VERTEX_INDEX_BUFFER_THRESHOLD
bool hasMaterialWithBlending(QSGGeometryNode *n)
static int qsg_countNodesInBatch(const Batch *batch)
bool operator==(const GraphicsState &a, const GraphicsState &b) noexcept
QRhiCommandBuffer::IndexFormat qsg_indexFormat(const QSGGeometry *geometry)
bool operator!=(const GraphicsState &a, const GraphicsState &b) noexcept
bool qsg_sort_element_decreasing_order(Element *a, Element *b)
size_t qHash(const ShaderKey &k, size_t seed) noexcept
void qsg_dumpShadowRoots(BatchRootInfo *i, int indent)
void qsg_dumpShadowRoots(Node *n)
static bool isScale(const QMatrix4x4 &m)
static bool is2DSafe(const QMatrix4x4 &m)
size_t qHash(const GraphicsPipelineStateKey &k, size_t seed) noexcept
Int aligned(Int v, Int byteAlign)
const quint32 DEFAULT_BUFFER_POOL_SIZE_LIMIT
Combined button and popup list for selecting options.
Q_DECLARE_TYPEINFO(QDateTime::Data, Q_RELOCATABLE_TYPE)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
#define DECLARE_DEBUG_VAR(variable)
#define QSGNODE_DIRTY_PARENT
QT_BEGIN_NAMESPACE int qt_sg_envInt(const char *name, int defaultValue)
#define SHADOWNODE_TRAVERSE(NODE)
#define QSGNODE_TRAVERSE(NODE)
Q_DECLARE_TYPEINFO(QSGBatchRenderer::DrawSet, Q_PRIMITIVE_TYPE)
Q_DECLARE_TYPEINFO(QSGBatchRenderer::GraphicsState, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(QSGBatchRenderer::GraphicsPipelineStateKey, Q_RELOCATABLE_TYPE)
#define QSG_RENDERER_COORD_LIMIT
Q_DECLARE_TYPEINFO(QSGBatchRenderer::RenderPassState, Q_RELOCATABLE_TYPE)
bool geometryWasChanged(QSGGeometryNode *gn)
BatchCompatibility isMaterialCompatible(Element *e) const
StencilClipState stencilClipState
QDataBuffer< DrawSet > drawSets
DrawSet(int v, int z, int i)
QRhiGraphicsPipeline * depthPostPassPs
QRhiShaderResourceBindings * srb
QRhiGraphicsPipeline * ps
void setNode(QSGGeometryNode *n)
static GraphicsPipelineStateKey create(const GraphicsState &state, const ShaderManagerShader *sms, const QRhiRenderPassDescriptor *rpDesc, const QRhiShaderResourceBindings *srb)
QSGGeometry::DrawingMode drawMode
QSGNode::NodeType type() const
BatchRootInfo * rootInfo() const
QSGNode::DirtyState dirtyState
ClipBatchRootInfo * clipInfo() const
RenderNodeElement * renderNodeElement() const
bool hasChild(Node *child) const
void map(const QMatrix4x4 &mat)
void set(float nx, float ny)
void operator|=(const Pt &pt)
void set(float left, float top, float right, float bottom)
void map(const QMatrix4x4 &m)
bool intersects(const Rect &r)
void operator|=(const Rect &r)
const QMatrix4x4 * projectionMatrix() const override
const QRegion * clipRegion() const override
QRhiDepthStencilClearValue dsClear
QRhiGraphicsPipeline::Topology topology
QRhiCommandBuffer::IndexFormat format
QSGRendererInterface::RenderMode renderMode
QVarLengthArray< QRhiShaderStage, 2 > stages
QRhiShaderResourceBindings * srb
QDataBuffer< StencilDrawCall > drawCalls