| 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 "flutter/vulkan/procs/vulkan_handle.h" |
| 13 | |
| 14 | namespace vulkan { |
| 15 | |
| 16 | class VulkanProcTable; |
| 17 | class VulkanSurface; |
| 18 | |
| 19 | class VulkanDevice { |
| 20 | public: |
| 21 | /// @brief Create a new VkDevice with a resolved VkQueue suitable for |
| 22 | /// rendering with Skia. |
| 23 | /// |
| 24 | VulkanDevice(VulkanProcTable& vk, |
| 25 | VulkanHandle<VkPhysicalDevice> physical_device, |
| 26 | bool enable_validation_layers); |
| 27 | |
| 28 | /// @brief Wrap an existing VkDevice and VkQueue. |
| 29 | /// |
| 30 | VulkanDevice(VulkanProcTable& vk, |
| 31 | VulkanHandle<VkPhysicalDevice> physical_device, |
| 32 | VulkanHandle<VkDevice> device, |
| 33 | uint32_t queue_family_index, |
| 34 | VulkanHandle<VkQueue> queue); |
| 35 | ~VulkanDevice(); |
| 36 | |
| 37 | bool IsValid() const; |
| 38 | |
| 39 | const VulkanHandle<VkDevice>& GetHandle() const; |
| 40 | |
| 41 | const VulkanHandle<VkPhysicalDevice>& GetPhysicalDeviceHandle() const; |
| 42 | |
| 43 | const VulkanHandle<VkQueue>& GetQueueHandle() const; |
| 44 | |
| 45 | const VulkanHandle<VkCommandPool>& GetCommandPool() const; |
| 46 | |
| 47 | uint32_t GetGraphicsQueueIndex() const; |
| 48 | |
| 49 | void ReleaseDeviceOwnership(); |
| 50 | |
| 51 | [[nodiscard]] bool GetSurfaceCapabilities( |
| 52 | const VulkanSurface& surface, |
| 53 | VkSurfaceCapabilitiesKHR* capabilities) const; |
| 54 | |
| 55 | [[nodiscard]] bool GetPhysicalDeviceFeatures( |
| 56 | VkPhysicalDeviceFeatures* features) const; |
| 57 | |
| 58 | [[nodiscard]] bool GetPhysicalDeviceFeaturesSkia( |
| 59 | uint32_t* /* mask of GrVkFeatureFlags */ features) const; |
| 60 | |
| 61 | [[nodiscard]] int ChooseSurfaceFormat( |
| 62 | const VulkanSurface& surface, |
| 63 | const std::vector<VkFormat>& desired_formats, |
| 64 | VkSurfaceFormatKHR* format) const; |
| 65 | |
| 66 | [[nodiscard]] bool ChoosePresentMode(const VulkanSurface& surface, |
| 67 | VkPresentModeKHR* present_mode) const; |
| 68 | |
| 69 | [[nodiscard]] bool QueueSubmit( |
| 70 | std::vector<VkPipelineStageFlags> wait_dest_pipeline_stages, |
| 71 | const std::vector<VkSemaphore>& wait_semaphores, |
| 72 | const std::vector<VkSemaphore>& signal_semaphores, |
| 73 | const std::vector<VkCommandBuffer>& command_buffers, |
| 74 | const VulkanHandle<VkFence>& fence) const; |
| 75 | |
| 76 | [[nodiscard]] bool WaitIdle() const; |
| 77 | |
| 78 | private: |
| 79 | VulkanProcTable& vk; |
| 80 | VulkanHandle<VkPhysicalDevice> physical_device_; |
| 81 | VulkanHandle<VkDevice> device_; |
| 82 | VulkanHandle<VkQueue> queue_; |
| 83 | VulkanHandle<VkCommandPool> command_pool_; |
| 84 | uint32_t graphics_queue_index_; |
| 85 | bool valid_; |
| 86 | |
| 87 | bool InitializeCommandPool(); |
| 88 | std::vector<VkQueueFamilyProperties> GetQueueFamilyProperties() const; |
| 89 | |
| 90 | FML_DISALLOW_COPY_AND_ASSIGN(VulkanDevice); |
| 91 | }; |
| 92 | |
| 93 | } // namespace vulkan |
| 94 | |
| 95 | #endif // FLUTTER_VULKAN_VULKAN_DEVICE_H_ |
| 96 | |