• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 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 
7 // RendererGL.h: Defines the class interface for RendererGL.
8 
9 #ifndef LIBANGLE_RENDERER_GL_RENDERERGL_H_
10 #define LIBANGLE_RENDERER_GL_RENDERERGL_H_
11 
12 #include <list>
13 #include <mutex>
14 #include <thread>
15 
16 #include "libANGLE/Caps.h"
17 #include "libANGLE/Error.h"
18 #include "libANGLE/Version.h"
19 #include "libANGLE/renderer/gl/renderergl_utils.h"
20 #include "platform/FeaturesGL.h"
21 
22 namespace angle
23 {
24 struct FrontendFeatures;
25 }  // namespace angle
26 
27 namespace gl
28 {
29 struct IndexRange;
30 class Path;
31 class State;
32 }  // namespace gl
33 
34 namespace egl
35 {
36 class AttributeMap;
37 }  // namespace egl
38 
39 namespace sh
40 {
41 struct BlockMemberInfo;
42 }  // namespace sh
43 
44 namespace rx
45 {
46 class BlitGL;
47 class ClearMultiviewGL;
48 class ContextImpl;
49 class DisplayGL;
50 class FunctionsGL;
51 class RendererGL;
52 class StateManagerGL;
53 
54 // WorkerContext wraps a native GL context shared from the main context. It is used by the workers
55 // for khr_parallel_shader_compile.
56 class WorkerContext : angle::NonCopyable
57 {
58   public:
~WorkerContext()59     virtual ~WorkerContext() {}
60 
61     virtual bool makeCurrent()   = 0;
62     virtual void unmakeCurrent() = 0;
63 };
64 
65 class ScopedWorkerContextGL
66 {
67   public:
68     ScopedWorkerContextGL(RendererGL *renderer, std::string *infoLog);
69     ~ScopedWorkerContextGL();
70 
71     bool operator()() const;
72 
73   private:
74     RendererGL *mRenderer = nullptr;
75     bool mValid           = false;
76 };
77 
78 class RendererGL : angle::NonCopyable
79 {
80   public:
81     RendererGL(std::unique_ptr<FunctionsGL> functions,
82                const egl::AttributeMap &attribMap,
83                DisplayGL *display);
84     virtual ~RendererGL();
85 
86     angle::Result flush();
87     angle::Result finish();
88 
89     // CHROMIUM_path_rendering implementation
90     void stencilFillPath(const gl::State &state,
91                          const gl::Path *path,
92                          GLenum fillMode,
93                          GLuint mask);
94     void stencilStrokePath(const gl::State &state,
95                            const gl::Path *path,
96                            GLint reference,
97                            GLuint mask);
98     void coverFillPath(const gl::State &state, const gl::Path *path, GLenum coverMode);
99     void coverStrokePath(const gl::State &state, const gl::Path *path, GLenum coverMode);
100     void stencilThenCoverFillPath(const gl::State &state,
101                                   const gl::Path *path,
102                                   GLenum fillMode,
103                                   GLuint mask,
104                                   GLenum coverMode);
105     void stencilThenCoverStrokePath(const gl::State &state,
106                                     const gl::Path *path,
107                                     GLint reference,
108                                     GLuint mask,
109                                     GLenum coverMode);
110     void coverFillPathInstanced(const gl::State &state,
111                                 const std::vector<gl::Path *> &paths,
112                                 GLenum coverMode,
113                                 GLenum transformType,
114                                 const GLfloat *transformValues);
115     void coverStrokePathInstanced(const gl::State &state,
116                                   const std::vector<gl::Path *> &paths,
117                                   GLenum coverMode,
118                                   GLenum transformType,
119                                   const GLfloat *transformValues);
120     void stencilFillPathInstanced(const gl::State &state,
121                                   const std::vector<gl::Path *> &paths,
122                                   GLenum fillMode,
123                                   GLuint mask,
124                                   GLenum transformType,
125                                   const GLfloat *transformValues);
126     void stencilStrokePathInstanced(const gl::State &state,
127                                     const std::vector<gl::Path *> &paths,
128                                     GLint reference,
129                                     GLuint mask,
130                                     GLenum transformType,
131                                     const GLfloat *transformValues);
132 
133     void stencilThenCoverFillPathInstanced(const gl::State &state,
134                                            const std::vector<gl::Path *> &paths,
135                                            GLenum coverMode,
136                                            GLenum fillMode,
137                                            GLuint mask,
138                                            GLenum transformType,
139                                            const GLfloat *transformValues);
140     void stencilThenCoverStrokePathInstanced(const gl::State &state,
141                                              const std::vector<gl::Path *> &paths,
142                                              GLenum coverMode,
143                                              GLint reference,
144                                              GLuint mask,
145                                              GLenum transformType,
146                                              const GLfloat *transformValues);
147 
148     gl::GraphicsResetStatus getResetStatus();
149 
150     // EXT_debug_marker
151     void insertEventMarker(GLsizei length, const char *marker);
152     void pushGroupMarker(GLsizei length, const char *marker);
153     void popGroupMarker();
154 
155     // KHR_debug
156     void pushDebugGroup(GLenum source, GLuint id, const std::string &message);
157     void popDebugGroup();
158 
159     std::string getVendorString() const;
160     std::string getRendererDescription() const;
161 
162     GLint getGPUDisjoint();
163     GLint64 getTimestamp();
164 
165     const gl::Version &getMaxSupportedESVersion() const;
getFunctions()166     const FunctionsGL *getFunctions() const { return mFunctions.get(); }
getStateManager()167     StateManagerGL *getStateManager() const { return mStateManager; }
getFeatures()168     const angle::FeaturesGL &getFeatures() const { return mFeatures; }
getBlitter()169     BlitGL *getBlitter() const { return mBlitter; }
getMultiviewClearer()170     ClearMultiviewGL *getMultiviewClearer() const { return mMultiviewClearer; }
171 
172     MultiviewImplementationTypeGL getMultiviewImplementationType() const;
173     const gl::Caps &getNativeCaps() const;
174     const gl::TextureCapsMap &getNativeTextureCaps() const;
175     const gl::Extensions &getNativeExtensions() const;
176     const gl::Limitations &getNativeLimitations() const;
177     void initializeFrontendFeatures(angle::FrontendFeatures *features) const;
178 
179     angle::Result dispatchCompute(const gl::Context *context,
180                                   GLuint numGroupsX,
181                                   GLuint numGroupsY,
182                                   GLuint numGroupsZ);
183     angle::Result dispatchComputeIndirect(const gl::Context *context, GLintptr indirect);
184 
185     angle::Result memoryBarrier(GLbitfield barriers);
186     angle::Result memoryBarrierByRegion(GLbitfield barriers);
187 
188     bool bindWorkerContext(std::string *infoLog);
189     void unbindWorkerContext();
190     // Checks if the driver has the KHR_parallel_shader_compile or ARB_parallel_shader_compile
191     // extension.
192     bool hasNativeParallelCompile();
193     void setMaxShaderCompilerThreads(GLuint count);
194 
195     static unsigned int getMaxWorkerContexts();
196 
197   protected:
198     virtual WorkerContext *createWorkerContext(std::string *infoLog) = 0;
199 
200   private:
201     void ensureCapsInitialized() const;
202     void generateCaps(gl::Caps *outCaps,
203                       gl::TextureCapsMap *outTextureCaps,
204                       gl::Extensions *outExtensions,
205                       gl::Limitations *outLimitations) const;
206 
207     mutable gl::Version mMaxSupportedESVersion;
208 
209     std::unique_ptr<FunctionsGL> mFunctions;
210     StateManagerGL *mStateManager;
211 
212     BlitGL *mBlitter;
213     ClearMultiviewGL *mMultiviewClearer;
214 
215     bool mUseDebugOutput;
216 
217     mutable bool mCapsInitialized;
218     mutable gl::Caps mNativeCaps;
219     mutable gl::TextureCapsMap mNativeTextureCaps;
220     mutable gl::Extensions mNativeExtensions;
221     mutable gl::Limitations mNativeLimitations;
222     mutable MultiviewImplementationTypeGL mMultiviewImplementationType;
223 
224     // The thread-to-context mapping for the currently active worker threads.
225     std::unordered_map<std::thread::id, std::unique_ptr<WorkerContext>> mCurrentWorkerContexts;
226     // The worker contexts available to use.
227     std::list<std::unique_ptr<WorkerContext>> mWorkerContextPool;
228     // Protect the concurrent accesses to worker contexts.
229     std::mutex mWorkerMutex;
230 
231     bool mNativeParallelCompileEnabled;
232 
233     angle::FeaturesGL mFeatures;
234 };
235 
236 }  // namespace rx
237 
238 #endif  // LIBANGLE_RENDERER_GL_RENDERERGL_H_
239