• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 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_DawnAsyncWait_DEFINED
9 #define skgpu_graphite_DawnAsyncWait_DEFINED
10 
11 #include "webgpu/webgpu_cpp.h"
12 
13 #include <atomic>
14 #include <functional>
15 
16 namespace skgpu::graphite {
17 
18 class DawnAsyncWait {
19 public:
20     explicit DawnAsyncWait(const wgpu::Device& device);
21 
22     // Returns true if the wait has been signaled and false otherwise. This function yields
23     // execution to the event loop where Dawn's asynchronous tasks get scheduled and returns
24     // as soon as the loop yields the execution back to the caller.
25     bool yieldAndCheck() const;
26 
27     // Busy-waits until this wait has been signaled.
28     // TODO(armansito): This could benefit from a timeout in the case the wait never gets signaled.
29     void busyWait() const;
30 
31     // Marks this wait as resolved. Once called, all calls to `yieldAndCheck` and `busyWait` will
32     // return true immediately.
signal()33     void signal() { fSignaled.store(true); }
34 
35     // Resets this object into its unsignaled state.
reset()36     void reset() { fSignaled.store(false); }
37 
38 private:
39     wgpu::Device fDevice;
40     std::atomic_bool fSignaled;
41 };
42 
43 } // namespace skgpu::graphite
44 
45 #endif // skgpu_graphite_DawnAsyncWait_DEFINED
46