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