diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-09-25 21:18:28 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-09-29 21:24:27 +0200 |
commit | 331c8cd5b40fc6ce4301fdde365c2f7c0b5c6445 (patch) | |
tree | 8f2bf7cc8acb217b6ff14083f1f44fb1e648b232 /src/gui/rhi | |
parent | 04641454beb27f667062dbf79116729f159b0041 (diff) |
rhi: gl: Pre-sort uniform metadata based on offset
Because we will iterate through this list and issue a memcpy
for each entry. Better to keep it sorted based on offset to
be more cache friendly.
Change-Id: Ie9dcb259e9a543937cbdcdea85aec9eb92dba1b1
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/gui/rhi')
-rw-r--r-- | src/gui/rhi/qrhigles2.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index f81ba44358..3405465d54 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -2827,19 +2827,17 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC case QRhiShaderResourceBinding::UniformBuffer: { int viewOffset = b->u.ubuf.offset; - if (dynOfsCount) { - for (int j = 0; j < dynOfsCount; ++j) { - if (dynOfsPairs[2 * j] == uint(b->binding)) { - viewOffset = int(dynOfsPairs[2 * j + 1]); - break; - } + for (int j = 0; j < dynOfsCount; ++j) { + if (dynOfsPairs[2 * j] == uint(b->binding)) { + viewOffset = int(dynOfsPairs[2 * j + 1]); + break; } } QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, b->u.ubuf.buf); const char *bufView = bufD->ubuf + viewOffset; QGles2UniformDescriptionVector &uniforms(maybeGraphicsPs ? QRHI_RES(QGles2GraphicsPipeline, maybeGraphicsPs)->uniforms : QRHI_RES(QGles2ComputePipeline, maybeComputePs)->uniforms); - for (QGles2UniformDescription &uniform : uniforms) { + for (const QGles2UniformDescription &uniform : qAsConst(uniforms)) { if (uniform.binding == b->binding) { // in a uniform buffer everything is at least 4 byte aligned // so this should not cause unaligned reads @@ -4410,6 +4408,12 @@ bool QGles2GraphicsPipeline::create() for (const QShaderDescription::UniformBlock &ub : fsDesc.uniformBlocks()) rhiD->gatherUniforms(program, ub, &activeUniformLocations, &uniforms); + std::sort(uniforms.begin(), uniforms.end(), + [](const QGles2UniformDescription &a, const QGles2UniformDescription &b) + { + return a.offset < b.offset; + }); + for (const QShaderDescription::InOutVariable &v : vsDesc.combinedImageSamplers()) rhiD->gatherSamplers(program, v, &samplers); |