1 | // Copyright 2013 The Flutter 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 FLUTTER_VULKAN_VULKAN_DEVICE_H_ |
6 | #define FLUTTER_VULKAN_VULKAN_DEVICE_H_ |
7 | |
8 | #include <vector> |
9 | |
10 | #include "flutter/fml/compiler_specific.h" |
11 | #include "flutter/fml/macros.h" |
12 | #include "vulkan_handle.h" |
13 | |
14 | namespace vulkan { |
15 | |
16 | class VulkanProcTable; |
17 | class VulkanSurface; |
18 | |
19 | class VulkanDevice { |
20 | public: |
21 | VulkanDevice(VulkanProcTable& vk, |
22 | VulkanHandle<VkPhysicalDevice> physical_device, |
23 | bool enable_validation_layers); |
24 | |
25 | ~VulkanDevice(); |
26 | |
27 | bool IsValid() const; |
28 | |
29 | const VulkanHandle<VkDevice>& GetHandle() const; |
30 | |
31 | const VulkanHandle<VkPhysicalDevice>& GetPhysicalDeviceHandle() const; |
32 | |
33 | const VulkanHandle<VkQueue>& GetQueueHandle() const; |
34 | |
35 | const VulkanHandle<VkCommandPool>& GetCommandPool() const; |
36 | |
37 | uint32_t GetGraphicsQueueIndex() const; |
38 | |
39 | void ReleaseDeviceOwnership(); |
40 | |
41 | [[nodiscard]] bool GetSurfaceCapabilities( |
42 | const VulkanSurface& surface, |
43 | VkSurfaceCapabilitiesKHR* capabilities) const; |
44 | |
45 | [[nodiscard]] bool GetPhysicalDeviceFeatures( |
46 | VkPhysicalDeviceFeatures* features) const; |
47 | |
48 | [[nodiscard]] bool GetPhysicalDeviceFeaturesSkia( |
49 | uint32_t* /* mask of GrVkFeatureFlags */ features) const; |
50 | |
51 | [[nodiscard]] int ChooseSurfaceFormat(const VulkanSurface& surface, |
52 | std::vector<VkFormat> desired_formats, |
53 | VkSurfaceFormatKHR* format) const; |
54 | |
55 | [[nodiscard]] bool ChoosePresentMode(const VulkanSurface& surface, |
56 | VkPresentModeKHR* present_mode) const; |
57 | |
58 | [[nodiscard]] bool QueueSubmit( |
59 | std::vector<VkPipelineStageFlags> wait_dest_pipeline_stages, |
60 | const std::vector<VkSemaphore>& wait_semaphores, |
61 | const std::vector<VkSemaphore>& signal_semaphores, |
62 | const std::vector<VkCommandBuffer>& command_buffers, |
63 | const VulkanHandle<VkFence>& fence) const; |
64 | |
65 | [[nodiscard]] bool WaitIdle() const; |
66 | |
67 | private: |
68 | VulkanProcTable& vk; |
69 | VulkanHandle<VkPhysicalDevice> physical_device_; |
70 | VulkanHandle<VkDevice> device_; |
71 | VulkanHandle<VkQueue> queue_; |
72 | VulkanHandle<VkCommandPool> command_pool_; |
73 | uint32_t graphics_queue_index_; |
74 | bool valid_; |
75 | bool enable_validation_layers_; |
76 | |
77 | std::vector<VkQueueFamilyProperties> GetQueueFamilyProperties() const; |
78 | |
79 | FML_DISALLOW_COPY_AND_ASSIGN(VulkanDevice); |
80 | }; |
81 | |
82 | } // namespace vulkan |
83 | |
84 | #endif // FLUTTER_VULKAN_VULKAN_DEVICE_H_ |
85 | |