Commit 021bad40 by Jamie Madill Committed by Commit Bot

D3D: Add streaming buffer initialize.

This gives us better control over the error returned by the init routine. Also changes the streaming buffer in VertexDataManager to not be a unique_ptr. Bug: angleproject:2738 Change-Id: I3193840dfb71c7574adbe65bc5f9227f4add1fd3 Reviewed-on: https://chromium-review.googlesource.com/1151448Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 21e9baf7
...@@ -66,6 +66,7 @@ VertexBufferInterface::~VertexBufferInterface() ...@@ -66,6 +66,7 @@ VertexBufferInterface::~VertexBufferInterface()
if (mVertexBuffer) if (mVertexBuffer)
{ {
mVertexBuffer->release(); mVertexBuffer->release();
mVertexBuffer = nullptr;
} }
} }
...@@ -122,12 +123,23 @@ VertexBuffer *VertexBufferInterface::getVertexBuffer() const ...@@ -122,12 +123,23 @@ VertexBuffer *VertexBufferInterface::getVertexBuffer() const
} }
// StreamingVertexBufferInterface Implementation // StreamingVertexBufferInterface Implementation
StreamingVertexBufferInterface::StreamingVertexBufferInterface(BufferFactoryD3D *factory, StreamingVertexBufferInterface::StreamingVertexBufferInterface(BufferFactoryD3D *factory)
std::size_t initialSize)
: VertexBufferInterface(factory, true), mWritePosition(0), mReservedSpace(0) : VertexBufferInterface(factory, true), mWritePosition(0), mReservedSpace(0)
{ {
// TODO(jmadill): Make an initialize method that can return an error. }
ANGLE_SWALLOW_ERR(setBufferSize(static_cast<unsigned int>(initialSize)));
gl::Error StreamingVertexBufferInterface::initialize(std::size_t initialSize)
{
return setBufferSize(static_cast<unsigned int>(initialSize));
}
void StreamingVertexBufferInterface::reset()
{
if (mVertexBuffer)
{
mVertexBuffer->release();
mVertexBuffer = nullptr;
}
} }
StreamingVertexBufferInterface::~StreamingVertexBufferInterface() StreamingVertexBufferInterface::~StreamingVertexBufferInterface()
......
...@@ -103,9 +103,12 @@ class VertexBufferInterface : angle::NonCopyable ...@@ -103,9 +103,12 @@ class VertexBufferInterface : angle::NonCopyable
class StreamingVertexBufferInterface : public VertexBufferInterface class StreamingVertexBufferInterface : public VertexBufferInterface
{ {
public: public:
StreamingVertexBufferInterface(BufferFactoryD3D *factory, std::size_t initialSize); StreamingVertexBufferInterface(BufferFactoryD3D *factory);
~StreamingVertexBufferInterface() override; ~StreamingVertexBufferInterface() override;
gl::Error initialize(std::size_t initialSize);
void reset();
gl::Error storeDynamicAttribute(const gl::VertexAttribute &attrib, gl::Error storeDynamicAttribute(const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding, const gl::VertexBinding &binding,
GLenum currentValueType, GLenum currentValueType,
......
...@@ -197,7 +197,7 @@ VertexDataManager::CurrentValueState::~CurrentValueState() ...@@ -197,7 +197,7 @@ VertexDataManager::CurrentValueState::~CurrentValueState()
} }
VertexDataManager::VertexDataManager(BufferFactoryD3D *factory) VertexDataManager::VertexDataManager(BufferFactoryD3D *factory)
: mFactory(factory), mStreamingBuffer(), mCurrentValueCache(gl::MAX_VERTEX_ATTRIBS) : mFactory(factory), mStreamingBuffer(factory), mCurrentValueCache(gl::MAX_VERTEX_ATTRIBS)
{ {
} }
...@@ -207,10 +207,7 @@ VertexDataManager::~VertexDataManager() ...@@ -207,10 +207,7 @@ VertexDataManager::~VertexDataManager()
gl::Error VertexDataManager::initialize() gl::Error VertexDataManager::initialize()
{ {
mStreamingBuffer.reset( return mStreamingBuffer.initialize(INITIAL_STREAM_BUFFER_SIZE);
new StreamingVertexBufferInterface(mFactory, INITIAL_STREAM_BUFFER_SIZE));
ANGLE_TRY_ALLOCATION(mStreamingBuffer);
return gl::NoError();
} }
void VertexDataManager::deinitialize() void VertexDataManager::deinitialize()
...@@ -225,8 +222,6 @@ gl::Error VertexDataManager::prepareVertexData(const gl::Context *context, ...@@ -225,8 +222,6 @@ gl::Error VertexDataManager::prepareVertexData(const gl::Context *context,
std::vector<TranslatedAttribute> *translatedAttribs, std::vector<TranslatedAttribute> *translatedAttribs,
GLsizei instances) GLsizei instances)
{ {
ASSERT(mStreamingBuffer);
const gl::State &state = context->getGLState(); const gl::State &state = context->getGLState();
const gl::VertexArray *vertexArray = state.getVertexArray(); const gl::VertexArray *vertexArray = state.getVertexArray();
const auto &vertexAttributes = vertexArray->getVertexAttributes(); const auto &vertexAttributes = vertexArray->getVertexAttributes();
...@@ -410,7 +405,7 @@ gl::Error VertexDataManager::storeDynamicAttribs( ...@@ -410,7 +405,7 @@ gl::Error VertexDataManager::storeDynamicAttribs(
}; };
// Will trigger unmapping on return. // Will trigger unmapping on return.
StreamingBufferUnmapper localUnmapper(mStreamingBuffer.get()); StreamingBufferUnmapper localUnmapper(&mStreamingBuffer);
// Reserve the required space for the dynamic buffers. // Reserve the required space for the dynamic buffers.
for (auto attribIndex : dynamicAttribsMask) for (auto attribIndex : dynamicAttribsMask)
...@@ -455,7 +450,7 @@ void VertexDataManager::PromoteDynamicAttribs( ...@@ -455,7 +450,7 @@ void VertexDataManager::PromoteDynamicAttribs(
gl::Error VertexDataManager::reserveSpaceForAttrib(const TranslatedAttribute &translatedAttrib, gl::Error VertexDataManager::reserveSpaceForAttrib(const TranslatedAttribute &translatedAttrib,
GLint start, GLint start,
size_t count, size_t count,
GLsizei instances) const GLsizei instances)
{ {
ASSERT(translatedAttrib.attribute && translatedAttrib.binding); ASSERT(translatedAttrib.attribute && translatedAttrib.binding);
const auto &attrib = *translatedAttrib.attribute; const auto &attrib = *translatedAttrib.attribute;
...@@ -486,14 +481,14 @@ gl::Error VertexDataManager::reserveSpaceForAttrib(const TranslatedAttribute &tr ...@@ -486,14 +481,14 @@ gl::Error VertexDataManager::reserveSpaceForAttrib(const TranslatedAttribute &tr
return gl::InvalidOperation() << "Vertex buffer is not big enough for the draw call."; return gl::InvalidOperation() << "Vertex buffer is not big enough for the draw call.";
} }
} }
return mStreamingBuffer->reserveVertexSpace(attrib, binding, totalCount, instances); return mStreamingBuffer.reserveVertexSpace(attrib, binding, totalCount, instances);
} }
gl::Error VertexDataManager::storeDynamicAttrib(const gl::Context *context, gl::Error VertexDataManager::storeDynamicAttrib(const gl::Context *context,
TranslatedAttribute *translated, TranslatedAttribute *translated,
GLint start, GLint start,
size_t count, size_t count,
GLsizei instances) const GLsizei instances)
{ {
ASSERT(translated->attribute && translated->binding); ASSERT(translated->attribute && translated->binding);
const auto &attrib = *translated->attribute; const auto &attrib = *translated->attribute;
...@@ -531,11 +526,11 @@ gl::Error VertexDataManager::storeDynamicAttrib(const gl::Context *context, ...@@ -531,11 +526,11 @@ gl::Error VertexDataManager::storeDynamicAttrib(const gl::Context *context,
size_t totalCount = gl::ComputeVertexBindingElementCount(binding.getDivisor(), count, size_t totalCount = gl::ComputeVertexBindingElementCount(binding.getDivisor(), count,
static_cast<size_t>(instances)); static_cast<size_t>(instances));
ANGLE_TRY(mStreamingBuffer->storeDynamicAttribute( ANGLE_TRY(mStreamingBuffer.storeDynamicAttribute(
attrib, binding, translated->currentValueType, firstVertexIndex, attrib, binding, translated->currentValueType, firstVertexIndex,
static_cast<GLsizei>(totalCount), instances, &streamOffset, sourceData)); static_cast<GLsizei>(totalCount), instances, &streamOffset, sourceData));
VertexBuffer *vertexBuffer = mStreamingBuffer->getVertexBuffer(); VertexBuffer *vertexBuffer = mStreamingBuffer.getVertexBuffer();
translated->vertexBuffer.set(vertexBuffer); translated->vertexBuffer.set(vertexBuffer);
translated->serial = vertexBuffer->getSerial(); translated->serial = vertexBuffer->getSerial();
...@@ -554,7 +549,8 @@ gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribCurrentValu ...@@ -554,7 +549,8 @@ gl::Error VertexDataManager::storeCurrentValue(const gl::VertexAttribCurrentValu
if (!buffer) if (!buffer)
{ {
buffer.reset(new StreamingVertexBufferInterface(mFactory, CONSTANT_VERTEX_BUFFER_SIZE)); buffer.reset(new StreamingVertexBufferInterface(mFactory));
ANGLE_TRY(buffer->initialize(CONSTANT_VERTEX_BUFFER_SIZE));
} }
if (cachedState->data != currentValue) if (cachedState->data != currentValue)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
#include "libANGLE/Constants.h" #include "libANGLE/Constants.h"
#include "libANGLE/VertexAttribute.h" #include "libANGLE/VertexAttribute.h"
#include "libANGLE/renderer/d3d/VertexBuffer.h"
namespace gl namespace gl
{ {
...@@ -132,17 +133,17 @@ class VertexDataManager : angle::NonCopyable ...@@ -132,17 +133,17 @@ class VertexDataManager : angle::NonCopyable
gl::Error reserveSpaceForAttrib(const TranslatedAttribute &translatedAttrib, gl::Error reserveSpaceForAttrib(const TranslatedAttribute &translatedAttrib,
GLint start, GLint start,
size_t count, size_t count,
GLsizei instances) const; GLsizei instances);
gl::Error storeDynamicAttrib(const gl::Context *context, gl::Error storeDynamicAttrib(const gl::Context *context,
TranslatedAttribute *translated, TranslatedAttribute *translated,
GLint start, GLint start,
size_t count, size_t count,
GLsizei instances) const; GLsizei instances);
BufferFactoryD3D *const mFactory; BufferFactoryD3D *const mFactory;
std::unique_ptr<StreamingVertexBufferInterface> mStreamingBuffer; StreamingVertexBufferInterface mStreamingBuffer;
std::vector<CurrentValueState> mCurrentValueCache; std::vector<CurrentValueState> mCurrentValueCache;
gl::AttributesMask mDynamicAttribsMaskCache; gl::AttributesMask mDynamicAttribsMaskCache;
}; };
......
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