Commit 5ead927f by Geoff Lang

Don't use a helper function to get the vertex attributes.

The overhead of the function call ended up being a hot spot for draw calls since the attributes are iterated over many times in VertexDataManager. BUG=angleproject:959 Change-Id: I9bbfcbd115661ad629db9ed93d683cd8d0dc9a78 Reviewed-on: https://chromium-review.googlesource.com/263102Tested-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 5b97287e
...@@ -1055,11 +1055,6 @@ void State::setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GL ...@@ -1055,11 +1055,6 @@ void State::setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GL
getVertexArray()->setAttributeState(attribNum, boundBuffer, size, type, normalized, pureInteger, stride, pointer); getVertexArray()->setAttributeState(attribNum, boundBuffer, size, type, normalized, pureInteger, stride, pointer);
} }
const VertexAttribute &State::getVertexAttribState(unsigned int attribNum) const
{
return getVertexArray()->getVertexAttribute(attribNum);
}
const VertexAttribCurrentValueData &State::getVertexAttribCurrentValue(unsigned int attribNum) const const VertexAttribCurrentValueData &State::getVertexAttribCurrentValue(unsigned int attribNum) const
{ {
ASSERT(static_cast<size_t>(attribNum) < mVertexAttribCurrentValues.size()); ASSERT(static_cast<size_t>(attribNum) < mVertexAttribCurrentValues.size());
...@@ -1451,9 +1446,10 @@ bool State::hasMappedBuffer(GLenum target) const ...@@ -1451,9 +1446,10 @@ bool State::hasMappedBuffer(GLenum target) const
{ {
if (target == GL_ARRAY_BUFFER) if (target == GL_ARRAY_BUFFER)
{ {
const VertexArray *vao = getVertexArray();
for (size_t attribIndex = 0; attribIndex < mVertexAttribCurrentValues.size(); attribIndex++) for (size_t attribIndex = 0; attribIndex < mVertexAttribCurrentValues.size(); attribIndex++)
{ {
const gl::VertexAttribute &vertexAttrib = getVertexAttribState(static_cast<unsigned int>(attribIndex)); const gl::VertexAttribute &vertexAttrib = vao->getVertexAttribute(attribIndex);
gl::Buffer *boundBuffer = vertexAttrib.buffer.get(); gl::Buffer *boundBuffer = vertexAttrib.buffer.get();
if (vertexAttrib.enabled && boundBuffer && boundBuffer->isMapped()) if (vertexAttrib.enabled && boundBuffer && boundBuffer->isMapped())
{ {
......
...@@ -229,7 +229,6 @@ class State ...@@ -229,7 +229,6 @@ class State
void setVertexAttribi(GLuint index, const GLint values[4]); void setVertexAttribi(GLuint index, const GLint values[4]);
void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type, void setVertexAttribState(unsigned int attribNum, Buffer *boundBuffer, GLint size, GLenum type,
bool normalized, bool pureInteger, GLsizei stride, const void *pointer); bool normalized, bool pureInteger, GLsizei stride, const void *pointer);
const VertexAttribute &getVertexAttribState(unsigned int attribNum) const;
const VertexAttribCurrentValueData &getVertexAttribCurrentValue(unsigned int attribNum) const; const VertexAttribCurrentValueData &getVertexAttribCurrentValue(unsigned int attribNum) const;
const void *getVertexAttribPointer(unsigned int attribNum) const; const void *getVertexAttribPointer(unsigned int attribNum) const;
......
...@@ -59,6 +59,11 @@ const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) co ...@@ -59,6 +59,11 @@ const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) co
return mVertexAttributes[attributeIndex]; return mVertexAttributes[attributeIndex];
} }
const std::vector<VertexAttribute> &VertexArray::getVertexAttributes() const
{
return mVertexAttributes;
}
void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor) void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)
{ {
ASSERT(index < getMaxAttribs()); ASSERT(index < getMaxAttribs());
......
...@@ -37,13 +37,14 @@ class VertexArray ...@@ -37,13 +37,14 @@ class VertexArray
GLuint id() const; GLuint id() const;
const VertexAttribute& getVertexAttribute(size_t attributeIndex) const; const VertexAttribute& getVertexAttribute(size_t attributeIndex) const;
const std::vector<VertexAttribute> &getVertexAttributes() const;
void detachBuffer(GLuint bufferName); void detachBuffer(GLuint bufferName);
void setVertexAttribDivisor(GLuint index, GLuint divisor); void setVertexAttribDivisor(GLuint index, GLuint divisor);
void enableAttribute(unsigned int attributeIndex, bool enabledState); void enableAttribute(unsigned int attributeIndex, bool enabledState);
void setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type, void setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
bool normalized, bool pureInteger, GLsizei stride, const void *pointer); bool normalized, bool pureInteger, GLsizei stride, const void *pointer);
const VertexAttribute* getVertexAttributes() const { return &mVertexAttributes[0]; }
Buffer *getElementArrayBuffer() const { return mElementArrayBuffer.get(); } Buffer *getElementArrayBuffer() const { return mElementArrayBuffer.get(); }
void setElementArrayBuffer(Buffer *buffer); void setElementArrayBuffer(Buffer *buffer);
GLuint getElementArrayBufferId() const { return mElementArrayBuffer.id(); } GLuint getElementArrayBufferId() const { return mElementArrayBuffer.id(); }
......
...@@ -190,8 +190,8 @@ void VertexFormat::GetInputLayout(VertexFormat *inputLayout, ...@@ -190,8 +190,8 @@ void VertexFormat::GetInputLayout(VertexFormat *inputLayout,
Program *program, Program *program,
const State &state) const State &state)
{ {
const VertexAttribute *vertexAttributes = state.getVertexArray()->getVertexAttributes(); const std::vector<VertexAttribute> &vertexAttributes = state.getVertexArray()->getVertexAttributes();
for (unsigned int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) for (unsigned int attributeIndex = 0; attributeIndex < vertexAttributes.size(); attributeIndex++)
{ {
int semanticIndex = program->getSemanticIndex(attributeIndex); int semanticIndex = program->getSemanticIndex(attributeIndex);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "libANGLE/Buffer.h" #include "libANGLE/Buffer.h"
#include "libANGLE/Program.h" #include "libANGLE/Program.h"
#include "libANGLE/VertexAttribute.h" #include "libANGLE/VertexAttribute.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/State.h" #include "libANGLE/State.h"
namespace namespace
...@@ -85,13 +86,13 @@ VertexDataManager::~VertexDataManager() ...@@ -85,13 +86,13 @@ VertexDataManager::~VertexDataManager()
} }
} }
void VertexDataManager::hintUnmapAllResources(const gl::State &state) void VertexDataManager::hintUnmapAllResources(const std::vector<gl::VertexAttribute> &vertexAttributes)
{ {
mStreamingBuffer->getVertexBuffer()->hintUnmapResource(); mStreamingBuffer->getVertexBuffer()->hintUnmapResource();
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) for (size_t i = 0; i < vertexAttributes.size(); i++)
{ {
const gl::VertexAttribute &attrib = state.getVertexAttribState(i); const gl::VertexAttribute &attrib = vertexAttributes[i];
if (attrib.enabled) if (attrib.enabled)
{ {
gl::Buffer *buffer = attrib.buffer.get(); gl::Buffer *buffer = attrib.buffer.get();
...@@ -122,25 +123,25 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta ...@@ -122,25 +123,25 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta
return gl::Error(GL_OUT_OF_MEMORY, "Internal streaming vertex buffer is unexpectedly NULL."); return gl::Error(GL_OUT_OF_MEMORY, "Internal streaming vertex buffer is unexpectedly NULL.");
} }
const gl::VertexArray *vertexArray = state.getVertexArray();
const std::vector<gl::VertexAttribute> &vertexAttributes = vertexArray->getVertexAttributes();
// Invalidate static buffers that don't contain matching attributes // Invalidate static buffers that don't contain matching attributes
for (int attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++) for (int attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++)
{ {
translated[attributeIndex].active = (state.getProgram()->getSemanticIndex(attributeIndex) != -1); translated[attributeIndex].active = (state.getProgram()->getSemanticIndex(attributeIndex) != -1);
const gl::VertexAttribute &curAttrib = state.getVertexAttribState(attributeIndex); if (translated[attributeIndex].active && vertexAttributes[attributeIndex].enabled)
if (translated[attributeIndex].active && curAttrib.enabled)
{ {
invalidateMatchingStaticData(curAttrib, state.getVertexAttribCurrentValue(attributeIndex)); invalidateMatchingStaticData(vertexAttributes[attributeIndex], state.getVertexAttribCurrentValue(attributeIndex));
} }
} }
// Reserve the required space in the buffers // Reserve the required space in the buffers
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{ {
const gl::VertexAttribute &curAttrib = state.getVertexAttribState(i); if (translated[i].active && vertexAttributes[i].enabled)
if (translated[i].active && curAttrib.enabled)
{ {
gl::Error error = reserveSpaceForAttrib(curAttrib, state.getVertexAttribCurrentValue(i), count, instances); gl::Error error = reserveSpaceForAttrib(vertexAttributes[i], state.getVertexAttribCurrentValue(i), count, instances);
if (error.isError()) if (error.isError())
{ {
return error; return error;
...@@ -151,7 +152,7 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta ...@@ -151,7 +152,7 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta
// Perform the vertex data translations // Perform the vertex data translations
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{ {
const gl::VertexAttribute &curAttrib = state.getVertexAttribState(i); const gl::VertexAttribute &curAttrib = vertexAttributes[i];
if (translated[i].active) if (translated[i].active)
{ {
if (curAttrib.enabled) if (curAttrib.enabled)
...@@ -161,7 +162,7 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta ...@@ -161,7 +162,7 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta
if (error.isError()) if (error.isError())
{ {
hintUnmapAllResources(state); hintUnmapAllResources(vertexAttributes);
return error; return error;
} }
} }
...@@ -177,7 +178,7 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta ...@@ -177,7 +178,7 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta
mCurrentValueBuffer[i]); mCurrentValueBuffer[i]);
if (error.isError()) if (error.isError())
{ {
hintUnmapAllResources(state); hintUnmapAllResources(vertexAttributes);
return error; return error;
} }
} }
...@@ -185,11 +186,11 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta ...@@ -185,11 +186,11 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta
} }
// Hint to unmap all the resources // Hint to unmap all the resources
hintUnmapAllResources(state); hintUnmapAllResources(vertexAttributes);
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{ {
const gl::VertexAttribute &curAttrib = state.getVertexAttribState(i); const gl::VertexAttribute &curAttrib = vertexAttributes[i];
if (translated[i].active && curAttrib.enabled) if (translated[i].active && curAttrib.enabled)
{ {
gl::Buffer *buffer = curAttrib.buffer.get(); gl::Buffer *buffer = curAttrib.buffer.get();
......
...@@ -80,7 +80,7 @@ class VertexDataManager ...@@ -80,7 +80,7 @@ class VertexDataManager
size_t *cachedOffset, size_t *cachedOffset,
StreamingVertexBufferInterface *buffer); StreamingVertexBufferInterface *buffer);
void hintUnmapAllResources(const gl::State &state); void hintUnmapAllResources(const std::vector<gl::VertexAttribute> &vertexAttributes);
RendererD3D *const mRenderer; RendererD3D *const mRenderer;
......
...@@ -2856,7 +2856,6 @@ void GL_APIENTRY GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params) ...@@ -2856,7 +2856,6 @@ void GL_APIENTRY GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
return; return;
} }
const VertexAttribute &attribState = context->getState().getVertexAttribState(index);
if (!ValidateGetVertexAttribParameters(context, pname)) if (!ValidateGetVertexAttribParameters(context, pname))
{ {
return; return;
...@@ -2872,6 +2871,7 @@ void GL_APIENTRY GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params) ...@@ -2872,6 +2871,7 @@ void GL_APIENTRY GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
} }
else else
{ {
const VertexAttribute &attribState = context->getState().getVertexArray()->getVertexAttribute(index);
*params = QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname); *params = QuerySingleVertexAttributeParameter<GLfloat>(attribState, pname);
} }
} }
...@@ -2890,8 +2890,6 @@ void GL_APIENTRY GetVertexAttribiv(GLuint index, GLenum pname, GLint* params) ...@@ -2890,8 +2890,6 @@ void GL_APIENTRY GetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
return; return;
} }
const VertexAttribute &attribState = context->getState().getVertexAttribState(index);
if (!ValidateGetVertexAttribParameters(context, pname)) if (!ValidateGetVertexAttribParameters(context, pname))
{ {
return; return;
...@@ -2908,6 +2906,7 @@ void GL_APIENTRY GetVertexAttribiv(GLuint index, GLenum pname, GLint* params) ...@@ -2908,6 +2906,7 @@ void GL_APIENTRY GetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
} }
else else
{ {
const VertexAttribute &attribState = context->getState().getVertexArray()->getVertexAttribute(index);
*params = QuerySingleVertexAttributeParameter<GLint>(attribState, pname); *params = QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
} }
} }
......
...@@ -1379,8 +1379,6 @@ void GL_APIENTRY GetVertexAttribIiv(GLuint index, GLenum pname, GLint* params) ...@@ -1379,8 +1379,6 @@ void GL_APIENTRY GetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
return; return;
} }
const VertexAttribute &attribState = context->getState().getVertexAttribState(index);
if (!ValidateGetVertexAttribParameters(context, pname)) if (!ValidateGetVertexAttribParameters(context, pname))
{ {
return; return;
...@@ -1396,6 +1394,7 @@ void GL_APIENTRY GetVertexAttribIiv(GLuint index, GLenum pname, GLint* params) ...@@ -1396,6 +1394,7 @@ void GL_APIENTRY GetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
} }
else else
{ {
const VertexAttribute &attribState = context->getState().getVertexArray()->getVertexAttribute(index);
*params = QuerySingleVertexAttributeParameter<GLint>(attribState, pname); *params = QuerySingleVertexAttributeParameter<GLint>(attribState, pname);
} }
} }
...@@ -1421,8 +1420,6 @@ void GL_APIENTRY GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params) ...@@ -1421,8 +1420,6 @@ void GL_APIENTRY GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
return; return;
} }
const VertexAttribute &attribState = context->getState().getVertexAttribState(index);
if (!ValidateGetVertexAttribParameters(context, pname)) if (!ValidateGetVertexAttribParameters(context, pname))
{ {
return; return;
...@@ -1438,6 +1435,7 @@ void GL_APIENTRY GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params) ...@@ -1438,6 +1435,7 @@ void GL_APIENTRY GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
} }
else else
{ {
const VertexAttribute &attribState = context->getState().getVertexArray()->getVertexAttribute(index);
*params = QuerySingleVertexAttributeParameter<GLuint>(attribState, pname); *params = QuerySingleVertexAttributeParameter<GLuint>(attribState, pname);
} }
} }
......
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