rhi: Improve srb layout serialization helpers

Be idiomatic and return the output iterator one past the last element.
Otherwise passing in a plain pointer (as exercised by the autotest now)
fails to function because we write over the same 4 elements again and
again for each binding.

Pick-to: 6.2
Change-Id: If74463fa5140ffa2b1d5be97b71868848ad46614
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
This commit is contained in:
Laszlo Agocs 2021-09-07 15:53:59 +02:00
parent 7e8c7b3ed8
commit ce9d0491f2
3 changed files with 13 additions and 3 deletions

View File

@ -3052,7 +3052,7 @@ void QRhiImplementation::updateLayoutDesc(QRhiShaderResourceBindings *srb)
const QRhiShaderResourceBinding::Data *d = b.data();
srb->m_layoutDescHash ^= uint(d->binding) ^ uint(d->stage) ^ uint(d->type)
^ uint(d->type == QRhiShaderResourceBinding::SampledTexture ? d->u.stex.count : 1);
d->serialize(layoutDescAppender);
layoutDescAppender = d->serialize(layoutDescAppender);
}
}

View File

@ -413,13 +413,14 @@ public:
} u;
template<typename Output>
void serialize(Output dst) const
Output serialize(Output dst) const
{
// must write out exactly LAYOUT_DESC_ENTRIES_PER_BINDING elements here
*dst++ = quint32(binding);
*dst++ = quint32(stage);
*dst++ = quint32(type);
*dst++ = quint32(type == QRhiShaderResourceBinding::SampledTexture ? u.stex.count : 1);
return dst;
}
};
@ -434,7 +435,7 @@ public:
Output dst)
{
while (first != last) {
first->data()->serialize(dst);
dst = first->data()->serialize(dst);
++first;
}
}

View File

@ -3273,6 +3273,7 @@ void tst_QRhi::srbLayoutCompatibility()
QVERIFY(srb2->isLayoutCompatible(srb1.data()));
QCOMPARE(srb1->serializedLayoutDescription(), srb2->serializedLayoutDescription());
QVERIFY(srb1->serializedLayoutDescription().count() == 0);
}
// different count (not compatible)
@ -3290,6 +3291,8 @@ void tst_QRhi::srbLayoutCompatibility()
QVERIFY(!srb2->isLayoutCompatible(srb1.data()));
QVERIFY(srb1->serializedLayoutDescription() != srb2->serializedLayoutDescription());
QVERIFY(srb1->serializedLayoutDescription().count() == 0);
QVERIFY(srb2->serializedLayoutDescription().count() == 1 * QRhiShaderResourceBinding::LAYOUT_DESC_ENTRIES_PER_BINDING);
}
// full match (compatible)
@ -3314,6 +3317,7 @@ void tst_QRhi::srbLayoutCompatibility()
QVERIFY(!srb1->serializedLayoutDescription().isEmpty());
QVERIFY(!srb2->serializedLayoutDescription().isEmpty());
QCOMPARE(srb1->serializedLayoutDescription(), srb2->serializedLayoutDescription());
QVERIFY(srb1->serializedLayoutDescription().count() == 2 * QRhiShaderResourceBinding::LAYOUT_DESC_ENTRIES_PER_BINDING);
// see what we would get if a binding list got serialized "manually", without pulling it out from the srb after building
// (the results should be identical)
@ -3323,6 +3327,11 @@ void tst_QRhi::srbLayoutCompatibility()
QVector<quint32> layoutDesc2;
QRhiShaderResourceBinding::serializeLayoutDescription(srb2->cbeginBindings(), srb2->cendBindings(), std::back_inserter(layoutDesc2));
QCOMPARE(layoutDesc2, srb2->serializedLayoutDescription());
// exercise with an "output iterator" different from back_inserter
quint32 layoutDesc3[2 * QRhiShaderResourceBinding::LAYOUT_DESC_ENTRIES_PER_BINDING];
QRhiShaderResourceBinding::serializeLayoutDescription(srb1->cbeginBindings(), srb1->cendBindings(), layoutDesc3);
QVERIFY(!memcmp(layoutDesc3, layoutDesc1.constData(), sizeof(quint32) * 2 * QRhiShaderResourceBinding::LAYOUT_DESC_ENTRIES_PER_BINDING));
}
// different visibility (not compatible)