summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2021-09-07 15:53:59 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-09-07 22:12:52 +0000
commitd9675966287521fdc158430f5bce5370cbb80cce (patch)
tree9f128008d140705de7fcf1ddb33bdc8d9d42d443
parenta6cc60ee029602651932108f517a59bac8ee2699 (diff)
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. Change-Id: If74463fa5140ffa2b1d5be97b71868848ad46614 Reviewed-by: Andy Nichols <andy.nichols@qt.io> (cherry picked from commit ce9d0491f2a3836991c3c44fa70c32f1f606ab28) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/gui/rhi/qrhi.cpp2
-rw-r--r--src/gui/rhi/qrhi_p.h5
-rw-r--r--tests/auto/gui/rhi/qrhi/tst_qrhi.cpp9
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)