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