Commit c43cdad2 by Jamie Madill Committed by Commit Bot

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: 's avatarGeoff Lang <geofflang@chromium.org>
parent 03cb5266
......@@ -1107,8 +1107,7 @@ void Context::bindVertexArray(GLuint vertexArrayHandle)
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 @@ void Context::bindVertexBuffer(GLuint bindingIndex,
{
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::bindImageTexture(GLuint unit,
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::detachProgramPipeline(GLuint pipeline)
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::disable(GLenum cap)
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::enable(GLenum cap)
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 @@ void Context::vertexAttribPointer(GLuint index,
{
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 @@ void Context::vertexAttribFormat(GLuint attribIndex,
{
mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
relativeOffset);
mStateCache.updateVertexElementLimits(this);
mStateCache.onVertexArraySizeChange(this);
}
void Context::vertexAttribIFormat(GLuint attribIndex,
......@@ -4649,20 +4643,19 @@ void Context::vertexAttribIFormat(GLuint attribIndex,
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 @@ void Context::vertexAttribIPointer(GLuint index,
{
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 @@ void Context::linkProgram(GLuint program)
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 @@ void Context::programBinary(GLuint program, GLenum binaryFormat, const void *bin
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 @@ void Context::onSubjectStateChange(const Context *context,
{
case kVertexArraySubjectIndex:
mGLState.setObjectDirty(GL_VERTEX_ARRAY);
mStateCache.updateVertexElementLimits(this);
mStateCache.onVertexArraySizeChange(this);
break;
case kReadFramebufferSubjectIndex:
......@@ -7719,4 +7709,32 @@ void StateCache::updateVertexElementLimits(Context *context)
}
}
}
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
......@@ -89,31 +89,37 @@ class StateCache final : angle::NonCopyable
~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;
......
......@@ -59,7 +59,7 @@ void Context::clearDepthx(GLfixed depth)
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 @@ void Context::disableClientState(ClientVertexArrayType clientState)
{
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment