StateCache: Make external API easier to understand.
Instead of updating the cache directly we use event notifier functions.
For example instead of calling updateActiveAttribsMask in
Context::linkProgram we call onProgramExecutableChange. This makes the
code more self-documenting and easier to maintain.
Bug: angleproject:2747
Change-Id: Id27b58f646f6924db4c16e28609d6baf6b51c78e
Reviewed-on: https://chromium-review.googlesource.com/1164066
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp
index d24178d..2ef5c2a 100644
--- a/src/libANGLE/Context.cpp
+++ b/src/libANGLE/Context.cpp
@@ -1107,8 +1107,7 @@
VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
mGLState.setVertexArrayBinding(this, vertexArray);
mVertexArrayObserverBinding.bind(vertexArray);
- mStateCache.updateActiveAttribsMask(this);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onVertexArrayBindingChange(this);
}
void Context::bindVertexBuffer(GLuint bindingIndex,
@@ -1118,7 +1117,7 @@
{
Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
- mStateCache.updateActiveAttribsMask(this);
+ mStateCache.onVertexArrayStateChange(this);
}
void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
@@ -1144,8 +1143,7 @@
void Context::useProgram(GLuint program)
{
mGLState.setProgram(this, getProgram(program));
- mStateCache.updateActiveAttribsMask(this);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onProgramExecutableChange(this);
}
void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
@@ -2799,8 +2797,7 @@
void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
{
mGLState.setVertexAttribDivisor(this, index, divisor);
- mStateCache.updateActiveAttribsMask(this);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onVertexArrayStateChange(this);
}
void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
@@ -4407,8 +4404,7 @@
void Context::disableVertexAttribArray(GLuint index)
{
mGLState.setEnableVertexAttribArray(index, false);
- mStateCache.updateActiveAttribsMask(this);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onVertexArrayStateChange(this);
}
void Context::enable(GLenum cap)
@@ -4419,8 +4415,7 @@
void Context::enableVertexAttribArray(GLuint index)
{
mGLState.setEnableVertexAttribArray(index, true);
- mStateCache.updateActiveAttribsMask(this);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onVertexArrayStateChange(this);
}
void Context::frontFace(GLenum mode)
@@ -4628,8 +4623,7 @@
{
mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
size, type, ConvertToBool(normalized), false, stride, ptr);
- mStateCache.updateActiveAttribsMask(this);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onVertexArrayStateChange(this);
}
void Context::vertexAttribFormat(GLuint attribIndex,
@@ -4640,7 +4634,7 @@
{
mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
relativeOffset);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onVertexArraySizeChange(this);
}
void Context::vertexAttribIFormat(GLuint attribIndex,
@@ -4649,20 +4643,19 @@
GLuint relativeOffset)
{
mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onVertexArraySizeChange(this);
}
void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
{
mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
- mStateCache.updateActiveAttribsMask(this);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onVertexArrayStateChange(this);
}
void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
{
mGLState.setVertexBindingDivisor(bindingIndex, divisor);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onVertexArraySizeChange(this);
}
void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
@@ -4678,8 +4671,7 @@
{
mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
size, type, false, true, stride, pointer);
- mStateCache.updateActiveAttribsMask(this);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onVertexArrayStateChange(this);
}
void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
@@ -5565,8 +5557,7 @@
ASSERT(programObject);
handleError(programObject->link(this));
mGLState.onProgramExecutableChange(programObject);
- mStateCache.updateActiveAttribsMask(this);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onProgramExecutableChange(this);
}
void Context::releaseShaderCompiler()
@@ -5774,8 +5765,7 @@
ASSERT(programObject != nullptr);
handleError(programObject->loadBinary(this, binaryFormat, binary, length));
- mStateCache.updateActiveAttribsMask(this);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onProgramExecutableChange(this);
}
void Context::uniform1ui(GLint location, GLuint v0)
@@ -7580,7 +7570,7 @@
{
case kVertexArraySubjectIndex:
mGLState.setObjectDirty(GL_VERTEX_ARRAY);
- mStateCache.updateVertexElementLimits(this);
+ mStateCache.onVertexArraySizeChange(this);
break;
case kReadFramebufferSubjectIndex:
@@ -7719,4 +7709,32 @@
}
}
}
+
+void StateCache::onVertexArrayBindingChange(Context *context)
+{
+ updateActiveAttribsMask(context);
+ updateVertexElementLimits(context);
+}
+
+void StateCache::onProgramExecutableChange(Context *context)
+{
+ updateActiveAttribsMask(context);
+ updateVertexElementLimits(context);
+}
+
+void StateCache::onVertexArraySizeChange(Context *context)
+{
+ updateVertexElementLimits(context);
+}
+
+void StateCache::onVertexArrayStateChange(Context *context)
+{
+ updateActiveAttribsMask(context);
+ updateVertexElementLimits(context);
+}
+
+void StateCache::onGLES1ClientStateChange(Context *context)
+{
+ updateActiveAttribsMask(context);
+}
} // namespace gl
diff --git a/src/libANGLE/Context.h b/src/libANGLE/Context.h
index 0db5870..82bcc17 100644
--- a/src/libANGLE/Context.h
+++ b/src/libANGLE/Context.h
@@ -89,31 +89,37 @@
~StateCache();
// Places that can trigger updateActiveAttribsMask:
- // 1. GLES1: clientActiveTexture.
- // 2. GLES1: disableClientState/enableClientState.
- // 3. Context: linkProgram/useProgram/programBinary. Note: should check programBinary bits.
- // 4. Context: bindVertexArray.
- // 5. Vertex Array: most any state change.
+ // 1. onVertexArrayBindingChange.
+ // 2. onProgramExecutableChange.
+ // 3. onVertexArrayStateChange.
+ // 4. onGLES1ClientStateChange.
AttributesMask getActiveBufferedAttribsMask() const { return mCachedActiveBufferedAttribsMask; }
AttributesMask getActiveClientAttribsMask() const { return mCachedActiveClientAttribsMask; }
bool hasAnyEnabledClientAttrib() const { return mCachedHasAnyEnabledClientAttrib; }
// Places that can trigger updateVertexElementLimits:
- // 1. Context: bindVertexArray.
- // 2. Context: any executable change (linkProgram/useProgram/programBinary).
- // 3. Vertex Array: any state change call.
- // 4. Buffer: a dependent buffer resize.
+ // 1. onVertexArrayBindingChange.
+ // 2. onProgramExecutableChange.
+ // 3. onVertexArraySizeChange.
+ // 4. onVertexArrayStateChange.
GLint64 getNonInstancedVertexElementLimit() const
{
return mCachedNonInstancedVertexElementLimit;
}
GLint64 getInstancedVertexElementLimit() const { return mCachedInstancedVertexElementLimit; }
+ // State change notifications.
+ void onVertexArrayBindingChange(Context *context);
+ void onProgramExecutableChange(Context *context);
+ void onVertexArraySizeChange(Context *context);
+ void onVertexArrayStateChange(Context *context);
+ void onGLES1ClientStateChange(Context *context);
+
+ private:
// Cache update functions.
void updateActiveAttribsMask(Context *context);
void updateVertexElementLimits(Context *context);
- private:
AttributesMask mCachedActiveBufferedAttribsMask;
AttributesMask mCachedActiveClientAttribsMask;
bool mCachedHasAnyEnabledClientAttrib;
diff --git a/src/libANGLE/Context_gles_1_0.cpp b/src/libANGLE/Context_gles_1_0.cpp
index 8b8b984..d49606f 100644
--- a/src/libANGLE/Context_gles_1_0.cpp
+++ b/src/libANGLE/Context_gles_1_0.cpp
@@ -59,7 +59,7 @@
void Context::clientActiveTexture(GLenum texture)
{
mGLState.gles1().setClientTextureUnit(texture - GL_TEXTURE0);
- mStateCache.updateActiveAttribsMask(this);
+ mStateCache.onGLES1ClientStateChange(this);
}
void Context::clipPlanef(GLenum p, const GLfloat *eqn)
@@ -110,14 +110,14 @@
{
mGLState.gles1().setClientStateEnabled(clientState, false);
disableVertexAttribArray(vertexArrayIndex(clientState));
- mStateCache.updateActiveAttribsMask(this);
+ mStateCache.onGLES1ClientStateChange(this);
}
void Context::enableClientState(ClientVertexArrayType clientState)
{
mGLState.gles1().setClientStateEnabled(clientState, true);
enableVertexAttribArray(vertexArrayIndex(clientState));
- mStateCache.updateActiveAttribsMask(this);
+ mStateCache.onGLES1ClientStateChange(this);
}
void Context::fogf(GLenum pname, GLfloat param)