dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 1 | // Copyright (c) 2016 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 | #ifndef GPU_VULKAN_VULKAN_DEVICE_QUEUE_H_ |
| 6 | #define GPU_VULKAN_VULKAN_DEVICE_QUEUE_H_ |
| 7 | |
| 8 | #include <vulkan/vulkan.h> |
| 9 | |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 10 | #include <memory> |
| 11 | |
Michael Spang | 7509e6d | 2018-05-16 17:08:28 | [diff] [blame] | 12 | #include "base/callback.h" |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 13 | #include "base/logging.h" |
| 14 | #include "base/macros.h" |
Vikas Soni | b08bd9b | 2019-06-13 05:49:47 | [diff] [blame] | 15 | #include "build/build_config.h" |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 16 | #include "gpu/vulkan/vulkan_export.h" |
Michael Spang | 4e46bc2 | 2018-06-21 23:07:51 | [diff] [blame] | 17 | #include "ui/gfx/extension_set.h" |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 18 | |
| 19 | namespace gpu { |
| 20 | |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 21 | class VulkanCommandPool; |
Peng Huang | c2d69cc | 2019-10-07 23:02:25 | [diff] [blame] | 22 | class VulkanFenceHelper; |
| 23 | class VulkanInfo; |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 24 | |
| 25 | class VULKAN_EXPORT VulkanDeviceQueue { |
| 26 | public: |
| 27 | enum DeviceQueueOption { |
| 28 | GRAPHICS_QUEUE_FLAG = 0x01, |
| 29 | PRESENTATION_SUPPORT_QUEUE_FLAG = 0x02, |
| 30 | }; |
| 31 | |
Emircan Uysaler | d41c9bf | 2019-08-08 20:38:33 | [diff] [blame] | 32 | VulkanDeviceQueue(VkInstance vk_instance, |
| 33 | bool enforce_protected_memory = false); |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 34 | ~VulkanDeviceQueue(); |
| 35 | |
Michael Spang | 7509e6d | 2018-05-16 17:08:28 | [diff] [blame] | 36 | using GetPresentationSupportCallback = |
| 37 | base::RepeatingCallback<bool(VkPhysicalDevice, |
| 38 | const std::vector<VkQueueFamilyProperties>&, |
| 39 | uint32_t queue_family_index)>; |
| 40 | bool Initialize( |
| 41 | uint32_t options, |
Peng Huang | c2d69cc | 2019-10-07 23:02:25 | [diff] [blame] | 42 | const VulkanInfo& info, |
Michael Spang | 4e46bc2 | 2018-06-21 23:07:51 | [diff] [blame] | 43 | const std::vector<const char*>& required_extensions, |
Peng Huang | 334077c | 2020-02-24 15:27:44 | [diff] [blame] | 44 | const std::vector<const char*>& optional_extensions, |
Emircan Uysaler | d41c9bf | 2019-08-08 20:38:33 | [diff] [blame] | 45 | bool allow_protected_memory, |
Sergey Ulanov | e82b100 | 2019-07-22 22:23:39 | [diff] [blame] | 46 | const GetPresentationSupportCallback& get_presentation_support); |
Michael Spang | 7509e6d | 2018-05-16 17:08:28 | [diff] [blame] | 47 | |
Shouqun Liu | 80cd8a8 | 2019-06-17 18:15:19 | [diff] [blame] | 48 | bool InitializeForWebView(VkPhysicalDevice vk_physical_device, |
| 49 | VkDevice vk_device, |
| 50 | VkQueue vk_queue, |
| 51 | uint32_t vk_queue_index, |
| 52 | gfx::ExtensionSet enabled_extensions); |
Peng Huang | bcf31dc | 2019-03-12 00:35:40 | [diff] [blame] | 53 | |
Michael Spang | 4e46bc2 | 2018-06-21 23:07:51 | [diff] [blame] | 54 | const gfx::ExtensionSet& enabled_extensions() const { |
| 55 | return enabled_extensions_; |
| 56 | } |
| 57 | |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 58 | void Destroy(); |
| 59 | |
| 60 | VkPhysicalDevice GetVulkanPhysicalDevice() const { |
| 61 | DCHECK_NE(static_cast<VkPhysicalDevice>(VK_NULL_HANDLE), |
| 62 | vk_physical_device_); |
| 63 | return vk_physical_device_; |
| 64 | } |
| 65 | |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 66 | const VkPhysicalDeviceProperties& vk_physical_device_properties() const { |
| 67 | return vk_physical_device_properties_; |
| 68 | } |
| 69 | |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 70 | VkDevice GetVulkanDevice() const { |
| 71 | DCHECK_NE(static_cast<VkDevice>(VK_NULL_HANDLE), vk_device_); |
| 72 | return vk_device_; |
| 73 | } |
| 74 | |
| 75 | VkQueue GetVulkanQueue() const { |
| 76 | DCHECK_NE(static_cast<VkQueue>(VK_NULL_HANDLE), vk_queue_); |
| 77 | return vk_queue_; |
| 78 | } |
| 79 | |
suyambu.rm | f2fbf53 | 2017-12-04 08:38:15 | [diff] [blame] | 80 | VkInstance GetVulkanInstance() const { return vk_instance_; } |
| 81 | |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 82 | uint32_t GetVulkanQueueIndex() const { return vk_queue_index_; } |
| 83 | |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 84 | std::unique_ptr<gpu::VulkanCommandPool> CreateCommandPool(); |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 85 | |
Eric Karl | f9ec4a50 | 2019-04-11 18:29:52 | [diff] [blame] | 86 | VulkanFenceHelper* GetFenceHelper() const { return cleanup_helper_.get(); } |
| 87 | |
Vikas Soni | b08bd9b | 2019-06-13 05:49:47 | [diff] [blame] | 88 | const VkPhysicalDeviceFeatures2& enabled_device_features_2() const { |
| 89 | return enabled_device_features_2_; |
Saman Sami | a009003 | 2019-06-06 21:41:36 | [diff] [blame] | 90 | } |
| 91 | |
Peng Huang | 784a2d0 | 2019-06-13 14:55:21 | [diff] [blame] | 92 | const VkPhysicalDeviceFeatures& enabled_device_features() const { |
| 93 | return enabled_device_features_2_.features; |
| 94 | } |
| 95 | |
Emircan Uysaler | d41c9bf | 2019-08-08 20:38:33 | [diff] [blame] | 96 | bool allow_protected_memory() const { return allow_protected_memory_; } |
| 97 | |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 98 | private: |
Michael Spang | 4e46bc2 | 2018-06-21 23:07:51 | [diff] [blame] | 99 | gfx::ExtensionSet enabled_extensions_; |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 100 | VkPhysicalDevice vk_physical_device_ = VK_NULL_HANDLE; |
Peng Huang | 3c13b50 | 2019-05-08 01:40:00 | [diff] [blame] | 101 | VkPhysicalDeviceProperties vk_physical_device_properties_; |
Peng Huang | bcf31dc | 2019-03-12 00:35:40 | [diff] [blame] | 102 | VkDevice owned_vk_device_ = VK_NULL_HANDLE; |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 103 | VkDevice vk_device_ = VK_NULL_HANDLE; |
| 104 | VkQueue vk_queue_ = VK_NULL_HANDLE; |
| 105 | uint32_t vk_queue_index_ = 0; |
Michael Spang | 7509e6d | 2018-05-16 17:08:28 | [diff] [blame] | 106 | const VkInstance vk_instance_; |
Eric Karl | f9ec4a50 | 2019-04-11 18:29:52 | [diff] [blame] | 107 | std::unique_ptr<VulkanFenceHelper> cleanup_helper_; |
Peng Huang | c2d69cc | 2019-10-07 23:02:25 | [diff] [blame] | 108 | VkPhysicalDeviceFeatures2 enabled_device_features_2_; |
Sergey Ulanov | 6ff66f2 | 2019-08-14 00:38:39 | [diff] [blame] | 109 | |
Emircan Uysaler | d41c9bf | 2019-08-08 20:38:33 | [diff] [blame] | 110 | const bool enforce_protected_memory_; |
| 111 | bool allow_protected_memory_ = false; |
Vikas Soni | b08bd9b | 2019-06-13 05:49:47 | [diff] [blame] | 112 | |
Sergey Ulanov | 6ff66f2 | 2019-08-14 00:38:39 | [diff] [blame] | 113 | #if defined(OS_ANDROID) || defined(OS_FUCHSIA) |
Vikas Soni | b08bd9b | 2019-06-13 05:49:47 | [diff] [blame] | 114 | VkPhysicalDeviceSamplerYcbcrConversionFeatures |
Peng Huang | c2d69cc | 2019-10-07 23:02:25 | [diff] [blame] | 115 | sampler_ycbcr_conversion_features_; |
Sergey Ulanov | 6ff66f2 | 2019-08-14 00:38:39 | [diff] [blame] | 116 | #endif // defined(OS_ANDROID) || defined(OS_FUCHSIA) |
| 117 | |
Peng Huang | c2d69cc | 2019-10-07 23:02:25 | [diff] [blame] | 118 | VkPhysicalDeviceProtectedMemoryFeatures protected_memory_features_; |
dyen | 8a145fb7 | 2016-03-31 00:37:51 | [diff] [blame] | 119 | |
| 120 | DISALLOW_COPY_AND_ASSIGN(VulkanDeviceQueue); |
| 121 | }; |
| 122 | |
| 123 | } // namespace gpu |
| 124 | |
| 125 | #endif // GPU_VULKAN_VULKAN_DEVICE_QUEUE_H_ |