1 // 2 // Copyright 2019 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 // ContextMtl.h: 7 // Defines the class interface for ContextMtl, implementing ContextImpl. 8 // 9 10 #ifndef LIBANGLE_RENDERER_METAL_CONTEXTMTL_H_ 11 #define LIBANGLE_RENDERER_METAL_CONTEXTMTL_H_ 12 13 #import <Metal/Metal.h> 14 #import <mach/mach_types.h> 15 16 #include "common/Optional.h" 17 #include "image_util/loadimage.h" 18 #include "libANGLE/Context.h" 19 #include "libANGLE/renderer/ContextImpl.h" 20 #include "libANGLE/renderer/metal/ProvokingVertexHelper.h" 21 #include "libANGLE/renderer/metal/mtl_buffer_manager.h" 22 #include "libANGLE/renderer/metal/mtl_buffer_pool.h" 23 #include "libANGLE/renderer/metal/mtl_command_buffer.h" 24 #include "libANGLE/renderer/metal/mtl_context_device.h" 25 #include "libANGLE/renderer/metal/mtl_occlusion_query_pool.h" 26 #include "libANGLE/renderer/metal/mtl_pipeline_cache.h" 27 #include "libANGLE/renderer/metal/mtl_resources.h" 28 #include "libANGLE/renderer/metal/mtl_state_cache.h" 29 #include "libANGLE/renderer/metal/mtl_utils.h" 30 namespace rx 31 { 32 class DisplayMtl; 33 class FramebufferMtl; 34 class VertexArrayMtl; 35 class ProgramMtl; 36 class ProgramExecutableMtl; 37 class RenderTargetMtl; 38 class WindowSurfaceMtl; 39 class TransformFeedbackMtl; 40 41 class ContextMtl : public ContextImpl, public mtl::Context 42 { 43 public: 44 ContextMtl(const gl::State &state, 45 gl::ErrorSet *errorSet, 46 const egl::AttributeMap &attribs, 47 DisplayMtl *display); 48 ~ContextMtl() override; 49 50 angle::Result initialize(const angle::ImageLoadContext &imageLoadContext) override; 51 52 void onDestroy(const gl::Context *context) override; 53 54 // Flush and finish. 55 angle::Result flush(const gl::Context *context) override; 56 angle::Result finish(const gl::Context *context) override; 57 58 // Drawing methods. 59 angle::Result drawArrays(const gl::Context *context, 60 gl::PrimitiveMode mode, 61 GLint first, 62 GLsizei count) override; 63 angle::Result drawArraysInstanced(const gl::Context *context, 64 gl::PrimitiveMode mode, 65 GLint first, 66 GLsizei count, 67 GLsizei instanceCount) override; 68 angle::Result drawArraysInstancedBaseInstance(const gl::Context *context, 69 gl::PrimitiveMode mode, 70 GLint first, 71 GLsizei count, 72 GLsizei instanceCount, 73 GLuint baseInstance) override; 74 75 angle::Result drawElements(const gl::Context *context, 76 gl::PrimitiveMode mode, 77 GLsizei count, 78 gl::DrawElementsType type, 79 const void *indices) override; 80 angle::Result drawElementsBaseVertex(const gl::Context *context, 81 gl::PrimitiveMode mode, 82 GLsizei count, 83 gl::DrawElementsType type, 84 const void *indices, 85 GLint baseVertex) override; 86 angle::Result drawElementsInstanced(const gl::Context *context, 87 gl::PrimitiveMode mode, 88 GLsizei count, 89 gl::DrawElementsType type, 90 const void *indices, 91 GLsizei instanceCount) override; 92 angle::Result drawElementsInstancedBaseVertex(const gl::Context *context, 93 gl::PrimitiveMode mode, 94 GLsizei count, 95 gl::DrawElementsType type, 96 const void *indices, 97 GLsizei instanceCount, 98 GLint baseVertex) override; 99 angle::Result drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context, 100 gl::PrimitiveMode mode, 101 GLsizei count, 102 gl::DrawElementsType type, 103 const void *indices, 104 GLsizei instances, 105 GLint baseVertex, 106 GLuint baseInstance) override; 107 angle::Result drawRangeElements(const gl::Context *context, 108 gl::PrimitiveMode mode, 109 GLuint start, 110 GLuint end, 111 GLsizei count, 112 gl::DrawElementsType type, 113 const void *indices) override; 114 angle::Result drawRangeElementsBaseVertex(const gl::Context *context, 115 gl::PrimitiveMode mode, 116 GLuint start, 117 GLuint end, 118 GLsizei count, 119 gl::DrawElementsType type, 120 const void *indices, 121 GLint baseVertex) override; 122 angle::Result drawArraysIndirect(const gl::Context *context, 123 gl::PrimitiveMode mode, 124 const void *indirect) override; 125 angle::Result drawElementsIndirect(const gl::Context *context, 126 gl::PrimitiveMode mode, 127 gl::DrawElementsType type, 128 const void *indirect) override; 129 angle::Result multiDrawArrays(const gl::Context *context, 130 gl::PrimitiveMode mode, 131 const GLint *firsts, 132 const GLsizei *counts, 133 GLsizei drawcount) override; 134 angle::Result multiDrawArraysInstanced(const gl::Context *context, 135 gl::PrimitiveMode mode, 136 const GLint *firsts, 137 const GLsizei *counts, 138 const GLsizei *instanceCounts, 139 GLsizei drawcount) override; 140 angle::Result multiDrawArraysIndirect(const gl::Context *context, 141 gl::PrimitiveMode mode, 142 const void *indirect, 143 GLsizei drawcount, 144 GLsizei stride) override; 145 angle::Result multiDrawElements(const gl::Context *context, 146 gl::PrimitiveMode mode, 147 const GLsizei *counts, 148 gl::DrawElementsType type, 149 const GLvoid *const *indices, 150 GLsizei drawcount) override; 151 angle::Result multiDrawElementsInstanced(const gl::Context *context, 152 gl::PrimitiveMode mode, 153 const GLsizei *counts, 154 gl::DrawElementsType type, 155 const GLvoid *const *indices, 156 const GLsizei *instanceCounts, 157 GLsizei drawcount) override; 158 angle::Result multiDrawElementsIndirect(const gl::Context *context, 159 gl::PrimitiveMode mode, 160 gl::DrawElementsType type, 161 const void *indirect, 162 GLsizei drawcount, 163 GLsizei stride) override; 164 angle::Result multiDrawArraysInstancedBaseInstance(const gl::Context *context, 165 gl::PrimitiveMode mode, 166 const GLint *firsts, 167 const GLsizei *counts, 168 const GLsizei *instanceCounts, 169 const GLuint *baseInstances, 170 GLsizei drawcount) override; 171 angle::Result multiDrawElementsInstancedBaseVertexBaseInstance(const gl::Context *context, 172 gl::PrimitiveMode mode, 173 const GLsizei *counts, 174 gl::DrawElementsType type, 175 const GLvoid *const *indices, 176 const GLsizei *instanceCounts, 177 const GLint *baseVertices, 178 const GLuint *baseInstances, 179 GLsizei drawcount) override; 180 // Device loss 181 gl::GraphicsResetStatus getResetStatus() override; 182 183 // EXT_debug_marker 184 angle::Result insertEventMarker(GLsizei length, const char *marker) override; 185 angle::Result pushGroupMarker(GLsizei length, const char *marker) override; 186 angle::Result popGroupMarker() override; 187 188 // KHR_debug 189 angle::Result pushDebugGroup(const gl::Context *context, 190 GLenum source, 191 GLuint id, 192 const std::string &message) override; 193 angle::Result popDebugGroup(const gl::Context *context) override; 194 195 // State sync with dirty bits. 196 angle::Result syncState(const gl::Context *context, 197 const gl::state::DirtyBits dirtyBits, 198 const gl::state::DirtyBits bitMask, 199 const gl::state::ExtendedDirtyBits extendedDirtyBits, 200 const gl::state::ExtendedDirtyBits extendedBitMask, 201 gl::Command command) override; 202 203 // Disjoint timer queries 204 GLint getGPUDisjoint() override; 205 GLint64 getTimestamp() override; 206 207 // Context switching 208 angle::Result onMakeCurrent(const gl::Context *context) override; 209 angle::Result onUnMakeCurrent(const gl::Context *context) override; 210 211 // Native capabilities, unmodified by gl::Context. 212 gl::Caps getNativeCaps() const override; 213 const gl::TextureCapsMap &getNativeTextureCaps() const override; 214 const gl::Extensions &getNativeExtensions() const override; 215 const gl::Limitations &getNativeLimitations() const override; 216 const ShPixelLocalStorageOptions &getNativePixelLocalStorageOptions() const override; 217 getProgramExecutable()218 const ProgramExecutableMtl *getProgramExecutable() const { return mExecutable; } 219 220 // Shader creation 221 CompilerImpl *createCompiler() override; 222 ShaderImpl *createShader(const gl::ShaderState &state) override; 223 ProgramImpl *createProgram(const gl::ProgramState &state) override; 224 ProgramExecutableImpl *createProgramExecutable( 225 const gl::ProgramExecutable *executable) override; 226 227 // Framebuffer creation 228 FramebufferImpl *createFramebuffer(const gl::FramebufferState &state) override; 229 230 // Texture creation 231 TextureImpl *createTexture(const gl::TextureState &state) override; 232 233 // Renderbuffer creation 234 RenderbufferImpl *createRenderbuffer(const gl::RenderbufferState &state) override; 235 236 // Buffer creation 237 BufferImpl *createBuffer(const gl::BufferState &state) override; 238 239 // Vertex Array creation 240 VertexArrayImpl *createVertexArray(const gl::VertexArrayState &state) override; 241 242 // Query and Fence creation 243 QueryImpl *createQuery(gl::QueryType type) override; 244 FenceNVImpl *createFenceNV() override; 245 SyncImpl *createSync() override; 246 247 // Transform Feedback creation 248 TransformFeedbackImpl *createTransformFeedback( 249 const gl::TransformFeedbackState &state) override; 250 251 // Sampler object creation 252 SamplerImpl *createSampler(const gl::SamplerState &state) override; 253 254 // Program Pipeline object creation 255 ProgramPipelineImpl *createProgramPipeline(const gl::ProgramPipelineState &data) override; 256 257 // Memory object creation. 258 MemoryObjectImpl *createMemoryObject() override; 259 260 // Semaphore creation. 261 SemaphoreImpl *createSemaphore() override; 262 263 // Overlay creation. 264 OverlayImpl *createOverlay(const gl::OverlayState &state) override; 265 266 angle::Result dispatchCompute(const gl::Context *context, 267 GLuint numGroupsX, 268 GLuint numGroupsY, 269 GLuint numGroupsZ) override; 270 angle::Result dispatchComputeIndirect(const gl::Context *context, GLintptr indirect) override; 271 272 angle::Result memoryBarrier(const gl::Context *context, GLbitfield barriers) override; 273 angle::Result memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) override; 274 275 // override mtl::ErrorHandler 276 void handleError(GLenum error, 277 const char *message, 278 const char *file, 279 const char *function, 280 unsigned int line) override; 281 void handleError(NSError *error, 282 const char *message, 283 const char *file, 284 const char *function, 285 unsigned int line) override; 286 287 using ContextImpl::handleError; 288 289 void invalidateState(const gl::Context *context); 290 void invalidateDefaultAttribute(size_t attribIndex); 291 void invalidateDefaultAttributes(const gl::AttributesMask &dirtyMask); 292 void invalidateCurrentTextures(); 293 void invalidateDriverUniforms(); 294 void invalidateRenderPipeline(); 295 296 void updateIncompatibleAttachments(const gl::State &glState); 297 298 // Call this to notify ContextMtl whenever FramebufferMtl's state changed 299 void onDrawFrameBufferChangedState(const gl::Context *context, 300 FramebufferMtl *framebuffer, 301 bool renderPassChanged); 302 void onBackbufferResized(const gl::Context *context, WindowSurfaceMtl *backbuffer); 303 304 // Invoke by QueryMtl 305 angle::Result onOcclusionQueryBegin(const gl::Context *context, QueryMtl *query); 306 void onOcclusionQueryEnd(const gl::Context *context, QueryMtl *query); 307 void onOcclusionQueryDestroy(const gl::Context *context, QueryMtl *query); 308 309 // Useful for temporarily pause then restart occlusion query during clear/blit with draw. hasActiveOcclusionQuery()310 bool hasActiveOcclusionQuery() const { return mOcclusionQuery; } 311 // Disable the occlusion query in the current render pass. 312 // The render pass must already started. 313 void disableActiveOcclusionQueryInRenderPass(); 314 // Re-enable the occlusion query in the current render pass. 315 // The render pass must already started. 316 // NOTE: the old query's result will be retained and combined with the new result. 317 angle::Result restartActiveOcclusionQueryInRenderPass(); 318 319 // Invoke by TransformFeedbackMtl 320 void onTransformFeedbackActive(const gl::Context *context, TransformFeedbackMtl *xfb); 321 void onTransformFeedbackInactive(const gl::Context *context, TransformFeedbackMtl *xfb); 322 323 // Invoked by multiple classes in SyncMtl.mm 324 #if ANGLE_MTL_EVENT_AVAILABLE 325 // Enqueue an event and return the command queue serial that the event was or will be placed in. 326 uint64_t queueEventSignal(id<MTLEvent> event, uint64_t value); 327 void serverWaitEvent(id<MTLEvent> event, uint64_t value); 328 #endif 329 330 const mtl::ClearColorValue &getClearColorValue() const; 331 const mtl::WriteMaskArray &getWriteMaskArray() const; 332 float getClearDepthValue() const; 333 uint32_t getClearStencilValue() const; 334 // Return front facing stencil write mask 335 uint32_t getStencilMask() const; 336 bool getDepthMask() const; 337 338 const mtl::Format &getPixelFormat(angle::FormatID angleFormatId) const; 339 const mtl::FormatCaps &getNativeFormatCaps(MTLPixelFormat mtlFormat) const; 340 // See mtl::FormatTable::getVertexFormat() 341 const mtl::VertexFormat &getVertexFormat(angle::FormatID angleFormatId, 342 bool tightlyPacked) const; 343 344 angle::Result getIncompleteTexture(const gl::Context *context, 345 gl::TextureType type, 346 gl::SamplerFormat format, 347 gl::Texture **textureOut); 348 349 // Recommended to call these methods to end encoding instead of invoking the encoder's 350 // endEncoding() directly. 351 void endRenderEncoding(mtl::RenderCommandEncoder *encoder); 352 // Ends any active command encoder 353 void endEncoding(bool forceSaveRenderPassContent); 354 355 void flushCommandBuffer(mtl::CommandBufferFinishOperation operation); 356 void present(const gl::Context *context, id<CAMetalDrawable> presentationDrawable); 357 angle::Result finishCommandBuffer(); 358 359 // Check whether compatible render pass has been started. Compatible render pass is a render 360 // pass having the same attachments, and possibly having different load/store options. 361 bool hasStartedRenderPass(const mtl::RenderPassDesc &desc); 362 363 // Get current render encoder. May be nullptr if no render pass has been started. 364 mtl::RenderCommandEncoder *getRenderCommandEncoder(); 365 366 // Will end current command encoder if it is valid, then start new encoder. 367 // Unless hasStartedRenderPass(desc) returns true. 368 // Note: passing a compatible render pass with different load/store options won't end the 369 // current render pass. If a new render pass is desired, call endEncoding() prior to this. 370 mtl::RenderCommandEncoder *getRenderPassCommandEncoder(const mtl::RenderPassDesc &desc); 371 372 // Utilities to quickly create render command encoder to a specific texture: 373 // The previous content of texture will be loaded 374 mtl::RenderCommandEncoder *getTextureRenderCommandEncoder(const mtl::TextureRef &textureTarget, 375 const mtl::ImageNativeIndex &index); 376 // The previous content of texture will be loaded if clearColor is not provided 377 mtl::RenderCommandEncoder *getRenderTargetCommandEncoderWithClear( 378 const RenderTargetMtl &renderTarget, 379 const Optional<MTLClearColor> &clearColor); 380 // The previous content of texture will be loaded 381 mtl::RenderCommandEncoder *getRenderTargetCommandEncoder(const RenderTargetMtl &renderTarget); 382 383 // Will end current command encoder and start new blit command encoder. Unless a blit comamnd 384 // encoder is already started. 385 mtl::BlitCommandEncoder *getBlitCommandEncoder(); 386 387 // Will end current command encoder and start new compute command encoder. Unless a compute 388 // command encoder is already started. 389 mtl::ComputeCommandEncoder *getComputeCommandEncoder(); 390 391 // Because this backend uses an intermediate representation for the rendering 392 // commands, a render encoder can coexist with blit/compute command encoders. 393 // Note: the blit/compute commands will run before the pending render commands. 394 mtl::BlitCommandEncoder *getBlitCommandEncoderWithoutEndingRenderEncoder(); 395 mtl::ComputeCommandEncoder *getComputeCommandEncoderWithoutEndingRenderEncoder(); 396 397 // Get the provoking vertex command encoder. 398 mtl::ComputeCommandEncoder *getIndexPreprocessingCommandEncoder(); 399 400 bool isCurrentRenderEncoderSerial(uint64_t serial); 401 getMetalDevice()402 const mtl::ContextDevice &getMetalDevice() const { return mContextDevice; } 403 getBufferManager()404 mtl::BufferManager &getBufferManager() { return mBufferManager; } 405 getPipelineCache()406 mtl::PipelineCache &getPipelineCache() { return mPipelineCache; } 407 getImageLoadContext()408 const angle::ImageLoadContext &getImageLoadContext() const { return mImageLoadContext; } 409 getForceResyncDrawFramebuffer()410 bool getForceResyncDrawFramebuffer() const { return mForceResyncDrawFramebuffer; } getIncompatibleAttachments()411 gl::DrawBufferMask getIncompatibleAttachments() const { return mIncompatibleAttachments; } 412 413 private: 414 void ensureCommandBufferReady(); 415 void endBlitAndComputeEncoding(); 416 angle::Result resyncDrawFramebufferIfNeeded(const gl::Context *context); 417 angle::Result setupDraw(const gl::Context *context, 418 gl::PrimitiveMode mode, 419 GLint firstVertex, 420 GLsizei vertexOrIndexCount, 421 GLsizei instanceCount, 422 gl::DrawElementsType indexTypeOrNone, 423 const void *indices, 424 bool xfbPass, 425 bool *isNoOp); 426 427 angle::Result setupDrawImpl(const gl::Context *context, 428 gl::PrimitiveMode mode, 429 GLint firstVertex, 430 GLsizei vertexOrIndexCount, 431 GLsizei instanceCount, 432 gl::DrawElementsType indexTypeOrNone, 433 const void *indices, 434 bool xfbPass, 435 bool *isNoOp); 436 437 angle::Result drawTriFanArrays(const gl::Context *context, 438 GLint first, 439 GLsizei count, 440 GLsizei instances, 441 GLuint baseInstance); 442 angle::Result drawTriFanArraysWithBaseVertex(const gl::Context *context, 443 GLint first, 444 GLsizei count, 445 GLsizei instances, 446 GLuint baseInstance); 447 angle::Result drawTriFanArraysLegacy(const gl::Context *context, 448 GLint first, 449 GLsizei count, 450 GLsizei instances); 451 angle::Result drawTriFanElements(const gl::Context *context, 452 GLsizei count, 453 gl::DrawElementsType type, 454 const void *indices, 455 GLsizei instances, 456 GLint baseVertex, 457 GLuint baseInstance); 458 459 angle::Result drawLineLoopArraysNonInstanced(const gl::Context *context, 460 GLint first, 461 GLsizei count); 462 angle::Result drawLineLoopArrays(const gl::Context *context, 463 GLint first, 464 GLsizei count, 465 GLsizei instances, 466 GLuint baseInstance); 467 angle::Result drawLineLoopElementsNonInstancedNoPrimitiveRestart(const gl::Context *context, 468 GLsizei count, 469 gl::DrawElementsType type, 470 const void *indices); 471 angle::Result drawLineLoopElements(const gl::Context *context, 472 GLsizei count, 473 gl::DrawElementsType type, 474 const void *indices, 475 GLsizei instances, 476 GLint baseVertex, 477 GLuint baseInstance); 478 479 angle::Result drawArraysProvokingVertexImpl(const gl::Context *context, 480 gl::PrimitiveMode mode, 481 GLsizei first, 482 GLsizei count, 483 GLsizei instances, 484 GLuint baseInstance); 485 486 angle::Result drawArraysImpl(const gl::Context *context, 487 gl::PrimitiveMode mode, 488 GLint first, 489 GLsizei count, 490 GLsizei instanceCount, 491 GLuint baseInstance); 492 493 angle::Result drawElementsImpl(const gl::Context *context, 494 gl::PrimitiveMode mode, 495 GLsizei count, 496 gl::DrawElementsType type, 497 const void *indices, 498 GLsizei instanceCount, 499 GLint baseVertex, 500 GLuint baseInstance); 501 void flushCommandBufferIfNeeded(); 502 void updateExtendedState(const gl::State &glState, 503 const gl::state::ExtendedDirtyBits extendedDirtyBits); 504 505 void updateViewport(FramebufferMtl *framebufferMtl, 506 const gl::Rectangle &viewport, 507 float nearPlane, 508 float farPlane); 509 void updateDepthRange(float nearPlane, float farPlane); 510 void updateBlendDescArray(const gl::BlendStateExt &blendStateExt); 511 void updateScissor(const gl::State &glState); 512 void updateCullMode(const gl::State &glState); 513 void updateFrontFace(const gl::State &glState); 514 void updateDrawFrameBufferBinding(const gl::Context *context); 515 void updateProgramExecutable(const gl::Context *context); 516 void updateVertexArray(const gl::Context *context); 517 bool requiresIndexRewrite(const gl::State &state, gl::PrimitiveMode mode); 518 angle::Result updateDefaultAttribute(size_t attribIndex); 519 void filterOutXFBOnlyDirtyBits(const gl::Context *context); 520 angle::Result handleDirtyActiveTextures(const gl::Context *context); 521 angle::Result handleDirtyDefaultAttribs(const gl::Context *context); 522 angle::Result handleDirtyDriverUniforms(const gl::Context *context, 523 GLint drawCallFirstVertex, 524 uint32_t verticesPerInstance); 525 angle::Result fillDriverXFBUniforms(GLint drawCallFirstVertex, 526 uint32_t verticesPerInstance, 527 uint32_t skippedInstances); 528 angle::Result handleDirtyDepthStencilState(const gl::Context *context); 529 angle::Result handleDirtyDepthBias(const gl::Context *context); 530 angle::Result handleDirtyRenderPass(const gl::Context *context); 531 angle::Result checkIfPipelineChanged(const gl::Context *context, 532 gl::PrimitiveMode primitiveMode, 533 bool xfbPass, 534 bool *pipelineDescChanged); 535 536 angle::Result startOcclusionQueryInRenderPass(QueryMtl *query, bool clearOldValue); 537 538 // Dirty bits. 539 enum DirtyBitType : size_t 540 { 541 DIRTY_BIT_DEFAULT_ATTRIBS, 542 DIRTY_BIT_TEXTURES, 543 DIRTY_BIT_DRIVER_UNIFORMS, 544 DIRTY_BIT_DEPTH_STENCIL_DESC, 545 DIRTY_BIT_DEPTH_BIAS, 546 DIRTY_BIT_DEPTH_CLIP_MODE, 547 DIRTY_BIT_STENCIL_REF, 548 DIRTY_BIT_BLEND_COLOR, 549 DIRTY_BIT_VIEWPORT, 550 DIRTY_BIT_SCISSOR, 551 DIRTY_BIT_DRAW_FRAMEBUFFER, 552 DIRTY_BIT_CULL_MODE, 553 DIRTY_BIT_FILL_MODE, 554 DIRTY_BIT_WINDING, 555 DIRTY_BIT_RENDER_PIPELINE, 556 DIRTY_BIT_UNIFORM_BUFFERS_BINDING, 557 DIRTY_BIT_RASTERIZER_DISCARD, 558 559 DIRTY_BIT_INVALID, 560 DIRTY_BIT_MAX = DIRTY_BIT_INVALID, 561 }; 562 563 // Must keep this in sync with DriverUniform::createUniformFields in: 564 // src/compiler/translator/tree_util/DriverUniform.cpp 565 // and DriverUniformMetal::createUniformFields in: 566 // src/compiler/translator/DriverUniformMetal.cpp 567 struct DriverUniforms 568 { 569 uint32_t acbBufferOffsets[2]; 570 float depthRange[2]; 571 uint32_t renderArea; 572 uint32_t flipXY; 573 uint32_t unused; 574 uint32_t misc; 575 576 int32_t xfbBufferOffsets[4]; 577 int32_t xfbVerticesPerInstance; 578 uint32_t coverageMask; // Metal specific 579 uint32_t unused2[2]; 580 }; 581 static_assert(sizeof(DriverUniforms) % (sizeof(uint32_t) * 4) == 0, 582 "DriverUniforms should be 16 bytes aligned"); 583 584 struct DefaultAttribute 585 { 586 uint8_t values[sizeof(float) * 4]; 587 }; 588 589 angle::ImageLoadContext mImageLoadContext; 590 591 mtl::OcclusionQueryPool mOcclusionQueryPool; 592 593 mtl::CommandBuffer mCmdBuffer; 594 mtl::RenderCommandEncoder mRenderEncoder; 595 mtl::BlitCommandEncoder mBlitEncoder; 596 mtl::ComputeCommandEncoder mComputeEncoder; 597 bool mHasMetalSharedEvents = false; 598 599 mtl::PipelineCache mPipelineCache; 600 601 // Cached back-end objects 602 FramebufferMtl *mDrawFramebuffer = nullptr; 603 VertexArrayMtl *mVertexArray = nullptr; 604 ProgramExecutableMtl *mExecutable = nullptr; 605 QueryMtl *mOcclusionQuery = nullptr; 606 607 using DirtyBits = angle::BitSet<DIRTY_BIT_MAX>; 608 609 gl::AttributesMask mDirtyDefaultAttribsMask; 610 DirtyBits mDirtyBits; 611 612 uint32_t mRenderPassesSinceFlush = 0; 613 614 // State 615 mtl::RenderPipelineDesc mRenderPipelineDesc; 616 mtl::DepthStencilDesc mDepthStencilDesc; 617 mtl::BlendDescArray mBlendDescArray; 618 mtl::WriteMaskArray mWriteMaskArray; 619 mtl::ClearColorValue mClearColor; 620 uint32_t mClearStencil = 0; 621 uint32_t mStencilRefFront = 0; 622 uint32_t mStencilRefBack = 0; 623 MTLViewport mViewport; 624 MTLScissorRect mScissorRect; 625 MTLWinding mWinding; 626 MTLCullMode mCullMode; 627 bool mCullAllPolygons = false; 628 629 // Cached state to handle attachments incompatible with the current program 630 bool mForceResyncDrawFramebuffer = false; 631 gl::DrawBufferMask mIncompatibleAttachments; 632 633 mtl::BufferManager mBufferManager; 634 635 // Lineloop and TriFan index buffer 636 mtl::BufferPool mLineLoopIndexBuffer; 637 mtl::BufferPool mLineLoopLastSegmentIndexBuffer; 638 mtl::BufferPool mTriFanIndexBuffer; 639 // one buffer can be reused for any starting vertex in DrawArrays() 640 mtl::BufferRef mTriFanArraysIndexBuffer; 641 642 // Dummy texture to be used for transform feedback only pass. 643 mtl::TextureRef mDummyXFBRenderTexture; 644 645 DriverUniforms mDriverUniforms; 646 647 DefaultAttribute mDefaultAttributes[mtl::kMaxVertexAttribs]; 648 649 IncompleteTextureSet mIncompleteTextures; 650 ProvokingVertexHelper mProvokingVertexHelper; 651 652 mtl::ContextDevice mContextDevice; 653 }; 654 655 } // namespace rx 656 657 #endif /* LIBANGLE_RENDERER_METAL_CONTEXTMTL_H_ */ 658