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)16DawnAsyncWait::DawnAsyncWait(const DawnSharedContext* sharedContext) 17 : fSharedContext(sharedContext) 18 , fSignaled(false) {} 19 yieldAndCheck() const20bool 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() const31bool DawnAsyncWait::mayBusyWait() const { return fSharedContext->caps()->allowCpuSync(); } 32 busyWait() const33void DawnAsyncWait::busyWait() const { 34 SkASSERT(fSharedContext->hasTick()); 35 while (!this->yieldAndCheck()) {} 36 } 37 38 } // namespace skgpu::graphite 39