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