xref: /aosp_15_r20/external/skia/src/gpu/graphite/dawn/DawnAsyncWait.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 #include "src/gpu/graphite/dawn/DawnAsyncWait.h"
9 
10 #include "src/gpu/graphite/Caps.h"
11 #include "src/gpu/graphite/dawn/DawnSharedContext.h"
12 #include "src/gpu/graphite/dawn/DawnUtilsPriv.h"
13 
14 namespace skgpu::graphite {
15 
DawnAsyncWait(const DawnSharedContext * sharedContext)16 DawnAsyncWait::DawnAsyncWait(const DawnSharedContext* sharedContext)
17         : fSharedContext(sharedContext)
18         , fSignaled(false) {}
19 
yieldAndCheck() const20 bool DawnAsyncWait::yieldAndCheck() const {
21     if (fSharedContext->hasTick()) {
22         if (fSignaled.load(std::memory_order_acquire)) {
23             return true;
24         }
25 
26         fSharedContext->tick();
27     }
28     return fSignaled.load(std::memory_order_acquire);
29 }
30 
mayBusyWait() const31 bool DawnAsyncWait::mayBusyWait() const { return fSharedContext->caps()->allowCpuSync(); }
32 
busyWait() const33 void DawnAsyncWait::busyWait() const {
34     SkASSERT(fSharedContext->hasTick());
35     while (!this->yieldAndCheck()) {}
36 }
37 
38 }  // namespace skgpu::graphite
39