1 /* 2 * Copyright 2017 Google Inc. 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 GrVkSemaphore_DEFINED 9 #define GrVkSemaphore_DEFINED 10 11 #include "src/gpu/GrSemaphore.h" 12 13 #include "include/gpu/vk/GrVkTypes.h" 14 #include "src/gpu/GrResourceProvider.h" 15 #include "src/gpu/vk/GrVkResource.h" 16 17 class GrBackendSemaphore; 18 class GrVkGpu; 19 20 class GrVkSemaphore : public GrSemaphore { 21 public: 22 static sk_sp<GrVkSemaphore> Make(GrVkGpu* gpu, bool isOwned); 23 24 using WrapType = GrResourceProvider::SemaphoreWrapType; 25 26 static sk_sp<GrVkSemaphore> MakeWrapped(GrVkGpu* gpu, 27 VkSemaphore semaphore, 28 WrapType wrapType, 29 GrWrapOwnership); 30 31 GrBackendSemaphore backendSemaphore() const override; 32 33 class Resource : public GrVkResource { 34 public: Resource(VkSemaphore semaphore,bool prohibitSignal,bool prohibitWait,bool isOwned)35 Resource(VkSemaphore semaphore, bool prohibitSignal, bool prohibitWait, bool isOwned) 36 : INHERITED() 37 , fSemaphore(semaphore) 38 , fHasBeenSubmittedToQueueForSignal(prohibitSignal) 39 , fHasBeenSubmittedToQueueForWait(prohibitWait) 40 , fIsOwned(isOwned) {} 41 ~Resource()42 ~Resource() override {} 43 semaphore()44 VkSemaphore semaphore() const { return fSemaphore; } 45 shouldSignal()46 bool shouldSignal() const { 47 return !fHasBeenSubmittedToQueueForSignal; 48 } shouldWait()49 bool shouldWait() const { 50 return !fHasBeenSubmittedToQueueForWait; 51 } 52 markAsSignaled()53 void markAsSignaled() { 54 fHasBeenSubmittedToQueueForSignal = true; 55 } markAsWaited()56 void markAsWaited() { 57 fHasBeenSubmittedToQueueForWait = true; 58 } 59 60 #ifdef SK_TRACE_VK_RESOURCES dumpInfo()61 void dumpInfo() const override { 62 SkDebugf("GrVkSemaphore: %d (%d refs)\n", fSemaphore, this->getRefCnt()); 63 } 64 #endif 65 private: 66 void freeGPUData(GrVkGpu* gpu) const override; 67 68 VkSemaphore fSemaphore; 69 bool fHasBeenSubmittedToQueueForSignal; 70 bool fHasBeenSubmittedToQueueForWait; 71 bool fIsOwned; 72 73 typedef GrVkResource INHERITED; 74 }; 75 getResource()76 Resource* getResource() { return fResource; } 77 78 private: 79 GrVkSemaphore(GrVkGpu* gpu, VkSemaphore semaphore, bool prohibitSignal, bool prohibitWait, 80 bool isOwned); 81 82 void onRelease() override; 83 void onAbandon() override; 84 85 Resource* fResource; 86 87 typedef GrSemaphore INHERITED; 88 }; 89 90 #endif 91