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