diff --git a/src/common/angleutils.h b/src/common/angleutils.h index b2df6791c..1c601c12d 100644 --- a/src/common/angleutils.h +++ b/src/common/angleutils.h @@ -253,6 +253,10 @@ std::string ToString(const T &value) // TODO(jmadill): Clean this up at some point. #define EGL_PLATFORM_ANGLE_PLATFORM_METHODS_ANGLEX 0x9999 +// This internal enum is used to filter internal errors that are already handled. +// TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491 +#define GL_INTERNAL_ERROR_ANGLEX 0x6AEE + #define ANGLE_TRY_CHECKED_MATH(result) \ if (!result) \ { \ diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp index a26351067..80a90d769 100644 --- a/src/libANGLE/Context.cpp +++ b/src/libANGLE/Context.cpp @@ -330,6 +330,7 @@ Context::Context(rx::EGLImplFactory *implFactory, memoryProgramCache != nullptr), mConfig(config), mClientType(EGL_OPENGL_ES_API), + mErrors(this), mHasBeenCurrent(false), mContextLost(false), mResetStatus(GL_NO_ERROR), @@ -2541,21 +2542,9 @@ void Context::getProgramInterfaceivRobust(GLuint program, UNIMPLEMENTED(); } -void Context::handleError(const Error &error) const +void Context::handleError(const Error &error) { - if (ANGLE_UNLIKELY(error.isError())) - { - GLenum code = error.getCode(); - mErrors.insert(code); - if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory) - { - markContextLost(); - } - - ASSERT(!error.getMessage().empty()); - mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(), - GL_DEBUG_SEVERITY_HIGH, error.getMessage()); - } + mErrors.handleError(error); } // Get one of the recorded errors and clear its flag, if any. @@ -2568,14 +2557,12 @@ GLenum Context::getError() } else { - GLenum error = *mErrors.begin(); - mErrors.erase(mErrors.begin()); - return error; + return mErrors.popError(); } } // NOTE: this function should not assume that this context is current! -void Context::markContextLost() const +void Context::markContextLost() { if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT) { @@ -7542,4 +7529,48 @@ void Context::maxShaderCompilerThreads(GLuint count) mGLState.setMaxShaderCompilerThreads(count); } +// ErrorSet implementation. +ErrorSet::ErrorSet(Context *context) : mContext(context) +{ +} + +ErrorSet::~ErrorSet() = default; + +void ErrorSet::handleError(const Error &error) +{ + // This internal enum is used to filter internal errors that are already handled. + // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491 + if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX) + { + return; + } + + if (ANGLE_UNLIKELY(error.isError())) + { + GLenum code = error.getCode(); + mErrors.insert(code); + if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory) + { + mContext->markContextLost(); + } + + ASSERT(!error.getMessage().empty()); + mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, + error.getID(), GL_DEBUG_SEVERITY_HIGH, + error.getMessage()); + } +} + +bool ErrorSet::empty() const +{ + return mErrors.empty(); +} + +GLenum ErrorSet::popError() +{ + ASSERT(!empty()); + GLenum error = *mErrors.begin(); + mErrors.erase(mErrors.begin()); + return error; +} } // namespace gl diff --git a/src/libANGLE/Context.h b/src/libANGLE/Context.h index 537c83ecc..9c6b6f2b3 100644 --- a/src/libANGLE/Context.h +++ b/src/libANGLE/Context.h @@ -63,6 +63,21 @@ class TransformFeedback; class VertexArray; struct VertexAttribute; +class ErrorSet : angle::NonCopyable +{ + public: + explicit ErrorSet(Context *context); + ~ErrorSet(); + + void handleError(const Error &error); + bool empty() const; + GLenum popError(); + + private: + Context *mContext; + std::set mErrors; +}; + class Context final : public egl::LabeledObject, angle::NonCopyable { public: @@ -1380,10 +1395,10 @@ class Context final : public egl::LabeledObject, angle::NonCopyable void framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level); // Consumes the error. - void handleError(const Error &error) const; + void handleError(const Error &error); GLenum getError(); - void markContextLost() const; + void markContextLost(); bool isContextLost() const; GLenum getGraphicsResetStatus(); bool isResetNotificationEnabled(); @@ -1574,17 +1589,16 @@ class Context final : public egl::LabeledObject, angle::NonCopyable std::vector mRequestableExtensionStrings; // Recorded errors - typedef std::set ErrorSet; - mutable ErrorSet mErrors; + ErrorSet mErrors; // GLES1 renderer state std::unique_ptr mGLES1Renderer; // Current/lost context flags bool mHasBeenCurrent; - mutable bool mContextLost; - mutable GLenum mResetStatus; - mutable bool mContextLostForced; + bool mContextLost; + GLenum mResetStatus; + bool mContextLostForced; GLenum mResetStrategy; const bool mRobustAccess; const bool mSurfacelessSupported; diff --git a/src/libANGLE/Error.cpp b/src/libANGLE/Error.cpp index f432d68d1..fbc0b4486 100644 --- a/src/libANGLE/Error.cpp +++ b/src/libANGLE/Error.cpp @@ -26,7 +26,6 @@ std::unique_ptr EmplaceErrorString(std::string &&message) namespace gl { - Error::Error(GLenum errorCode, std::string &&message) : mCode(errorCode), mID(errorCode), mMessage(EmplaceErrorString(std::move(message))) { @@ -108,3 +107,19 @@ std::ostream &operator<<(std::ostream &os, const Error &err) } } // namespace egl + +// angle::Result Implementation. +namespace angle +{ +Result::operator gl::Error() const +{ + if (mStop) + { + return gl::Error(GL_INTERNAL_ERROR_ANGLEX); + } + else + { + return gl::NoError(); + } +} +} // namespace angle diff --git a/src/libANGLE/Error.h b/src/libANGLE/Error.h index bf66d4452..4d17ac4ec 100644 --- a/src/libANGLE/Error.h +++ b/src/libANGLE/Error.h @@ -262,6 +262,35 @@ inline Error NoError() #undef ANGLE_CONCAT2 #undef ANGLE_CONCAT1 +namespace angle +{ +// Result signals if calling code should continue running or early exit. A value of Stop() can +// either indicate and Error or a non-Error early exit condition such as a detected no-op. +class ANGLE_NO_DISCARD Result +{ + public: + // TODO(jmadill): Rename when refactor is complete. http://anglebug.com/2491 + bool isError() const { return mStop; } + + static Result Stop() { return Result(true); } + static Result Continue() { return Result(false); } + + // TODO(jmadill): Remove when refactor is complete. http://anglebug.com/2491 + operator gl::Error() const; + + // TODO(jmadill): Remove when refactor is complete. http://anglebug.com/2491 + template + operator gl::ErrorOrResult() const + { + return operator gl::Error(); + } + + private: + Result(bool stop) : mStop(stop) {} + bool mStop; +}; +} // namespace angle + #include "Error.inl" #endif // LIBANGLE_ERROR_H_ diff --git a/src/libANGLE/Framebuffer.cpp b/src/libANGLE/Framebuffer.cpp index 60494c0f8..fe12e2e13 100644 --- a/src/libANGLE/Framebuffer.cpp +++ b/src/libANGLE/Framebuffer.cpp @@ -1024,7 +1024,8 @@ GLenum Framebuffer::checkStatus(const Context *context) Error err = syncState(context); if (err.isError()) { - context->handleError(err); + // TODO(jmadill): Remove when refactor complete. http://anglebug.com/2491 + const_cast(context)->handleError(err); return GetDefaultReturnValue(); } if (!mImpl->checkStatus(context)) diff --git a/src/libANGLE/renderer/ContextImpl.cpp b/src/libANGLE/renderer/ContextImpl.cpp index 8d3df291d..c36612127 100644 --- a/src/libANGLE/renderer/ContextImpl.cpp +++ b/src/libANGLE/renderer/ContextImpl.cpp @@ -9,11 +9,13 @@ #include "libANGLE/renderer/ContextImpl.h" +#include "libANGLE/Context.h" + namespace rx { ContextImpl::ContextImpl(const gl::ContextState &state) - : mState(state), mMemoryProgramCache(nullptr) + : mState(state), mMemoryProgramCache(nullptr), mErrors(nullptr) { } @@ -116,4 +118,13 @@ void ContextImpl::setMemoryProgramCache(gl::MemoryProgramCache *memoryProgramCac mMemoryProgramCache = memoryProgramCache; } +void ContextImpl::setErrorSet(gl::ErrorSet *errorSet) +{ + mErrors = errorSet; +} + +void ContextImpl::handleError(const gl::Error &error) +{ + mErrors->handleError(error); +} } // namespace rx diff --git a/src/libANGLE/renderer/ContextImpl.h b/src/libANGLE/renderer/ContextImpl.h index cc4f0d9c3..cdf6bcc78 100644 --- a/src/libANGLE/renderer/ContextImpl.h +++ b/src/libANGLE/renderer/ContextImpl.h @@ -18,6 +18,7 @@ namespace gl { +class ErrorSet; class MemoryProgramCache; class Path; struct Workarounds; @@ -181,9 +182,15 @@ class ContextImpl : public GLImplFactory // on draw calls we can store the refreshed shaders in the cache. void setMemoryProgramCache(gl::MemoryProgramCache *memoryProgramCache); + // TODO(jmadill): Move init into the constructor. http://anglebug.com/2491 + void setErrorSet(gl::ErrorSet *errorSet); + + void handleError(const gl::Error &error); + protected: const gl::ContextState &mState; gl::MemoryProgramCache *mMemoryProgramCache; + gl::ErrorSet *mErrors; }; } // namespace rx