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 gl::GraphicsResetStatus getResetStatus(); 90 91 // EXT_debug_marker 92 void insertEventMarker(GLsizei length, const char *marker); 93 void pushGroupMarker(GLsizei length, const char *marker); 94 void popGroupMarker(); 95 96 // KHR_debug 97 void pushDebugGroup(GLenum source, GLuint id, const std::string &message); 98 void popDebugGroup(); 99 100 GLint getGPUDisjoint(); 101 GLint64 getTimestamp(); 102 103 const gl::Version &getMaxSupportedESVersion() const; getFunctions()104 const FunctionsGL *getFunctions() const { return mFunctions.get(); } getStateManager()105 StateManagerGL *getStateManager() const { return mStateManager; } getFeatures()106 const angle::FeaturesGL &getFeatures() const { return mFeatures; } getBlitter()107 BlitGL *getBlitter() const { return mBlitter; } getMultiviewClearer()108 ClearMultiviewGL *getMultiviewClearer() const { return mMultiviewClearer; } 109 110 MultiviewImplementationTypeGL getMultiviewImplementationType() const; 111 const gl::Caps &getNativeCaps() const; 112 const gl::TextureCapsMap &getNativeTextureCaps() const; 113 const gl::Extensions &getNativeExtensions() const; 114 const gl::Limitations &getNativeLimitations() const; 115 void initializeFrontendFeatures(angle::FrontendFeatures *features) const; 116 117 angle::Result dispatchCompute(const gl::Context *context, 118 GLuint numGroupsX, 119 GLuint numGroupsY, 120 GLuint numGroupsZ); 121 angle::Result dispatchComputeIndirect(const gl::Context *context, GLintptr indirect); 122 123 angle::Result memoryBarrier(GLbitfield barriers); 124 angle::Result memoryBarrierByRegion(GLbitfield barriers); 125 126 bool bindWorkerContext(std::string *infoLog); 127 void unbindWorkerContext(); 128 // Checks if the driver has the KHR_parallel_shader_compile or ARB_parallel_shader_compile 129 // extension. 130 bool hasNativeParallelCompile(); 131 void setMaxShaderCompilerThreads(GLuint count); 132 133 static unsigned int getMaxWorkerContexts(); 134 135 void setNeedsFlushBeforeDeleteTextures(); 136 void flushIfNecessaryBeforeDeleteTextures(); 137 138 void markWorkSubmitted(); 139 140 void handleGPUSwitch(); 141 142 protected: 143 virtual WorkerContext *createWorkerContext(std::string *infoLog) = 0; 144 145 private: 146 void ensureCapsInitialized() const; 147 void generateCaps(gl::Caps *outCaps, 148 gl::TextureCapsMap *outTextureCaps, 149 gl::Extensions *outExtensions, 150 gl::Limitations *outLimitations) const; 151 152 mutable gl::Version mMaxSupportedESVersion; 153 154 std::unique_ptr<FunctionsGL> mFunctions; 155 StateManagerGL *mStateManager; 156 157 BlitGL *mBlitter; 158 ClearMultiviewGL *mMultiviewClearer; 159 160 bool mUseDebugOutput; 161 162 mutable bool mCapsInitialized; 163 mutable gl::Caps mNativeCaps; 164 mutable gl::TextureCapsMap mNativeTextureCaps; 165 mutable gl::Extensions mNativeExtensions; 166 mutable gl::Limitations mNativeLimitations; 167 mutable MultiviewImplementationTypeGL mMultiviewImplementationType; 168 169 bool mWorkDoneSinceLastFlush = false; 170 171 // The thread-to-context mapping for the currently active worker threads. 172 angle::HashMap<std::thread::id, std::unique_ptr<WorkerContext>> mCurrentWorkerContexts; 173 // The worker contexts available to use. 174 std::list<std::unique_ptr<WorkerContext>> mWorkerContextPool; 175 // Protect the concurrent accesses to worker contexts. 176 std::mutex mWorkerMutex; 177 178 bool mNativeParallelCompileEnabled; 179 180 angle::FeaturesGL mFeatures; 181 182 // Workaround for anglebug.com/4267 183 bool mNeedsFlushBeforeDeleteTextures; 184 }; 185 186 } // namespace rx 187 188 #endif // LIBANGLE_RENDERER_GL_RENDERERGL_H_ 189