2019-10-16 09:26:54 +00:00
|
|
|
// Copyright 2019 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/d3d12/D3D12Error.h"
|
|
|
|
|
2020-06-16 17:53:38 +00:00
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
2019-10-16 09:26:54 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace dawn_native { namespace d3d12 {
|
2020-06-11 17:12:35 +00:00
|
|
|
MaybeError CheckHRESULTImpl(HRESULT result, const char* context) {
|
2019-10-16 09:26:54 +00:00
|
|
|
if (DAWN_LIKELY(SUCCEEDED(result))) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-06-16 17:53:38 +00:00
|
|
|
std::ostringstream messageStream;
|
|
|
|
messageStream << context << " failed with ";
|
|
|
|
if (result == E_FAKE_ERROR_FOR_TESTING) {
|
|
|
|
messageStream << "E_FAKE_ERROR_FOR_TESTING";
|
|
|
|
} else {
|
|
|
|
messageStream << "0x" << std::uppercase << std::setfill('0') << std::setw(8) << std::hex
|
|
|
|
<< result;
|
|
|
|
}
|
2020-04-01 20:09:16 +00:00
|
|
|
|
|
|
|
if (result == DXGI_ERROR_DEVICE_REMOVED) {
|
2020-06-16 17:53:38 +00:00
|
|
|
return DAWN_DEVICE_LOST_ERROR(messageStream.str());
|
2020-04-01 20:09:16 +00:00
|
|
|
} else {
|
2020-06-16 17:53:38 +00:00
|
|
|
return DAWN_INTERNAL_ERROR(messageStream.str());
|
2020-04-01 20:09:16 +00:00
|
|
|
}
|
2019-10-16 09:26:54 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 17:12:35 +00:00
|
|
|
MaybeError CheckOutOfMemoryHRESULTImpl(HRESULT result, const char* context) {
|
|
|
|
if (result == E_OUTOFMEMORY || result == E_FAKE_OUTOFMEMORY_ERROR_FOR_TESTING) {
|
2019-10-28 12:59:36 +00:00
|
|
|
return DAWN_OUT_OF_MEMORY_ERROR(context);
|
|
|
|
}
|
2020-06-11 17:12:35 +00:00
|
|
|
|
|
|
|
return CheckHRESULTImpl(result, context);
|
2019-10-28 12:59:36 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 12:07:43 +00:00
|
|
|
}} // namespace dawn_native::d3d12
|