summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2021-09-06 15:45:01 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2021-09-07 14:41:11 +0200
commitb6b0c33058ba7f43661e316d9f27d4102f6a988f (patch)
treee8b61d8730a3cb3725ac77be70546f4830ea0802 /src/gui
parentcca8ed0547405b1c018e995ad366ba0ab4c2a0e8 (diff)
rhi: Make the serialized srb layout description accessible
...by the Qt Quick renderer, for example. A typical Qt Quick material binding set serializes to 8 uints. This would not demand a container like QVector. However, being implicitly shared is essential here due to the intended usage (query the serialized blob, put it into a cache key, hash it, compare it, all without any copying and new allocs; we can afford an extra alloc upon each srb construction, but don't want more afterwards in the rendering engines) Also make it clear in the pipeline docs that the optimization Qt Quick is (soon going to be) doing is legal. (the srb ref in the pipeline can be dead and dangling as long as every call to setShaderResources() specifies a layout-compatible alternative) Pick-to: 6.2 Change-Id: I97efbea1fa3516b10c9832adbab0a21b7bc0845d Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/rhi/qrhi.cpp8
-rw-r--r--src/gui/rhi/qrhi_p.h7
2 files changed, 14 insertions, 1 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp
index 70c8bf5813..2da5959b56 100644
--- a/src/gui/rhi/qrhi.cpp
+++ b/src/gui/rhi/qrhi.cpp
@@ -2996,6 +2996,7 @@ QRhiResource::Type QRhiTextureRenderTarget::resourceType() const
QRhiShaderResourceBindings::QRhiShaderResourceBindings(QRhiImplementation *rhi)
: QRhiResource(rhi)
{
+ m_layoutDesc.reserve(BINDING_PREALLOC * LAYOUT_DESC_FIELD_COUNT);
}
/*!
@@ -5614,6 +5615,13 @@ void QRhiCommandBuffer::setGraphicsPipeline(QRhiGraphicsPipeline *ps)
srb. In this case setShaderResources() must be called even if \a srb is
the same as in the last call.
+ When \a srb is not null, the QRhiShaderResourceBindings object the pipeline
+ was built with in create() is guaranteed to be not accessed in any form. In
+ fact, it does not need to be valid even at this point: destroying the
+ pipeline's associated srb after create() and instead explicitly specifying
+ another, \l{QRhiShaderResourceBindings::isLayoutCompatible()}{layout
+ compatible} one in every setShaderResources() call is valid.
+
\a dynamicOffsets allows specifying buffer offsets for uniform buffers that
were associated with \a srb via
QRhiShaderResourceBinding::uniformBufferWithDynamicOffset(). This is
diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h
index 1e570e8818..8c3e0fdfb2 100644
--- a/src/gui/rhi/qrhi_p.h
+++ b/src/gui/rhi/qrhi_p.h
@@ -1037,6 +1037,8 @@ public:
bool isLayoutCompatible(const QRhiShaderResourceBindings *other) const;
+ QVector<uint> serializedLayoutDescription() const { return m_layoutDesc; }
+
virtual bool create() = 0;
enum UpdateFlag {
@@ -1052,7 +1054,10 @@ protected:
QRhiShaderResourceBindings(QRhiImplementation *rhi);
QVarLengthArray<QRhiShaderResourceBinding, BINDING_PREALLOC> m_bindings;
uint m_layoutDescHash = 0;
- QVarLengthArray<uint, BINDING_PREALLOC * LAYOUT_DESC_FIELD_COUNT> m_layoutDesc;
+ // Intentionally not using QVLA for m_layoutDesc: clients like Qt Quick are much
+ // better served with an implicitly shared container here, because they will likely
+ // throw this directly into structs serving as cache keys.
+ QVector<uint> m_layoutDesc;
friend class QRhiImplementation;
#ifndef QT_NO_DEBUG_STREAM
friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderResourceBindings &);