Commit f7100b98 by Geoff Lang

Updated the vertex buffer classes to use Error objects.

BUG=angle:520 Change-Id: Id003e66b2acbf37dbbe66aaca2fa336c3c884be2 Reviewed-on: https://chromium-review.googlesource.com/217102Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent d5a796ca
...@@ -1683,10 +1683,10 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan ...@@ -1683,10 +1683,10 @@ void Context::drawArrays(GLenum mode, GLint first, GLsizei count, GLsizei instan
applyRenderTarget(mode, false); applyRenderTarget(mode, false);
applyState(mode); applyState(mode);
GLenum err = mRenderer->applyVertexBuffer(programBinary, mState.getVertexArray()->getVertexAttributes(), mState.getVertexAttribCurrentValues(), first, count, instances); Error error = mRenderer->applyVertexBuffer(programBinary, mState.getVertexArray()->getVertexAttributes(), mState.getVertexAttribCurrentValues(), first, count, instances);
if (err != GL_NO_ERROR) if (error.isError())
{ {
return gl::error(err); return gl::error(error.getCode());
} }
bool transformFeedbackActive = applyTransformFeedbackBuffers(); bool transformFeedbackActive = applyTransformFeedbackBuffers();
...@@ -1740,12 +1740,12 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type, ...@@ -1740,12 +1740,12 @@ void Context::drawElements(GLenum mode, GLsizei count, GLenum type,
} }
GLsizei vertexCount = indexInfo.indexRange.length() + 1; GLsizei vertexCount = indexInfo.indexRange.length() + 1;
GLenum err = mRenderer->applyVertexBuffer(programBinary, vao->getVertexAttributes(), error = mRenderer->applyVertexBuffer(programBinary, vao->getVertexAttributes(),
mState.getVertexAttribCurrentValues(), mState.getVertexAttribCurrentValues(),
indexInfo.indexRange.start, vertexCount, instances); indexInfo.indexRange.start, vertexCount, instances);
if (err != GL_NO_ERROR) if (error.isError())
{ {
return gl::error(err); return gl::error(error.getCode());
} }
bool transformFeedbackActive = applyTransformFeedbackBuffers(); bool transformFeedbackActive = applyTransformFeedbackBuffers();
......
...@@ -133,8 +133,8 @@ class Renderer ...@@ -133,8 +133,8 @@ class Renderer
bool rasterizerDiscard, bool transformFeedbackActive) = 0; bool rasterizerDiscard, bool transformFeedbackActive) = 0;
virtual void applyUniforms(const gl::ProgramBinary &programBinary) = 0; virtual void applyUniforms(const gl::ProgramBinary &programBinary) = 0;
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0; virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[], virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances) = 0; GLint first, GLsizei count, GLsizei instances) = 0;
virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0; virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]) = 0; virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]) = 0;
......
...@@ -62,7 +62,7 @@ unsigned int VertexBufferInterface::getBufferSize() const ...@@ -62,7 +62,7 @@ unsigned int VertexBufferInterface::getBufferSize() const
return mVertexBuffer->getBufferSize(); return mVertexBuffer->getBufferSize();
} }
bool VertexBufferInterface::setBufferSize(unsigned int size) gl::Error VertexBufferInterface::setBufferSize(unsigned int size)
{ {
if (mVertexBuffer->getBufferSize() == 0) if (mVertexBuffer->getBufferSize() == 0)
{ {
...@@ -84,34 +84,39 @@ void VertexBufferInterface::setWritePosition(unsigned int writePosition) ...@@ -84,34 +84,39 @@ void VertexBufferInterface::setWritePosition(unsigned int writePosition)
mWritePosition = writePosition; mWritePosition = writePosition;
} }
bool VertexBufferInterface::discard() gl::Error VertexBufferInterface::discard()
{ {
return mVertexBuffer->discard(); return mVertexBuffer->discard();
} }
bool VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, gl::Error VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset) GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset)
{ {
gl::Error error(GL_NO_ERROR);
unsigned int spaceRequired; unsigned int spaceRequired;
if (!mVertexBuffer->getSpaceRequired(attrib, count, instances, &spaceRequired)) error = mVertexBuffer->getSpaceRequired(attrib, count, instances, &spaceRequired);
if (error.isError())
{ {
return false; return error;
} }
if (mWritePosition + spaceRequired < mWritePosition) if (mWritePosition + spaceRequired < mWritePosition)
{ {
return false; return gl::Error(GL_OUT_OF_MEMORY, "Internal error, new vertex buffer write position would overflow.");
} }
if (!reserveSpace(mReservedSpace)) error = reserveSpace(mReservedSpace);
if (error.isError())
{ {
return false; return error;
} }
mReservedSpace = 0; mReservedSpace = 0;
if (!mVertexBuffer->storeVertexAttributes(attrib, currentValue, start, count, instances, mWritePosition)) error = mVertexBuffer->storeVertexAttributes(attrib, currentValue, start, count, instances, mWritePosition);
if (error.isError())
{ {
return false; return error;
} }
if (outStreamOffset) if (outStreamOffset)
...@@ -124,21 +129,25 @@ bool VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &att ...@@ -124,21 +129,25 @@ bool VertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &att
// Align to 16-byte boundary // Align to 16-byte boundary
mWritePosition = rx::roundUp(mWritePosition, 16u); mWritePosition = rx::roundUp(mWritePosition, 16u);
return true; return gl::Error(GL_NO_ERROR);
} }
bool VertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances) gl::Error VertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances)
{ {
gl::Error error(GL_NO_ERROR);
unsigned int requiredSpace; unsigned int requiredSpace;
if (!mVertexBuffer->getSpaceRequired(attrib, count, instances, &requiredSpace)) error = mVertexBuffer->getSpaceRequired(attrib, count, instances, &requiredSpace);
if (error.isError())
{ {
return false; return error;
} }
// Protect against integer overflow // Protect against integer overflow
if (mReservedSpace + requiredSpace < mReservedSpace) if (mReservedSpace + requiredSpace < mReservedSpace)
{ {
return false; return gl::Error(GL_OUT_OF_MEMORY, "Unable to reserve %u extra bytes in internal vertex buffer, "
"it would result in an overflow.", requiredSpace);
} }
mReservedSpace += requiredSpace; mReservedSpace += requiredSpace;
...@@ -146,7 +155,7 @@ bool VertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &attrib ...@@ -146,7 +155,7 @@ bool VertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &attrib
// Align to 16-byte boundary // Align to 16-byte boundary
mReservedSpace = rx::roundUp(mReservedSpace, 16u); mReservedSpace = rx::roundUp(mReservedSpace, 16u);
return true; return gl::Error(GL_NO_ERROR);
} }
VertexBuffer* VertexBufferInterface::getVertexBuffer() const VertexBuffer* VertexBufferInterface::getVertexBuffer() const
...@@ -197,25 +206,29 @@ StreamingVertexBufferInterface::~StreamingVertexBufferInterface() ...@@ -197,25 +206,29 @@ StreamingVertexBufferInterface::~StreamingVertexBufferInterface()
{ {
} }
bool StreamingVertexBufferInterface::reserveSpace(unsigned int size) gl::Error StreamingVertexBufferInterface::reserveSpace(unsigned int size)
{ {
bool result = true;
unsigned int curBufferSize = getBufferSize(); unsigned int curBufferSize = getBufferSize();
if (size > curBufferSize) if (size > curBufferSize)
{ {
result = setBufferSize(std::max(size, 3 * curBufferSize / 2)); gl::Error error = setBufferSize(std::max(size, 3 * curBufferSize / 2));
if (error.isError())
{
return error;
}
setWritePosition(0); setWritePosition(0);
} }
else if (getWritePosition() + size > curBufferSize) else if (getWritePosition() + size > curBufferSize)
{ {
if (!discard()) gl::Error error = discard();
if (error.isError())
{ {
return false; return error;
} }
setWritePosition(0); setWritePosition(0);
} }
return result; return gl::Error(GL_NO_ERROR);
} }
StaticVertexBufferInterface::StaticVertexBufferInterface(rx::Renderer *renderer) : VertexBufferInterface(renderer, false) StaticVertexBufferInterface::StaticVertexBufferInterface(rx::Renderer *renderer) : VertexBufferInterface(renderer, false)
...@@ -251,46 +264,44 @@ bool StaticVertexBufferInterface::lookupAttribute(const gl::VertexAttribute &att ...@@ -251,46 +264,44 @@ bool StaticVertexBufferInterface::lookupAttribute(const gl::VertexAttribute &att
return false; return false;
} }
bool StaticVertexBufferInterface::reserveSpace(unsigned int size) gl::Error StaticVertexBufferInterface::reserveSpace(unsigned int size)
{ {
unsigned int curSize = getBufferSize(); unsigned int curSize = getBufferSize();
if (curSize == 0) if (curSize == 0)
{ {
setBufferSize(size); return setBufferSize(size);
return true;
} }
else if (curSize >= size) else if (curSize >= size)
{ {
return true; return gl::Error(GL_NO_ERROR);
} }
else else
{ {
UNREACHABLE(); // Static vertex buffers can't be resized UNREACHABLE();
return false; return gl::Error(GL_INVALID_OPERATION, "Internal error, Static vertex buffers can't be resized.");
} }
} }
bool StaticVertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, gl::Error StaticVertexBufferInterface::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset) GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset)
{ {
unsigned int streamOffset; unsigned int streamOffset;
if (VertexBufferInterface::storeVertexAttributes(attrib, currentValue, start, count, instances, &streamOffset)) gl::Error error = VertexBufferInterface::storeVertexAttributes(attrib, currentValue, start, count, instances, &streamOffset);
if (error.isError())
{ {
size_t attributeOffset = static_cast<size_t>(attrib.offset) % ComputeVertexAttributeStride(attrib); return error;
VertexElement element = { attrib.type, attrib.size, ComputeVertexAttributeStride(attrib), attrib.normalized, attrib.pureInteger, attributeOffset, streamOffset }; }
mCache.push_back(element);
if (outStreamOffset) size_t attributeOffset = static_cast<size_t>(attrib.offset) % ComputeVertexAttributeStride(attrib);
{ VertexElement element = { attrib.type, attrib.size, ComputeVertexAttributeStride(attrib), attrib.normalized, attrib.pureInteger, attributeOffset, streamOffset };
*outStreamOffset = streamOffset; mCache.push_back(element);
}
return true; if (outStreamOffset)
}
else
{ {
return false; *outStreamOffset = streamOffset;
} }
return gl::Error(GL_NO_ERROR);
} }
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define LIBGLESV2_RENDERER_VERTEXBUFFER_H_ #define LIBGLESV2_RENDERER_VERTEXBUFFER_H_
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libGLESv2/Error.h"
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
...@@ -33,16 +34,16 @@ class VertexBuffer ...@@ -33,16 +34,16 @@ class VertexBuffer
VertexBuffer(); VertexBuffer();
virtual ~VertexBuffer(); virtual ~VertexBuffer();
virtual bool initialize(unsigned int size, bool dynamicUsage) = 0; virtual gl::Error initialize(unsigned int size, bool dynamicUsage) = 0;
virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int offset) = 0; GLint start, GLsizei count, GLsizei instances, unsigned int offset) = 0;
virtual bool 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;
virtual unsigned int getBufferSize() const = 0; virtual unsigned int getBufferSize() const = 0;
virtual bool setBufferSize(unsigned int size) = 0; virtual gl::Error setBufferSize(unsigned int size) = 0;
virtual bool discard() = 0; virtual gl::Error discard() = 0;
unsigned int getSerial() const; unsigned int getSerial() const;
...@@ -62,14 +63,14 @@ class VertexBufferInterface ...@@ -62,14 +63,14 @@ class VertexBufferInterface
VertexBufferInterface(rx::Renderer *renderer, bool dynamic); VertexBufferInterface(rx::Renderer *renderer, bool dynamic);
virtual ~VertexBufferInterface(); virtual ~VertexBufferInterface();
bool reserveVertexSpace(const gl::VertexAttribute &attribute, GLsizei count, GLsizei instances); gl::Error reserveVertexSpace(const gl::VertexAttribute &attribute, GLsizei count, GLsizei instances);
unsigned int getBufferSize() const; unsigned int getBufferSize() const;
unsigned int getSerial() const; unsigned int getSerial() const;
virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset); GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset);
bool directStoragePossible(const gl::VertexAttribute &attrib, bool directStoragePossible(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue) const; const gl::VertexAttribCurrentValueData &currentValue) const;
...@@ -77,14 +78,14 @@ class VertexBufferInterface ...@@ -77,14 +78,14 @@ class VertexBufferInterface
VertexBuffer* getVertexBuffer() const; VertexBuffer* getVertexBuffer() const;
protected: protected:
virtual bool reserveSpace(unsigned int size) = 0; virtual gl::Error reserveSpace(unsigned int size) = 0;
unsigned int getWritePosition() const; unsigned int getWritePosition() const;
void setWritePosition(unsigned int writePosition); void setWritePosition(unsigned int writePosition);
bool discard(); gl::Error discard();
bool setBufferSize(unsigned int size); gl::Error setBufferSize(unsigned int size);
private: private:
DISALLOW_COPY_AND_ASSIGN(VertexBufferInterface); DISALLOW_COPY_AND_ASSIGN(VertexBufferInterface);
...@@ -105,7 +106,7 @@ class StreamingVertexBufferInterface : public VertexBufferInterface ...@@ -105,7 +106,7 @@ class StreamingVertexBufferInterface : public VertexBufferInterface
~StreamingVertexBufferInterface(); ~StreamingVertexBufferInterface();
protected: protected:
bool reserveSpace(unsigned int size); gl::Error reserveSpace(unsigned int size);
}; };
class StaticVertexBufferInterface : public VertexBufferInterface class StaticVertexBufferInterface : public VertexBufferInterface
...@@ -114,13 +115,13 @@ class StaticVertexBufferInterface : public VertexBufferInterface ...@@ -114,13 +115,13 @@ class StaticVertexBufferInterface : public VertexBufferInterface
explicit StaticVertexBufferInterface(rx::Renderer *renderer); explicit StaticVertexBufferInterface(rx::Renderer *renderer);
~StaticVertexBufferInterface(); ~StaticVertexBufferInterface();
bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset); GLint start, GLsizei count, GLsizei instances, unsigned int *outStreamOffset);
bool lookupAttribute(const gl::VertexAttribute &attribute, unsigned int* outStreamFffset); bool lookupAttribute(const gl::VertexAttribute &attribute, unsigned int* outStreamFffset);
protected: protected:
bool reserveSpace(unsigned int size); gl::Error reserveSpace(unsigned int size);
private: private:
struct VertexElement struct VertexElement
......
...@@ -52,33 +52,33 @@ class VertexDataManager ...@@ -52,33 +52,33 @@ class VertexDataManager
VertexDataManager(rx::Renderer *renderer); VertexDataManager(rx::Renderer *renderer);
virtual ~VertexDataManager(); virtual ~VertexDataManager();
GLenum prepareVertexData(const gl::VertexAttribute attribs[], const gl::VertexAttribCurrentValueData currentValues[], gl::Error prepareVertexData(const gl::VertexAttribute attribs[], const gl::VertexAttribCurrentValueData currentValues[],
gl::ProgramBinary *programBinary, GLint start, GLsizei count, TranslatedAttribute *outAttribs, GLsizei instances); gl::ProgramBinary *programBinary, GLint start, GLsizei count, TranslatedAttribute *outAttribs, GLsizei instances);
private: private:
DISALLOW_COPY_AND_ASSIGN(VertexDataManager); DISALLOW_COPY_AND_ASSIGN(VertexDataManager);
bool reserveSpaceForAttrib(const gl::VertexAttribute &attrib, gl::Error reserveSpaceForAttrib(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue, const gl::VertexAttribCurrentValueData &currentValue,
GLsizei count, GLsizei count,
GLsizei instances) const; GLsizei instances) const;
void invalidateMatchingStaticData(const gl::VertexAttribute &attrib, void invalidateMatchingStaticData(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue) const; const gl::VertexAttribCurrentValueData &currentValue) const;
GLenum storeAttribute(const gl::VertexAttribute &attrib, gl::Error storeAttribute(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated,
GLint start,
GLsizei count,
GLsizei instances);
GLenum storeCurrentValue(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue, const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated, TranslatedAttribute *translated,
gl::VertexAttribCurrentValueData *cachedValue, GLint start,
size_t *cachedOffset, GLsizei count,
StreamingVertexBufferInterface *buffer); GLsizei instances);
gl::Error storeCurrentValue(const gl::VertexAttribute &attrib,
const gl::VertexAttribCurrentValueData &currentValue,
TranslatedAttribute *translated,
gl::VertexAttribCurrentValueData *cachedValue,
size_t *cachedOffset,
StreamingVertexBufferInterface *buffer);
rx::Renderer *const mRenderer; rx::Renderer *const mRenderer;
......
...@@ -85,16 +85,15 @@ void InputLayoutCache::markDirty() ...@@ -85,16 +85,15 @@ void InputLayoutCache::markDirty()
} }
} }
GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS], gl::Error InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
gl::ProgramBinary *programBinary) gl::ProgramBinary *programBinary)
{ {
int sortedSemanticIndices[gl::MAX_VERTEX_ATTRIBS]; int sortedSemanticIndices[gl::MAX_VERTEX_ATTRIBS];
programBinary->sortAttributesByLayout(attributes, sortedSemanticIndices); programBinary->sortAttributesByLayout(attributes, sortedSemanticIndices);
if (!mDevice || !mDeviceContext) if (!mDevice || !mDeviceContext)
{ {
ERR("InputLayoutCache is not initialized."); return gl::Error(GL_OUT_OF_MEMORY, "Internal input layout cache is not initialized.");
return GL_INVALID_OPERATION;
} }
InputLayoutKey ilKey = { 0 }; InputLayoutKey ilKey = { 0 };
...@@ -149,8 +148,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M ...@@ -149,8 +148,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
HRESULT result = mDevice->CreateInputLayout(descs, ilKey.elementCount, shader->getFunction(), shader->getLength(), &inputLayout); HRESULT result = mDevice->CreateInputLayout(descs, ilKey.elementCount, shader->getFunction(), shader->getLength(), &inputLayout);
if (FAILED(result)) if (FAILED(result))
{ {
ERR("Failed to crate input layout, result: 0x%08x", result); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal input layout, HRESULT: 0x%08x", result);
return GL_INVALID_OPERATION;
} }
if (mInputLayoutMap.size() >= kMaxInputLayouts) if (mInputLayoutMap.size() >= kMaxInputLayouts)
...@@ -222,7 +220,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M ...@@ -222,7 +220,7 @@ GLenum InputLayoutCache::applyVertexBuffers(TranslatedAttribute attributes[gl::M
mCurrentVertexStrides + minDiff, mCurrentVertexOffsets + minDiff); mCurrentVertexStrides + minDiff, mCurrentVertexOffsets + minDiff);
} }
return GL_NO_ERROR; return gl::Error(GL_NO_ERROR);
} }
std::size_t InputLayoutCache::hashInputLayout(const InputLayoutKey &inputLayout) std::size_t InputLayoutCache::hashInputLayout(const InputLayoutKey &inputLayout)
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_ #define LIBGLESV2_RENDERER_INPUTLAYOUTCACHE_H_
#include "libGLESv2/Constants.h" #include "libGLESv2/Constants.h"
#include "libGLESv2/Error.h"
#include "common/angleutils.h" #include "common/angleutils.h"
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
...@@ -37,8 +38,8 @@ class InputLayoutCache ...@@ -37,8 +38,8 @@ class InputLayoutCache
void clear(); void clear();
void markDirty(); void markDirty();
GLenum applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS], gl::Error applyVertexBuffers(TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS],
gl::ProgramBinary *programBinary); gl::ProgramBinary *programBinary);
private: private:
DISALLOW_COPY_AND_ASSIGN(InputLayoutCache); DISALLOW_COPY_AND_ASSIGN(InputLayoutCache);
......
...@@ -933,14 +933,14 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -933,14 +933,14 @@ bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer)
return true; return true;
} }
GLenum Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[], gl::Error Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances) GLint first, GLsizei count, GLsizei instances)
{ {
TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS]; TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS];
GLenum err = mVertexDataManager->prepareVertexData(vertexAttributes, currentValues, programBinary, first, count, attributes, instances); gl::Error error = mVertexDataManager->prepareVertexData(vertexAttributes, currentValues, programBinary, first, count, attributes, instances);
if (err != GL_NO_ERROR) if (error.isError())
{ {
return err; return error;
} }
return mInputLayoutCache.applyVertexBuffers(attributes, programBinary); return mInputLayoutCache.applyVertexBuffers(attributes, programBinary);
......
...@@ -80,8 +80,8 @@ class Renderer11 : public Renderer ...@@ -80,8 +80,8 @@ class Renderer11 : public Renderer
virtual void applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer, virtual void applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
bool rasterizerDiscard, bool transformFeedbackActive); bool rasterizerDiscard, bool transformFeedbackActive);
virtual void applyUniforms(const gl::ProgramBinary &programBinary); virtual void applyUniforms(const gl::ProgramBinary &programBinary);
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[], virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances); GLint first, GLsizei count, GLsizei instances);
virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo); virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]); virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]);
......
...@@ -28,7 +28,7 @@ VertexBuffer11::~VertexBuffer11() ...@@ -28,7 +28,7 @@ VertexBuffer11::~VertexBuffer11()
SafeRelease(mBuffer); SafeRelease(mBuffer);
} }
bool VertexBuffer11::initialize(unsigned int size, bool dynamicUsage) gl::Error VertexBuffer11::initialize(unsigned int size, bool dynamicUsage)
{ {
SafeRelease(mBuffer); SafeRelease(mBuffer);
...@@ -49,13 +49,14 @@ bool VertexBuffer11::initialize(unsigned int size, bool dynamicUsage) ...@@ -49,13 +49,14 @@ bool VertexBuffer11::initialize(unsigned int size, bool dynamicUsage)
HRESULT result = dxDevice->CreateBuffer(&bufferDesc, NULL, &mBuffer); HRESULT result = dxDevice->CreateBuffer(&bufferDesc, NULL, &mBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
return false; return gl::Error(GL_OUT_OF_MEMORY, "Failed to allocate internal vertex buffer of size, %lu.", size);
} }
} }
mBufferSize = size; mBufferSize = size;
mDynamicUsage = dynamicUsage; mDynamicUsage = dynamicUsage;
return true;
return gl::Error(GL_NO_ERROR);
} }
VertexBuffer11 *VertexBuffer11::makeVertexBuffer11(VertexBuffer *vetexBuffer) VertexBuffer11 *VertexBuffer11::makeVertexBuffer11(VertexBuffer *vetexBuffer)
...@@ -64,66 +65,62 @@ VertexBuffer11 *VertexBuffer11::makeVertexBuffer11(VertexBuffer *vetexBuffer) ...@@ -64,66 +65,62 @@ VertexBuffer11 *VertexBuffer11::makeVertexBuffer11(VertexBuffer *vetexBuffer)
return static_cast<VertexBuffer11*>(vetexBuffer); return static_cast<VertexBuffer11*>(vetexBuffer);
} }
bool VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int offset) GLint start, GLsizei count, GLsizei instances, unsigned int offset)
{ {
if (mBuffer) if (!mBuffer)
{ {
gl::Buffer *buffer = attrib.buffer.get(); return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized.");
int inputStride = ComputeVertexAttributeStride(attrib); }
ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext();
D3D11_MAPPED_SUBRESOURCE mappedResource; gl::Buffer *buffer = attrib.buffer.get();
HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource); int inputStride = ComputeVertexAttributeStride(attrib);
if (FAILED(result)) ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext();
{
ERR("Vertex buffer map failed with error 0x%08x", result);
return false;
}
uint8_t* output = reinterpret_cast<uint8_t*>(mappedResource.pData) + offset; D3D11_MAPPED_SUBRESOURCE mappedResource;
HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource);
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal vertex buffer, HRESULT: 0x%08x.", result);
}
uint8_t *output = reinterpret_cast<uint8_t*>(mappedResource.pData) + offset;
const uint8_t *input = NULL; const uint8_t *input = NULL;
if (attrib.enabled) if (attrib.enabled)
{
if (buffer)
{ {
if (buffer) Buffer11 *storage = Buffer11::makeBuffer11(buffer->getImplementation());
{ input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset);
Buffer11 *storage = Buffer11::makeBuffer11(buffer->getImplementation());
input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset);
}
else
{
input = static_cast<const uint8_t*>(attrib.pointer);
}
} }
else else
{ {
input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues); input = static_cast<const uint8_t*>(attrib.pointer);
} }
if (instances == 0 || attrib.divisor == 0)
{
input += inputStride * start;
}
gl::VertexFormat vertexFormat(attrib, currentValue.Type);
const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormat);
ASSERT(vertexFormatInfo.copyFunction != NULL);
vertexFormatInfo.copyFunction(input, inputStride, count, output);
dxContext->Unmap(mBuffer, 0);
return true;
} }
else else
{ {
ERR("Vertex buffer not initialized."); input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
return false;
} }
if (instances == 0 || attrib.divisor == 0)
{
input += inputStride * start;
}
gl::VertexFormat vertexFormat(attrib, currentValue.Type);
const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormat);
ASSERT(vertexFormatInfo.copyFunction != NULL);
vertexFormatInfo.copyFunction(input, inputStride, count, output);
dxContext->Unmap(mBuffer, 0);
return gl::Error(GL_NO_ERROR);
} }
bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, gl::Error VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count,
GLsizei instances, unsigned int *outSpaceRequired) const GLsizei instances, unsigned int *outSpaceRequired) const
{ {
unsigned int elementCount = 0; unsigned int elementCount = 0;
if (attrib.enabled) if (attrib.enabled)
...@@ -148,11 +145,11 @@ bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei ...@@ -148,11 +145,11 @@ bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei
{ {
*outSpaceRequired = elementSize * elementCount; *outSpaceRequired = elementSize * elementCount;
} }
return true; return gl::Error(GL_NO_ERROR);
} }
else else
{ {
return false; return gl::Error(GL_OUT_OF_MEMORY, "New vertex buffer size would result in an overflow.");
} }
} }
else else
...@@ -162,7 +159,7 @@ bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei ...@@ -162,7 +159,7 @@ bool VertexBuffer11::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei
{ {
*outSpaceRequired = elementSize * 4; *outSpaceRequired = elementSize * 4;
} }
return true; return gl::Error(GL_NO_ERROR);
} }
} }
...@@ -171,7 +168,7 @@ unsigned int VertexBuffer11::getBufferSize() const ...@@ -171,7 +168,7 @@ unsigned int VertexBuffer11::getBufferSize() const
return mBufferSize; return mBufferSize;
} }
bool VertexBuffer11::setBufferSize(unsigned int size) gl::Error VertexBuffer11::setBufferSize(unsigned int size)
{ {
if (size > mBufferSize) if (size > mBufferSize)
{ {
...@@ -179,33 +176,29 @@ bool VertexBuffer11::setBufferSize(unsigned int size) ...@@ -179,33 +176,29 @@ bool VertexBuffer11::setBufferSize(unsigned int size)
} }
else else
{ {
return true; return gl::Error(GL_NO_ERROR);
} }
} }
bool VertexBuffer11::discard() gl::Error VertexBuffer11::discard()
{ {
if (mBuffer) if (!mBuffer)
{ {
ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext(); return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized.");
}
D3D11_MAPPED_SUBRESOURCE mappedResource;
HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
{
ERR("Vertex buffer map failed with error 0x%08x", result);
return false;
}
dxContext->Unmap(mBuffer, 0); ID3D11DeviceContext *dxContext = mRenderer->getDeviceContext();
return true; D3D11_MAPPED_SUBRESOURCE mappedResource;
} HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
else if (FAILED(result))
{ {
ERR("Vertex buffer not initialized."); return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal buffer for discarding, HRESULT: 0x%08x", result);
return false;
} }
dxContext->Unmap(mBuffer, 0);
return gl::Error(GL_NO_ERROR);
} }
ID3D11Buffer *VertexBuffer11::getBuffer() const ID3D11Buffer *VertexBuffer11::getBuffer() const
......
...@@ -21,19 +21,19 @@ class VertexBuffer11 : public VertexBuffer ...@@ -21,19 +21,19 @@ class VertexBuffer11 : public VertexBuffer
explicit VertexBuffer11(rx::Renderer11 *const renderer); explicit VertexBuffer11(rx::Renderer11 *const renderer);
virtual ~VertexBuffer11(); virtual ~VertexBuffer11();
virtual bool initialize(unsigned int size, bool dynamicUsage); virtual gl::Error initialize(unsigned int size, bool dynamicUsage);
static VertexBuffer11 *makeVertexBuffer11(VertexBuffer *vetexBuffer); static VertexBuffer11 *makeVertexBuffer11(VertexBuffer *vetexBuffer);
virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int offset); GLint start, GLsizei count, GLsizei instances, unsigned int offset);
virtual bool 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;
virtual unsigned int getBufferSize() const; virtual unsigned int getBufferSize() const;
virtual bool setBufferSize(unsigned int size); virtual gl::Error setBufferSize(unsigned int size);
virtual bool discard(); virtual gl::Error discard();
ID3D11Buffer *getBuffer() const; ID3D11Buffer *getBuffer() const;
......
...@@ -1260,14 +1260,14 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer) ...@@ -1260,14 +1260,14 @@ bool Renderer9::applyRenderTarget(gl::Framebuffer *framebuffer)
return true; return true;
} }
GLenum Renderer9::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[], gl::Error Renderer9::applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances) GLint first, GLsizei count, GLsizei instances)
{ {
TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS]; TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS];
GLenum err = mVertexDataManager->prepareVertexData(vertexAttributes, currentValues, programBinary, first, count, attributes, instances); gl::Error error = mVertexDataManager->prepareVertexData(vertexAttributes, currentValues, programBinary, first, count, attributes, instances);
if (err != GL_NO_ERROR) if (error.isError())
{ {
return err; return error;
} }
return mVertexDeclarationCache.applyDeclaration(mDevice, attributes, programBinary, instances, &mRepeatDraw); return mVertexDeclarationCache.applyDeclaration(mDevice, attributes, programBinary, instances, &mRepeatDraw);
......
...@@ -81,8 +81,8 @@ class Renderer9 : public Renderer ...@@ -81,8 +81,8 @@ class Renderer9 : public Renderer
bool rasterizerDiscard, bool transformFeedbackActive); bool rasterizerDiscard, bool transformFeedbackActive);
virtual void applyUniforms(const gl::ProgramBinary &programBinary); virtual void applyUniforms(const gl::ProgramBinary &programBinary);
virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount); virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount);
virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[], virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
GLint first, GLsizei count, GLsizei instances); GLint first, GLsizei count, GLsizei instances);
virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo); virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo);
virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]); virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]);
......
...@@ -29,7 +29,7 @@ VertexBuffer9::~VertexBuffer9() ...@@ -29,7 +29,7 @@ VertexBuffer9::~VertexBuffer9()
SafeRelease(mVertexBuffer); SafeRelease(mVertexBuffer);
} }
bool VertexBuffer9::initialize(unsigned int size, bool dynamicUsage) gl::Error VertexBuffer9::initialize(unsigned int size, bool dynamicUsage)
{ {
SafeRelease(mVertexBuffer); SafeRelease(mVertexBuffer);
...@@ -47,14 +47,13 @@ bool VertexBuffer9::initialize(unsigned int size, bool dynamicUsage) ...@@ -47,14 +47,13 @@ bool VertexBuffer9::initialize(unsigned int size, bool dynamicUsage)
if (FAILED(result)) if (FAILED(result))
{ {
ERR("Out of memory allocating a vertex buffer of size %lu.", size); return gl::Error(GL_OUT_OF_MEMORY, "Failed to allocate internal vertex buffer of size, %lu.", size);
return false;
} }
} }
mBufferSize = size; mBufferSize = size;
mDynamicUsage = dynamicUsage; mDynamicUsage = dynamicUsage;
return true; return gl::Error(GL_NO_ERROR);
} }
VertexBuffer9 *VertexBuffer9::makeVertexBuffer9(VertexBuffer *vertexBuffer) VertexBuffer9 *VertexBuffer9::makeVertexBuffer9(VertexBuffer *vertexBuffer)
...@@ -63,84 +62,80 @@ VertexBuffer9 *VertexBuffer9::makeVertexBuffer9(VertexBuffer *vertexBuffer) ...@@ -63,84 +62,80 @@ VertexBuffer9 *VertexBuffer9::makeVertexBuffer9(VertexBuffer *vertexBuffer)
return static_cast<VertexBuffer9*>(vertexBuffer); return static_cast<VertexBuffer9*>(vertexBuffer);
} }
bool VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, gl::Error VertexBuffer9::storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int offset) GLint start, GLsizei count, GLsizei instances, unsigned int offset)
{ {
if (mVertexBuffer) if (!mVertexBuffer)
{ {
gl::Buffer *buffer = attrib.buffer.get(); return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized.");
}
int inputStride = gl::ComputeVertexAttributeStride(attrib); gl::Buffer *buffer = attrib.buffer.get();
int elementSize = gl::ComputeVertexAttributeTypeSize(attrib);
DWORD lockFlags = mDynamicUsage ? D3DLOCK_NOOVERWRITE : 0; int inputStride = gl::ComputeVertexAttributeStride(attrib);
int elementSize = gl::ComputeVertexAttributeTypeSize(attrib);
uint8_t *mapPtr = NULL; DWORD lockFlags = mDynamicUsage ? D3DLOCK_NOOVERWRITE : 0;
unsigned int mapSize; uint8_t *mapPtr = NULL;
if (!spaceRequired(attrib, count, instances, &mapSize))
{
return false;
}
HRESULT result = mVertexBuffer->Lock(offset, mapSize, reinterpret_cast<void**>(&mapPtr), lockFlags); unsigned int mapSize;
gl::Error error = spaceRequired(attrib, count, instances, &mapSize);
if (error.isError())
{
return error;
}
if (FAILED(result)) HRESULT result = mVertexBuffer->Lock(offset, mapSize, reinterpret_cast<void**>(&mapPtr), lockFlags);
{ if (FAILED(result))
ERR("Lock failed with error 0x%08x", result); {
return false; 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 = NULL;
if (attrib.enabled) if (attrib.enabled)
{
if (buffer)
{ {
if (buffer) BufferImpl *storage = buffer->getImplementation();
{ input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset);
BufferImpl *storage = buffer->getImplementation();
input = static_cast<const uint8_t*>(storage->getData()) + static_cast<int>(attrib.offset);
}
else
{
input = static_cast<const uint8_t*>(attrib.pointer);
}
} }
else else
{ {
input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues); input = static_cast<const uint8_t*>(attrib.pointer);
}
if (instances == 0 || attrib.divisor == 0)
{
input += inputStride * start;
} }
}
else
{
input = reinterpret_cast<const uint8_t*>(currentValue.FloatValues);
}
gl::VertexFormat vertexFormat(attrib, currentValue.Type); if (instances == 0 || attrib.divisor == 0)
const d3d9::VertexFormat &d3dVertexInfo = d3d9::GetVertexFormatInfo(mRenderer->getCapsDeclTypes(), vertexFormat); {
bool needsConversion = (d3dVertexInfo.conversionType & VERTEX_CONVERT_CPU) > 0; input += inputStride * start;
}
if (!needsConversion && inputStride == elementSize)
{
size_t copySize = static_cast<size_t>(count) * static_cast<size_t>(inputStride);
memcpy(mapPtr, input, copySize);
}
else
{
d3dVertexInfo.copyFunction(input, inputStride, count, mapPtr);
}
mVertexBuffer->Unlock(); gl::VertexFormat vertexFormat(attrib, currentValue.Type);
const d3d9::VertexFormat &d3dVertexInfo = d3d9::GetVertexFormatInfo(mRenderer->getCapsDeclTypes(), vertexFormat);
bool needsConversion = (d3dVertexInfo.conversionType & VERTEX_CONVERT_CPU) > 0;
return true; if (!needsConversion && inputStride == elementSize)
{
size_t copySize = static_cast<size_t>(count) * static_cast<size_t>(inputStride);
memcpy(mapPtr, input, copySize);
} }
else else
{ {
ERR("Vertex buffer not initialized."); d3dVertexInfo.copyFunction(input, inputStride, count, mapPtr);
return false;
} }
mVertexBuffer->Unlock();
return gl::Error(GL_NO_ERROR);
} }
bool VertexBuffer9::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances, gl::Error VertexBuffer9::getSpaceRequired(const gl::VertexAttribute &attrib, GLsizei count, GLsizei instances,
unsigned int *outSpaceRequired) const unsigned int *outSpaceRequired) const
{ {
return spaceRequired(attrib, count, instances, outSpaceRequired); return spaceRequired(attrib, count, instances, outSpaceRequired);
} }
...@@ -150,7 +145,7 @@ unsigned int VertexBuffer9::getBufferSize() const ...@@ -150,7 +145,7 @@ unsigned int VertexBuffer9::getBufferSize() const
return mBufferSize; return mBufferSize;
} }
bool VertexBuffer9::setBufferSize(unsigned int size) gl::Error VertexBuffer9::setBufferSize(unsigned int size)
{ {
if (size > mBufferSize) if (size > mBufferSize)
{ {
...@@ -158,38 +153,33 @@ bool VertexBuffer9::setBufferSize(unsigned int size) ...@@ -158,38 +153,33 @@ bool VertexBuffer9::setBufferSize(unsigned int size)
} }
else else
{ {
return true; return gl::Error(GL_NO_ERROR);
} }
} }
bool VertexBuffer9::discard() gl::Error VertexBuffer9::discard()
{ {
if (mVertexBuffer) if (!mVertexBuffer)
{ {
void *dummy; return gl::Error(GL_OUT_OF_MEMORY, "Internal vertex buffer is not initialized.");
HRESULT result; }
result = mVertexBuffer->Lock(0, 1, &dummy, D3DLOCK_DISCARD);
if (FAILED(result))
{
ERR("Discard lock failed with error 0x%08x", result);
return false;
}
result = mVertexBuffer->Unlock(); void *dummy;
if (FAILED(result)) HRESULT result;
{
ERR("Discard unlock failed with error 0x%08x", result);
return false;
}
return true; result = mVertexBuffer->Lock(0, 1, &dummy, D3DLOCK_DISCARD);
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal buffer for discarding, HRESULT: 0x%08x", result);
} }
else
result = mVertexBuffer->Unlock();
if (FAILED(result))
{ {
ERR("Vertex buffer not initialized."); return gl::Error(GL_OUT_OF_MEMORY, "Failed to unlock internal buffer for discarding, HRESULT: 0x%08x", result);
return false;
} }
return gl::Error(GL_NO_ERROR);
} }
IDirect3DVertexBuffer9 * VertexBuffer9::getBuffer() const IDirect3DVertexBuffer9 * VertexBuffer9::getBuffer() const
...@@ -197,8 +187,8 @@ IDirect3DVertexBuffer9 * VertexBuffer9::getBuffer() const ...@@ -197,8 +187,8 @@ IDirect3DVertexBuffer9 * VertexBuffer9::getBuffer() const
return mVertexBuffer; return mVertexBuffer;
} }
bool VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t count, GLsizei instances, gl::Error VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t count, GLsizei instances,
unsigned int *outSpaceRequired) const unsigned int *outSpaceRequired) const
{ {
gl::VertexFormat vertexFormat(attrib, GL_FLOAT); gl::VertexFormat vertexFormat(attrib, GL_FLOAT);
const d3d9::VertexFormat &d3d9VertexInfo = d3d9::GetVertexFormatInfo(mRenderer->getCapsDeclTypes(), vertexFormat); const d3d9::VertexFormat &d3d9VertexInfo = d3d9::GetVertexFormatInfo(mRenderer->getCapsDeclTypes(), vertexFormat);
...@@ -222,11 +212,11 @@ bool VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t ...@@ -222,11 +212,11 @@ bool VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t
{ {
*outSpaceRequired = d3d9VertexInfo.outputElementSize * elementCount; *outSpaceRequired = d3d9VertexInfo.outputElementSize * elementCount;
} }
return true; return gl::Error(GL_NO_ERROR);
} }
else else
{ {
return false; return gl::Error(GL_OUT_OF_MEMORY, "New vertex buffer size would result in an overflow.");
} }
} }
else else
...@@ -236,7 +226,7 @@ bool VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t ...@@ -236,7 +226,7 @@ bool VertexBuffer9::spaceRequired(const gl::VertexAttribute &attrib, std::size_t
{ {
*outSpaceRequired = elementSize * 4; *outSpaceRequired = elementSize * 4;
} }
return true; return gl::Error(GL_NO_ERROR);
} }
} }
......
...@@ -21,18 +21,18 @@ class VertexBuffer9 : public VertexBuffer ...@@ -21,18 +21,18 @@ class VertexBuffer9 : public VertexBuffer
explicit VertexBuffer9(rx::Renderer9 *renderer); explicit VertexBuffer9(rx::Renderer9 *renderer);
virtual ~VertexBuffer9(); virtual ~VertexBuffer9();
virtual bool initialize(unsigned int size, bool dynamicUsage); virtual gl::Error initialize(unsigned int size, bool dynamicUsage);
static VertexBuffer9 *makeVertexBuffer9(VertexBuffer *vertexBuffer); static VertexBuffer9 *makeVertexBuffer9(VertexBuffer *vertexBuffer);
virtual bool storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue, virtual gl::Error storeVertexAttributes(const gl::VertexAttribute &attrib, const gl::VertexAttribCurrentValueData &currentValue,
GLint start, GLsizei count, GLsizei instances, unsigned int offset); GLint start, GLsizei count, GLsizei instances, unsigned int offset);
virtual bool 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;
virtual unsigned int getBufferSize() const; virtual unsigned int getBufferSize() const;
virtual bool setBufferSize(unsigned int size); virtual gl::Error setBufferSize(unsigned int size);
virtual bool discard(); virtual gl::Error discard();
IDirect3DVertexBuffer9 *getBuffer() const; IDirect3DVertexBuffer9 *getBuffer() const;
...@@ -45,8 +45,8 @@ class VertexBuffer9 : public VertexBuffer ...@@ -45,8 +45,8 @@ class VertexBuffer9 : public VertexBuffer
unsigned int mBufferSize; unsigned int mBufferSize;
bool mDynamicUsage; bool mDynamicUsage;
bool spaceRequired(const gl::VertexAttribute &attrib, std::size_t count, GLsizei instances, gl::Error spaceRequired(const gl::VertexAttribute &attrib, std::size_t count, GLsizei instances,
unsigned int *outSpaceRequired) const; unsigned int *outSpaceRequired) const;
}; };
} }
......
...@@ -40,7 +40,7 @@ VertexDeclarationCache::~VertexDeclarationCache() ...@@ -40,7 +40,7 @@ VertexDeclarationCache::~VertexDeclarationCache()
} }
} }
GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], gl::ProgramBinary *programBinary, GLsizei instances, GLsizei *repeatDraw) gl::Error VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], gl::ProgramBinary *programBinary, GLsizei instances, GLsizei *repeatDraw)
{ {
*repeatDraw = 1; *repeatDraw = 1;
...@@ -188,7 +188,7 @@ GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, Transl ...@@ -188,7 +188,7 @@ GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, Transl
mLastSetVDecl = entry->vertexDeclaration; mLastSetVDecl = entry->vertexDeclaration;
} }
return GL_NO_ERROR; return gl::Error(GL_NO_ERROR);
} }
} }
...@@ -210,12 +210,17 @@ GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, Transl ...@@ -210,12 +210,17 @@ GLenum VertexDeclarationCache::applyDeclaration(IDirect3DDevice9 *device, Transl
} }
memcpy(lastCache->cachedElements, elements, (element - elements) * sizeof(D3DVERTEXELEMENT9)); memcpy(lastCache->cachedElements, elements, (element - elements) * sizeof(D3DVERTEXELEMENT9));
device->CreateVertexDeclaration(elements, &lastCache->vertexDeclaration); HRESULT result = device->CreateVertexDeclaration(elements, &lastCache->vertexDeclaration);
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal vertex declaration, result: 0x%X.", result);
}
device->SetVertexDeclaration(lastCache->vertexDeclaration); device->SetVertexDeclaration(lastCache->vertexDeclaration);
mLastSetVDecl = lastCache->vertexDeclaration; mLastSetVDecl = lastCache->vertexDeclaration;
lastCache->lruCount = ++mMaxLru; lastCache->lruCount = ++mMaxLru;
return GL_NO_ERROR; return gl::Error(GL_NO_ERROR);
} }
void VertexDeclarationCache::markStateDirty() void VertexDeclarationCache::markStateDirty()
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#ifndef LIBGLESV2_RENDERER_VERTEXDECLARATIONCACHE_H_ #ifndef LIBGLESV2_RENDERER_VERTEXDECLARATIONCACHE_H_
#define LIBGLESV2_RENDERER_VERTEXDECLARATIONCACHE_H_ #define LIBGLESV2_RENDERER_VERTEXDECLARATIONCACHE_H_
#include "libGLESv2/Error.h"
#include "libGLESv2/renderer/d3d/VertexDataManager.h" #include "libGLESv2/renderer/d3d/VertexDataManager.h"
namespace gl namespace gl
...@@ -25,7 +26,7 @@ class VertexDeclarationCache ...@@ -25,7 +26,7 @@ class VertexDeclarationCache
VertexDeclarationCache(); VertexDeclarationCache();
~VertexDeclarationCache(); ~VertexDeclarationCache();
GLenum applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], gl::ProgramBinary *programBinary, GLsizei instances, GLsizei *repeatDraw); gl::Error applyDeclaration(IDirect3DDevice9 *device, TranslatedAttribute attributes[], gl::ProgramBinary *programBinary, GLsizei instances, GLsizei *repeatDraw);
void markStateDirty(); void markStateDirty();
......
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