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