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() ...@@ -363,7 +363,7 @@ Error Display::initialize()
if (isInitialized()) if (isInitialized())
{ {
return Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
Error error = mImplementation->initialize(this); Error error = mImplementation->initialize(this);
...@@ -421,7 +421,7 @@ Error Display::initialize() ...@@ -421,7 +421,7 @@ Error Display::initialize()
mInitialized = true; mInitialized = true;
return Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
void Display::terminate() void Display::terminate()
...@@ -548,7 +548,7 @@ Error Display::createWindowSurface(const Config *configuration, EGLNativeWindowT ...@@ -548,7 +548,7 @@ Error Display::createWindowSurface(const Config *configuration, EGLNativeWindowT
ASSERT(outSurface != nullptr); ASSERT(outSurface != nullptr);
*outSurface = surface; *outSurface = surface;
return Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
Error Display::createPbufferSurface(const Config *configuration, const AttributeMap &attribs, Surface **outSurface) Error Display::createPbufferSurface(const Config *configuration, const AttributeMap &attribs, Surface **outSurface)
...@@ -579,7 +579,7 @@ Error Display::createPbufferSurface(const Config *configuration, const Attribute ...@@ -579,7 +579,7 @@ Error Display::createPbufferSurface(const Config *configuration, const Attribute
ASSERT(outSurface != nullptr); ASSERT(outSurface != nullptr);
*outSurface = surface; *outSurface = surface;
return Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
Error Display::createPbufferFromClientBuffer(const Config *configuration, EGLClientBuffer shareHandle, Error Display::createPbufferFromClientBuffer(const Config *configuration, EGLClientBuffer shareHandle,
...@@ -611,7 +611,7 @@ Error Display::createPbufferFromClientBuffer(const Config *configuration, EGLCli ...@@ -611,7 +611,7 @@ Error Display::createPbufferFromClientBuffer(const Config *configuration, EGLCli
ASSERT(outSurface != nullptr); ASSERT(outSurface != nullptr);
*outSurface = surface; *outSurface = surface;
return Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
Error Display::createPixmapSurface(const Config *configuration, NativePixmapType nativePixmap, const AttributeMap &attribs, Error Display::createPixmapSurface(const Config *configuration, NativePixmapType nativePixmap, const AttributeMap &attribs,
...@@ -643,7 +643,7 @@ Error Display::createPixmapSurface(const Config *configuration, NativePixmapType ...@@ -643,7 +643,7 @@ Error Display::createPixmapSurface(const Config *configuration, NativePixmapType
ASSERT(outSurface != nullptr); ASSERT(outSurface != nullptr);
*outSurface = surface; *outSurface = surface;
return Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
Error Display::createImage(gl::Context *context, Error Display::createImage(gl::Context *context,
...@@ -696,7 +696,7 @@ Error Display::createImage(gl::Context *context, ...@@ -696,7 +696,7 @@ Error Display::createImage(gl::Context *context,
image->addRef(); image->addRef();
mImageSet.insert(image); mImageSet.insert(image);
return Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
Error Display::createContext(const Config *configuration, gl::Context *shareContext, const AttributeMap &attribs, 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 ...@@ -721,7 +721,7 @@ Error Display::createContext(const Config *configuration, gl::Context *shareCont
ASSERT(outContext != nullptr); ASSERT(outContext != nullptr);
*outContext = context; *outContext = context;
return Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
Error Display::makeCurrent(egl::Surface *drawSurface, egl::Surface *readSurface, gl::Context *context) Error Display::makeCurrent(egl::Surface *drawSurface, egl::Surface *readSurface, gl::Context *context)
......
...@@ -74,6 +74,11 @@ class ErrorOrResult ...@@ -74,6 +74,11 @@ class ErrorOrResult
T mResult; T mResult;
}; };
inline Error NoError()
{
return Error(GL_NO_ERROR);
}
} // namespace gl } // namespace gl
namespace egl namespace egl
...@@ -107,6 +112,35 @@ class Error final ...@@ -107,6 +112,35 @@ class Error final
} // namespace egl } // 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" #include "Error.inl"
#endif // LIBANGLE_ERROR_H_ #endif // LIBANGLE_ERROR_H_
...@@ -137,31 +137,19 @@ gl::Error RendererD3D::genericDrawElements(const gl::Data &data, ...@@ -137,31 +137,19 @@ gl::Error RendererD3D::genericDrawElements(const gl::Data &data,
programD3D->updateSamplerMapping(); programD3D->updateSamplerMapping();
gl::Error error = generateSwizzles(data); ANGLE_TRY(generateSwizzles(data));
if (error.isError())
{
return error;
}
if (!applyPrimitiveType(mode, count, usesPointSize)) if (!applyPrimitiveType(mode, count, usesPointSize))
{ {
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
error = updateState(data, mode); ANGLE_TRY(updateState(data, mode));
if (error.isError())
{
return error;
}
TranslatedIndexData indexInfo; TranslatedIndexData indexInfo;
indexInfo.indexRange = indexRange; indexInfo.indexRange = indexRange;
error = applyIndexBuffer(data, indices, count, mode, type, &indexInfo); ANGLE_TRY(applyIndexBuffer(data, indices, count, mode, type, &indexInfo));
if (error.isError())
{
return error;
}
applyTransformFeedbackBuffers(*data.state); applyTransformFeedbackBuffers(*data.state);
// Transform feedback is not allowed for DrawElements, this error should have been caught at the API validation // Transform feedback is not allowed for DrawElements, this error should have been caught at the API validation
...@@ -169,41 +157,18 @@ gl::Error RendererD3D::genericDrawElements(const gl::Data &data, ...@@ -169,41 +157,18 @@ gl::Error RendererD3D::genericDrawElements(const gl::Data &data,
ASSERT(!data.state->isTransformFeedbackActiveUnpaused()); ASSERT(!data.state->isTransformFeedbackActiveUnpaused());
size_t vertexCount = indexInfo.indexRange.vertexCount(); size_t vertexCount = indexInfo.indexRange.vertexCount();
error = applyVertexBuffer(*data.state, mode, static_cast<GLsizei>(indexInfo.indexRange.start), ANGLE_TRY(applyVertexBuffer(*data.state, mode, static_cast<GLsizei>(indexInfo.indexRange.start),
static_cast<GLsizei>(vertexCount), instances, &indexInfo); static_cast<GLsizei>(vertexCount), instances, &indexInfo));
if (error.isError()) ANGLE_TRY(applyTextures(data));
{ ANGLE_TRY(applyShaders(data, mode));
return error; ANGLE_TRY(programD3D->applyUniformBuffers(data));
}
error = applyTextures(data);
if (error.isError())
{
return error;
}
error = applyShaders(data, mode);
if (error.isError())
{
return error;
}
error = programD3D->applyUniformBuffers(data);
if (error.isError())
{
return error;
}
if (!skipDraw(data, mode)) if (!skipDraw(data, mode))
{ {
error = drawElementsImpl(data, indexInfo, mode, count, type, indices, instances); ANGLE_TRY(drawElementsImpl(data, indexInfo, mode, count, type, indices, instances));
if (error.isError())
{
return error;
}
} }
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error RendererD3D::genericDrawArrays(const gl::Data &data, gl::Error RendererD3D::genericDrawArrays(const gl::Data &data,
...@@ -219,68 +184,30 @@ gl::Error RendererD3D::genericDrawArrays(const gl::Data &data, ...@@ -219,68 +184,30 @@ gl::Error RendererD3D::genericDrawArrays(const gl::Data &data,
programD3D->updateSamplerMapping(); programD3D->updateSamplerMapping();
gl::Error error = generateSwizzles(data); ANGLE_TRY(generateSwizzles(data));
if (error.isError())
{
return error;
}
if (!applyPrimitiveType(mode, count, usesPointSize)) if (!applyPrimitiveType(mode, count, usesPointSize))
{ {
return gl::Error(GL_NO_ERROR); return gl::NoError();
}
error = updateState(data, mode);
if (error.isError())
{
return error;
}
applyTransformFeedbackBuffers(*data.state);
error = applyVertexBuffer(*data.state, mode, first, count, instances, nullptr);
if (error.isError())
{
return error;
}
error = applyTextures(data);
if (error.isError())
{
return error;
} }
error = applyShaders(data, mode); ANGLE_TRY(updateState(data, mode));
if (error.isError()) ANGLE_TRY(applyTransformFeedbackBuffers(*data.state));
{ ANGLE_TRY(applyVertexBuffer(*data.state, mode, first, count, instances, nullptr));
return error; ANGLE_TRY(applyTextures(data));
} ANGLE_TRY(applyShaders(data, mode));
ANGLE_TRY(programD3D->applyUniformBuffers(data));
error = programD3D->applyUniformBuffers(data);
if (error.isError())
{
return error;
}
if (!skipDraw(data, mode)) if (!skipDraw(data, mode))
{ {
error = drawArraysImpl(data, mode, count, instances); ANGLE_TRY(drawArraysImpl(data, mode, count, instances));
if (error.isError())
{
return error;
}
if (data.state->isTransformFeedbackActiveUnpaused()) if (data.state->isTransformFeedbackActiveUnpaused())
{ {
error = markTransformFeedbackUsage(data); ANGLE_TRY(markTransformFeedbackUsage(data));
if (error.isError())
{
return error;
}
} }
} }
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error RendererD3D::generateSwizzles(const gl::Data &data, gl::SamplerType type) gl::Error RendererD3D::generateSwizzles(const gl::Data &data, gl::SamplerType type)
...@@ -299,33 +226,19 @@ gl::Error RendererD3D::generateSwizzles(const gl::Data &data, gl::SamplerType ty ...@@ -299,33 +226,19 @@ gl::Error RendererD3D::generateSwizzles(const gl::Data &data, gl::SamplerType ty
ASSERT(texture); ASSERT(texture);
if (texture->getTextureState().swizzleRequired()) if (texture->getTextureState().swizzleRequired())
{ {
gl::Error error = generateSwizzle(texture); ANGLE_TRY(generateSwizzle(texture));
if (error.isError())
{
return error;
}
} }
} }
} }
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error RendererD3D::generateSwizzles(const gl::Data &data) gl::Error RendererD3D::generateSwizzles(const gl::Data &data)
{ {
gl::Error error = generateSwizzles(data, gl::SAMPLER_VERTEX); ANGLE_TRY(generateSwizzles(data, gl::SAMPLER_VERTEX));
if (error.isError()) ANGLE_TRY(generateSwizzles(data, gl::SAMPLER_PIXEL));
{ return gl::NoError();
return error;
}
error = generateSwizzles(data, gl::SAMPLER_PIXEL);
if (error.isError())
{
return error;
}
return gl::Error(GL_NO_ERROR);
} }
unsigned int RendererD3D::GetBlendSampleMask(const gl::Data &data, int samples) unsigned int RendererD3D::GetBlendSampleMask(const gl::Data &data, int samples)
...@@ -371,11 +284,7 @@ gl::Error RendererD3D::applyShaders(const gl::Data &data, GLenum drawMode) ...@@ -371,11 +284,7 @@ gl::Error RendererD3D::applyShaders(const gl::Data &data, GLenum drawMode)
ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program); ProgramD3D *programD3D = GetImplAs<ProgramD3D>(program);
programD3D->updateCachedInputLayout(*data.state); programD3D->updateCachedInputLayout(*data.state);
gl::Error error = applyShadersImpl(data, drawMode); ANGLE_TRY(applyShadersImpl(data, drawMode));
if (error.isError())
{
return error;
}
return programD3D->applyUniforms(drawMode); return programD3D->applyUniforms(drawMode);
} }
...@@ -411,45 +320,23 @@ gl::Error RendererD3D::applyTextures(const gl::Data &data, gl::SamplerType shade ...@@ -411,45 +320,23 @@ gl::Error RendererD3D::applyTextures(const gl::Data &data, gl::SamplerType shade
!std::binary_search(framebufferTextures.begin(), !std::binary_search(framebufferTextures.begin(),
framebufferTextures.begin() + framebufferTextureCount, texture)) framebufferTextures.begin() + framebufferTextureCount, texture))
{ {
gl::Error error = setSamplerState(shaderType, samplerIndex, texture, samplerState); ANGLE_TRY(setSamplerState(shaderType, samplerIndex, texture, samplerState));
if (error.isError()) ANGLE_TRY(setTexture(shaderType, samplerIndex, texture));
{
return error;
}
error = setTexture(shaderType, samplerIndex, texture);
if (error.isError())
{
return error;
}
} }
else else
{ {
// Texture is not sampler complete or it is in use by the framebuffer. Bind the incomplete texture. // Texture is not sampler complete or it is in use by the framebuffer. Bind the incomplete texture.
gl::Texture *incompleteTexture = getIncompleteTexture(textureType); gl::Texture *incompleteTexture = getIncompleteTexture(textureType);
gl::Error error = setSamplerState(shaderType, samplerIndex, incompleteTexture, ANGLE_TRY(setSamplerState(shaderType, samplerIndex, incompleteTexture,
incompleteTexture->getSamplerState()); incompleteTexture->getSamplerState()));
if (error.isError()) ANGLE_TRY(setTexture(shaderType, samplerIndex, incompleteTexture));
{
return error;
}
error = setTexture(shaderType, samplerIndex, incompleteTexture);
if (error.isError())
{
return error;
}
} }
} }
else else
{ {
// No texture bound to this slot even though it is used by the shader, bind a NULL texture // No texture bound to this slot even though it is used by the shader, bind a NULL texture
gl::Error error = setTexture(shaderType, samplerIndex, NULL); ANGLE_TRY(setTexture(shaderType, samplerIndex, nullptr));
if (error.isError())
{
return error;
}
} }
} }
...@@ -458,7 +345,7 @@ gl::Error RendererD3D::applyTextures(const gl::Data &data, gl::SamplerType shade ...@@ -458,7 +345,7 @@ gl::Error RendererD3D::applyTextures(const gl::Data &data, gl::SamplerType shade
: data.caps->maxVertexTextureImageUnits; : data.caps->maxVertexTextureImageUnits;
clearTextures(shaderType, samplerRange, samplerCount); clearTextures(shaderType, samplerRange, samplerCount);
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error RendererD3D::applyTextures(const gl::Data &data) gl::Error RendererD3D::applyTextures(const gl::Data &data)
...@@ -466,19 +353,9 @@ gl::Error RendererD3D::applyTextures(const gl::Data &data) ...@@ -466,19 +353,9 @@ gl::Error RendererD3D::applyTextures(const gl::Data &data)
FramebufferTextureArray framebufferTextures; FramebufferTextureArray framebufferTextures;
size_t framebufferSerialCount = getBoundFramebufferTextures(data, &framebufferTextures); size_t framebufferSerialCount = getBoundFramebufferTextures(data, &framebufferTextures);
gl::Error error = applyTextures(data, gl::SAMPLER_VERTEX, framebufferTextures, framebufferSerialCount); ANGLE_TRY(applyTextures(data, gl::SAMPLER_VERTEX, framebufferTextures, framebufferSerialCount));
if (error.isError()) ANGLE_TRY(applyTextures(data, gl::SAMPLER_PIXEL, framebufferTextures, framebufferSerialCount));
{ return gl::NoError();
return error;
}
error = applyTextures(data, gl::SAMPLER_PIXEL, framebufferTextures, framebufferSerialCount);
if (error.isError())
{
return error;
}
return gl::Error(GL_NO_ERROR);
} }
bool RendererD3D::skipDraw(const gl::Data &data, GLenum drawMode) bool RendererD3D::skipDraw(const gl::Data &data, GLenum drawMode)
...@@ -522,15 +399,11 @@ gl::Error RendererD3D::markTransformFeedbackUsage(const gl::Data &data) ...@@ -522,15 +399,11 @@ gl::Error RendererD3D::markTransformFeedbackUsage(const gl::Data &data)
if (binding.get() != nullptr) if (binding.get() != nullptr)
{ {
BufferD3D *bufferD3D = GetImplAs<BufferD3D>(binding.get()); BufferD3D *bufferD3D = GetImplAs<BufferD3D>(binding.get());
auto error = bufferD3D->markTransformFeedbackUsage(); ANGLE_TRY(bufferD3D->markTransformFeedbackUsage());
if (error.isError())
{
return error;
}
} }
} }
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
size_t RendererD3D::getBoundFramebufferTextures(const gl::Data &data, FramebufferTextureArray *outTextureArray) size_t RendererD3D::getBoundFramebufferTextures(const gl::Data &data, FramebufferTextureArray *outTextureArray)
...@@ -711,4 +584,4 @@ gl::DebugAnnotator *RendererD3D::getAnnotator() ...@@ -711,4 +584,4 @@ gl::DebugAnnotator *RendererD3D::getAnnotator()
ASSERT(mAnnotator); ASSERT(mAnnotator);
return mAnnotator; return mAnnotator;
} }
} } // namespace rx
...@@ -94,13 +94,8 @@ gl::ErrorOrResult<unsigned int> VertexBufferInterface::getSpaceRequired( ...@@ -94,13 +94,8 @@ gl::ErrorOrResult<unsigned int> VertexBufferInterface::getSpaceRequired(
GLsizei count, GLsizei count,
GLsizei instances) const GLsizei instances) const
{ {
auto errorOrSpaceRequired = mFactory->getVertexSpaceRequired(attrib, count, instances); unsigned int spaceRequired = 0;
if (errorOrSpaceRequired.isError()) ANGLE_TRY_RESULT(mFactory->getVertexSpaceRequired(attrib, count, instances), spaceRequired);
{
return errorOrSpaceRequired.getError();
}
unsigned int spaceRequired = errorOrSpaceRequired.getResult();
// Align to 16-byte boundary // Align to 16-byte boundary
unsigned int alignedSpaceRequired = roundUp(spaceRequired, 16u); unsigned int alignedSpaceRequired = roundUp(spaceRequired, 16u);
...@@ -141,24 +136,16 @@ gl::Error StreamingVertexBufferInterface::reserveSpace(unsigned int size) ...@@ -141,24 +136,16 @@ gl::Error StreamingVertexBufferInterface::reserveSpace(unsigned int size)
unsigned int curBufferSize = getBufferSize(); unsigned int curBufferSize = getBufferSize();
if (size > curBufferSize) if (size > curBufferSize)
{ {
gl::Error error = setBufferSize(std::max(size, 3 * curBufferSize / 2)); ANGLE_TRY(setBufferSize(std::max(size, 3 * curBufferSize / 2)));
if (error.isError())
{
return error;
}
mWritePosition = 0; mWritePosition = 0;
} }
else if (mWritePosition + size > curBufferSize) else if (mWritePosition + size > curBufferSize)
{ {
gl::Error error = discard(); ANGLE_TRY(discard());
if (error.isError())
{
return error;
}
mWritePosition = 0; mWritePosition = 0;
} }
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error StreamingVertexBufferInterface::storeDynamicAttribute(const gl::VertexAttribute &attrib, gl::Error StreamingVertexBufferInterface::storeDynamicAttribute(const gl::VertexAttribute &attrib,
...@@ -169,55 +156,37 @@ gl::Error StreamingVertexBufferInterface::storeDynamicAttribute(const gl::Vertex ...@@ -169,55 +156,37 @@ gl::Error StreamingVertexBufferInterface::storeDynamicAttribute(const gl::Vertex
unsigned int *outStreamOffset, unsigned int *outStreamOffset,
const uint8_t *sourceData) const uint8_t *sourceData)
{ {
auto spaceRequiredOrError = getSpaceRequired(attrib, count, instances); unsigned int spaceRequired = 0;
if (spaceRequiredOrError.isError()) ANGLE_TRY_RESULT(getSpaceRequired(attrib, count, instances), spaceRequired);
{
return spaceRequiredOrError.getError();
}
unsigned int alignedSpaceRequired = spaceRequiredOrError.getResult();
// Protect against integer overflow // 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."); return gl::Error(GL_OUT_OF_MEMORY, "Internal error, new vertex buffer write position would overflow.");
} }
gl::Error error = reserveSpace(mReservedSpace); ANGLE_TRY(reserveSpace(mReservedSpace));
if (error.isError())
{
return error;
}
mReservedSpace = 0; mReservedSpace = 0;
error = mVertexBuffer->storeVertexAttributes(attrib, currentValueType, start, count, instances, ANGLE_TRY(mVertexBuffer->storeVertexAttributes(attrib, currentValueType, start, count,
mWritePosition, sourceData); instances, mWritePosition, sourceData));
if (error.isError())
{
return error;
}
if (outStreamOffset) if (outStreamOffset)
{ {
*outStreamOffset = mWritePosition; *outStreamOffset = mWritePosition;
} }
mWritePosition += alignedSpaceRequired; mWritePosition += spaceRequired;
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error StreamingVertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &attrib, gl::Error StreamingVertexBufferInterface::reserveVertexSpace(const gl::VertexAttribute &attrib,
GLsizei count, GLsizei count,
GLsizei instances) GLsizei instances)
{ {
auto errorOrRequiredSpace = mFactory->getVertexSpaceRequired(attrib, count, instances); unsigned int requiredSpace = 0;
if (errorOrRequiredSpace.isError()) ANGLE_TRY_RESULT(mFactory->getVertexSpaceRequired(attrib, count, instances), requiredSpace);
{
return errorOrRequiredSpace.getError();
}
unsigned int requiredSpace = errorOrRequiredSpace.getResult();
// Align to 16-byte boundary // Align to 16-byte boundary
unsigned int alignedRequiredSpace = roundUp(requiredSpace, 16u); unsigned int alignedRequiredSpace = roundUp(requiredSpace, 16u);
...@@ -234,7 +203,7 @@ gl::Error StreamingVertexBufferInterface::reserveVertexSpace(const gl::VertexAtt ...@@ -234,7 +203,7 @@ gl::Error StreamingVertexBufferInterface::reserveVertexSpace(const gl::VertexAtt
mReservedSpace += alignedRequiredSpace; mReservedSpace += alignedRequiredSpace;
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
// StaticVertexBufferInterface Implementation // StaticVertexBufferInterface Implementation
...@@ -293,24 +262,17 @@ gl::Error StaticVertexBufferInterface::storeStaticAttribute(const gl::VertexAttr ...@@ -293,24 +262,17 @@ gl::Error StaticVertexBufferInterface::storeStaticAttribute(const gl::VertexAttr
GLsizei instances, GLsizei instances,
const uint8_t *sourceData) const uint8_t *sourceData)
{ {
auto spaceRequiredOrError = getSpaceRequired(attrib, count, instances); unsigned int spaceRequired = 0;
if (spaceRequiredOrError.isError()) ANGLE_TRY_RESULT(getSpaceRequired(attrib, count, instances), spaceRequired);
{ setBufferSize(spaceRequired);
return spaceRequiredOrError.getError();
}
setBufferSize(spaceRequiredOrError.getResult());
ASSERT(attrib.enabled); ASSERT(attrib.enabled);
gl::Error error = mVertexBuffer->storeVertexAttributes(attrib, GL_NONE, start, count, instances, ANGLE_TRY(mVertexBuffer->storeVertexAttributes(attrib, GL_NONE, start, count, instances, 0,
0, sourceData); sourceData));
if (!error.isError())
{
mSignature.set(attrib); mSignature.set(attrib);
mVertexBuffer->hintUnmapResource(); mVertexBuffer->hintUnmapResource();
} return gl::NoError();
return error;
} }
} // namespace rx } // namespace rx
...@@ -290,45 +290,28 @@ Buffer11::~Buffer11() ...@@ -290,45 +290,28 @@ Buffer11::~Buffer11()
gl::Error Buffer11::setData(const void *data, size_t size, GLenum usage) gl::Error Buffer11::setData(const void *data, size_t size, GLenum usage)
{ {
updateD3DBufferUsage(usage); updateD3DBufferUsage(usage);
ANGLE_TRY(setSubData(data, size, 0));
gl::Error error = setSubData(data, size, 0); return gl::NoError();
if (error.isError())
{
return error;
}
return error;
} }
gl::Error Buffer11::getData(const uint8_t **outData) gl::Error Buffer11::getData(const uint8_t **outData)
{ {
auto systemOrError = getSystemMemoryStorage(); SystemMemoryStorage *systemMemoryStorage = nullptr;
if (systemOrError.isError()) ANGLE_TRY_RESULT(getSystemMemoryStorage(), systemMemoryStorage);
{
*outData = nullptr;
return systemOrError.getError();
}
SystemMemoryStorage *systemMemoryStorage = systemOrError.getResult();
mReadUsageCount = 0; mReadUsageCount = 0;
ASSERT(systemMemoryStorage->getSize() >= mSize); ASSERT(systemMemoryStorage->getSize() >= mSize);
*outData = systemMemoryStorage->getSystemCopy()->data(); *outData = systemMemoryStorage->getSystemCopy()->data();
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::ErrorOrResult<Buffer11::SystemMemoryStorage *> Buffer11::getSystemMemoryStorage() gl::ErrorOrResult<Buffer11::SystemMemoryStorage *> Buffer11::getSystemMemoryStorage()
{ {
auto systemOrError = getBufferStorage(BUFFER_USAGE_SYSTEM_MEMORY); BufferStorage *storage = nullptr;
if (systemOrError.isError()) ANGLE_TRY_RESULT(getBufferStorage(BUFFER_USAGE_SYSTEM_MEMORY), storage);
{ return GetAs<SystemMemoryStorage>(storage);
return systemOrError.getError();
}
auto resultT = GetAs<SystemMemoryStorage>(systemOrError.getResult());
return resultT;
} }
gl::Error Buffer11::setSubData(const void *data, size_t size, size_t offset) gl::Error Buffer11::setSubData(const void *data, size_t size, size_t offset)
...@@ -342,23 +325,11 @@ gl::Error Buffer11::setSubData(const void *data, size_t size, size_t offset) ...@@ -342,23 +325,11 @@ gl::Error Buffer11::setSubData(const void *data, size_t size, size_t offset)
BufferStorage *writeBuffer = nullptr; BufferStorage *writeBuffer = nullptr;
if (supportsDirectBinding()) if (supportsDirectBinding())
{ {
auto stagingOrError = getStagingStorage(); ANGLE_TRY_RESULT(getStagingStorage(), writeBuffer);
if (stagingOrError.isError())
{
return stagingOrError.getError();
}
writeBuffer = stagingOrError.getResult();
} }
else else
{ {
auto systemOrError = getSystemMemoryStorage(); ANGLE_TRY_RESULT(getSystemMemoryStorage(), writeBuffer);
if (systemOrError.isError())
{
return systemOrError.getError();
}
writeBuffer = systemOrError.getResult();
} }
ASSERT(writeBuffer); ASSERT(writeBuffer);
...@@ -368,11 +339,7 @@ gl::Error Buffer11::setSubData(const void *data, size_t size, size_t offset) ...@@ -368,11 +339,7 @@ gl::Error Buffer11::setSubData(const void *data, size_t size, size_t offset)
if (writeBuffer->getSize() < requiredSize) if (writeBuffer->getSize() < requiredSize)
{ {
bool preserveData = (offset > 0); bool preserveData = (offset > 0);
gl::Error error = writeBuffer->resize(requiredSize, preserveData); ANGLE_TRY(writeBuffer->resize(requiredSize, preserveData));
if (error.isError())
{
return error;
}
} }
writeBuffer->setData(static_cast<const uint8_t *>(data), offset, size); writeBuffer->setData(static_cast<const uint8_t *>(data), offset, size);
...@@ -382,7 +349,7 @@ gl::Error Buffer11::setSubData(const void *data, size_t size, size_t offset) ...@@ -382,7 +349,7 @@ gl::Error Buffer11::setSubData(const void *data, size_t size, size_t offset)
mSize = std::max(mSize, requiredSize); mSize = std::max(mSize, requiredSize);
invalidateStaticData(); invalidateStaticData();
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error Buffer11::copySubData(BufferImpl *source, gl::Error Buffer11::copySubData(BufferImpl *source,
...@@ -393,29 +360,16 @@ gl::Error Buffer11::copySubData(BufferImpl *source, ...@@ -393,29 +360,16 @@ gl::Error Buffer11::copySubData(BufferImpl *source,
Buffer11 *sourceBuffer = GetAs<Buffer11>(source); Buffer11 *sourceBuffer = GetAs<Buffer11>(source);
ASSERT(sourceBuffer != nullptr); ASSERT(sourceBuffer != nullptr);
auto latestOrError = getLatestBufferStorage(); BufferStorage *copyDest = nullptr;
if (latestOrError.isError()) ANGLE_TRY_RESULT(getLatestBufferStorage(), copyDest);
{
return latestOrError.getError();
}
BufferStorage *copyDest = latestOrError.getResult();
if (!copyDest) if (!copyDest)
{ {
auto stagingOrError = getStagingStorage(); ANGLE_TRY_RESULT(getStagingStorage(), copyDest);
if (stagingOrError.isError())
{
return stagingOrError.getError();
}
copyDest = stagingOrError.getResult();
} }
auto sourceLatestOrError = sourceBuffer->getLatestBufferStorage(); BufferStorage *copySource = nullptr;
if (sourceLatestOrError.isError()) ANGLE_TRY_RESULT(sourceBuffer->getLatestBufferStorage(), copySource);
{
return sourceLatestOrError.getError();
}
BufferStorage *copySource = sourceLatestOrError.getResult();
if (!copySource || !copyDest) if (!copySource || !copyDest)
{ {
...@@ -426,21 +380,11 @@ gl::Error Buffer11::copySubData(BufferImpl *source, ...@@ -426,21 +380,11 @@ gl::Error Buffer11::copySubData(BufferImpl *source,
// pack buffer partner, because other native buffers can't be mapped // pack buffer partner, because other native buffers can't be mapped
if (copyDest->getUsage() == BUFFER_USAGE_PIXEL_PACK && !copySource->isMappable()) if (copyDest->getUsage() == BUFFER_USAGE_PIXEL_PACK && !copySource->isMappable())
{ {
auto sourceStagingOrError = sourceBuffer->getStagingStorage(); ANGLE_TRY_RESULT(sourceBuffer->getStagingStorage(), copySource);
if (sourceStagingOrError.isError())
{
return sourceStagingOrError.getError();
}
copySource = sourceStagingOrError.getResult();
} }
else if (copySource->getUsage() == BUFFER_USAGE_PIXEL_PACK && !copyDest->isMappable()) else if (copySource->getUsage() == BUFFER_USAGE_PIXEL_PACK && !copyDest->isMappable())
{ {
auto stagingOrError = getStagingStorage(); ANGLE_TRY_RESULT(getStagingStorage(), copyDest);
if (stagingOrError.isError())
{
return stagingOrError.getError();
}
copyDest = stagingOrError.getResult();
} }
// D3D11 does not allow overlapped copies until 11.1, and only if the // D3D11 does not allow overlapped copies until 11.1, and only if the
...@@ -450,35 +394,24 @@ gl::Error Buffer11::copySubData(BufferImpl *source, ...@@ -450,35 +394,24 @@ gl::Error Buffer11::copySubData(BufferImpl *source,
{ {
if (copySource->getUsage() == BUFFER_USAGE_STAGING) if (copySource->getUsage() == BUFFER_USAGE_STAGING)
{ {
auto vertexOrError = getBufferStorage(BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK); ANGLE_TRY_RESULT(getBufferStorage(BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK),
if (vertexOrError.isError()) copySource);
{
return vertexOrError.getError();
}
copySource = vertexOrError.getResult();
} }
else else
{ {
auto stagingOrError = getStagingStorage(); ANGLE_TRY_RESULT(getStagingStorage(), copySource);
if (stagingOrError.isError())
{
return stagingOrError.getError();
}
copySource = stagingOrError.getResult();
} }
} }
auto resultOrError = copyDest->copyFromStorage(copySource, sourceOffset, size, destOffset); CopyResult copyResult = CopyResult::NOT_RECREATED;
if (resultOrError.isError()) ANGLE_TRY_RESULT(copyDest->copyFromStorage(copySource, sourceOffset, size, destOffset),
{ copyResult);
return resultOrError.getError();
}
copyDest->setDataRevision(copyDest->getDataRevision() + 1); copyDest->setDataRevision(copyDest->getDataRevision() + 1);
mSize = std::max<size_t>(mSize, destOffset + size); mSize = std::max<size_t>(mSize, destOffset + size);
invalidateStaticData(); invalidateStaticData();
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error Buffer11::map(GLenum access, GLvoid **mapPtr) gl::Error Buffer11::map(GLenum access, GLvoid **mapPtr)
...@@ -493,12 +426,9 @@ gl::Error Buffer11::mapRange(size_t offset, size_t length, GLbitfield access, GL ...@@ -493,12 +426,9 @@ gl::Error Buffer11::mapRange(size_t offset, size_t length, GLbitfield access, GL
{ {
ASSERT(!mMappedStorage); ASSERT(!mMappedStorage);
auto latestOrError = getLatestBufferStorage(); BufferStorage *latestStorage = nullptr;
if (latestOrError.isError()) ANGLE_TRY_RESULT(getLatestBufferStorage(), latestStorage);
{
return latestOrError.getError();
}
BufferStorage *latestStorage = latestOrError.getResult();
if (latestStorage && (latestStorage->getUsage() == BUFFER_USAGE_PIXEL_PACK || if (latestStorage && (latestStorage->getUsage() == BUFFER_USAGE_PIXEL_PACK ||
latestStorage->getUsage() == BUFFER_USAGE_STAGING)) latestStorage->getUsage() == BUFFER_USAGE_STAGING))
{ {
...@@ -507,14 +437,9 @@ gl::Error Buffer11::mapRange(size_t offset, size_t length, GLbitfield access, GL ...@@ -507,14 +437,9 @@ gl::Error Buffer11::mapRange(size_t offset, size_t length, GLbitfield access, GL
} }
else else
{ {
// Fall back to using the staging buffer if the latest storage does // Fall back to using the staging buffer if the latest storage does not exist or is not
// not exist or is not CPU-accessible. // CPU-accessible.
auto stagingOrError = getStagingStorage(); ANGLE_TRY_RESULT(getStagingStorage(), mMappedStorage);
if (stagingOrError.isError())
{
return stagingOrError.getError();
}
mMappedStorage = stagingOrError.getResult();
} }
if (!mMappedStorage) if (!mMappedStorage)
...@@ -530,15 +455,11 @@ gl::Error Buffer11::mapRange(size_t offset, size_t length, GLbitfield access, GL ...@@ -530,15 +455,11 @@ gl::Error Buffer11::mapRange(size_t offset, size_t length, GLbitfield access, GL
} }
uint8_t *mappedBuffer = nullptr; uint8_t *mappedBuffer = nullptr;
auto error = mMappedStorage->map(offset, length, access, &mappedBuffer); ANGLE_TRY(mMappedStorage->map(offset, length, access, &mappedBuffer));
if (error.isError())
{
return error;
}
ASSERT(mappedBuffer); ASSERT(mappedBuffer);
*mapPtr = static_cast<GLvoid *>(mappedBuffer); *mapPtr = static_cast<GLvoid *>(mappedBuffer);
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error Buffer11::unmap(GLboolean *result) gl::Error Buffer11::unmap(GLboolean *result)
...@@ -550,25 +471,22 @@ gl::Error Buffer11::unmap(GLboolean *result) ...@@ -550,25 +471,22 @@ gl::Error Buffer11::unmap(GLboolean *result)
// TODO: detect if we had corruption. if so, return false. // TODO: detect if we had corruption. if so, return false.
*result = GL_TRUE; *result = GL_TRUE;
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error Buffer11::markTransformFeedbackUsage() gl::Error Buffer11::markTransformFeedbackUsage()
{ {
auto tfOrError = getBufferStorage(BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK); BufferStorage *transformFeedbackStorage = nullptr;
if (tfOrError.isError()) ANGLE_TRY_RESULT(getBufferStorage(BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK),
{ transformFeedbackStorage);
return tfOrError.getError();
}
BufferStorage *transformFeedbackStorage = tfOrError.getResult();
if (transformFeedbackStorage) if (transformFeedbackStorage)
{ {
transformFeedbackStorage->setDataRevision(transformFeedbackStorage->getDataRevision() + 1); transformFeedbackStorage->setDataRevision(transformFeedbackStorage->getDataRevision() + 1);
} }
invalidateStaticData(); invalidateStaticData();
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error Buffer11::markBufferUsage() gl::Error Buffer11::markBufferUsage()
...@@ -581,93 +499,58 @@ gl::Error Buffer11::markBufferUsage() ...@@ -581,93 +499,58 @@ gl::Error Buffer11::markBufferUsage()
BufferStorage *&sysMemUsage = mBufferStorages[BUFFER_USAGE_SYSTEM_MEMORY]; BufferStorage *&sysMemUsage = mBufferStorages[BUFFER_USAGE_SYSTEM_MEMORY];
if (mReadUsageCount > usageLimit && sysMemUsage != nullptr) if (mReadUsageCount > usageLimit && sysMemUsage != nullptr)
{ {
auto latestOrError = getLatestBufferStorage(); BufferStorage *latestStorage = nullptr;
if (latestOrError.isError()) ANGLE_TRY_RESULT(getLatestBufferStorage(), latestStorage);
{ if (latestStorage != sysMemUsage)
return latestOrError.getError();
}
if (latestOrError.getResult() != sysMemUsage)
{ {
SafeDelete(sysMemUsage); SafeDelete(sysMemUsage);
} }
} }
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getBuffer(BufferUsage usage) gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getBuffer(BufferUsage usage)
{ {
gl::Error error = markBufferUsage(); ANGLE_TRY(markBufferUsage());
if (error.isError())
{
return error;
}
auto bufferOrError = getBufferStorage(usage); BufferStorage *storage = nullptr;
if (bufferOrError.isError()) ANGLE_TRY_RESULT(getBufferStorage(usage), storage);
{ return GetAs<NativeStorage>(storage)->getNativeStorage();
return bufferOrError.getError();
}
return GetAs<NativeStorage>(bufferOrError.getResult())->getNativeStorage();
} }
gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getEmulatedIndexedBuffer( gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getEmulatedIndexedBuffer(
SourceIndexData *indexInfo, SourceIndexData *indexInfo,
const TranslatedAttribute &attribute) const TranslatedAttribute &attribute)
{ {
gl::Error error = markBufferUsage();
if (error.isError())
{
return error;
}
ASSERT(indexInfo); ASSERT(indexInfo);
auto emulatedOrError = getBufferStorage(BUFFER_USAGE_EMULATED_INDEXED_VERTEX); ANGLE_TRY(markBufferUsage());
if (emulatedOrError.isError())
{
return emulatedOrError.getError();
}
EmulatedIndexedStorage *emulatedStorage = BufferStorage *untypedStorage = nullptr;
GetAs<EmulatedIndexedStorage>(emulatedOrError.getResult()); ANGLE_TRY_RESULT(getBufferStorage(BUFFER_USAGE_EMULATED_INDEXED_VERTEX), untypedStorage);
auto errorOrResult = emulatedStorage->getNativeStorage(indexInfo, attribute);
if (errorOrResult.isError()) EmulatedIndexedStorage *emulatedStorage = GetAs<EmulatedIndexedStorage>(untypedStorage);
{
return errorOrResult.getError(); ID3D11Buffer *nativeStorage = nullptr;
} ANGLE_TRY_RESULT(emulatedStorage->getNativeStorage(indexInfo, attribute), nativeStorage);
return errorOrResult.getResult(); return nativeStorage;
} }
gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getConstantBufferRange(GLintptr offset, GLsizeiptr size) gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getConstantBufferRange(GLintptr offset, GLsizeiptr size)
{ {
gl::Error error = markBufferUsage(); ANGLE_TRY(markBufferUsage());
if (error.isError())
{
return error;
}
BufferStorage *bufferStorage; BufferStorage *bufferStorage = nullptr;
if (offset == 0) if (offset == 0)
{ {
auto uniformOrError = getBufferStorage(BUFFER_USAGE_UNIFORM); ANGLE_TRY_RESULT(getBufferStorage(BUFFER_USAGE_UNIFORM), bufferStorage);
if (uniformOrError.isError())
{
return uniformOrError.getError();
}
bufferStorage = uniformOrError.getResult();
} }
else else
{ {
auto constantOrError = getConstantBufferRangeStorage(offset, size); ANGLE_TRY_RESULT(getConstantBufferRangeStorage(offset, size), bufferStorage);
if (constantOrError.isError())
{
return constantOrError.getError();
}
bufferStorage = constantOrError.getResult();
} }
return GetAs<NativeStorage>(bufferStorage)->getNativeStorage(); return GetAs<NativeStorage>(bufferStorage)->getNativeStorage();
...@@ -675,12 +558,8 @@ gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getConstantBufferRange(GLintptr offs ...@@ -675,12 +558,8 @@ gl::ErrorOrResult<ID3D11Buffer *> Buffer11::getConstantBufferRange(GLintptr offs
gl::ErrorOrResult<ID3D11ShaderResourceView *> Buffer11::getSRV(DXGI_FORMAT srvFormat) gl::ErrorOrResult<ID3D11ShaderResourceView *> Buffer11::getSRV(DXGI_FORMAT srvFormat)
{ {
auto unpackOrError = getBufferStorage(BUFFER_USAGE_PIXEL_UNPACK); BufferStorage *storage = nullptr;
if (unpackOrError.isError()) ANGLE_TRY_RESULT(getBufferStorage(BUFFER_USAGE_PIXEL_UNPACK), storage);
{
return unpackOrError.getError();
}
BufferStorage *storage = unpackOrError.getResult();
ID3D11Buffer *buffer = GetAs<NativeStorage>(storage)->getNativeStorage(); ID3D11Buffer *buffer = GetAs<NativeStorage>(storage)->getNativeStorage();
auto bufferSRVIt = mBufferResourceViews.find(srvFormat); auto bufferSRVIt = mBufferResourceViews.find(srvFormat);
...@@ -722,29 +601,17 @@ gl::ErrorOrResult<ID3D11ShaderResourceView *> Buffer11::getSRV(DXGI_FORMAT srvFo ...@@ -722,29 +601,17 @@ gl::ErrorOrResult<ID3D11ShaderResourceView *> Buffer11::getSRV(DXGI_FORMAT srvFo
gl::Error Buffer11::packPixels(const gl::FramebufferAttachment &readAttachment, gl::Error Buffer11::packPixels(const gl::FramebufferAttachment &readAttachment,
const PackPixelsParams &params) const PackPixelsParams &params)
{ {
auto packOrError = getPackStorage(); PackStorage *packStorage = nullptr;
if (packOrError.isError()) ANGLE_TRY_RESULT(getPackStorage(), packStorage);
{
return packOrError.getError();
}
PackStorage *packStorage = packOrError.getResult();
auto latestOrError = getLatestBufferStorage(); BufferStorage *latestStorage = nullptr;
if (latestOrError.isError()) ANGLE_TRY_RESULT(getLatestBufferStorage(), latestStorage);
{
return latestOrError.getError();
}
BufferStorage *latestStorage = latestOrError.getResult();
ASSERT(packStorage); ASSERT(packStorage);
gl::Error error = packStorage->packPixels(readAttachment, params); ANGLE_TRY(packStorage->packPixels(readAttachment, params));
if (error.isError())
{
return error;
}
packStorage->setDataRevision(latestStorage ? latestStorage->getDataRevision() + 1 : 1); packStorage->setDataRevision(latestStorage ? latestStorage->getDataRevision() + 1 : 1);
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
size_t Buffer11::getTotalCPUBufferMemoryBytes() const size_t Buffer11::getTotalCPUBufferMemoryBytes() const
...@@ -789,18 +656,10 @@ gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getBufferStorage(BufferUs ...@@ -789,18 +656,10 @@ gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getBufferStorage(BufferUs
// resize buffer // resize buffer
if (newStorage->getSize() < mSize) if (newStorage->getSize() < mSize)
{ {
auto error = newStorage->resize(mSize, true); ANGLE_TRY(newStorage->resize(mSize, true));
if (error.isError())
{
return error;
}
} }
auto error = updateBufferStorage(newStorage, 0, mSize); ANGLE_TRY(updateBufferStorage(newStorage, 0, mSize));
if (error.isError())
{
return error;
}
return newStorage; return newStorage;
} }
...@@ -850,12 +709,7 @@ gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getConstantBufferRangeSto ...@@ -850,12 +709,7 @@ gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getConstantBufferRangeSto
mConstantBufferRangeStoragesCache.erase(iter); mConstantBufferRangeStoragesCache.erase(iter);
} }
auto error = newStorage->resize(size, false); ANGLE_TRY(newStorage->resize(size, false));
if (error.isError())
{
return error;
}
mConstantBufferStorageAdditionalSize += sizeDelta; mConstantBufferStorageAdditionalSize += sizeDelta;
// We don't copy the old data when resizing the constant buffer because the data may be // We don't copy the old data when resizing the constant buffer because the data may be
...@@ -864,12 +718,7 @@ gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getConstantBufferRangeSto ...@@ -864,12 +718,7 @@ gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getConstantBufferRangeSto
newStorage->setDataRevision(0); newStorage->setDataRevision(0);
} }
auto error = updateBufferStorage(newStorage, offset, size); ANGLE_TRY(updateBufferStorage(newStorage, offset, size));
if (error.isError())
{
return error;
}
return newStorage; return newStorage;
} }
...@@ -877,13 +726,9 @@ gl::Error Buffer11::updateBufferStorage(BufferStorage *storage, ...@@ -877,13 +726,9 @@ gl::Error Buffer11::updateBufferStorage(BufferStorage *storage,
size_t sourceOffset, size_t sourceOffset,
size_t storageSize) size_t storageSize)
{ {
auto latestOrError = getLatestBufferStorage(); BufferStorage *latestBuffer = nullptr;
if (latestOrError.isError()) ANGLE_TRY_RESULT(getLatestBufferStorage(), latestBuffer);
{
return latestOrError.getError();
}
BufferStorage *latestBuffer = latestOrError.getResult();
if (latestBuffer && latestBuffer->getDataRevision() > storage->getDataRevision()) if (latestBuffer && latestBuffer->getDataRevision() > storage->getDataRevision())
{ {
// Copy through a staging buffer if we're copying from or to a non-staging, mappable // Copy through a staging buffer if we're copying from or to a non-staging, mappable
...@@ -893,38 +738,30 @@ gl::Error Buffer11::updateBufferStorage(BufferStorage *storage, ...@@ -893,38 +738,30 @@ gl::Error Buffer11::updateBufferStorage(BufferStorage *storage,
storage->getUsage() != BUFFER_USAGE_STAGING && storage->getUsage() != BUFFER_USAGE_STAGING &&
(!latestBuffer->isMappable() || !storage->isMappable())) (!latestBuffer->isMappable() || !storage->isMappable()))
{ {
auto stagingOrError = getStagingStorage(); NativeStorage *stagingBuffer = nullptr;
if (stagingOrError.isError()) ANGLE_TRY_RESULT(getStagingStorage(), stagingBuffer);
{
return stagingOrError.getError();
}
NativeStorage *stagingBuffer = stagingOrError.getResult();
auto resultOrError = CopyResult copyResult = CopyResult::NOT_RECREATED;
stagingBuffer->copyFromStorage(latestBuffer, 0, latestBuffer->getSize(), 0); ANGLE_TRY_RESULT(
if (resultOrError.isError()) stagingBuffer->copyFromStorage(latestBuffer, 0, latestBuffer->getSize(), 0),
{ copyResult);
return resultOrError.getError();
}
stagingBuffer->setDataRevision(latestBuffer->getDataRevision()); stagingBuffer->setDataRevision(latestBuffer->getDataRevision());
latestBuffer = stagingBuffer; latestBuffer = stagingBuffer;
} }
auto resultOrError = storage->copyFromStorage(latestBuffer, sourceOffset, storageSize, 0); CopyResult copyResult = CopyResult::NOT_RECREATED;
if (resultOrError.isError()) ANGLE_TRY_RESULT(storage->copyFromStorage(latestBuffer, sourceOffset, storageSize, 0),
{ copyResult);
return resultOrError.getError();
}
// If the D3D buffer has been recreated, we should update our serial. // If the D3D buffer has been recreated, we should update our serial.
if (resultOrError.getResult() == CopyResult::RECREATED) if (copyResult == CopyResult::RECREATED)
{ {
updateSerial(); updateSerial();
} }
storage->setDataRevision(latestBuffer->getDataRevision()); storage->setDataRevision(latestBuffer->getDataRevision());
} }
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getLatestBufferStorage() const gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getLatestBufferStorage() const
...@@ -945,11 +782,7 @@ gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getLatestBufferStorage() ...@@ -945,11 +782,7 @@ gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getLatestBufferStorage()
// resize buffer // resize buffer
if (latestStorage && latestStorage->getSize() < mSize) if (latestStorage && latestStorage->getSize() < mSize)
{ {
auto error = latestStorage->resize(mSize, true); ANGLE_TRY(latestStorage->resize(mSize, true));
if (error.isError())
{
return error;
}
} }
return latestStorage; return latestStorage;
...@@ -957,24 +790,16 @@ gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getLatestBufferStorage() ...@@ -957,24 +790,16 @@ gl::ErrorOrResult<Buffer11::BufferStorage *> Buffer11::getLatestBufferStorage()
gl::ErrorOrResult<Buffer11::NativeStorage *> Buffer11::getStagingStorage() gl::ErrorOrResult<Buffer11::NativeStorage *> Buffer11::getStagingStorage()
{ {
auto stagingOrError = getBufferStorage(BUFFER_USAGE_STAGING); BufferStorage *stagingStorage = nullptr;
if (stagingOrError.isError()) ANGLE_TRY_RESULT(getBufferStorage(BUFFER_USAGE_STAGING), stagingStorage);
{ return GetAs<NativeStorage>(stagingStorage);
return stagingOrError.getError();
}
return GetAs<NativeStorage>(stagingOrError.getResult());
} }
gl::ErrorOrResult<Buffer11::PackStorage *> Buffer11::getPackStorage() gl::ErrorOrResult<Buffer11::PackStorage *> Buffer11::getPackStorage()
{ {
auto packOrError = getBufferStorage(BUFFER_USAGE_PIXEL_PACK); BufferStorage *packStorage = nullptr;
if (packOrError.isError()) ANGLE_TRY_RESULT(getBufferStorage(BUFFER_USAGE_PIXEL_PACK), packStorage);
{ return GetAs<PackStorage>(packStorage);
return packOrError.getError();
}
return GetAs<PackStorage>(packOrError.getResult());
} }
bool Buffer11::supportsDirectBinding() const bool Buffer11::supportsDirectBinding() const
...@@ -995,17 +820,13 @@ gl::Error Buffer11::BufferStorage::setData(const uint8_t *data, size_t offset, s ...@@ -995,17 +820,13 @@ gl::Error Buffer11::BufferStorage::setData(const uint8_t *data, size_t offset, s
ASSERT(isMappable()); ASSERT(isMappable());
uint8_t *writePointer = nullptr; uint8_t *writePointer = nullptr;
gl::Error error = map(offset, size, GL_MAP_WRITE_BIT, &writePointer); ANGLE_TRY(map(offset, size, GL_MAP_WRITE_BIT, &writePointer));
if (error.isError())
{
return error;
}
memcpy(writePointer, data, size); memcpy(writePointer, data, size);
unmap(); unmap();
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
Buffer11::NativeStorage::NativeStorage(Renderer11 *renderer, BufferUsage usage) Buffer11::NativeStorage::NativeStorage(Renderer11 *renderer, BufferUsage usage)
...@@ -1042,11 +863,7 @@ gl::ErrorOrResult<CopyResult> Buffer11::NativeStorage::copyFromStorage(BufferSto ...@@ -1042,11 +863,7 @@ gl::ErrorOrResult<CopyResult> Buffer11::NativeStorage::copyFromStorage(BufferSto
ASSERT(source->isMappable()); ASSERT(source->isMappable());
uint8_t *sourcePointer = nullptr; uint8_t *sourcePointer = nullptr;
gl::Error error = source->map(sourceOffset, size, GL_MAP_READ_BIT, &sourcePointer); ANGLE_TRY(source->map(sourceOffset, size, GL_MAP_READ_BIT, &sourcePointer));
if (error.isError())
{
return error;
}
D3D11_MAPPED_SUBRESOURCE mappedResource; D3D11_MAPPED_SUBRESOURCE mappedResource;
HRESULT hr = context->Map(mNativeStorage, 0, D3D11_MAP_WRITE, 0, &mappedResource); HRESULT hr = context->Map(mNativeStorage, 0, D3D11_MAP_WRITE, 0, &mappedResource);
...@@ -1128,7 +945,7 @@ gl::Error Buffer11::NativeStorage::resize(size_t size, bool preserveData) ...@@ -1128,7 +945,7 @@ gl::Error Buffer11::NativeStorage::resize(size_t size, bool preserveData)
mBufferSize = bufferDesc.ByteWidth; mBufferSize = bufferDesc.ByteWidth;
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
void Buffer11::NativeStorage::fillBufferDesc(D3D11_BUFFER_DESC *bufferDesc, void Buffer11::NativeStorage::fillBufferDesc(D3D11_BUFFER_DESC *bufferDesc,
...@@ -1353,11 +1170,7 @@ gl::ErrorOrResult<CopyResult> Buffer11::EmulatedIndexedStorage::copyFromStorage( ...@@ -1353,11 +1170,7 @@ gl::ErrorOrResult<CopyResult> Buffer11::EmulatedIndexedStorage::copyFromStorage(
{ {
ASSERT(source->isMappable()); ASSERT(source->isMappable());
uint8_t *sourceData = nullptr; uint8_t *sourceData = nullptr;
gl::Error error = source->map(sourceOffset, size, GL_MAP_READ_BIT, &sourceData); ANGLE_TRY(source->map(sourceOffset, size, GL_MAP_READ_BIT, &sourceData));
if (error.isError())
{
return error;
}
ASSERT(destOffset + size <= mMemoryBuffer.size()); ASSERT(destOffset + size <= mMemoryBuffer.size());
memcpy(mMemoryBuffer.data() + destOffset, sourceData, size); memcpy(mMemoryBuffer.data() + destOffset, sourceData, size);
source->unmap(); source->unmap();
...@@ -1438,11 +1251,7 @@ gl::Error Buffer11::PackStorage::map(size_t offset, ...@@ -1438,11 +1251,7 @@ gl::Error Buffer11::PackStorage::map(size_t offset,
// and if D3D packs the staging texture memory identically to how we would fill // and if D3D packs the staging texture memory identically to how we would fill
// the pack buffer according to the current pack state. // the pack buffer according to the current pack state.
gl::Error error = flushQueuedPackCommand(); ANGLE_TRY(flushQueuedPackCommand());
if (error.isError())
{
return error;
}
mDataModified = (mDataModified || (access & GL_MAP_WRITE_BIT) != 0); mDataModified = (mDataModified || (access & GL_MAP_WRITE_BIT) != 0);
...@@ -1458,18 +1267,10 @@ void Buffer11::PackStorage::unmap() ...@@ -1458,18 +1267,10 @@ void Buffer11::PackStorage::unmap()
gl::Error Buffer11::PackStorage::packPixels(const gl::FramebufferAttachment &readAttachment, gl::Error Buffer11::PackStorage::packPixels(const gl::FramebufferAttachment &readAttachment,
const PackPixelsParams &params) const PackPixelsParams &params)
{ {
gl::Error error = flushQueuedPackCommand(); ANGLE_TRY(flushQueuedPackCommand());
if (error.isError())
{
return error;
}
RenderTarget11 *renderTarget = nullptr; RenderTarget11 *renderTarget = nullptr;
error = readAttachment.getRenderTarget(&renderTarget); ANGLE_TRY(readAttachment.getRenderTarget(&renderTarget));
if (error.isError())
{
return error;
}
ID3D11Resource *renderTargetResource = renderTarget->getTexture(); ID3D11Resource *renderTargetResource = renderTarget->getTexture();
ASSERT(renderTargetResource); ASSERT(renderTargetResource);
...@@ -1484,14 +1285,10 @@ gl::Error Buffer11::PackStorage::packPixels(const gl::FramebufferAttachment &rea ...@@ -1484,14 +1285,10 @@ gl::Error Buffer11::PackStorage::packPixels(const gl::FramebufferAttachment &rea
if (!mStagingTexture.getResource() || mStagingTexture.getFormat() != srcTexture.getFormat() || if (!mStagingTexture.getResource() || mStagingTexture.getFormat() != srcTexture.getFormat() ||
mStagingTexture.getExtents() != srcTextureSize) mStagingTexture.getExtents() != srcTextureSize)
{ {
auto textureOrError = CreateStagingTexture( ANGLE_TRY_RESULT(CreateStagingTexture(srcTexture.getTextureType(), srcTexture.getFormat(),
srcTexture.getTextureType(), srcTexture.getFormat(), srcTexture.getANGLEFormat(), srcTexture.getANGLEFormat(), srcTextureSize,
srcTextureSize, mRenderer->getDevice()); mRenderer->getDevice()),
if (textureOrError.isError()) mStagingTexture);
{
return textureOrError.getError();
}
mStagingTexture = std::move(textureOrError.getResult());
} }
// ReadPixels from multisampled FBOs isn't supported in current GL // ReadPixels from multisampled FBOs isn't supported in current GL
...@@ -1516,7 +1313,7 @@ gl::Error Buffer11::PackStorage::packPixels(const gl::FramebufferAttachment &rea ...@@ -1516,7 +1313,7 @@ gl::Error Buffer11::PackStorage::packPixels(const gl::FramebufferAttachment &rea
immediateContext->CopySubresourceRegion(mStagingTexture.getResource(), 0, 0, 0, 0, immediateContext->CopySubresourceRegion(mStagingTexture.getResource(), 0, 0, 0, 0,
srcTexture.getResource(), srcSubresource, &srcBox); srcTexture.getResource(), srcSubresource, &srcBox);
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error Buffer11::PackStorage::flushQueuedPackCommand() gl::Error Buffer11::PackStorage::flushQueuedPackCommand()
...@@ -1525,16 +1322,12 @@ gl::Error Buffer11::PackStorage::flushQueuedPackCommand() ...@@ -1525,16 +1322,12 @@ gl::Error Buffer11::PackStorage::flushQueuedPackCommand()
if (mQueuedPackCommand) if (mQueuedPackCommand)
{ {
gl::Error error = ANGLE_TRY(
mRenderer->packPixels(mStagingTexture, *mQueuedPackCommand, mMemoryBuffer.data()); mRenderer->packPixels(mStagingTexture, *mQueuedPackCommand, mMemoryBuffer.data()));
mQueuedPackCommand.reset(nullptr); mQueuedPackCommand.reset(nullptr);
if (error.isError())
{
return error;
}
} }
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
Buffer11::SystemMemoryStorage::SystemMemoryStorage(Renderer11 *renderer) Buffer11::SystemMemoryStorage::SystemMemoryStorage(Renderer11 *renderer)
...@@ -1549,11 +1342,7 @@ gl::ErrorOrResult<CopyResult> Buffer11::SystemMemoryStorage::copyFromStorage(Buf ...@@ -1549,11 +1342,7 @@ gl::ErrorOrResult<CopyResult> Buffer11::SystemMemoryStorage::copyFromStorage(Buf
{ {
ASSERT(source->isMappable()); ASSERT(source->isMappable());
uint8_t *sourceData = nullptr; uint8_t *sourceData = nullptr;
gl::Error error = source->map(sourceOffset, size, GL_MAP_READ_BIT, &sourceData); ANGLE_TRY(source->map(sourceOffset, size, GL_MAP_READ_BIT, &sourceData));
if (error.isError())
{
return error;
}
ASSERT(destOffset + size <= mSystemCopy.size()); ASSERT(destOffset + size <= mSystemCopy.size());
memcpy(mSystemCopy.data() + destOffset, sourceData, size); memcpy(mSystemCopy.data() + destOffset, sourceData, size);
source->unmap(); source->unmap();
...@@ -1571,7 +1360,7 @@ gl::Error Buffer11::SystemMemoryStorage::resize(size_t size, bool preserveData) ...@@ -1571,7 +1360,7 @@ gl::Error Buffer11::SystemMemoryStorage::resize(size_t size, bool preserveData)
mBufferSize = size; mBufferSize = size;
} }
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error Buffer11::SystemMemoryStorage::map(size_t offset, gl::Error Buffer11::SystemMemoryStorage::map(size_t offset,
......
...@@ -241,11 +241,7 @@ gl::Error InputLayoutCache::applyVertexBuffers( ...@@ -241,11 +241,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(
} }
} }
gl::Error error = updateInputLayout(state, mode, sortedSemanticIndices, numIndicesPerInstance); ANGLE_TRY(updateInputLayout(state, mode, sortedSemanticIndices, numIndicesPerInstance));
if (error.isError())
{
return error;
}
bool dirtyBuffers = false; bool dirtyBuffers = false;
size_t minDiff = gl::MAX_VERTEX_ATTRIBS; size_t minDiff = gl::MAX_VERTEX_ATTRIBS;
...@@ -280,11 +276,7 @@ gl::Error InputLayoutCache::applyVertexBuffers( ...@@ -280,11 +276,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(
if (indexInfo->srcIndexData.srcBuffer != nullptr) if (indexInfo->srcIndexData.srcBuffer != nullptr)
{ {
const uint8_t *bufferData = nullptr; const uint8_t *bufferData = nullptr;
error = indexInfo->srcIndexData.srcBuffer->getData(&bufferData); ANGLE_TRY(indexInfo->srcIndexData.srcBuffer->getData(&bufferData));
if (error.isError())
{
return error;
}
ASSERT(bufferData != nullptr); ASSERT(bufferData != nullptr);
ptrdiff_t offset = ptrdiff_t offset =
...@@ -293,23 +285,14 @@ gl::Error InputLayoutCache::applyVertexBuffers( ...@@ -293,23 +285,14 @@ gl::Error InputLayoutCache::applyVertexBuffers(
indexInfo->srcIndexData.srcIndices = bufferData + offset; indexInfo->srcIndexData.srcIndices = bufferData + offset;
} }
auto bufferOrError = ANGLE_TRY_RESULT(
bufferStorage->getEmulatedIndexedBuffer(&indexInfo->srcIndexData, attrib); bufferStorage->getEmulatedIndexedBuffer(&indexInfo->srcIndexData, attrib),
if (bufferOrError.isError()) buffer);
{
return bufferOrError.getError();
}
buffer = bufferOrError.getResult();
} }
else else
{ {
auto bufferOrError = ANGLE_TRY_RESULT(
bufferStorage->getBuffer(BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK); bufferStorage->getBuffer(BUFFER_USAGE_VERTEX_OR_TRANSFORM_FEEDBACK), buffer);
if (bufferOrError.isError())
{
return bufferOrError.getError();
}
buffer = bufferOrError.getResult();
} }
vertexStride = attrib.stride; vertexStride = attrib.stride;
...@@ -428,7 +411,7 @@ gl::Error InputLayoutCache::applyVertexBuffers( ...@@ -428,7 +411,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(
&mCurrentVertexOffsets[minDiff]); &mCurrentVertexOffsets[minDiff]);
} }
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error InputLayoutCache::updateVertexOffsetsForPointSpritesEmulation(GLsizei emulatedInstanceId) gl::Error InputLayoutCache::updateVertexOffsetsForPointSpritesEmulation(GLsizei emulatedInstanceId)
...@@ -449,7 +432,7 @@ gl::Error InputLayoutCache::updateVertexOffsetsForPointSpritesEmulation(GLsizei ...@@ -449,7 +432,7 @@ gl::Error InputLayoutCache::updateVertexOffsetsForPointSpritesEmulation(GLsizei
mDeviceContext->IASetVertexBuffers(0, gl::MAX_VERTEX_ATTRIBS, mCurrentBuffers.data(), mDeviceContext->IASetVertexBuffers(0, gl::MAX_VERTEX_ATTRIBS, mCurrentBuffers.data(),
mCurrentVertexStrides.data(), mCurrentVertexOffsets.data()); mCurrentVertexStrides.data(), mCurrentVertexOffsets.data());
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error InputLayoutCache::updateInputLayout(const gl::State &state, gl::Error InputLayoutCache::updateInputLayout(const gl::State &state,
...@@ -509,12 +492,8 @@ gl::Error InputLayoutCache::updateInputLayout(const gl::State &state, ...@@ -509,12 +492,8 @@ gl::Error InputLayoutCache::updateInputLayout(const gl::State &state,
} }
else else
{ {
gl::Error error = createInputLayout(sortedSemanticIndices, mode, program, ANGLE_TRY(createInputLayout(sortedSemanticIndices, mode, program, numIndicesPerInstance,
numIndicesPerInstance, &inputLayout); &inputLayout));
if (error.isError())
{
return error;
}
if (mLayoutMap.size() >= mCacheSize) if (mLayoutMap.size() >= mCacheSize)
{ {
TRACE("Overflowed the limit of %u input layouts, purging half the cache.", TRACE("Overflowed the limit of %u input layouts, purging half the cache.",
...@@ -544,7 +523,7 @@ gl::Error InputLayoutCache::updateInputLayout(const gl::State &state, ...@@ -544,7 +523,7 @@ gl::Error InputLayoutCache::updateInputLayout(const gl::State &state,
mCurrentIL = inputLayout; mCurrentIL = inputLayout;
} }
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error InputLayoutCache::createInputLayout(const AttribIndexArray &sortedSemanticIndices, gl::Error InputLayoutCache::createInputLayout(const AttribIndexArray &sortedSemanticIndices,
...@@ -636,12 +615,7 @@ gl::Error InputLayoutCache::createInputLayout(const AttribIndexArray &sortedSema ...@@ -636,12 +615,7 @@ gl::Error InputLayoutCache::createInputLayout(const AttribIndexArray &sortedSema
const gl::InputLayout &shaderInputLayout = GetInputLayout(mCurrentAttributes); const gl::InputLayout &shaderInputLayout = GetInputLayout(mCurrentAttributes);
ShaderExecutableD3D *shader = nullptr; ShaderExecutableD3D *shader = nullptr;
gl::Error error = ANGLE_TRY(programD3D->getVertexExecutableForInputLayout(shaderInputLayout, &shader, nullptr));
programD3D->getVertexExecutableForInputLayout(shaderInputLayout, &shader, nullptr);
if (error.isError())
{
return error;
}
ShaderExecutableD3D *shader11 = GetAs<ShaderExecutable11>(shader); ShaderExecutableD3D *shader11 = GetAs<ShaderExecutable11>(shader);
...@@ -654,7 +628,7 @@ gl::Error InputLayoutCache::createInputLayout(const AttribIndexArray &sortedSema ...@@ -654,7 +628,7 @@ gl::Error InputLayoutCache::createInputLayout(const AttribIndexArray &sortedSema
"Failed to create internal input layout, HRESULT: 0x%08x", result); "Failed to create internal input layout, HRESULT: 0x%08x", result);
} }
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
} // namespace rx } // namespace rx
...@@ -64,7 +64,7 @@ gl::Error PixelTransfer11::loadResources() ...@@ -64,7 +64,7 @@ gl::Error PixelTransfer11::loadResources()
{ {
if (mResourcesLoaded) if (mResourcesLoaded)
{ {
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
HRESULT result = S_OK; HRESULT result = S_OK;
...@@ -141,17 +141,13 @@ gl::Error PixelTransfer11::loadResources() ...@@ -141,17 +141,13 @@ gl::Error PixelTransfer11::loadResources()
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal buffer to texture geometry shader."); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal buffer to texture geometry shader.");
} }
gl::Error error = buildShaderMap(); ANGLE_TRY(buildShaderMap());
if (error.isError())
{
return error;
}
StructZero(&mParamsData); StructZero(&mParamsData);
mResourcesLoaded = true; mResourcesLoaded = true;
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat, 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 ...@@ -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, gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTargetD3D *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea) GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea)
{ {
gl::Error error = loadResources(); ANGLE_TRY(loadResources());
if (error.isError())
{
return error;
}
gl::Extents destSize = destRenderTarget->getExtents(); gl::Extents destSize = destRenderTarget->getExtents();
...@@ -208,12 +200,8 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpac ...@@ -208,12 +200,8 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpac
DXGI_FORMAT srvFormat = sourceFormatInfo.formatSet->srvFormat; DXGI_FORMAT srvFormat = sourceFormatInfo.formatSet->srvFormat;
ASSERT(srvFormat != DXGI_FORMAT_UNKNOWN); ASSERT(srvFormat != DXGI_FORMAT_UNKNOWN);
Buffer11 *bufferStorage11 = GetAs<Buffer11>(sourceBuffer.getImplementation()); Buffer11 *bufferStorage11 = GetAs<Buffer11>(sourceBuffer.getImplementation());
auto srvOrError = bufferStorage11->getSRV(srvFormat); ID3D11ShaderResourceView *bufferSRV = nullptr;
if (srvOrError.isError()) ANGLE_TRY_RESULT(bufferStorage11->getSRV(srvFormat), bufferSRV);
{
return srvOrError.getError();
}
ID3D11ShaderResourceView *bufferSRV = srvOrError.getResult();
ASSERT(bufferSRV != nullptr); ASSERT(bufferSRV != nullptr);
ID3D11RenderTargetView *textureRTV = GetAs<RenderTarget11>(destRenderTarget)->getRenderTargetView(); ID3D11RenderTargetView *textureRTV = GetAs<RenderTarget11>(destRenderTarget)->getRenderTargetView();
...@@ -272,7 +260,7 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpac ...@@ -272,7 +260,7 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpac
mRenderer->markAllStateDirty(); mRenderer->markAllStateDirty();
return gl::Error(GL_NO_ERROR); return gl::NoError();
} }
gl::Error PixelTransfer11::buildShaderMap() gl::Error PixelTransfer11::buildShaderMap()
...@@ -292,7 +280,7 @@ 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 ID3D11PixelShader *PixelTransfer11::findBufferToTexturePS(GLenum internalFormat) const
...@@ -307,4 +295,4 @@ ID3D11PixelShader *PixelTransfer11::findBufferToTexturePS(GLenum internalFormat) ...@@ -307,4 +295,4 @@ ID3D11PixelShader *PixelTransfer11::findBufferToTexturePS(GLenum internalFormat)
return (shaderMapIt == mBufferToTexturePSMap.end() ? NULL : shaderMapIt->second); 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