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/ganesh/GrSemaphore.h" 12 13 #include "include/gpu/vk/GrVkTypes.h" 14 #include "include/private/gpu/ganesh/GrTypesPriv.h" 15 #include "src/gpu/ganesh/vk/GrVkManagedResource.h" 16 17 #include <cinttypes> 18 19 class GrBackendSemaphore; 20 class GrVkGpu; 21 22 class GrVkSemaphore : public GrSemaphore { 23 public: 24 static std::unique_ptr<GrVkSemaphore> Make(GrVkGpu* gpu, bool isOwned); 25 26 static std::unique_ptr<GrVkSemaphore> MakeWrapped(GrVkGpu*, 27 VkSemaphore, 28 GrSemaphoreWrapType, 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: %" PRIdPTR " (%d refs)\n", (intptr_t)fSemaphore, 70 this->getRefCnt()); 71 } 72 #endif 73 private: 74 void freeGPUData() const override; 75 76 VkSemaphore fSemaphore; 77 bool fHasBeenSubmittedToQueueForSignal; 78 bool fHasBeenSubmittedToQueueForWait; 79 bool fIsOwned; 80 81 using INHERITED = GrVkManagedResource; 82 }; 83 getResource()84 Resource* getResource() { return fResource; } 85 86 private: 87 GrVkSemaphore(GrVkGpu* gpu, VkSemaphore semaphore, bool prohibitSignal, bool prohibitWait, 88 bool isOwned); 89 setIsOwned()90 void setIsOwned() override { 91 fResource->setIsOwned(); 92 } 93 94 Resource* fResource; 95 96 using INHERITED = GrSemaphore; 97 }; 98 99 #endif 100