• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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/TintUtils.h"
16 #include "dawn_native/Device.h"
17 
18 #include <tint/tint.h>
19 
20 namespace dawn_native {
21 
22     namespace {
23 
24         thread_local DeviceBase* tlDevice = nullptr;
25 
TintICEReporter(const tint::diag::List & diagnostics)26         void TintICEReporter(const tint::diag::List& diagnostics) {
27             if (tlDevice) {
28                 tlDevice->HandleError(InternalErrorType::Validation, diagnostics.str().c_str());
29             }
30         }
31 
InitializeTintErrorReporter()32         bool InitializeTintErrorReporter() {
33             tint::SetInternalCompilerErrorReporter(&TintICEReporter);
34             return true;
35         }
36 
37     }  // namespace
38 
ScopedTintICEHandler(DeviceBase * device)39     ScopedTintICEHandler::ScopedTintICEHandler(DeviceBase* device) {
40         // Call tint::SetInternalCompilerErrorReporter() the first time
41         // this constructor is called. Static initialization is
42         // guaranteed to be thread-safe, and only occur once.
43         static bool init_once_tint_error_reporter = InitializeTintErrorReporter();
44         (void)init_once_tint_error_reporter;
45 
46         // Shouldn't have overlapping instances of this handler.
47         ASSERT(tlDevice == nullptr);
48         tlDevice = device;
49     }
50 
~ScopedTintICEHandler()51     ScopedTintICEHandler::~ScopedTintICEHandler() {
52         tlDevice = nullptr;
53     }
54 
55 }  // namespace dawn_native