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 // ContextVk.h: 7 // Defines the class interface for ContextVk, implementing ContextImpl. 8 // 9 10 #ifndef LIBANGLE_RENDERER_VULKAN_CONTEXTVK_H_ 11 #define LIBANGLE_RENDERER_VULKAN_CONTEXTVK_H_ 12 13 #include "volk.h" 14 15 #include "common/PackedEnums.h" 16 #include "libANGLE/renderer/ContextImpl.h" 17 #include "libANGLE/renderer/vulkan/OverlayVk.h" 18 #include "libANGLE/renderer/vulkan/PersistentCommandPool.h" 19 #include "libANGLE/renderer/vulkan/RendererVk.h" 20 #include "libANGLE/renderer/vulkan/vk_helpers.h" 21 22 namespace angle 23 { 24 struct FeaturesVk; 25 } // namespace angle 26 27 namespace rx 28 { 29 class ProgramExecutableVk; 30 class RendererVk; 31 class WindowSurfaceVk; 32 33 // The possible rotations of the surface/draw framebuffer, used for pre-rotating gl_Position 34 // in the vertex shader. 35 enum class SurfaceRotationType 36 { 37 Identity, 38 Rotated90Degrees, 39 Rotated180Degrees, 40 Rotated270Degrees, 41 FlippedIdentity, 42 FlippedRotated90Degrees, 43 FlippedRotated180Degrees, 44 FlippedRotated270Degrees, 45 46 InvalidEnum, 47 EnumCount = InvalidEnum, 48 }; 49 50 struct CommandBatch final : angle::NonCopyable 51 { 52 CommandBatch(); 53 ~CommandBatch(); 54 CommandBatch(CommandBatch &&other); 55 CommandBatch &operator=(CommandBatch &&other); 56 57 void destroy(VkDevice device); 58 59 vk::PrimaryCommandBuffer primaryCommands; 60 // commandPool is for secondary CommandBuffer allocation 61 vk::CommandPool commandPool; 62 vk::Shared<vk::Fence> fence; 63 Serial serial; 64 }; 65 66 class CommandQueue final : angle::NonCopyable 67 { 68 public: 69 CommandQueue(); 70 ~CommandQueue(); 71 72 angle::Result init(vk::Context *context); 73 void destroy(VkDevice device); 74 void handleDeviceLost(RendererVk *renderer); 75 76 bool hasInFlightCommands() const; 77 78 angle::Result allocatePrimaryCommandBuffer(vk::Context *context, 79 const vk::CommandPool &commandPool, 80 vk::PrimaryCommandBuffer *commandBufferOut); 81 angle::Result releasePrimaryCommandBuffer(vk::Context *context, 82 vk::PrimaryCommandBuffer &&commandBuffer); 83 84 void clearAllGarbage(RendererVk *renderer); 85 86 angle::Result finishToSerial(vk::Context *context, Serial serial, uint64_t timeout); 87 88 angle::Result submitFrame(vk::Context *context, 89 egl::ContextPriority priority, 90 const VkSubmitInfo &submitInfo, 91 const vk::Shared<vk::Fence> &sharedFence, 92 vk::GarbageList *currentGarbage, 93 vk::CommandPool *commandPool, 94 vk::PrimaryCommandBuffer &&commandBuffer); 95 96 vk::Shared<vk::Fence> getLastSubmittedFence(const vk::Context *context) const; 97 98 // Check to see which batches have finished completion (forward progress for 99 // mLastCompletedQueueSerial, for example for when the application busy waits on a query 100 // result). It would be nice if we didn't have to expose this for QueryVk::getResult. 101 angle::Result checkCompletedCommands(vk::Context *context); 102 103 private: 104 angle::Result releaseToCommandBatch(vk::Context *context, 105 vk::PrimaryCommandBuffer &&commandBuffer, 106 vk::CommandPool *commandPool, 107 CommandBatch *batch); 108 109 vk::GarbageQueue mGarbageQueue; 110 std::vector<CommandBatch> mInFlightCommands; 111 112 // Keeps a free list of reusable primary command buffers. 113 vk::PersistentCommandPool mPrimaryCommandPool; 114 }; 115 116 struct CommandBufferHelper : angle::NonCopyable 117 { 118 public: 119 void bufferRead(vk::ResourceUseList *resourceUseList, 120 VkAccessFlags readAccessType, 121 vk::BufferHelper *buffer); 122 void bufferWrite(vk::ResourceUseList *resourceUseList, 123 VkAccessFlags writeAccessType, 124 vk::BufferHelper *buffer); 125 126 void imageRead(vk::ResourceUseList *resourceUseList, 127 VkImageAspectFlags aspectFlags, 128 vk::ImageLayout imageLayout, 129 vk::ImageHelper *image); 130 131 void imageWrite(vk::ResourceUseList *resourceUseList, 132 VkImageAspectFlags aspectFlags, 133 vk::ImageLayout imageLayout, 134 vk::ImageHelper *image); 135 136 void imageBarrier(VkPipelineStageFlags srcStageMask, 137 VkPipelineStageFlags dstStageMask, 138 const VkImageMemoryBarrier &imageMemoryBarrier); 139 getCommandBufferCommandBufferHelper140 vk::CommandBuffer &getCommandBuffer() { return mCommandBuffer; } 141 142 protected: 143 CommandBufferHelper(); 144 ~CommandBufferHelper(); 145 146 void executeBarriers(vk::PrimaryCommandBuffer *primary); 147 148 VkPipelineStageFlags mImageBarrierSrcStageMask; 149 VkPipelineStageFlags mImageBarrierDstStageMask; 150 std::vector<VkImageMemoryBarrier> mImageMemoryBarriers; 151 VkFlags mGlobalMemoryBarrierSrcAccess; 152 VkFlags mGlobalMemoryBarrierDstAccess; 153 VkPipelineStageFlags mGlobalMemoryBarrierStages; 154 vk::CommandBuffer mCommandBuffer; 155 }; 156 157 class OutsideRenderPassCommandBuffer final : public CommandBufferHelper 158 { 159 public: 160 OutsideRenderPassCommandBuffer(); 161 ~OutsideRenderPassCommandBuffer(); 162 163 void flushToPrimary(ContextVk *contextVk, vk::PrimaryCommandBuffer *primary); 164 empty()165 bool empty() const { return mCommandBuffer.empty(); } 166 void reset(); 167 }; 168 169 class RenderPassCommandBuffer final : public CommandBufferHelper 170 { 171 public: 172 RenderPassCommandBuffer(); 173 ~RenderPassCommandBuffer(); 174 175 void initialize(angle::PoolAllocator *poolAllocator); 176 177 void beginRenderPass(const vk::Framebuffer &framebuffer, 178 const gl::Rectangle &renderArea, 179 const vk::RenderPassDesc &renderPassDesc, 180 const vk::AttachmentOpsArray &renderPassAttachmentOps, 181 const std::vector<VkClearValue> &clearValues, 182 vk::CommandBuffer **commandBufferOut); 183 184 void beginTransformFeedback(size_t validBufferCount, 185 const VkBuffer *counterBuffers, 186 bool rebindBuffer); 187 clearRenderPassColorAttachment(size_t attachmentIndex,const VkClearColorValue & clearValue)188 void clearRenderPassColorAttachment(size_t attachmentIndex, const VkClearColorValue &clearValue) 189 { 190 SetBitField(mAttachmentOps[attachmentIndex].loadOp, VK_ATTACHMENT_LOAD_OP_CLEAR); 191 mClearValues[attachmentIndex].color = clearValue; 192 } 193 clearRenderPassDepthAttachment(size_t attachmentIndex,float depth)194 void clearRenderPassDepthAttachment(size_t attachmentIndex, float depth) 195 { 196 SetBitField(mAttachmentOps[attachmentIndex].loadOp, VK_ATTACHMENT_LOAD_OP_CLEAR); 197 SetBitField(mClearValues[attachmentIndex].depthStencil.depth, depth); 198 } 199 clearRenderPassStencilAttachment(size_t attachmentIndex,uint32_t stencil)200 void clearRenderPassStencilAttachment(size_t attachmentIndex, uint32_t stencil) 201 { 202 SetBitField(mAttachmentOps[attachmentIndex].stencilLoadOp, VK_ATTACHMENT_LOAD_OP_CLEAR); 203 SetBitField(mClearValues[attachmentIndex].depthStencil.stencil, stencil); 204 } 205 invalidateRenderPassColorAttachment(size_t attachmentIndex)206 void invalidateRenderPassColorAttachment(size_t attachmentIndex) 207 { 208 SetBitField(mAttachmentOps[attachmentIndex].storeOp, VK_ATTACHMENT_STORE_OP_DONT_CARE); 209 } 210 invalidateRenderPassDepthAttachment(size_t attachmentIndex)211 void invalidateRenderPassDepthAttachment(size_t attachmentIndex) 212 { 213 SetBitField(mAttachmentOps[attachmentIndex].storeOp, VK_ATTACHMENT_STORE_OP_DONT_CARE); 214 } 215 invalidateRenderPassStencilAttachment(size_t attachmentIndex)216 void invalidateRenderPassStencilAttachment(size_t attachmentIndex) 217 { 218 SetBitField(mAttachmentOps[attachmentIndex].stencilStoreOp, 219 VK_ATTACHMENT_STORE_OP_DONT_CARE); 220 } 221 updateRenderPassAttachmentFinalLayout(size_t attachmentIndex,vk::ImageLayout finalLayout)222 void updateRenderPassAttachmentFinalLayout(size_t attachmentIndex, vk::ImageLayout finalLayout) 223 { 224 SetBitField(mAttachmentOps[attachmentIndex].finalLayout, finalLayout); 225 } 226 getRenderArea()227 const gl::Rectangle &getRenderArea() const { return mRenderArea; } 228 229 angle::Result flushToPrimary(ContextVk *contextVk, vk::PrimaryCommandBuffer *primary); 230 empty()231 bool empty() const { return !started() && mCommandBuffer.empty(); } started()232 bool started() const { return mRenderPassStarted; } 233 void reset(); 234 235 void resumeTransformFeedbackIfStarted(); 236 void pauseTransformFeedbackIfStarted(); 237 getAndResetCounter()238 uint32_t getAndResetCounter() 239 { 240 uint32_t count = mCounter; 241 mCounter = 0; 242 return count; 243 } 244 getFramebufferHandle()245 VkFramebuffer getFramebufferHandle() const { return mFramebuffer.getHandle(); } 246 247 private: 248 void addRenderPassCommandDiagnostics(ContextVk *contextVk); 249 250 uint32_t mCounter; 251 vk::RenderPassDesc mRenderPassDesc; 252 vk::AttachmentOpsArray mAttachmentOps; 253 vk::Framebuffer mFramebuffer; 254 gl::Rectangle mRenderArea; 255 gl::AttachmentArray<VkClearValue> mClearValues; 256 bool mRenderPassStarted; 257 258 // Transform feedback state 259 gl::TransformFeedbackBuffersArray<VkBuffer> mTransformFeedbackCounterBuffers; 260 uint32_t mValidTransformFeedbackBufferCount; 261 bool mRebindTransformFeedbackBuffers; 262 }; 263 264 static constexpr uint32_t kMaxGpuEventNameLen = 32; 265 using EventName = std::array<char, kMaxGpuEventNameLen>; 266 267 class ContextVk : public ContextImpl, public vk::Context 268 { 269 public: 270 ContextVk(const gl::State &state, gl::ErrorSet *errorSet, RendererVk *renderer); 271 ~ContextVk() override; 272 273 angle::Result initialize() override; 274 275 void onDestroy(const gl::Context *context) override; 276 277 // Flush and finish. 278 angle::Result flush(const gl::Context *context) override; 279 angle::Result finish(const gl::Context *context) override; 280 281 // Drawing methods. 282 angle::Result drawArrays(const gl::Context *context, 283 gl::PrimitiveMode mode, 284 GLint first, 285 GLsizei count) override; 286 angle::Result drawArraysInstanced(const gl::Context *context, 287 gl::PrimitiveMode mode, 288 GLint first, 289 GLsizei count, 290 GLsizei instanceCount) override; 291 angle::Result drawArraysInstancedBaseInstance(const gl::Context *context, 292 gl::PrimitiveMode mode, 293 GLint first, 294 GLsizei count, 295 GLsizei instanceCount, 296 GLuint baseInstance) override; 297 298 angle::Result drawElements(const gl::Context *context, 299 gl::PrimitiveMode mode, 300 GLsizei count, 301 gl::DrawElementsType type, 302 const void *indices) override; 303 angle::Result drawElementsBaseVertex(const gl::Context *context, 304 gl::PrimitiveMode mode, 305 GLsizei count, 306 gl::DrawElementsType type, 307 const void *indices, 308 GLint baseVertex) override; 309 angle::Result drawElementsInstanced(const gl::Context *context, 310 gl::PrimitiveMode mode, 311 GLsizei count, 312 gl::DrawElementsType type, 313 const void *indices, 314 GLsizei instanceCount) override; 315 angle::Result drawElementsInstancedBaseVertex(const gl::Context *context, 316 gl::PrimitiveMode mode, 317 GLsizei count, 318 gl::DrawElementsType type, 319 const void *indices, 320 GLsizei instanceCount, 321 GLint baseVertex) override; 322 angle::Result drawElementsInstancedBaseVertexBaseInstance(const gl::Context *context, 323 gl::PrimitiveMode mode, 324 GLsizei count, 325 gl::DrawElementsType type, 326 const void *indices, 327 GLsizei instances, 328 GLint baseVertex, 329 GLuint baseInstance) override; 330 angle::Result drawRangeElements(const gl::Context *context, 331 gl::PrimitiveMode mode, 332 GLuint start, 333 GLuint end, 334 GLsizei count, 335 gl::DrawElementsType type, 336 const void *indices) override; 337 angle::Result drawRangeElementsBaseVertex(const gl::Context *context, 338 gl::PrimitiveMode mode, 339 GLuint start, 340 GLuint end, 341 GLsizei count, 342 gl::DrawElementsType type, 343 const void *indices, 344 GLint baseVertex) override; 345 angle::Result drawArraysIndirect(const gl::Context *context, 346 gl::PrimitiveMode mode, 347 const void *indirect) override; 348 angle::Result drawElementsIndirect(const gl::Context *context, 349 gl::PrimitiveMode mode, 350 gl::DrawElementsType type, 351 const void *indirect) override; 352 angle::Result clearWithRenderPassOp(const gl::Rectangle &clearArea, 353 gl::DrawBufferMask clearColorBuffers, 354 bool clearDepth, 355 bool clearStencil, 356 const VkClearColorValue &clearColorValue, 357 const VkClearDepthStencilValue &clearDepthStencilValue); 358 359 // Device loss 360 gl::GraphicsResetStatus getResetStatus() override; 361 362 // Vendor and description strings. 363 std::string getVendorString() const override; 364 std::string getRendererDescription() const override; 365 366 // EXT_debug_marker 367 angle::Result insertEventMarker(GLsizei length, const char *marker) override; 368 angle::Result pushGroupMarker(GLsizei length, const char *marker) override; 369 angle::Result popGroupMarker() override; 370 371 // KHR_debug 372 angle::Result pushDebugGroup(const gl::Context *context, 373 GLenum source, 374 GLuint id, 375 const std::string &message) override; 376 angle::Result popDebugGroup(const gl::Context *context) override; 377 378 bool isViewportFlipEnabledForDrawFBO() const; 379 bool isViewportFlipEnabledForReadFBO() const; 380 // When the device/surface is rotated such that the surface's aspect ratio is different than 381 // the native device (e.g. 90 degrees), the width and height of the viewport, scissor, and 382 // render area must be swapped. 383 bool isRotatedAspectRatioForDrawFBO() const; 384 bool isRotatedAspectRatioForReadFBO() const; 385 386 void invalidateProgramBindingHelper(const gl::State &glState); 387 angle::Result invalidateProgramExecutableHelper(const gl::Context *context); 388 389 // State sync with dirty bits. 390 angle::Result syncState(const gl::Context *context, 391 const gl::State::DirtyBits &dirtyBits, 392 const gl::State::DirtyBits &bitMask) override; 393 394 // Disjoint timer queries 395 GLint getGPUDisjoint() override; 396 GLint64 getTimestamp() override; 397 398 // Context switching 399 angle::Result onMakeCurrent(const gl::Context *context) override; 400 angle::Result onUnMakeCurrent(const gl::Context *context) override; 401 402 // Native capabilities, unmodified by gl::Context. 403 gl::Caps getNativeCaps() const override; 404 const gl::TextureCapsMap &getNativeTextureCaps() const override; 405 const gl::Extensions &getNativeExtensions() const override; 406 const gl::Limitations &getNativeLimitations() const override; 407 408 // Shader creation 409 CompilerImpl *createCompiler() override; 410 ShaderImpl *createShader(const gl::ShaderState &state) override; 411 ProgramImpl *createProgram(const gl::ProgramState &state) override; 412 413 // Framebuffer creation 414 FramebufferImpl *createFramebuffer(const gl::FramebufferState &state) override; 415 416 // Texture creation 417 TextureImpl *createTexture(const gl::TextureState &state) override; 418 419 // Renderbuffer creation 420 RenderbufferImpl *createRenderbuffer(const gl::RenderbufferState &state) override; 421 422 // Buffer creation 423 BufferImpl *createBuffer(const gl::BufferState &state) override; 424 425 // Vertex Array creation 426 VertexArrayImpl *createVertexArray(const gl::VertexArrayState &state) override; 427 428 // Query and Fence creation 429 QueryImpl *createQuery(gl::QueryType type) override; 430 FenceNVImpl *createFenceNV() override; 431 SyncImpl *createSync() override; 432 433 // Transform Feedback creation 434 TransformFeedbackImpl *createTransformFeedback( 435 const gl::TransformFeedbackState &state) override; 436 437 // Sampler object creation 438 SamplerImpl *createSampler(const gl::SamplerState &state) override; 439 440 // Program Pipeline object creation 441 ProgramPipelineImpl *createProgramPipeline(const gl::ProgramPipelineState &data) override; 442 443 // Memory object creation. 444 MemoryObjectImpl *createMemoryObject() override; 445 446 // Semaphore creation. 447 SemaphoreImpl *createSemaphore() override; 448 449 // Overlay creation. 450 OverlayImpl *createOverlay(const gl::OverlayState &state) override; 451 452 angle::Result dispatchCompute(const gl::Context *context, 453 GLuint numGroupsX, 454 GLuint numGroupsY, 455 GLuint numGroupsZ) override; 456 angle::Result dispatchComputeIndirect(const gl::Context *context, GLintptr indirect) override; 457 458 angle::Result memoryBarrier(const gl::Context *context, GLbitfield barriers) override; 459 angle::Result memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) override; 460 461 VkDevice getDevice() const; getPriority()462 egl::ContextPriority getPriority() const { return mContextPriority; } 463 getFeatures()464 ANGLE_INLINE const angle::FeaturesVk &getFeatures() const { return mRenderer->getFeatures(); } 465 invalidateVertexAndIndexBuffers()466 ANGLE_INLINE void invalidateVertexAndIndexBuffers() 467 { 468 // TODO: Make the pipeline invalidate more fine-grained. Only need to dirty here if PSO 469 // VtxInput state (stride, fmt, inputRate...) has changed. http://anglebug.com/3256 470 invalidateCurrentGraphicsPipeline(); 471 mGraphicsDirtyBits.set(DIRTY_BIT_VERTEX_BUFFERS); 472 mGraphicsDirtyBits.set(DIRTY_BIT_INDEX_BUFFER); 473 } 474 invalidateVertexBuffers()475 ANGLE_INLINE void invalidateVertexBuffers() 476 { 477 mGraphicsDirtyBits.set(DIRTY_BIT_VERTEX_BUFFERS); 478 } 479 onVertexAttributeChange(size_t attribIndex,GLuint stride,GLuint divisor,angle::FormatID format,GLuint relativeOffset)480 ANGLE_INLINE void onVertexAttributeChange(size_t attribIndex, 481 GLuint stride, 482 GLuint divisor, 483 angle::FormatID format, 484 GLuint relativeOffset) 485 { 486 invalidateVertexAndIndexBuffers(); 487 // Set divisor to 1 for attribs with emulated divisor 488 mGraphicsPipelineDesc->updateVertexInput( 489 &mGraphicsPipelineTransition, static_cast<uint32_t>(attribIndex), stride, 490 divisor > mRenderer->getMaxVertexAttribDivisor() ? 1 : divisor, format, relativeOffset); 491 } 492 493 void invalidateDefaultAttribute(size_t attribIndex); 494 void invalidateDefaultAttributes(const gl::AttributesMask &dirtyMask); 495 void onDrawFramebufferChange(FramebufferVk *framebufferVk); onHostVisibleBufferWrite()496 void onHostVisibleBufferWrite() { mIsAnyHostVisibleBufferWritten = true; } 497 498 void invalidateCurrentTransformFeedbackBuffers(); 499 void invalidateCurrentTransformFeedbackState(); 500 void onTransformFeedbackStateChanged(); 501 502 // When UtilsVk issues draw or dispatch calls, it binds descriptor sets that the context is not 503 // aware of. This function is called to make sure affected descriptor set bindings are dirtied 504 // for the next application draw/dispatch call. 505 void invalidateGraphicsDescriptorSet(uint32_t usedDescriptorSet); 506 void invalidateComputeDescriptorSet(uint32_t usedDescriptorSet); 507 508 void optimizeRenderPassForPresent(VkFramebuffer framebufferHandle); 509 510 vk::DynamicQueryPool *getQueryPool(gl::QueryType queryType); 511 512 const VkClearValue &getClearColorValue() const; 513 const VkClearValue &getClearDepthStencilValue() const; 514 VkColorComponentFlags getClearColorMask() const; 515 angle::Result getIncompleteTexture(const gl::Context *context, 516 gl::TextureType type, 517 gl::Texture **textureOut); 518 void updateColorMask(const gl::BlendState &blendState); 519 void updateSampleMask(const gl::State &glState); 520 521 void handleError(VkResult errorCode, 522 const char *file, 523 const char *function, 524 unsigned int line) override; getActiveTextures()525 const gl::ActiveTextureArray<vk::TextureUnit> &getActiveTextures() const 526 { 527 return mActiveTextures; 528 } getActiveImages()529 const gl::ActiveTextureArray<TextureVk *> &getActiveImages() const { return mActiveImages; } 530 setIndexBufferDirty()531 void setIndexBufferDirty() 532 { 533 mGraphicsDirtyBits.set(DIRTY_BIT_INDEX_BUFFER); 534 mLastIndexBufferOffset = reinterpret_cast<const void *>(angle::DirtyPointer); 535 } 536 537 void insertWaitSemaphore(const vk::Semaphore *waitSemaphore); 538 539 bool shouldFlush(); 540 angle::Result flushImpl(const vk::Semaphore *semaphore); 541 angle::Result finishImpl(); 542 543 void addWaitSemaphore(VkSemaphore semaphore); 544 545 const vk::CommandPool &getCommandPool() const; 546 getCurrentQueueSerial()547 Serial getCurrentQueueSerial() const { return mRenderer->getCurrentQueueSerial(); } getLastSubmittedQueueSerial()548 Serial getLastSubmittedQueueSerial() const { return mRenderer->getLastSubmittedQueueSerial(); } getLastCompletedQueueSerial()549 Serial getLastCompletedQueueSerial() const { return mRenderer->getLastCompletedQueueSerial(); } 550 551 bool isSerialInUse(Serial serial) const; 552 553 template <typename T> addGarbage(T * object)554 void addGarbage(T *object) 555 { 556 if (object->valid()) 557 { 558 mCurrentGarbage.emplace_back(vk::GetGarbage(object)); 559 } 560 } 561 562 // It would be nice if we didn't have to expose this for QueryVk::getResult. 563 angle::Result checkCompletedCommands(); 564 565 // Wait for completion of batches until (at least) batch with given serial is finished. 566 angle::Result finishToSerial(Serial serial); 567 568 angle::Result getCompatibleRenderPass(const vk::RenderPassDesc &desc, 569 vk::RenderPass **renderPassOut); 570 angle::Result getRenderPassWithOps(const vk::RenderPassDesc &desc, 571 const vk::AttachmentOpsArray &ops, 572 vk::RenderPass **renderPassOut); 573 574 // Get (or allocate) the fence that will be signaled on next submission. 575 angle::Result getNextSubmitFence(vk::Shared<vk::Fence> *sharedFenceOut); 576 vk::Shared<vk::Fence> getLastSubmittedFence() const; 577 getShaderLibrary()578 vk::ShaderLibrary &getShaderLibrary() { return mShaderLibrary; } getUtils()579 UtilsVk &getUtils() { return mUtils; } 580 581 angle::Result getTimestamp(uint64_t *timestampOut); 582 583 // Create Begin/End/Instant GPU trace events, which take their timestamps from GPU queries. 584 // The events are queued until the query results are available. Possible values for `phase` 585 // are TRACE_EVENT_PHASE_* traceGpuEvent(vk::PrimaryCommandBuffer * commandBuffer,char phase,const EventName & name)586 ANGLE_INLINE angle::Result traceGpuEvent(vk::PrimaryCommandBuffer *commandBuffer, 587 char phase, 588 const EventName &name) 589 { 590 if (mGpuEventsEnabled) 591 return traceGpuEventImpl(commandBuffer, phase, name); 592 return angle::Result::Continue; 593 } 594 getRenderPassCache()595 RenderPassCache &getRenderPassCache() { return mRenderPassCache; } 596 597 vk::DescriptorSetLayoutDesc getDriverUniformsDescriptorSetDesc( 598 VkShaderStageFlags shaderStages) const; 599 600 // We use texture serials to optimize texture binding updates. Each permutation of a 601 // {VkImage/VkSampler} generates a unique serial. These serials are combined to form a unique 602 // signature for each descriptor set. This allows us to keep a cache of descriptor sets and 603 // avoid calling vkAllocateDesctiporSets each texture update. generateTextureSerial()604 Serial generateTextureSerial() { return mTextureSerialFactory.generate(); } getActiveTexturesDesc()605 const vk::TextureDescriptorDesc &getActiveTexturesDesc() const { return mActiveTexturesDesc; } generateAttachmentImageSerial()606 Serial generateAttachmentImageSerial() { return mAttachmentImageSerialFactory.generate(); } 607 608 angle::Result updateScissor(const gl::State &glState); 609 emulateSeamfulCubeMapSampling()610 bool emulateSeamfulCubeMapSampling() const { return mEmulateSeamfulCubeMapSampling; } 611 useOldRewriteStructSamplers()612 bool useOldRewriteStructSamplers() const { return mUseOldRewriteStructSamplers; } 613 getOverlay()614 const gl::OverlayType *getOverlay() const { return mState.getOverlay(); } 615 getResourceUseList()616 vk::ResourceUseList &getResourceUseList() { return mResourceUseList; } 617 618 angle::Result onBufferRead(VkAccessFlags readAccessType, vk::BufferHelper *buffer); 619 angle::Result onBufferWrite(VkAccessFlags writeAccessType, vk::BufferHelper *buffer); 620 621 angle::Result onImageRead(VkImageAspectFlags aspectFlags, 622 vk::ImageLayout imageLayout, 623 vk::ImageHelper *image); 624 625 angle::Result onImageWrite(VkImageAspectFlags aspectFlags, 626 vk::ImageLayout imageLayout, 627 vk::ImageHelper *image); 628 629 void onRenderPassImageWrite(VkImageAspectFlags aspectFlags, 630 vk::ImageLayout imageLayout, 631 vk::ImageHelper *image); 632 endRenderPassAndGetCommandBuffer(vk::CommandBuffer ** commandBufferOut)633 angle::Result endRenderPassAndGetCommandBuffer(vk::CommandBuffer **commandBufferOut) 634 { 635 ANGLE_TRY(endRenderPass()); 636 *commandBufferOut = &mOutsideRenderPassCommands.getCommandBuffer(); 637 return angle::Result::Continue; 638 } 639 640 angle::Result flushAndBeginRenderPass(const vk::Framebuffer &framebuffer, 641 const gl::Rectangle &renderArea, 642 const vk::RenderPassDesc &renderPassDesc, 643 const vk::AttachmentOpsArray &renderPassAttachmentOps, 644 const std::vector<VkClearValue> &clearValues, 645 vk::CommandBuffer **commandBufferOut); 646 hasStartedRenderPass()647 bool hasStartedRenderPass() const { return !mRenderPassCommands.empty(); } 648 getStartedRenderPassCommands()649 RenderPassCommandBuffer &getStartedRenderPassCommands() 650 { 651 ASSERT(hasStartedRenderPass()); 652 return mRenderPassCommands; 653 } 654 flushAndGetPrimaryCommandBuffer(vk::PrimaryCommandBuffer ** primaryCommands)655 angle::Result flushAndGetPrimaryCommandBuffer(vk::PrimaryCommandBuffer **primaryCommands) 656 { 657 flushOutsideRenderPassCommands(); 658 ANGLE_TRY(endRenderPass()); 659 *primaryCommands = &mPrimaryCommands; 660 661 // We assume any calling code is going to record primary commands. 662 mHasPrimaryCommands = true; 663 return angle::Result::Continue; 664 } 665 getContextPriority()666 egl::ContextPriority getContextPriority() const override { return mContextPriority; } 667 angle::Result startRenderPass(gl::Rectangle renderArea); 668 angle::Result endRenderPass(); 669 670 angle::Result syncExternalMemory(); 671 672 void addCommandBufferDiagnostics(const std::string &commandBufferDiagnostics); 673 674 VkIndexType getVkIndexType(gl::DrawElementsType glIndexType) const; 675 size_t getVkIndexTypeSize(gl::DrawElementsType glIndexType) const; 676 bool shouldConvertUint8VkIndexType(gl::DrawElementsType glIndexType) const; 677 isBresenhamEmulationEnabled(const gl::PrimitiveMode mode)678 ANGLE_INLINE bool isBresenhamEmulationEnabled(const gl::PrimitiveMode mode) 679 { 680 return getFeatures().basicGLLineRasterization.enabled && gl::IsLineMode(mode); 681 } 682 getExecutable()683 const ProgramExecutableVk *getExecutable() const { return mExecutable; } getExecutable()684 ProgramExecutableVk *getExecutable() { return mExecutable; } 685 686 bool isRobustResourceInitEnabled() const override; 687 688 // occlusion query 689 void beginOcclusionQuery(QueryVk *queryVk); 690 void endOcclusionQuery(QueryVk *queryVk); 691 692 private: 693 // Dirty bits. 694 enum DirtyBitType : size_t 695 { 696 DIRTY_BIT_DEFAULT_ATTRIBS, 697 DIRTY_BIT_PIPELINE, 698 DIRTY_BIT_TEXTURES, 699 DIRTY_BIT_VERTEX_BUFFERS, 700 DIRTY_BIT_INDEX_BUFFER, 701 DIRTY_BIT_DRIVER_UNIFORMS, 702 DIRTY_BIT_DRIVER_UNIFORMS_BINDING, 703 DIRTY_BIT_SHADER_RESOURCES, // excluding textures, which are handled separately. 704 DIRTY_BIT_TRANSFORM_FEEDBACK_BUFFERS, 705 DIRTY_BIT_TRANSFORM_FEEDBACK_STATE, 706 DIRTY_BIT_TRANSFORM_FEEDBACK_RESUME, 707 DIRTY_BIT_DESCRIPTOR_SETS, 708 DIRTY_BIT_MAX, 709 }; 710 711 using DirtyBits = angle::BitSet<DIRTY_BIT_MAX>; 712 713 using DirtyBitHandler = angle::Result (ContextVk::*)(const gl::Context *, 714 vk::CommandBuffer *commandBuffer); 715 716 struct DriverUniformsDescriptorSet 717 { 718 vk::DynamicBuffer dynamicBuffer; 719 VkDescriptorSet descriptorSet; 720 uint32_t dynamicOffset; 721 vk::BindingPointer<vk::DescriptorSetLayout> descriptorSetLayout; 722 vk::RefCountedDescriptorPoolBinding descriptorPoolBinding; 723 724 DriverUniformsDescriptorSet(); 725 ~DriverUniformsDescriptorSet(); 726 727 void init(RendererVk *rendererVk); 728 void destroy(RendererVk *rendererVk); 729 }; 730 731 enum class PipelineType 732 { 733 Graphics = 0, 734 Compute = 1, 735 736 InvalidEnum = 2, 737 EnumCount = 2, 738 }; 739 740 // The GpuEventQuery struct holds together a timestamp query and enough data to create a 741 // trace event based on that. Use traceGpuEvent to insert such queries. They will be readback 742 // when the results are available, without inserting a GPU bubble. 743 // 744 // - eventName will be the reported name of the event 745 // - phase is either 'B' (duration begin), 'E' (duration end) or 'i' (instant // event). 746 // See Google's "Trace Event Format": 747 // https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU 748 // - serial is the serial of the batch the query was submitted on. Until the batch is 749 // submitted, the query is not checked to avoid incuring a flush. 750 struct GpuEventQuery final 751 { 752 EventName name; 753 char phase; 754 vk::QueryHelper queryHelper; 755 }; 756 757 // Once a query result is available, the timestamp is read and a GpuEvent object is kept until 758 // the next clock sync, at which point the clock drift is compensated in the results before 759 // handing them off to the application. 760 struct GpuEvent final 761 { 762 uint64_t gpuTimestampCycles; 763 std::array<char, kMaxGpuEventNameLen> name; 764 char phase; 765 }; 766 767 struct GpuClockSyncInfo 768 { 769 double gpuTimestampS; 770 double cpuTimestampS; 771 }; 772 773 angle::Result setupDraw(const gl::Context *context, 774 gl::PrimitiveMode mode, 775 GLint firstVertexOrInvalid, 776 GLsizei vertexOrIndexCount, 777 GLsizei instanceCount, 778 gl::DrawElementsType indexTypeOrInvalid, 779 const void *indices, 780 DirtyBits dirtyBitMask, 781 vk::CommandBuffer **commandBufferOut); 782 angle::Result setupIndexedDraw(const gl::Context *context, 783 gl::PrimitiveMode mode, 784 GLsizei indexCount, 785 GLsizei instanceCount, 786 gl::DrawElementsType indexType, 787 const void *indices, 788 vk::CommandBuffer **commandBufferOut); 789 angle::Result setupIndirectDraw(const gl::Context *context, 790 gl::PrimitiveMode mode, 791 DirtyBits dirtyBitMask, 792 vk::BufferHelper *indirectBuffer, 793 VkDeviceSize indirectBufferOffset, 794 vk::CommandBuffer **commandBufferOut); 795 angle::Result setupIndexedIndirectDraw(const gl::Context *context, 796 gl::PrimitiveMode mode, 797 gl::DrawElementsType indexType, 798 vk::BufferHelper *indirectBuffer, 799 VkDeviceSize indirectBufferOffset, 800 vk::CommandBuffer **commandBufferOut); 801 802 angle::Result setupLineLoopIndexedIndirectDraw(const gl::Context *context, 803 gl::PrimitiveMode mode, 804 gl::DrawElementsType indexType, 805 vk::BufferHelper *srcIndirectBuf, 806 VkDeviceSize indirectBufferOffset, 807 vk::CommandBuffer **commandBufferOut, 808 vk::BufferHelper **indirectBufferOut, 809 VkDeviceSize *indirectBufferOffsetOut); 810 angle::Result setupLineLoopIndirectDraw(const gl::Context *context, 811 gl::PrimitiveMode mode, 812 vk::BufferHelper *indirectBuffer, 813 VkDeviceSize indirectBufferOffset, 814 vk::CommandBuffer **commandBufferOut, 815 vk::BufferHelper **indirectBufferOut, 816 VkDeviceSize *indirectBufferOffsetOut); 817 818 angle::Result setupLineLoopDraw(const gl::Context *context, 819 gl::PrimitiveMode mode, 820 GLint firstVertex, 821 GLsizei vertexOrIndexCount, 822 gl::DrawElementsType indexTypeOrInvalid, 823 const void *indices, 824 vk::CommandBuffer **commandBufferOut, 825 uint32_t *numIndicesOut); 826 angle::Result setupDispatch(const gl::Context *context, vk::CommandBuffer **commandBufferOut); 827 828 void updateViewport(FramebufferVk *framebufferVk, 829 const gl::Rectangle &viewport, 830 float nearPlane, 831 float farPlane, 832 bool invertViewport); 833 void updateDepthRange(float nearPlane, float farPlane); 834 void updateFlipViewportDrawFramebuffer(const gl::State &glState); 835 void updateFlipViewportReadFramebuffer(const gl::State &glState); 836 void updateSurfaceRotationDrawFramebuffer(const gl::State &glState); 837 void updateSurfaceRotationReadFramebuffer(const gl::State &glState); 838 839 angle::Result updateActiveTextures(const gl::Context *context); 840 angle::Result updateActiveImages(const gl::Context *context, 841 CommandBufferHelper *commandBufferHelper); 842 angle::Result updateDefaultAttribute(size_t attribIndex); 843 invalidateCurrentGraphicsPipeline()844 ANGLE_INLINE void invalidateCurrentGraphicsPipeline() 845 { 846 mGraphicsDirtyBits |= mNewGraphicsPipelineDirtyBits; 847 // The draw mode may have changed, toggling whether line rasterization is 848 // enabled or not, which means we need to recreate the graphics pipeline. 849 mCurrentGraphicsPipeline = nullptr; 850 } invalidateCurrentComputePipeline()851 ANGLE_INLINE void invalidateCurrentComputePipeline() 852 { 853 mComputeDirtyBits.set(DIRTY_BIT_PIPELINE); 854 mCurrentComputePipeline = nullptr; 855 } 856 857 void invalidateCurrentDefaultUniforms(); 858 angle::Result invalidateCurrentTextures(const gl::Context *context); 859 void invalidateCurrentShaderResources(); 860 void invalidateGraphicsDriverUniforms(); 861 void invalidateDriverUniforms(); 862 863 // Handlers for graphics pipeline dirty bits. 864 angle::Result handleDirtyGraphicsDefaultAttribs(const gl::Context *context, 865 vk::CommandBuffer *commandBuffer); 866 angle::Result handleDirtyGraphicsPipeline(const gl::Context *context, 867 vk::CommandBuffer *commandBuffer); 868 angle::Result handleDirtyGraphicsTextures(const gl::Context *context, 869 vk::CommandBuffer *commandBuffer); 870 angle::Result handleDirtyGraphicsVertexBuffers(const gl::Context *context, 871 vk::CommandBuffer *commandBuffer); 872 angle::Result handleDirtyGraphicsIndexBuffer(const gl::Context *context, 873 vk::CommandBuffer *commandBuffer); 874 angle::Result handleDirtyGraphicsDriverUniforms(const gl::Context *context, 875 vk::CommandBuffer *commandBuffer); 876 angle::Result handleDirtyGraphicsDriverUniformsBinding(const gl::Context *context, 877 vk::CommandBuffer *commandBuffer); 878 angle::Result handleDirtyGraphicsShaderResources(const gl::Context *context, 879 vk::CommandBuffer *commandBuffer); 880 angle::Result handleDirtyGraphicsTransformFeedbackBuffersEmulation( 881 const gl::Context *context, 882 vk::CommandBuffer *commandBuffer); 883 angle::Result handleDirtyGraphicsTransformFeedbackBuffersExtension( 884 const gl::Context *context, 885 vk::CommandBuffer *commandBuffer); 886 angle::Result handleDirtyGraphicsTransformFeedbackState(const gl::Context *context, 887 vk::CommandBuffer *commandBuffer); 888 angle::Result handleDirtyGraphicsTransformFeedbackResume(const gl::Context *context, 889 vk::CommandBuffer *commandBuffer); 890 891 // Handlers for compute pipeline dirty bits. 892 angle::Result handleDirtyComputePipeline(const gl::Context *context, 893 vk::CommandBuffer *commandBuffer); 894 angle::Result handleDirtyComputeTextures(const gl::Context *context, 895 vk::CommandBuffer *commandBuffer); 896 angle::Result handleDirtyComputeDriverUniforms(const gl::Context *context, 897 vk::CommandBuffer *commandBuffer); 898 angle::Result handleDirtyComputeDriverUniformsBinding(const gl::Context *context, 899 vk::CommandBuffer *commandBuffer); 900 angle::Result handleDirtyComputeShaderResources(const gl::Context *context, 901 vk::CommandBuffer *commandBuffer); 902 903 // Common parts of the common dirty bit handlers. 904 angle::Result handleDirtyTexturesImpl(CommandBufferHelper *commandBufferHelper); 905 angle::Result handleDirtyShaderResourcesImpl(const gl::Context *context, 906 CommandBufferHelper *commandBufferHelper); 907 void handleDirtyDriverUniformsBindingImpl(vk::CommandBuffer *commandBuffer, 908 VkPipelineBindPoint bindPoint, 909 const DriverUniformsDescriptorSet &driverUniforms); 910 angle::Result handleDirtyDescriptorSets(const gl::Context *context, 911 vk::CommandBuffer *commandBuffer); 912 angle::Result allocateDriverUniforms(size_t driverUniformsSize, 913 DriverUniformsDescriptorSet *driverUniforms, 914 VkBuffer *bufferOut, 915 uint8_t **ptrOut, 916 bool *newBufferOut); 917 angle::Result updateDriverUniformsDescriptorSet(VkBuffer buffer, 918 bool newBuffer, 919 size_t driverUniformsSize, 920 DriverUniformsDescriptorSet *driverUniforms); 921 922 void writeAtomicCounterBufferDriverUniformOffsets(uint32_t *offsetsOut, size_t offsetsSize); 923 924 angle::Result submitFrame(const VkSubmitInfo &submitInfo, 925 vk::PrimaryCommandBuffer &&commandBuffer); 926 angle::Result memoryBarrierImpl(GLbitfield barriers, VkPipelineStageFlags stageMask); 927 928 angle::Result synchronizeCpuGpuTime(); 929 angle::Result traceGpuEventImpl(vk::PrimaryCommandBuffer *commandBuffer, 930 char phase, 931 const EventName &name); 932 angle::Result checkCompletedGpuEvents(); 933 void flushGpuEvents(double nextSyncGpuTimestampS, double nextSyncCpuTimestampS); 934 void handleDeviceLost(); 935 void waitForSwapchainImageIfNecessary(); 936 bool shouldEmulateSeamfulCubeMapSampling() const; 937 bool shouldUseOldRewriteStructSamplers() const; 938 void clearAllGarbage(); 939 angle::Result ensureSubmitFenceInitialized(); 940 angle::Result startPrimaryCommandBuffer(); 941 bool hasRecordedCommands(); 942 void dumpCommandStreamDiagnostics(); 943 void flushOutsideRenderPassCommands(); 944 onRenderPassFinished()945 ANGLE_INLINE void onRenderPassFinished() { mRenderPassCommandBuffer = nullptr; } 946 947 void initIndexTypeMap(); 948 949 std::array<DirtyBitHandler, DIRTY_BIT_MAX> mGraphicsDirtyBitHandlers; 950 std::array<DirtyBitHandler, DIRTY_BIT_MAX> mComputeDirtyBitHandlers; 951 952 vk::CommandBuffer *mRenderPassCommandBuffer; 953 954 vk::PipelineHelper *mCurrentGraphicsPipeline; 955 vk::PipelineAndSerial *mCurrentComputePipeline; 956 gl::PrimitiveMode mCurrentDrawMode; 957 958 WindowSurfaceVk *mCurrentWindowSurface; 959 // Records the current rotation of the surface (draw/read) framebuffer, derived from 960 // mCurrentWindowSurface->getPreTransform(). 961 SurfaceRotationType mCurrentRotationDrawFramebuffer; 962 SurfaceRotationType mCurrentRotationReadFramebuffer; 963 964 // Keep a cached pipeline description structure that can be used to query the pipeline cache. 965 // Kept in a pointer so allocations can be aligned, and structs can be portably packed. 966 std::unique_ptr<vk::GraphicsPipelineDesc> mGraphicsPipelineDesc; 967 vk::GraphicsPipelineTransitionBits mGraphicsPipelineTransition; 968 969 // These pools are externally sychronized, so cannot be accessed from different 970 // threads simultaneously. Hence, we keep them in the ContextVk instead of the RendererVk. 971 // Note that this implementation would need to change in shared resource scenarios. Likely 972 // we'd instead share a single set of pools between the share groups. 973 vk::DynamicDescriptorPool mDriverUniformsDescriptorPool; 974 angle::PackedEnumMap<gl::QueryType, vk::DynamicQueryPool> mQueryPools; 975 976 // Dirty bits. 977 DirtyBits mGraphicsDirtyBits; 978 DirtyBits mComputeDirtyBits; 979 DirtyBits mNonIndexedDirtyBitsMask; 980 DirtyBits mIndexedDirtyBitsMask; 981 DirtyBits mNewGraphicsCommandBufferDirtyBits; 982 DirtyBits mNewComputeCommandBufferDirtyBits; 983 DirtyBits mNewGraphicsPipelineDirtyBits; 984 985 // Cached back-end objects. 986 VertexArrayVk *mVertexArray; 987 FramebufferVk *mDrawFramebuffer; 988 ProgramVk *mProgram; 989 ProgramPipelineVk *mProgramPipeline; 990 ProgramExecutableVk *mExecutable; 991 992 // occlusion query 993 QueryVk *mActiveQueryAnySamples; 994 QueryVk *mActiveQueryAnySamplesConservative; 995 996 // Graph resource used to record dispatch commands and hold resource dependencies. 997 vk::DispatchHelper mDispatcher; 998 999 // The offset we had the last time we bound the index buffer. 1000 const GLvoid *mLastIndexBufferOffset; 1001 gl::DrawElementsType mCurrentDrawElementsType; 1002 angle::PackedEnumMap<gl::DrawElementsType, VkIndexType> mIndexTypeMap; 1003 1004 // Cache the current draw call's firstVertex to be passed to 1005 // TransformFeedbackVk::getBufferOffsets. Unfortunately, gl_BaseVertex support in Vulkan is 1006 // not yet ubiquitous, which would have otherwise removed the need for this value to be passed 1007 // as a uniform. 1008 GLint mXfbBaseVertex; 1009 // Cache the current draw call's vertex count as well to support instanced draw calls 1010 GLuint mXfbVertexCountPerInstance; 1011 1012 // Cached clear value/mask for color and depth/stencil. 1013 VkClearValue mClearColorValue; 1014 VkClearValue mClearDepthStencilValue; 1015 VkColorComponentFlags mClearColorMask; 1016 1017 IncompleteTextureSet mIncompleteTextures; 1018 1019 // If the current surface bound to this context wants to have all rendering flipped vertically. 1020 // Updated on calls to onMakeCurrent. 1021 bool mFlipYForCurrentSurface; 1022 bool mFlipViewportForDrawFramebuffer; 1023 bool mFlipViewportForReadFramebuffer; 1024 1025 // If any host-visible buffer is written by the GPU since last submission, a barrier is inserted 1026 // at the end of the command buffer to make that write available to the host. 1027 bool mIsAnyHostVisibleBufferWritten; 1028 1029 // Whether this context should do seamful cube map sampling emulation. 1030 bool mEmulateSeamfulCubeMapSampling; 1031 1032 // Whether this context should use the old version of the 1033 // RewriteStructSamplers pass. 1034 bool mUseOldRewriteStructSamplers; 1035 1036 angle::PackedEnumMap<PipelineType, DriverUniformsDescriptorSet> mDriverUniforms; 1037 1038 // This cache should also probably include the texture index (shader location) and array 1039 // index (also in the shader). This info is used in the descriptor update step. 1040 gl::ActiveTextureArray<vk::TextureUnit> mActiveTextures; 1041 vk::TextureDescriptorDesc mActiveTexturesDesc; 1042 1043 gl::ActiveTextureArray<TextureVk *> mActiveImages; 1044 1045 // "Current Value" aka default vertex attribute state. 1046 gl::AttributesMask mDirtyDefaultAttribsMask; 1047 gl::AttribArray<vk::DynamicBuffer> mDefaultAttribBuffers; 1048 1049 // We use a single pool for recording commands. We also keep a free list for pool recycling. 1050 vk::CommandPool mCommandPool; 1051 1052 CommandQueue mCommandQueue; 1053 vk::GarbageList mCurrentGarbage; 1054 1055 RenderPassCache mRenderPassCache; 1056 1057 // mSubmitFence is the fence that's going to be signaled at the next submission. This is used 1058 // to support SyncVk objects, which may outlive the context (as EGLSync objects). 1059 // 1060 // TODO(geofflang): this is in preparation for moving RendererVk functionality to ContextVk, and 1061 // is otherwise unnecessary as the SyncVk objects don't actually outlive the renderer currently. 1062 // http://anglebug.com/2701 1063 vk::Shared<vk::Fence> mSubmitFence; 1064 1065 // Pool allocator used for command graph but may be expanded to other allocations 1066 angle::PoolAllocator mPoolAllocator; 1067 1068 // When the command graph is disabled we record commands completely linearly. We have plans to 1069 // reorder independent draws so that we can create fewer RenderPasses in some scenarios. 1070 OutsideRenderPassCommandBuffer mOutsideRenderPassCommands; 1071 RenderPassCommandBuffer mRenderPassCommands; 1072 vk::PrimaryCommandBuffer mPrimaryCommands; 1073 bool mHasPrimaryCommands; 1074 1075 // Internal shader library. 1076 vk::ShaderLibrary mShaderLibrary; 1077 UtilsVk mUtils; 1078 1079 bool mGpuEventsEnabled; 1080 vk::DynamicQueryPool mGpuEventQueryPool; 1081 // A list of queries that have yet to be turned into an event (their result is not yet 1082 // available). 1083 std::vector<GpuEventQuery> mInFlightGpuEventQueries; 1084 // A list of gpu events since the last clock sync. 1085 std::vector<GpuEvent> mGpuEvents; 1086 1087 // Semaphores that must be waited on in the next submission. 1088 std::vector<VkSemaphore> mWaitSemaphores; 1089 std::vector<VkPipelineStageFlags> mWaitSemaphoreStageMasks; 1090 1091 // Hold information from the last gpu clock sync for future gpu-to-cpu timestamp conversions. 1092 GpuClockSyncInfo mGpuClockSync; 1093 1094 // The very first timestamp queried for a GPU event is used as origin, so event timestamps would 1095 // have a value close to zero, to avoid losing 12 bits when converting these 64 bit values to 1096 // double. 1097 uint64_t mGpuEventTimestampOrigin; 1098 1099 // Used to count events for tracing. 1100 uint32_t mPrimaryBufferCounter; 1101 uint32_t mRenderPassCounter; 1102 1103 // Generators for texture & framebuffer serials. 1104 SerialFactory mTextureSerialFactory; 1105 SerialFactory mAttachmentImageSerialFactory; 1106 1107 gl::State::DirtyBits mPipelineDirtyBitsMask; 1108 1109 // List of all resources currently being used by this ContextVk's recorded commands. 1110 vk::ResourceUseList mResourceUseList; 1111 1112 egl::ContextPriority mContextPriority; 1113 1114 std::vector<std::string> mCommandBufferDiagnostics; 1115 }; 1116 } // namespace rx 1117 1118 #endif // LIBANGLE_RENDERER_VULKAN_CONTEXTVK_H_ 1119