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