6#ifndef QSGBATCHRENDERER_P_H
7#define QSGBATCHRENDERER_P_H
20#include <private/qsgrenderer_p.h>
21#include <private/qsgdefaultrendercontext_p.h>
22#include <private/qsgnodeupdater_p.h>
23#include <private/qsgrendernode_p.h>
24#include <private/qdatabuffer_p.h>
25#include <private/qsgtexture_p.h>
27#include <QtCore/QBitArray>
28#include <QtCore/QStack>
37#define QSG_RENDERER_COORD_LIMIT 1000000.0f
70 for (
int i=0;
i<PageSize; ++
i)
88template <
typename Type,
int PageSize>
class Allocator
105 if (
pages.at(
i)->available > 0) {
121 uint pos =
p->blocks[PageSize -
p->available];
122 void *mem =
p->at(
pos);
124 p->allocated.setBit(
pos);
133 qFatal(
"Double delete in allocator: page=%d, index=%d", pageIndex ,
index);
137 memset(mem, 0,
sizeof(
Type));
159 for (
int i=0;
i<
pages.size(); ++
i) {
161 if ((
Type *) (&
p->data[0]) <=
t && (
Type *) (&
p->data[PageSize *
sizeof(
Type)]) >
t) {
191 r.x =
x *
m[0] +
y *
m[4] +
m[12];
192 r.y =
x *
m[1] +
y *
m[5] +
m[13];
204 d <<
"Pt(" <<
p.x <<
p.y <<
")";
243 bool xOverlap =
r.tl.x <
br.
x &&
r.br.x >
tl.
x;
244 bool yOverlap =
r.tl.y <
br.
y &&
r.br.y >
tl.
y;
245 return xOverlap && yOverlap;
257 d <<
"Rect(" <<
r.tl.x <<
r.tl.y <<
r.br.x <<
r.br.y <<
")";
382 bool updateStencilBuffer =
false;
408 void cleanupRemovedElements();
410 bool isTranslateOnlyToRoot()
const;
411 bool isSafeToBatch()
const;
423 positionAttribute = -1;
424 uploadedThisFrame =
false;
425 isRenderNode =
false;
426 ubufDataValid =
false;
489 child->m_next = m_child;
491 child->setParent(
this);
502 if (m_child ==
child)
503 m_child =
child->m_next;
507 child->m_next =
nullptr;
508 child->m_prev =
nullptr;
509 child->setParent(
nullptr);
520 Q_ASSERT(m_parent ==
nullptr ||
p ==
nullptr);
568 void visitOpacityNode(
Node *
n);
569 void visitTransformNode(
Node *
n);
570 void visitGeometryNode(
Node *
n);
571 void visitClipNode(
Node *
n);
575 void updateStates(
QSGNode *
n)
override;
576 void visitNode(
Node *
n);
586 int m_transformChange;
594 bool depthTest =
false;
595 bool depthWrite =
false;
597 bool blending =
false;
602 QRhiGraphicsPipeline::ColorMask colorWrite = QRhiGraphicsPipeline::ColorMask(0xF);
604 bool usesScissor =
false;
605 bool stencilTest =
false;
608 float lineWidth = 1.0f;
635 return {
state, sms, rtDesc, srbDesc, {
qHash(rtDesc),
qHash(srbDesc) } };
639bool operator==(
const GraphicsPipelineStateKey &
a,
const GraphicsPipelineStateKey &
b)
noexcept;
640bool operator!=(
const GraphicsPipelineStateKey &
a,
const GraphicsPipelineStateKey &
b)
noexcept;
641size_t qHash(
const GraphicsPipelineStateKey &k,
size_t seed = 0) noexcept;
646 delete materialShader;
666 void clearCachedRendererData();
714 virtual void visualizeChangesPrepare(
Node *
n,
uint parentChanges = 0);
733 void nodeChanged(
QSGNode *node, QSGNode::DirtyState
state)
override;
735 void prepareInline()
override;
736 void renderInline()
override;
737 void releaseCachedResources()
override;
770 BuildRenderListsForTaggedRoots = 0x0001,
771 BuildRenderLists = 0x0002,
772 BuildBatches = 0x0004,
779 void destroyGraphicsResources();
783 void buildRenderListsFromScratch();
784 void buildRenderListsForTaggedRoots();
785 void tagSubRoots(
Node *node);
786 void buildRenderLists(
QSGNode *node);
788 void deleteRemovedElements();
790 void prepareOpaqueBatches();
791 bool checkOverlap(
int first,
int last,
const Rect &bounds);
792 void prepareAlphaBatches();
793 void invalidateBatchAndOverlappingRenderOrders(
Batch *batch);
795 void uploadBatch(
Batch *
b);
796 void uploadMergedElement(
Element *
e,
int vaOffset,
char **vertexData,
char **zData,
char **indexData,
void *iBasePtr,
int *indexCount);
810 ClipState::ClipType updateStencilClip(
const QSGClipNode *clip);
812 void applyClipStateToGraphicsState();
815 void enqueueStencilDraw(
const Batch *batch);
817 void renderRenderNode(
Batch *batch);
819 void renderRhiRenderNode(
const Batch *batch);
823 bool changeBatchRoot(
Node *node,
Node *newRoot);
824 void registerBatchRoot(
Node *childRoot,
Node *parentRoot);
825 void removeBatchRootFromParent(
Node *childRoot);
826 void nodeChangedBatchRoot(
Node *node,
Node *root);
827 void turnNodeIntoBatchRoot(
Node *node);
828 void nodeWasTransformed(
Node *node,
int *vertexCount);
829 void nodeWasRemoved(
Node *node);
830 void nodeWasAdded(
QSGNode *node,
Node *shadowParent);
834 inline Batch *newBatch();
835 void invalidateAndRecycleBatch(
Batch *
b);
836 void releaseElement(
Element *
e,
bool inDestructor =
false);
839 bool hasVisualizationModeWithContinuousUpdate()
const override;
846 int m_nextRenderOrder;
847 bool m_partialRebuild;
849 bool m_forceNoDepthBuffer;
863#if defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
864 int m_renderOrderRebuildLower;
865 int m_renderOrderRebuildUpper;
868 int m_batchNodeThreshold;
869 int m_batchVertexThreshold;
870 int m_srbPoolThreshold;
888 uint m_ubufAlignment;
889 bool m_uint32IndexForRhi;
896 struct StencilClipCommonData {
904 } m_stencilClipCommon;
906 inline int mergedIndexElemSize()
const;
907 inline bool useDepthBuffer()
const;
908 inline void setStateForDepthPostPass();
911Batch *Renderer::newBatch()
914 int size = m_batchPool.size();
916 b = m_batchPool.at(
size - 1);
918 m_batchPool.resize(
size - 1);
921 Q_ASSERT(offsetof(Batch, ibo) ==
sizeof(Buffer) + offsetof(Batch, vbo));
922 memset(&
b->vbo, 0,
sizeof(Buffer) * 2);
924 b->stencilClipState.reset();
931int Renderer::mergedIndexElemSize()
const
942bool Renderer::useDepthBuffer()
const
947void Renderer::setStateForDepthPostPass()
949 m_gstate.colorWrite = {};
950 m_gstate.depthWrite =
true;
951 m_gstate.depthTest =
true;
955void Renderer::StencilClipCommonData::reset()
976 updateStencilBuffer =
false;
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
The QColor class provides colors based on RGB, HSV or CMYK values.
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
const float * constData() const
Returns a constant pointer to the raw data of this matrix.
IndexFormat
Specifies the index data type.
PolygonMode
Specifies the polygon rasterization mode.
BlendFactor
Specifies the blend factor.
CompareOp
Specifies the depth or stencil comparison function.
CullMode
Specifies the culling mode.
Topology
Specifies the primitive topology.
virtual QVector< quint32 > serializedFormat() const =0
QVector< quint32 > serializedLayoutDescription() const
const Type * at(uint index) const
QVector< AllocatorPage< Type, PageSize > * > pages
void releaseExplicit(uint pageIndex, uint index)
QMultiHash< QVector< quint32 >, QRhiShaderResourceBindings * > srbPool
QHash< GraphicsPipelineStateKey, QRhiGraphicsPipeline * > pipelineCache
ShaderManager(QSGDefaultRenderContext *ctx)
QVector< quint32 > srbLayoutDescSerializeWorkspace
void registerWithParentRoot(QSGNode *subRoot, QSGNode *parentRoot)
void updateRootTransforms(Node *n)
virtual void visualize()=0
void setMode(VisualizeMode mode)
virtual void prepareVisualize()=0
VisualizeMode mode() const
virtual void releaseResources()=0
QHash< Node *, uint > m_visualizeChangeSet
VisualizeMode m_visualizeMode
The QSGClipNode class implements the clipping functionality in the scene graph.
The QSGGeometryNode class is used for all rendered content in the scene graph.
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
DrawingMode
Specifies the drawing mode, also called primitive topology.
Encapsulates the current rendering state during a call to QSGMaterialShader::updateUniformData() and ...
The QSGMaterialShader class represents a graphics API independent shader program.
The QSGMaterial class encapsulates rendering state for a shader program.
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
NodeType
Can be used to figure out the type of node.
NodeType type() const
Returns the type of this node.
The QSGRenderNode class represents a set of custom rendering commands targeting the graphics API that...
RenderMode
\value RenderMode2D Normal 2D rendering \value RenderMode2DNoDepthBuffer Normal 2D rendering with dep...
The renderer class is the abstract baseclass used for rendering the QML scene graph.
QMap< QString, QString > map
[6]
qDeleteAll(list.begin(), list.end())
size_t qHash(const GraphicsState &s, size_t seed) noexcept
QDebug operator<<(QDebug d, const Pt &p)
bool hasMaterialWithBlending(QSGGeometryNode *n)
bool operator==(const GraphicsState &a, const GraphicsState &b) noexcept
bool operator!=(const GraphicsState &a, const GraphicsState &b) noexcept
Combined button and popup list for selecting options.
std::pair< T1, T2 > QPair
#define Q_DECLARE_FLAGS(Flags, Enum)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLenum GLenum dstAlpha
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLenum srcAlpha
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei GLenum const void * indices
GLfixed GLfixed GLint GLint order
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
#define QSG_RENDERER_COORD_LIMIT
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
unsigned long long quint64
QSvgRenderer * renderer
[0]
StencilClipState stencilClipState
QDataBuffer< DrawSet > drawSets
uint nonDynamicChangeCount
const QSGClipNode * clipList
DrawSet(int v, int z, int i)
QRhiGraphicsPipeline * depthPostPassPs
QRhiShaderResourceBindings * srb
QRhiGraphicsPipeline * ps
void setNode(QSGGeometryNode *n)
uint boundsOutsideFloatRange
const ShaderManagerShader * sms
size_t srbLayoutDescriptionHash
size_t renderTargetDescriptionHash
static GraphicsPipelineStateKey create(const GraphicsState &state, const ShaderManagerShader *sms, const QRhiRenderPassDescriptor *rpDesc, const QRhiShaderResourceBindings *srb)
QVector< quint32 > renderTargetDescription
QVector< quint32 > srbLayoutDescription
QSGNode::NodeType type() const
BatchRootInfo * rootInfo() const
QSGNode::DirtyState dirtyState
ClipBatchRootInfo * clipInfo() const
Node * firstChild() const
RenderNodeElement * renderNodeElement() const
Element * element() 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)
bool isOutsideFloatRange() const
bool intersects(const Rect &r)
RenderNodeElement(QSGRenderNode *rn)
QSGRenderNode * renderNode
QRhiDepthStencilClearValue dsClear
ShaderManager::Shader * sms
quint64 timePrepareOpaque
QVarLengthArray< PreparedRenderBatch, 64 > opaqueRenderBatches
QVarLengthArray< PreparedRenderBatch, 64 > alphaRenderBatches
QRhiVertexInputLayout inputLayout
QVarLengthArray< QRhiShaderStage, 2 > stages
QRhiCommandBuffer::IndexFormat indexFormat
QDataBuffer< StencilDrawCall > drawCalls