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 #include "include/gpu/graphite/BackendSemaphore.h" 9 10 namespace skgpu::graphite { 11 12 BackendSemaphore::BackendSemaphore() = default; 13 14 BackendSemaphore::~BackendSemaphore() = default; 15 BackendSemaphore(const BackendSemaphore & that)16BackendSemaphore::BackendSemaphore(const BackendSemaphore& that) { 17 *this = that; 18 } 19 operator =(const BackendSemaphore & that)20BackendSemaphore& BackendSemaphore::operator=(const BackendSemaphore& that) { 21 if (!that.isValid()) { 22 fIsValid = false; 23 return *this; 24 } 25 SkASSERT(!this->isValid() || this->backend() == that.backend()); 26 fIsValid = true; 27 fBackend = that.fBackend; 28 29 switch (that.backend()) { 30 #ifdef SK_DAWN 31 case BackendApi::kDawn: 32 SK_ABORT("Unsupported Backend"); 33 #endif 34 #ifdef SK_METAL 35 case BackendApi::kMetal: 36 fMtlEvent = that.fMtlEvent; 37 fMtlValue = that.fMtlValue; 38 break; 39 #endif 40 #ifdef SK_VULKAN 41 case BackendApi::kVulkan: 42 fVkSemaphore = that.fVkSemaphore; 43 break; 44 #endif 45 default: 46 SK_ABORT("Unsupported Backend"); 47 } 48 return *this; 49 } 50 51 #ifdef SK_METAL BackendSemaphore(CFTypeRef mtlEvent,uint64_t value)52BackendSemaphore::BackendSemaphore(CFTypeRef mtlEvent, uint64_t value) 53 : fMtlEvent(mtlEvent) 54 , fMtlValue(value) {} 55 getMtlEvent() const56CFTypeRef BackendSemaphore::getMtlEvent() const { 57 if (this->isValid() && this->backend() == BackendApi::kMetal) { 58 return fMtlEvent; 59 } 60 return nullptr; 61 } 62 getMtlValue() const63uint64_t BackendSemaphore::getMtlValue() const { 64 if (this->isValid() && this->backend() == BackendApi::kMetal) { 65 return fMtlValue; 66 } 67 return 0; 68 } 69 #endif // SK_METAL 70 71 #ifdef SK_VULKAN BackendSemaphore(VkSemaphore semaphore)72BackendSemaphore::BackendSemaphore(VkSemaphore semaphore) 73 : fVkSemaphore(semaphore) 74 , fIsValid(true) 75 , fBackend(BackendApi::kVulkan) {} 76 getVkSemaphore() const77VkSemaphore BackendSemaphore::getVkSemaphore() const { 78 if (this->isValid() && this->backend() == BackendApi::kVulkan) { 79 return fVkSemaphore; 80 } 81 return VK_NULL_HANDLE; 82 } 83 #endif 84 85 } // End of namespace skgpu::graphite 86