From 7065c21fbb3dae73c7e7ee3c370b9bb3258c6de5 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Tue, 16 Nov 2021 00:50:04 +0000 Subject: [PATCH] Add descriptive error contexts to adapter initialization To help diagnose issues where Dawn fails to create or initialize an adapter. Bug: none Change-Id: I0c757f99596e9b4ac0e559807654ffaf9cb03feb Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/69420 Reviewed-by: Austin Eng Commit-Queue: Austin Eng --- src/dawn_native/Adapter.cpp | 16 +++++++++++++--- src/dawn_native/Error.h | 8 ++------ src/dawn_native/ErrorData.cpp | 6 +++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/dawn_native/Adapter.cpp b/src/dawn_native/Adapter.cpp index bdbfc2cdbf..a0ee2c7a1e 100644 --- a/src/dawn_native/Adapter.cpp +++ b/src/dawn_native/Adapter.cpp @@ -25,9 +25,19 @@ namespace dawn_native { } MaybeError AdapterBase::Initialize() { - DAWN_TRY(InitializeImpl()); - DAWN_TRY(InitializeSupportedFeaturesImpl()); - DAWN_TRY(InitializeSupportedLimitsImpl(&mLimits)); + DAWN_TRY_CONTEXT(InitializeImpl(), "initializing adapter (backend=%s)", mBackend); + DAWN_TRY_CONTEXT( + InitializeSupportedFeaturesImpl(), + "gathering supported features for \"%s\" - \"%s\" (vendorId=%#06x deviceId=%#06x " + "backend=%s type=%s)", + mPCIInfo.name, mDriverDescription, mPCIInfo.vendorId, mPCIInfo.deviceId, mBackend, + mAdapterType); + DAWN_TRY_CONTEXT( + InitializeSupportedLimitsImpl(&mLimits), + "gathering supported limits for \"%s\" - \"%s\" (vendorId=%#06x deviceId=%#06x " + "backend=%s type=%s)", + mPCIInfo.name, mDriverDescription, mPCIInfo.vendorId, mPCIInfo.deviceId, mBackend, + mAdapterType); // Enforce internal Dawn constants. mLimits.v1.maxVertexBufferArrayStride = diff --git a/src/dawn_native/Error.h b/src/dawn_native/Error.h index 7e6726ed94..da093de09c 100644 --- a/src/dawn_native/Error.h +++ b/src/dawn_native/Error.h @@ -113,12 +113,8 @@ namespace dawn_native { // the current function. #define DAWN_TRY(EXPR) DAWN_TRY_WITH_CLEANUP(EXPR, {}) -#define DAWN_TRY_CONTEXT(EXPR, ...) \ - DAWN_TRY_WITH_CLEANUP(EXPR, { \ - if (error->GetType() == InternalErrorType::Validation) { \ - error->AppendContext(absl::StrFormat(__VA_ARGS__)); \ - } \ - }) +#define DAWN_TRY_CONTEXT(EXPR, ...) \ + DAWN_TRY_WITH_CLEANUP(EXPR, { error->AppendContext(absl::StrFormat(__VA_ARGS__)); }) #define DAWN_TRY_WITH_CLEANUP(EXPR, BODY) \ { \ diff --git a/src/dawn_native/ErrorData.cpp b/src/dawn_native/ErrorData.cpp index 93ef6be68f..6e28161985 100644 --- a/src/dawn_native/ErrorData.cpp +++ b/src/dawn_native/ErrorData.cpp @@ -79,7 +79,11 @@ namespace dawn_native { for (auto context : mContexts) { ss << " - While " << context << "\n"; } - } else { + } + + // For non-validation errors, or erros that lack a context include the + // stack trace for debugging purposes. + if (mContexts.empty() || mType != InternalErrorType::Validation) { for (const auto& callsite : mBacktrace) { ss << " at " << callsite.function << " (" << callsite.file << ":" << callsite.line << ")\n";