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