From 331c8cd5b40fc6ce4301fdde365c2f7c0b5c6445 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 25 Sep 2020 21:18:28 +0200 Subject: 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 --- src/gui/rhi/qrhigles2.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/gui/rhi') 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); -- cgit v1.2.3