• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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/Error.h"
16 
17 #include "dawn_native/ErrorData.h"
18 #include "dawn_native/dawn_platform.h"
19 
20 namespace dawn_native {
21 
IgnoreErrors(MaybeError maybeError)22     void IgnoreErrors(MaybeError maybeError) {
23         if (maybeError.IsError()) {
24             std::unique_ptr<ErrorData> errorData = maybeError.AcquireError();
25             // During shutdown and destruction, device lost errors can be ignored.
26             // We can also ignore other unexpected internal errors on shut down and treat it as
27             // device lost so that we can continue with destruction.
28             ASSERT(errorData->GetType() == InternalErrorType::DeviceLost ||
29                    errorData->GetType() == InternalErrorType::Internal);
30         }
31     }
32 
ToWGPUErrorType(InternalErrorType type)33     wgpu::ErrorType ToWGPUErrorType(InternalErrorType type) {
34         switch (type) {
35             case InternalErrorType::Validation:
36                 return wgpu::ErrorType::Validation;
37             case InternalErrorType::OutOfMemory:
38                 return wgpu::ErrorType::OutOfMemory;
39 
40             // There is no equivalent of Internal errors in the WebGPU API. Internal errors cause
41             // the device at the API level to be lost, so treat it like a DeviceLost error.
42             case InternalErrorType::Internal:
43             case InternalErrorType::DeviceLost:
44                 return wgpu::ErrorType::DeviceLost;
45 
46             default:
47                 return wgpu::ErrorType::Unknown;
48         }
49     }
50 
FromWGPUErrorType(wgpu::ErrorType type)51     InternalErrorType FromWGPUErrorType(wgpu::ErrorType type) {
52         switch (type) {
53             case wgpu::ErrorType::Validation:
54                 return InternalErrorType::Validation;
55             case wgpu::ErrorType::OutOfMemory:
56                 return InternalErrorType::OutOfMemory;
57             case wgpu::ErrorType::DeviceLost:
58                 return InternalErrorType::DeviceLost;
59             default:
60                 return InternalErrorType::Internal;
61         }
62     }
63 
64 }  // namespace dawn_native
65