tree: c4066977fbc493d5e21c322d60cf93322e174daf [path history] [tgz]
  1. android/
  2. doc/
  3. fuchsia/
  4. ggp/
  5. linux/
  6. mac/
  7. null/
  8. shaders/
  9. win32/
  10. AllocatorHelperPool.cpp
  11. AllocatorHelperPool.h
  12. AllocatorHelperRing.cpp
  13. AllocatorHelperRing.h
  14. BufferVk.cpp
  15. BufferVk.h
  17. cl_types.h
  18. CLCommandQueueVk.cpp
  19. CLCommandQueueVk.h
  20. CLContextVk.cpp
  21. CLContextVk.h
  22. CLDeviceVk.cpp
  23. CLDeviceVk.h
  24. CLEventVk.cpp
  25. CLEventVk.h
  26. CLKernelVk.cpp
  27. CLKernelVk.h
  28. CLMemoryVk.cpp
  29. CLMemoryVk.h
  30. CLPlatformVk.cpp
  31. CLPlatformVk.h
  32. CLProgramVk.cpp
  33. CLProgramVk.h
  34. CLSamplerVk.cpp
  35. CLSamplerVk.h
  36. CommandProcessor.cpp
  37. CommandProcessor.h
  38. CompilerVk.cpp
  39. CompilerVk.h
  40. ContextVk.cpp
  41. ContextVk.h
  42. DebugAnnotatorVk.cpp
  43. DebugAnnotatorVk.h
  44. DeviceVk.cpp
  45. DeviceVk.h
  46. DisplayVk.cpp
  47. DisplayVk.h
  48. DisplayVk_api.h
  49. FenceNVVk.cpp
  50. FenceNVVk.h
  51. FramebufferVk.cpp
  52. FramebufferVk.h
  56. ImageVk.cpp
  57. ImageVk.h
  58. MemoryObjectVk.cpp
  59. MemoryObjectVk.h
  60. MemoryTracking.cpp
  61. MemoryTracking.h
  62. OverlayVk.cpp
  63. OverlayVk.h
  64. OWNERS
  65. PersistentCommandPool.cpp
  66. PersistentCommandPool.h
  67. ProgramExecutableVk.cpp
  68. ProgramExecutableVk.h
  69. ProgramPipelineVk.cpp
  70. ProgramPipelineVk.h
  71. ProgramVk.cpp
  72. ProgramVk.h
  73. QueryVk.cpp
  74. QueryVk.h
  76. RenderbufferVk.cpp
  77. RenderbufferVk.h
  78. RendererVk.cpp
  79. RendererVk.h
  80. RenderTargetVk.cpp
  81. RenderTargetVk.h
  82. ResourceVk.cpp
  83. ResourceVk.h
  84. SamplerVk.cpp
  85. SamplerVk.h
  86. SecondaryCommandBuffer.cpp
  87. SecondaryCommandBuffer.h
  88. SecondaryCommandPool.cpp
  89. SecondaryCommandPool.h
  90. SemaphoreVk.cpp
  91. SemaphoreVk.h
  92. ShaderInterfaceVariableInfoMap.cpp
  93. ShaderInterfaceVariableInfoMap.h
  94. ShaderVk.cpp
  95. ShaderVk.h
  96. spv_utils.cpp
  97. spv_utils.h
  98. Suballocation.cpp
  99. Suballocation.h
  100. SurfaceVk.cpp
  101. SurfaceVk.h
  102. SyncVk.cpp
  103. SyncVk.h
  104. TextureVk.cpp
  105. TextureVk.h
  106. TransformFeedbackVk.cpp
  107. TransformFeedbackVk.h
  108. UtilsVk.cpp
  109. UtilsVk.h
  110. VertexArrayVk.cpp
  111. VertexArrayVk.h
  112. vk_cache_utils.cpp
  113. vk_cache_utils.h
  114. vk_caps_utils.cpp
  115. vk_caps_utils.h
  116. vk_command_buffer_utils.h
  117. vk_format_map.json
  118. vk_format_table_autogen.cpp
  119. vk_format_utils.cpp
  120. vk_format_utils.h
  121. vk_helpers.cpp
  122. vk_helpers.h
  123. vk_internal_shaders_autogen.cpp
  124. vk_internal_shaders_autogen.gni
  125. vk_internal_shaders_autogen.h
  126. vk_mandatory_format_support_data.json
  127. vk_mandatory_format_support_table_autogen.cpp
  128. vk_mem_alloc_wrapper.cpp
  129. vk_mem_alloc_wrapper.h
  130. vk_utils.cpp
  131. vk_utils.h
  132. vk_wrapper.h
  133. VkImageImageSiblingVk.cpp
  134. VkImageImageSiblingVk.h
  135. vulkan_backend.gni
  136. VulkanSecondaryCommandBuffer.cpp
  137. VulkanSecondaryCommandBuffer.h

