• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // SyncVk:
7 //    Defines the class interface for SyncVk, implementing SyncImpl.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_VULKAN_FENCESYNCVK_H_
11 #define LIBANGLE_RENDERER_VULKAN_FENCESYNCVK_H_
12 
13 #include "libANGLE/renderer/EGLSyncImpl.h"
14 #include "libANGLE/renderer/SyncImpl.h"
15 #include "libANGLE/renderer/vulkan/ResourceVk.h"
16 
17 namespace egl
18 {
19 class AttributeMap;
20 }
21 
22 namespace rx
23 {
24 namespace vk
25 {
26 // The behaviors of SyncImpl and EGLSyncImpl as fence syncs (only supported type) are currently
27 // identical for the Vulkan backend, and this class implements both interfaces.
28 class SyncHelper
29 {
30   public:
31     SyncHelper();
32     ~SyncHelper();
33 
34     void releaseToRenderer(RendererVk *renderer);
35 
36     angle::Result initialize(ContextVk *contextVk);
37     angle::Result clientWait(Context *context,
38                              ContextVk *contextVk,
39                              bool flushCommands,
40                              uint64_t timeout,
41                              VkResult *outResult);
42     angle::Result serverWait(ContextVk *contextVk);
43     angle::Result getStatus(Context *context, bool *signaled);
44 
45   private:
46     // The vkEvent that's signaled on `init` and can be waited on in `serverWait`, or queried with
47     // `getStatus`.
48     Event mEvent;
49     // The fence is signaled once the CB including the `init` signal is executed.
50     // `clientWait` waits on this fence.
51     Shared<Fence> mFence;
52 
53     SharedResourceUse mUse;
54 };
55 }  // namespace vk
56 
57 class SyncVk final : public SyncImpl
58 {
59   public:
60     SyncVk();
61     ~SyncVk() override;
62 
63     void onDestroy(const gl::Context *context) override;
64 
65     angle::Result set(const gl::Context *context, GLenum condition, GLbitfield flags) override;
66     angle::Result clientWait(const gl::Context *context,
67                              GLbitfield flags,
68                              GLuint64 timeout,
69                              GLenum *outResult) override;
70     angle::Result serverWait(const gl::Context *context,
71                              GLbitfield flags,
72                              GLuint64 timeout) override;
73     angle::Result getStatus(const gl::Context *context, GLint *outResult) override;
74 
75   private:
76     vk::SyncHelper mFenceSync;
77 };
78 
79 class EGLSyncVk final : public EGLSyncImpl
80 {
81   public:
82     EGLSyncVk(const egl::AttributeMap &attribs);
83     ~EGLSyncVk() override;
84 
85     void onDestroy(const egl::Display *display) override;
86 
87     egl::Error initialize(const egl::Display *display,
88                           const gl::Context *context,
89                           EGLenum type) override;
90     egl::Error clientWait(const egl::Display *display,
91                           const gl::Context *context,
92                           EGLint flags,
93                           EGLTime timeout,
94                           EGLint *outResult) override;
95     egl::Error serverWait(const egl::Display *display,
96                           const gl::Context *context,
97                           EGLint flags) override;
98     egl::Error getStatus(const egl::Display *display, EGLint *outStatus) override;
99 
100     egl::Error dupNativeFenceFD(const egl::Display *display, EGLint *result) const override;
101 
102   private:
103     vk::SyncHelper mFenceSync;
104 };
105 }  // namespace rx
106 
107 #endif  // LIBANGLE_RENDERER_VULKAN_FENCESYNCVK_H_
108