• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  #include "vk/GrVkTypes.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  
AcquireMutex()46          static void AcquireMutex() { GetMutex()->acquire(); }
ReleaseMutex()47          static void ReleaseMutex() { GetMutex()->release(); }
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              GetMutex()->assertHeld();
58              fHasBeenSubmittedToQueueForSignal = true;
59          }
markAsWaited()60          void markAsWaited() {
61              GetMutex()->assertHeld();
62              fHasBeenSubmittedToQueueForWait = true;
63          }
64  
65  #ifdef SK_TRACE_VK_RESOURCES
dumpInfo()66          void dumpInfo() const override {
67              SkDebugf("GrVkSemaphore: %d (%d refs)\n", fSemaphore, this->getRefCnt());
68          }
69  #endif
70      private:
71          void freeGPUData(GrVkGpu* gpu) const override;
72  
GetMutex()73          static SkMutex* GetMutex() {
74              static SkMutex kMutex;
75              return &kMutex;
76          }
77  
78          VkSemaphore fSemaphore;
79          bool        fHasBeenSubmittedToQueueForSignal;
80          bool        fHasBeenSubmittedToQueueForWait;
81          bool        fIsOwned;
82  
83          typedef GrVkResource INHERITED;
84      };
85  
getResource()86      Resource* getResource() { return fResource; }
87  
88  private:
89      GrVkSemaphore(GrVkGpu* gpu, VkSemaphore semaphore, bool prohibitSignal, bool prohibitWait,
90                    bool isOwned);
91  
92      void onRelease() override;
93      void onAbandon() override;
94  
95      Resource* fResource;
96  
97      typedef GrSemaphore INHERITED;
98  };
99  
100  #endif
101