From dfa303c9af3ed6af76a2cb588cd2f9c563ca1886 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 17 Sep 2020 15:20:58 +0200 Subject: [PATCH] rhi: Improve srb hash perf somewhat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not qHashBits on the whole data that is at least 260 bytes, a big part of it often unused. Just hash binding/stage/type and the first resource pointer. Change-Id: If9b3dc9acf36edf225302b1216d91e87b652b8ef Reviewed-by: Christian Strømme --- src/gui/rhi/qrhi.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index b052a2f140..aff3494284 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -2829,8 +2829,6 @@ bool QRhiShaderResourceBindings::isLayoutCompatible(const QRhiShaderResourceBind */ QRhiShaderResourceBinding::QRhiShaderResourceBinding() { - // Zero out everything, including possible padding, because will use - // qHashBits on it. memset(&d.u, 0, sizeof(d.u)); } @@ -3330,8 +3328,33 @@ bool operator!=(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBind size_t qHash(const QRhiShaderResourceBinding &b, size_t seed) noexcept { const QRhiShaderResourceBinding::Data *d = b.data(); - return seed + uint(d->binding) + 10 * uint(d->stage) + 100 * uint(d->type) - + qHashBits(&d->u, sizeof(d->u), seed); + size_t h = uint(d->binding) ^ uint(d->stage) ^ uint(d->type) ^ seed; + switch (d->type) { + case QRhiShaderResourceBinding::UniformBuffer: + h ^= qHash(reinterpret_cast(d->u.ubuf.buf)); + break; + case QRhiShaderResourceBinding::SampledTexture: + h ^= qHash(reinterpret_cast(d->u.stex.texSamplers[0].tex)); + h ^= qHash(reinterpret_cast(d->u.stex.texSamplers[0].sampler)); + break; + case QRhiShaderResourceBinding::ImageLoad: + Q_FALLTHROUGH(); + case QRhiShaderResourceBinding::ImageStore: + Q_FALLTHROUGH(); + case QRhiShaderResourceBinding::ImageLoadStore: + h ^= qHash(reinterpret_cast(d->u.simage.tex)); + break; + case QRhiShaderResourceBinding::BufferLoad: + Q_FALLTHROUGH(); + case QRhiShaderResourceBinding::BufferStore: + Q_FALLTHROUGH(); + case QRhiShaderResourceBinding::BufferLoadStore: + h ^= qHash(reinterpret_cast(d->u.sbuf.buf)); + break; + default: + break; + } + return h; } #ifndef QT_NO_DEBUG_STREAM