summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorJean-Michaƫl Celerier <jean-michael.celerier@kdab.com>2020-04-24 15:41:56 +0200
committerPaul Lemire <paul.lemire@kdab.com>2020-05-27 15:31:41 +0200
commit9d9305184ea0b19809baac844ae32bf9323d19d2 (patch)
tree61df2db25347adaf21c10c59b478807440ebf6e7 /src/plugins
parentd52cba5b86cdfc5077a0ee1cc7cf868cb4d6cd87 (diff)
Reduce uniform copies
Change-Id: I322e97d9d0da185a98ced5e782a801b3474a892a Reviewed-by: Mike Krus <mike.krus@kdab.com> (cherry picked from commit 897b6cd5de7042edcdaf610f80d97d2b422c73c2)
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp19
-rw-r--r--src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h21
2 files changed, 29 insertions, 11 deletions
diff --git a/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp
index 95f4758ba..34f31f23f 100644
--- a/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp
+++ b/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp
@@ -1270,21 +1270,20 @@ bool SubmissionContext::setParameters(ShaderParameterPack &parameterPack, GLShad
}
// Update uniforms in the Default Uniform Block
- const PackUniformHash values = parameterPack.uniforms();
- const QVector<int> &activeUniformsIndices = parameterPack.submissionUniformIndices();
+ const PackUniformHash& values = parameterPack.uniforms();
+ const auto &activeUniformsIndices = parameterPack.submissionUniformIndices();
const QVector<ShaderUniform> &shaderUniforms = shader->uniforms();
for (const int shaderUniformIndex : activeUniformsIndices) {
const ShaderUniform &uniform = shaderUniforms[shaderUniformIndex];
- const UniformValue &v = values.value(uniform.m_nameId);
+ values.apply(uniform.m_nameId, [&] (const UniformValue& v) {
+ // skip invalid textures/images
+ if (!((v.valueType() == UniformValue::TextureValue ||
+ v.valueType() == UniformValue::ShaderImageValue) &&
+ *v.constData<int>() == -1))
+ applyUniform(uniform, v);
+ });
- // skip invalid textures/images
- if ((v.valueType() == UniformValue::TextureValue ||
- v.valueType() == UniformValue::ShaderImageValue) &&
- *v.constData<int>() == -1)
- continue;
-
- applyUniform(uniform, v);
}
// if not all data is valid, the next frame will be rendered immediately
return true;
diff --git a/src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h b/src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h
index 2ed80ef2a..78cb8515f 100644
--- a/src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h
+++ b/src/plugins/renderers/opengl/renderer/shaderparameterpack_p.h
@@ -116,6 +116,17 @@ struct PackUniformHash
}
}
+ void insert(int key, UniformValue &&value)
+ {
+ const int idx = keys.indexOf(key);
+ if (idx != -1) {
+ values[idx] = std::move(value);
+ } else {
+ keys.push_back(key);
+ values.push_back(std::move(value));
+ }
+ }
+
UniformValue value(int key) const
{
const int idx = keys.indexOf(key);
@@ -133,13 +144,21 @@ struct PackUniformHash
return value(key);
}
+ template<typename F>
+ void apply(int key, F func) const noexcept
+ {
+ const int idx = keys.indexOf(key);
+ if (idx != -1)
+ func(values[idx]);
+ }
+
void erase(int idx)
{
keys.removeAt(idx);
values.removeAt(idx);
}
- bool contains(int key) const
+ bool contains(int key) const noexcept
{
return keys.contains(key);
}