Commit 9c38580b by Jamie Madill

Refactor VertexDataManager to store translated attrib.

Refactoring patch only. Reduces the number of parameters we need to pass around in internal functions. Clears the way for future optimization work. BUG=angleproject:959 Change-Id: Ic98ab5a07189eaa053dffce994546666bb07cede Reviewed-on: https://chromium-review.googlesource.com/277281Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 3b345ebd
...@@ -130,22 +130,29 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta ...@@ -130,22 +130,29 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta
const gl::VertexArray *vertexArray = state.getVertexArray(); const gl::VertexArray *vertexArray = state.getVertexArray();
const std::vector<gl::VertexAttribute> &vertexAttributes = vertexArray->getVertexAttributes(); const std::vector<gl::VertexAttribute> &vertexAttributes = vertexArray->getVertexAttributes();
// Invalidate static buffers that don't contain matching attributes for (size_t attribIndex = 0; attribIndex < vertexAttributes.size(); ++attribIndex)
for (int attributeIndex = 0; attributeIndex < gl::MAX_VERTEX_ATTRIBS; attributeIndex++)
{ {
translated[attributeIndex].active = (state.getProgram()->getSemanticIndex(attributeIndex) != -1); translated[attribIndex].active = (state.getProgram()->getSemanticIndex(attribIndex) != -1);
if (translated[attributeIndex].active && vertexAttributes[attributeIndex].enabled) if (translated[attribIndex].active)
{ {
invalidateMatchingStaticData(vertexAttributes[attributeIndex], state.getVertexAttribCurrentValue(attributeIndex)); // Record the attribute now
translated[attribIndex].attribute = &vertexAttributes[attribIndex];
if (vertexAttributes[attribIndex].enabled)
{
// Also invalidate static buffers that don't contain matching attributes
invalidateMatchingStaticData(vertexAttributes[attribIndex],
state.getVertexAttribCurrentValue(attribIndex));
}
} }
} }
// 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++)
{ {
if (translated[i].active && vertexAttributes[i].enabled) if (translated[i].active && translated[i].attribute->enabled)
{ {
gl::Error error = reserveSpaceForAttrib(vertexAttributes[i], state.getVertexAttribCurrentValue(i), count, instances); gl::Error error = reserveSpaceForAttrib(*translated[i].attribute, state.getVertexAttribCurrentValue(i), count, instances);
if (error.isError()) if (error.isError())
{ {
return error; return error;
...@@ -156,13 +163,15 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta ...@@ -156,13 +163,15 @@ 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 = vertexAttributes[i];
if (translated[i].active) if (translated[i].active)
{ {
if (curAttrib.enabled) if (translated[i].attribute->enabled)
{ {
gl::Error error = storeAttribute(curAttrib, state.getVertexAttribCurrentValue(i), gl::Error error = storeAttribute(state.getVertexAttribCurrentValue(i),
&translated[i], start, count, instances); &translated[i],
start,
count,
instances);
if (error.isError()) if (error.isError())
{ {
...@@ -177,8 +186,7 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta ...@@ -177,8 +186,7 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta
mCurrentValueCache[i].buffer = new StreamingVertexBufferInterface(mFactory, CONSTANT_VERTEX_BUFFER_SIZE); mCurrentValueCache[i].buffer = new StreamingVertexBufferInterface(mFactory, CONSTANT_VERTEX_BUFFER_SIZE);
} }
gl::Error error = storeCurrentValue(curAttrib, gl::Error error = storeCurrentValue(state.getVertexAttribCurrentValue(i),
state.getVertexAttribCurrentValue(i),
&translated[i], &translated[i],
&mCurrentValueCache[i]); &mCurrentValueCache[i]);
if (error.isError()) if (error.isError())
...@@ -271,13 +279,14 @@ gl::Error VertexDataManager::reserveSpaceForAttrib(const gl::VertexAttribute &at ...@@ -271,13 +279,14 @@ gl::Error VertexDataManager::reserveSpaceForAttrib(const gl::VertexAttribute &at
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib, gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribCurrentValueData &currentValue,
const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated, TranslatedAttribute *translated,
GLint start, GLint start,
GLsizei count, GLsizei count,
GLsizei instances) GLsizei instances)
{ {
const gl::VertexAttribute &attrib = *translated->attribute;
gl::Buffer *buffer = attrib.buffer.get(); gl::Buffer *buffer = attrib.buffer.get();
ASSERT(buffer || attrib.pointer); ASSERT(buffer || attrib.pointer);
...@@ -350,7 +359,6 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib, ...@@ -350,7 +359,6 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
translated->serial = directStorage ? storage->getSerial() : vertexBuffer->getSerial(); translated->serial = directStorage ? storage->getSerial() : vertexBuffer->getSerial();
translated->divisor = attrib.divisor; translated->divisor = attrib.divisor;
translated->attribute = &attrib;
translated->currentValueType = currentValue.Type; translated->currentValueType = currentValue.Type;
translated->stride = outputElementSize; translated->stride = outputElementSize;
translated->offset = streamOffset; translated->offset = streamOffset;
...@@ -358,13 +366,13 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib, ...@@ -358,13 +366,13 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribute &attrib, gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribCurrentValueData &currentValue,
const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated, TranslatedAttribute *translated,
CurrentValueState *cachedState) CurrentValueState *cachedState)
{ {
if (cachedState->data != currentValue) if (cachedState->data != currentValue)
{ {
const gl::VertexAttribute &attrib = *translated->attribute;
gl::Error error = cachedState->buffer->reserveVertexSpace(attrib, 1, 0); gl::Error error = cachedState->buffer->reserveVertexSpace(attrib, 1, 0);
if (error.isError()) if (error.isError())
{ {
...@@ -387,7 +395,6 @@ gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribute &attrib ...@@ -387,7 +395,6 @@ gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribute &attrib
translated->serial = cachedState->buffer->getSerial(); translated->serial = cachedState->buffer->getSerial();
translated->divisor = 0; translated->divisor = 0;
translated->attribute = &attrib;
translated->currentValueType = currentValue.Type; translated->currentValueType = currentValue.Type;
translated->stride = 0; translated->stride = 0;
translated->offset = cachedState->offset; translated->offset = cachedState->offset;
......
...@@ -74,15 +74,13 @@ class VertexDataManager : angle::NonCopyable ...@@ -74,15 +74,13 @@ class VertexDataManager : angle::NonCopyable
void invalidateMatchingStaticData(const gl::VertexAttribute &attrib, void invalidateMatchingStaticData(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue) const; const gl::VertexAttribCurrentValueData &currentValue) const;
gl::Error storeAttribute(const gl::VertexAttribute &attrib, gl::Error storeAttribute(const gl::VertexAttribCurrentValueData &currentValue,
const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated, TranslatedAttribute *translated,
GLint start, GLint start,
GLsizei count, GLsizei count,
GLsizei instances); GLsizei instances);
gl::Error storeCurrentValue(const gl::VertexAttribute &attrib, gl::Error storeCurrentValue(const gl::VertexAttribCurrentValueData &currentValue,
const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated, TranslatedAttribute *translated,
CurrentValueState *cachedState); CurrentValueState *cachedState);
......
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