Optimize Texture binding by only applying referenced textures.
Update ProgramGL to track which the current values of sampler uniforms so
that only the currently applied texture units have to be bound for the
draw call.
BUG=angleproject:882
Change-Id: I280aa106172b13a5fbb31cdefba27b6691c0a0e4
Reviewed-on: https://chromium-review.googlesource.com/264803
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/renderer/gl/ProgramGL.cpp b/src/libANGLE/renderer/gl/ProgramGL.cpp
index 63c224d..014759a 100644
--- a/src/libANGLE/renderer/gl/ProgramGL.cpp
+++ b/src/libANGLE/renderer/gl/ProgramGL.cpp
@@ -154,6 +154,15 @@
}
mUniformIndex[location] = gl::VariableLocation(uniformName, arrayIndex, static_cast<unsigned int>(mUniforms.size()));
+
+ // If the uniform is a sampler, track it in the sampler bindings array
+ if (gl::IsSamplerType(uniformType))
+ {
+ SamplerLocation samplerLoc;
+ samplerLoc.samplerIndex = mSamplerBindings.size();
+ samplerLoc.arrayIndex = arrayIndex;
+ mSamplerUniformMap[location] = samplerLoc;
+ }
}
}
@@ -162,6 +171,15 @@
// TODO: determine uniform precision
mUniforms.push_back(new gl::LinkedUniform(uniformType, GL_NONE, uniformName, arraySize, -1, sh::BlockMemberInfo::getDefaultBlockInfo()));
+
+ // If uniform is a sampler type, insert it into the mSamplerBindings array
+ if (gl::IsSamplerType(uniformType))
+ {
+ SamplerBindingGL samplerBinding;
+ samplerBinding.textureType = gl::SamplerTypeToTextureType(uniformType);
+ samplerBinding.boundTextureUnits.resize(uniformSize, 0);
+ mSamplerBindings.push_back(samplerBinding);
+ }
}
// Query the attribute information
@@ -223,6 +241,16 @@
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform1iv(location, count, v);
+
+ auto iter = mSamplerUniformMap.find(location);
+ if (iter != mSamplerUniformMap.end())
+ {
+ const SamplerLocation &samplerLoc = iter->second;
+ std::vector<GLuint> &boundTextureUnits = mSamplerBindings[samplerLoc.samplerIndex].boundTextureUnits;
+
+ size_t copyCount = std::max<size_t>(count, boundTextureUnits.size() - samplerLoc.arrayIndex);
+ std::copy(v, v + copyCount, boundTextureUnits.begin() + samplerLoc.arrayIndex);
+ }
}
void ProgramGL::setUniform2iv(GLint location, GLsizei count, const GLint *v)
@@ -408,6 +436,9 @@
void ProgramGL::reset()
{
ProgramImpl::reset();
+
+ mSamplerUniformMap.clear();
+ mSamplerBindings.clear();
}
GLuint ProgramGL::getProgramID() const
@@ -415,4 +446,9 @@
return mProgramID;
}
+const std::vector<SamplerBindingGL> &ProgramGL::getAppliedSamplerUniforms() const
+{
+ return mSamplerBindings;
+}
+
}