Commit dbfc6c63 by Jamie Madill

D3D: Make directStoragePossible a local static method.

This method doesn't need to call through to the VertexBuffer class, since in only really depends on vertex format caps. This makes the code local to the VertexDataManager, the only place it is used. Refactoring patch only, for VertexArray11 dirty bits. BUG=angleproject:1327 Change-Id: I315313a72a00186930d7f9b1091ccb91f37f9f96 Reviewed-on: https://chromium-review.googlesource.com/329740Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 7649fcaa
...@@ -68,6 +68,8 @@ class BufferD3D : public BufferImpl ...@@ -68,6 +68,8 @@ class BufferD3D : public BufferImpl
bool primitiveRestartEnabled, bool primitiveRestartEnabled,
gl::IndexRange *outRange) override; gl::IndexRange *outRange) override;
BufferFactoryD3D *getFactory() const { return mFactory; }
protected: protected:
void updateSerial(); void updateSerial();
void updateD3DBufferUsage(GLenum usage); void updateD3DBufferUsage(GLenum usage);
......
...@@ -8,12 +8,12 @@ ...@@ -8,12 +8,12 @@
// class with derivations, classes that perform graphics API agnostic vertex buffer operations. // class with derivations, classes that perform graphics API agnostic vertex buffer operations.
#include "libANGLE/renderer/d3d/VertexBuffer.h" #include "libANGLE/renderer/d3d/VertexBuffer.h"
#include "common/mathutil.h"
#include "libANGLE/renderer/d3d/BufferD3D.h" #include "libANGLE/renderer/d3d/BufferD3D.h"
#include "libANGLE/renderer/d3d/RendererD3D.h" #include "libANGLE/renderer/d3d/RendererD3D.h"
#include "libANGLE/VertexAttribute.h" #include "libANGLE/VertexAttribute.h"
#include "common/mathutil.h"
namespace rx namespace rx
{ {
...@@ -172,41 +172,6 @@ VertexBuffer* VertexBufferInterface::getVertexBuffer() const ...@@ -172,41 +172,6 @@ VertexBuffer* VertexBufferInterface::getVertexBuffer() const
return mVertexBuffer; return mVertexBuffer;
} }
bool VertexBufferInterface::directStoragePossible(const gl::VertexAttribute &attrib,
GLenum currentValueType) const
{
gl::Buffer *buffer = attrib.buffer.get();
BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : 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.type != GL_FLOAT)
{
gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib, currentValueType);
unsigned int outputElementSize;
getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize);
alignment = std::min<size_t>(outputElementSize, 4);
// TODO(jmadill): add VertexFormatCaps
requiresConversion = (mFactory->getVertexConversionType(vertexFormatType) & VERTEX_CONVERT_CPU) != 0;
}
bool isAligned = (static_cast<size_t>(ComputeVertexAttributeStride(attrib)) % alignment == 0) &&
(static_cast<size_t>(attrib.offset) % alignment == 0);
return !requiresConversion && isAligned;
}
StreamingVertexBufferInterface::StreamingVertexBufferInterface(BufferFactoryD3D *factory, std::size_t initialSize) StreamingVertexBufferInterface::StreamingVertexBufferInterface(BufferFactoryD3D *factory, std::size_t initialSize)
: VertexBufferInterface(factory, true) : VertexBufferInterface(factory, true)
{ {
...@@ -329,4 +294,4 @@ void StaticVertexBufferInterface::commit() ...@@ -329,4 +294,4 @@ void StaticVertexBufferInterface::commit()
mIsCommitted = true; mIsCommitted = true;
} }
} }
} } // namespace rx
...@@ -84,9 +84,6 @@ class VertexBufferInterface : angle::NonCopyable ...@@ -84,9 +84,6 @@ class VertexBufferInterface : angle::NonCopyable
unsigned int *outStreamOffset, unsigned int *outStreamOffset,
const uint8_t *sourceData); const uint8_t *sourceData);
bool directStoragePossible(const gl::VertexAttribute &attrib,
GLenum currentValueType) const;
VertexBuffer* getVertexBuffer() const; VertexBuffer* getVertexBuffer() const;
protected: protected:
......
...@@ -10,24 +10,30 @@ ...@@ -10,24 +10,30 @@
#include "libANGLE/renderer/d3d/VertexDataManager.h" #include "libANGLE/renderer/d3d/VertexDataManager.h"
#include "libANGLE/Buffer.h" #include "libANGLE/Buffer.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/Program.h" #include "libANGLE/Program.h"
#include "libANGLE/State.h" #include "libANGLE/State.h"
#include "libANGLE/VertexAttribute.h" #include "libANGLE/VertexAttribute.h"
#include "libANGLE/VertexArray.h" #include "libANGLE/VertexArray.h"
#include "libANGLE/renderer/d3d/BufferD3D.h" #include "libANGLE/renderer/d3d/BufferD3D.h"
#include "libANGLE/renderer/d3d/RendererD3D.h"
#include "libANGLE/renderer/d3d/VertexBuffer.h" #include "libANGLE/renderer/d3d/VertexBuffer.h"
namespace rx
{
namespace namespace
{ {
enum { INITIAL_STREAM_BUFFER_SIZE = 1024*1024 }; enum
// This has to be at least 4k or else it fails on ATI cards.
enum { CONSTANT_VERTEX_BUFFER_SIZE = 4096 };
}
namespace rx
{ {
INITIAL_STREAM_BUFFER_SIZE = 1024 * 1024
};
// This has to be at least 4k or else it fails on ATI cards.
enum
{
CONSTANT_VERTEX_BUFFER_SIZE = 4096
};
static int ElementsInBuffer(const gl::VertexAttribute &attrib, unsigned int size) int ElementsInBuffer(const gl::VertexAttribute &attrib, unsigned int size)
{ {
// Size cannot be larger than a GLsizei // Size cannot be larger than a GLsizei
if (size > static_cast<unsigned int>(std::numeric_limits<int>::max())) if (size > static_cast<unsigned int>(std::numeric_limits<int>::max()))
...@@ -41,6 +47,61 @@ static int ElementsInBuffer(const gl::VertexAttribute &attrib, unsigned int size ...@@ -41,6 +47,61 @@ static int ElementsInBuffer(const gl::VertexAttribute &attrib, unsigned int size
stride; stride;
} }
bool DirectStoragePossible(const gl::VertexAttribute &attrib)
{
// Current value attribs may not use direct storage.
if (!attrib.enabled)
{
return false;
}
gl::Buffer *buffer = attrib.buffer.get();
if (!buffer)
{
return false;
}
BufferD3D *bufferD3D = GetImplAs<BufferD3D>(buffer);
ASSERT(bufferD3D);
if (!bufferD3D->supportsDirectBinding())
{
return false;
}
StaticVertexBufferInterface *staticBuffer =
bufferD3D->getStaticVertexBuffer(attrib, D3D_BUFFER_CREATE_IF_NECESSARY);
// Dynamic buffers can not be stored directly.
if (!staticBuffer)
{
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.type != GL_FLOAT)
{
gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib);
unsigned int outputElementSize;
staticBuffer->getVertexBuffer()->getSpaceRequired(attrib, 1, 0, &outputElementSize);
alignment = std::min<size_t>(outputElementSize, 4);
// TODO(jmadill): add VertexFormatCaps
BufferFactoryD3D *factory = bufferD3D->getFactory();
requiresConversion =
(factory->getVertexConversionType(vertexFormatType) & VERTEX_CONVERT_CPU) != 0;
}
bool isAligned = (static_cast<size_t>(ComputeVertexAttributeStride(attrib)) % alignment == 0) &&
(static_cast<size_t>(attrib.offset) % alignment == 0);
return !requiresConversion && isAligned;
}
} // anonymous namespace
VertexDataManager::CurrentValueState::CurrentValueState() VertexDataManager::CurrentValueState::CurrentValueState()
: buffer(nullptr), : buffer(nullptr),
offset(0) offset(0)
...@@ -236,9 +297,8 @@ gl::Error VertexDataManager::reserveSpaceForAttrib(const TranslatedAttribute &tr ...@@ -236,9 +297,8 @@ gl::Error VertexDataManager::reserveSpaceForAttrib(const TranslatedAttribute &tr
StaticVertexBufferInterface *staticBuffer = StaticVertexBufferInterface *staticBuffer =
bufferImpl ? bufferImpl->getStaticVertexBuffer(attrib, D3D_BUFFER_CREATE_IF_NECESSARY) bufferImpl ? bufferImpl->getStaticVertexBuffer(attrib, D3D_BUFFER_CREATE_IF_NECESSARY)
: NULL; : NULL;
VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer);
if (!vertexBuffer->directStoragePossible(attrib, translatedAttrib.currentValueType)) if (!DirectStoragePossible(attrib))
{ {
if (staticBuffer) if (staticBuffer)
{ {
...@@ -283,24 +343,22 @@ gl::Error VertexDataManager::storeAttribute(TranslatedAttribute *translated, ...@@ -283,24 +343,22 @@ gl::Error VertexDataManager::storeAttribute(TranslatedAttribute *translated,
ASSERT(buffer || attrib.pointer); ASSERT(buffer || attrib.pointer);
ASSERT(attrib.enabled); ASSERT(attrib.enabled);
BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : NULL; BufferD3D *storage = buffer ? GetImplAs<BufferD3D>(buffer) : nullptr;
StaticVertexBufferInterface *staticBuffer = auto *staticBuffer =
storage ? storage->getStaticVertexBuffer(attrib, D3D_BUFFER_DO_NOT_CREATE) : NULL; storage ? storage->getStaticVertexBuffer(attrib, D3D_BUFFER_DO_NOT_CREATE) : nullptr;
VertexBufferInterface *vertexBuffer = staticBuffer ? staticBuffer : static_cast<VertexBufferInterface*>(mStreamingBuffer); auto *vertexBuffer =
bool directStorage = vertexBuffer->directStoragePossible(attrib, translated->currentValueType); staticBuffer ? staticBuffer : static_cast<VertexBufferInterface *>(mStreamingBuffer);
translated->vertexBuffer = vertexBuffer->getVertexBuffer();
// Instanced vertices do not apply the 'start' offset // Instanced vertices do not apply the 'start' offset
GLint firstVertexIndex = (attrib.divisor > 0 ? 0 : start); GLint firstVertexIndex = (attrib.divisor > 0 ? 0 : start);
translated->vertexBuffer = vertexBuffer->getVertexBuffer(); if (DirectStoragePossible(attrib))
if (directStorage)
{ {
translated->storage = storage; translated->storage = storage;
translated->serial = storage->getSerial(); translated->serial = storage->getSerial();
translated->stride = static_cast<unsigned int>(ComputeVertexAttributeStride(attrib)); translated->stride = static_cast<unsigned int>(ComputeVertexAttributeStride(attrib));
translated->offset = static_cast<unsigned int>(attrib.offset + translated->stride * firstVertexIndex); translated->offset = static_cast<unsigned int>(attrib.offset + translated->stride * firstVertexIndex);
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
...@@ -429,4 +487,4 @@ gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribCurrentValu ...@@ -429,4 +487,4 @@ gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribCurrentValu
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
} } // namespace rx
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