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 15 #include "libANGLE/Caps.h" 16 #include "libANGLE/Error.h" 17 #include "libANGLE/Version.h" 18 #include "libANGLE/renderer/gl/renderergl_utils.h" 19 #include "platform/autogen/FeaturesGL_autogen.h" 20 21 namespace angle 22 { 23 struct FrontendFeatures; 24 } // namespace angle 25 26 namespace gl 27 { 28 struct IndexRange; 29 class Path; 30 class State; 31 } // namespace gl 32 33 namespace egl 34 { 35 class AttributeMap; 36 } // namespace egl 37 38 namespace sh 39 { 40 struct BlockMemberInfo; 41 } // namespace sh 42 43 namespace rx 44 { 45 class BlitGL; 46 class ClearMultiviewGL; 47 class ContextImpl; 48 class DisplayGL; 49 class FunctionsGL; 50 class PLSProgramCache; 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 [[nodiscard]] 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 PLSProgramCache *getPLSProgramCache(); 110 111 MultiviewImplementationTypeGL getMultiviewImplementationType() const; 112 const gl::Caps &getNativeCaps() const; 113 const gl::TextureCapsMap &getNativeTextureCaps() const; 114 const gl::Extensions &getNativeExtensions() const; 115 const gl::Limitations &getNativeLimitations() const; 116 const ShPixelLocalStorageOptions &getNativePixelLocalStorageOptions() const; 117 void initializeFrontendFeatures(angle::FrontendFeatures *features) const; 118 119 angle::Result dispatchCompute(const gl::Context *context, 120 GLuint numGroupsX, 121 GLuint numGroupsY, 122 GLuint numGroupsZ); 123 angle::Result dispatchComputeIndirect(const gl::Context *context, GLintptr indirect); 124 125 angle::Result memoryBarrier(GLbitfield barriers); 126 angle::Result memoryBarrierByRegion(GLbitfield barriers); 127 128 void framebufferFetchBarrier(); 129 130 bool bindWorkerContext(std::string *infoLog); 131 void unbindWorkerContext(); 132 // Checks if the driver has the KHR_parallel_shader_compile or ARB_parallel_shader_compile 133 // extension. 134 bool hasNativeParallelCompile(); 135 void setMaxShaderCompilerThreads(GLuint count); 136 137 static unsigned int getMaxWorkerContexts(); 138 139 void setNeedsFlushBeforeDeleteTextures(); 140 void flushIfNecessaryBeforeDeleteTextures(); 141 142 void markWorkSubmitted(); 143 144 void handleGPUSwitch(); 145 146 protected: 147 virtual WorkerContext *createWorkerContext(std::string *infoLog) = 0; 148 149 private: 150 void ensureCapsInitialized() const; 151 void generateCaps(gl::Caps *outCaps, 152 gl::TextureCapsMap *outTextureCaps, 153 gl::Extensions *outExtensions, 154 gl::Limitations *outLimitations) const; 155 156 mutable gl::Version mMaxSupportedESVersion; 157 158 std::unique_ptr<FunctionsGL> mFunctions; 159 StateManagerGL *mStateManager; 160 161 BlitGL *mBlitter; 162 ClearMultiviewGL *mMultiviewClearer; 163 164 // Load/store programs for EXT_shader_pixel_local_storage. 165 PLSProgramCache *mPLSProgramCache = nullptr; 166 167 bool mUseDebugOutput; 168 169 mutable bool mCapsInitialized; 170 mutable gl::Caps mNativeCaps; 171 mutable gl::TextureCapsMap mNativeTextureCaps; 172 mutable gl::Extensions mNativeExtensions; 173 mutable gl::Limitations mNativeLimitations; 174 mutable ShPixelLocalStorageOptions mNativePLSOptions; 175 mutable MultiviewImplementationTypeGL mMultiviewImplementationType; 176 177 bool mWorkDoneSinceLastFlush = false; 178 179 // The thread-to-context mapping for the currently active worker threads. 180 angle::HashMap<uint64_t, std::unique_ptr<WorkerContext>> mCurrentWorkerContexts; 181 // The worker contexts available to use. 182 std::list<std::unique_ptr<WorkerContext>> mWorkerContextPool; 183 // Protect the concurrent accesses to worker contexts. 184 std::mutex mWorkerMutex; 185 186 bool mNativeParallelCompileEnabled; 187 188 angle::FeaturesGL mFeatures; 189 190 // Workaround for anglebug.com/4267 191 bool mNeedsFlushBeforeDeleteTextures; 192 }; 193 194 } // namespace rx 195 196 #endif // LIBANGLE_RENDERER_GL_RENDERERGL_H_ 197