• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     // MultiDraw* impl added as we need workaround for promoting dynamic attributes in D3D backend
119     virtual angle::Result multiDrawArrays(const gl::Context *context,
120                                           gl::PrimitiveMode mode,
121                                           const GLint *firsts,
122                                           const GLsizei *counts,
123                                           GLsizei drawcount)                      = 0;
124     virtual angle::Result multiDrawArraysIndirect(const gl::Context *context,
125                                                   gl::PrimitiveMode mode,
126                                                   const void *indirect,
127                                                   GLsizei drawcount,
128                                                   GLsizei stride)                 = 0;
129     virtual angle::Result multiDrawArraysInstanced(const gl::Context *context,
130                                                    gl::PrimitiveMode mode,
131                                                    const GLint *firsts,
132                                                    const GLsizei *counts,
133                                                    const GLsizei *instanceCounts,
134                                                    GLsizei drawcount)             = 0;
135     virtual angle::Result multiDrawElements(const gl::Context *context,
136                                             gl::PrimitiveMode mode,
137                                             const GLsizei *counts,
138                                             gl::DrawElementsType type,
139                                             const GLvoid *const *indices,
140                                             GLsizei drawcount)                    = 0;
141     virtual angle::Result multiDrawElementsInstanced(const gl::Context *context,
142                                                      gl::PrimitiveMode mode,
143                                                      const GLsizei *counts,
144                                                      gl::DrawElementsType type,
145                                                      const GLvoid *const *indices,
146                                                      const GLsizei *instanceCounts,
147                                                      GLsizei drawcount)           = 0;
148     virtual angle::Result multiDrawElementsIndirect(const gl::Context *context,
149                                                     gl::PrimitiveMode mode,
150                                                     gl::DrawElementsType type,
151                                                     const void *indirect,
152                                                     GLsizei drawcount,
153                                                     GLsizei stride)               = 0;
154     virtual angle::Result multiDrawArraysInstancedBaseInstance(const gl::Context *context,
155                                                                gl::PrimitiveMode mode,
156                                                                const GLint *firsts,
157                                                                const GLsizei *counts,
158                                                                const GLsizei *instanceCounts,
159                                                                const GLuint *baseInstances,
160                                                                GLsizei drawcount) = 0;
161     virtual angle::Result multiDrawElementsInstancedBaseVertexBaseInstance(
162         const gl::Context *context,
163         gl::PrimitiveMode mode,
164         const GLsizei *counts,
165         gl::DrawElementsType type,
166         const GLvoid *const *indices,
167         const GLsizei *instanceCounts,
168         const GLint *baseVertices,
169         const GLuint *baseInstances,
170         GLsizei drawcount) = 0;
171 
172     // Device loss
173     virtual gl::GraphicsResetStatus getResetStatus() = 0;
174 
175     // EXT_debug_marker
176     virtual angle::Result insertEventMarker(GLsizei length, const char *marker) = 0;
177     virtual angle::Result pushGroupMarker(GLsizei length, const char *marker)   = 0;
178     virtual angle::Result popGroupMarker()                                      = 0;
179 
180     // KHR_debug
181     virtual angle::Result pushDebugGroup(const gl::Context *context,
182                                          GLenum source,
183                                          GLuint id,
184                                          const std::string &message) = 0;
185     virtual angle::Result popDebugGroup(const gl::Context *context)  = 0;
186     virtual angle::Result handleNoopDrawEvent();
187 
188     // KHR_parallel_shader_compile
setMaxShaderCompilerThreads(GLuint count)189     virtual void setMaxShaderCompilerThreads(GLuint count) {}
190 
191     // GL_ANGLE_texture_storage_external
192     virtual void invalidateTexture(gl::TextureType target);
193 
194     // EXT_shader_framebuffer_fetch_non_coherent
framebufferFetchBarrier()195     virtual void framebufferFetchBarrier() {}
196 
197     // State sync with dirty bits.
198     virtual angle::Result syncState(const gl::Context *context,
199                                     const gl::State::DirtyBits &dirtyBits,
200                                     const gl::State::DirtyBits &bitMask,
201                                     gl::Command command) = 0;
202 
203     // Disjoint timer queries
204     virtual GLint getGPUDisjoint() = 0;
205     virtual GLint64 getTimestamp() = 0;
206 
207     // Context switching
208     virtual angle::Result onMakeCurrent(const gl::Context *context) = 0;
209     virtual angle::Result onUnMakeCurrent(const gl::Context *context);
210 
211     // Native capabilities, unmodified by gl::Context.
212     virtual gl::Caps getNativeCaps() const                         = 0;
213     virtual const gl::TextureCapsMap &getNativeTextureCaps() const = 0;
214     virtual const gl::Extensions &getNativeExtensions() const      = 0;
215     virtual const gl::Limitations &getNativeLimitations() const    = 0;
216 
217     virtual angle::Result dispatchCompute(const gl::Context *context,
218                                           GLuint numGroupsX,
219                                           GLuint numGroupsY,
220                                           GLuint numGroupsZ)         = 0;
221     virtual angle::Result dispatchComputeIndirect(const gl::Context *context,
222                                                   GLintptr indirect) = 0;
223 
224     virtual angle::Result memoryBarrier(const gl::Context *context, GLbitfield barriers) = 0;
225     virtual angle::Result memoryBarrierByRegion(const gl::Context *context,
226                                                 GLbitfield barriers)                     = 0;
227 
getState()228     const gl::State &getState() const { return mState; }
getClientMajorVersion()229     int getClientMajorVersion() const { return mState.getClientMajorVersion(); }
getClientMinorVersion()230     int getClientMinorVersion() const { return mState.getClientMinorVersion(); }
getCaps()231     const gl::Caps &getCaps() const { return mState.getCaps(); }
getTextureCaps()232     const gl::TextureCapsMap &getTextureCaps() const { return mState.getTextureCaps(); }
getExtensions()233     const gl::Extensions &getExtensions() const { return mState.getExtensions(); }
getLimitations()234     const gl::Limitations &getLimitations() const { return mState.getLimitations(); }
235 
236     // A common GL driver behaviour is to trigger dynamic shader recompilation on a draw call,
237     // based on the current render states. We store a mutable pointer to the program cache so
238     // on draw calls we can store the refreshed shaders in the cache.
239     void setMemoryProgramCache(gl::MemoryProgramCache *memoryProgramCache);
240 
241     void handleError(GLenum errorCode,
242                      const char *message,
243                      const char *file,
244                      const char *function,
245                      unsigned int line);
246 
247     virtual egl::ContextPriority getContextPriority() const;
248 
249     // EGL_ANGLE_power_preference implementation.
250     virtual egl::Error releaseHighPowerGPU(gl::Context *context);
251     virtual egl::Error reacquireHighPowerGPU(gl::Context *context);
252 
253     // GL_ANGLE_vulkan_image
254     virtual angle::Result acquireTextures(const gl::Context *context,
255                                           const gl::TextureBarrierVector &textureBarriers);
256     virtual angle::Result releaseTextures(const gl::Context *context,
257                                           gl::TextureBarrierVector *textureBarriers);
258 
259   protected:
260     const gl::State &mState;
261     gl::MemoryProgramCache *mMemoryProgramCache;
262     gl::ErrorSet *mErrors;
263 };
264 
265 }  // namespace rx
266 
267 #endif  // LIBANGLE_RENDERER_CONTEXTIMPL_H_
268