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) ...@@ -1107,8 +1107,7 @@ void Context::bindVertexArray(GLuint vertexArrayHandle)
VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle); VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
mGLState.setVertexArrayBinding(this, vertexArray); mGLState.setVertexArrayBinding(this, vertexArray);
mVertexArrayObserverBinding.bind(vertexArray); mVertexArrayObserverBinding.bind(vertexArray);
mStateCache.updateActiveAttribsMask(this); mStateCache.onVertexArrayBindingChange(this);
mStateCache.updateVertexElementLimits(this);
} }
void Context::bindVertexBuffer(GLuint bindingIndex, void Context::bindVertexBuffer(GLuint bindingIndex,
...@@ -1118,7 +1117,7 @@ void Context::bindVertexBuffer(GLuint bindingIndex, ...@@ -1118,7 +1117,7 @@ void Context::bindVertexBuffer(GLuint bindingIndex,
{ {
Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride); mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
mStateCache.updateActiveAttribsMask(this); mStateCache.onVertexArrayStateChange(this);
} }
void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle) void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
...@@ -1144,8 +1143,7 @@ void Context::bindImageTexture(GLuint unit, ...@@ -1144,8 +1143,7 @@ void Context::bindImageTexture(GLuint unit,
void Context::useProgram(GLuint program) void Context::useProgram(GLuint program)
{ {
mGLState.setProgram(this, getProgram(program)); mGLState.setProgram(this, getProgram(program));
mStateCache.updateActiveAttribsMask(this); mStateCache.onProgramExecutableChange(this);
mStateCache.updateVertexElementLimits(this);
} }
void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program) void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
...@@ -2799,8 +2797,7 @@ void Context::detachProgramPipeline(GLuint pipeline) ...@@ -2799,8 +2797,7 @@ void Context::detachProgramPipeline(GLuint pipeline)
void Context::vertexAttribDivisor(GLuint index, GLuint divisor) void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
{ {
mGLState.setVertexAttribDivisor(this, index, divisor); mGLState.setVertexAttribDivisor(this, index, divisor);
mStateCache.updateActiveAttribsMask(this); mStateCache.onVertexArrayStateChange(this);
mStateCache.updateVertexElementLimits(this);
} }
void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param) void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
...@@ -4407,8 +4404,7 @@ void Context::disable(GLenum cap) ...@@ -4407,8 +4404,7 @@ void Context::disable(GLenum cap)
void Context::disableVertexAttribArray(GLuint index) void Context::disableVertexAttribArray(GLuint index)
{ {
mGLState.setEnableVertexAttribArray(index, false); mGLState.setEnableVertexAttribArray(index, false);
mStateCache.updateActiveAttribsMask(this); mStateCache.onVertexArrayStateChange(this);
mStateCache.updateVertexElementLimits(this);
} }
void Context::enable(GLenum cap) void Context::enable(GLenum cap)
...@@ -4419,8 +4415,7 @@ void Context::enable(GLenum cap) ...@@ -4419,8 +4415,7 @@ void Context::enable(GLenum cap)
void Context::enableVertexAttribArray(GLuint index) void Context::enableVertexAttribArray(GLuint index)
{ {
mGLState.setEnableVertexAttribArray(index, true); mGLState.setEnableVertexAttribArray(index, true);
mStateCache.updateActiveAttribsMask(this); mStateCache.onVertexArrayStateChange(this);
mStateCache.updateVertexElementLimits(this);
} }
void Context::frontFace(GLenum mode) void Context::frontFace(GLenum mode)
...@@ -4628,8 +4623,7 @@ void Context::vertexAttribPointer(GLuint index, ...@@ -4628,8 +4623,7 @@ void Context::vertexAttribPointer(GLuint index,
{ {
mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array), mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
size, type, ConvertToBool(normalized), false, stride, ptr); size, type, ConvertToBool(normalized), false, stride, ptr);
mStateCache.updateActiveAttribsMask(this); mStateCache.onVertexArrayStateChange(this);
mStateCache.updateVertexElementLimits(this);
} }
void Context::vertexAttribFormat(GLuint attribIndex, void Context::vertexAttribFormat(GLuint attribIndex,
...@@ -4640,7 +4634,7 @@ void Context::vertexAttribFormat(GLuint attribIndex, ...@@ -4640,7 +4634,7 @@ void Context::vertexAttribFormat(GLuint attribIndex,
{ {
mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false, mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
relativeOffset); relativeOffset);
mStateCache.updateVertexElementLimits(this); mStateCache.onVertexArraySizeChange(this);
} }
void Context::vertexAttribIFormat(GLuint attribIndex, void Context::vertexAttribIFormat(GLuint attribIndex,
...@@ -4649,20 +4643,19 @@ void Context::vertexAttribIFormat(GLuint attribIndex, ...@@ -4649,20 +4643,19 @@ void Context::vertexAttribIFormat(GLuint attribIndex,
GLuint relativeOffset) GLuint relativeOffset)
{ {
mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset); mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
mStateCache.updateVertexElementLimits(this); mStateCache.onVertexArraySizeChange(this);
} }
void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex) void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
{ {
mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex); mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
mStateCache.updateActiveAttribsMask(this); mStateCache.onVertexArrayStateChange(this);
mStateCache.updateVertexElementLimits(this);
} }
void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor) void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
{ {
mGLState.setVertexBindingDivisor(bindingIndex, divisor); mGLState.setVertexBindingDivisor(bindingIndex, divisor);
mStateCache.updateVertexElementLimits(this); mStateCache.onVertexArraySizeChange(this);
} }
void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height) void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
...@@ -4678,8 +4671,7 @@ void Context::vertexAttribIPointer(GLuint index, ...@@ -4678,8 +4671,7 @@ void Context::vertexAttribIPointer(GLuint index,
{ {
mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array), mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
size, type, false, true, stride, pointer); size, type, false, true, stride, pointer);
mStateCache.updateActiveAttribsMask(this); mStateCache.onVertexArrayStateChange(this);
mStateCache.updateVertexElementLimits(this);
} }
void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w) void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
...@@ -5565,8 +5557,7 @@ void Context::linkProgram(GLuint program) ...@@ -5565,8 +5557,7 @@ void Context::linkProgram(GLuint program)
ASSERT(programObject); ASSERT(programObject);
handleError(programObject->link(this)); handleError(programObject->link(this));
mGLState.onProgramExecutableChange(programObject); mGLState.onProgramExecutableChange(programObject);
mStateCache.updateActiveAttribsMask(this); mStateCache.onProgramExecutableChange(this);
mStateCache.updateVertexElementLimits(this);
} }
void Context::releaseShaderCompiler() void Context::releaseShaderCompiler()
...@@ -5774,8 +5765,7 @@ void Context::programBinary(GLuint program, GLenum binaryFormat, const void *bin ...@@ -5774,8 +5765,7 @@ void Context::programBinary(GLuint program, GLenum binaryFormat, const void *bin
ASSERT(programObject != nullptr); ASSERT(programObject != nullptr);
handleError(programObject->loadBinary(this, binaryFormat, binary, length)); handleError(programObject->loadBinary(this, binaryFormat, binary, length));
mStateCache.updateActiveAttribsMask(this); mStateCache.onProgramExecutableChange(this);
mStateCache.updateVertexElementLimits(this);
} }
void Context::uniform1ui(GLint location, GLuint v0) void Context::uniform1ui(GLint location, GLuint v0)
...@@ -7580,7 +7570,7 @@ void Context::onSubjectStateChange(const Context *context, ...@@ -7580,7 +7570,7 @@ void Context::onSubjectStateChange(const Context *context,
{ {
case kVertexArraySubjectIndex: case kVertexArraySubjectIndex:
mGLState.setObjectDirty(GL_VERTEX_ARRAY); mGLState.setObjectDirty(GL_VERTEX_ARRAY);
mStateCache.updateVertexElementLimits(this); mStateCache.onVertexArraySizeChange(this);
break; break;
case kReadFramebufferSubjectIndex: case kReadFramebufferSubjectIndex:
...@@ -7719,4 +7709,32 @@ void StateCache::updateVertexElementLimits(Context *context) ...@@ -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 } // namespace gl
...@@ -89,31 +89,37 @@ class StateCache final : angle::NonCopyable ...@@ -89,31 +89,37 @@ class StateCache final : angle::NonCopyable
~StateCache(); ~StateCache();
// Places that can trigger updateActiveAttribsMask: // Places that can trigger updateActiveAttribsMask:
// 1. GLES1: clientActiveTexture. // 1. onVertexArrayBindingChange.
// 2. GLES1: disableClientState/enableClientState. // 2. onProgramExecutableChange.
// 3. Context: linkProgram/useProgram/programBinary. Note: should check programBinary bits. // 3. onVertexArrayStateChange.
// 4. Context: bindVertexArray. // 4. onGLES1ClientStateChange.
// 5. Vertex Array: most any state change.
AttributesMask getActiveBufferedAttribsMask() const { return mCachedActiveBufferedAttribsMask; } AttributesMask getActiveBufferedAttribsMask() const { return mCachedActiveBufferedAttribsMask; }
AttributesMask getActiveClientAttribsMask() const { return mCachedActiveClientAttribsMask; } AttributesMask getActiveClientAttribsMask() const { return mCachedActiveClientAttribsMask; }
bool hasAnyEnabledClientAttrib() const { return mCachedHasAnyEnabledClientAttrib; } bool hasAnyEnabledClientAttrib() const { return mCachedHasAnyEnabledClientAttrib; }
// Places that can trigger updateVertexElementLimits: // Places that can trigger updateVertexElementLimits:
// 1. Context: bindVertexArray. // 1. onVertexArrayBindingChange.
// 2. Context: any executable change (linkProgram/useProgram/programBinary). // 2. onProgramExecutableChange.
// 3. Vertex Array: any state change call. // 3. onVertexArraySizeChange.
// 4. Buffer: a dependent buffer resize. // 4. onVertexArrayStateChange.
GLint64 getNonInstancedVertexElementLimit() const GLint64 getNonInstancedVertexElementLimit() const
{ {
return mCachedNonInstancedVertexElementLimit; return mCachedNonInstancedVertexElementLimit;
} }
GLint64 getInstancedVertexElementLimit() const { return mCachedInstancedVertexElementLimit; } 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. // Cache update functions.
void updateActiveAttribsMask(Context *context); void updateActiveAttribsMask(Context *context);
void updateVertexElementLimits(Context *context); void updateVertexElementLimits(Context *context);
private:
AttributesMask mCachedActiveBufferedAttribsMask; AttributesMask mCachedActiveBufferedAttribsMask;
AttributesMask mCachedActiveClientAttribsMask; AttributesMask mCachedActiveClientAttribsMask;
bool mCachedHasAnyEnabledClientAttrib; bool mCachedHasAnyEnabledClientAttrib;
......
...@@ -59,7 +59,7 @@ void Context::clearDepthx(GLfixed depth) ...@@ -59,7 +59,7 @@ void Context::clearDepthx(GLfixed depth)
void Context::clientActiveTexture(GLenum texture) void Context::clientActiveTexture(GLenum texture)
{ {
mGLState.gles1().setClientTextureUnit(texture - GL_TEXTURE0); mGLState.gles1().setClientTextureUnit(texture - GL_TEXTURE0);
mStateCache.updateActiveAttribsMask(this); mStateCache.onGLES1ClientStateChange(this);
} }
void Context::clipPlanef(GLenum p, const GLfloat *eqn) void Context::clipPlanef(GLenum p, const GLfloat *eqn)
...@@ -110,14 +110,14 @@ void Context::disableClientState(ClientVertexArrayType clientState) ...@@ -110,14 +110,14 @@ void Context::disableClientState(ClientVertexArrayType clientState)
{ {
mGLState.gles1().setClientStateEnabled(clientState, false); mGLState.gles1().setClientStateEnabled(clientState, false);
disableVertexAttribArray(vertexArrayIndex(clientState)); disableVertexAttribArray(vertexArrayIndex(clientState));
mStateCache.updateActiveAttribsMask(this); mStateCache.onGLES1ClientStateChange(this);
} }
void Context::enableClientState(ClientVertexArrayType clientState) void Context::enableClientState(ClientVertexArrayType clientState)
{ {
mGLState.gles1().setClientStateEnabled(clientState, true); mGLState.gles1().setClientStateEnabled(clientState, true);
enableVertexAttribArray(vertexArrayIndex(clientState)); enableVertexAttribArray(vertexArrayIndex(clientState));
mStateCache.updateActiveAttribsMask(this); mStateCache.onGLES1ClientStateChange(this);
} }
void Context::fogf(GLenum pname, GLfloat param) 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