tree: 9c7ea5e702cc0a3ba72365994ed1522e8ea8736c [path history] [tgz]
  1. BufferVk.cpp
  2. BufferVk.h
  3. CommandGraph.cpp
  4. CommandGraph.h
  5. CompilerVk.cpp
  6. CompilerVk.h
  7. ContextVk.cpp
  8. ContextVk.h
  9. DeviceVk.cpp
  10. DeviceVk.h
  11. DisplayVk.cpp
  12. DisplayVk.h
  13. FenceNVVk.cpp
  14. FenceNVVk.h
  15. FramebufferVk.cpp
  16. FramebufferVk.h
  17. GlslangWrapper.cpp
  18. GlslangWrapper.h
  19. ImageVk.cpp
  20. ImageVk.h
  21. ProgramPipelineVk.cpp
  22. ProgramPipelineVk.h
  23. ProgramVk.cpp
  24. ProgramVk.h
  25. QueryVk.cpp
  26. QueryVk.h
  27. README.md
  28. RenderTargetVk.cpp
  29. RenderTargetVk.h
  30. RenderbufferVk.cpp
  31. RenderbufferVk.h
  32. RendererVk.cpp
  33. RendererVk.h
  34. SamplerVk.cpp
  35. SamplerVk.h
  36. ShaderVk.cpp
  37. ShaderVk.h
  38. SurfaceVk.cpp
  39. SurfaceVk.h
  40. SyncVk.cpp
  41. SyncVk.h
  42. TextureVk.cpp
  43. TextureVk.h
  44. TransformFeedbackVk.cpp
  45. TransformFeedbackVk.h
  46. UtilsVk.cpp
  47. UtilsVk.h
  48. VertexArrayVk.cpp
  49. VertexArrayVk.h
  50. android/
  51. fuchsia/
  52. gen_vk_format_table.py
  53. gen_vk_internal_shaders.py
  54. gen_vk_mandatory_format_support_table.py
  55. shaders/
  56. vk_cache_utils.cpp
  57. vk_cache_utils.h
  58. vk_caps_utils.cpp
  59. vk_caps_utils.h
  60. vk_format_map.json
  61. vk_format_table_autogen.cpp
  62. vk_format_utils.cpp
  63. vk_format_utils.h
  64. vk_helpers.cpp
  65. vk_helpers.h
  66. vk_internal_shaders_autogen.cpp
  67. vk_internal_shaders_autogen.gni
  68. vk_internal_shaders_autogen.h
  69. vk_mandatory_format_support_data.json
  70. vk_mandatory_format_support_table_autogen.cpp
  71. vk_utils.cpp
  72. vk_utils.h
  73. vk_wrapper.h
  74. win32/
  75. xcb/
src/libANGLE/renderer/vulkan/README.md

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 is a singleton. RendererVk owns shared global resources like the VkDevice, VkQueue, the Vulkan format tables and internal Vulkan shaders. The back-end creates a new ContextVk instance to manage each allocated OpenGL Context. ContextVk processes state changes and handles action commands like glDrawArrays and glDrawElements.

Fast OpenGL State Transitions

Typical OpenGL programs issue a few small state change commands between draw call commands. We want the typical app's use case to be as fast as possible so this leads to unique performance challenges.

Vulkan in quite different from OpenGL because it requires a separate compiled VkPipeline for each state vector. Compiling VkPipelines is multiple orders of magnitude slower than enabling or disabling an OpenGL render state. To speed this up we use three levels of caching when transitioning states in the Vulkan back-end.

The first level is the driver's VkPipelineCache. The driver cache reduces pipeline recompilation time significantly. But even cached pipeline recompilations are orders of manitude slower than OpenGL state changes.

The second level cache is an ANGLE-owned hash map from OpenGL state vectors to compiled pipelines. See GraphicsPipelineCache in vk_cache_utils.h. ANGLE's GraphicsPipelineDesc class is a tightly packed 256-byte description of the current OpenGL rendering state. We also use a xxHash for the fastest possible hash computation. The hash map speeds up state changes considerably. But it is still significantly slower than OpenGL implementations.

To get best performance we use a transition table from each OpenGL state vector to neighbouring state vectors. The transition table points from GraphicsPipelineCache entries directly to neighbouring VkPipeline objects. When the application changes state the state change bits are recorded into a compact bit mask that covers the GraphicsPipelineDesc state vector. Then on the next draw call we scan the transition bit mask and compare the GraphicsPipelineDesc of the current state vector and the state vector of the cached transition. With the hash map we compute a hash over the entire state vector and then do a 256-byte memcmp to guard against hash collisions. With the transition table we will only compare as many bytes as were changed in the transition bit mask. By skipping the expensive hashing and memcmp we can get as good or faster performance than native OpenGL drivers.

Note that the current design of the transition table stores transitions in an unsorted list. If applications map from one state to many this will slow down the transition time. This could be improved in the future using a faster look up. For instance we could keep a sorted transition table or use a small hash map for transitions.