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/961302
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/Buffer.cpp b/src/libANGLE/Buffer.cpp
index 410f60d..92bf542 100644
--- a/src/libANGLE/Buffer.cpp
+++ b/src/libANGLE/Buffer.cpp
@@ -214,6 +214,11 @@
return NoError();
}
+bool Buffer::isBound() const
+{
+ return mState.mBindingCount;
+}
+
bool Buffer::isBoundForTransformFeedbackAndOtherUse() const
{
return mState.mTransformFeedbackBindingCount > 0 &&
diff --git a/src/libANGLE/Buffer.h b/src/libANGLE/Buffer.h
index 068f7da..9ad5938 100644
--- a/src/libANGLE/Buffer.h
+++ b/src/libANGLE/Buffer.h
@@ -113,6 +113,7 @@
rx::BufferImpl *getImplementation() const { return mImpl; }
+ bool isBound() const;
bool isBoundForTransformFeedbackAndOtherUse() const;
void onBindingChanged(bool bound, BufferBinding target);
diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp
index ad3dad0..01e58f6 100644
--- a/src/libANGLE/Context.cpp
+++ b/src/libANGLE/Context.cpp
@@ -658,14 +658,15 @@
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 @@
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
diff --git a/src/libANGLE/Context.h b/src/libANGLE/Context.h
index cff1fb2..6a0ff2e 100644
--- a/src/libANGLE/Context.h
+++ b/src/libANGLE/Context.h
@@ -1221,7 +1221,7 @@
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);
diff --git a/src/libANGLE/State.cpp b/src/libANGLE/State.cpp
index e7b81a3..7d509b0 100644
--- a/src/libANGLE/State.cpp
+++ b/src/libANGLE/State.cpp
@@ -1427,8 +1427,13 @@
}
}
-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)
diff --git a/src/libANGLE/State.h b/src/libANGLE/State.h
index 97a0162..2176a65 100644
--- a/src/libANGLE/State.h
+++ b/src/libANGLE/State.h
@@ -245,7 +245,7 @@
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);