diff --git a/src/dawn_native/CommandEncoder.cpp b/src/dawn_native/CommandEncoder.cpp index 21060e4756..1bd2efd36b 100644 --- a/src/dawn_native/CommandEncoder.cpp +++ b/src/dawn_native/CommandEncoder.cpp @@ -815,7 +815,7 @@ namespace dawn_native { void CommandEncoder::APIInjectValidationError(const char* message) { if (mEncodingContext.CheckCurrentEncoder(this)) { - mEncodingContext.HandleError(InternalErrorType::Validation, message); + mEncodingContext.HandleError(DAWN_VALIDATION_ERROR(message)); } } diff --git a/src/dawn_native/EncodingContext.cpp b/src/dawn_native/EncodingContext.cpp index acdecd788e..1752f6c422 100644 --- a/src/dawn_native/EncodingContext.cpp +++ b/src/dawn_native/EncodingContext.cpp @@ -53,18 +53,17 @@ namespace dawn_native { } } - void EncodingContext::HandleError(InternalErrorType type, const char* message) { + void EncodingContext::HandleError(std::unique_ptr error) { if (!IsFinished()) { // Encoding should only generate validation errors. - ASSERT(type == InternalErrorType::Validation); + ASSERT(error->GetType() == InternalErrorType::Validation); // If the encoding context is not finished, errors are deferred until // Finish() is called. - if (!mGotError) { - mGotError = true; - mErrorMessage = message; + if (mError == nullptr) { + mError = std::move(error); } } else { - mDevice->HandleError(type, message); + mDevice->HandleError(error->GetType(), error->GetMessage().c_str()); } } @@ -129,8 +128,8 @@ namespace dawn_native { mCurrentEncoder = nullptr; mTopLevelEncoder = nullptr; - if (mGotError) { - return DAWN_VALIDATION_ERROR(mErrorMessage); + if (mError != nullptr) { + return std::move(mError); } if (currentEncoder != topLevelEncoder) { return DAWN_VALIDATION_ERROR("Command buffer recording ended mid-pass"); diff --git a/src/dawn_native/EncodingContext.h b/src/dawn_native/EncodingContext.h index f181e57fb8..7d0f88d22e 100644 --- a/src/dawn_native/EncodingContext.h +++ b/src/dawn_native/EncodingContext.h @@ -39,15 +39,11 @@ namespace dawn_native { CommandIterator* GetIterator(); // Functions to handle encoder errors - void HandleError(InternalErrorType type, const char* message); - - inline void ConsumeError(std::unique_ptr error) { - HandleError(error->GetType(), error->GetMessage().c_str()); - } + void HandleError(std::unique_ptr error); inline bool ConsumedError(MaybeError maybeError) { if (DAWN_UNLIKELY(maybeError.IsError())) { - ConsumeError(maybeError.AcquireError()); + HandleError(maybeError.AcquireError()); return true; } return false; @@ -57,11 +53,10 @@ namespace dawn_native { if (DAWN_UNLIKELY(encoder != mCurrentEncoder)) { if (mCurrentEncoder != mTopLevelEncoder) { // The top level encoder was used when a pass encoder was current. - HandleError(InternalErrorType::Validation, - "Command cannot be recorded inside a pass"); + HandleError(DAWN_VALIDATION_ERROR("Command cannot be recorded inside a pass")); } else { - HandleError(InternalErrorType::Validation, - "Recording in an error or already ended pass encoder"); + HandleError(DAWN_VALIDATION_ERROR( + "Recording in an error or already ended pass encoder")); } return false; } @@ -113,8 +108,7 @@ namespace dawn_native { bool mWasMovedToIterator = false; bool mWereCommandsAcquired = false; - bool mGotError = false; - std::string mErrorMessage; + std::unique_ptr mError; }; } // namespace dawn_native