summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qrhi.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2020-09-17 15:20:58 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2020-09-17 18:30:12 +0200
commitdfa303c9af3ed6af76a2cb588cd2f9c563ca1886 (patch)
tree6072f4c84c60a141d02547d44db6a8f2b74d77b4 /src/gui/rhi/qrhi.cpp
parentd0a929301aa751c610f404ad22407b32c3a85d7b (diff)
rhi: Improve srb hash perf somewhat
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 <christian.stromme@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhi.cpp')
-rw-r--r--src/gui/rhi/qrhi.cpp31
1 files 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<quintptr>(d->u.ubuf.buf));
+ break;
+ case QRhiShaderResourceBinding::SampledTexture:
+ h ^= qHash(reinterpret_cast<quintptr>(d->u.stex.texSamplers[0].tex));
+ h ^= qHash(reinterpret_cast<quintptr>(d->u.stex.texSamplers[0].sampler));
+ break;
+ case QRhiShaderResourceBinding::ImageLoad:
+ Q_FALLTHROUGH();
+ case QRhiShaderResourceBinding::ImageStore:
+ Q_FALLTHROUGH();
+ case QRhiShaderResourceBinding::ImageLoadStore:
+ h ^= qHash(reinterpret_cast<quintptr>(d->u.simage.tex));
+ break;
+ case QRhiShaderResourceBinding::BufferLoad:
+ Q_FALLTHROUGH();
+ case QRhiShaderResourceBinding::BufferStore:
+ Q_FALLTHROUGH();
+ case QRhiShaderResourceBinding::BufferLoadStore:
+ h ^= qHash(reinterpret_cast<quintptr>(d->u.sbuf.buf));
+ break;
+ default:
+ break;
+ }
+ return h;
}
#ifndef QT_NO_DEBUG_STREAM