vulkan_util.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. //
  5. // This file defines some helper functions for Vulkan API.
  6. #ifndef GPU_VULKAN_VULKAN_UTIL_H_
  7. #define GPU_VULKAN_VULKAN_UTIL_H_
  8. #include <vulkan/vulkan_core.h>
  9. #include <memory>
  10. #include <vector>
  11. #include "base/component_export.h"
  12. #include "base/containers/span.h"
  13. #include "gpu/vulkan/semaphore_handle.h"
  14. namespace gpu {
  15. constexpr uint32_t kVendorARM = 0x13b5;
  16. constexpr uint32_t kVendorQualcomm = 0x5143;
  17. constexpr uint32_t kVendorImagination = 0x1010;
  18. struct GPUInfo;
  19. class VulkanInfo;
  20. // Submits semaphores to be signaled to the vulkan queue. Semaphores are
  21. // signaled once this submission is executed. vk_fence is an optional handle
  22. // to fence to be signaled once this submission completes execution.
  23. COMPONENT_EXPORT(VULKAN)
  24. bool SubmitSignalVkSemaphores(VkQueue vk_queue,
  25. const base::span<VkSemaphore>& vk_semaphore,
  26. VkFence vk_fence = VK_NULL_HANDLE);
  27. // Submits a semaphore to be signaled to the vulkan queue. Semaphore is
  28. // signaled once this submission is executed. vk_fence is an optional handle
  29. // to fence to be signaled once this submission completes execution.
  30. COMPONENT_EXPORT(VULKAN)
  31. bool SubmitSignalVkSemaphore(VkQueue vk_queue,
  32. VkSemaphore vk_semaphore,
  33. VkFence vk_fence = VK_NULL_HANDLE);
  34. // Submits semaphores to be waited upon to the vulkan queue. Semaphores are
  35. // waited on before this submission is executed. vk_fence is an optional
  36. // handle to fence to be signaled once this submission completes execution.
  37. COMPONENT_EXPORT(VULKAN)
  38. bool SubmitWaitVkSemaphores(VkQueue vk_queue,
  39. const base::span<VkSemaphore>& vk_semaphores,
  40. VkFence vk_fence = VK_NULL_HANDLE);
  41. // Submits a semaphore to be waited upon to the vulkan queue. Semaphore is
  42. // waited on before this submission is executed. vk_fence is an optional
  43. // handle to fence to be signaled once this submission completes execution.
  44. COMPONENT_EXPORT(VULKAN)
  45. bool SubmitWaitVkSemaphore(VkQueue vk_queue,
  46. VkSemaphore vk_semaphore,
  47. VkFence vk_fence = VK_NULL_HANDLE);
  48. // Creates semaphore that can be exported to external handles of the specified
  49. // |handle_types|.
  50. COMPONENT_EXPORT(VULKAN)
  51. VkSemaphore CreateExternalVkSemaphore(
  52. VkDevice vk_device,
  53. VkExternalSemaphoreHandleTypeFlags handle_types);
  54. // Imports a semaphore from a handle.
  55. COMPONENT_EXPORT(VULKAN)
  56. VkSemaphore ImportVkSemaphoreHandle(VkDevice vk_device, SemaphoreHandle handle);
  57. // Gets a handle from a semaphore
  58. COMPONENT_EXPORT(VULKAN)
  59. SemaphoreHandle GetVkSemaphoreHandle(
  60. VkDevice vk_device,
  61. VkSemaphore vk_semaphore,
  62. VkExternalSemaphoreHandleTypeFlagBits handle_type);
  63. COMPONENT_EXPORT(VULKAN)
  64. std::string VkVersionToString(uint32_t version);
  65. COMPONENT_EXPORT(VULKAN)
  66. VKAPI_ATTR VkResult VKAPI_CALL
  67. CreateGraphicsPipelinesHook(VkDevice device,
  68. VkPipelineCache pipelineCache,
  69. uint32_t createInfoCount,
  70. const VkGraphicsPipelineCreateInfo* pCreateInfos,
  71. const VkAllocationCallbacks* pAllocator,
  72. VkPipeline* pPipelines);
  73. // Below vulkanQueue*Hook methods are used to ensure that Skia calls the correct
  74. // version of those methods which are made thread safe by using locks. See
  75. // vulkan_function_pointers.h vkQueue* method references for more details.
  76. COMPONENT_EXPORT(VULKAN)
  77. VKAPI_ATTR VkResult VKAPI_CALL
  78. VulkanQueueSubmitHook(VkQueue queue,
  79. uint32_t submitCount,
  80. const VkSubmitInfo* pSubmits,
  81. VkFence fence);
  82. COMPONENT_EXPORT(VULKAN)
  83. VKAPI_ATTR VkResult VKAPI_CALL VulkanQueueWaitIdleHook(VkQueue queue);
  84. COMPONENT_EXPORT(VULKAN)
  85. VKAPI_ATTR VkResult VKAPI_CALL
  86. VulkanQueuePresentKHRHook(VkQueue queue, const VkPresentInfoKHR* pPresentInfo);
  87. COMPONENT_EXPORT(VULKAN)
  88. bool CheckVulkanCompabilities(const VulkanInfo& vulkan_info,
  89. const GPUInfo& gpu_info,
  90. std::string enable_by_device_name);
  91. COMPONENT_EXPORT(VULKAN)
  92. VkImageLayout GLImageLayoutToVkImageLayout(uint32_t layout);
  93. COMPONENT_EXPORT(VULKAN)
  94. uint32_t VkImageLayoutToGLImageLayout(VkImageLayout layout);
  95. } // namespace gpu
  96. #endif // GPU_VULKAN_VULKAN_UTIL_H_