aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2024-01-31 21:28:07 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2024-02-02 14:16:14 +0100
commit2462d9d8c60be46b5a929c46a5e9f5a97220b3d7 (patch)
tree4166eae87c93b8ef448d57dbe9980c5b4daa3066
parent3b01f90fa5fcb7320ce034dc9fe02279012d0b87 (diff)
sg: Fix some material-related multiview issues
Every time type is compared and compare() is called, viewCount() must also be compared. More importantly, the correct view count (handled via internal flags for SC/BC) has to be pushed to the QSGMaterial always, before checking for an existing QSGMaterialShader - otherwise if material #2 has a hit for a shader from material #1, material #2 will never have the view count pushed so it continues to report viewCount() == 1, which has...interesting consequences. Avoid this. Change-Id: I0808cc57f53a8dab891d1b36b41790f58c978ef4 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r--src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
index 59a9c1d894..5746d984bf 100644
--- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
+++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp
@@ -213,6 +213,8 @@ ShaderManager::Shader *ShaderManager::prepareMaterial(QSGMaterial *material,
QSGRendererInterface::RenderMode renderMode,
int multiViewCount)
{
+ qsg_setMultiViewFlagsOnMaterial(material, multiViewCount);
+
QSGMaterialType *type = material->type();
ShaderKey key = { type, renderMode, multiViewCount };
Shader *shader = rewrittenShaders.value(key, nullptr);
@@ -220,7 +222,6 @@ ShaderManager::Shader *ShaderManager::prepareMaterial(QSGMaterial *material,
return shader;
shader = new Shader;
- qsg_setMultiViewFlagsOnMaterial(material, multiViewCount);
QSGMaterialShader *s = static_cast<QSGMaterialShader *>(material->createShader(renderMode));
context->initializeRhiShader(s, QShader::BatchableVertexShader);
shader->materialShader = s;
@@ -242,6 +243,8 @@ ShaderManager::Shader *ShaderManager::prepareMaterialNoRewrite(QSGMaterial *mate
QSGRendererInterface::RenderMode renderMode,
int multiViewCount)
{
+ qsg_setMultiViewFlagsOnMaterial(material, multiViewCount);
+
QSGMaterialType *type = material->type();
ShaderKey key = { type, renderMode, multiViewCount };
Shader *shader = stockShaders.value(key, nullptr);
@@ -249,7 +252,6 @@ ShaderManager::Shader *ShaderManager::prepareMaterialNoRewrite(QSGMaterial *mate
return shader;
shader = new Shader;
- qsg_setMultiViewFlagsOnMaterial(material, multiViewCount);
QSGMaterialShader *s = static_cast<QSGMaterialShader *>(material->createShader(renderMode));
context->initializeRhiShader(s, QShader::StandardShader);
shader->materialShader = s;
@@ -705,7 +707,7 @@ BatchCompatibility Batch::isMaterialCompatible(Element *e) const
QSGMaterial *m = e->node->activeMaterial();
QSGMaterial *nm = n->node->activeMaterial();
- return (nm->type() == m->type() && nm->compare(m) == 0)
+ return (nm->type() == m->type() && nm->viewCount() == m->viewCount() && nm->compare(m) == 0)
? BatchIsCompatible
: BatchBreaksOnCompare;
}
@@ -1739,6 +1741,7 @@ void Renderer::prepareOpaqueBatches()
&& gni->geometry()->attributes() == gnj->geometry()->attributes()
&& gni->inheritedOpacity() == gnj->inheritedOpacity()
&& gni->activeMaterial()->type() == gnj->activeMaterial()->type()
+ && gni->activeMaterial()->viewCount() == gnj->activeMaterial()->viewCount()
&& gni->activeMaterial()->compare(gnj->activeMaterial()) == 0) {
ej->batch = batch;
next->nextInBatch = ej;
@@ -1850,6 +1853,7 @@ void Renderer::prepareAlphaBatches()
&& gni->geometry()->attributes() == gnj->geometry()->attributes()
&& gni->inheritedOpacity() == gnj->inheritedOpacity()
&& gni->activeMaterial()->type() == gnj->activeMaterial()->type()
+ && gni->activeMaterial()->viewCount() == gnj->activeMaterial()->viewCount()
&& gni->activeMaterial()->compare(gnj->activeMaterial()) == 0) {
if (!overlapBounds.intersects(ej->bounds) || !checkOverlap(i+1, j - 1, ej->bounds)) {
ej->batch = batch;