11#include <QtCore/QElapsedTimer>
12#include <QtCore/QtNumeric>
13#include <QtCore/qalgorithms.h>
15#include <QtGui/QGuiApplication>
17#include <private/qnumeric_p.h>
22#include <QtQuick/private/qsgnode_p.h>
33#define DECLARE_DEBUG_VAR(variable)
34 static bool debug_ ## variable()
35 { static bool value = qgetenv("QSG_RENDERER_DEBUG").contains(QT_STRINGIFY(variable)); return value; }
46#undef DECLARE_DEBUG_VAR
48#define QSGNODE_TRAVERSE(NODE) for (QSGNode *child = NODE->firstChild(); child; child = child->nextSibling())
49#define SHADOWNODE_TRAVERSE(NODE) for (Node *child = NODE->firstChild(); child; child = child->sibling())
53 static int sizes[] = {
55 sizeof(
unsigned char),
57 sizeof(
unsigned short),
66 Q_ASSERT(type >= QSGGeometry::ByteType && type <= QSGGeometry::DoubleType);
67 return sizes[type - QSGGeometry::ByteType];
77static bool isTranslate(
const QMatrix4x4 &m) {
return m.flags() <= QMatrix4x4::Translation; }
78static bool isScale(
const QMatrix4x4 &m) {
return m.flags() <= QMatrix4x4::Scale; }
79static bool is2DSafe(
const QMatrix4x4 &m) {
return m.flags() < QMatrix4x4::Rotation; }
98 return (v + byteAlign - 1) & ~(byteAlign - 1);
104 case QSGGeometry::FloatType:
105 if (a.tupleSize == 4)
106 return QRhiVertexInputAttribute::Float4;
107 if (a.tupleSize == 3)
108 return QRhiVertexInputAttribute::Float3;
109 if (a.tupleSize == 2)
110 return QRhiVertexInputAttribute::Float2;
111 if (a.tupleSize == 1)
112 return QRhiVertexInputAttribute::Float;
114 case QSGGeometry::UnsignedByteType:
115 if (a.tupleSize == 4)
116 return QRhiVertexInputAttribute::UNormByte4;
117 if (a.tupleSize == 2)
118 return QRhiVertexInputAttribute::UNormByte2;
119 if (a.tupleSize == 1)
120 return QRhiVertexInputAttribute::UNormByte;
125 qWarning(
"Unsupported attribute type 0x%x with %d components", a.type, a.tupleSize);
126 Q_UNREACHABLE_RETURN(QRhiVertexInputAttribute::Float);
132 const QSGMaterialShaderPrivate *sd = QSGMaterialShaderPrivate::get(s);
133 if (!sd->vertexShader) {
134 qWarning(
"No vertex shader in QSGMaterialShader %p", s);
135 return QRhiVertexInputLayout();
138 const int attrCount = geometry->attributeCount();
139 QVarLengthArray<QRhiVertexInputAttribute, 8> inputAttributes;
140 inputAttributes.reserve(attrCount + 1);
142 for (
int i = 0; i < attrCount; ++i) {
143 const QSGGeometry::Attribute &a = geometry->attributes()[i];
144 if (!sd->vertexShader->vertexInputLocations.contains(a.position)) {
145 qWarning(
"Vertex input %d is present in material but not in shader. This is wrong.",
148 inputAttributes.append(QRhiVertexInputAttribute(
VERTEX_BUFFER_BINDING, a.position, qsg_vertexInputFormat(a), offset));
149 offset += a.tupleSize * size_of_type(a.type);
152 inputAttributes.append(QRhiVertexInputAttribute(
ZORDER_BUFFER_BINDING, sd->vertexShader->qt_order_attrib_location,
153 QRhiVertexInputAttribute::Float, 0));
157 QVarLengthArray<QRhiVertexInputBinding, 2> inputBindings;
158 inputBindings.append(QRhiVertexInputBinding(geometry->sizeOfVertex()));
160 inputBindings.append(QRhiVertexInputBinding(
sizeof(
float)));
163 inputLayout.setBindings(inputBindings.cbegin(), inputBindings.cend());
164 inputLayout.setAttributes(inputAttributes.cbegin(), inputAttributes.cend());
171 switch (geometry->indexType()) {
172 case QSGGeometry::UnsignedShortType:
173 return QRhiCommandBuffer::IndexUInt16;
175 case QSGGeometry::UnsignedIntType:
176 return QRhiCommandBuffer::IndexUInt32;
179 Q_UNREACHABLE_RETURN(QRhiCommandBuffer::IndexUInt16);
185 QRhiGraphicsPipeline::Topology topology = QRhiGraphicsPipeline::Triangles;
186 switch (geomDrawMode) {
187 case QSGGeometry::DrawPoints:
188 topology = QRhiGraphicsPipeline::Points;
190 case QSGGeometry::DrawLines:
191 topology = QRhiGraphicsPipeline::Lines;
193 case QSGGeometry::DrawLineStrip:
194 topology = QRhiGraphicsPipeline::LineStrip;
196 case QSGGeometry::DrawTriangles:
197 topology = QRhiGraphicsPipeline::Triangles;
199 case QSGGeometry::DrawTriangleStrip:
200 topology = QRhiGraphicsPipeline::TriangleStrip;
202 case QSGGeometry::DrawTriangleFan:
204 static bool triangleFanSupported =
false;
205 static bool triangleFanSupportChecked =
false;
206 if (!triangleFanSupportChecked) {
207 triangleFanSupportChecked =
true;
208 triangleFanSupported = rhi->isFeatureSupported(QRhi::TriangleFanTopology);
210 if (triangleFanSupported) {
211 topology = QRhiGraphicsPipeline::TriangleFan;
217 qWarning(
"Primitive topology 0x%x not supported", geomDrawMode);
225 material->setFlag(QSGMaterial::MultiView2, multiViewCount == 2);
226 material->setFlag(QSGMaterial::MultiView3, multiViewCount == 3);
227 material->setFlag(QSGMaterial::MultiView4, multiViewCount == 4);
231 const QSGGeometry *geometry,
232 QSGRendererInterface::RenderMode renderMode,
237 QSGMaterialType *type = material->type();
238 ShaderKey key = { type, renderMode, multiViewCount };
239 Shader *shader = rewrittenShaders.value(key,
nullptr);
244 QSGMaterialShader *s =
static_cast<QSGMaterialShader *>(material->createShader(renderMode));
245 context->initializeRhiShader(s, QShader::BatchableVertexShader);
246 shader->materialShader = s;
247 shader->inputLayout = calculateVertexInputLayout(s, geometry,
true);
248 QSGMaterialShaderPrivate *sD = QSGMaterialShaderPrivate::get(s);
250 { QRhiShaderStage::Vertex, sD->shader(QShader::VertexStage), QShader::BatchableVertexShader },
251 { QRhiShaderStage::Fragment, sD->shader(QShader::FragmentStage) }
254 shader->lastOpacity = 0;
256 rewrittenShaders[key] = shader;
260ShaderManager::Shader *
ShaderManager::prepareMaterialNoRewrite(QSGMaterial *material,
261 const QSGGeometry *geometry,
262 QSGRendererInterface::RenderMode renderMode,
267 QSGMaterialType *type = material->type();
268 ShaderKey key = { type, renderMode, multiViewCount };
269 Shader *shader = stockShaders.value(key,
nullptr);
274 QSGMaterialShader *s =
static_cast<QSGMaterialShader *>(material->createShader(renderMode));
275 context->initializeRhiShader(s, QShader::StandardShader);
276 shader->materialShader = s;
277 shader->inputLayout = calculateVertexInputLayout(s, geometry,
false);
278 QSGMaterialShaderPrivate *sD = QSGMaterialShaderPrivate::get(s);
280 { QRhiShaderStage::Vertex, sD->shader(QShader::VertexStage) },
281 { QRhiShaderStage::Fragment, sD->shader(QShader::FragmentStage) }
284 shader->lastOpacity = 0;
286 stockShaders[key] = shader;
293 qDeleteAll(stockShaders);
294 stockShaders.clear();
295 qDeleteAll(rewrittenShaders);
296 rewrittenShaders.clear();
298 qDeleteAll(pipelineCache);
299 pipelineCache.clear();
300 ++pipelineCacheGeneration;
308 for (ShaderManager::Shader *sms : std::as_const(stockShaders)) {
309 QSGMaterialShader *s = sms->materialShader;
311 QSGMaterialShaderPrivate *sd = QSGMaterialShaderPrivate::get(s);
312 sd->clearCachedRendererData();
315 for (ShaderManager::Shader *sms : std::as_const(rewrittenShaders)) {
316 QSGMaterialShader *s = sms->materialShader;
318 QSGMaterialShaderPrivate *sd = QSGMaterialShaderPrivate::get(s);
319 sd->clearCachedRendererData();
326 static int extraIndent = 0;
329 QByteArray ind(indent + extraIndent + 10,
' ');
332 qDebug(
"%s - no info", ind.constData());
335 for (QSet<Node *>::const_iterator it = i->subRoots.constBegin();
336 it != i->subRoots.constEnd(); ++it) {
337 qDebug() << ind.constData() <<
"-" << *it;
338 qsg_dumpShadowRoots((*it)->rootInfo(), indent);
347#ifndef QT_NO_DEBUG_OUTPUT
348 static int indent = 0;
351 QByteArray ind(indent,
' ');
353 if (n->type() == QSGNode::ClipNodeType || n->isBatchRoot) {
354 qDebug() << ind.constData() <<
"[X]" << n->sgNode << Qt::hex << uint(n->sgNode->flags());
358 d << ind.constData() <<
"[ ]" << n->sgNode << Qt::hex << uint(n->sgNode->flags());
359 if (n->type() == QSGNode::GeometryNodeType)
360 d <<
"order" << Qt::dec << n->element()->order;
378 m_combined_matrix_stack.add(&m_identityMatrix);
379 m_rootMatrices.add(m_identityMatrix);
384 m_current_clip =
nullptr;
387 m_transformChange = 0;
390 Node *sn = renderer->m_nodes.value(n, 0);
393 if (Q_UNLIKELY(debug_roots()))
396 if (Q_UNLIKELY(debug_build())) {
397 qDebug(
"Updater::updateStates()");
398 if (sn->dirtyState & (QSGNode::DirtyNodeAdded << 16))
399 qDebug(
" - nodes have been added");
400 if (sn->dirtyState & (QSGNode::DirtyMatrix << 16))
401 qDebug(
" - transforms have changed");
402 if (sn->dirtyState & (QSGNode::DirtyOpacity << 16))
403 qDebug(
" - opacity has changed");
404 if (uint(sn->dirtyState) & uint(QSGNode::DirtyForceUpdate << 16))
405 qDebug(
" - forceupdate");
409 renderer->m_visualizer->visualizeChangesPrepare(sn);
416 if (m_added == 0 && n->dirtyState == 0 && m_force_update == 0 && m_transformChange == 0 && m_opacityChange == 0)
420 if (n->dirtyState & QSGNode::DirtyNodeAdded)
423 int force = m_force_update;
424 if (n->dirtyState & QSGNode::DirtyForceUpdate)
428 case QSGNode::OpacityNodeType:
431 case QSGNode::TransformNodeType:
434 case QSGNode::GeometryNodeType:
437 case QSGNode::ClipNodeType:
440 case QSGNode::RenderNodeType:
450 m_force_update = force;
458 QSGClipNode *cn =
static_cast<QSGClipNode *>(n->sgNode);
460 if (m_roots.last() && m_added > 0)
461 renderer->registerBatchRoot(n, m_roots.last());
463 cn->setRendererClipList(m_current_clip);
466 m_rootMatrices.add(m_rootMatrices.last() * *m_combined_matrix_stack.last());
467 extra->matrix = m_rootMatrices.last();
468 cn->setRendererMatrix(&extra->matrix);
469 m_combined_matrix_stack << &m_identityMatrix;
473 m_current_clip = cn->clipList();
474 m_rootMatrices.pop_back();
475 m_combined_matrix_stack.pop_back();
481 QSGOpacityNode *on =
static_cast<QSGOpacityNode *>(n->sgNode);
483 qreal combined = m_opacity_stack.last() * on->opacity();
484 on->setCombinedOpacity(combined);
485 m_opacity_stack.add(combined);
487 if (m_added == 0 && n->dirtyState & QSGNode::DirtyOpacity) {
488 bool was = n->isOpaque;
491 renderer->m_rebuild = Renderer::FullRebuild;
503 m_opacity_stack.pop_back();
508 bool popMatrixStack =
false;
509 bool popRootStack =
false;
510 bool dirty = n->dirtyState & QSGNode::DirtyMatrix;
512 QSGTransformNode *tn =
static_cast<QSGTransformNode *>(n->sgNode);
514 if (n->isBatchRoot) {
515 if (m_added > 0 && m_roots.last())
516 renderer->registerBatchRoot(n, m_roots.last());
517 tn->setCombinedMatrix(m_rootMatrices.last() * *m_combined_matrix_stack.last() * tn->matrix());
522 if (!n->becameBatchRoot && m_added == 0 && m_force_update == 0 && m_opacityChange == 0 && dirty && (n->dirtyState & ~QSGNode::DirtyMatrix) == 0) {
524 for (QSet<Node *>::const_iterator it = info->subRoots.constBegin();
525 it != info->subRoots.constEnd(); ++it) {
531 n->becameBatchRoot =
false;
533 m_combined_matrix_stack.add(&m_identityMatrix);
535 m_rootMatrices.add(tn->combinedMatrix());
537 popMatrixStack =
true;
539 }
else if (!tn->matrix().isIdentity()) {
540 tn->setCombinedMatrix(*m_combined_matrix_stack.last() * tn->matrix());
541 m_combined_matrix_stack.add(&tn->combinedMatrix());
542 popMatrixStack =
true;
544 tn->setCombinedMatrix(*m_combined_matrix_stack.last());
555 m_combined_matrix_stack.pop_back();
558 m_rootMatrices.pop_back();
564 QSGGeometryNode *gn =
static_cast<QSGGeometryNode *>(n->sgNode);
566 gn->setRendererMatrix(m_combined_matrix_stack.last());
567 gn->setRendererClipList(m_current_clip);
568 gn->setInheritedOpacity(m_opacity_stack.last());
573 e->translateOnlyToRoot = isTranslate(*gn->matrix());
577 while (info !=
nullptr) {
580 renderer->m_rebuild |= Renderer::BuildRenderLists;
582 renderer->m_rebuild |= Renderer::BuildRenderListsForTaggedRoots;
583 renderer->m_taggedRoots << e
->root;
591 renderer->m_rebuild |= Renderer::FullRebuild;
594 if (m_transformChange) {
596 e->translateOnlyToRoot = isTranslate(*gn->matrix());
598 if (m_opacityChange) {
601 renderer->invalidateBatchAndOverlappingRenderOrders(e
->batch);
615 if (n->type() == QSGNode::TransformNodeType)
616 m =
static_cast<QSGTransformNode *>(n->sgNode)->matrix() * m;
622 if (node->type() == QSGNode::ClipNodeType) {
623 static_cast<ClipBatchRootInfo *>(info)->matrix = m;
625 Q_ASSERT(node->type() == QSGNode::TransformNodeType);
626 static_cast<QSGTransformNode *>(node->sgNode)->setCombinedMatrix(m);
629 for (QSet<Node *>::const_iterator it = info->subRoots.constBegin();
630 it != info->subRoots.constEnd(); ++it) {
638 for (
int a=0; a<g->attributeCount(); ++a) {
639 const QSGGeometry::Attribute &attr = g->attributes()[a];
640 if (attr.isVertexCoordinate && attr.tupleSize == 2 && attr.type == QSGGeometry::FloatType) {
643 vaOffset += attr.tupleSize * size_of_type(attr.type);
651 const float *m = matrix.constData();
652 if (isScale(matrix)) {
672 set(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX);
682 Q_ASSERT(!boundsComputed);
683 boundsComputed =
true;
685 QSGGeometry *g = node->geometry();
686 int offset = qsg_positionAttribute(g);
689 bounds.set(-FLT_MAX, -FLT_MAX, FLT_MAX, FLT_MAX);
693 bounds.set(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX);
694 char *vd = (
char *) g->vertexData() + offset;
695 for (
int i=0; i<g->vertexCount(); ++i) {
697 vd += g->sizeOfVertex();
699 bounds.map(*node->matrix());
701 if (!qt_is_finite(bounds.tl.x) || bounds.tl.x == FLT_MAX)
703 if (!qt_is_finite(bounds.tl.y) || bounds.tl.y == FLT_MAX)
705 if (!qt_is_finite(bounds.br.x) || bounds.br.x == -FLT_MAX)
707 if (!qt_is_finite(bounds.br.y) || bounds.br.y == -FLT_MAX)
713 boundsOutsideFloatRange = bounds.isOutsideFloatRange();
722 if (node->activeMaterial()->flags().testFlag(QSGMaterial::RequiresFullMatrixExceptTranslate)) {
723 const float margin = 2.0f;
735 while (n && (n == e || n->removed))
743 QSGMaterial *m = e->node->activeMaterial();
744 QSGMaterial *nm = n->node->activeMaterial();
745 return (nm->type() == m->type() && nm->viewCount() == m->viewCount() && nm->compare(m) == 0)
751
752
753
754
758 Q_ASSERT_X(e,
"Batch::geometryWasChanged",
"Batch is expected to 'valid' at this time");
760 while (e && (e->node == gn || e->removed))
762 if (!e || e->node->geometry()->attributes() == gn->geometry()->attributes()) {
796
797
798
817 only &= e->translateOnlyToRoot;
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
843 if (e->boundsOutsideFloatRange)
845 if (!is2DSafe(*e->node->matrix()))
866 for (
int i=0; i<batches.size(); ++i) {
867 sum += qsg_countNodesInBatch(batches.at(i));
894#if defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
939 qDebug(
"Batch thresholds: nodes: %d vertices: %d srb pool: %d buffer pool: %d",
958 qsg_wipeBuffer(&batch->vbo);
959 qsg_wipeBuffer(&batch->ibo);
960 batch->stencilClipState.reset();
1405#ifndef QT_NO_DEBUG_OUTPUT
1410 debug <<
"Geometry";
1412 debug <<
"Material";
1422 debug <<
"SubtreeBlocked";
1424 debug <<
"ForceUpdate";
1439#if defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1642 for (
int i=0; i<renderList.size(); ++i) {
1643 Element *e = renderList.at(i);
1644 if (e && !e->removed) {
1653 for (
int i=0; i<orphans.size(); ++i) {
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1761#if defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
1790
1791
1828 for (
int j =
i - 1;
j >= 0; --
j) {
1870#if defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
1884
1885
1886
1887
1888
1889
1890
1891
1892
1946#if !defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
1981
1982
1983
1984
2001 case QSGGeometry::DrawTriangleStrip:
2008 case QSGGeometry::DrawLines:
2010 return iCount - (iCount % 2);
2011 case QSGGeometry::DrawTriangles:
2013 return iCount - (iCount % 3);
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2142 if (node->type() == QSGNode::TransformNodeType)
2143 return static_cast<QSGTransformNode *>(node->sgNode)->combinedMatrix();
2144 Q_ASSERT(node->type() == QSGNode::ClipNodeType);
2145 QSGClipNode *c =
static_cast<QSGClipNode *>(node->sgNode);
2146 return *c->matrix();
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2312 Q_ASSERT_X(
false,
"uploadBatch (unmerged)",
"uint index with ushort effective index - cannot happen");
2320#ifndef QT_NO_DEBUG_OUTPUT
2326 dump <<
" --- " <<
i <<
": ";
2336 dump << *(
const float *)(
vd +
offset +
t *
sizeof(
float)) <<
" ";
2340 dump << *(
const unsigned char *)(
vd +
offset +
t *
sizeof(
unsigned char)) <<
" ";
2438 qWarning(
"Failed to build stencil clip pipeline");
2557 qWarning(
"Failed to build stencil clip vertex buffer");
2575 qWarning(
"Failed to build stencil clip index buffer");
2593 qWarning(
"Failed to build stencil clip uniform buffer");
2606 qWarning(
"Failed to build stencil clip srb");
2630 qWarning(
"updateClipState: Clip list entries have different primitive topologies, this is not currently supported.");
2632 qWarning(
"updateClipState: Clip list entries have different vertex input layouts, this is must not happen.");
2714 }
else if (
i == 1) {
2743 return f == QRhiGraphicsPipeline::ConstantColor
2744 || f == QRhiGraphicsPipeline::OneMinusConstantColor
2745 || f == QRhiGraphicsPipeline::ConstantAlpha
2746 || f == QRhiGraphicsPipeline::OneMinusConstantAlpha;
2874 qWarning(
"Failed to build graphics pipeline state");
2911static QRhiSampler *
newSampler(QRhi *rhi,
const QSGSamplerDescription &desc)
2913 QRhiSampler::Filter magFilter;
2914 QRhiSampler::Filter minFilter;
2915 QRhiSampler::Filter mipmapMode;
2916 QRhiSampler::AddressMode u;
2917 QRhiSampler::AddressMode v;
2919 switch (desc.filtering) {
2920 case QSGTexture::None:
2922 case QSGTexture::Nearest:
2923 magFilter = minFilter = QRhiSampler::Nearest;
2925 case QSGTexture::Linear:
2926 magFilter = minFilter = QRhiSampler::Linear;
2930 magFilter = minFilter = QRhiSampler::Nearest;
2934 switch (desc.mipmapFiltering) {
2935 case QSGTexture::None:
2936 mipmapMode = QRhiSampler::None;
2938 case QSGTexture::Nearest:
2939 mipmapMode = QRhiSampler::Nearest;
2941 case QSGTexture::Linear:
2942 mipmapMode = QRhiSampler::Linear;
2946 mipmapMode = QRhiSampler::None;
2950 switch (desc.horizontalWrap) {
2951 case QSGTexture::Repeat:
2952 u = QRhiSampler::Repeat;
2954 case QSGTexture::ClampToEdge:
2955 u = QRhiSampler::ClampToEdge;
2957 case QSGTexture::MirroredRepeat:
2958 u = QRhiSampler::Mirror;
2962 u = QRhiSampler::ClampToEdge;
2966 switch (desc.verticalWrap) {
2967 case QSGTexture::Repeat:
2968 v = QRhiSampler::Repeat;
2970 case QSGTexture::ClampToEdge:
2971 v = QRhiSampler::ClampToEdge;
2973 case QSGTexture::MirroredRepeat:
2974 v = QRhiSampler::Mirror;
2978 v = QRhiSampler::ClampToEdge;
2982 return rhi->newSampler(magFilter, minFilter, mipmapMode, u, v);
3006 Q_ASSERT(
int(QSGMaterialShader::GraphicsPipelineState::OneMinusSrc1Alpha) ==
int(QRhiGraphicsPipeline::OneMinusSrc1Alpha));
3007 Q_ASSERT(
int(QSGMaterialShader::GraphicsPipelineState::BlendOp::Max) ==
int(QRhiGraphicsPipeline::Max));
3008 Q_ASSERT(
int(QSGMaterialShader::GraphicsPipelineState::A) ==
int(QRhiGraphicsPipeline::A));
3009 Q_ASSERT(
int(QSGMaterialShader::GraphicsPipelineState::CullBack) ==
int(QRhiGraphicsPipeline::Back));
3010 Q_ASSERT(
int(QSGMaterialShader::GraphicsPipelineState::Line) ==
int(QRhiGraphicsPipeline::Line));
3011 dst->srcColor = QSGMaterialShader::GraphicsPipelineState::BlendFactor(src->srcColor);
3012 dst->dstColor = QSGMaterialShader::GraphicsPipelineState::BlendFactor(src->dstColor);
3020 dst->separateBlendFactors =
false;
3022 dst->srcAlpha = QSGMaterialShader::GraphicsPipelineState::BlendFactor(src->srcAlpha);
3023 dst->dstAlpha = QSGMaterialShader::GraphicsPipelineState::BlendFactor(src->dstAlpha);
3025 dst->opColor = QSGMaterialShader::GraphicsPipelineState::BlendOp(src->opColor);
3026 dst->opAlpha = QSGMaterialShader::GraphicsPipelineState::BlendOp(src->opAlpha);
3028 dst->colorWrite = QSGMaterialShader::GraphicsPipelineState::ColorMask(
int(src->colorWrite));
3030 dst->cullMode = QSGMaterialShader::GraphicsPipelineState::CullMode(src->cullMode);
3031 dst->polygonMode = QSGMaterialShader::GraphicsPipelineState::PolygonMode(src->polygonMode);
3035 QSGMaterialShader::GraphicsPipelineState *src)
3038 dst->srcColor = QRhiGraphicsPipeline::BlendFactor(src->srcColor);
3039 dst->dstColor = QRhiGraphicsPipeline::BlendFactor(src->dstColor);
3040 if (src->separateBlendFactors) {
3041 dst->srcAlpha = QRhiGraphicsPipeline::BlendFactor(src->srcAlpha);
3042 dst->dstAlpha = QRhiGraphicsPipeline::BlendFactor(src->dstAlpha);
3044 dst->srcAlpha = dst->srcColor;
3045 dst->dstAlpha = dst->dstColor;
3047 dst->opColor = QRhiGraphicsPipeline::BlendOp(src->opColor);
3048 dst->opAlpha = QRhiGraphicsPipeline::BlendOp(src->opAlpha);
3049 dst->colorWrite = QRhiGraphicsPipeline::ColorMask(
int(src->colorWrite));
3050 dst->cullMode = QRhiGraphicsPipeline::CullMode(src->cullMode);
3051 dst->polygonMode = QRhiGraphicsPipeline::PolygonMode(src->polygonMode);
3140 qWarning(
"No QSGTexture provided from updateSampledImage(). This is wrong.");
3161 qWarning(
"QSGTexture anisotropy levels are not currently supported");
3178 qWarning(
"Failed to build sampler");
3343 Q_ASSERT_X(
false,
"updateMaterialDynamicData",
"No srb action set, this cannot happen");
3385#ifndef QT_NO_DEBUG_OUTPUT
3494 qWarning(
"Line widths other than 1 are not supported by the graphics API");
3502 qWarning(
"Point size is not controllable by QSGGeometry. "
3503 "Set gl_PointSize from the vertex shader instead.");
3822
3823
3824
3866 qWarning(
"prepareRenderPass() called with an already prepared render pass context");
3890 type +=
" renderlists";
3897 qDebug() <<
"Renderer::render()" <<
this <<
type;
3913 qDebug(
"Opaque render lists %s:", (
complete ?
"(complete)" :
"(partial)"));
3918 qDebug(
"Alpha render list %s:",
complete ?
"(complete)" :
"(partial)");
3939 qDebug(
"Opaque Batches:");
3947 qDebug(
"Alpha Batches:");
4110#if defined(QSGBATCHRENDERER_INVALIDATE_WEDGED_NODES)
4162 qWarning(
"recordRenderPass() called without a prepared render pass context");
4219 qDebug(
" -> times: build: %d, prepare(opaque/alpha): %d/%d, sorting: %d, upload(opaque/alpha): %d/%d, record rendering: %d",
4385 else if (
mode ==
"clip")
4387 else if (
mode ==
"overdraw")
4389 else if (
mode ==
"batches")
4391 else if (
mode ==
"changes")
4404 && a.depthFunc == b.depthFunc
4406 && a.srcColor == b.srcColor
4407 && a.dstColor == b.dstColor
4408 && a.srcAlpha == b.srcAlpha
4409 && a.dstAlpha == b.dstAlpha
4410 && a.opColor == b.opColor
4411 && a.opAlpha == b.opAlpha
4412 && a.colorWrite == b.colorWrite
4413 && a.cullMode == b.cullMode
4417 && a.drawMode == b.drawMode
4419 && a.polygonMode == b.polygonMode
4446 return a.state == b.state
4447 && a
.sms->materialShader == b
.sms->materialShader
4448 && a.renderTargetDescription == b.renderTargetDescription
4449 && a.srbLayoutDescription == b.srbLayoutDescription;
4459 return qHash(k.state, seed)
4460 ^ qHash(k.sms->materialShader)
4461 ^ k.extra.renderTargetDescriptionHash
4462 ^ k.extra.srbLayoutDescriptionHash;
4467 return a.type == b.type
4468 && a.renderMode == b.renderMode
4479 return qHash(k.type, seed) ^
int(k.renderMode) ^ k.multiViewCount;
4492#define QSGNODE_DIRTY_PARENT (QSGNode::DirtyNodeAdded
4493 | QSGNode::DirtyOpacity
4494 | QSGNode::DirtyMatrix
4495 | QSGNode::DirtyNodeRemoved)
4500 uint selfDirty = n->dirtyState | parentChanges;
4501 if (n->type() == QSGNode::GeometryNodeType && selfDirty != 0)
4502 m_visualizeChangeSet.insert(n, selfDirty);
4504 visualizeChangesPrepare(child, childDirty);
4512#include "moc_qsgbatchrenderer_p.cpp"
void clearCachedRendererData()
void updateRootTransforms(Node *n, Node *root, const QMatrix4x4 &combined)
void visitClipNode(Node *n)
void updateStates(QSGNode *n) override
void visitOpacityNode(Node *n)
void updateRootTransforms(Node *n)
void visitTransformNode(Node *n)
void visitGeometryNode(Node *n)
Visualizer(Renderer *renderer)
VisualizeMode m_visualizeMode
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)
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)
const quint32 MIN_UNIFORM_BUFFER_SIZE
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
static int qsg_countNodesInBatch(const Batch *batch)
const int UNIFORM_BUFFER_SHRINK_FRAMES
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)
#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)
bool geometryWasChanged(QSGGeometryNode *gn)
bool isSafeToBatch() const
void cleanupRemovedElements()
BatchCompatibility isMaterialCompatible(Element *e) const
bool isTranslateOnlyToRoot() const
const ShaderManagerShader * sms
BatchRootInfo * rootInfo() const
ClipBatchRootInfo * clipInfo() const
RenderNodeElement * renderNodeElement() const
Element * element() const
void operator|=(const Pt &pt)
void set(float left, float top, float right, float bottom)
void map(const QMatrix4x4 &m)
bool stencilEnabled() const override
QRect scissorRect() const override
const QMatrix4x4 * projectionMatrix() const override
const QRegion * clipRegion() const override
bool scissorEnabled() const override
int stencilValue() const override
const QMatrix4x4 * m_projectionMatrix