Commit 7d112bb9 by Jamie Madill

Refactor source pointer math out of VertexBuffer9/11.

This math can live in a single place in the VertexDataManager. This cleans up the code and paves the way for future optimizations. BUG=angleproject:959 Change-Id: I7138c6e080d9c3d6507b55d981bfb62c2590a2a8 Reviewed-on: https://chromium-review.googlesource.com/277282Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 9c38580b
...@@ -90,8 +90,13 @@ gl::Error VertexBufferInterface::discard() ...@@ -90,8 +90,13 @@ gl::Error VertexBufferInterface::discard()
return mVertexBuffer->discard(); return mVertexBuffer->discard();
} }
gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset) const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int *outStreamOffset,
const uint8_t *sourceData)
{ {
gl::Error error(GL_NO_ERROR); gl::Error error(GL_NO_ERROR);
...@@ -114,7 +119,7 @@ gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute ...@@ -114,7 +119,7 @@ gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute
} }
mReservedSpace = 0; mReservedSpace = 0;
error = mVertexBuffer->storeVertexAttributes(attrib, currentValue, start, count, instances, mWritePosition); error = mVertexBuffer->storeVertexAttributes(attrib, currentValue, start, count, instances, mWritePosition, sourceData);
if (error.isError()) if (error.isError())
{ {
return error; return error;
...@@ -286,11 +291,16 @@ gl::Error StaticVertexBufferInterface::reserveSpace(unsigned int size) ...@@ -286,11 +291,16 @@ gl::Error StaticVertexBufferInterface::reserveSpace(unsigned int size)
} }
} }
gl::Error StaticVertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, gl::Error StaticVertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset) const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int *outStreamOffset,
const uint8_t *sourceData)
{ {
unsigned int streamOffset; unsigned int streamOffset;
gl::Error error = VertexBufferInterface::storeVertexAttributes(attrib, currentValue, start, count, instances, &streamOffset); gl::Error error = VertexBufferInterface::storeVertexAttributes(attrib, currentValue, start, count, instances, &streamOffset, sourceData);
if (error.isError()) if (error.isError())
{ {
return error; return error;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <vector> #include <vector>
namespace gl namespace gl
...@@ -36,8 +37,13 @@ class VertexBuffer : angle::NonCopyable ...@@ -36,8 +37,13 @@ class VertexBuffer : angle::NonCopyable
virtual gl::Error initialize(unsigned int size, bool dynamicUsage) = 0; virtual gl::Error initialize(unsigned int size, bool dynamicUsage) = 0;
virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
GLint start, GLsizei count, GLsizei instances, unsigned int offset) = 0; const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int offset,
const uint8_t *sourceData) = 0;
virtual gl::Error getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances, virtual gl::Error getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
unsigned int *outSpaceRequired) const = 0; unsigned int *outSpaceRequired) const = 0;
...@@ -70,8 +76,13 @@ class VertexBufferInterface : angle::NonCopyable ...@@ -70,8 +76,13 @@ class VertexBufferInterface : angle::NonCopyable
unsigned int getSerial() const; unsigned int getSerial() const;
virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset); const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int *outStreamOffset,
const uint8_t *sourceData);
bool directStoragePossible(const gl::VertexAttribute &attrib, bool directStoragePossible(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue) const; const gl::VertexAttribCurrentValueData &currentValue) const;
...@@ -114,8 +125,13 @@ class StaticVertexBufferInterface : public VertexBufferInterface ...@@ -114,8 +125,13 @@ class StaticVertexBufferInterface : public VertexBufferInterface
explicit StaticVertexBufferInterface(BufferFactoryD3D *factory); explicit StaticVertexBufferInterface(BufferFactoryD3D *factory);
~StaticVertexBufferInterface(); ~StaticVertexBufferInterface();
gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset); const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int *outStreamOffset,
const uint8_t *sourceData) override;
bool lookupAttribute(const gl::VertexAttribute &attribute, unsigned int* outStreamFffset); bool lookupAttribute(const gl::VertexAttribute &attribute, unsigned int* outStreamFffset);
......
...@@ -289,24 +289,52 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribCurrentValueDa ...@@ -289,24 +289,52 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribCurrentValueDa
gl::Buffer *buffer = attrib.buffer.get(); gl::Buffer *buffer = attrib.buffer.get();
ASSERT(buffer || attrib.pointer); ASSERT(buffer || attrib.pointer);
ASSERT(attrib.enabled);
BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : NULL; BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : NULL;
StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL; StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL;
VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer); VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
bool directStorage = vertexBuffer->directStoragePossible(attrib, currentValue); bool directStorage = vertexBuffer->directStoragePossible(attrib, currentValue);
unsigned int streamOffset = 0;
unsigned int outputElementSize = 0;
// Instanced vertices do not apply the 'start' offset // Instanced vertices do not apply the 'start' offset
GLint firstVertexIndex = (instances > 0 && attrib.divisor > 0 ? 0 : start); GLint firstVertexIndex = (instances > 0 && attrib.divisor > 0 ? 0 : start);
translated->vertexBuffer = vertexBuffer->getVertexBuffer();
if (directStorage) if (directStorage)
{ {
outputElementSize = ComputeVertexAttributeStride(attrib); translated->storage = storage;
streamOffset = static_cast<unsigned int>(attrib.offset + outputElementSize * firstVertexIndex); translated->serial = storage->getSerial();
translated->divisor = attrib.divisor;
translated->currentValueType = currentValue.Type;
translated->stride = ComputeVertexAttributeStride(attrib);
translated->offset = static_cast<unsigned int>(attrib.offset + translated->stride * firstVertexIndex);
return gl::Error(GL_NO_ERROR);
}
// Compute source data pointer
const uint8_t *sourceData = nullptr;
if (buffer)
{
gl::Error error = storage->getData(&sourceData);
if (error.isError())
{
return error;
}
sourceData += static_cast<int>(attrib.offset);
}
else
{
sourceData = static_cast<const uint8_t*>(attrib.pointer);
} }
else if (staticBuffer)
unsigned int streamOffset = 0;
unsigned int outputElementSize = 0;
if (staticBuffer)
{ {
gl::Error error = staticBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize); gl::Error error = staticBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize);
if (error.isError()) if (error.isError())
...@@ -320,8 +348,13 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribCurrentValueDa ...@@ -320,8 +348,13 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribCurrentValueDa
int totalCount = ElementsInBuffer(attrib, storage->getSize()); int totalCount = ElementsInBuffer(attrib, storage->getSize());
int startIndex = attrib.offset / ComputeVertexAttributeStride(attrib); int startIndex = attrib.offset / ComputeVertexAttributeStride(attrib);
error = staticBuffer->storeVertexAttributes(attrib, currentValue, -startIndex, totalCount, error = staticBuffer->storeVertexAttributes(attrib,
0, &streamOffset); currentValue,
-startIndex,
totalCount,
0,
&streamOffset,
sourceData);
if (error.isError()) if (error.isError())
{ {
return error; return error;
...@@ -346,17 +379,21 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribCurrentValueDa ...@@ -346,17 +379,21 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribCurrentValueDa
return error; return error;
} }
error = mStreamingBuffer->storeVertexAttributes(attrib, currentValue, firstVertexIndex, error = mStreamingBuffer->storeVertexAttributes(attrib,
totalCount, instances, &streamOffset); currentValue,
firstVertexIndex,
totalCount,
instances,
&streamOffset,
sourceData);
if (error.isError()) if (error.isError())
{ {
return error; return error;
} }
} }
translated->storage = directStorage ? storage : NULL; translated->storage = nullptr;
translated->vertexBuffer = vertexBuffer->getVertexBuffer(); translated->serial = vertexBuffer->getSerial();
translated->serial = directStorage ? storage->getSerial() : vertexBuffer->getSerial();
translated->divisor = attrib.divisor; translated->divisor = attrib.divisor;
translated->currentValueType = currentValue.Type; translated->currentValueType = currentValue.Type;
...@@ -379,8 +416,9 @@ gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribCurrentValu ...@@ -379,8 +416,9 @@ gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribCurrentValu
return error; return error;
} }
const uint8_t *sourceData = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
unsigned int streamOffset; unsigned int streamOffset;
error = cachedState->buffer->storeVertexAttributes(attrib, currentValue, 0, 1, 0, &streamOffset); error = cachedState->buffer->storeVertexAttributes(attrib, currentValue, 0, 1, 0, &streamOffset, sourceData);
if (error.isError()) if (error.isError())
{ {
return error; return error;
......
...@@ -103,15 +103,19 @@ void VertexBuffer11::hintUnmapResource() ...@@ -103,15 +103,19 @@ void VertexBuffer11::hintUnmapResource()
} }
} }
gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib,
GLint start, GLsizei count, GLsizei instances, unsigned int offset) const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int offset,
const uint8_t *sourceData)
{ {
if (!mBuffer) if (!mBuffer)
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized."); return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized.");
} }
gl::Buffer *buffer = attrib.buffer.get();
int inputStride = ComputeVertexAttributeStride(attrib); int inputStride = ComputeVertexAttributeStride(attrib);
// This will map the resource if it isn't already mapped. // This will map the resource if it isn't already mapped.
...@@ -123,28 +127,7 @@ gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attri ...@@ -123,28 +127,7 @@ gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attri
uint8_t *output = mMappedResourceData + offset; uint8_t *output = mMappedResourceData + offset;
const uint8_t *input = NULL; const uint8_t *input = sourceData;
if (attrib.enabled)
{
if (buffer)
{
BufferD3D *storage = GetImplAs<BufferD3D>(buffer);
error = storage->getData(&input);
if (error.isError())
{
return error;
}
input += static_cast<int>(attrib.offset);
}
else
{
input = static_cast<const uint8_t*>(attrib.pointer);
}
}
else
{
input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
}
if (instances == 0 || attrib.divisor == 0) if (instances == 0 || attrib.divisor == 0)
{ {
......
...@@ -25,8 +25,13 @@ class VertexBuffer11 : public VertexBuffer ...@@ -25,8 +25,13 @@ class VertexBuffer11 : public VertexBuffer
virtual gl::Error initialize(unsigned int size, bool dynamicUsage); virtual gl::Error initialize(unsigned int size, bool dynamicUsage);
virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
GLint start, GLsizei count, GLsizei instances, unsigned int offset); const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int offset,
const uint8_t *sourceData) override;
virtual gl::Error getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances, virtual gl::Error getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
unsigned int *outSpaceRequired) const; unsigned int *outSpaceRequired) const;
......
...@@ -56,16 +56,19 @@ gl::Error VertexBuffer9::initialize(unsigned int size, bool dynamicUsage) ...@@ -56,16 +56,19 @@ gl::Error VertexBuffer9::initialize(unsigned int size, bool dynamicUsage)
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
gl::Error VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, gl::Error VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib,
GLint start, GLsizei count, GLsizei instances, unsigned int offset) const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int offset,
const uint8_t *sourceData)
{ {
if (!mVertexBuffer) if (!mVertexBuffer)
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized."); return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized.");
} }
gl::Buffer *buffer = attrib.buffer.get();
int inputStride = gl::ComputeVertexAttributeStride(attrib); int inputStride = gl::ComputeVertexAttributeStride(attrib);
int elementSize = gl::ComputeVertexAttributeTypeSize(attrib); int elementSize = gl::ComputeVertexAttributeTypeSize(attrib);
...@@ -86,29 +89,7 @@ gl::Error VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib ...@@ -86,29 +89,7 @@ gl::Error VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib
return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal vertex buffer, HRESULT: 0x%08x.", result); return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal vertex buffer, HRESULT: 0x%08x.", result);
} }
const uint8_t *input = NULL; const uint8_t *input = sourceData;
if (attrib.enabled)
{
if (buffer)
{
BufferD3D *storage = GetImplAs<BufferD3D>(buffer);
ASSERT(storage);
error = storage->getData(&input);
if (error.isError())
{
return error;
}
input += static_cast<int>(attrib.offset);
}
else
{
input = static_cast<const uint8_t*>(attrib.pointer);
}
}
else
{
input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
}
if (instances == 0 || attrib.divisor == 0) if (instances == 0 || attrib.divisor == 0)
{ {
......
...@@ -23,8 +23,13 @@ class VertexBuffer9 : public VertexBuffer ...@@ -23,8 +23,13 @@ class VertexBuffer9 : public VertexBuffer
virtual gl::Error initialize(unsigned int size, bool dynamicUsage); virtual gl::Error initialize(unsigned int size, bool dynamicUsage);
virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
GLint start, GLsizei count, GLsizei instances, unsigned int offset); const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int offset,
const uint8_t *sourceData) override;
virtual gl::Error getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances, unsigned int *outSpaceRequired) const; virtual gl::Error getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances, unsigned int *outSpaceRequired) const;
......
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