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