diff options
-rw-r--r-- | src/gui/rhi/qrhi.cpp | 2 | ||||
-rw-r--r-- | src/gui/rhi/qrhi_p.h | 5 | ||||
-rw-r--r-- | tests/auto/gui/rhi/qrhi/tst_qrhi.cpp | 9 |
3 files changed, 13 insertions, 3 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index 420e70cecf..64168b4dc6 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -3058,7 +3058,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); } } diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index 81b00cd07f..527d72e486 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -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; } } diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp index 603acc03de..8398dac3eb 100644 --- a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp +++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp @@ -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) |