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 // DisplayVk.h: 7 // Defines the class interface for DisplayVk, implementing DisplayImpl. 8 // 9 10 #ifndef LIBANGLE_RENDERER_VULKAN_DISPLAYVK_H_ 11 #define LIBANGLE_RENDERER_VULKAN_DISPLAYVK_H_ 12 13 #include "common/MemoryBuffer.h" 14 #include "libANGLE/renderer/DisplayImpl.h" 15 #include "libANGLE/renderer/vulkan/ResourceVk.h" 16 #include "libANGLE/renderer/vulkan/vk_cache_utils.h" 17 #include "libANGLE/renderer/vulkan/vk_utils.h" 18 19 namespace rx 20 { 21 class RendererVk; 22 23 using ContextVkSet = std::set<ContextVk *>; 24 25 class ShareGroupVk : public ShareGroupImpl 26 { 27 public: 28 ShareGroupVk(); 29 void onDestroy(const egl::Display *display) override; 30 31 // PipelineLayoutCache and DescriptorSetLayoutCache can be shared between multiple threads 32 // accessing them via shared contexts. The ShareGroup locks around gl entrypoints ensuring 33 // synchronous update to the caches. getPipelineLayoutCache()34 PipelineLayoutCache &getPipelineLayoutCache() { return mPipelineLayoutCache; } getDescriptorSetLayoutCache()35 DescriptorSetLayoutCache &getDescriptorSetLayoutCache() { return mDescriptorSetLayoutCache; } getContexts()36 ContextVkSet *getContexts() { return &mContexts; } 37 releaseResourceUseLists()38 std::vector<vk::ResourceUseList> &&releaseResourceUseLists() 39 { 40 return std::move(mResourceUseLists); 41 } acquireResourceUseList(vk::ResourceUseList && resourceUseList)42 void acquireResourceUseList(vk::ResourceUseList &&resourceUseList) 43 { 44 mResourceUseLists.emplace_back(std::move(resourceUseList)); 45 } 46 47 private: 48 // ANGLE uses a PipelineLayout cache to store compatible pipeline layouts. 49 PipelineLayoutCache mPipelineLayoutCache; 50 51 // DescriptorSetLayouts are also managed in a cache. 52 DescriptorSetLayoutCache mDescriptorSetLayoutCache; 53 54 // The list of contexts within the share group 55 ContextVkSet mContexts; 56 57 // List of resources currently used that need to be freed when any ContextVk in this 58 // ShareGroupVk submits the next command. 59 std::vector<vk::ResourceUseList> mResourceUseLists; 60 }; 61 62 class DisplayVk : public DisplayImpl, public vk::Context 63 { 64 public: 65 DisplayVk(const egl::DisplayState &state); 66 ~DisplayVk() override; 67 68 egl::Error initialize(egl::Display *display) override; 69 void terminate() override; 70 71 egl::Error makeCurrent(egl::Display *display, 72 egl::Surface *drawSurface, 73 egl::Surface *readSurface, 74 gl::Context *context) override; 75 76 bool testDeviceLost() override; 77 egl::Error restoreLostDevice(const egl::Display *display) override; 78 79 std::string getRendererDescription() override; 80 std::string getVendorString() override; 81 std::string getVersionString() override; 82 83 DeviceImpl *createDevice() override; 84 85 egl::Error waitClient(const gl::Context *context) override; 86 egl::Error waitNative(const gl::Context *context, EGLint engine) override; 87 88 SurfaceImpl *createWindowSurface(const egl::SurfaceState &state, 89 EGLNativeWindowType window, 90 const egl::AttributeMap &attribs) override; 91 SurfaceImpl *createPbufferSurface(const egl::SurfaceState &state, 92 const egl::AttributeMap &attribs) override; 93 SurfaceImpl *createPbufferFromClientBuffer(const egl::SurfaceState &state, 94 EGLenum buftype, 95 EGLClientBuffer clientBuffer, 96 const egl::AttributeMap &attribs) override; 97 SurfaceImpl *createPixmapSurface(const egl::SurfaceState &state, 98 NativePixmapType nativePixmap, 99 const egl::AttributeMap &attribs) override; 100 101 ImageImpl *createImage(const egl::ImageState &state, 102 const gl::Context *context, 103 EGLenum target, 104 const egl::AttributeMap &attribs) override; 105 106 ContextImpl *createContext(const gl::State &state, 107 gl::ErrorSet *errorSet, 108 const egl::Config *configuration, 109 const gl::Context *shareContext, 110 const egl::AttributeMap &attribs) override; 111 112 StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType, 113 const egl::AttributeMap &attribs) override; 114 115 EGLSyncImpl *createSync(const egl::AttributeMap &attribs) override; 116 117 gl::Version getMaxSupportedESVersion() const override; 118 gl::Version getMaxConformantESVersion() const override; 119 120 virtual const char *getWSIExtension() const = 0; 121 virtual const char *getWSILayer() const; 122 virtual bool isUsingSwapchain() const; 123 124 // Determine if a config with given formats and sample counts is supported. This callback may 125 // modify the config to add or remove platform specific attributes such as nativeVisualID. If 126 // the config is not supported by the window system, it removes the EGL_WINDOW_BIT from 127 // surfaceType, which would still allow the config to be used for pbuffers. 128 virtual void checkConfigSupport(egl::Config *config) = 0; 129 130 ANGLE_NO_DISCARD bool getScratchBuffer(size_t requestedSizeBytes, 131 angle::MemoryBuffer **scratchBufferOut) const; getScratchBuffer()132 angle::ScratchBuffer *getScratchBuffer() const { return &mScratchBuffer; } 133 134 void handleError(VkResult result, 135 const char *file, 136 const char *function, 137 unsigned int line) override; 138 139 // TODO(jmadill): Remove this once refactor is done. http://anglebug.com/3041 140 egl::Error getEGLError(EGLint errorCode); 141 142 void populateFeatureList(angle::FeatureList *features) override; 143 144 ShareGroupImpl *createShareGroup() override; 145 146 protected: 147 void generateExtensions(egl::DisplayExtensions *outExtensions) const override; 148 149 private: 150 virtual SurfaceImpl *createWindowSurfaceVk(const egl::SurfaceState &state, 151 EGLNativeWindowType window) = 0; 152 void generateCaps(egl::Caps *outCaps) const override; 153 154 virtual angle::Result waitNativeImpl(); 155 156 mutable angle::ScratchBuffer mScratchBuffer; 157 158 vk::Error mSavedError; 159 }; 160 161 } // namespace rx 162 163 #endif // LIBANGLE_RENDERER_VULKAN_DISPLAYVK_H_ 164