Commit b3f4e8d1 by Jamie Madill

Refactor VertexDataManager's current value cache.

This clears the way for future optimizations. BUG=angleproject:959 Change-Id: Ief9077159e1e5fed5670862454a6f0b41d630551 Reviewed-on: https://chromium-review.googlesource.com/277280Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent f9327d33
...@@ -55,20 +55,28 @@ static int StreamingBufferElementCount(const gl::VertexAttribute &attrib, int ve ...@@ -55,20 +55,28 @@ static int StreamingBufferElementCount(const gl::VertexAttribute &attrib, int ve
return vertexDrawCount; return vertexDrawCount;
} }
VertexDataManager::VertexDataManager(BufferFactoryD3D *factory) VertexDataManager::CurrentValueState::CurrentValueState()
: mFactory(factory) : buffer(nullptr),
offset(0)
{ {
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) data.FloatValues[0] = std::numeric_limits<float>::quiet_NaN();
{ data.FloatValues[1] = std::numeric_limits<float>::quiet_NaN();
mCurrentValue[i].FloatValues[0] = std::numeric_limits<float>::quiet_NaN(); data.FloatValues[2] = std::numeric_limits<float>::quiet_NaN();
mCurrentValue[i].FloatValues[1] = std::numeric_limits<float>::quiet_NaN(); data.FloatValues[3] = std::numeric_limits<float>::quiet_NaN();
mCurrentValue[i].FloatValues[2] = std::numeric_limits<float>::quiet_NaN(); data.Type = GL_FLOAT;
mCurrentValue[i].FloatValues[3] = std::numeric_limits<float>::quiet_NaN(); }
mCurrentValue[i].Type = GL_FLOAT;
mCurrentValueBuffer[i] = NULL; VertexDataManager::CurrentValueState::~CurrentValueState()
mCurrentValueOffsets[i] = 0; {
} SafeDelete(buffer);
}
VertexDataManager::VertexDataManager(BufferFactoryD3D *factory)
: mFactory(factory),
mStreamingBuffer(nullptr),
// TODO(jmadill): use context caps
mCurrentValueCache(gl::MAX_VERTEX_ATTRIBS)
{
mStreamingBuffer = new StreamingVertexBufferInterface(factory, INITIAL_STREAM_BUFFER_SIZE); mStreamingBuffer = new StreamingVertexBufferInterface(factory, INITIAL_STREAM_BUFFER_SIZE);
if (!mStreamingBuffer) if (!mStreamingBuffer)
...@@ -79,12 +87,7 @@ VertexDataManager::VertexDataManager(BufferFactoryD3D *factory) ...@@ -79,12 +87,7 @@ VertexDataManager::VertexDataManager(BufferFactoryD3D *factory)
VertexDataManager::~VertexDataManager() VertexDataManager::~VertexDataManager()
{ {
delete mStreamingBuffer; SafeDelete(mStreamingBuffer);
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++)
{
delete mCurrentValueBuffer[i];
}
} }
void VertexDataManager::hintUnmapAllResources(const std::vector<gl::VertexAttribute> &vertexAttributes) void VertexDataManager::hintUnmapAllResources(const std::vector<gl::VertexAttribute> &vertexAttributes)
...@@ -107,11 +110,11 @@ void VertexDataManager::hintUnmapAllResources(const std::vector<gl::VertexAttrib ...@@ -107,11 +110,11 @@ void VertexDataManager::hintUnmapAllResources(const std::vector<gl::VertexAttrib
} }
} }
for (int i = 0; i < gl::MAX_VERTEX_ATTRIBS; i++) for (auto &currentValue : mCurrentValueCache)
{ {
if (mCurrentValueBuffer[i] != NULL) if (currentValue.buffer != nullptr)
{ {
mCurrentValueBuffer[i]->getVertexBuffer()->hintUnmapResource(); currentValue.buffer->getVertexBuffer()->hintUnmapResource();
} }
} }
} }
...@@ -169,14 +172,15 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta ...@@ -169,14 +172,15 @@ gl::Error VertexDataManager::prepareVertexData(const gl::State &state, GLint sta
} }
else else
{ {
if (!mCurrentValueBuffer[i]) if (mCurrentValueCache[i].buffer == nullptr)
{ {
mCurrentValueBuffer[i] = new StreamingVertexBufferInterface(mFactory, CONSTANT_VERTEX_BUFFER_SIZE); mCurrentValueCache[i].buffer = new StreamingVertexBufferInterface(mFactory, CONSTANT_VERTEX_BUFFER_SIZE);
} }
gl::Error error = storeCurrentValue(curAttrib, state.getVertexAttribCurrentValue(i), &translated[i], gl::Error error = storeCurrentValue(curAttrib,
&mCurrentValue[i], &mCurrentValueOffsets[i], state.getVertexAttribCurrentValue(i),
mCurrentValueBuffer[i]); &translated[i],
&mCurrentValueCache[i]);
if (error.isError()) if (error.isError())
{ {
hintUnmapAllResources(vertexAttributes); hintUnmapAllResources(vertexAttributes);
...@@ -357,38 +361,36 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib, ...@@ -357,38 +361,36 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribute &attrib,
gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribute &attrib, gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue, const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated, TranslatedAttribute *translated,
gl::VertexAttribCurrentValueData *cachedValue, CurrentValueState *cachedState)
size_t *cachedOffset,
StreamingVertexBufferInterface *buffer)
{ {
if (*cachedValue != currentValue) if (cachedState->data != currentValue)
{ {
gl::Error error = buffer->reserveVertexSpace(attrib, 1, 0); gl::Error error = cachedState->buffer->reserveVertexSpace(attrib, 1, 0);
if (error.isError()) if (error.isError())
{ {
return error; return error;
} }
unsigned int streamOffset; unsigned int streamOffset;
error = buffer->storeVertexAttributes(attrib, currentValue, 0, 1, 0, &streamOffset); error = cachedState->buffer->storeVertexAttributes(attrib, currentValue, 0, 1, 0, &streamOffset);
if (error.isError()) if (error.isError())
{ {
return error; return error;
} }
*cachedValue = currentValue; cachedState->data = currentValue;
*cachedOffset = streamOffset; cachedState->offset = streamOffset;
} }
translated->storage = NULL; translated->storage = NULL;
translated->vertexBuffer = buffer->getVertexBuffer(); translated->vertexBuffer = cachedState->buffer->getVertexBuffer();
translated->serial = buffer->getSerial(); translated->serial = cachedState->buffer->getSerial();
translated->divisor = 0; translated->divisor = 0;
translated->attribute = &attrib; translated->attribute = &attrib;
translated->currentValueType = currentValue.Type; translated->currentValueType = currentValue.Type;
translated->stride = 0; translated->stride = 0;
translated->offset = *cachedOffset; translated->offset = cachedState->offset;
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
......
...@@ -56,6 +56,16 @@ class VertexDataManager : angle::NonCopyable ...@@ -56,6 +56,16 @@ class VertexDataManager : angle::NonCopyable
TranslatedAttribute *outAttribs, GLsizei instances); TranslatedAttribute *outAttribs, GLsizei instances);
private: private:
struct CurrentValueState
{
CurrentValueState();
~CurrentValueState();
StreamingVertexBufferInterface *buffer;
gl::VertexAttribCurrentValueData data;
size_t offset;
};
gl::Error reserveSpaceForAttrib(const gl::VertexAttribute &attrib, gl::Error reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue, const gl::VertexAttribCurrentValueData &currentValue,
GLsizei count, GLsizei count,
...@@ -74,20 +84,14 @@ class VertexDataManager : angle::NonCopyable ...@@ -74,20 +84,14 @@ class VertexDataManager : angle::NonCopyable
gl::Error storeCurrentValue(const gl::VertexAttribute &attrib, gl::Error storeCurrentValue(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue, const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated, TranslatedAttribute *translated,
gl::VertexAttribCurrentValueData *cachedValue, CurrentValueState *cachedState);
size_t *cachedOffset,
StreamingVertexBufferInterface *buffer);
void hintUnmapAllResources(const std::vector<gl::VertexAttribute> &vertexAttributes); void hintUnmapAllResources(const std::vector<gl::VertexAttribute> &vertexAttributes);
BufferFactoryD3D *const mFactory; BufferFactoryD3D *const mFactory;
StreamingVertexBufferInterface *mStreamingBuffer; StreamingVertexBufferInterface *mStreamingBuffer;
std::vector<CurrentValueState> mCurrentValueCache;
gl::VertexAttribCurrentValueData mCurrentValue[gl::MAX_VERTEX_ATTRIBS];
StreamingVertexBufferInterface *mCurrentValueBuffer[gl::MAX_VERTEX_ATTRIBS];
std::size_t mCurrentValueOffsets[gl::MAX_VERTEX_ATTRIBS];
}; };
} }
......
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