• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef SWAP_CHAIN_STATE_VK_H
2 #define SWAP_CHAIN_STATE_VK_H
3 
4 #include <functional>
5 #include <memory>
6 #include <optional>
7 #include <type_traits>
8 #include <unordered_set>
9 #include <vector>
10 
11 #include "vulkan/cereal/common/goldfish_vk_dispatch.h"
12 
13 struct SwapchainCreateInfoWrapper {
14     VkSwapchainCreateInfoKHR mCreateInfo;
15     std::vector<uint32_t> mQueueFamilyIndices;
16 
17     SwapchainCreateInfoWrapper(const SwapchainCreateInfoWrapper&);
18     SwapchainCreateInfoWrapper(SwapchainCreateInfoWrapper&&) = delete;
19     SwapchainCreateInfoWrapper& operator=(const SwapchainCreateInfoWrapper&);
20     SwapchainCreateInfoWrapper& operator=(SwapchainCreateInfoWrapper&&) = delete;
21 
22     SwapchainCreateInfoWrapper(const VkSwapchainCreateInfoKHR&);
23 
24     void setQueueFamilyIndices(const std::vector<uint32_t>& queueFamilyIndices);
25 };
26 
27 // Assert SwapchainCreateInfoWrapper is a copy only class.
28 static_assert(std::is_copy_assignable_v<SwapchainCreateInfoWrapper> &&
29               std::is_copy_constructible_v<SwapchainCreateInfoWrapper> &&
30               !std::is_move_constructible_v<SwapchainCreateInfoWrapper> &&
31               !std::is_move_assignable_v<SwapchainCreateInfoWrapper>);
32 
33 class SwapChainStateVk {
34    public:
35     static std::vector<const char *> getRequiredInstanceExtensions();
36     static std::vector<const char *> getRequiredDeviceExtensions();
37     static bool validateQueueFamilyProperties(const goldfish_vk::VulkanDispatch &, VkPhysicalDevice,
38                                               VkSurfaceKHR, uint32_t queueFamilyIndex);
39     static std::optional<SwapchainCreateInfoWrapper> createSwapChainCi(
40         const goldfish_vk::VulkanDispatch&, VkSurfaceKHR, VkPhysicalDevice, uint32_t width,
41         uint32_t height, const std::unordered_set<uint32_t>& queueFamilyIndices);
42 
43     explicit SwapChainStateVk(const goldfish_vk::VulkanDispatch &, VkDevice,
44                               const VkSwapchainCreateInfoKHR &);
45     ~SwapChainStateVk();
46     VkFormat getFormat();
47     const std::vector<VkImage> &getVkImages() const;
48     const std::vector<VkImageView> &getVkImageViews() const;
49     VkSwapchainKHR getSwapChain() const;
50 
51    private:
52     const static VkFormat k_vkFormat = VK_FORMAT_B8G8R8A8_UNORM;
53     const static VkColorSpaceKHR k_vkColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
54 
55     const goldfish_vk::VulkanDispatch &m_vk;
56     VkDevice m_vkDevice;
57     VkSwapchainKHR m_vkSwapChain;
58     std::vector<VkImage> m_vkImages;
59     std::vector<VkImageView> m_vkImageViews;
60 };
61 
62 #endif