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 ~SyncHelper() override; 38 39 virtual void releaseToRenderer(RendererVk *renderer); 40 41 virtual angle::Result initialize(ContextVk *contextVk, bool isEglSyncObject); 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 }; 59 60 // Implementation of sync types: EGLSync(EGL_SYNC_ANDROID_NATIVE_FENCE_ANDROID). 61 class SyncHelperNativeFence : public SyncHelper 62 { 63 public: 64 SyncHelperNativeFence(); 65 ~SyncHelperNativeFence() override; 66 67 void releaseToRenderer(RendererVk *renderer) override; 68 69 angle::Result initializeWithFd(ContextVk *contextVk, int inFd); 70 angle::Result clientWait(Context *context, 71 ContextVk *contextVk, 72 bool flushCommands, 73 uint64_t timeout, 74 VkResult *outResult) override; 75 angle::Result serverWait(ContextVk *contextVk) override; 76 angle::Result getStatus(Context *context, bool *signaled) const override; 77 angle::Result dupNativeFenceFD(Context *context, int *fdOut) const override; 78 79 private: 80 vk::Fence mFenceWithFd; 81 int mNativeFenceFd; 82 }; 83 84 } // namespace vk 85 86 // Implementor for glFenceSync. 87 class SyncVk final : public SyncImpl 88 { 89 public: 90 SyncVk(); 91 ~SyncVk() override; 92 93 void onDestroy(const gl::Context *context) override; 94 95 angle::Result set(const gl::Context *context, GLenum condition, GLbitfield flags) override; 96 angle::Result clientWait(const gl::Context *context, 97 GLbitfield flags, 98 GLuint64 timeout, 99 GLenum *outResult) override; 100 angle::Result serverWait(const gl::Context *context, 101 GLbitfield flags, 102 GLuint64 timeout) override; 103 angle::Result getStatus(const gl::Context *context, GLint *outResult) override; 104 105 private: 106 vk::SyncHelper mSyncHelper; 107 }; 108 109 // Implementor for EGLSync. 110 class EGLSyncVk final : public EGLSyncImpl 111 { 112 public: 113 EGLSyncVk(const egl::AttributeMap &attribs); 114 ~EGLSyncVk() override; 115 116 void onDestroy(const egl::Display *display) override; 117 118 egl::Error initialize(const egl::Display *display, 119 const gl::Context *context, 120 EGLenum type) override; 121 egl::Error clientWait(const egl::Display *display, 122 const gl::Context *context, 123 EGLint flags, 124 EGLTime timeout, 125 EGLint *outResult) override; 126 egl::Error serverWait(const egl::Display *display, 127 const gl::Context *context, 128 EGLint flags) override; 129 egl::Error getStatus(const egl::Display *display, EGLint *outStatus) override; 130 131 egl::Error dupNativeFenceFD(const egl::Display *display, EGLint *fdOut) const override; 132 133 private: 134 EGLenum mType; 135 vk::SyncHelper *mSyncHelper; // SyncHelper or SyncHelperNativeFence decided at run-time. 136 const egl::AttributeMap &mAttribs; 137 }; 138 } // namespace rx 139 140 #endif // LIBANGLE_RENDERER_VULKAN_FENCESYNCVK_H_ 141