diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2021-09-01 12:26:39 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-09-03 20:50:01 +0000 |
commit | 976274a340464a68262955fe5d7090ebf8c49c7e (patch) | |
tree | e5940784ed665a6659adc0a88e85a3c7908328a2 | |
parent | 7057314961c8b92dab92524d9b3edbc4dab67481 (diff) |
rhi: Include resource count in srb layout compatibility checks
Relevant for Vulkan, given that descriptorCount is part of
VkDescriptorSetLayoutBinding, meaning two srbs with arrays of
SampledTextures should only be reported as compatible if the
array size matches.
Also reduces the prealloc size for the VLAs. For Qt Quick even a
lower number would be sufficient, but we still keep the number
something fairly high in order to play nice with Quick3D.
Change-Id: Id92b7c09b051ebe54b1fa2bf4ba78950fe60ba27
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
(cherry picked from commit 6cdf95a970f499f7d724e79638856a71942dd30d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/gui/rhi/qrhi.cpp | 13 | ||||
-rw-r--r-- | src/gui/rhi/qrhi_p.h | 6 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index c49a6d9c7f..2bf175f505 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -3050,9 +3050,11 @@ void QRhiImplementation::updateLayoutDesc(QRhiShaderResourceBindings *srb) srb->m_layoutDesc.clear(); for (const QRhiShaderResourceBinding &b : qAsConst(srb->m_bindings)) { const QRhiShaderResourceBinding::Data *d = b.data(); - // must match QRhiShaderResourceBinding::isLayoutCompatible() - srb->m_layoutDescHash ^= uint(d->binding) ^ uint(d->stage) ^ uint(d->type); - srb->m_layoutDesc << uint(d->binding) << uint(d->stage) << uint(d->type); + // the logic must match QRhiShaderResourceBinding::isLayoutCompatible() + const int count = d->type == QRhiShaderResourceBinding::SampledTexture ? d->u.stex.count : 1; + // the number of entries here should match LAYOUT_DESC_FIELD_COUNT + srb->m_layoutDescHash ^= uint(d->binding) ^ uint(d->stage) ^ uint(d->type) ^ uint(count); + srb->m_layoutDesc << uint(d->binding) << uint(d->stage) << uint(d->type) << uint(count); } } @@ -3116,7 +3118,10 @@ void QRhiImplementation::updateLayoutDesc(QRhiShaderResourceBindings *srb) */ bool QRhiShaderResourceBinding::isLayoutCompatible(const QRhiShaderResourceBinding &other) const { - return d.binding == other.d.binding && d.stage == other.d.stage && d.type == other.d.type; + // i.e. everything that goes into a VkDescriptorSetLayoutBinding must match + const int thisCount = d.type == QRhiShaderResourceBinding::SampledTexture ? d.u.stex.count : 1; + const int otherCount = other.d.type == QRhiShaderResourceBinding::SampledTexture ? other.d.u.stex.count : 1; + return d.binding == other.d.binding && d.stage == other.d.stage && d.type == other.d.type && thisCount == otherCount; } /*! diff --git a/src/gui/rhi/qrhi_p.h b/src/gui/rhi/qrhi_p.h index c2a09b7edf..1f05b7da8a 100644 --- a/src/gui/rhi/qrhi_p.h +++ b/src/gui/rhi/qrhi_p.h @@ -1040,10 +1040,12 @@ public: virtual bool create() = 0; protected: + static const int BINDING_PREALLOC = 12; + static const int LAYOUT_DESC_FIELD_COUNT = 4; QRhiShaderResourceBindings(QRhiImplementation *rhi); - QVarLengthArray<QRhiShaderResourceBinding, 16> m_bindings; + QVarLengthArray<QRhiShaderResourceBinding, BINDING_PREALLOC> m_bindings; uint m_layoutDescHash = 0; - QVarLengthArray<uint, 16 * 3> m_layoutDesc; + QVarLengthArray<uint, BINDING_PREALLOC * LAYOUT_DESC_FIELD_COUNT> m_layoutDesc; friend class QRhiImplementation; #ifndef QT_NO_DEBUG_STREAM friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderResourceBindings &); |