1 // 2 // Copyright 2016 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 // ContextGL: 7 // OpenGL-specific functionality associated with a GL Context. 8 // 9 10 #ifndef LIBANGLE_RENDERER_GL_CONTEXTGL_H_ 11 #define LIBANGLE_RENDERER_GL_CONTEXTGL_H_ 12 13 #include "libANGLE/renderer/ContextImpl.h" 14 #include "libANGLE/renderer/gl/RendererGL.h" 15 16 namespace angle 17 { 18 struct FeaturesGL; 19 } // namespace angle 20 21 namespace sh 22 { 23 struct BlockMemberInfo; 24 } // namespace sh 25 26 namespace rx 27 { 28 class BlitGL; 29 class ClearMultiviewGL; 30 class FunctionsGL; 31 class RendererGL; 32 class StateManagerGL; 33 34 enum class RobustnessVideoMemoryPurgeStatus 35 { 36 NOT_REQUESTED = 0, 37 REQUESTED = 1, 38 }; 39 40 class ContextGL : public ContextImpl 41 { 42 public: 43 ContextGL(const gl::State &state, 44 gl::ErrorSet *errorSet, 45 const std::shared_ptr<RendererGL> &renderer, 46 RobustnessVideoMemoryPurgeStatus robustnessVideoMemoryPurgeStatus); 47 ~ContextGL() override; 48 49 angle::Result initialize(const angle::ImageLoadContext &imageLoadContext) override; 50 51 // Shader creation 52 CompilerImpl *createCompiler() override; 53 ShaderImpl *createShader(const gl::ShaderState &data) override; 54 ProgramImpl *createProgram(const gl::ProgramState &data) override; 55 ProgramExecutableImpl *createProgramExecutable( 56 const gl::ProgramExecutable *executable) override; 57 58 // Framebuffer creation 59 FramebufferImpl *createFramebuffer(const gl::FramebufferState &data) override; 60 61 // Texture creation 62 TextureImpl *createTexture(const gl::TextureState &state) override; 63 64 // Renderbuffer creation 65 RenderbufferImpl *createRenderbuffer(const gl::RenderbufferState &state) override; 66 67 // Buffer creation 68 BufferImpl *createBuffer(const gl::BufferState &state) override; 69 70 // Vertex Array creation 71 VertexArrayImpl *createVertexArray(const gl::VertexArrayState &data) override; 72 73 // Query and Fence creation 74 QueryImpl *createQuery(gl::QueryType type) override; 75 FenceNVImpl *createFenceNV() override; 76 SyncImpl *createSync() override; 77 78 // Transform Feedback creation 79 TransformFeedbackImpl *createTransformFeedback( 80 const gl::TransformFeedbackState &state) override; 81 82 // Sampler object creation 83 SamplerImpl *createSampler(const gl::SamplerState &state) override; 84 85 // Program Pipeline object creation 86 ProgramPipelineImpl *createProgramPipeline(const gl::ProgramPipelineState &data) override; 87 88 // Memory object creation. 89 MemoryObjectImpl *createMemoryObject() override; 90 91 // Semaphore creation. 92 SemaphoreImpl *createSemaphore() override; 93 94 // Overlay creation. 95 OverlayImpl *createOverlay(const gl::OverlayState &state) override; 96 97 // Flush and finish. 98 angle::Result flush(const gl::Context *context) override; 99 angle::Result finish(const gl::Context *context) override; 100 101 // Drawing methods. 102 angle::Result drawArrays(const gl::Context *context, 103 gl::PrimitiveMode mode, 104 GLint first, 105 GLsizei count) override; 106 angle::Result drawArraysInstanced(const gl::Context *context, 107 gl::PrimitiveMode mode, 108 GLint first, 109 GLsizei count, 110 GLsizei instanceCount) override; 111 angle::Result drawArraysInstancedBaseInstance(const gl::Context *context, 112 gl::PrimitiveMode mode, 113 GLint first, 114 GLsizei count, 115 GLsizei instanceCount, 116 GLuint baseInstance) override; 117 118 angle::Result drawElements(const gl::Context *context, 119 gl::PrimitiveMode mode, 120 GLsizei count, 121 gl::DrawElementsType type, 122 const void *indices) override; 123 angle::Result drawElementsBaseVertex(const gl::Context *context, 124 gl::PrimitiveMode mode, 125 GLsizei count, 126 gl::DrawElementsType type, 127 const void *indices, 128 GLint baseVertex) override; 129 angle::Result drawElementsInstanced(const gl::Context *context, 130 gl::PrimitiveMode mode, 131 GLsizei count, 132 gl::DrawElementsType type, 133 const void *indices, 134 GLsizei instances) override; 135 angle::Result drawElementsInstancedBaseVertex(const gl::Context *context, 136 gl::PrimitiveMode mode, 137 GLsizei count, 138 gl::DrawElementsType type, 139 const void *indices, 140 GLsizei instanceCount, 141 GLint baseVertex) override; 142 angle::Result drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context, 143 gl::PrimitiveMode mode, 144 GLsizei count, 145 gl::DrawElementsType type, 146 const void *indices, 147 GLsizei instances, 148 GLint baseVertex, 149 GLuint baseInstance) override; 150 angle::Result drawRangeElements(const gl::Context *context, 151 gl::PrimitiveMode mode, 152 GLuint start, 153 GLuint end, 154 GLsizei count, 155 gl::DrawElementsType type, 156 const void *indices) override; 157 angle::Result drawRangeElementsBaseVertex(const gl::Context *context, 158 gl::PrimitiveMode mode, 159 GLuint start, 160 GLuint end, 161 GLsizei count, 162 gl::DrawElementsType type, 163 const void *indices, 164 GLint baseVertex) override; 165 angle::Result drawArraysIndirect(const gl::Context *context, 166 gl::PrimitiveMode mode, 167 const void *indirect) override; 168 angle::Result drawElementsIndirect(const gl::Context *context, 169 gl::PrimitiveMode mode, 170 gl::DrawElementsType type, 171 const void *indirect) override; 172 173 angle::Result multiDrawArrays(const gl::Context *context, 174 gl::PrimitiveMode mode, 175 const GLint *firsts, 176 const GLsizei *counts, 177 GLsizei drawcount) override; 178 angle::Result multiDrawArraysInstanced(const gl::Context *context, 179 gl::PrimitiveMode mode, 180 const GLint *firsts, 181 const GLsizei *counts, 182 const GLsizei *instanceCounts, 183 GLsizei drawcount) override; 184 angle::Result multiDrawArraysIndirect(const gl::Context *context, 185 gl::PrimitiveMode mode, 186 const void *indirect, 187 GLsizei drawcount, 188 GLsizei stride) override; 189 angle::Result multiDrawElements(const gl::Context *context, 190 gl::PrimitiveMode mode, 191 const GLsizei *counts, 192 gl::DrawElementsType type, 193 const GLvoid *const *indices, 194 GLsizei drawcount) override; 195 angle::Result multiDrawElementsInstanced(const gl::Context *context, 196 gl::PrimitiveMode mode, 197 const GLsizei *counts, 198 gl::DrawElementsType type, 199 const GLvoid *const *indices, 200 const GLsizei *instanceCounts, 201 GLsizei drawcount) override; 202 angle::Result multiDrawElementsIndirect(const gl::Context *context, 203 gl::PrimitiveMode mode, 204 gl::DrawElementsType type, 205 const void *indirect, 206 GLsizei drawcount, 207 GLsizei stride) override; 208 angle::Result multiDrawArraysInstancedBaseInstance(const gl::Context *context, 209 gl::PrimitiveMode mode, 210 const GLint *firsts, 211 const GLsizei *counts, 212 const GLsizei *instanceCounts, 213 const GLuint *baseInstances, 214 GLsizei drawcount) override; 215 angle::Result multiDrawElementsInstancedBaseVertexBaseInstance(const gl::Context *context, 216 gl::PrimitiveMode mode, 217 const GLsizei *counts, 218 gl::DrawElementsType type, 219 const GLvoid *const *indices, 220 const GLsizei *instanceCounts, 221 const GLint *baseVertices, 222 const GLuint *baseInstances, 223 GLsizei drawcount) override; 224 225 // Device loss 226 gl::GraphicsResetStatus getResetStatus() override; 227 228 // EXT_debug_marker 229 angle::Result insertEventMarker(GLsizei length, const char *marker) override; 230 angle::Result pushGroupMarker(GLsizei length, const char *marker) override; 231 angle::Result popGroupMarker() override; 232 233 // KHR_debug 234 angle::Result pushDebugGroup(const gl::Context *context, 235 GLenum source, 236 GLuint id, 237 const std::string &message) override; 238 angle::Result popDebugGroup(const gl::Context *context) override; 239 240 // State sync with dirty bits. 241 angle::Result syncState(const gl::Context *context, 242 const gl::state::DirtyBits dirtyBits, 243 const gl::state::DirtyBits bitMask, 244 const gl::state::ExtendedDirtyBits extendedDirtyBits, 245 const gl::state::ExtendedDirtyBits extendedBitMask, 246 gl::Command command) override; 247 248 // Disjoint timer queries 249 GLint getGPUDisjoint() override; 250 GLint64 getTimestamp() override; 251 252 // Context switching 253 angle::Result onMakeCurrent(const gl::Context *context) override; 254 angle::Result onUnMakeCurrent(const gl::Context *context) override; 255 256 // Caps queries 257 gl::Caps getNativeCaps() const override; 258 const gl::TextureCapsMap &getNativeTextureCaps() const override; 259 const gl::Extensions &getNativeExtensions() const override; 260 const gl::Limitations &getNativeLimitations() const override; 261 const ShPixelLocalStorageOptions &getNativePixelLocalStorageOptions() const override; 262 263 // Handle helpers getFunctions()264 ANGLE_INLINE const FunctionsGL *getFunctions() const { return mRenderer->getFunctions(); } 265 266 StateManagerGL *getStateManager(); 267 const angle::FeaturesGL &getFeaturesGL() const; 268 BlitGL *getBlitter() const; 269 ClearMultiviewGL *getMultiviewClearer() const; 270 271 angle::Result dispatchCompute(const gl::Context *context, 272 GLuint numGroupsX, 273 GLuint numGroupsY, 274 GLuint numGroupsZ) override; 275 angle::Result dispatchComputeIndirect(const gl::Context *context, GLintptr indirect) override; 276 277 angle::Result memoryBarrier(const gl::Context *context, GLbitfield barriers) override; 278 angle::Result memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) override; 279 280 void framebufferFetchBarrier() override; 281 282 angle::Result startTiling(const gl::Context *context, 283 const gl::Rectangle &area, 284 GLbitfield preserveMask) override; 285 angle::Result endTiling(const gl::Context *context, GLbitfield preserveMask) override; 286 287 void setMaxShaderCompilerThreads(GLuint count) override; 288 289 void invalidateTexture(gl::TextureType target) override; 290 291 void validateState() const; 292 293 void setNeedsFlushBeforeDeleteTextures(); 294 void flushIfNecessaryBeforeDeleteTextures(); 295 296 void markWorkSubmitted(); 297 298 MultiviewImplementationTypeGL getMultiviewImplementationType() const; 299 bool hasNativeParallelCompile(); 300 getDebug()301 const gl::Debug &getDebug() const { return mState.getDebug(); } 302 303 private: 304 angle::Result setDrawArraysState(const gl::Context *context, 305 GLint first, 306 GLsizei count, 307 GLsizei instanceCount); 308 309 angle::Result setDrawElementsState(const gl::Context *context, 310 GLsizei count, 311 gl::DrawElementsType type, 312 const void *indices, 313 GLsizei instanceCount, 314 const void **outIndices); 315 316 gl::AttributesMask updateAttributesForBaseInstance(GLuint baseInstance); 317 void resetUpdatedAttributes(gl::AttributesMask attribMask); 318 319 protected: 320 std::shared_ptr<RendererGL> mRenderer; 321 322 RobustnessVideoMemoryPurgeStatus mRobustnessVideoMemoryPurgeStatus; 323 }; 324 325 } // namespace rx 326 327 #endif // LIBANGLE_RENDERER_GL_CONTEXTGL_H_ 328