• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2019 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 // DisplayMtl.h:
7 //    Defines the class interface for DisplayMtl, implementing DisplayImpl.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_METAL_DISPLAYMTL_H_
11 #define LIBANGLE_RENDERER_METAL_DISPLAYMTL_H_
12 
13 #include "common/PackedEnums.h"
14 #include "libANGLE/angletypes.h"
15 #include "libANGLE/renderer/DisplayImpl.h"
16 #include "libANGLE/renderer/ShareGroupImpl.h"
17 #include "libANGLE/renderer/metal/mtl_command_buffer.h"
18 #include "libANGLE/renderer/metal/mtl_context_device.h"
19 #include "libANGLE/renderer/metal/mtl_format_utils.h"
20 #include "libANGLE/renderer/metal/mtl_library_cache.h"
21 #include "libANGLE/renderer/metal/mtl_render_utils.h"
22 #include "libANGLE/renderer/metal/mtl_state_cache.h"
23 #include "libANGLE/renderer/metal/mtl_utils.h"
24 #include "platform/autogen/FeaturesMtl_autogen.h"
25 
26 namespace egl
27 {
28 class Surface;
29 }
30 
31 namespace rx
32 {
33 class ShareGroupMtl : public ShareGroupImpl
34 {
35   public:
ShareGroupMtl(const egl::ShareGroupState & state)36     ShareGroupMtl(const egl::ShareGroupState &state) : ShareGroupImpl(state) {}
37 };
38 
39 class ContextMtl;
40 
41 struct DefaultShaderAsyncInfoMtl;
42 
43 class DisplayMtl : public DisplayImpl
44 {
45   public:
46     DisplayMtl(const egl::DisplayState &state);
47     ~DisplayMtl() override;
48 
49     egl::Error initialize(egl::Display *display) override;
50     void terminate() override;
51 
getDisplay()52     egl::Display *getDisplay() const { return mDisplay; }
53 
54     bool testDeviceLost() override;
55     egl::Error restoreLostDevice(const egl::Display *display) override;
56 
57     std::string getRendererDescription() override;
58     std::string getVendorString() override;
59     std::string getVersionString(bool includeFullVersion) override;
60 
61     DeviceImpl *createDevice() override;
62 
63     egl::Error waitClient(const gl::Context *context) override;
64     egl::Error waitNative(const gl::Context *context, EGLint engine) override;
65 
66     egl::Error waitUntilWorkScheduled() override;
67 
68     SurfaceImpl *createWindowSurface(const egl::SurfaceState &state,
69                                      EGLNativeWindowType window,
70                                      const egl::AttributeMap &attribs) override;
71     SurfaceImpl *createPbufferSurface(const egl::SurfaceState &state,
72                                       const egl::AttributeMap &attribs) override;
73     SurfaceImpl *createPbufferFromClientBuffer(const egl::SurfaceState &state,
74                                                EGLenum buftype,
75                                                EGLClientBuffer clientBuffer,
76                                                const egl::AttributeMap &attribs) override;
77     SurfaceImpl *createPixmapSurface(const egl::SurfaceState &state,
78                                      NativePixmapType nativePixmap,
79                                      const egl::AttributeMap &attribs) override;
80 
81     ImageImpl *createImage(const egl::ImageState &state,
82                            const gl::Context *context,
83                            EGLenum target,
84                            const egl::AttributeMap &attribs) override;
85 
86     ContextImpl *createContext(const gl::State &state,
87                                gl::ErrorSet *errorSet,
88                                const egl::Config *configuration,
89                                const gl::Context *shareContext,
90                                const egl::AttributeMap &attribs) override;
91 
92     StreamProducerImpl *createStreamProducerD3DTexture(egl::Stream::ConsumerType consumerType,
93                                                        const egl::AttributeMap &attribs) override;
94 
95     ShareGroupImpl *createShareGroup(const egl::ShareGroupState &state) override;
96 
97     ExternalImageSiblingImpl *createExternalImageSibling(const gl::Context *context,
98                                                          EGLenum target,
99                                                          EGLClientBuffer buffer,
100                                                          const egl::AttributeMap &attribs) override;
101     gl::Version getMaxSupportedESVersion() const override;
102     gl::Version getMaxConformantESVersion() const override;
103 
104     EGLSyncImpl *createSync() override;
105 
106     egl::Error makeCurrent(egl::Display *display,
107                            egl::Surface *drawSurface,
108                            egl::Surface *readSurface,
109                            gl::Context *context) override;
110 
111     void initializeFrontendFeatures(angle::FrontendFeatures *features) const override;
112 
113     void populateFeatureList(angle::FeatureList *features) override;
114 
115     bool isValidNativeWindow(EGLNativeWindowType window) const override;
116 
117     egl::Error validateClientBuffer(const egl::Config *configuration,
118                                     EGLenum buftype,
119                                     EGLClientBuffer clientBuffer,
120                                     const egl::AttributeMap &attribs) const override;
121 
122     egl::Error validateImageClientBuffer(const gl::Context *context,
123                                          EGLenum target,
124                                          EGLClientBuffer clientBuffer,
125                                          const egl::AttributeMap &attribs) const override;
126 
127     egl::ConfigSet generateConfigs() override;
128 
129     gl::Caps getNativeCaps() const;
130     const gl::TextureCapsMap &getNativeTextureCaps() const;
131     const gl::Extensions &getNativeExtensions() const;
132     const gl::Limitations &getNativeLimitations() const;
133     const ShPixelLocalStorageOptions &getNativePixelLocalStorageOptions() const;
getFeatures()134     const angle::FeaturesMtl &getFeatures() const { return mFeatures; }
135 
136     // Check whether either of the specified iOS or Mac GPU family is supported
137     bool supportsEitherGPUFamily(uint8_t iOSFamily, uint8_t macFamily) const;
138     bool supportsAppleGPUFamily(uint8_t iOSFamily) const;
139     bool supportsMacGPUFamily(uint8_t macFamily) const;
140     bool supportsDepth24Stencil8PixelFormat() const;
141     bool supports32BitFloatFiltering() const;
142     bool supportsBCTextureCompression() const;
143     bool isAMD() const;
144     bool isAMDBronzeDriver() const;
145     bool isAMDFireProDevice() const;
146     bool isIntel() const;
147     bool isNVIDIA() const;
148     bool isSimulator() const;
149 
getMetalDevice()150     id<MTLDevice> getMetalDevice() const { return mMetalDevice; }
151 
cmdQueue()152     mtl::CommandQueue &cmdQueue() { return mCmdQueue; }
getFormatTable()153     const mtl::FormatTable &getFormatTable() const { return mFormatTable; }
getUtils()154     mtl::RenderUtils &getUtils() { return *mUtils; }
getStateCache()155     mtl::StateCache &getStateCache() { return mStateCache; }
getLibraryCache()156     mtl::LibraryCache &getLibraryCache() { return mLibraryCache; }
getMaxColorTargetBits()157     uint32_t getMaxColorTargetBits() { return mMaxColorTargetBits; }
hasFragmentMemoryBarriers()158     bool hasFragmentMemoryBarriers() const { return mHasFragmentMemoryBarriers; }
159 
160     id<MTLLibrary> getDefaultShadersLib();
161 
getPixelFormat(angle::FormatID angleFormatId)162     const mtl::Format &getPixelFormat(angle::FormatID angleFormatId) const
163     {
164         return mFormatTable.getPixelFormat(angleFormatId);
165     }
getNativeFormatCaps(MTLPixelFormat mtlFormat)166     const mtl::FormatCaps &getNativeFormatCaps(MTLPixelFormat mtlFormat) const
167     {
168         return mFormatTable.getNativeFormatCaps(mtlFormat);
169     }
170 
171     // See mtl::FormatTable::getVertexFormat()
getVertexFormat(angle::FormatID angleFormatId,bool tightlyPacked)172     const mtl::VertexFormat &getVertexFormat(angle::FormatID angleFormatId,
173                                              bool tightlyPacked) const
174     {
175         return mFormatTable.getVertexFormat(angleFormatId, tightlyPacked);
176     }
177 
178     angle::ObjCPtr<MTLSharedEventListener> getOrCreateSharedEventListener();
179 
180   protected:
181     void generateExtensions(egl::DisplayExtensions *outExtensions) const override;
182     void generateCaps(egl::Caps *outCaps) const override;
183 
184   private:
185     angle::Result initializeImpl(egl::Display *display);
186     void ensureCapsInitialized() const;
187     void initializeCaps() const;
188     void initializeExtensions() const;
189     void initializeTextureCaps() const;
190     void initializeFeatures();
191     void initializeLimitations();
192     EGLenum EGLDrawingBufferTextureTarget();
193     angle::ObjCPtr<id<MTLDevice>> getMetalDeviceMatchingAttribute(const egl::AttributeMap &attribs);
194     angle::Result initializeShaderLibrary();
195 
196     egl::Display *mDisplay;
197 
198     angle::ObjCPtr<id<MTLDevice>> mMetalDevice   = nil;
199     uint32_t mMetalDeviceVendorId                = 0;
200 
201     // Expensive-to-compute AMD Bronze driver detection
202     mutable bool mComputedAMDBronze = false;
203     mutable bool mIsAMDBronze       = false;
204 
205     mtl::CommandQueue mCmdQueue;
206 
207     mutable mtl::FormatTable mFormatTable;
208     mtl::StateCache mStateCache;
209     mtl::LibraryCache mLibraryCache;
210     std::unique_ptr<mtl::RenderUtils> mUtils;
211 
212     // Built-in Shaders
213     angle::ObjCPtr<id<MTLLibrary>> mDefaultShaders;
214     angle::ObjCPtr<MTLSharedEventListener> mSharedEventListener;
215 
216     mutable bool mCapsInitialized;
217     mutable gl::TextureCapsMap mNativeTextureCaps;
218     mutable gl::Extensions mNativeExtensions;
219     mutable gl::Caps mNativeCaps;
220     mutable gl::Limitations mNativeLimitations;
221     mutable ShPixelLocalStorageOptions mNativePLSOptions;
222     mutable uint32_t mMaxColorTargetBits = 0;
223     mutable bool mHasFragmentMemoryBarriers;
224 
225     angle::FeaturesMtl mFeatures;
226 };
227 
228 }  // namespace rx
229 
230 #endif /* LIBANGLE_RENDERER_METAL_DISPLAYMTL_H_ */
231