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
6#ifndef QSGRHIVISUALIZER_P_H
7#define QSGRHIVISUALIZER_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
21
22#include <QtCore/qrandom.h>
23
25
26namespace QSGBatchRenderer
27{
28
30{
31public:
32 RhiVisualizer(Renderer *renderer);
34
35 void prepareVisualize() override;
36 void visualize() override;
37
38 void releaseResources() override;
39
40 struct DrawCall
41 {
42 static const int UBUF_SIZE = 152; // visualization.vert/frag
43 struct {
44 char data[UBUF_SIZE]; // matrix, rotation, color, pattern, projection
45 } uniforms;
46 struct {
49 int count;
50 int stride;
51 const void *data; // only when using own vbuf
52 } vertex;
53 struct {
55 int count;
56 int stride;
57 const void *data; // only when using own ibuf
58 } index;
59 struct {
60 QRhiBuffer *vbuf; // either same for all draw calls and owned by the *Vis, or points to a Batch.Buffer.vbo.buf
62 QRhiBuffer *ibuf; // same, but for index
65 } buf;
66 };
67
68private:
69 QShader m_vs;
70 QShader m_fs;
71
72 void recordDrawCalls(const QVector<DrawCall> &drawCalls,
73 QRhiCommandBuffer *cb,
74 QRhiShaderResourceBindings *srb,
75 bool blendOneOne = false);
76
77 class PipelineCache {
78 public:
79 QRhiGraphicsPipeline *pipeline(RhiVisualizer *visualizer,
80 QRhi *rhi,
81 QRhiShaderResourceBindings *srb,
82 QRhiRenderPassDescriptor *rpDesc,
83 QRhiGraphicsPipeline::Topology topology,
84 QRhiVertexInputAttribute::Format vertexFormat,
85 quint32 vertexStride,
86 bool blendOneOne);
87 void releaseResources();
88 private:
89 struct Pipeline {
90 QRhiGraphicsPipeline::Topology topology;
91 QRhiVertexInputAttribute::Format format;
92 quint32 stride;
93 QRhiGraphicsPipeline *ps;
94 };
95 QVarLengthArray<Pipeline, 16> pipelines;
96 };
97
98 PipelineCache m_pipelines;
99
100 class Fade {
101 public:
102 void prepare(RhiVisualizer *visualizer,
103 QRhi *rhi, QRhiResourceUpdateBatch *u, QRhiRenderPassDescriptor *rpDesc);
104 void releaseResources();
105 void render(QRhiCommandBuffer *cb);
106 private:
107 RhiVisualizer *visualizer;
108 QRhiBuffer *vbuf = nullptr;
109 QRhiBuffer *ubuf = nullptr;
110 QRhiGraphicsPipeline *ps = nullptr;
111 QRhiShaderResourceBindings *srb = nullptr;
112 } m_fade;
113
114 class ChangeVis {
115 public:
116 void prepare(Node *n, RhiVisualizer *visualizer,
117 QRhi *rhi, QRhiResourceUpdateBatch *u);
118 void releaseResources();
119 void render(QRhiCommandBuffer *cb);
120 private:
121 void gather(Node *n);
122 RhiVisualizer *visualizer;
123 QVector<DrawCall> drawCalls;
124 QRhiBuffer *vbuf = nullptr;
125 QRhiBuffer *ibuf = nullptr;
126 QRhiBuffer *ubuf = nullptr;
127 QRhiShaderResourceBindings *srb = nullptr;
128 } m_changeVis;
129
130 class BatchVis {
131 public:
132 void prepare(const QDataBuffer<Batch *> &opaqueBatches,
133 const QDataBuffer<Batch *> &alphaBatches,
134 RhiVisualizer *visualizer,
135 QRhi *rhi, QRhiResourceUpdateBatch *u,
136 bool forceUintIndex);
137 void releaseResources();
138 void render(QRhiCommandBuffer *cb);
139 private:
140 void gather(Batch *b);
141 RhiVisualizer *visualizer;
142 bool forceUintIndex;
143 QVector<DrawCall> drawCalls;
144 QRhiBuffer *ubuf = nullptr;
145 QRhiShaderResourceBindings *srb = nullptr;
146 } m_batchVis;
147
148 class ClipVis {
149 public:
150 void prepare(QSGNode *node, RhiVisualizer *visualizer,
151 QRhi *rhi, QRhiResourceUpdateBatch *u);
152 void releaseResources();
153 void render(QRhiCommandBuffer *cb);
154 private:
155 void gather(QSGNode *node);
156 RhiVisualizer *visualizer;
157 QVector<DrawCall> drawCalls;
158 QRhiBuffer *vbuf = nullptr;
159 QRhiBuffer *ibuf = nullptr;
160 QRhiBuffer *ubuf = nullptr;
161 QRhiShaderResourceBindings *srb = nullptr;
162 } m_clipVis;
163
164 class OverdrawVis {
165 public:
166 void prepare(Node *n, RhiVisualizer *visualizer,
167 QRhi *rhi, QRhiResourceUpdateBatch *u);
168 void releaseResources();
169 void render(QRhiCommandBuffer *cb);
170 private:
171 void gather(Node *n);
172 RhiVisualizer *visualizer;
173 QVector<DrawCall> drawCalls;
174 QRhiBuffer *vbuf = nullptr;
175 QRhiBuffer *ibuf = nullptr;
176 QRhiBuffer *ubuf = nullptr;
177 QRhiShaderResourceBindings *srb = nullptr;
178 float step = 0.0f;
179 QMatrix4x4 rotation;
180 struct {
181 QRhiBuffer *vbuf = nullptr;
182 QRhiBuffer *ubuf = nullptr;
183 QRhiShaderResourceBindings *srb = nullptr;
184 QRhiGraphicsPipeline *ps = nullptr;
185 } box;
186 } m_overdrawVis;
187
188 QRandomGenerator m_randomGenerator;
189
190 friend class Fade;
191 friend class PipelineCache;
192 friend class ChangeVis;
193 friend class ClipVis;
194 friend class OverdrawVis;
195};
196
197} // namespace QSGBatchRenderer
198
199QT_END_NAMESPACE
200
201#endif // QSGRHIVISUALIZER_P_H
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:322
const Type * at(uint index) const
char data[sizeof(Type) *PageSize]
QVector< AllocatorPage< Type, PageSize > * > pages
void releaseExplicit(uint pageIndex, uint index)
Shader * prepareMaterial(QSGMaterial *material, const QSGGeometry *geometry=nullptr, QSGRendererInterface::RenderMode renderMode=QSGRendererInterface::RenderMode2D, int multiViewCount=0)
QMultiHash< QVector< quint32 >, QRhiShaderResourceBindings * > srbPool
QHash< GraphicsPipelineStateKey, QRhiGraphicsPipeline * > pipelineCache
ShaderManager(QSGDefaultRenderContext *ctx)
QVector< quint32 > srbLayoutDescSerializeWorkspace
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
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2568
Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_RELOCATABLE_TYPE)
#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