Commit 854429de by Jamie Madill Committed by Commit Bot

D3D: Return error from getVertexSpaceRequired.

This removes another use of the gl::ErrorOrResult pattern. Unblocks error refactoring. Bug: angleproject:2738 Change-Id: Ib611a3b68f8995469befd51797dfed34eaeee84e Reviewed-on: https://chromium-review.googlesource.com/1151450 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent b1565903
......@@ -93,12 +93,12 @@ class BufferFactoryD3D : angle::NonCopyable
// Warning: you should ensure binding really matches attrib.bindingIndex before using this
// function.
virtual gl::ErrorOrResult<unsigned int> getVertexSpaceRequired(
const gl::Context *context,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t count,
GLsizei instances) const = 0;
virtual gl::Error getVertexSpaceRequired(const gl::Context *context,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t count,
GLsizei instances,
unsigned int *bytesRequiredOut) const = 0;
};
using AttribIndexArray = gl::AttribArray<int>;
......
......@@ -98,8 +98,8 @@ gl::ErrorOrResult<unsigned int> VertexBufferInterface::getSpaceRequired(
GLsizei instances) const
{
unsigned int spaceRequired = 0;
ANGLE_TRY_RESULT(mFactory->getVertexSpaceRequired(context, attrib, binding, count, instances),
spaceRequired);
ANGLE_TRY(mFactory->getVertexSpaceRequired(context, attrib, binding, count, instances,
&spaceRequired));
// Align to 16-byte boundary
unsigned int alignedSpaceRequired = roundUp(spaceRequired, 16u);
......@@ -212,8 +212,8 @@ gl::Error StreamingVertexBufferInterface::reserveVertexSpace(const gl::Context *
GLsizei instances)
{
unsigned int requiredSpace = 0;
ANGLE_TRY_RESULT(mFactory->getVertexSpaceRequired(context, attrib, binding, count, instances),
requiredSpace);
ANGLE_TRY(mFactory->getVertexSpaceRequired(context, attrib, binding, count, instances,
&requiredSpace));
// Align to 16-byte boundary
auto alignedRequiredSpace = rx::CheckedRoundUp(requiredSpace, 16u);
......
......@@ -96,14 +96,11 @@ bool DirectStoragePossible(const gl::Context *context,
if (attrib.type != GL_FLOAT)
{
auto errorOrElementSize = factory->getVertexSpaceRequired(context, attrib, binding, 1, 0);
if (errorOrElementSize.isError())
{
ERR() << "Unlogged error in DirectStoragePossible.";
return false;
}
alignment = std::min<size_t>(errorOrElementSize.getResult(), 4);
unsigned int elementSize = 0;
gl::Error error =
factory->getVertexSpaceRequired(context, attrib, binding, 1, 0, &elementSize);
ASSERT(!error.isError());
alignment = std::min<size_t>(elementSize, 4);
}
GLintptr offset = ComputeVertexAttributeOffset(attrib, binding);
......@@ -355,9 +352,8 @@ gl::Error VertexDataManager::StoreStaticAttrib(const gl::Context *context,
unsigned int streamOffset = 0;
translated->storage = nullptr;
ANGLE_TRY_RESULT(
bufferD3D->getFactory()->getVertexSpaceRequired(context, attrib, binding, 1, 0),
translated->stride);
ANGLE_TRY(bufferD3D->getFactory()->getVertexSpaceRequired(context, attrib, binding, 1, 0,
&translated->stride));
auto *staticBuffer = bufferD3D->getStaticVertexBuffer(attrib, binding);
ASSERT(staticBuffer);
......@@ -539,8 +535,8 @@ gl::Error VertexDataManager::storeDynamicAttrib(const gl::Context *context,
unsigned int streamOffset = 0;
translated->storage = nullptr;
ANGLE_TRY_RESULT(mFactory->getVertexSpaceRequired(context, attrib, binding, 1, 0),
translated->stride);
ANGLE_TRY(
mFactory->getVertexSpaceRequired(context, attrib, binding, 1, 0, &translated->stride));
size_t totalCount = gl::ComputeVertexBindingElementCount(binding.getDivisor(), count,
static_cast<size_t>(instances));
......
......@@ -3563,16 +3563,17 @@ GLenum Renderer11::getVertexComponentType(gl::VertexFormatType vertexFormatType)
return d3d11::GetComponentType(format.nativeFormat);
}
gl::ErrorOrResult<unsigned int> Renderer11::getVertexSpaceRequired(
const gl::Context *context,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t count,
GLsizei instances) const
gl::Error Renderer11::getVertexSpaceRequired(const gl::Context *context,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t count,
GLsizei instances,
unsigned int *bytesRequiredOut) const
{
if (!attrib.enabled)
{
return 16u;
*bytesRequiredOut = 16u;
return gl::NoError();
}
unsigned int elementCount = 0;
......@@ -3602,7 +3603,8 @@ gl::ErrorOrResult<unsigned int> Renderer11::getVertexSpaceRequired(
return gl::OutOfMemory() << "New vertex buffer size would result in an overflow.";
}
return elementSize * elementCount;
*bytesRequiredOut = elementSize * elementCount;
return gl::NoError();
}
void Renderer11::generateCaps(gl::Caps *outCaps,
......
......@@ -346,11 +346,12 @@ class Renderer11 : public RendererD3D
// Warning: you should ensure binding really matches attrib.bindingIndex before using this
// function.
gl::ErrorOrResult<unsigned int> getVertexSpaceRequired(const gl::Context *context,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t count,
GLsizei instances) const override;
gl::Error getVertexSpaceRequired(const gl::Context *context,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t count,
GLsizei instances,
unsigned int *bytesRequiredOut) const override;
gl::Error readFromAttachment(const gl::Context *context,
const gl::FramebufferAttachment &srcAttachment,
......
......@@ -2961,15 +2961,17 @@ GLenum Renderer9::getVertexComponentType(gl::VertexFormatType vertexFormatType)
return d3d9::GetVertexFormatInfo(getCapsDeclTypes(), vertexFormatType).componentType;
}
gl::ErrorOrResult<unsigned int> Renderer9::getVertexSpaceRequired(const gl::Context *context,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t count,
GLsizei instances) const
gl::Error Renderer9::getVertexSpaceRequired(const gl::Context *context,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t count,
GLsizei instances,
unsigned int *bytesRequiredOut) const
{
if (!attrib.enabled)
{
return 16u;
*bytesRequiredOut = 16u;
return gl::NoError();
}
gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib, GL_FLOAT);
......@@ -2993,7 +2995,8 @@ gl::ErrorOrResult<unsigned int> Renderer9::getVertexSpaceRequired(const gl::Cont
return gl::OutOfMemory() << "New vertex buffer size would result in an overflow.";
}
return static_cast<unsigned int>(d3d9VertexInfo.outputElementSize) * elementCount;
*bytesRequiredOut = static_cast<unsigned int>(d3d9VertexInfo.outputElementSize) * elementCount;
return gl::NoError();
}
void Renderer9::generateCaps(gl::Caps *outCaps,
......
......@@ -351,11 +351,12 @@ class Renderer9 : public RendererD3D
// Warning: you should ensure binding really matches attrib.bindingIndex before using this
// function.
gl::ErrorOrResult<unsigned int> getVertexSpaceRequired(const gl::Context *context,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t count,
GLsizei instances) const override;
gl::Error getVertexSpaceRequired(const gl::Context *context,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding,
size_t count,
GLsizei instances,
unsigned int *bytesRequiredOut) const override;
gl::Error copyToRenderTarget(IDirect3DSurface9 *dest,
IDirect3DSurface9 *source,
......
......@@ -81,14 +81,9 @@ gl::Error VertexBuffer9::storeVertexAttributes(const gl::Context *context,
uint8_t *mapPtr = nullptr;
auto errorOrMapSize =
mRenderer->getVertexSpaceRequired(context, attrib, binding, count, instances);
if (errorOrMapSize.isError())
{
return errorOrMapSize.getError();
}
unsigned int mapSize = errorOrMapSize.getResult();
unsigned int mapSize = 0;
ANGLE_TRY(
mRenderer->getVertexSpaceRequired(context, attrib, binding, count, instances, &mapSize));
HRESULT result = mVertexBuffer->Lock(offset, mapSize, reinterpret_cast<void**>(&mapPtr), lockFlags);
if (FAILED(result))
......
......@@ -55,12 +55,13 @@ class MockBufferFactoryD3D : public rx::BufferFactoryD3D
MOCK_METHOD0(createVertexBuffer, rx::VertexBuffer *());
MOCK_CONST_METHOD1(getVertexConversionType, rx::VertexConversionType(gl::VertexFormatType));
MOCK_CONST_METHOD1(getVertexComponentType, GLenum(gl::VertexFormatType));
MOCK_CONST_METHOD5(getVertexSpaceRequired,
gl::ErrorOrResult<unsigned int>(const gl::Context *,
const gl::VertexAttribute &,
const gl::VertexBinding &,
size_t,
GLsizei));
MOCK_CONST_METHOD6(getVertexSpaceRequired,
gl::Error(const gl::Context *,
const gl::VertexAttribute &,
const gl::VertexBinding &,
size_t,
GLsizei,
unsigned int *));
// Dependency injection
rx::IndexBuffer *createIndexBuffer() override
......
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