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 // ContextImpl: 7 // Implementation-specific functionality associated with a GL Context. 8 // 9 10 #ifndef LIBANGLE_RENDERER_CONTEXTIMPL_H_ 11 #define LIBANGLE_RENDERER_CONTEXTIMPL_H_ 12 13 #include <vector> 14 15 #include "common/angleutils.h" 16 #include "libANGLE/State.h" 17 #include "libANGLE/renderer/GLImplFactory.h" 18 19 namespace gl 20 { 21 class ErrorSet; 22 class MemoryProgramCache; 23 class Path; 24 class Semaphore; 25 struct Workarounds; 26 } // namespace gl 27 28 namespace rx 29 { 30 class ContextImpl : public GLImplFactory 31 { 32 public: 33 ContextImpl(const gl::State &state, gl::ErrorSet *errorSet); 34 ~ContextImpl() override; 35 onDestroy(const gl::Context * context)36 virtual void onDestroy(const gl::Context *context) {} 37 38 virtual angle::Result initialize() = 0; 39 40 // Flush and finish. 41 virtual angle::Result flush(const gl::Context *context) = 0; 42 virtual angle::Result finish(const gl::Context *context) = 0; 43 44 // Drawing methods. 45 virtual angle::Result drawArrays(const gl::Context *context, 46 gl::PrimitiveMode mode, 47 GLint first, 48 GLsizei count) = 0; 49 virtual angle::Result drawArraysInstanced(const gl::Context *context, 50 gl::PrimitiveMode mode, 51 GLint first, 52 GLsizei count, 53 GLsizei instanceCount) = 0; 54 // Necessary for Vulkan since gl_InstanceIndex includes baseInstance 55 virtual angle::Result drawArraysInstancedBaseInstance(const gl::Context *context, 56 gl::PrimitiveMode mode, 57 GLint first, 58 GLsizei count, 59 GLsizei instanceCount, 60 GLuint baseInstance) = 0; 61 62 virtual angle::Result drawElements(const gl::Context *context, 63 gl::PrimitiveMode mode, 64 GLsizei count, 65 gl::DrawElementsType type, 66 const void *indices) = 0; 67 virtual angle::Result drawElementsBaseVertex(const gl::Context *context, 68 gl::PrimitiveMode mode, 69 GLsizei count, 70 gl::DrawElementsType type, 71 const void *indices, 72 GLint baseVertex) = 0; 73 virtual angle::Result drawElementsInstanced(const gl::Context *context, 74 gl::PrimitiveMode mode, 75 GLsizei count, 76 gl::DrawElementsType type, 77 const void *indices, 78 GLsizei instances) = 0; 79 virtual angle::Result drawElementsInstancedBaseVertex(const gl::Context *context, 80 gl::PrimitiveMode mode, 81 GLsizei count, 82 gl::DrawElementsType type, 83 const void *indices, 84 GLsizei instances, 85 GLint baseVertex) = 0; 86 virtual angle::Result drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context, 87 gl::PrimitiveMode mode, 88 GLsizei count, 89 gl::DrawElementsType type, 90 const void *indices, 91 GLsizei instances, 92 GLint baseVertex, 93 GLuint baseInstance) = 0; 94 virtual angle::Result drawRangeElements(const gl::Context *context, 95 gl::PrimitiveMode mode, 96 GLuint start, 97 GLuint end, 98 GLsizei count, 99 gl::DrawElementsType type, 100 const void *indices) = 0; 101 virtual angle::Result drawRangeElementsBaseVertex(const gl::Context *context, 102 gl::PrimitiveMode mode, 103 GLuint start, 104 GLuint end, 105 GLsizei count, 106 gl::DrawElementsType type, 107 const void *indices, 108 GLint baseVertex) = 0; 109 110 virtual angle::Result drawArraysIndirect(const gl::Context *context, 111 gl::PrimitiveMode mode, 112 const void *indirect) = 0; 113 virtual angle::Result drawElementsIndirect(const gl::Context *context, 114 gl::PrimitiveMode mode, 115 gl::DrawElementsType type, 116 const void *indirect) = 0; 117 118 // Device loss 119 virtual gl::GraphicsResetStatus getResetStatus() = 0; 120 121 // Vendor and description strings. 122 virtual std::string getVendorString() const = 0; 123 virtual std::string getRendererDescription() const = 0; 124 125 // EXT_debug_marker 126 virtual angle::Result insertEventMarker(GLsizei length, const char *marker) = 0; 127 virtual angle::Result pushGroupMarker(GLsizei length, const char *marker) = 0; 128 virtual angle::Result popGroupMarker() = 0; 129 130 // KHR_debug 131 virtual angle::Result pushDebugGroup(const gl::Context *context, 132 GLenum source, 133 GLuint id, 134 const std::string &message) = 0; 135 virtual angle::Result popDebugGroup(const gl::Context *context) = 0; 136 137 // KHR_parallel_shader_compile setMaxShaderCompilerThreads(GLuint count)138 virtual void setMaxShaderCompilerThreads(GLuint count) {} 139 140 // GL_ANGLE_texture_storage_external 141 virtual void invalidateTexture(gl::TextureType target); 142 143 // State sync with dirty bits. 144 virtual angle::Result syncState(const gl::Context *context, 145 const gl::State::DirtyBits &dirtyBits, 146 const gl::State::DirtyBits &bitMask) = 0; 147 148 // Disjoint timer queries 149 virtual GLint getGPUDisjoint() = 0; 150 virtual GLint64 getTimestamp() = 0; 151 152 // Context switching 153 virtual angle::Result onMakeCurrent(const gl::Context *context) = 0; 154 virtual angle::Result onUnMakeCurrent(const gl::Context *context); 155 156 // Native capabilities, unmodified by gl::Context. 157 virtual gl::Caps getNativeCaps() const = 0; 158 virtual const gl::TextureCapsMap &getNativeTextureCaps() const = 0; 159 virtual const gl::Extensions &getNativeExtensions() const = 0; 160 virtual const gl::Limitations &getNativeLimitations() const = 0; 161 162 virtual angle::Result dispatchCompute(const gl::Context *context, 163 GLuint numGroupsX, 164 GLuint numGroupsY, 165 GLuint numGroupsZ) = 0; 166 virtual angle::Result dispatchComputeIndirect(const gl::Context *context, 167 GLintptr indirect) = 0; 168 169 virtual angle::Result memoryBarrier(const gl::Context *context, GLbitfield barriers) = 0; 170 virtual angle::Result memoryBarrierByRegion(const gl::Context *context, 171 GLbitfield barriers) = 0; 172 getState()173 const gl::State &getState() const { return mState; } getClientMajorVersion()174 int getClientMajorVersion() const { return mState.getClientMajorVersion(); } getClientMinorVersion()175 int getClientMinorVersion() const { return mState.getClientMinorVersion(); } getCaps()176 const gl::Caps &getCaps() const { return mState.getCaps(); } getTextureCaps()177 const gl::TextureCapsMap &getTextureCaps() const { return mState.getTextureCaps(); } getExtensions()178 const gl::Extensions &getExtensions() const { return mState.getExtensions(); } getLimitations()179 const gl::Limitations &getLimitations() const { return mState.getLimitations(); } 180 181 // A common GL driver behaviour is to trigger dynamic shader recompilation on a draw call, 182 // based on the current render states. We store a mutable pointer to the program cache so 183 // on draw calls we can store the refreshed shaders in the cache. 184 void setMemoryProgramCache(gl::MemoryProgramCache *memoryProgramCache); 185 186 void handleError(GLenum errorCode, 187 const char *message, 188 const char *file, 189 const char *function, 190 unsigned int line); 191 192 virtual egl::ContextPriority getContextPriority() const; 193 194 protected: 195 const gl::State &mState; 196 gl::MemoryProgramCache *mMemoryProgramCache; 197 gl::ErrorSet *mErrors; 198 }; 199 200 } // namespace rx 201 202 #endif // LIBANGLE_RENDERER_CONTEXTIMPL_H_ 203