Skip to content

Commit 2462d9d

Browse files
committed
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>
1 parent 3b01f90 commit 2462d9d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,15 @@ ShaderManager::Shader *ShaderManager::prepareMaterial(QSGMaterial *material,
213213
QSGRendererInterface::RenderMode renderMode,
214214
int multiViewCount)
215215
{
216+
qsg_setMultiViewFlagsOnMaterial(material, multiViewCount);
217+
216218
QSGMaterialType *type = material->type();
217219
ShaderKey key = { type, renderMode, multiViewCount };
218220
Shader *shader = rewrittenShaders.value(key, nullptr);
219221
if (shader)
220222
return shader;
221223

222224
shader = new Shader;
223-
qsg_setMultiViewFlagsOnMaterial(material, multiViewCount);
224225
QSGMaterialShader *s = static_cast<QSGMaterialShader *>(material->createShader(renderMode));
225226
context->initializeRhiShader(s, QShader::BatchableVertexShader);
226227
shader->materialShader = s;
@@ -242,14 +243,15 @@ ShaderManager::Shader *ShaderManager::prepareMaterialNoRewrite(QSGMaterial *mate
242243
QSGRendererInterface::RenderMode renderMode,
243244
int multiViewCount)
244245
{
246+
qsg_setMultiViewFlagsOnMaterial(material, multiViewCount);
247+
245248
QSGMaterialType *type = material->type();
246249
ShaderKey key = { type, renderMode, multiViewCount };
247250
Shader *shader = stockShaders.value(key, nullptr);
248251
if (shader)
249252
return shader;
250253

251254
shader = new Shader;
252-
qsg_setMultiViewFlagsOnMaterial(material, multiViewCount);
253255
QSGMaterialShader *s = static_cast<QSGMaterialShader *>(material->createShader(renderMode));
254256
context->initializeRhiShader(s, QShader::StandardShader);
255257
shader->materialShader = s;
@@ -705,7 +707,7 @@ BatchCompatibility Batch::isMaterialCompatible(Element *e) const
705707

706708
QSGMaterial *m = e->node->activeMaterial();
707709
QSGMaterial *nm = n->node->activeMaterial();
708-
return (nm->type() == m->type() && nm->compare(m) == 0)
710+
return (nm->type() == m->type() && nm->viewCount() == m->viewCount() && nm->compare(m) == 0)
709711
? BatchIsCompatible
710712
: BatchBreaksOnCompare;
711713
}
@@ -1739,6 +1741,7 @@ void Renderer::prepareOpaqueBatches()
17391741
&& gni->geometry()->attributes() == gnj->geometry()->attributes()
17401742
&& gni->inheritedOpacity() == gnj->inheritedOpacity()
17411743
&& gni->activeMaterial()->type() == gnj->activeMaterial()->type()
1744+
&& gni->activeMaterial()->viewCount() == gnj->activeMaterial()->viewCount()
17421745
&& gni->activeMaterial()->compare(gnj->activeMaterial()) == 0) {
17431746
ej->batch = batch;
17441747
next->nextInBatch = ej;
@@ -1850,6 +1853,7 @@ void Renderer::prepareAlphaBatches()
18501853
&& gni->geometry()->attributes() == gnj->geometry()->attributes()
18511854
&& gni->inheritedOpacity() == gnj->inheritedOpacity()
18521855
&& gni->activeMaterial()->type() == gnj->activeMaterial()->type()
1856+
&& gni->activeMaterial()->viewCount() == gnj->activeMaterial()->viewCount()
18531857
&& gni->activeMaterial()->compare(gnj->activeMaterial()) == 0) {
18541858
if (!overlapBounds.intersects(ej->bounds) || !checkOverlap(i+1, j - 1, ej->bounds)) {
18551859
ej->batch = batch;

0 commit comments

Comments
 (0)