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