Micro-optimize uniform updates.
This CL is adapted from work by matavenrath@nvidia.com. It does the
following small optimizations:
* inlines a bunch of accessors.
* reorders checks to hit the cache more often
Also some small style updates.
Bug: angleproject:1671
Change-Id: I8f21318e6644dcfe1f99c98f7f377742fcad78d3
Reviewed-on: https://chromium-review.googlesource.com/1054367
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/libANGLE/Program.cpp b/src/libANGLE/Program.cpp
index 318bae2..de06eb3 100644
--- a/src/libANGLE/Program.cpp
+++ b/src/libANGLE/Program.cpp
@@ -1318,11 +1318,6 @@
mInfoLog.reset();
}
-bool Program::isLinked() const
-{
- return mLinked;
-}
-
bool Program::hasLinkedShaderStage(ShaderType shaderType) const
{
ASSERT(shaderType != ShaderType::InvalidEnum);
@@ -1759,17 +1754,6 @@
return mState.mUniformLocations[location];
}
-const std::vector<VariableLocation> &Program::getUniformLocations() const
-{
- return mState.mUniformLocations;
-}
-
-const LinkedUniform &Program::getUniformByIndex(GLuint index) const
-{
- ASSERT(index < static_cast<size_t>(mState.mUniforms.size()));
- return mState.mUniforms[index];
-}
-
const BufferVariable &Program::getBufferVariableByIndex(GLuint index) const
{
ASSERT(index < static_cast<size_t>(mState.mBufferVariables.size()));
diff --git a/src/libANGLE/Program.h b/src/libANGLE/Program.h
index fe1d62d..092e24f 100644
--- a/src/libANGLE/Program.h
+++ b/src/libANGLE/Program.h
@@ -404,10 +404,10 @@
RangeUI mAtomicCounterUniformRange;
// An array of the samplers that are used by the program
- std::vector<gl::SamplerBinding> mSamplerBindings;
+ std::vector<SamplerBinding> mSamplerBindings;
// An array of the images that are used by the program
- std::vector<gl::ImageBinding> mImageBindings;
+ std::vector<ImageBinding> mImageBindings;
// Names and mapped names of output variables that are arrays include [0] in the end, similarly
// to uniforms.
@@ -494,8 +494,8 @@
GLint components,
const GLfloat *coeffs);
- Error link(const gl::Context *context);
- bool isLinked() const;
+ Error link(const Context *context);
+ bool isLinked() const { return mLinked; }
bool hasLinkedShaderStage(ShaderType shaderType) const;
@@ -552,8 +552,16 @@
bool isValidUniformLocation(GLint location) const;
const LinkedUniform &getUniformByLocation(GLint location) const;
const VariableLocation &getUniformLocation(GLint location) const;
- const std::vector<VariableLocation> &getUniformLocations() const;
- const LinkedUniform &getUniformByIndex(GLuint index) const;
+ const std::vector<VariableLocation> &getUniformLocations() const
+ {
+ return mState.mUniformLocations;
+ }
+
+ const LinkedUniform &getUniformByIndex(GLuint index) const
+ {
+ ASSERT(index < static_cast<size_t>(mState.mUniforms.size()));
+ return mState.mUniforms[index];
+ }
const BufferVariable &getBufferVariableByIndex(GLuint index) const;
@@ -632,7 +640,7 @@
void validate(const Caps &caps);
bool validateSamplers(InfoLog *infoLog, const Caps &caps);
bool isValidated() const;
- bool samplesFromTexture(const gl::State &state, GLuint textureID) const;
+ bool samplesFromTexture(const State &state, GLuint textureID) const;
const AttributesMask &getActiveAttribLocationsMask() const
{
@@ -735,7 +743,7 @@
bool linkValidateFragmentInputBindings(const Context *context, InfoLog &infoLog) const;
bool linkValidateBuiltInVaryings(const Context *context, InfoLog &infoLog) const;
- bool linkValidateTransformFeedback(const gl::Context *context,
+ bool linkValidateTransformFeedback(const Context *context,
InfoLog &infoLog,
const ProgramMergedVaryings &linkedVaryings,
const Caps &caps) const;
diff --git a/src/libANGLE/VertexAttribute.cpp b/src/libANGLE/VertexAttribute.cpp
index 35ab30f..f837ef7 100644
--- a/src/libANGLE/VertexAttribute.cpp
+++ b/src/libANGLE/VertexAttribute.cpp
@@ -49,7 +49,7 @@
mBuffer->onBindingChanged(context, true, BufferBinding::Array);
}
-void VertexBinding::onContainerBindingChanged(const Context *context, bool bound)
+void VertexBinding::onContainerBindingChanged(const Context *context, bool bound) const
{
if (mBuffer.get())
mBuffer->onBindingChanged(context, bound, BufferBinding::Array);
@@ -71,11 +71,6 @@
}
}
-GLuint64 VertexBinding::getCachedBufferSizeMinusOffset() const
-{
- return mCachedBufferSizeMinusOffset;
-}
-
VertexAttribute::VertexAttribute(GLuint bindingIndex)
: enabled(false),
type(GL_FLOAT),
diff --git a/src/libANGLE/VertexAttribute.h b/src/libANGLE/VertexAttribute.h
index 6b3af37..0b17bc9 100644
--- a/src/libANGLE/VertexAttribute.h
+++ b/src/libANGLE/VertexAttribute.h
@@ -39,11 +39,15 @@
const BindingPointer<Buffer> &getBuffer() const { return mBuffer; }
void setBuffer(const gl::Context *context, Buffer *bufferIn, bool containerIsBound);
- void onContainerBindingChanged(const Context *context, bool bound);
+ void onContainerBindingChanged(const Context *context, bool bound) const;
+
+ GLuint64 getCachedBufferSizeMinusOffset() const
+ {
+ return mCachedBufferSizeMinusOffset;
+ }
// Called from VertexArray.
void updateCachedBufferSizeMinusOffset();
- GLuint64 getCachedBufferSizeMinusOffset() const;
private:
GLuint mStride;
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index 56d6e76..cbf4ef2 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -2096,7 +2096,7 @@
const auto &uniform = program->getUniformByIndex(uniformLocation.index);
// attempting to write an array to a non-array uniform is an INVALID_OPERATION
- if (!uniform.isArray() && count > 1)
+ if (count > 1 && !uniform.isArray())
{
context->handleError(InvalidOperation());
return false;