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()
return mVertexBuffer->discard();
}
gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset)
gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int *outStreamOffset,
const uint8_t *sourceData)
{
gl::Error error(GL_NO_ERROR);
......@@ -114,7 +119,7 @@ gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute
}
mReservedSpace = 0;
error = mVertexBuffer->storeVertexAttributes(attrib, currentValue, start, count, instances, mWritePosition);
error = mVertexBuffer->storeVertexAttributes(attrib, currentValue, start, count, instances, mWritePosition, sourceData);
if (error.isError())
{
return error;
......@@ -286,11 +291,16 @@ gl::Error StaticVertexBufferInterface::reserveSpace(unsigned int size)
}
}
gl::Error StaticVertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset)
gl::Error StaticVertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int *outStreamOffset,
const uint8_t *sourceData)
{
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())
{
return error;
......
......@@ -16,6 +16,7 @@
#include <GLES2/gl2.h>
#include <cstddef>
#include <cstdint>
#include <vector>
namespace gl
......@@ -36,8 +37,13 @@ class VertexBuffer : angle::NonCopyable
virtual gl::Error initialize(unsigned int size, bool dynamicUsage) = 0;
virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int offset) = 0;
virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
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,
unsigned int *outSpaceRequired) const = 0;
......@@ -70,8 +76,13 @@ class VertexBufferInterface : angle::NonCopyable
unsigned int getSerial() const;
virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset);
virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int *outStreamOffset,
const uint8_t *sourceData);
bool directStoragePossible(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue) const;
......@@ -114,8 +125,13 @@ class StaticVertexBufferInterface : public VertexBufferInterface
explicit StaticVertexBufferInterface(BufferFactoryD3D *factory);
~StaticVertexBufferInterface();
gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset);
gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
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);
......
......@@ -289,24 +289,52 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribCurrentValueDa
gl::Buffer *buffer = attrib.buffer.get();
ASSERT(buffer || attrib.pointer);
ASSERT(attrib.enabled);
BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : NULL;
StaticVertexBufferInterface *staticBuffer = storage ? storage->getStaticVertexBuffer() : NULL;
VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
bool directStorage = vertexBuffer->directStoragePossible(attrib, currentValue);
unsigned int streamOffset = 0;
unsigned int outputElementSize = 0;
// Instanced vertices do not apply the 'start' offset
GLint firstVertexIndex = (instances > 0 && attrib.divisor > 0 ? 0 : start);
translated->vertexBuffer = vertexBuffer->getVertexBuffer();
if (directStorage)
{
outputElementSize = ComputeVertexAttributeStride(attrib);
streamOffset = static_cast<unsigned int>(attrib.offset + outputElementSize * firstVertexIndex);
translated->storage = storage;
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);
if (error.isError())
......@@ -320,8 +348,13 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribCurrentValueDa
int totalCount = ElementsInBuffer(attrib, storage->getSize());
int startIndex = attrib.offset / ComputeVertexAttributeStride(attrib);
error = staticBuffer->storeVertexAttributes(attrib, currentValue, -startIndex, totalCount,
0, &streamOffset);
error = staticBuffer->storeVertexAttributes(attrib,
currentValue,
-startIndex,
totalCount,
0,
&streamOffset,
sourceData);
if (error.isError())
{
return error;
......@@ -346,17 +379,21 @@ gl::Error VertexDataManager::storeAttribute(const gl::VertexAttribCurrentValueDa
return error;
}
error = mStreamingBuffer->storeVertexAttributes(attrib, currentValue, firstVertexIndex,
totalCount, instances, &streamOffset);
error = mStreamingBuffer->storeVertexAttributes(attrib,
currentValue,
firstVertexIndex,
totalCount,
instances,
&streamOffset,
sourceData);
if (error.isError())
{
return error;
}
}
translated->storage = directStorage ? storage : NULL;
translated->vertexBuffer = vertexBuffer->getVertexBuffer();
translated->serial = directStorage ? storage->getSerial() : vertexBuffer->getSerial();
translated->storage = nullptr;
translated->serial = vertexBuffer->getSerial();
translated->divisor = attrib.divisor;
translated->currentValueType = currentValue.Type;
......@@ -379,8 +416,9 @@ gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribCurrentValu
return error;
}
const uint8_t *sourceData = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
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())
{
return error;
......
......@@ -103,15 +103,19 @@ void VertexBuffer11::hintUnmapResource()
}
}
gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int offset)
gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int offset,
const uint8_t *sourceData)
{
if (!mBuffer)
{
return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized.");
}
gl::Buffer *buffer = attrib.buffer.get();
int inputStride = ComputeVertexAttributeStride(attrib);
// This will map the resource if it isn't already mapped.
......@@ -123,28 +127,7 @@ gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attri
uint8_t *output = mMappedResourceData + offset;
const uint8_t *input = NULL;
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);
}
const uint8_t *input = sourceData;
if (instances == 0 || attrib.divisor == 0)
{
......
......@@ -25,8 +25,13 @@ class VertexBuffer11 : public VertexBuffer
virtual gl::Error initialize(unsigned int size, bool dynamicUsage);
virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int offset);
gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
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;
......
......@@ -56,16 +56,19 @@ gl::Error VertexBuffer9::initialize(unsigned int size, bool dynamicUsage)
return gl::Error(GL_NO_ERROR);
}
gl::Error VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int offset)
gl::Error VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue,
GLint start,
GLsizei count,
GLsizei instances,
unsigned int offset,
const uint8_t *sourceData)
{
if (!mVertexBuffer)
{
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 elementSize = gl::ComputeVertexAttributeTypeSize(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);
}
const uint8_t *input = NULL;
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);
}
const uint8_t *input = sourceData;
if (instances == 0 || attrib.divisor == 0)
{
......
......@@ -23,8 +23,13 @@ class VertexBuffer9 : public VertexBuffer
virtual gl::Error initialize(unsigned int size, bool dynamicUsage);
virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int offset);
gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib,
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;
......
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