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 
10 #include <vulkan/vulkan.h>
11 
12 #include <memory>
13 #include <vector>
14 
15 #include "base/component_export.h"
16 #include "base/containers/span.h"
17 #include "gpu/vulkan/semaphore_handle.h"
18 
19 namespace gpu {
20 
21 struct GPUInfo;
22 class VulkanInfo;
23 
24 // Submits semaphores to be signaled to the vulkan queue. Semaphores are
25 // signaled once this submission is executed. vk_fence is an optional handle
26 // to fence to be signaled once this submission completes execution.
27 COMPONENT_EXPORT(VULKAN)
28 bool SubmitSignalVkSemaphores(VkQueue vk_queue,
29                               const base::span<VkSemaphore>& vk_semaphore,
30                               VkFence vk_fence = VK_NULL_HANDLE);
31 
32 // Submits a semaphore to be signaled to the vulkan queue. Semaphore is
33 // signaled once this submission is executed. vk_fence is an optional handle
34 // to fence to be signaled once this submission completes execution.
35 COMPONENT_EXPORT(VULKAN)
36 bool SubmitSignalVkSemaphore(VkQueue vk_queue,
37                              VkSemaphore vk_semaphore,
38                              VkFence vk_fence = VK_NULL_HANDLE);
39 
40 // Submits semaphores to be waited upon to the vulkan queue. Semaphores are
41 // waited on before this submission is executed. vk_fence is an optional
42 // handle to fence to be signaled once this submission completes execution.
43 COMPONENT_EXPORT(VULKAN)
44 bool SubmitWaitVkSemaphores(VkQueue vk_queue,
45                             const base::span<VkSemaphore>& vk_semaphores,
46                             VkFence vk_fence = VK_NULL_HANDLE);
47 
48 // Submits a semaphore to be waited upon to the vulkan queue. Semaphore is
49 // waited on before this submission is executed. vk_fence is an optional
50 // handle to fence to be signaled once this submission completes execution.
51 COMPONENT_EXPORT(VULKAN)
52 bool SubmitWaitVkSemaphore(VkQueue vk_queue,
53                            VkSemaphore vk_semaphore,
54                            VkFence vk_fence = VK_NULL_HANDLE);
55 
56 // Creates semaphore that can be exported to external handles of the specified
57 // |handle_types|.
58 COMPONENT_EXPORT(VULKAN)
59 VkSemaphore CreateExternalVkSemaphore(
60     VkDevice vk_device,
61     VkExternalSemaphoreHandleTypeFlags handle_types);
62 
63 // Imports a semaphore from a handle.
64 COMPONENT_EXPORT(VULKAN)
65 VkSemaphore ImportVkSemaphoreHandle(VkDevice vk_device, SemaphoreHandle handle);
66 
67 // Gets a handle from a semaphore
68 COMPONENT_EXPORT(VULKAN)
69 SemaphoreHandle GetVkSemaphoreHandle(
70     VkDevice vk_device,
71     VkSemaphore vk_semaphore,
72     VkExternalSemaphoreHandleTypeFlagBits handle_type);
73 
74 COMPONENT_EXPORT(VULKAN)
75 std::string VkVersionToString(uint32_t version);
76 
77 COMPONENT_EXPORT(VULKAN)
78 VKAPI_ATTR VkResult VKAPI_CALL QueueSubmitHook(VkQueue queue,
79                                                uint32_t submitCount,
80                                                const VkSubmitInfo* pSubmits,
81                                                VkFence fence);
82 
83 COMPONENT_EXPORT(VULKAN)
84 VKAPI_ATTR void RecordImportingVKSemaphoreIntoGL();
85 
86 COMPONENT_EXPORT(VULKAN) void ReportUMAPerSwapBuffers();
87 
88 COMPONENT_EXPORT(VULKAN)
89 bool CheckVulkanCompabilities(const VulkanInfo& vulkan_info,
90                               const GPUInfo& gpu_info);
91 
92 }  // namespace gpu
93 
94 #endif  // GPU_VULKAN_VULKAN_UTIL_H_
95