• 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 // Context11:
7 //   D3D11-specific functionality associated with a GL Context.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_D3D_D3D11_CONTEXT11_H_
11 #define LIBANGLE_RENDERER_D3D_D3D11_CONTEXT11_H_
12 
13 #include <stack>
14 #include "libANGLE/renderer/ContextImpl.h"
15 #include "libANGLE/renderer/d3d/ContextD3D.h"
16 #include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h"
17 
18 namespace rx
19 {
20 class Renderer11;
21 
22 class Context11 : public ContextD3D, public MultisampleTextureInitializer
23 {
24   public:
25     Context11(const gl::State &state, gl::ErrorSet *errorSet, Renderer11 *renderer);
26     ~Context11() override;
27 
28     angle::Result initialize() override;
29     void onDestroy(const gl::Context *context) override;
30 
31     // Shader creation
32     CompilerImpl *createCompiler() override;
33     ShaderImpl *createShader(const gl::ShaderState &data) override;
34     ProgramImpl *createProgram(const gl::ProgramState &data) override;
35 
36     // Framebuffer creation
37     FramebufferImpl *createFramebuffer(const gl::FramebufferState &data) override;
38 
39     // Texture creation
40     TextureImpl *createTexture(const gl::TextureState &state) override;
41 
42     // Renderbuffer creation
43     RenderbufferImpl *createRenderbuffer(const gl::RenderbufferState &state) override;
44 
45     // Buffer creation
46     BufferImpl *createBuffer(const gl::BufferState &state) override;
47 
48     // Vertex Array creation
49     VertexArrayImpl *createVertexArray(const gl::VertexArrayState &data) override;
50 
51     // Query and Fence creation
52     QueryImpl *createQuery(gl::QueryType type) override;
53     FenceNVImpl *createFenceNV() override;
54     SyncImpl *createSync() override;
55 
56     // Transform Feedback creation
57     TransformFeedbackImpl *createTransformFeedback(
58         const gl::TransformFeedbackState &state) override;
59 
60     // Sampler object creation
61     SamplerImpl *createSampler(const gl::SamplerState &state) override;
62 
63     // Program Pipeline object creation
64     ProgramPipelineImpl *createProgramPipeline(const gl::ProgramPipelineState &data) override;
65 
66     // Memory object creation.
67     MemoryObjectImpl *createMemoryObject() override;
68 
69     // Semaphore creation.
70     SemaphoreImpl *createSemaphore() override;
71 
72     // Overlay creation.
73     OverlayImpl *createOverlay(const gl::OverlayState &state) override;
74 
75     // Flush and finish.
76     angle::Result flush(const gl::Context *context) override;
77     angle::Result finish(const gl::Context *context) override;
78 
79     // Drawing methods.
80     angle::Result drawArrays(const gl::Context *context,
81                              gl::PrimitiveMode mode,
82                              GLint first,
83                              GLsizei count) override;
84     angle::Result drawArraysInstanced(const gl::Context *context,
85                                       gl::PrimitiveMode mode,
86                                       GLint first,
87                                       GLsizei count,
88                                       GLsizei instanceCount) override;
89     angle::Result drawArraysInstancedBaseInstance(const gl::Context *context,
90                                                   gl::PrimitiveMode mode,
91                                                   GLint first,
92                                                   GLsizei count,
93                                                   GLsizei instanceCount,
94                                                   GLuint baseInstance) override;
95 
96     angle::Result drawElements(const gl::Context *context,
97                                gl::PrimitiveMode mode,
98                                GLsizei count,
99                                gl::DrawElementsType type,
100                                const void *indices) override;
101     angle::Result drawElementsBaseVertex(const gl::Context *context,
102                                          gl::PrimitiveMode mode,
103                                          GLsizei count,
104                                          gl::DrawElementsType type,
105                                          const void *indices,
106                                          GLint baseVertex) override;
107     angle::Result drawElementsInstanced(const gl::Context *context,
108                                         gl::PrimitiveMode mode,
109                                         GLsizei count,
110                                         gl::DrawElementsType type,
111                                         const void *indices,
112                                         GLsizei instances) override;
113     angle::Result drawElementsInstancedBaseVertex(const gl::Context *context,
114                                                   gl::PrimitiveMode mode,
115                                                   GLsizei count,
116                                                   gl::DrawElementsType type,
117                                                   const void *indices,
118                                                   GLsizei instances,
119                                                   GLint baseVertex) override;
120     angle::Result drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context,
121                                                               gl::PrimitiveMode mode,
122                                                               GLsizei count,
123                                                               gl::DrawElementsType type,
124                                                               const void *indices,
125                                                               GLsizei instances,
126                                                               GLint baseVertex,
127                                                               GLuint baseInstance) override;
128     angle::Result drawRangeElements(const gl::Context *context,
129                                     gl::PrimitiveMode mode,
130                                     GLuint start,
131                                     GLuint end,
132                                     GLsizei count,
133                                     gl::DrawElementsType type,
134                                     const void *indices) override;
135     angle::Result drawRangeElementsBaseVertex(const gl::Context *context,
136                                               gl::PrimitiveMode mode,
137                                               GLuint start,
138                                               GLuint end,
139                                               GLsizei count,
140                                               gl::DrawElementsType type,
141                                               const void *indices,
142                                               GLint baseVertex) override;
143     angle::Result drawArraysIndirect(const gl::Context *context,
144                                      gl::PrimitiveMode mode,
145                                      const void *indirect) override;
146     angle::Result drawElementsIndirect(const gl::Context *context,
147                                        gl::PrimitiveMode mode,
148                                        gl::DrawElementsType type,
149                                        const void *indirect) override;
150 
151     angle::Result multiDrawArrays(const gl::Context *context,
152                                   gl::PrimitiveMode mode,
153                                   const GLint *firsts,
154                                   const GLsizei *counts,
155                                   GLsizei drawcount) override;
156     angle::Result multiDrawArraysInstanced(const gl::Context *context,
157                                            gl::PrimitiveMode mode,
158                                            const GLint *firsts,
159                                            const GLsizei *counts,
160                                            const GLsizei *instanceCounts,
161                                            GLsizei drawcount) override;
162     angle::Result multiDrawArraysIndirect(const gl::Context *context,
163                                           gl::PrimitiveMode mode,
164                                           const void *indirect,
165                                           GLsizei drawcount,
166                                           GLsizei stride) override;
167     angle::Result multiDrawElements(const gl::Context *context,
168                                     gl::PrimitiveMode mode,
169                                     const GLsizei *counts,
170                                     gl::DrawElementsType type,
171                                     const GLvoid *const *indices,
172                                     GLsizei drawcount) override;
173     angle::Result multiDrawElementsInstanced(const gl::Context *context,
174                                              gl::PrimitiveMode mode,
175                                              const GLsizei *counts,
176                                              gl::DrawElementsType type,
177                                              const GLvoid *const *indices,
178                                              const GLsizei *instanceCounts,
179                                              GLsizei drawcount) override;
180     angle::Result multiDrawElementsIndirect(const gl::Context *context,
181                                             gl::PrimitiveMode mode,
182                                             gl::DrawElementsType type,
183                                             const void *indirect,
184                                             GLsizei drawcount,
185                                             GLsizei stride) override;
186     angle::Result multiDrawArraysInstancedBaseInstance(const gl::Context *context,
187                                                        gl::PrimitiveMode mode,
188                                                        const GLint *firsts,
189                                                        const GLsizei *counts,
190                                                        const GLsizei *instanceCounts,
191                                                        const GLuint *baseInstances,
192                                                        GLsizei drawcount) override;
193     angle::Result multiDrawElementsInstancedBaseVertexBaseInstance(const gl::Context *context,
194                                                                    gl::PrimitiveMode mode,
195                                                                    const GLsizei *counts,
196                                                                    gl::DrawElementsType type,
197                                                                    const GLvoid *const *indices,
198                                                                    const GLsizei *instanceCounts,
199                                                                    const GLint *baseVertices,
200                                                                    const GLuint *baseInstances,
201                                                                    GLsizei drawcount) override;
202 
203     // Device loss
204     gl::GraphicsResetStatus getResetStatus() override;
205 
206     // EXT_debug_marker
207     angle::Result insertEventMarker(GLsizei length, const char *marker) override;
208     angle::Result pushGroupMarker(GLsizei length, const char *marker) override;
209     angle::Result popGroupMarker() override;
210 
211     // KHR_debug
212     angle::Result pushDebugGroup(const gl::Context *context,
213                                  GLenum source,
214                                  GLuint id,
215                                  const std::string &message) override;
216     angle::Result popDebugGroup(const gl::Context *context) override;
217 
218     // State sync with dirty bits.
219     angle::Result syncState(const gl::Context *context,
220                             const gl::state::DirtyBits dirtyBits,
221                             const gl::state::DirtyBits bitMask,
222                             const gl::state::ExtendedDirtyBits extendedDirtyBits,
223                             const gl::state::ExtendedDirtyBits extendedBitMask,
224                             gl::Command command) override;
225 
226     // Disjoint timer queries
227     GLint getGPUDisjoint() override;
228     GLint64 getTimestamp() override;
229 
230     // Context switching
231     angle::Result onMakeCurrent(const gl::Context *context) override;
232 
233     // Caps queries
234     gl::Caps getNativeCaps() const override;
235     const gl::TextureCapsMap &getNativeTextureCaps() const override;
236     const gl::Extensions &getNativeExtensions() const override;
237     const gl::Limitations &getNativeLimitations() const override;
238     const ShPixelLocalStorageOptions &getNativePixelLocalStorageOptions() const override;
239 
getRenderer()240     Renderer11 *getRenderer() const { return mRenderer; }
241     angle::ImageLoadContext getImageLoadContext() const;
242 
243     angle::Result dispatchCompute(const gl::Context *context,
244                                   GLuint numGroupsX,
245                                   GLuint numGroupsY,
246                                   GLuint numGroupsZ) override;
247     angle::Result dispatchComputeIndirect(const gl::Context *context, GLintptr indirect) override;
248 
249     angle::Result memoryBarrier(const gl::Context *context, GLbitfield barriers) override;
250     angle::Result memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) override;
251 
252     angle::Result triggerDrawCallProgramRecompilation(const gl::Context *context,
253                                                       gl::PrimitiveMode drawMode);
254     angle::Result triggerDispatchCallProgramRecompilation(const gl::Context *context);
255     angle::Result getIncompleteTexture(const gl::Context *context,
256                                        gl::TextureType type,
257                                        gl::Texture **textureOut);
258 
259     angle::Result initializeMultisampleTextureToBlack(const gl::Context *context,
260                                                       gl::Texture *glTexture) override;
261 
262     void handleResult(HRESULT hr,
263                       const char *message,
264                       const char *file,
265                       const char *function,
266                       unsigned int line) override;
267 
268     void setGPUDisjoint();
269     angle::Result checkDisjointQuery();
270     HRESULT checkDisjointQueryStatus();
271     UINT64 getDisjointFrequency();
272     void setDisjointFrequency(UINT64 frequency);
273 
274   private:
275     angle::Result drawElementsImpl(const gl::Context *context,
276                                    gl::PrimitiveMode mode,
277                                    GLsizei indexCount,
278                                    gl::DrawElementsType indexType,
279                                    const void *indices,
280                                    GLsizei instanceCount,
281                                    GLint baseVertex,
282                                    GLuint baseInstance,
283                                    bool promoteDynamic,
284                                    bool isInstancedDraw);
285 
286     Renderer11 *mRenderer;
287     IncompleteTextureSet mIncompleteTextures;
288     std::stack<std::string> mMarkerStack;
289     d3d11::Query mDisjointQuery;
290     bool mDisjointQueryStarted;
291     bool mDisjoint;
292     UINT64 mFrequency;
293 };
294 }  // namespace rx
295 
296 #endif  // LIBANGLE_RENDERER_D3D_D3D11_CONTEXT11_H_
297