Natasha Lee 3fe84b5b33 Fix AssertAndIgnoreDeviceLossError to handle errors injected by fuzzer
Fuzzer recently started sometimes injecting errors with
CheckHRESULT returning E_FAKE_ERROR_FOR_TESTING, which needs to also be ignored
in AssertAndIgnoreDeviceLossError so that we can continue with destruction.

Rename AssertAndIgnoreDeviceLossError to IgnoreErrors

This CL also adds Austin's pretty printing of HRESULT results as hex values
and adds printing of "E_FAKE_ERROR_FOR_TESTING" error.

Bug: chromium:1094448
Change-Id: I6715a5eec02919a3e3b4c86d493b3f7e84c5e206
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/23241
Commit-Queue: Natasha Lee <natlee@microsoft.com>
Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
2020-06-16 17:53:38 +00:00

65 lines
2.5 KiB
C++

// Copyright 2018 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dawn_native/Error.h"
#include "dawn_native/ErrorData.h"
#include "dawn_native/dawn_platform.h"
namespace dawn_native {
void IgnoreErrors(MaybeError maybeError) {
if (maybeError.IsError()) {
std::unique_ptr<ErrorData> errorData = maybeError.AcquireError();
// During shutdown and destruction, device lost errors can be ignored.
// We can also ignore other unexpected internal errors on shut down and treat it as
// device lost so that we can continue with destruction.
ASSERT(errorData->GetType() == InternalErrorType::DeviceLost ||
errorData->GetType() == InternalErrorType::Internal);
}
}
wgpu::ErrorType ToWGPUErrorType(InternalErrorType type) {
switch (type) {
case InternalErrorType::Validation:
return wgpu::ErrorType::Validation;
case InternalErrorType::OutOfMemory:
return wgpu::ErrorType::OutOfMemory;
// There is no equivalent of Internal errors in the WebGPU API. Internal errors cause
// the device at the API level to be lost, so treat it like a DeviceLost error.
case InternalErrorType::Internal:
case InternalErrorType::DeviceLost:
return wgpu::ErrorType::DeviceLost;
default:
return wgpu::ErrorType::Unknown;
}
}
InternalErrorType FromWGPUErrorType(wgpu::ErrorType type) {
switch (type) {
case wgpu::ErrorType::Validation:
return InternalErrorType::Validation;
case wgpu::ErrorType::OutOfMemory:
return InternalErrorType::OutOfMemory;
case wgpu::ErrorType::DeviceLost:
return InternalErrorType::DeviceLost;
default:
return InternalErrorType::Internal;
}
}
} // namespace dawn_native