1 // Copyright 2019 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "dawn_native/d3d12/D3D12Error.h" 16 17 #include <iomanip> 18 #include <sstream> 19 #include <string> 20 21 namespace dawn_native { namespace d3d12 { CheckHRESULTImpl(HRESULT result,const char * context)22 MaybeError CheckHRESULTImpl(HRESULT result, const char* context) { 23 if (DAWN_LIKELY(SUCCEEDED(result))) { 24 return {}; 25 } 26 27 std::ostringstream messageStream; 28 messageStream << context << " failed with "; 29 if (result == E_FAKE_ERROR_FOR_TESTING) { 30 messageStream << "E_FAKE_ERROR_FOR_TESTING"; 31 } else { 32 messageStream << "0x" << std::uppercase << std::setfill('0') << std::setw(8) << std::hex 33 << result; 34 } 35 36 if (result == DXGI_ERROR_DEVICE_REMOVED) { 37 return DAWN_DEVICE_LOST_ERROR(messageStream.str()); 38 } else { 39 return DAWN_INTERNAL_ERROR(messageStream.str()); 40 } 41 } 42 CheckOutOfMemoryHRESULTImpl(HRESULT result,const char * context)43 MaybeError CheckOutOfMemoryHRESULTImpl(HRESULT result, const char* context) { 44 if (result == E_OUTOFMEMORY || result == E_FAKE_OUTOFMEMORY_ERROR_FOR_TESTING) { 45 return DAWN_OUT_OF_MEMORY_ERROR(context); 46 } 47 48 return CheckHRESULTImpl(result, context); 49 } 50 51 }} // namespace dawn_native::d3d12 52