Improve speed of iterating dirty textures.
We had a performance regression in the Textures benchmark. What the
test was doing was iterating over all possible texture state,
ensuring the active texture was dirty every frame. This is an attempt
to improve on the speed by not doing as much resetting work in
State::syncProgramTextures. It introduces an active textures mask to
speed iteration over the active texture set.
Also makes a refactoring change to Context to make it easier to limit
caps to an implementation maxium. The number of active textures is
limited to 64 so they easily fit in the bitset mask, with a limit of
32 per shader stage. No mask is currenly kept for compute shaders.
With the fix the performance should be about the same as before (which
is good, as the test always sets the textures dirty).
Test: TexturesBenchmark.Run/gl_8_textures_5_rebind_3_state_8_mips
BUG=chromium:765363
BUG=angleproject:1387
Change-Id: I8bcf95be3671195373573f89f406edaba40aa1be
Reviewed-on: https://chromium-review.googlesource.com/670279
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Frank Henigman <fjhenigman@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp
index a0955d2..74ff875 100644
--- a/src/libANGLE/Context.cpp
+++ b/src/libANGLE/Context.cpp
@@ -240,6 +240,12 @@
}
}
+template <typename CapT, typename MaxT>
+void LimitCap(CapT *cap, MaxT maximum)
+{
+ *cap = std::min(*cap, static_cast<CapT>(maximum));
+}
+
} // anonymous namespace
namespace gl
@@ -2672,19 +2678,25 @@
mExtensions.programCacheControl = true;
// Apply implementation limits
- mCaps.maxVertexAttributes = std::min<GLuint>(mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
- mCaps.maxVertexAttribBindings =
- getClientVersion() < ES_3_1
- ? mCaps.maxVertexAttributes
- : std::min<GLuint>(mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
+ LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
- mCaps.maxVertexUniformBlocks = std::min<GLuint>(
- mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
- mCaps.maxVertexOutputComponents =
- std::min<GLuint>(mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
+ if (getClientVersion() < ES_3_1)
+ {
+ mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
+ }
+ else
+ {
+ LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
+ }
- mCaps.maxFragmentInputComponents =
- std::min<GLuint>(mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
+ LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
+ LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
+ LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
+
+ // Limit textures as well, so we can use fast bitsets with texture bindings.
+ LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
+ LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
+ LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
// WebGL compatibility
mExtensions.webglCompatibility = mWebGLContext;