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