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>
This commit is contained in:
Laszlo Agocs 2020-09-25 21:18:28 +02:00
parent 04641454be
commit 331c8cd5b4

View File

@ -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);