#pragma once #include #include #include #include #include "vk_mem_alloc.h" class CommandPool; class Instance { public: explicit Instance(); ~Instance(); GLFWwindow *window = nullptr; VkSurfaceKHR surface = VK_NULL_HANDLE; VkPhysicalDevice physicalDevice = VK_NULL_HANDLE; VkDevice device = VK_NULL_HANDLE; VmaAllocator allocator = VK_NULL_HANDLE; VkQueue graphicsQueue = VK_NULL_HANDLE; VkQueue presentQueue = VK_NULL_HANDLE; VkQueue computeQueue = VK_NULL_HANDLE; CommandPool* commandPool = nullptr; struct QueueFamilyIndices { std::optional graphicsFamily; std::optional computeFamily; std::optional presentFamily; std::optional graphicsAndComputeFamily; bool isComplete() const { return graphicsFamily.has_value() && computeFamily.has_value() && presentFamily.has_value() && graphicsAndComputeFamily.has_value(); } std::set uniqueQueueFamilies(){ return { graphicsFamily.value(), presentFamily.value(), computeFamily.value(), graphicsAndComputeFamily.value() }; } }; static QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface); static Instance* instance; private: VkInstance handle = VK_NULL_HANDLE; void initWindow(); void createInstance(); void createSurface(); void pickPhysicalDevice(); void createLogicalDevice(); void createAllocator(); bool isDeviceSuitable(VkPhysicalDevice potentialPhysicalDevice); static bool checkDeviceExtensionSupport(VkPhysicalDevice device); };