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 27 // Represents an invalid native fence FD. 28 constexpr int kInvalidFenceFd = EGL_NO_NATIVE_FENCE_FD_ANDROID; 29 30 // Implementation of fence types - glFenceSync, and EGLSync(EGL_SYNC_FENCE_KHR). 31 // The behaviors of SyncVk and EGLFenceSyncVk as fence syncs are currently 32 // identical for the Vulkan backend, and this class implements both interfaces. 33 class SyncHelper : public vk::Resource 34 { 35 public: 36 SyncHelper(); 37 virtual ~SyncHelper(); 38 39 virtual void releaseToRenderer(RendererVk *renderer); 40 41 virtual angle::Result initialize(ContextVk *contextVk); 42 virtual angle::Result clientWait(Context *context, 43 ContextVk *contextVk, 44 bool flushCommands, 45 uint64_t timeout, 46 VkResult *outResult); 47 virtual angle::Result serverWait(ContextVk *contextVk); 48 virtual angle::Result getStatus(Context *context, bool *signaled) const; dupNativeFenceFD(Context * context,int * fdOut)49 virtual angle::Result dupNativeFenceFD(Context *context, int *fdOut) const 50 { 51 return angle::Result::Stop; 52 } 53 54 private: 55 // The vkEvent that's signaled on `init` and can be waited on in `serverWait`, or queried with 56 // `getStatus`. 57 Event mEvent; 58 // The fence is signaled once the CB including the `init` signal is executed. 59 // `clientWait` waits on this fence. 60 Shared<Fence> mFence; 61 }; 62 63 // Implementation of sync types: EGLSync(EGL_SYNC_ANDROID_NATIVE_FENCE_ANDROID). 64 class SyncHelperNativeFence : public SyncHelper 65 { 66 public: SyncHelperNativeFence()67 SyncHelperNativeFence() {} ~SyncHelperNativeFence()68 ~SyncHelperNativeFence() override {} 69 70 void releaseToRenderer(RendererVk *renderer) override; 71 72 angle::Result initializeWithFd(ContextVk *contextVk, int inFd); 73 angle::Result clientWait(Context *context, 74 ContextVk *contextVk, 75 bool flushCommands, 76 uint64_t timeout, 77 VkResult *outResult) override; 78 angle::Result serverWait(ContextVk *contextVk) override; 79 angle::Result getStatus(Context *context, bool *signaled) const override; 80 angle::Result dupNativeFenceFD(Context *context, int *fdOut) const override; 81 82 private: 83 vk::Fence mFenceWithFd; 84 }; 85 86 } // namespace vk 87 88 // Implementor for glFenceSync. 89 class SyncVk final : public SyncImpl 90 { 91 public: 92 SyncVk(); 93 ~SyncVk() override; 94 95 void onDestroy(const gl::Context *context) override; 96 97 angle::Result set(const gl::Context *context, GLenum condition, GLbitfield flags) override; 98 angle::Result clientWait(const gl::Context *context, 99 GLbitfield flags, 100 GLuint64 timeout, 101 GLenum *outResult) override; 102 angle::Result serverWait(const gl::Context *context, 103 GLbitfield flags, 104 GLuint64 timeout) override; 105 angle::Result getStatus(const gl::Context *context, GLint *outResult) override; 106 107 private: 108 vk::SyncHelper mSyncHelper; 109 }; 110 111 // Implementor for EGLSync. 112 class EGLSyncVk final : public EGLSyncImpl 113 { 114 public: 115 EGLSyncVk(const egl::AttributeMap &attribs); 116 ~EGLSyncVk() override; 117 118 void onDestroy(const egl::Display *display) override; 119 120 egl::Error initialize(const egl::Display *display, 121 const gl::Context *context, 122 EGLenum type) override; 123 egl::Error clientWait(const egl::Display *display, 124 const gl::Context *context, 125 EGLint flags, 126 EGLTime timeout, 127 EGLint *outResult) override; 128 egl::Error serverWait(const egl::Display *display, 129 const gl::Context *context, 130 EGLint flags) override; 131 egl::Error getStatus(const egl::Display *display, EGLint *outStatus) override; 132 133 egl::Error dupNativeFenceFD(const egl::Display *display, EGLint *fdOut) const override; 134 135 private: 136 EGLenum mType; 137 vk::SyncHelper *mSyncHelper; // SyncHelper or SyncHelperNativeFence decided at run-time. 138 const egl::AttributeMap &mAttribs; 139 }; 140 } // namespace rx 141 142 #endif // LIBANGLE_RENDERER_VULKAN_FENCESYNCVK_H_ 143