Commit da123308 by Jamie Madill Committed by Commit Bot

Add ANGLE_TRY macros to reduce boilerplate with gl/egl Errors.

The macros don't need to disambiguate between GL/EGL. Also make helpers to deal with ErrorOrResult. BUG=angleproject:1310 BUG=angleproject:1327 Change-Id: I8041c4b17a859fe1f236bca3ad266453d67a8fd4 Reviewed-on: https://chromium-review.googlesource.com/335826Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent e2fcf5c3
......@@ -363,7 +363,7 @@ Error Display::initialize()
if (isInitialized())
{
return Error(EGL_SUCCESS);
return egl::Error(EGL_SUCCESS);
}
Error error = mImplementation->initialize(this);
......@@ -421,7 +421,7 @@ Error Display::initialize()
mInitialized = true;
return Error(EGL_SUCCESS);
return egl::Error(EGL_SUCCESS);
}
void Display::terminate()
......@@ -548,7 +548,7 @@ Error Display::createWindowSurface(const Config *configuration, EGLNativeWindowT
ASSERT(outSurface != nullptr);
*outSurface = surface;
return Error(EGL_SUCCESS);
return egl::Error(EGL_SUCCESS);
}
Error Display::createPbufferSurface(const Config *configuration, const AttributeMap &attribs, Surface **outSurface)
......@@ -579,7 +579,7 @@ Error Display::createPbufferSurface(const Config *configuration, const Attribute
ASSERT(outSurface != nullptr);
*outSurface = surface;
return Error(EGL_SUCCESS);
return egl::Error(EGL_SUCCESS);
}
Error Display::createPbufferFromClientBuffer(const Config *configuration, EGLClientBuffer shareHandle,
......@@ -611,7 +611,7 @@ Error Display::createPbufferFromClientBuffer(const Config *configuration, EGLCli
ASSERT(outSurface != nullptr);
*outSurface = surface;
return Error(EGL_SUCCESS);
return egl::Error(EGL_SUCCESS);
}
Error Display::createPixmapSurface(const Config *configuration, NativePixmapType nativePixmap, const AttributeMap &attribs,
......@@ -643,7 +643,7 @@ Error Display::createPixmapSurface(const Config *configuration, NativePixmapType
ASSERT(outSurface != nullptr);
*outSurface = surface;
return Error(EGL_SUCCESS);
return egl::Error(EGL_SUCCESS);
}
Error Display::createImage(gl::Context *context,
......@@ -696,7 +696,7 @@ Error Display::createImage(gl::Context *context,
image->addRef();
mImageSet.insert(image);
return Error(EGL_SUCCESS);
return egl::Error(EGL_SUCCESS);
}
Error Display::createContext(const Config *configuration, gl::Context *shareContext, const AttributeMap &attribs,
......@@ -721,7 +721,7 @@ Error Display::createContext(const Config *configuration, gl::Context *shareCont
ASSERT(outContext != nullptr);
*outContext = context;
return Error(EGL_SUCCESS);
return egl::Error(EGL_SUCCESS);
}
Error Display::makeCurrent(egl::Surface *drawSurface, egl::Surface *readSurface, gl::Context *context)
......
......@@ -74,6 +74,11 @@ class ErrorOrResult
T mResult;
};
inline Error NoError()
{
return Error(GL_NO_ERROR);
}
} // namespace gl
namespace egl
......@@ -107,6 +112,35 @@ class Error final
} // namespace egl
#define ANGLE_CONCAT1(x, y) x##y
#define ANGLE_CONCAT2(x, y) ANGLE_CONCAT1(x, y)
#define ANGLE_LOCAL_VAR ANGLE_CONCAT2(_localVar, __LINE__)
#define ANGLE_TRY(EXPR) \
{ \
auto ANGLE_LOCAL_VAR = EXPR; \
if (ANGLE_LOCAL_VAR.isError()) \
{ \
return ANGLE_LOCAL_VAR; \
} \
} \
ANGLE_EMPTY_STATEMENT
#define ANGLE_TRY_RESULT(EXPR, RESULT) \
{ \
auto ANGLE_LOCAL_VAR = EXPR; \
if (ANGLE_LOCAL_VAR.isError()) \
{ \
return ANGLE_LOCAL_VAR.getError(); \
} \
RESULT = ANGLE_LOCAL_VAR.getResult(); \
} \
ANGLE_EMPTY_STATEMENT
#undef ANGLE_LOCAL_VAR
#undef ANGLE_CONCAT2
#undef ANGLE_CONCAT1
#include "Error.inl"
#endif // LIBANGLE_ERROR_H_
......@@ -94,13 +94,8 @@ gl::ErrorOrResult<unsigned int> VertexBufferInterface::getSpaceRequired(
GLsizei count,
GLsizei instances) const
{
auto errorOrSpaceRequired = mFactory->getVertexSpaceRequired(attrib, count, instances);
if (errorOrSpaceRequired.isError())
{
return errorOrSpaceRequired.getError();
}
unsigned int spaceRequired = errorOrSpaceRequired.getResult();
unsigned int spaceRequired = 0;
ANGLE_TRY_RESULT(mFactory->getVertexSpaceRequired(attrib, count, instances), spaceRequired);
// Align to 16-byte boundary
unsigned int alignedSpaceRequired = roundUp(spaceRequired, 16u);
......@@ -141,24 +136,16 @@ gl::Error StreamingVertexBufferInterface::reserveSpace(unsigned int size)
unsigned int curBufferSize = getBufferSize();
if (size > curBufferSize)
{
gl::Error error = setBufferSize(std::max(size, 3 * curBufferSize / 2));
if (error.isError())
{
return error;
}
ANGLE_TRY(setBufferSize(std::max(size, 3 * curBufferSize / 2)));
mWritePosition = 0;
}
else if (mWritePosition + size > curBufferSize)
{
gl::Error error = discard();
if (error.isError())
{
return error;
}
ANGLE_TRY(discard());
mWritePosition = 0;
}
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
gl::Error StreamingVertexBufferInterface::storeDynamicAttribute(const gl::VertexAttribute &attrib,
......@@ -169,55 +156,37 @@ gl::Error StreamingVertexBufferInterface::storeDynamicAttribute(const gl::Vertex
unsigned int *outStreamOffset,
const uint8_t *sourceData)
{
auto spaceRequiredOrError = getSpaceRequired(attrib, count, instances);
if (spaceRequiredOrError.isError())
{
return spaceRequiredOrError.getError();
}
unsigned int alignedSpaceRequired = spaceRequiredOrError.getResult();
unsigned int spaceRequired = 0;
ANGLE_TRY_RESULT(getSpaceRequired(attrib, count, instances), spaceRequired);
// Protect against integer overflow
if (!IsUnsignedAdditionSafe(mWritePosition, alignedSpaceRequired))
if (!IsUnsignedAdditionSafe(mWritePosition, spaceRequired))
{
return gl::Error(GL_OUT_OF_MEMORY, "Internal error, new vertex buffer write position would overflow.");
}
gl::Error error = reserveSpace(mReservedSpace);
if (error.isError())
{
return error;
}
ANGLE_TRY(reserveSpace(mReservedSpace));
mReservedSpace = 0;
error = mVertexBuffer->storeVertexAttributes(attrib, currentValueType, start, count, instances,
mWritePosition, sourceData);
if (error.isError())
{
return error;
}
ANGLE_TRY(mVertexBuffer->storeVertexAttributes(attrib, currentValueType, start, count,
instances, mWritePosition, sourceData));
if (outStreamOffset)
{
*outStreamOffset = mWritePosition;
}
mWritePosition += alignedSpaceRequired;
mWritePosition += spaceRequired;
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
gl::Error StreamingVertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &attrib,
GLsizei count,
GLsizei instances)
{
auto errorOrRequiredSpace = mFactory->getVertexSpaceRequired(attrib, count, instances);
if (errorOrRequiredSpace.isError())
{
return errorOrRequiredSpace.getError();
}
unsigned int requiredSpace = errorOrRequiredSpace.getResult();
unsigned int requiredSpace = 0;
ANGLE_TRY_RESULT(mFactory->getVertexSpaceRequired(attrib, count, instances), requiredSpace);
// Align to 16-byte boundary
unsigned int alignedRequiredSpace = roundUp(requiredSpace, 16u);
......@@ -234,7 +203,7 @@ gl::Error StreamingVertexBufferInterface::reserveVertexSpace(const gl::VertexAtt
mReservedSpace += alignedRequiredSpace;
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
// StaticVertexBufferInterface Implementation
......@@ -293,24 +262,17 @@ gl::Error StaticVertexBufferInterface::storeStaticAttribute(const gl::VertexAttr
GLsizei instances,
const uint8_t *sourceData)
{
auto spaceRequiredOrError = getSpaceRequired(attrib, count, instances);
if (spaceRequiredOrError.isError())
{
return spaceRequiredOrError.getError();
}
setBufferSize(spaceRequiredOrError.getResult());
unsigned int spaceRequired = 0;
ANGLE_TRY_RESULT(getSpaceRequired(attrib, count, instances), spaceRequired);
setBufferSize(spaceRequired);
ASSERT(attrib.enabled);
gl::Error error = mVertexBuffer->storeVertexAttributes(attrib, GL_NONE, start, count, instances,
0, sourceData);
if (!error.isError())
{
mSignature.set(attrib);
mVertexBuffer->hintUnmapResource();
}
ANGLE_TRY(mVertexBuffer->storeVertexAttributes(attrib, GL_NONE, start, count, instances, 0,
sourceData));
return error;
mSignature.set(attrib);
mVertexBuffer->hintUnmapResource();
return gl::NoError();
}
} // namespace rx
......@@ -241,11 +241,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(
}
}
gl::Error error = updateInputLayout(state, mode, sortedSemanticIndices, numIndicesPerInstance);
if (error.isError())
{
return error;
}
ANGLE_TRY(updateInputLayout(state, mode, sortedSemanticIndices, numIndicesPerInstance));
bool dirtyBuffers = false;
size_t minDiff = gl::MAX_VERTEX_ATTRIBS;
......@@ -280,11 +276,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(
if (indexInfo->srcIndexData.srcBuffer != nullptr)
{
const uint8_t *bufferData = nullptr;
error = indexInfo->srcIndexData.srcBuffer->getData(&bufferData);
if (error.isError())
{
return error;
}
ANGLE_TRY(indexInfo->srcIndexData.srcBuffer->getData(&bufferData));
ASSERT(bufferData != nullptr);
ptrdiff_t offset =
......@@ -293,23 +285,14 @@ gl::Error InputLayoutCache::applyVertexBuffers(
indexInfo->srcIndexData.srcIndices = bufferData + offset;
}
auto bufferOrError =
bufferStorage->getEmulatedIndexedBuffer(&indexInfo->srcIndexData, attrib);
if (bufferOrError.isError())
{
return bufferOrError.getError();
}
buffer = bufferOrError.getResult();
ANGLE_TRY_RESULT(
bufferStorage->getEmulatedIndexedBuffer(&indexInfo->srcIndexData, attrib),
buffer);
}
else
{
auto bufferOrError =
bufferStorage->getBuffer(BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK);
if (bufferOrError.isError())
{
return bufferOrError.getError();
}
buffer = bufferOrError.getResult();
ANGLE_TRY_RESULT(
bufferStorage->getBuffer(BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK), buffer);
}
vertexStride = attrib.stride;
......@@ -428,7 +411,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(
&mCurrentVertexOffsets[minDiff]);
}
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
gl::Error InputLayoutCache::updateVertexOffsetsForPointSpritesEmulation(GLsizei emulatedInstanceId)
......@@ -449,7 +432,7 @@ gl::Error InputLayoutCache::updateVertexOffsetsForPointSpritesEmulation(GLsizei
mDeviceContext->IASetVertexBuffers(0, gl::MAX_VERTEX_ATTRIBS, mCurrentBuffers.data(),
mCurrentVertexStrides.data(), mCurrentVertexOffsets.data());
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
gl::Error InputLayoutCache::updateInputLayout(const gl::State &state,
......@@ -509,12 +492,8 @@ gl::Error InputLayoutCache::updateInputLayout(const gl::State &state,
}
else
{
gl::Error error = createInputLayout(sortedSemanticIndices, mode, program,
numIndicesPerInstance, &inputLayout);
if (error.isError())
{
return error;
}
ANGLE_TRY(createInputLayout(sortedSemanticIndices, mode, program, numIndicesPerInstance,
&inputLayout));
if (mLayoutMap.size() >= mCacheSize)
{
TRACE("Overflowed the limit of %u input layouts, purging half the cache.",
......@@ -544,7 +523,7 @@ gl::Error InputLayoutCache::updateInputLayout(const gl::State &state,
mCurrentIL = inputLayout;
}
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
gl::Error InputLayoutCache::createInputLayout(const AttribIndexArray &sortedSemanticIndices,
......@@ -636,12 +615,7 @@ gl::Error InputLayoutCache::createInputLayout(const AttribIndexArray &sortedSema
const gl::InputLayout &shaderInputLayout = GetInputLayout(mCurrentAttributes);
ShaderExecutableD3D *shader = nullptr;
gl::Error error =
programD3D->getVertexExecutableForInputLayout(shaderInputLayout, &shader, nullptr);
if (error.isError())
{
return error;
}
ANGLE_TRY(programD3D->getVertexExecutableForInputLayout(shaderInputLayout, &shader, nullptr));
ShaderExecutableD3D *shader11 = GetAs<ShaderExecutable11>(shader);
......@@ -654,7 +628,7 @@ gl::Error InputLayoutCache::createInputLayout(const AttribIndexArray &sortedSema
"Failed to create internal input layout, HRESULT: 0x%08x", result);
}
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
} // namespace rx
......@@ -64,7 +64,7 @@ gl::Error PixelTransfer11::loadResources()
{
if (mResourcesLoaded)
{
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
HRESULT result = S_OK;
......@@ -141,17 +141,13 @@ gl::Error PixelTransfer11::loadResources()
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal buffer to texture geometry shader.");
}
gl::Error error = buildShaderMap();
if (error.isError())
{
return error;
}
ANGLE_TRY(buildShaderMap());
StructZero(&mParamsData);
mResourcesLoaded = true;
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat,
......@@ -180,11 +176,7 @@ void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, cons
gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTargetD3D *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea)
{
gl::Error error = loadResources();
if (error.isError())
{
return error;
}
ANGLE_TRY(loadResources());
gl::Extents destSize = destRenderTarget->getExtents();
......@@ -208,12 +200,8 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpac
DXGI_FORMAT srvFormat = sourceFormatInfo.formatSet->srvFormat;
ASSERT(srvFormat != DXGI_FORMAT_UNKNOWN);
Buffer11 *bufferStorage11 = GetAs<Buffer11>(sourceBuffer.getImplementation());
auto srvOrError = bufferStorage11->getSRV(srvFormat);
if (srvOrError.isError())
{
return srvOrError.getError();
}
ID3D11ShaderResourceView *bufferSRV = srvOrError.getResult();
ID3D11ShaderResourceView *bufferSRV = nullptr;
ANGLE_TRY_RESULT(bufferStorage11->getSRV(srvFormat), bufferSRV);
ASSERT(bufferSRV != nullptr);
ID3D11RenderTargetView *textureRTV = GetAs<RenderTarget11>(destRenderTarget)->getRenderTargetView();
......@@ -272,7 +260,7 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpac
mRenderer->markAllStateDirty();
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
gl::Error PixelTransfer11::buildShaderMap()
......@@ -292,7 +280,7 @@ gl::Error PixelTransfer11::buildShaderMap()
}
}
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
ID3D11PixelShader *PixelTransfer11::findBufferToTexturePS(GLenum internalFormat) const
......@@ -307,4 +295,4 @@ ID3D11PixelShader *PixelTransfer11::findBufferToTexturePS(GLenum internalFormat)
return (shaderMapIt == mBufferToTexturePSMap.end() ? NULL : shaderMapIt->second);
}
}
} // namespace rx
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