summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/angle/src/libGLESv2/renderer/VertexBuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/angle/src/libGLESv2/renderer/VertexBuffer.cpp')
-rw-r--r--chromium/third_party/angle/src/libGLESv2/renderer/VertexBuffer.cpp95
1 files changed, 49 insertions, 46 deletions
diff --git a/chromium/third_party/angle/src/libGLESv2/renderer/VertexBuffer.cpp b/chromium/third_party/angle/src/libGLESv2/renderer/VertexBuffer.cpp
index a073d95033f..8adfb5bfa74 100644
--- a/chromium/third_party/angle/src/libGLESv2/renderer/VertexBuffer.cpp
+++ b/chromium/third_party/angle/src/libGLESv2/renderer/VertexBuffer.cpp
@@ -10,7 +10,9 @@
#include "libGLESv2/renderer/VertexBuffer.h"
#include "libGLESv2/renderer/Renderer.h"
-#include "libGLESv2/Context.h"
+#include "libGLESv2/VertexAttribute.h"
+#include "libGLESv2/renderer/BufferStorage.h"
+#include "common/mathutil.h"
namespace rx
{
@@ -87,8 +89,8 @@ bool VertexBufferInterface::discard()
return mVertexBuffer->discard();
}
-bool VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, GLsizei instances,
- unsigned int *outStreamOffset)
+bool VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
+ GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset)
{
unsigned int spaceRequired;
if (!mVertexBuffer->getSpaceRequired(attrib, count, instances, &spaceRequired))
@@ -107,7 +109,7 @@ bool VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &att
}
mReservedSpace = 0;
- if (!mVertexBuffer->storeVertexAttributes(attrib, start, count, instances, mWritePosition))
+ if (!mVertexBuffer->storeVertexAttributes(attrib, currentValue, start, count, instances, mWritePosition))
{
return false;
}
@@ -119,33 +121,8 @@ bool VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &att
mWritePosition += spaceRequired;
- return true;
-}
-
-bool VertexBufferInterface::storeRawData(const void* data, unsigned int size, unsigned int *outStreamOffset)
-{
- if (mWritePosition + size < mWritePosition)
- {
- return false;
- }
-
- if (!reserveSpace(mReservedSpace))
- {
- return false;
- }
- mReservedSpace = 0;
-
- if (!mVertexBuffer->storeRawData(data, size, mWritePosition))
- {
- return false;
- }
-
- if (outStreamOffset)
- {
- *outStreamOffset = mWritePosition;
- }
-
- mWritePosition += size;
+ // Align to 16-byte boundary
+ mWritePosition = rx::roundUp(mWritePosition, 16u);
return true;
}
@@ -165,18 +142,10 @@ bool VertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &attrib
}
mReservedSpace += requiredSpace;
- return true;
-}
-bool VertexBufferInterface::reserveRawDataSpace(unsigned int size)
-{
- // Protect against integer overflow
- if (mReservedSpace + size < mReservedSpace)
- {
- return false;
- }
+ // Align to 16-byte boundary
+ mReservedSpace = rx::roundUp(mReservedSpace, 16u);
- mReservedSpace += size;
return true;
}
@@ -185,6 +154,39 @@ VertexBuffer* VertexBufferInterface::getVertexBuffer() const
return mVertexBuffer;
}
+bool VertexBufferInterface::directStoragePossible(const gl::VertexAttribute &attrib,
+ const gl::VertexAttribCurrentValueData &currentValue) const
+{
+ gl::Buffer *buffer = attrib.mBoundBuffer.get();
+ BufferStorage *storage = buffer ? buffer->getStorage() : NULL;
+
+ if (!storage || !storage->supportsDirectBinding())
+ {
+ return false;
+ }
+
+ // Alignment restrictions: In D3D, vertex data must be aligned to
+ // the format stride, or to a 4-byte boundary, whichever is smaller.
+ // (Undocumented, and experimentally confirmed)
+ size_t alignment = 4;
+ bool requiresConversion = false;
+
+ if (attrib.mType != GL_FLOAT)
+ {
+ gl::VertexFormat vertexFormat(attrib, currentValue.Type);
+
+ unsigned int outputElementSize;
+ getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize);
+ alignment = std::min<size_t>(outputElementSize, 4);
+
+ requiresConversion = (mRenderer->getVertexConversionType(vertexFormat) & VERTEX_CONVERT_CPU) != 0;
+ }
+
+ bool isAligned = (static_cast<size_t>(attrib.stride()) % alignment == 0) &&
+ (static_cast<size_t>(attrib.mOffset) % alignment == 0);
+
+ return !requiresConversion && isAligned;
+}
StreamingVertexBufferInterface::StreamingVertexBufferInterface(rx::Renderer *renderer, std::size_t initialSize) : VertexBufferInterface(renderer, true)
{
@@ -231,7 +233,8 @@ bool StaticVertexBufferInterface::lookupAttribute(const gl::VertexAttribute &att
if (mCache[element].type == attribute.mType &&
mCache[element].size == attribute.mSize &&
mCache[element].stride == attribute.stride() &&
- mCache[element].normalized == attribute.mNormalized)
+ mCache[element].normalized == attribute.mNormalized &&
+ mCache[element].pureInteger == attribute.mPureInteger)
{
if (mCache[element].attributeOffset == attribute.mOffset % attribute.stride())
{
@@ -266,14 +269,14 @@ bool StaticVertexBufferInterface::reserveSpace(unsigned int size)
}
}
-bool StaticVertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, GLint start, GLsizei count, GLsizei instances,
- unsigned int *outStreamOffset)
+bool StaticVertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
+ GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset)
{
unsigned int streamOffset;
- if (VertexBufferInterface::storeVertexAttributes(attrib, start, count, instances, &streamOffset))
+ if (VertexBufferInterface::storeVertexAttributes(attrib, currentValue, start, count, instances, &streamOffset))
{
int attributeOffset = attrib.mOffset % attrib.stride();
- VertexElement element = { attrib.mType, attrib.mSize, attrib.stride(), attrib.mNormalized, attributeOffset, streamOffset };
+ VertexElement element = { attrib.mType, attrib.mSize, attrib.stride(), attrib.mNormalized, attrib.mPureInteger, attributeOffset, streamOffset };
mCache.push_back(element);
if (outStreamOffset)