Sergey Ulanov | 730a7f0 | 2019-04-02 20:49:37 | [diff] [blame] | 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 | |
| 7 | #ifndef GPU_VULKAN_VULKAN_UTIL_H_ |
| 8 | #define GPU_VULKAN_VULKAN_UTIL_H_ |
| 9 | |
Bruce Dawson | 4d1542b | 2021-09-30 20:44:36 | [diff] [blame] | 10 | #include <vulkan/vulkan_core.h> |
Sergey Ulanov | 730a7f0 | 2019-04-02 20:49:37 | [diff] [blame] | 11 | |
| 12 | #include <memory> |
| 13 | #include <vector> |
| 14 | |
Peng Huang | 0a13bf5 | 2020-05-05 16:01:05 | [diff] [blame] | 15 | #include "base/component_export.h" |
Peng Huang | 96962eabf | 2019-04-24 03:48:30 | [diff] [blame] | 16 | #include "base/containers/span.h" |
Peng Huang | 8f3abd4 | 2020-04-03 20:07:24 | [diff] [blame] | 17 | #include "gpu/vulkan/semaphore_handle.h" |
Sergey Ulanov | 730a7f0 | 2019-04-02 20:49:37 | [diff] [blame] | 18 | |
| 19 | namespace gpu { |
| 20 | |
Jonathan Backer | 8e49819 | 2021-01-18 22:23:29 | [diff] [blame] | 21 | constexpr uint32_t kVendorARM = 0x13b5; |
| 22 | constexpr uint32_t kVendorQualcomm = 0x5143; |
| 23 | constexpr uint32_t kVendorImagination = 0x1010; |
| 24 | |
Peng Huang | e3df8ba | 2020-06-19 23:52:00 | [diff] [blame] | 25 | struct GPUInfo; |
| 26 | class VulkanInfo; |
| 27 | |
Peng Huang | 96962eabf | 2019-04-24 03:48:30 | [diff] [blame] | 28 | // Submits semaphores to be signaled to the vulkan queue. Semaphores are |
| 29 | // signaled once this submission is executed. vk_fence is an optional handle |
| 30 | // to fence to be signaled once this submission completes execution. |
Peng Huang | 0a13bf5 | 2020-05-05 16:01:05 | [diff] [blame] | 31 | COMPONENT_EXPORT(VULKAN) |
| 32 | bool SubmitSignalVkSemaphores(VkQueue vk_queue, |
| 33 | const base::span<VkSemaphore>& vk_semaphore, |
| 34 | VkFence vk_fence = VK_NULL_HANDLE); |
Peng Huang | 96962eabf | 2019-04-24 03:48:30 | [diff] [blame] | 35 | |
Sergey Ulanov | 730a7f0 | 2019-04-02 20:49:37 | [diff] [blame] | 36 | // Submits a semaphore to be signaled to the vulkan queue. Semaphore is |
| 37 | // signaled once this submission is executed. vk_fence is an optional handle |
| 38 | // to fence to be signaled once this submission completes execution. |
Peng Huang | 0a13bf5 | 2020-05-05 16:01:05 | [diff] [blame] | 39 | COMPONENT_EXPORT(VULKAN) |
| 40 | bool SubmitSignalVkSemaphore(VkQueue vk_queue, |
| 41 | VkSemaphore vk_semaphore, |
| 42 | VkFence vk_fence = VK_NULL_HANDLE); |
Sergey Ulanov | 730a7f0 | 2019-04-02 20:49:37 | [diff] [blame] | 43 | |
| 44 | // Submits semaphores to be waited upon to the vulkan queue. Semaphores are |
| 45 | // waited on before this submission is executed. vk_fence is an optional |
| 46 | // handle to fence to be signaled once this submission completes execution. |
Peng Huang | 0a13bf5 | 2020-05-05 16:01:05 | [diff] [blame] | 47 | COMPONENT_EXPORT(VULKAN) |
| 48 | bool SubmitWaitVkSemaphores(VkQueue vk_queue, |
| 49 | const base::span<VkSemaphore>& vk_semaphores, |
| 50 | VkFence vk_fence = VK_NULL_HANDLE); |
Sergey Ulanov | 730a7f0 | 2019-04-02 20:49:37 | [diff] [blame] | 51 | |
| 52 | // Submits a semaphore to be waited upon to the vulkan queue. Semaphore is |
| 53 | // waited on before this submission is executed. vk_fence is an optional |
| 54 | // handle to fence to be signaled once this submission completes execution. |
Peng Huang | 0a13bf5 | 2020-05-05 16:01:05 | [diff] [blame] | 55 | COMPONENT_EXPORT(VULKAN) |
| 56 | bool SubmitWaitVkSemaphore(VkQueue vk_queue, |
| 57 | VkSemaphore vk_semaphore, |
| 58 | VkFence vk_fence = VK_NULL_HANDLE); |
Sergey Ulanov | 730a7f0 | 2019-04-02 20:49:37 | [diff] [blame] | 59 | |
| 60 | // Creates semaphore that can be exported to external handles of the specified |
| 61 | // |handle_types|. |
Peng Huang | 0a13bf5 | 2020-05-05 16:01:05 | [diff] [blame] | 62 | COMPONENT_EXPORT(VULKAN) |
| 63 | VkSemaphore CreateExternalVkSemaphore( |
| 64 | VkDevice vk_device, |
| 65 | VkExternalSemaphoreHandleTypeFlags handle_types); |
Sergey Ulanov | 730a7f0 | 2019-04-02 20:49:37 | [diff] [blame] | 66 | |
Peng Huang | 8f3abd4 | 2020-04-03 20:07:24 | [diff] [blame] | 67 | // Imports a semaphore from a handle. |
Peng Huang | 0a13bf5 | 2020-05-05 16:01:05 | [diff] [blame] | 68 | COMPONENT_EXPORT(VULKAN) |
| 69 | VkSemaphore ImportVkSemaphoreHandle(VkDevice vk_device, SemaphoreHandle handle); |
Peng Huang | 8f3abd4 | 2020-04-03 20:07:24 | [diff] [blame] | 70 | |
| 71 | // Gets a handle from a semaphore |
Peng Huang | 0a13bf5 | 2020-05-05 16:01:05 | [diff] [blame] | 72 | COMPONENT_EXPORT(VULKAN) |
| 73 | SemaphoreHandle GetVkSemaphoreHandle( |
| 74 | VkDevice vk_device, |
| 75 | VkSemaphore vk_semaphore, |
| 76 | VkExternalSemaphoreHandleTypeFlagBits handle_type); |
Peng Huang | 8f3abd4 | 2020-04-03 20:07:24 | [diff] [blame] | 77 | |
Peng Huang | 0a13bf5 | 2020-05-05 16:01:05 | [diff] [blame] | 78 | COMPONENT_EXPORT(VULKAN) |
Peng Huang | 60108c2 | 2020-05-04 16:25:24 | [diff] [blame] | 79 | std::string VkVersionToString(uint32_t version); |
| 80 | |
Peng Huang | b49180ee | 2020-05-13 21:12:15 | [diff] [blame] | 81 | COMPONENT_EXPORT(VULKAN) |
Vasiliy Telezhnikov | ea02d91 | 2021-02-01 20:24:56 | [diff] [blame] | 82 | VKAPI_ATTR VkResult VKAPI_CALL |
| 83 | CreateGraphicsPipelinesHook(VkDevice device, |
| 84 | VkPipelineCache pipelineCache, |
| 85 | uint32_t createInfoCount, |
| 86 | const VkGraphicsPipelineCreateInfo* pCreateInfos, |
| 87 | const VkAllocationCallbacks* pAllocator, |
| 88 | VkPipeline* pPipelines); |
| 89 | |
Peng Huang | e3df8ba | 2020-06-19 23:52:00 | [diff] [blame] | 90 | COMPONENT_EXPORT(VULKAN) |
| 91 | bool CheckVulkanCompabilities(const VulkanInfo& vulkan_info, |
Jonathan Backer | f48f920 | 2021-01-14 18:39:46 | [diff] [blame] | 92 | const GPUInfo& gpu_info, |
| 93 | std::string enable_by_device_name); |
Peng Huang | e3df8ba | 2020-06-19 23:52:00 | [diff] [blame] | 94 | |
Sergey Ulanov | 730a7f0 | 2019-04-02 20:49:37 | [diff] [blame] | 95 | } // namespace gpu |
| 96 | |
| 97 | #endif // GPU_VULKAN_VULKAN_UTIL_H_ |