• Home
  • 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 "src/gpu/GrSemaphore.h"
12 
13 #include "include/gpu/vk/GrVkTypes.h"
14 #include "src/gpu/vk/GrVkManagedResource.h"
15 
16 #include <cinttypes>
17 
18 class GrBackendSemaphore;
19 class GrVkGpu;
20 
21 class GrVkSemaphore : public GrSemaphore {
22 public:
23     static std::unique_ptr<GrVkSemaphore> Make(GrVkGpu* gpu, bool isOwned);
24 
25     static std::unique_ptr<GrVkSemaphore> MakeWrapped(GrVkGpu*,
26                                                       VkSemaphore,
27                                                       GrSemaphoreWrapType,
28                                                       GrWrapOwnership);
29 
30     ~GrVkSemaphore() override;
31 
32     GrBackendSemaphore backendSemaphore() const override;
33 
34     class Resource : public GrVkManagedResource {
35     public:
Resource(const GrVkGpu * gpu,VkSemaphore semaphore,bool prohibitSignal,bool prohibitWait,bool isOwned)36         Resource(const GrVkGpu* gpu, VkSemaphore semaphore,
37                  bool prohibitSignal, bool prohibitWait, bool isOwned)
38                 : INHERITED(gpu)
39                 , fSemaphore(semaphore)
40                 , fHasBeenSubmittedToQueueForSignal(prohibitSignal)
41                 , fHasBeenSubmittedToQueueForWait(prohibitWait)
42                 , fIsOwned(isOwned) {}
43 
~Resource()44         ~Resource() override {}
45 
semaphore()46         VkSemaphore semaphore() const { return fSemaphore; }
47 
shouldSignal()48         bool shouldSignal() const {
49             return !fHasBeenSubmittedToQueueForSignal;
50         }
shouldWait()51         bool shouldWait() const {
52             return !fHasBeenSubmittedToQueueForWait;
53         }
54 
markAsSignaled()55         void markAsSignaled() {
56             fHasBeenSubmittedToQueueForSignal = true;
57         }
markAsWaited()58         void markAsWaited() {
59             fHasBeenSubmittedToQueueForWait = true;
60         }
61 
setIsOwned()62         void setIsOwned() {
63             fIsOwned = true;
64         }
65 
66 #ifdef SK_TRACE_MANAGED_RESOURCES
dumpInfo()67         void dumpInfo() const override {
68             SkDebugf("GrVkSemaphore: %" PRIdPTR " (%d refs)\n", (intptr_t)fSemaphore,
69                      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