Commit 4d9d4839 by James Darpinian Committed by Commit Bot

Optimize buffer deletion by returning early if buffer is not bound.

This improves angle_perftests bindings_gl_100_objects_allocated_every_iteration by over 30%. Bug: 820723 Change-Id: Icfaa0f54f7c61db6475948e3a95296f37ab4f7dc Reviewed-on: https://chromium-review.googlesource.com/961302Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent aac6df40
......@@ -214,6 +214,11 @@ Error Buffer::getIndexRange(const gl::Context *context,
return NoError();
}
bool Buffer::isBound() const
{
return mState.mBindingCount;
}
bool Buffer::isBoundForTransformFeedbackAndOtherUse() const
{
return mState.mTransformFeedbackBindingCount > 0 &&
......
......@@ -113,6 +113,7 @@ class Buffer final : public RefCountObject, public LabeledObject
rx::BufferImpl *getImplementation() const { return mImpl; }
bool isBound() const;
bool isBoundForTransformFeedbackAndOtherUse() const;
void onBindingChanged(bool bound, BufferBinding target);
......
......@@ -658,14 +658,15 @@ GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *c
return 0u;
}
void Context::deleteBuffer(GLuint buffer)
void Context::deleteBuffer(GLuint bufferName)
{
if (mState.mBuffers->getBuffer(buffer))
Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
if (buffer)
{
detachBuffer(buffer);
}
mState.mBuffers->deleteObject(this, buffer);
mState.mBuffers->deleteObject(this, bufferName);
}
void Context::deleteShader(GLuint shader)
......@@ -2354,7 +2355,7 @@ void Context::detachTexture(GLuint texture)
mGLState.detachTexture(this, mZeroTextures, texture);
}
void Context::detachBuffer(GLuint buffer)
void Context::detachBuffer(Buffer *buffer)
{
// Simple pass-through to State's detachBuffer method, since
// only buffer attachments to container objects that are bound to the current context
......
......@@ -1221,7 +1221,7 @@ class Context final : angle::NonCopyable
VertexArray *checkVertexArrayAllocation(GLuint vertexArrayHandle);
TransformFeedback *checkTransformFeedbackAllocation(GLuint transformFeedback);
void detachBuffer(GLuint buffer);
void detachBuffer(Buffer *buffer);
void detachTexture(GLuint texture);
void detachFramebuffer(GLuint framebuffer);
void detachRenderbuffer(GLuint renderbuffer);
......
......@@ -1427,8 +1427,13 @@ Buffer *State::getTargetBuffer(BufferBinding target) const
}
}
void State::detachBuffer(const Context *context, GLuint bufferName)
void State::detachBuffer(const Context *context, const Buffer *buffer)
{
if (!buffer->isBound())
{
return;
}
GLuint bufferName = buffer->id();
for (auto target : angle::AllEnums<BufferBinding>())
{
if (mBoundBuffers[target].id() == bufferName)
......
......@@ -245,7 +245,7 @@ class State : public angle::ObserverInterface, angle::NonCopyable
const OffsetBindingPointer<Buffer> &getIndexedShaderStorageBuffer(size_t index) const;
// Detach a buffer from all bindings
void detachBuffer(const Context *context, GLuint bufferName);
void detachBuffer(const Context *context, const Buffer *buffer);
// Vertex attrib manipulation
void setEnableVertexAttribArray(unsigned int attribNum, bool enabled);
......
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