Commit aebf9dde by Jamie Madill

Cache maximum enabled vertex attribute.

This can give us much faster draw call validation, by saving us from checking buffer sizes for non-enabled attribs. Also for checking if vertex buffers are mapped. Gives >100% increase in the benchmark. BUG=angleproject:959 Change-Id: I211c310385bdee46ed06f68ecd9c98385e1f8db9 Reviewed-on: https://chromium-review.googlesource.com/267751Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org>
parent 1377689c
...@@ -1418,7 +1418,8 @@ bool State::hasMappedBuffer(GLenum target) const ...@@ -1418,7 +1418,8 @@ bool State::hasMappedBuffer(GLenum target) const
{ {
const VertexArray *vao = getVertexArray(); const VertexArray *vao = getVertexArray();
const auto &vertexAttribs = vao->getVertexAttributes(); const auto &vertexAttribs = vao->getVertexAttributes();
for (size_t attribIndex = 0; attribIndex < vertexAttribs.size(); attribIndex++) unsigned int maxEnabledAttrib = vao->getMaxEnabledAttribute();
for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++)
{ {
const gl::VertexAttribute &vertexAttrib = vertexAttribs[attribIndex]; const gl::VertexAttribute &vertexAttrib = vertexAttribs[attribIndex];
gl::Buffer *boundBuffer = vertexAttrib.buffer.get(); gl::Buffer *boundBuffer = vertexAttrib.buffer.get();
......
...@@ -16,7 +16,8 @@ namespace gl ...@@ -16,7 +16,8 @@ namespace gl
VertexArray::VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs) VertexArray::VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs)
: mId(id), : mId(id),
mVertexArray(impl), mVertexArray(impl),
mVertexAttributes(maxAttribs) mVertexAttributes(maxAttribs),
mMaxEnabledAttribute(0)
{ {
ASSERT(impl != NULL); ASSERT(impl != NULL);
} }
...@@ -76,6 +77,19 @@ void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState ...@@ -76,6 +77,19 @@ void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState
ASSERT(attributeIndex < getMaxAttribs()); ASSERT(attributeIndex < getMaxAttribs());
mVertexAttributes[attributeIndex].enabled = enabledState; mVertexAttributes[attributeIndex].enabled = enabledState;
mVertexArray->enableAttribute(attributeIndex, enabledState); mVertexArray->enableAttribute(attributeIndex, enabledState);
// Update state cache
if (enabledState)
{
mMaxEnabledAttribute = std::max(attributeIndex, mMaxEnabledAttribute);
}
else if (mMaxEnabledAttribute == attributeIndex)
{
while (mMaxEnabledAttribute > 0 && !mVertexAttributes[mMaxEnabledAttribute].enabled)
{
--mMaxEnabledAttribute;
}
}
} }
void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type, void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
......
...@@ -53,12 +53,15 @@ class VertexArray ...@@ -53,12 +53,15 @@ class VertexArray
rx::VertexArrayImpl *getImplementation() { return mVertexArray; } rx::VertexArrayImpl *getImplementation() { return mVertexArray; }
const rx::VertexArrayImpl *getImplementation() const { return mVertexArray; } const rx::VertexArrayImpl *getImplementation() const { return mVertexArray; }
unsigned int getMaxEnabledAttribute() const { return mMaxEnabledAttribute; }
private: private:
GLuint mId; GLuint mId;
rx::VertexArrayImpl *mVertexArray; rx::VertexArrayImpl *mVertexArray;
std::vector<VertexAttribute> mVertexAttributes; std::vector<VertexAttribute> mVertexAttributes;
BindingPointer<Buffer> mElementArrayBuffer; BindingPointer<Buffer> mElementArrayBuffer;
unsigned int mMaxEnabledAttribute;
}; };
} }
......
...@@ -1407,7 +1407,8 @@ static bool ValidateDrawBase(Context *context, GLenum mode, GLsizei count, GLsiz ...@@ -1407,7 +1407,8 @@ static bool ValidateDrawBase(Context *context, GLenum mode, GLsizei count, GLsiz
const VertexArray *vao = state.getVertexArray(); const VertexArray *vao = state.getVertexArray();
const auto &vertexAttribs = vao->getVertexAttributes(); const auto &vertexAttribs = vao->getVertexAttributes();
const int *semanticIndexes = program->getSemanticIndexes(); const int *semanticIndexes = program->getSemanticIndexes();
for (size_t attributeIndex = 0; attributeIndex < vertexAttribs.size(); ++attributeIndex) unsigned int maxEnabledAttrib = vao->getMaxEnabledAttribute();
for (size_t attributeIndex = 0; attributeIndex < maxEnabledAttrib; ++attributeIndex)
{ {
const VertexAttribute &attrib = vertexAttribs[attributeIndex]; const VertexAttribute &attrib = vertexAttribs[attributeIndex];
bool attribActive = (semanticIndexes[attributeIndex] != -1); bool attribActive = (semanticIndexes[attributeIndex] != -1);
......
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