• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 Google LLC
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 skgpu_graphite_BackendSemaphore_DEFINED
9 #define skgpu_graphite_BackendSemaphore_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/gpu/graphite/GraphiteTypes.h"
13 
14 #ifdef SK_METAL
15 #include "include/gpu/graphite/mtl/MtlGraphiteTypes.h"
16 #endif
17 
18 #ifdef SK_VULKAN
19 #include "include/private/gpu/vk/SkiaVulkan.h"
20 #endif
21 
22 namespace skgpu::graphite {
23 
24 class SK_API BackendSemaphore {
25 public:
26     BackendSemaphore();
27 #ifdef SK_METAL
28     // TODO: Determine creator's responsibility for setting refcnt.
29     BackendSemaphore(CFTypeRef mtlEvent, uint64_t value);
30 #endif
31 
32 #ifdef SK_VULKAN
33     BackendSemaphore(VkSemaphore semaphore);
34 #endif
35 
36     BackendSemaphore(const BackendSemaphore&);
37 
38     ~BackendSemaphore();
39 
40     BackendSemaphore& operator=(const BackendSemaphore&);
41 
isValid()42     bool isValid() const { return fIsValid; }
backend()43     BackendApi backend() const { return fBackend; }
44 
45 #ifdef SK_METAL
46     CFTypeRef getMtlEvent() const;
47     uint64_t getMtlValue() const;
48 #endif
49 
50 #ifdef SK_VULKAN
51     VkSemaphore getVkSemaphore() const;
52 #endif
53 
54 private:
55     // TODO: For now, implement as a union until we figure out the plan for this and BackendTexture.
56     union {
57 #ifdef SK_DAWN
58         // TODO: WebGPU doesn't seem to have the notion of an Event or Semaphore
59 #endif
60 #ifdef SK_METAL
61         struct {
62             CFTypeRef fMtlEvent;    // Expected to be an id<MTLEvent>
63             uint64_t fMtlValue;
64         };
65 #endif
66 #ifdef SK_VULKAN
67         VkSemaphore fVkSemaphore;
68 #endif
69         void* fEnsureUnionNonEmpty;
70     };
71     bool fIsValid = false;
72     BackendApi fBackend;
73 };
74 
75 } // namespace skgpu::graphite
76 
77 #endif // skgpu_graphite_BackendSemaphore_DEFINED
78 
79