ANGLE: Vulkan Back-end

ANGLE's Vulkan back-end implementation lives in this folder.

Vulkan is an explicit graphics API. It has a lot in common with other explicit APIs such as Microsoft‘s D3D12 and Apple’s Metal. Compared to APIs like OpenGL or D3D11 explicit APIs can offer a number of significant benefits:

  • Lower API call CPU overhead.
  • A smaller API surface with more direct hardware control.
  • Better support for multi-core programming.
  • Vulkan in particular has open-source tooling and tests.

Back-end Design

The RendererVk class represents an EGLDisplay. RendererVk owns shared global resources like the VkDevice, VkQueue, the Vulkan format tables and internal Vulkan shaders. The ContextVk class implements the back-end of a front-end OpenGL Context. ContextVk processes state changes and handles action commands like glDrawArrays and glDrawElements.

Command recording

A render pass has three states: unstarted, started and active (we call it active in short), started but inactive (we call it inactive in short). The back-end records commands into command buffers via the following ContextVk APIs:

  • beginNewRenderPass: Writes out (aka flushes) prior pending commands into a primary command buffer, then starts a new render pass. Returns a secondary command buffer inside a render pass instance.
  • getOutsideRenderPassCommandBuffer: May flush prior command buffers and close the render pass if necessary, in addition to issuing the appropriate barriers. Returns a secondary command buffer outside a render pass instance.
  • getStartedRenderPassCommands: Returns a reference to the currently open render pass' commands buffer.
  • onRenderPassFinished: Puts render pass into inactive state where you can not record more commands into secondary command buffer, except in some special cases where ANGLE does some optimization internally.
  • flushCommandsAndEndRenderPassWithoutSubmit: Marks the end of render pass. It flushes secondary command buffer into vulkan's primary command buffer, puts secondary command buffer back to unstarted state and then goes into recycler for reuse.

The back-end (mostly) records Image and Buffer barriers through additional CommandBufferAccess APIs, the result of which is passed to getOutsideRenderPassCommandBuffer. Note that the barriers are not actually recorded until getOutsideRenderPassCommandBuffer is called:

  • onBufferTransferRead and onBufferComputeShaderRead accumulate VkBuffer read barriers.
  • onBufferTransferWrite and onBufferComputeShaderWrite accumulate VkBuffer write barriers.
  • onBuffferSelfCopy is a special case for VkBuffer self copies. It behaves the same as write.
  • onImageTransferRead and onImageComputerShadeRead accumulate VkImage read barriers.
  • onImageTransferWrite and onImageComputerShadeWrite accumulate VkImage write barriers.
  • onImageRenderPassRead and onImageRenderPassWrite accumulate VkImage barriers inside a started RenderPass.

After the back-end records commands to the primary buffer and we flush (e.g. on swap) or when we call RendererVk::finishQueueSerial, ANGLE submits the primary command buffer to a VkQueue.

See the code for more details.

Simple command recording example

In this example we'll be recording a buffer copy command:

    // Ensure that ANGLE sets proper read and write barriers for the Buffers.
    vk::CommandBufferAccess access;

    // Get a pointer to a secondary command buffer for command recording.
    vk::OutsideRenderPassCommandBuffer *commandBuffer;
    ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(access, &commandBuffer));

    // Record the copy command into the secondary buffer. We're done!
    commandBuffer->copyBuffer(srcBuffer->getBuffer(), dstBuffer->getBuffer(), copyCount, copies);

Additional Reading

More implementation details can be found in the doc directory: