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