1 /* 2 * Copyright 2023 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef skgpu_graphite_DawnErrorChecker_DEFINED 9 #define skgpu_graphite_DawnErrorChecker_DEFINED 10 11 #include "src/base/SkEnumBitMask.h" 12 13 #include "src/gpu/graphite/dawn/DawnAsyncWait.h" 14 15 #include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE 16 17 namespace skgpu::graphite { 18 19 class DawnCaps; 20 21 enum class DawnErrorType : uint32_t { 22 kNoError = 0b00000000, 23 kValidation = 0b00000001, 24 kOutOfMemory = 0b00000010, 25 kInternal = 0b00000100, 26 }; 27 SK_MAKE_BITMASK_OPS(DawnErrorType); 28 29 // DawnErrorChecker immediately pushes error scopes for all known Dawn error filter types 30 // (Validation, OutOfMemory, Internal) upon construction and detects any errors that are 31 // reported within those scopes. Errors can be detected synchronously by either 32 // 33 // 1. calling `check()`, which returns false if any errors were reported, or 34 // 2. destroying the DawnErrorChecker instance, which asserts if any errors are reported 35 // which weren't previously caught by calling `check()` directly. 36 // 37 class DawnErrorChecker { 38 public: 39 explicit DawnErrorChecker(const DawnSharedContext*); 40 ~DawnErrorChecker(); 41 42 SkEnumBitMask<DawnErrorType> popErrorScopes(); 43 44 private: 45 bool fArmed = true; 46 const DawnSharedContext* fSharedContext; 47 }; 48 49 } // namespace skgpu::graphite 50 51 #endif // skgpu_graphite_DawnErrorChecker_DEFINED 52